Commit 707544e2 authored by girafferz's avatar girafferz Committed by GitHub

fix: correctly handle token.decimals when value is 0 (#2636)

* fix: correctly handle token.decimals when value is 0

Previously, using "Number(data.token.decimals) || 18" caused a valid token.decimals value of 0 to fall back to 18. This commit updates the logic to correctly use 0 when defined, ensuring accurate calculations for tokens with 0 decimals.

* fix: use nullish coalescing for token decimals
parent 165f289b
......@@ -20,7 +20,7 @@ const TokenSelectItem = ({ data }: Props) => {
const secondRow = (() => {
switch (data.token.type) {
case 'ERC-20': {
const tokenDecimals = Number(data.token.decimals) || 18;
const tokenDecimals = Number(data.token.decimals ?? 18);
const text = `${ BigNumber(data.value).dividedBy(10 ** tokenDecimals).dp(8).toFormat() } ${ data.token.symbol || '' }`;
return (
......
......@@ -24,7 +24,7 @@ function getRequestParams(token: TokenInfo, tokenId?: string): WatchAssetParams
options: {
address: token.address,
symbol: token.symbol || '',
decimals: Number(token.decimals) || 18,
decimals: Number(token.decimals ?? '18'),
image: token.icon_url || '',
},
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment