From 5d9ddbc164998aefb7ffd28cf5031a007a5ef166 Mon Sep 17 00:00:00 2001 From: daniel-vahn Date: Tue, 14 May 2024 09:38:07 +0200 Subject: [PATCH] implemented disconnect --- src/App.tsx | 11 ++- .../connectOverlay/ConnectOverlay.tsx | 72 +++++++++++++------ 2 files changed, 59 insertions(+), 24 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 579dae7..57ef361 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -2,6 +2,7 @@ import { useState, useEffect } from 'react'; // import { useTonWallet } from '@tonconnect/ui-react'; import WebApp from '@twa-dev/sdk'; import axios from 'axios'; +import { RootState } from './redux/store'; import Avatar from './components/utils/Avatar'; import BackButton from './components/buttons/BackButton'; @@ -28,6 +29,7 @@ import receiveIcon from './assets/receive_icon.svg'; import sellIcon from './assets/sell_icon.svg'; import { useTonWallet } from '@tonconnect/ui-react'; import WalletConnectModal from './components/connectors/WalletConnectModal'; +import { useSelector } from 'react-redux'; enum View { LANDING = 0, @@ -43,6 +45,11 @@ const BRIDGE_URL = import.meta.env.VITE_BRIDGE_URL || ''; function App() { const [view, setView] = useState(View.LANDING); + // Connection State + const connectionState = useSelector( + (state: RootState) => state.connection.connectionState + ); + const skip = () => { setView(view + 1); }; @@ -203,7 +210,9 @@ function App() {
- {account && } + {connectionState === 'connected' && ( + + )}
diff --git a/src/components/connectOverlay/ConnectOverlay.tsx b/src/components/connectOverlay/ConnectOverlay.tsx index 86f224f..0826aea 100644 --- a/src/components/connectOverlay/ConnectOverlay.tsx +++ b/src/components/connectOverlay/ConnectOverlay.tsx @@ -165,6 +165,16 @@ const ConnectOverlay: React.FC = ({ WebApp.openLink(`https://etherscan.io/address/${account}`); }; + // Handle Disconnect + const handelDisconnect = () => { + window.localStorage.removeItem('providerId'); + window.localStorage.removeItem('walletConnectURI'); + window.localStorage.removeItem('walletProvider'); + window.localStorage.removeItem('walletconnect'); + window.localStorage.removeItem('WALLETCONNECT_DEEPLINK_CHOICE'); + dispatch(setConnectionState('disconnected')); + }; + return (
@@ -296,35 +306,51 @@ const ConnectOverlay: React.FC = ({ )} {connectionState === 'connected' && ( -
-
-
- +
+
+
+
+ +
+ {account &&

{truncateText(account, 8, 8)}

} +
+
+
+ +

+ Copy Address +

+
+
+ +

+ View on explorer +

+
- {account &&

{truncateText(account, 8, 8)}

}
-
-
- -

- Copy Address +

+
+

+ Connected with{' '} + {window.localStorage.getItem('walletProvider')}

- -

- View on explorer -

+

Disconnect