Skip to content

Commit

Permalink
Avoid an error with long-decimal token prices
Browse files Browse the repository at this point in the history
When an Ethereum token price has more decimals than the fiatDecimals,
BigInt would receive a floating-point number and error out; this commit
adds a call to Math.trunc to truncate further precision (not round!).
  • Loading branch information
Shadowfiend committed Oct 13, 2021
1 parent 0df26e3 commit 91561bd
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion background/lib/prices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export async function getEthereumTokenPrices(
symbol: currencySymbol.toUpperCase(),
decimals: fiatDecimals,
},
amount: BigInt(price * 10 ** fiatDecimals),
amount: BigInt(Math.trunc(price * 10 ** fiatDecimals)),
},
time: priceDetails.last_updated_at,
}
Expand Down

0 comments on commit 91561bd

Please sign in to comment.