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

feat: useCall convert bigint in args to string #549

Merged
merged 3 commits into from
Jan 11, 2025
Merged
Changes from 1 commit
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
23 changes: 22 additions & 1 deletion packages/core/src/hooks/use-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
DaveVodrazka marked this conversation as resolved.
Show resolved Hide resolved
blockIdentifier,
},
] as const;
Expand Down
Loading