@@ -4,7 +4,6 @@ import { useDispatch } from "@/hooks/useTypedDispatch";
4
4
import { useMultiSelector } from "@/hooks/useTypedSelector" ;
5
5
import { IRootState } from "@/store" ;
6
6
import { clearCurrentWallet } from "@/store/feature/user/wallets.slice" ;
7
- import { connectWallet , disconnectWallet } from "@/store/feature/wallet.slice" ;
8
7
import { fetchAllWallets , updateWallet } from "@/store/services/wallets.service" ;
9
8
import { CustomError } from "@/types/error" ;
10
9
import { Wallet } from "@/types/wallet" ;
@@ -13,7 +12,7 @@ import { ReactElement, useEffect, useMemo, useState } from "react";
13
12
import WalletAddressChangeForm from "./_partials/Form" ;
14
13
import { WalletInfo } from "./_partials/Info" ;
15
14
import SelectWalletConnectionMethod from "./_partials/SelectConnectionMethod" ;
16
-
15
+ import useWalletConnect from "@/hooks/useWalletConnect" ;
17
16
18
17
/**
19
18
* Interface for the edit profile props
@@ -46,7 +45,7 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
46
45
const [ showWalletConnectionMethod , setShowWalletConnectionMethod ] = useState ( false ) ;
47
46
const [ connectionMethod , setConnectionMethod ] = useState ( "" ) ;
48
47
49
-
48
+ const { openWeb3Modal , isConnected , disconnectWallet } = useWalletConnect ( ) ;
50
49
const dispatch = useDispatch ( ) ;
51
50
52
51
const closeModal = ( ) => {
@@ -91,12 +90,12 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
91
90
} ;
92
91
93
92
const disconnect = async ( ) => {
94
- await dispatch ( disconnectWallet ( ) ) ;
93
+ await disconnectWallet ( ) ;
95
94
} ;
96
95
97
96
const connect = async ( ) => {
98
97
try {
99
- await dispatch ( connectWallet ( ) ) ;
98
+ isConnected ? disconnect ( ) : openWeb3Modal ( ) ;
100
99
setShowEditAddress ( true ) ;
101
100
} catch ( e ) {
102
101
console . log ( e ) ;
@@ -137,7 +136,6 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
137
136
return wallets ?. require_wallet_connection || false ;
138
137
} , [ wallets ?. require_wallet_connection ] ) ;
139
138
140
-
141
139
const isWalletConnected = useMemo ( ( ) => {
142
140
return requireWalletConnection && ! ! wallet ?. address ;
143
141
} , [ requireWalletConnection , wallet ?. address ] ) ;
@@ -146,26 +144,32 @@ export default function EditProfile({ show, wallet, onClose }: EditProfileProps)
146
144
return Boolean ( showEditAddress && ! showWalletConnectionMethod && connectionMethod ) ;
147
145
} , [ connectionMethod , showEditAddress , showWalletConnectionMethod ] ) ;
148
146
149
-
150
147
useEffect ( ( ) => {
151
148
if ( ! currentAddress ) {
152
- setShowWalletConnectionMethod ( true ) ;
149
+ setShowWalletConnectionMethod ( true ) ;
153
150
}
154
151
} , [ currentAddress ] ) ;
155
152
156
-
157
153
return (
158
154
< Modal show = { show } onClose = { closeModal } >
159
155
< div className = "px-6" >
160
156
< WalletHeader wallet = { wallet } />
161
157
{ showWalletConnectionMethod && < SelectWalletConnectionMethod enableWalletConnection = { requireWalletConnection } onSelect = { setWalletConnectionMethod } /> }
162
158
163
- { ! showWalletConnectionMethod && (
164
- < WalletInfo address = { currentAddress } connectionMethod = { connectionMethod } onClick = { openEditAddress } />
165
- ) }
166
-
159
+ { ! showWalletConnectionMethod && < WalletInfo address = { currentAddress } connectionMethod = { connectionMethod } onClick = { openEditAddress } /> }
167
160
</ div >
168
- < WalletAddressChangeForm show = { showForm } onSave = { onSave } currentAddress = { currentAddress } loading = { loading } error = { error } token = { wallet ?. token } connectionMethod = { connectionMethod } closeModal = { closeModal } clearError = { ( ) => setError ( null ) } />
161
+ < WalletAddressChangeForm
162
+ show = { showForm }
163
+ onSave = { onSave }
164
+ currentAddress = { currentAddress }
165
+ loading = { loading }
166
+ error = { error }
167
+ token = { wallet ?. token }
168
+ connectionMethod = { connectionMethod }
169
+ closeModal = { closeModal }
170
+ clearError = { ( ) => setError ( null ) }
171
+ openEditAddress = { openEditAddress }
172
+ />
169
173
</ Modal >
170
174
) ;
171
175
}
0 commit comments