Skip to content

Commit aaaeac6

Browse files
committed
set LUX as initial network
1 parent c3596d7 commit aaaeac6

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

src/components/NavBar/ChainSelector.tsx

+26-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { TokenWarningRedIcon } from 'nft/components/icons'
1111
import { subhead } from 'nft/css/common.css'
1212
import { themeVars } from 'nft/css/sprinkles.css'
1313
import { useIsMobile } from 'nft/hooks'
14-
import { useCallback, useRef, useState } from 'react'
14+
import { useCallback, useRef, useState, useEffect } from 'react'
1515
import { ChevronDown, ChevronUp } from 'react-feather'
1616
import { useTheme } from 'styled-components/macro'
1717

@@ -20,20 +20,21 @@ import ChainSelectorRow from './ChainSelectorRow'
2020
import { NavDropdown } from './NavDropdown'
2121

2222
const NETWORK_SELECTOR_CHAINS = [
23+
SupportedChainId.LUX,
2324
SupportedChainId.MAINNET,
2425
SupportedChainId.POLYGON,
2526
SupportedChainId.OPTIMISM,
2627
SupportedChainId.ARBITRUM_ONE,
2728
SupportedChainId.CELO,
28-
SupportedChainId.LUX,
2929
]
3030

3131
interface ChainSelectorProps {
3232
leftAlign?: boolean
3333
}
3434

3535
export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
36-
const { chainId } = useWeb3React()
36+
const { account, chainId, connector } = useWeb3React()
37+
3738
const [isOpen, setIsOpen] = useState<boolean>(false)
3839
const isMobile = useIsMobile()
3940

@@ -49,6 +50,10 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
4950
useSyncChainQuery()
5051

5152
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)
5257

5358
const onSelectChain = useCallback(
5459
async (targetChainId: SupportedChainId) => {
@@ -60,6 +65,23 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
6065
[selectChain, setIsOpen]
6166
)
6267

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+
6385
if (!chainId) {
6486
return null
6587
}
@@ -73,6 +95,7 @@ export const ChainSelector = ({ leftAlign }: ChainSelectorProps) => {
7395
<ChainSelectorRow
7496
onSelectChain={onSelectChain}
7597
targetChain={chainId}
98+
setLastchainId={setlastchainId}
7699
key={chainId}
77100
isPending={chainId === pendingChainId}
78101
/>

src/components/NavBar/ChainSelectorRow.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ const Logo = styled.img`
6363
export default function ChainSelectorRow({
6464
targetChain,
6565
onSelectChain,
66+
setLastchainId,
6667
isPending,
6768
}: {
6869
targetChain: SupportedChainId
6970
onSelectChain: (targetChain: number) => void
71+
setLastchainId: React.Dispatch<React.SetStateAction<SupportedChainId | undefined>>
7072
isPending: boolean
7173
}) {
7274
const { chainId } = useWeb3React()
@@ -76,7 +78,7 @@ export default function ChainSelectorRow({
7678
const theme = useTheme()
7779

7880
return (
79-
<Container onClick={() => onSelectChain(targetChain)} data-testid={`chain-selector-option-${label.toLowerCase()}`}>
81+
<Container onClick={() => {setLastchainId(targetChain); onSelectChain(targetChain); }} data-testid={`chain-selector-option-${label.toLowerCase()}`}>
8082
<Logo src={logoUrl} alt={label} />
8183
<Label>{label}</Label>
8284
{isPending && <ApproveText>Approve in wallet</ApproveText>}

src/constants/chains.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* List of all the networks supported by the LX Interface
33
*/
44
export enum SupportedChainId {
5+
LUX = 7777,
6+
57
MAINNET = 1,
68
ROPSTEN = 3,
79
RINKEBY = 4,
@@ -19,8 +21,6 @@ export enum SupportedChainId {
1921

2022
CELO = 42220,
2123
CELO_ALFAJORES = 44787,
22-
23-
LUX = 7777,
2424
}
2525

2626
export const CHAIN_IDS_TO_NAMES = {

0 commit comments

Comments
 (0)