Move clear interval until after things are setup

This commit is contained in:
benthecarman
2024-06-05 17:17:39 -05:00
committed by Tony Giorgio
parent 152abb0e10
commit 318fa6f353

View File

@@ -163,6 +163,7 @@ export const makeMegaStoreContext = () => {
} }
}, },
async setup(password?: string): Promise<void> { async setup(password?: string): Promise<void> {
let interval: NodeJS.Timeout | undefined;
try { try {
const settings = await getSettings(); const settings = await getSettings();
setState({ load_stage: "setup" }); setState({ load_stage: "setup" });
@@ -179,7 +180,7 @@ export const makeMegaStoreContext = () => {
// 90 seconds to load or we bail // 90 seconds to load or we bail
const start = Date.now(); const start = Date.now();
const MAX_LOAD_TIME = 90000; const MAX_LOAD_TIME = 90000;
const interval = setInterval(() => { interval = setInterval(() => {
console.log("Running setup", Date.now() - start); console.log("Running setup", Date.now() - start);
if (Date.now() - start > MAX_LOAD_TIME) { if (Date.now() - start > MAX_LOAD_TIME) {
clearInterval(interval); clearInterval(interval);
@@ -215,8 +216,6 @@ export const makeMegaStoreContext = () => {
nsec nsec
); );
clearInterval(interval);
if (!success) { if (!success) {
throw new Error("Failed to initialize mutiny wallet"); throw new Error("Failed to initialize mutiny wallet");
} }
@@ -265,8 +264,15 @@ export const makeMegaStoreContext = () => {
console.log("Wallet initialized"); console.log("Wallet initialized");
clearInterval(interval);
await actions.postSetup(); await actions.postSetup();
} catch (e) { } catch (e) {
// clear the interval if it exists
if (interval) {
clearInterval(interval);
}
console.error(e); console.error(e);
if (eify(e).message === "Incorrect password entered.") { if (eify(e).message === "Incorrect password entered.") {
setState({ needs_password: true }); setState({ needs_password: true });