Skip to content

Commit

Permalink
[Explorer] Fix parsing for null values (MystenLabs#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
666lcz authored Jun 21, 2022
1 parent 7927372 commit ff39738
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ function LatestTxCardAPI({ count }: { count: number }) {
loadState: 'fail',
});
setIsLoaded(false);
console.error(
'Encountered error when fetching recent transactions',
err
);
});

return () => {
Expand Down
24 changes: 14 additions & 10 deletions sdk/typescript/src/rpc/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ff39738

Please sign in to comment.