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.5",
"description": "Deku typescript client to interact with deku-c",
"main": "lib/src/index.js",
"types": "lib/src/index.d.ts",
Expand Down
9 changes: 5 additions & 4 deletions deku-c/deku-c-toolkit/src/contract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { DekuToolkit } from "@marigold-dev/deku-toolkit";
import { stringifyReplacer } from "./utils";

export type JSONType =
| string
| number
| bigint
| boolean
| { [x: string]: JSONType }
| Array<JSONType>
Expand All @@ -15,7 +16,7 @@ const parseContractState = (json: JSONType): JSONType => {
switch (type) {
case "Int":
const value = json[1] as string;
return Number.parseInt(value);
return BigInt(value);
case "String": {
const value = json[1] as string;
return value;
Expand Down Expand Up @@ -144,8 +145,8 @@ export class Contract {
this.fetchInterval = setInterval(() => {
this.getState()
.then((state) => {
const previousState = JSON.stringify(previous);
const nextState = JSON.stringify(state);
const previousState = JSON.stringify(previous, stringifyReplacer);
const nextState = JSON.stringify(state, stringifyReplacer);
if (nextState === previousState) return null;
callback(state);
previous = state;
Expand Down
23 changes: 23 additions & 0 deletions deku-c/deku-c-toolkit/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ export const operationHashToContractAddress = async (
if (response.ok) return json.address;
throw json;
};


/**
* Helper to correctly parse BigInt
* @param _key unused
* @param value can be e BigInt
* @returns
*/
export const parseReviver = (_key: any, value: any) => {
const regex = new RegExp("^[0-9]+bigint$");
if (typeof value === 'string' && regex.test(value)) {
return BigInt(value.slice(0, -6));
}
return value;
}

export const stringifyReplacer = (_key: any, value: any) => {
if (typeof value === 'bigint') {
return value.toString() + 'bigint';
} else {
return value;
}
}