diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getFormattedNumber.ts b/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getFormattedNumber.ts index 91dd96f776..b7f83e3300 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getFormattedNumber.ts +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getFormattedNumber.ts @@ -8,9 +8,17 @@ import { DEFAULT_TOKEN_FORMATTING_DECIMALS } from '../../../lib/constants'; * removing trailing zeros */ export const getFormattedAmounts = ( - amount: string | number, + value: string | number, maxDecimals = DEFAULT_TOKEN_FORMATTING_DECIMALS, -) => tokenValueFormat(amount, maxDecimals).replace(/\.?0+$/, ''); +) => { + const amount = typeof value === 'number' ? value : parseFloat(value); + + if (amount > 0 && amount < 1) { + return tokenValueFormat(amount, maxDecimals).replace(/\.?0+$/, ''); + } + + return tokenValueFormat(amount, maxDecimals); +}; /** * Converts a crypto amount to a formatted string diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getRouteAndTokenBalances.ts b/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getRouteAndTokenBalances.ts index 11bc452fa0..0e6fcde7b6 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getRouteAndTokenBalances.ts +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/functions/getRouteAndTokenBalances.ts @@ -20,8 +20,6 @@ export function getRouteAndTokenBalances(routeData?: RouteData): RouteBalance { return emptyRouteBalance; } - const { fromToken } = routeData.amountData; - const usdPrice = routeData?.route.route.estimate.fromToken.usdPrice; if (!usdPrice) { return emptyRouteBalance; @@ -31,8 +29,8 @@ export function getRouteAndTokenBalances(routeData?: RouteData): RouteBalance { const routeBalance = getFormattedNumber( balance.balance, - fromToken?.decimals, - fromToken?.decimals, // preserve precision for usd conversion down below + balance?.decimals, + balance?.decimals, // preserve precision for usd conversion down below ); const routeBalanceUsd = (parseFloat(routeBalance) * usdPrice).toString(); diff --git a/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts b/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts index 25b6d316bd..7a104160f5 100644 --- a/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts +++ b/packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useRoutes.ts @@ -272,13 +272,14 @@ export const useRoutes = () => { }), ); + const sortedRoutes = sortRoutesByFastestTime(allRoutes); + // Only update routes if the request is the latest one if (currentRequestId === latestRequestIdRef.current) { - const sortedRoutes = sortRoutesByFastestTime(allRoutes); setRoutes(sortedRoutes); } - return allRoutes; + return sortedRoutes; }; return {