diff --git a/src/components/DeleteEverything.tsx b/src/components/DeleteEverything.tsx index 86d878c..71a052d 100644 --- a/src/components/DeleteEverything.tsx +++ b/src/components/DeleteEverything.tsx @@ -22,29 +22,7 @@ export function deleteDb(name: string) { } export function DeleteEverything() { - const [_store, actions] = useMegaStore(); - - async function resetNode() { - try { - setConfirmLoading(true); - deleteDb("gossip") - deleteDb("wallet") - localStorage.clear(); - - showToast({ title: "Deleted", description: `Deleted all data` }) - - setTimeout(() => { - window.location.href = "/"; - }, 3000); - } catch (e) { - console.error(e) - showToast(eify(e)) - } finally { - setConfirmOpen(false); - setConfirmLoading(false); - } - - } + const [_state, actions] = useMegaStore(); async function confirmReset() { setConfirmOpen(true); @@ -53,6 +31,25 @@ export function DeleteEverything() { const [confirmOpen, setConfirmOpen] = createSignal(false); const [confirmLoading, setConfirmLoading] = createSignal(false); + + async function resetNode() { + try { + setConfirmLoading(true); + await actions.deleteMutinyWallet(); + showToast({ title: "Deleted", description: `Deleted all data` }) + + setTimeout(() => { + window.location.href = "/"; + }, 1000); + } catch (e) { + console.error(e) + showToast(eify(e)) + } finally { + setConfirmOpen(false); + setConfirmLoading(false); + } + } + return ( <> @@ -61,4 +58,4 @@ export function DeleteEverything() { ) -} \ No newline at end of file +} diff --git a/src/state/megaStore.tsx b/src/state/megaStore.tsx index fc1cc90..cd3c14f 100644 --- a/src/state/megaStore.tsx +++ b/src/state/megaStore.tsx @@ -14,6 +14,7 @@ type UserStatus = undefined | "new_here" | "waitlisted" | "approved" | "paid" export type MegaStore = [{ waitlist_id?: string; mutiny_wallet?: MutinyWallet; + deleting: boolean; user_status: UserStatus; scan_result?: ParsedParams; balance?: MutinyBalance; @@ -25,6 +26,7 @@ export type MegaStore = [{ }, { fetchUserStatus(): Promise; setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise; + deleteMutinyWallet(): Promise; setWaitlistId(waitlist_id: string): void; setScanResult(scan_result: ParsedParams | undefined): void; sync(): Promise; @@ -36,6 +38,7 @@ export const Provider: ParentComponent = (props) => { const [state, setState] = createStore({ waitlist_id: localStorage.getItem("waitlist_id"), mutiny_wallet: undefined as MutinyWallet | undefined, + deleting: false, user_status: undefined as UserStatus, scan_result: undefined as ParsedParams | undefined, // TODO: wire this up to real price once we have caching @@ -74,6 +77,16 @@ export const Provider: ParentComponent = (props) => { console.error(e) } }, + async deleteMutinyWallet(): Promise { + await state.mutiny_wallet?.stop(); + setState((prevState) => ({ + ...prevState, + mutiny_wallet: undefined, + deleting: true, + })); + MutinyWallet.import_json("{}"); + localStorage.clear(); + }, setWaitlistId(waitlist_id: string) { setState({ waitlist_id }) }, @@ -115,7 +128,7 @@ export const Provider: ParentComponent = (props) => { // Only load node manager when status is approved createEffect(() => { - if (state.user_status === "approved" && !state.mutiny_wallet) { + if (state.user_status === "approved" && !state.mutiny_wallet && !state.deleting) { console.log("running setup node manager...") actions.setupMutinyWallet().then(() => console.log("node manager setup done")) } @@ -152,4 +165,4 @@ export function useMegaStore() { throw new Error("useMegaStore: cannot find a MegaStoreContext") } return context; -} \ No newline at end of file +} diff --git a/vite.config.ts b/vite.config.ts index ee8d5c2..565d4aa 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -52,7 +52,7 @@ export default defineConfig({ }, optimizeDeps: { // Don't want vite to bundle these late during dev causing reload - include: ["qr-scanner", "nostr-tools", "class-variance-authority"], + include: ["qr-scanner", "nostr-tools", "class-variance-authority", "@kobalte/core", "@solid-primitives/upload"], // This is necessary because otherwise `vite dev` can't find the wasm exclude: ["@mutinywallet/mutiny-wasm", "@mutinywallet/waila-wasm"], },