Skip to content

Commit e906dc5

Browse files
committed
fix: mobile
1 parent 66db2c1 commit e906dc5

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

src/components/Header/MobileGasPriceViewer.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const MotionBox = motion(Box)
1616

1717
const MobileGasPriceViewer = props => {
1818
const { dark } = props
19-
const { chainId } = useRainbowContext()
19+
const { chainId, walletCurrentAddress, connect } = useRainbowContext()
2020

2121
const gasPriceRef = useRef<HTMLDivElement>(null)
2222

@@ -47,6 +47,28 @@ const MobileGasPriceViewer = props => {
4747
return "-"
4848
}, [ethereumGasPrice])
4949

50+
const actionData = useMemo(() => {
51+
if (!walletCurrentAddress) {
52+
return {
53+
label: "Connect wallet to add Scroll",
54+
onClick: connect,
55+
}
56+
} else if (chainId === CHAIN_ID.L2) {
57+
return {
58+
label: "Add Scroll to wallet",
59+
onClick: () => {
60+
setwarningVisible(true)
61+
},
62+
}
63+
}
64+
return {
65+
label: "Add Scroll to wallet",
66+
onClick: async () => {
67+
await switchNetwork(CHAIN_ID.L2)
68+
},
69+
}
70+
}, [chainId, walletCurrentAddress])
71+
5072
useEffect(() => {
5173
const width = gasPriceRef.current?.offsetWidth
5274
setGasPriceWidth(width ?? 0)
@@ -56,14 +78,6 @@ const MobileGasPriceViewer = props => {
5678
setGasPricePanelVisible(!gasPricePanelVisible)
5779
}
5880

59-
const handleAddScrollToWallet = async () => {
60-
if (chainId === CHAIN_ID.L2) {
61-
setwarningVisible(true)
62-
} else {
63-
await switchNetwork(CHAIN_ID.L2)
64-
}
65-
}
66-
6781
const handleCloseWarning = () => {
6882
setwarningVisible(false)
6983
}
@@ -182,9 +196,9 @@ const MobileGasPriceViewer = props => {
182196
p: "0.8rem 2.4rem",
183197
height: "4rem",
184198
}}
185-
onClick={handleAddScrollToWallet}
199+
onClick={actionData.onClick}
186200
>
187-
Add Scroll to Wallet
201+
{actionData.label}
188202
</Button>
189203
</Box>
190204
</Collapse>

0 commit comments

Comments
 (0)