From 6ade2e052b9fe3c4860d58a2d6f06ca3e3b1d270 Mon Sep 17 00:00:00 2001 From: PhiMarHal Date: Mon, 2 Dec 2024 13:23:50 +0100 Subject: [PATCH] disconnect wallet --- app.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index 3f40bb0..2eb4d42 100644 --- a/app.js +++ b/app.js @@ -845,14 +845,26 @@ async function updateWalletDisplay() { walletInfo.innerHTML = ` ${displayText} `; - // Add click handler for copying + // Get the span element const addressSpan = walletInfo.querySelector('.wallet-address'); + + // Left click to disconnect addressSpan.addEventListener('click', async () => { + userAddress = null; + signer = null; + contract = new ethers.Contract(CONFIG.CONTRACT_ADDRESS, CONFIG.CONTRACT_ABI, provider); + await updateWalletDisplay(); + showStatus('Wallet disconnected', 'success'); + }); + + // Right click to copy address + addressSpan.addEventListener('contextmenu', async (e) => { + e.preventDefault(); // Prevent the context menu from appearing try { await navigator.clipboard.writeText(userAddress); showStatus('Address copied to clipboard!', 'success'); @@ -865,8 +877,8 @@ async function updateWalletDisplay() { console.error('Error fetching user info:', error); walletInfo.innerHTML = ` ${userAddress.slice(0, 6)}...${userAddress.slice(-4)} `; }