From 545d717b8bdadeb9019853e534565f7e2eee6788 Mon Sep 17 00:00:00 2001 From: benthecarman Date: Wed, 5 Jun 2024 18:39:56 -0500 Subject: [PATCH] Immediately timestamp double init defense --- src/logic/mutinyWalletSetup.ts | 14 ++++++++++---- src/state/megaStore.tsx | 6 ------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/logic/mutinyWalletSetup.ts b/src/logic/mutinyWalletSetup.ts index ff595329..fbaf3523 100644 --- a/src/logic/mutinyWalletSetup.ts +++ b/src/logic/mutinyWalletSetup.ts @@ -180,13 +180,19 @@ export async function doubleInitDefense() { // Ultimate defense against getting multiple instances of the wallet running. // If we detect that the wallet has already been initialized in this session, we'll reload the page. // A successful stop of the wallet in onCleanup will clear this flag - if (sessionStorage.getItem("MUTINY_WALLET_INITIALIZED")) { + const init = sessionStorage.getItem("MUTINY_WALLET_INITIALIZED"); + if (init) { + const diff = Date.now() - Number(init); console.error( - `Mutiny Wallet already initialized at ${sessionStorage.getItem( - "MUTINY_WALLET_INITIALIZED" - )}. Reloading page.` + `Mutiny Wallet already initialized at ${init}, ${diff}ms ago. Reloading page.` ); sessionStorage.removeItem("MUTINY_WALLET_INITIALIZED"); window.location.reload(); + } else { + // Timestamp our initialization for double init defense + sessionStorage.setItem( + "MUTINY_WALLET_INITIALIZED", + Date.now().toString() + ); } } diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index a6b7b234..41a0bcdb 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -263,12 +263,6 @@ export const makeMegaStoreContext = () => { expiration_warning }); - // Timestamp our initialization for double init defense - sessionStorage.setItem( - "MUTINY_WALLET_INITIALIZED", - Date.now().toString() - ); - console.log("Wallet initialized"); await actions.postSetup();