Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved examples and types (#7) #6

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ jobs:
- name: Validate
run: |
pnpm install
pnpm validate
pnpm validate:run
72 changes: 36 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ pnpm add cess-js-sdk
const { Space, InitAPI, Common, testnetConfig, wellKnownAcct } = require("cess-js-sdk");

async function main() {
const { api, keyring } = await InitAPI(testnetConfig);
const { addr, mnemonicOrAccountId32 } = wellKnownAcct;
const { api, keyring } = await InitAPI(testnetConfig);
const { addr, mnemonicOrAccountId32 } = wellKnownAcct;

const space = new Space(api, keyring);
const space = new Space(api, keyring);
/*
const bucket = new Bucket(api, keyring, true);
const space2 = new Space2(api, keyring, true);
Expand All @@ -40,42 +40,42 @@ async function main() {
true
);
*/
const common = new Common(api, keyring);

console.log("query userOwnedSpace:");
let result = await space.userOwnedSpace(addr);
const blockHeight = await common.queryBlockHeight();

result = common.formatSpaceInfo(result.data, blockHeight);
console.log(result);

function getDataIfOk(result) {
return result.msg === "ok" ? result.data : result;
}

if (result.totalSpace) {
console.log("expansionSpace:");
result = await space.expansionSpace(mnemonicOrAccountId32, 1);
console.log(getDataIfOk(result), "\n");

console.log("renewalSpace:");
result = await space.renewalSpace(mnemonicOrAccountId32, 1);
console.log(getDataIfOk(result), "\n");
} else {
console.log("buySpace:");
result = await space.buySpace(mnemonicOrAccountId32, 1);
console.log(getDataIfOk(result), "\n");
}

console.log("query userOwnedSpace:");
result = await space.userOwnedSpace(addr);
result = common.formatSpaceInfo(result.data, blockHeight);
console.log(result);
const common = new Common(api, keyring);

console.log("query userOwnedSpace:");
let result = await space.userOwnedSpace(addr);
const blockHeight = await common.queryBlockHeight();

result = common.formatSpaceInfo(result.data, blockHeight);
console.log(result);

function getDataIfOk(result) {
return result.msg === "ok" ? result.data : result;
}

if (result.totalSpace) {
console.log("expansionSpace:");
result = await space.expansionSpace(mnemonicOrAccountId32, 1);
console.log(getDataIfOk(result), "\n");

console.log("renewalSpace:");
result = await space.renewalSpace(mnemonicOrAccountId32, 1);
console.log(getDataIfOk(result), "\n");
} else {
console.log("buySpace:");
result = await space.buySpace(mnemonicOrAccountId32, 1);
console.log(getDataIfOk(result), "\n");
}

console.log("query userOwnedSpace:");
result = await space.userOwnedSpace(addr);
result = common.formatSpaceInfo(result.data, blockHeight);
console.log(result);
}

main()
.catch(console.error)
.finally(() => process.exit());
.catch(console.error)
.finally(() => process.exit());
```

More examples are in the [**examples**](./examples) directory.
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"scripts": {
"fmt": "prettier --write .",
"lint": "eslint .",
"test:types": "ts-node src/tests/types.ts",
"examples": "ts-node src/examples/index.ts",
"validate": "npm run fmt && npm run lint && npm run test:types"
"test:types": "tsx src/tests/types.ts",
"examples": "tsx src/examples/index.ts",
"validate": "pnpm prettier -c . && pnpm lint",
"validate:run": "pnpm prettier -c . && pnpm lint && pnpm test:types"
},
"dependencies": {
"@polkadot/api": "^10.9.1",
Expand Down Expand Up @@ -45,6 +46,7 @@
"lint-staged": "^15.0.2",
"prettier": "^3.0.3",
"ts-node": "^10.9.1",
"tsx": "^4.7.1",
"typescript": "^5.2.2"
},
"keywords": [
Expand Down
Loading
Loading