From 96f8293d45115a00b484efdcd2e83b9f91734f5b Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Wed, 8 Jan 2025 12:21:07 +0100 Subject: [PATCH 1/3] feat: useCall convert bigint in args to string --- packages/core/src/hooks/use-call.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/core/src/hooks/use-call.ts b/packages/core/src/hooks/use-call.ts index 658006a9..b624d56e 100644 --- a/packages/core/src/hooks/use-call.ts +++ b/packages/core/src/hooks/use-call.ts @@ -121,13 +121,34 @@ function queryKey({ args, blockIdentifier, }: { chain?: Chain; contract?: Contract } & CallArgs) { + function convertBigIntsToStrings(input: any): any { + if (typeof input === "bigint") { + return input.toString(10); + } + if (Array.isArray(input)) { + // Recursively process each element in the array + return input.map((item) => convertBigIntsToStrings(item)); + } + if (input && typeof input === "object") { + // If it's an object, process each key-value pair + const result: { [key: string]: any } = {}; + for (const key in input) { + if (Object.prototype.hasOwnProperty.call(input, key)) { + result[key] = convertBigIntsToStrings(input[key]); + } + } + return result; + } + + return input; + } return [ { entity: "readContract", chainId: chain?.name, contract: contract?.address, functionName, - args, + args: convertBigIntsToStrings(args), blockIdentifier, }, ] as const; From 7c601e3650dc8c30ef1c7e8e987b6eb7417f3369 Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Thu, 9 Jan 2025 12:10:16 +0100 Subject: [PATCH 2/3] Change files --- ...et-react-core-a41ab949-7f4b-43ab-9196-a874280859b9.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@starknet-react-core-a41ab949-7f4b-43ab-9196-a874280859b9.json diff --git a/change/@starknet-react-core-a41ab949-7f4b-43ab-9196-a874280859b9.json b/change/@starknet-react-core-a41ab949-7f4b-43ab-9196-a874280859b9.json new file mode 100644 index 00000000..11c528db --- /dev/null +++ b/change/@starknet-react-core-a41ab949-7f4b-43ab-9196-a874280859b9.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "feat: useCall convert bigint in args to string", + "packageName": "@starknet-react/core", + "email": "dave.vodrazka@gmail.com", + "dependentChangeType": "patch" +} From daa1c71a90fd0d3761765a5a6aa33a995938296e Mon Sep 17 00:00:00 2001 From: DaveVodrazka Date: Thu, 9 Jan 2025 12:11:38 +0100 Subject: [PATCH 3/3] fix: useCall simpler stringification --- packages/core/src/hooks/use-call.ts | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/packages/core/src/hooks/use-call.ts b/packages/core/src/hooks/use-call.ts index b624d56e..d0e4f4ef 100644 --- a/packages/core/src/hooks/use-call.ts +++ b/packages/core/src/hooks/use-call.ts @@ -121,34 +121,15 @@ function queryKey({ args, blockIdentifier, }: { chain?: Chain; contract?: Contract } & CallArgs) { - function convertBigIntsToStrings(input: any): any { - if (typeof input === "bigint") { - return input.toString(10); - } - if (Array.isArray(input)) { - // Recursively process each element in the array - return input.map((item) => convertBigIntsToStrings(item)); - } - if (input && typeof input === "object") { - // If it's an object, process each key-value pair - const result: { [key: string]: any } = {}; - for (const key in input) { - if (Object.prototype.hasOwnProperty.call(input, key)) { - result[key] = convertBigIntsToStrings(input[key]); - } - } - return result; - } - - return input; - } return [ { entity: "readContract", chainId: chain?.name, contract: contract?.address, functionName, - args: convertBigIntsToStrings(args), + args: JSON.stringify(args, (_, v) => + typeof v === "bigint" ? v.toString(10) : v, + ), blockIdentifier, }, ] as const;