From cf3c7d6c763ab8f9de89339e6c330bb458e5f4bc Mon Sep 17 00:00:00 2001 From: Eugene Chybisov Date: Sat, 6 Aug 2022 15:27:33 +0100 Subject: [PATCH] fix: switch chain only if route exists --- .../src/components/SwapButton/SwapButton.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/widget/src/components/SwapButton/SwapButton.tsx b/packages/widget/src/components/SwapButton/SwapButton.tsx index 8518e2a5c..d820d7332 100644 --- a/packages/widget/src/components/SwapButton/SwapButton.tsx +++ b/packages/widget/src/components/SwapButton/SwapButton.tsx @@ -28,8 +28,12 @@ export const SwapButton: React.FC = ({ const [chainId] = useWatch({ name: [SwapFormKeyHelper.getChainKey('from')], }); - const isCurrentChainMatch = - getChainById(chainId || ChainId.ETH)?.id === account.chainId; + + // Allow switching chain only if execution is not started + const switchChainAllowed = + getChainById(chainId || ChainId.ETH)?.id !== account.chainId && + currentRoute && + !currentRoute.steps.some((step) => step.execution); const handleSwapButtonClick = async () => { if (!account.isActive) { @@ -38,7 +42,7 @@ export const SwapButton: React.FC = ({ } else { navigate(navigationRoutes.selectWallet); } - } else if (!isCurrentChainMatch) { + } else if (switchChainAllowed) { await switchChain(chainId!); // check that the current route exists in the up to date route list } else { @@ -48,7 +52,7 @@ export const SwapButton: React.FC = ({ const getButtonText = () => { if (account.isActive) { - if (!isCurrentChainMatch) { + if (switchChainAllowed) { return t(`button.switchChain`); } if (!currentRoute) { @@ -68,7 +72,7 @@ export const SwapButton: React.FC = ({ disabled={ (insufficientFunds || !!insufficientGas.length || loading) && currentRoute && - isCurrentChainMatch + !switchChainAllowed } fullWidth >