@@ -16,7 +16,7 @@ const MotionBox = motion(Box)
16
16
17
17
const MobileGasPriceViewer = props => {
18
18
const { dark } = props
19
- const { chainId } = useRainbowContext ( )
19
+ const { chainId, walletCurrentAddress , connect } = useRainbowContext ( )
20
20
21
21
const gasPriceRef = useRef < HTMLDivElement > ( null )
22
22
@@ -47,6 +47,28 @@ const MobileGasPriceViewer = props => {
47
47
return "-"
48
48
} , [ ethereumGasPrice ] )
49
49
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
+
50
72
useEffect ( ( ) => {
51
73
const width = gasPriceRef . current ?. offsetWidth
52
74
setGasPriceWidth ( width ?? 0 )
@@ -56,14 +78,6 @@ const MobileGasPriceViewer = props => {
56
78
setGasPricePanelVisible ( ! gasPricePanelVisible )
57
79
}
58
80
59
- const handleAddScrollToWallet = async ( ) => {
60
- if ( chainId === CHAIN_ID . L2 ) {
61
- setwarningVisible ( true )
62
- } else {
63
- await switchNetwork ( CHAIN_ID . L2 )
64
- }
65
- }
66
-
67
81
const handleCloseWarning = ( ) => {
68
82
setwarningVisible ( false )
69
83
}
@@ -182,9 +196,9 @@ const MobileGasPriceViewer = props => {
182
196
p : "0.8rem 2.4rem" ,
183
197
height : "4rem" ,
184
198
} }
185
- onClick = { handleAddScrollToWallet }
199
+ onClick = { actionData . onClick }
186
200
>
187
- Add Scroll to Wallet
201
+ { actionData . label }
188
202
</ Button >
189
203
</ Box >
190
204
</ Collapse >
0 commit comments