Skip to content

Commit

Permalink
fix magnitude
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobar79 committed Jun 12, 2024
1 parent de50a66 commit 022b705
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/__swaps__/utils/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export function trimTrailingZeros(value: string) {
export function precisionBasedOffMagnitude(amount: number | string, isStablecoin = false): number {
'worklet';

const magnitude = orderOfMagnitudeWorklet(amount);
const magnitude = -orderOfMagnitudeWorklet(amount);
// don't let stablecoins go beneath 2nd order
if (magnitude < -2 && isStablecoin) {
return -STABLECOIN_MINIMUM_SIGNIFICANT_DECIMALS;
Expand Down Expand Up @@ -315,10 +315,11 @@ export function valueBasedDecimalFormatter({
return MAXIMUM_SIGNIFICANT_DECIMALS;
};

const _maximumFractionDigits = maximumFractionDigits();
// Format the number to add separators and trim trailing zeros
const numberFormatter = new Intl.NumberFormat('en-US', {
minimumFractionDigits: isStablecoin ? STABLECOIN_MINIMUM_SIGNIFICANT_DECIMALS : 0,
maximumFractionDigits: maximumFractionDigits(),
maximumFractionDigits: _maximumFractionDigits,
useGrouping: true,
});

Expand Down Expand Up @@ -364,12 +365,13 @@ export function niceIncrementFormatter({
}
if (percentageToSwap === 0.5) {
const amount = mulWorklet(inputAssetBalance, 0.5);
const precisionAdjustment = precisionBasedOffMagnitude(amount, isStablecoin);
return valueBasedDecimalFormatter({
amount,
usdTokenPrice: inputAssetUsdPrice,
assetBalanceDisplay,
roundingMode: 'up',
precisionAdjustment: precisionBasedOffMagnitude(amount, isStablecoin),
precisionAdjustment,
isStablecoin,
});
}
Expand Down

0 comments on commit 022b705

Please sign in to comment.