Testing full clearing of node manager

This commit is contained in:
Tony Giorgio
2023-04-29 13:41:39 -05:00
committed by Paul Miller
parent 09e595dcf8
commit ee6f532ba8
3 changed files with 37 additions and 27 deletions

View File

@@ -22,29 +22,7 @@ export function deleteDb(name: string) {
} }
export function DeleteEverything() { export function DeleteEverything() {
const [_store, actions] = useMegaStore(); const [_state, 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);
}
}
async function confirmReset() { async function confirmReset() {
setConfirmOpen(true); setConfirmOpen(true);
@@ -53,6 +31,25 @@ export function DeleteEverything() {
const [confirmOpen, setConfirmOpen] = createSignal(false); const [confirmOpen, setConfirmOpen] = createSignal(false);
const [confirmLoading, setConfirmLoading] = 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 ( return (
<> <>
<Button onClick={confirmReset}>Delete Everything</Button> <Button onClick={confirmReset}>Delete Everything</Button>

View File

@@ -14,6 +14,7 @@ type UserStatus = undefined | "new_here" | "waitlisted" | "approved" | "paid"
export type MegaStore = [{ export type MegaStore = [{
waitlist_id?: string; waitlist_id?: string;
mutiny_wallet?: MutinyWallet; mutiny_wallet?: MutinyWallet;
deleting: boolean;
user_status: UserStatus; user_status: UserStatus;
scan_result?: ParsedParams; scan_result?: ParsedParams;
balance?: MutinyBalance; balance?: MutinyBalance;
@@ -25,6 +26,7 @@ export type MegaStore = [{
}, { }, {
fetchUserStatus(): Promise<UserStatus>; fetchUserStatus(): Promise<UserStatus>;
setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise<void>; setupMutinyWallet(settings?: MutinyWalletSettingStrings): Promise<void>;
deleteMutinyWallet(): Promise<void>;
setWaitlistId(waitlist_id: string): void; setWaitlistId(waitlist_id: string): void;
setScanResult(scan_result: ParsedParams | undefined): void; setScanResult(scan_result: ParsedParams | undefined): void;
sync(): Promise<void>; sync(): Promise<void>;
@@ -36,6 +38,7 @@ export const Provider: ParentComponent = (props) => {
const [state, setState] = createStore({ const [state, setState] = createStore({
waitlist_id: localStorage.getItem("waitlist_id"), waitlist_id: localStorage.getItem("waitlist_id"),
mutiny_wallet: undefined as MutinyWallet | undefined, mutiny_wallet: undefined as MutinyWallet | undefined,
deleting: false,
user_status: undefined as UserStatus, user_status: undefined as UserStatus,
scan_result: undefined as ParsedParams | undefined, scan_result: undefined as ParsedParams | undefined,
// TODO: wire this up to real price once we have caching // TODO: wire this up to real price once we have caching
@@ -74,6 +77,16 @@ export const Provider: ParentComponent = (props) => {
console.error(e) console.error(e)
} }
}, },
async deleteMutinyWallet(): Promise<void> {
await state.mutiny_wallet?.stop();
setState((prevState) => ({
...prevState,
mutiny_wallet: undefined,
deleting: true,
}));
MutinyWallet.import_json("{}");
localStorage.clear();
},
setWaitlistId(waitlist_id: string) { setWaitlistId(waitlist_id: string) {
setState({ waitlist_id }) setState({ waitlist_id })
}, },
@@ -115,7 +128,7 @@ export const Provider: ParentComponent = (props) => {
// Only load node manager when status is approved // Only load node manager when status is approved
createEffect(() => { 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...") console.log("running setup node manager...")
actions.setupMutinyWallet().then(() => console.log("node manager setup done")) actions.setupMutinyWallet().then(() => console.log("node manager setup done"))
} }

View File

@@ -52,7 +52,7 @@ export default defineConfig({
}, },
optimizeDeps: { optimizeDeps: {
// Don't want vite to bundle these late during dev causing reload // 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 // This is necessary because otherwise `vite dev` can't find the wasm
exclude: ["@mutinywallet/mutiny-wasm", "@mutinywallet/waila-wasm"], exclude: ["@mutinywallet/mutiny-wasm", "@mutinywallet/waila-wasm"],
}, },