Skip to content

Commit 8b50d04

Browse files
committed
fix: erc20 bridge switch network to RSK on close
1 parent 2021d0b commit 8b50d04

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

apps/frontend/src/app/3_organisms/ERC20BridgeDialog/ERC20BridgeDialog.tsx

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ import {
1515
VerticalTabs,
1616
} from '@sovryn/ui';
1717

18+
import { RSK_CHAIN_ID } from '../../../config/chains';
19+
1820
import { MobileCloseButton } from '../../1_atoms/MobileCloseButton/MobileCloseButton';
1921
import { useAccount } from '../../../hooks/useAccount';
22+
import { useChainStore } from '../../../hooks/useChainStore';
2023
import { useIsMobile } from '../../../hooks/useIsMobile';
2124
import { translations } from '../../../locales/i18n';
2225
import { ACTIVE_CLASSNAME, queryClient } from './ERC20BridgeDialog.constants';
@@ -41,6 +44,15 @@ export const ERC20BridgeDialog: React.FC<ERC20BridgeDialogProps> = ({
4144
const [index, setIndex] = useState(step);
4245
const { account } = useAccount();
4346
const { isMobile } = useIsMobile();
47+
const { currentChainId, setCurrentChainId } = useChainStore();
48+
const isWrongChain = RSK_CHAIN_ID !== currentChainId;
49+
50+
const handleClose = useCallback(() => {
51+
if (isWrongChain) {
52+
setCurrentChainId(RSK_CHAIN_ID);
53+
}
54+
onClose();
55+
}, [onClose, isWrongChain, setCurrentChainId]);
4456

4557
useEffect(() => {
4658
setIndex(step);
@@ -53,8 +65,8 @@ export const ERC20BridgeDialog: React.FC<ERC20BridgeDialogProps> = ({
5365
infoText: t(translation.tabs.receiveInfoText),
5466
content: (
5567
<ReceiveFlowContextProvider>
56-
<ReceiveFlow onClose={onClose} />
57-
<MobileCloseButton onClick={onClose} />
68+
<ReceiveFlow onClose={handleClose} />
69+
<MobileCloseButton onClick={handleClose} />
5870
</ReceiveFlowContextProvider>
5971
),
6072
activeClassName: ACTIVE_CLASSNAME,
@@ -65,15 +77,15 @@ export const ERC20BridgeDialog: React.FC<ERC20BridgeDialogProps> = ({
6577
infoText: t(translation.tabs.sendInfoText),
6678
content: (
6779
<SendFlowContextProvider>
68-
<SendFlow onClose={onClose} />
69-
<MobileCloseButton onClick={onClose} />
80+
<SendFlow onClose={handleClose} />
81+
<MobileCloseButton onClick={handleClose} />
7082
</SendFlowContextProvider>
7183
),
7284
activeClassName: ACTIVE_CLASSNAME,
7385
dataAttribute: 'erc20-bridge-send',
7486
},
7587
];
76-
}, [onClose]);
88+
}, [handleClose]);
7789

7890
const onChangeIndex = useCallback((index: number | null) => {
7991
index !== null ? setIndex(index) : setIndex(0);
@@ -124,7 +136,7 @@ export const ERC20BridgeDialog: React.FC<ERC20BridgeDialogProps> = ({
124136
footer={() => (
125137
<Button
126138
text={t(translations.common.buttons.close)}
127-
onClick={onClose}
139+
onClick={handleClose}
128140
style={ButtonStyle.ghost}
129141
dataAttribute="erc20-bridge-close"
130142
/>

0 commit comments

Comments
 (0)