diff options
Diffstat (limited to 'client/src/components/DisconnectWallet.tsx')
-rw-r--r-- | client/src/components/DisconnectWallet.tsx | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/client/src/components/DisconnectWallet.tsx b/client/src/components/DisconnectWallet.tsx new file mode 100644 index 0000000..45e6643 --- /dev/null +++ b/client/src/components/DisconnectWallet.tsx @@ -0,0 +1,50 @@ +import React, { Dispatch, SetStateAction } from "react"; +import { BeaconWallet } from "@taquito/beacon-wallet"; +import { TezosToolkit } from "@taquito/taquito"; + +interface ButtonProps { + wallet: BeaconWallet | null; + setPublicToken: Dispatch<SetStateAction<string | null>>; + setUserAddress: Dispatch<SetStateAction<string>>; + setUserBalance: Dispatch<SetStateAction<number>>; + setWallet: Dispatch<SetStateAction<any>>; + setTezos: Dispatch<SetStateAction<TezosToolkit>>; + setBeaconConnection: Dispatch<SetStateAction<boolean>>; +} + +const DisconnectButton = ({ + wallet, + setPublicToken, + setUserAddress, + setUserBalance, + setWallet, + setTezos, + setBeaconConnection +}: ButtonProps): JSX.Element => { + const disconnectWallet = async (): Promise<void> => { + //window.localStorage.clear(); + setUserAddress(""); + setUserBalance(0); + setWallet(null); + const tezosTK = new TezosToolkit("https://api.tez.ie/rpc/granadanet"); + setTezos(tezosTK); + setBeaconConnection(false); + setPublicToken(null); + console.log("disconnecting wallet"); + if (wallet) { + await wallet.client.removeAllAccounts(); + await wallet.client.removeAllPeers(); + await wallet.client.destroy(); + } + }; + + return ( + <div className="buttons"> + <button className="button" onClick={disconnectWallet}> + <i className="fas fa-times"></i> Disconnect wallet + </button> + </div> + ); +}; + +export default DisconnectButton; |