Skip to content

Commit

Permalink
fix some flakiness
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Jun 6, 2024
1 parent a8bb8a1 commit 735e74a
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/__swaps__/utils/swaps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export function valueBasedDecimalFormatter({
}: {
amount: number | string;
usdTokenPrice: number;
assetBalanceDisplay: string;
assetBalanceDisplay?: string;
roundingMode?: 'up' | 'down';
precisionAdjustment?: number;
isStablecoin?: boolean;
Expand Down Expand Up @@ -280,13 +280,16 @@ export function valueBasedDecimalFormatter({
const maximumFractionDigits = () => {
// if we're selling max amount, we want to match what's displayed on the balance badge
// let's base the decimal places based on that (capped at 6)
if (isMaxAmount) {
const [, decimalPlacesFromDisplay] = assetBalanceDisplay.split('.');
if (decimalPlacesFromDisplay.length < 2 && isStablecoin) {
return 2;
if (isMaxAmount && assetBalanceDisplay) {
const decimals = assetBalanceDisplay.split('.');
if (decimals.length > 1) {
const [, decimalPlacesFromDisplay] = decimals;
if (decimalPlacesFromDisplay.length < 2 && isStablecoin) {
return 2;
}

return decimalPlacesFromDisplay.length > 6 ? 6 : decimalPlacesFromDisplay.length;
}

return decimalPlacesFromDisplay.length > 6 ? 6 : decimalPlacesFromDisplay.length;
}

if (!isNaN(decimalPlaces)) {
Expand Down

0 comments on commit 735e74a

Please sign in to comment.