From ea540afcf6c4241cdc9ff999a3a3f5696cc6ea13 Mon Sep 17 00:00:00 2001 From: Andrew Kirillov Date: Tue, 22 Oct 2024 15:14:36 -0700 Subject: [PATCH] core: utils: http: parse BigInt values directly from JSON source --- packages/core/src/utils/http.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/core/src/utils/http.ts b/packages/core/src/utils/http.ts index 172180d0..66bc5492 100644 --- a/packages/core/src/utils/http.ts +++ b/packages/core/src/utils/http.ts @@ -51,9 +51,18 @@ export async function getRelayerRaw(url: string, headers = {}) { url.includes('/open-orders') || url.includes('/metadata') ) { - return JSON.parse(data, (key, value) => { + // We use ts-ignore here because TypeScript doesn't recognize the + // `context` argument in the JSON.parse reviver + // @ts-ignore + return JSON.parse(data, (key, value, context) => { if (typeof value === 'number' && key !== 'price') { - return BigInt(value) + if (context?.source === undefined) { + console.warn( + `No JSON source for ${key}, converting parsed value to BigInt`, + ) + return BigInt(value) + } + return BigInt(context.source) } return value })