From 89bf9afba8ef8e820fcfbe8996c4f749326b166c Mon Sep 17 00:00:00 2001 From: Ruben Marcus Date: Tue, 22 Aug 2023 02:55:31 +0100 Subject: [PATCH] last try --- packages/wallet/src/wallet.ts | 42 +++++++++++++++-------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/packages/wallet/src/wallet.ts b/packages/wallet/src/wallet.ts index a34f1003f..dda1d62b4 100644 --- a/packages/wallet/src/wallet.ts +++ b/packages/wallet/src/wallet.ts @@ -273,11 +273,11 @@ export class MintbaseWallet { justify-content: center; align-items: center; height: 100vh; - position:fixed - top:0px - left:0px - width:100vw - background:#fff + position:fixed; + top:0px; + left:0px; + width:100vw; + background:#fff; } .lds-ellipsis { @@ -353,6 +353,8 @@ export class MintbaseWallet { this.injectKeyframeAnimations(); this.showLoadingAnimation(); + + function forceRefresh() { // Append a timestamp or random value as a query parameter to the URL const currentUrl = new URL(window.location.href); @@ -362,26 +364,18 @@ export class MintbaseWallet { window.location.href = currentUrl.toString(); } - const currentUrl = new URL(window.location.href); - currentUrl.searchParams.delete('account_id'); - currentUrl.searchParams.delete('public_key'); - - window.history.replaceState({}, document.title, currentUrl.toString()); - - // Listen for changes to the localStorage value - const storageEventListener = (event: StorageEvent) => { - if (event.key === 'mintbasewallet:account-data') { - window.removeEventListener('storage', storageEventListener); - this.hideLoadingAnimation(); - if (!this.reloaded) { - this.reloaded = true; - forceRefresh(); - } - } - }; + // Check if account data is already set in localStorage + const accountData = window.localStorage.getItem('mintbasewallet:account-data'); + if (accountData && !this.reloaded) { + this.reloaded = true; // Set the flag + + this.hideLoadingAnimation(); + + + forceRefresh(); // Trigger a single forced refresh + } - // Add the storage event listener - window.addEventListener('storage', storageEventListener); + } private reloaded = false;