Skip to content

Commit

Permalink
fix: insufficient gas message
Browse files Browse the repository at this point in the history
  • Loading branch information
chybisov committed Jul 18, 2022
1 parent 2adea9a commit 0b24868
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions packages/widget/src/hooks/useHasSufficientBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/widget/src/pages/SwapPage/SwapPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const SwapPage: React.FC = () => {
) : null}
</Fragment>
))}
<InsufficientGasOrFundsMessage mt={2} />
{status === 'idle' ? <InsufficientGasOrFundsMessage mt={2} /> : null}
{status === 'idle' || status === 'error' ? (
<Box mt={2}>
<SwapButton onClick={handleSwapClick} text={getSwapButtonText()} />
Expand Down

0 comments on commit 0b24868

Please sign in to comment.