Skip to content

Commit

Permalink
Use Big.js to safely wrap asset quantities
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Dec 6, 2024
1 parent d035664 commit cc736a7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/components/elements/asset.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { cn } from '$lib/utils';
import type { UnicoveContext } from '$lib/state/client.svelte';
import { getContext } from 'svelte';
import Big from 'big.js';
const context = getContext<UnicoveContext>('state');
Expand Down Expand Up @@ -34,7 +35,10 @@
};
function formatAssetValue() {
return Intl.NumberFormat(locale, assetOptions).format(asset?.value || fallback);
// Use Big.js to accurately convert the string into a usable number
// Some precision may be lost in extreme circumstances
const number = Number(new Big(asset?.quantity || fallback));
return Intl.NumberFormat(locale, assetOptions).format(number);
}
function formatCurrencyValue() {
Expand Down

0 comments on commit cc736a7

Please sign in to comment.