Skip to content

Commit

Permalink
timeout if load fails
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul authored and TonyGiorgio committed Apr 18, 2024
1 parent 713c1a6 commit 33ffdd3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/logic/mutinyWalletSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export async function setupMutinyWallet(
password?: string,
safeMode?: boolean,
shouldZapHodl?: boolean
): Promise<MutinyWallet> {
): Promise<MutinyWallet | undefined> {
console.log("Starting setup...");

// https://developer.mozilla.org/en-US/docs/Web/API/Storage_API
Expand Down Expand Up @@ -350,5 +350,9 @@ export async function setupMutinyWallet(

sessionStorage.setItem("MUTINY_WALLET_INITIALIZED", Date.now().toString());

return mutinyWallet;
if (mutinyWallet) {
return mutinyWallet;
} else {
return undefined;
}
}
30 changes: 30 additions & 0 deletions src/state/megaStore.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -204,13 +204,43 @@ export const Provider: ParentComponent = (props) => {
await setSettings(settings);
}

// 60 seconds to load or we bail
const start = Date.now();
const MAX_LOAD_TIME = 60000;
const interval = setInterval(() => {
console.log("Running setup", Date.now() - start);
if (Date.now() - start > MAX_LOAD_TIME) {
clearInterval(interval);
// Have to set state error here because throwing doesn't work if WASM panics
setState({
setup_error: new Error(
"Load timed out, please try again"
)
});
return;
}
}, 1000);

const mutinyWallet = await setupMutinyWallet(
settings,
password,
state.safe_mode,
state.should_zap_hodl
);

// Done with the timeout shenanigans
clearInterval(interval);

// I've never managed to trigger this but it's just some extra safety I guess
if (!mutinyWallet) {
setState({
setup_error: new Error(
"Failed to initialize Mutiny Wallet"
)
});
return;
}

// Give other components access to settings via the store
setState({ settings: settings });

Expand Down

0 comments on commit 33ffdd3

Please sign in to comment.