@@ -11,7 +11,7 @@ import { TokenWarningRedIcon } from 'nft/components/icons'
11
11
import { subhead } from 'nft/css/common.css'
12
12
import { themeVars } from 'nft/css/sprinkles.css'
13
13
import { useIsMobile } from 'nft/hooks'
14
- import { useCallback , useRef , useState } from 'react'
14
+ import { useCallback , useRef , useState , useEffect } from 'react'
15
15
import { ChevronDown , ChevronUp } from 'react-feather'
16
16
import { useTheme } from 'styled-components/macro'
17
17
@@ -20,20 +20,21 @@ import ChainSelectorRow from './ChainSelectorRow'
20
20
import { NavDropdown } from './NavDropdown'
21
21
22
22
const NETWORK_SELECTOR_CHAINS = [
23
+ SupportedChainId . LUX ,
23
24
SupportedChainId . MAINNET ,
24
25
SupportedChainId . POLYGON ,
25
26
SupportedChainId . OPTIMISM ,
26
27
SupportedChainId . ARBITRUM_ONE ,
27
28
SupportedChainId . CELO ,
28
- SupportedChainId . LUX ,
29
29
]
30
30
31
31
interface ChainSelectorProps {
32
32
leftAlign ?: boolean
33
33
}
34
34
35
35
export const ChainSelector = ( { leftAlign } : ChainSelectorProps ) => {
36
- const { chainId } = useWeb3React ( )
36
+ const { account, chainId, connector } = useWeb3React ( )
37
+
37
38
const [ isOpen , setIsOpen ] = useState < boolean > ( false )
38
39
const isMobile = useIsMobile ( )
39
40
@@ -49,6 +50,10 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
49
50
useSyncChainQuery ( )
50
51
51
52
const [ pendingChainId , setPendingChainId ] = useState < SupportedChainId | undefined > ( undefined )
53
+ const [ lastchainId , setlastchainId ] = useState < SupportedChainId | undefined > ( undefined )
54
+ const [ lastAccount , setLastAccount ] = useState < string | undefined > ( undefined )
55
+ const [ lastRequesting , setLastRequesting ] = useState < boolean > ( false )
56
+ const [ netChangeRequesting , setNetChangeRequesting ] = useState < boolean > ( false )
52
57
53
58
const onSelectChain = useCallback (
54
59
async ( targetChainId : SupportedChainId ) => {
@@ -60,6 +65,23 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
60
65
[ selectChain , setIsOpen ]
61
66
)
62
67
68
+ useEffect ( ( ) => {
69
+
70
+ if ( chainId == 1 && ! lastRequesting ) {
71
+ setLastRequesting ( true ) ;
72
+ onSelectChain ( SupportedChainId . LUX ) ;
73
+ }
74
+ else if ( lastchainId && lastchainId != chainId && ! lastAccount && account && account != lastAccount ) {
75
+ if ( ! netChangeRequesting ) {
76
+ setNetChangeRequesting ( true ) ;
77
+ onSelectChain ( lastchainId ) . finally ( ( ) => {
78
+ setNetChangeRequesting ( false ) ;
79
+ } )
80
+ }
81
+ }
82
+ setLastAccount ( account ) ;
83
+ } , [ chainId , account , lastchainId ] ) ;
84
+
63
85
if ( ! chainId ) {
64
86
return null
65
87
}
@@ -73,6 +95,7 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
73
95
< ChainSelectorRow
74
96
onSelectChain = { onSelectChain }
75
97
targetChain = { chainId }
98
+ setLastchainId = { setlastchainId }
76
99
key = { chainId }
77
100
isPending = { chainId === pendingChainId }
78
101
/>
0 commit comments