diff --git a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx index 023efe875..0a92861ea 100644 --- a/packages/nextjs/app/debug/_components/contract/utilsContract.tsx +++ b/packages/nextjs/app/debug/_components/contract/utilsContract.tsx @@ -18,16 +18,31 @@ const isJsonString = (str: string) => { } }; +const isBigInt = (str: string) => { + if (str.trim().length === 0) return false; + try { + BigInt(str); + return true; + } catch (e) { + return false; + } +}; + // Recursive function to deeply parse JSON strings, correctly handling nested arrays and encoded JSON strings const deepParseValues = (value: any): any => { if (typeof value === "string") { + // first try with bigInt because we losse precision with JSON.parse + if (isBigInt(value)) { + return BigInt(value); + } + if (isJsonString(value)) { const parsed = JSON.parse(value); return deepParseValues(parsed); - } else { - // It's a string but not a JSON string, return as is - return value; } + + // It's a string but not a JSON string, return as is + return value; } else if (Array.isArray(value)) { // If it's an array, recursively parse each element return value.map(element => deepParseValues(element));