timeout if load fails

This commit is contained in:
Paul Miller
2024-04-18 15:07:51 -05:00
committed by Tony Giorgio
parent 713c1a6be3
commit 33ffdd328c
2 changed files with 36 additions and 2 deletions

View File

@@ -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
@@ -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;
}
}

View File

@@ -204,6 +204,23 @@ 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,
@@ -211,6 +228,19 @@ export const Provider: ParentComponent = (props) => {
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 });