Skip to content
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit c7ca57a

Browse files
BrianBrian
authored andcommitted
Added ability to disconnect wallet
1 parent 28e6a50 commit c7ca57a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

frontend/public/locales/en/common.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,6 @@
4141
"userCancelTransaction": "Transaction Cancelled by User",
4242
"transactionSending": "Transaction Being Sent",
4343
"here": "here",
44-
"errorMinting": "Unable to Mint NFT"
44+
"errorMinting": "Unable to Mint NFT",
45+
"disconnectWallet": "Disconnect Wallet"
4546
}

frontend/src/components/DirectMint/DirectMint.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, {
44
useState,
55
useEffect,
66
} from 'react';
7-
import { useToast, Button, Input, Stack } from '@chakra-ui/react';
7+
import { useToast, Button, Input, Text } from '@chakra-ui/react';
88
import { ethers } from 'ethers';
99
import WalletConnectProvider from '@walletconnect/web3-provider';
1010
import Web3Modal from 'web3modal';
@@ -34,7 +34,6 @@ const providerOptions = {
3434
};
3535

3636
const DirectMint = ({ developerId }: DirectMintProps) => {
37-
console.log(process.env.NEXT_PUBLIC_INFURA_ID);
3837
const { t } = useTranslation();
3938
const [userWallet, setUserWallet] = useState('');
4039
const [tokenID, setTokenID] = useState(developerId ? developerId : '');
@@ -100,9 +99,19 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
10099
fetchAccountData();
101100
});
102101

102+
_provider.on('disconnect', (error: { code: number; message: string }) => {
103+
web3Modal?.clearCachedProvider();
104+
setUserWallet('');
105+
});
106+
103107
await fetchAccountData();
104108
};
105109

110+
const disconnectWallet = async () => {
111+
await web3Modal?.clearCachedProvider();
112+
setUserWallet('');
113+
};
114+
106115
const tokenNameHandler: ChangeEventHandler<HTMLInputElement> = (event) => {
107116
setTokenID(event.target.value);
108117
};
@@ -188,9 +197,19 @@ const DirectMint = ({ developerId }: DirectMintProps) => {
188197
{t('mintTokenText')}
189198
</Button>
190199

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>
193210
)}
211+
212+
{networkError && <Text color="red">{t('ethereumNetworkPrompt')}</Text>}
194213
</>
195214
);
196215
};

0 commit comments

Comments
 (0)