From ff39738ef4bb13828d51929398205fe2b361cb4f Mon Sep 17 00:00:00 2001 From: Chris Li <76067158+666lcz@users.noreply.github.com> Date: Tue, 21 Jun 2022 15:05:22 -0700 Subject: [PATCH] [Explorer] Fix parsing for null values (#2644) --- .../transaction-card/RecentTxCard.tsx | 4 ++++ sdk/typescript/src/rpc/client.ts | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/explorer/client/src/components/transaction-card/RecentTxCard.tsx b/explorer/client/src/components/transaction-card/RecentTxCard.tsx index f0d1f3ac28dfd..91915cacd2a8f 100644 --- a/explorer/client/src/components/transaction-card/RecentTxCard.tsx +++ b/explorer/client/src/components/transaction-card/RecentTxCard.tsx @@ -220,6 +220,10 @@ function LatestTxCardAPI({ count }: { count: number }) { loadState: 'fail', }); setIsLoaded(false); + console.error( + 'Encountered error when fetching recent transactions', + err + ); }); return () => { diff --git a/sdk/typescript/src/rpc/client.ts b/sdk/typescript/src/rpc/client.ts index b595e3debf0bd..be921c0d2c221 100644 --- a/sdk/typescript/src/rpc/client.ts +++ b/sdk/typescript/src/rpc/client.ts @@ -46,16 +46,20 @@ export class JsonRpcClient { try { let res: Response = await fetch(url, options); const text = await res.text(); - const result = JSON.stringify(LosslessJSON.parse(text, (key : string, value : any) => { - if (key === "balance") return value.toString(); - try { - if (value.isLosslessNumber) return value.valueOf(); - } catch { - return value.toString(); - } - return value; - } - )); + const result = JSON.stringify( + LosslessJSON.parse(text, (key: string, value: any) => { + if (value == null) { + return value; + } + if (key === 'balance') return value.toString(); + try { + if (value.isLosslessNumber) return value.valueOf(); + } catch { + return value.toString(); + } + return value; + }) + ); if (res.ok) { callback(null, result); } else {