@@ -15,8 +15,11 @@ import {
1515 VerticalTabs ,
1616} from '@sovryn/ui' ;
1717
18+ import { RSK_CHAIN_ID } from '../../../config/chains' ;
19+
1820import { MobileCloseButton } from '../../1_atoms/MobileCloseButton/MobileCloseButton' ;
1921import { useAccount } from '../../../hooks/useAccount' ;
22+ import { useChainStore } from '../../../hooks/useChainStore' ;
2023import { useIsMobile } from '../../../hooks/useIsMobile' ;
2124import { translations } from '../../../locales/i18n' ;
2225import { 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