Skip to content

Commit

Permalink
core: utils: http: parse BigInt values directly from JSON source
Browse files Browse the repository at this point in the history
  • Loading branch information
akirillo committed Oct 22, 2024
1 parent 2ddd805 commit ea540af
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/core/src/utils/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down

0 comments on commit ea540af

Please sign in to comment.