Skip to content
Open
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 deku-c/deku-c-toolkit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@marigold-dev/deku-c-toolkit",
"version": "0.1.4",
"version": "0.1.6",
"description": "Deku typescript client to interact with deku-c",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
Expand Down
24 changes: 19 additions & 5 deletions deku-c/deku-c-toolkit/src/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class Contract {
}

/**
* Invoke a deku-c smart contrat
* Invoke a Deku-C smart contrat
* @param parameter the parameter of the contract
* @returns the hash of the operation
*/
Expand All @@ -113,8 +113,8 @@ export class Contract {

/**
* Returns the state of the contract
* Parses it to a readable javascript object
* @returns javascript object
* Parses it to a readable Javascript object
* @returns Javascript object
*/
async getState(): Promise<any | null> {
const state = await this.getRawState();
Expand All @@ -123,7 +123,7 @@ export class Contract {
}

/**
* Returns the state of the contract as a wasm-vm state object
* Returns the state of the contract as a WASM-VM state object
* @returns an object representing the state of the contract
*/
async getRawState(): Promise<JSONType | null> {
Expand All @@ -137,6 +137,11 @@ export class Contract {
return json["state"];
}

/**
* Fetch the WASM-VM state of the contract each second
* Returns it as an object if there is at least one difference
* @returns an object representing the state of the contract
*/
async onNewState(callback: (state: JSONType) => void): Promise<void> {
// pull strategy
let previous: JSONType = null;
Expand All @@ -152,6 +157,15 @@ export class Contract {
return null;
})
.catch(console.error);
}, 2000);
}, 1000);
}

/**
* Cancel the interval to fetch the new state each second
* Can be useful to disconnect your user from your application
* @returns an object representing the state of the contract
*/
cancelOnNewState(): void {
if (this.fetchInterval) clearInterval(this.fetchInterval);
}
Comment on lines +168 to 170
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a doc to explain what this function does ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}