@@ -4,7 +4,7 @@ import React, {
4
4
useState ,
5
5
useEffect ,
6
6
} from 'react' ;
7
- import { useToast , Button , Input , Stack } from '@chakra-ui/react' ;
7
+ import { useToast , Button , Input , Text } from '@chakra-ui/react' ;
8
8
import { ethers } from 'ethers' ;
9
9
import WalletConnectProvider from '@walletconnect/web3-provider' ;
10
10
import Web3Modal from 'web3modal' ;
@@ -34,7 +34,6 @@ const providerOptions = {
34
34
} ;
35
35
36
36
const DirectMint = ( { developerId } : DirectMintProps ) => {
37
- console . log ( process . env . NEXT_PUBLIC_INFURA_ID ) ;
38
37
const { t } = useTranslation ( ) ;
39
38
const [ userWallet , setUserWallet ] = useState ( '' ) ;
40
39
const [ tokenID , setTokenID ] = useState ( developerId ? developerId : '' ) ;
@@ -100,9 +99,19 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
100
99
fetchAccountData ( ) ;
101
100
} ) ;
102
101
102
+ _provider . on ( 'disconnect' , ( error : { code : number ; message : string } ) => {
103
+ web3Modal ?. clearCachedProvider ( ) ;
104
+ setUserWallet ( '' ) ;
105
+ } ) ;
106
+
103
107
await fetchAccountData ( ) ;
104
108
} ;
105
109
110
+ const disconnectWallet = async ( ) => {
111
+ await web3Modal ?. clearCachedProvider ( ) ;
112
+ setUserWallet ( '' ) ;
113
+ } ;
114
+
106
115
const tokenNameHandler : ChangeEventHandler < HTMLInputElement > = ( event ) => {
107
116
setTokenID ( event . target . value ) ;
108
117
} ;
@@ -188,9 +197,19 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
188
197
{ t ( 'mintTokenText' ) }
189
198
</ Button >
190
199
191
- { networkError && (
192
- < p className = "network_error" > { t ( 'EthereumNetworkPrompt' ) } </ p >
200
+ { userWallet && (
201
+ < Button
202
+ w = "100%"
203
+ colorScheme = "orange"
204
+ onClick = { disconnectWallet }
205
+ mt = "10"
206
+ fontSize = { { base : 's' , sm : 'xl' } }
207
+ >
208
+ { t ( 'disconnectWallet' ) }
209
+ </ Button >
193
210
) }
211
+
212
+ { networkError && < Text color = "red" > { t ( 'ethereumNetworkPrompt' ) } </ Text > }
194
213
</ >
195
214
) ;
196
215
} ;
0 commit comments