Immediately timestamp double init defense

This commit is contained in:
benthecarman
2024-06-05 18:39:56 -05:00
committed by Paul Miller
parent b0986895a5
commit 9324548e0f
2 changed files with 10 additions and 10 deletions

View File

@@ -180,13 +180,19 @@ export async function doubleInitDefense() {
// Ultimate defense against getting multiple instances of the wallet running. // 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. // 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 // 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( console.error(
`Mutiny Wallet already initialized at ${sessionStorage.getItem( `Mutiny Wallet already initialized at ${init}, ${diff}ms ago. Reloading page.`
"MUTINY_WALLET_INITIALIZED"
)}. Reloading page.`
); );
sessionStorage.removeItem("MUTINY_WALLET_INITIALIZED"); sessionStorage.removeItem("MUTINY_WALLET_INITIALIZED");
window.location.reload(); window.location.reload();
} else {
// Timestamp our initialization for double init defense
sessionStorage.setItem(
"MUTINY_WALLET_INITIALIZED",
Date.now().toString()
);
} }
} }

View File

@@ -263,12 +263,6 @@ export const makeMegaStoreContext = () => {
expiration_warning expiration_warning
}); });
// Timestamp our initialization for double init defense
sessionStorage.setItem(
"MUTINY_WALLET_INITIALIZED",
Date.now().toString()
);
console.log("Wallet initialized"); console.log("Wallet initialized");
await actions.postSetup(); await actions.postSetup();