mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2025-12-17 06:14:21 +01:00
Immediately timestamp double init defense
This commit is contained in:
committed by
Paul Miller
parent
b0986895a5
commit
9324548e0f
@@ -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()
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user