Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Immediately timestamp double init defense #1188

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/logic/mutinyWalletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}
6 changes: 0 additions & 6 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading