From 0b24868a8110f313b5e2d09014ada80846c6aafd Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Mon, 18 Jul 2022 14:50:06 +0100 Subject: [PATCH] fix: insufficient gas message --- packages/widget/src/hooks/useHasSufficientBalance.ts | 10 +++------- packages/widget/src/pages/SwapPage/SwapPage.tsx | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/widget/src/hooks/useHasSufficientBalance.ts b/packages/widget/src/hooks/useHasSufficientBalance.ts index b5d61d535..9893024c9 100644 --- a/packages/widget/src/hooks/useHasSufficientBalance.ts +++ b/packages/widget/src/hooks/useHasSufficientBalance.ts @@ -27,7 +27,7 @@ export const useHasSufficientBalance = () => { const hasGasOnStartChain = useMemo(() => { const gasToken = route?.steps[0].estimate.gasCosts?.[0].token; - if (!account.isActive || !gasToken) { + if (!account.isActive || !gasToken || !fromAmount) { return true; } const gasTokenBalance = Big( @@ -43,16 +43,12 @@ export const useHasSufficientBalance = () => { ) .div(10 ** gasToken.decimals); if (route.fromToken.address === gasToken.address) { - const tokenBalance = Big( - fromChainTokenBalances?.find( - (t) => t.address === route.fromToken.address, - )?.amount ?? 0, - ); - requiredAmount = requiredAmount.plus(tokenBalance); + requiredAmount = requiredAmount.plus(Big(fromAmount)); } return gasTokenBalance.gt(0) && gasTokenBalance.gte(requiredAmount); }, [ account.isActive, + fromAmount, fromChainTokenBalances, route?.fromChainId, route?.fromToken.address, diff --git a/packages/widget/src/pages/SwapPage/SwapPage.tsx b/packages/widget/src/pages/SwapPage/SwapPage.tsx index 82fb18246..7bdf4927d 100644 --- a/packages/widget/src/pages/SwapPage/SwapPage.tsx +++ b/packages/widget/src/pages/SwapPage/SwapPage.tsx @@ -63,7 +63,7 @@ export const SwapPage: React.FC = () => { ) : null} ))} - + {status === 'idle' ? : null} {status === 'idle' || status === 'error' ? (