From 7fd7fd580b35aeb0e15fa6111fd69048d2be14ab Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Wed, 21 Jun 2023 13:57:23 -0500 Subject: [PATCH] add emergency kit and new error states --- src/components/DeleteEverything.tsx | 21 ++++++-- src/components/ErrorDisplay.tsx | 15 +++++- src/components/ImportExport.tsx | 29 ++++++---- src/components/Logs.tsx | 7 ++- src/components/SetupErrorDisplay.tsx | 79 +++++++++++++++++++++------- src/components/layout/index.tsx | 27 +++++++++- src/logic/browserCompatibility.ts | 6 +-- src/logic/mutinyWalletSetup.ts | 7 ++- src/routes/EmergencyKit.tsx | 45 ++++++++++++++++ src/routes/Settings.tsx | 9 ++++ src/state/megaStore.tsx | 22 +++++--- 11 files changed, 216 insertions(+), 51 deletions(-) create mode 100644 src/routes/EmergencyKit.tsx diff --git a/src/components/DeleteEverything.tsx b/src/components/DeleteEverything.tsx index 135e504..2a90794 100644 --- a/src/components/DeleteEverything.tsx +++ b/src/components/DeleteEverything.tsx @@ -1,3 +1,4 @@ +import initMutinyWallet, { MutinyWallet } from "@mutinywallet/mutiny-wasm"; import { createSignal } from "solid-js"; import { ConfirmDialog } from "~/components/Dialog"; import { Button } from "~/components/layout"; @@ -5,8 +6,8 @@ import { showToast } from "~/components/Toaster"; import { useMegaStore } from "~/state/megaStore"; import eify from "~/utils/eify"; -export function DeleteEverything() { - const [_state, actions] = useMegaStore(); +export function DeleteEverything(props: { emergency?: boolean }) { + const [state, actions] = useMegaStore(); async function confirmReset() { setConfirmOpen(true); @@ -18,7 +19,21 @@ export function DeleteEverything() { async function resetNode() { try { setConfirmLoading(true); - await actions.deleteMutinyWallet(); + // If we're in a context where the wallet is loaded we want to use the regular action to delete it + // Otherwise we just call the import_json method directly + if (state.mutiny_wallet && !props.emergency) { + try { + await actions.deleteMutinyWallet(); + } catch (e) { + // If we can't stop we want to keep going + console.error(e); + } + } else { + // If there's no mutiny_wallet loaded we might need to initialize WASM + await initMutinyWallet(); + await MutinyWallet.import_json("{}"); + } + showToast({ title: "Deleted", description: `Deleted all data` }); setTimeout(() => { diff --git a/src/components/ErrorDisplay.tsx b/src/components/ErrorDisplay.tsx index 8c76195..70234fe 100644 --- a/src/components/ErrorDisplay.tsx +++ b/src/components/ErrorDisplay.tsx @@ -1,11 +1,13 @@ -import { Title } from "solid-start"; +import { A, Title } from "solid-start"; import { Button, DefaultMain, LargeHeader, + NiceP, SafeArea, SmallHeader } from "~/components/layout"; +import { ExternalLink } from "./layout/ExternalLink"; export default function ErrorDisplay(props: { error: Error }) { return ( @@ -18,6 +20,17 @@ export default function ErrorDisplay(props: { error: Error }) { {props.error.name}:{" "} {props.error.message}

+ + Try reloading this page or clicking the "Dangit" button. If + you keep having problems,{" "} + + reach out to us for support. + + + + Getting desperate? Try the{" "} + emergency kit. +