diff --git a/src/components/Logs.tsx b/src/components/Logs.tsx index 966a024..ec31ab9 100644 --- a/src/components/Logs.tsx +++ b/src/components/Logs.tsx @@ -1,15 +1,30 @@ import { MutinyWallet } from "@mutinywallet/mutiny-wasm"; +import { createSignal, Show } from "solid-js"; -import { Button, InnerCard, NiceP, VStack } from "~/components"; +import { + Button, + InfoBox, + InnerCard, + NiceP, + SimpleDialog, + TextField, + VStack +} from "~/components"; import { useI18n } from "~/i18n/context"; -import { downloadTextFile } from "~/utils"; +import { downloadTextFile, eify } from "~/utils"; export function Logs() { const i18n = useI18n(); + + // Create state for errors, password and dialog visibility + const [error, setError] = createSignal(); + const [exportDecrypt, setExportDecrypt] = createSignal(false); + const [password, setPassword] = createSignal(); + async function handleSave() { try { - const logs = await MutinyWallet.get_logs(); - + setError(undefined); + const logs = await MutinyWallet.get_logs(password()); // Use password if required await downloadTextFile( logs.join("") || "", "mutiny-logs.txt", @@ -17,9 +32,26 @@ export function Logs() { ); } catch (e) { console.error(e); + const err = eify(e); + if (err.message === "Incorrect password entered.") { + setExportDecrypt(true); + } else { + setError(err); + } } } + function savePassword(e: Event) { + e.preventDefault(); + handleSave(); + setPassword(undefined); // clear password after use + setExportDecrypt(false); // close the dialog + } + + function noop() { + // noop + } + return ( @@ -30,6 +62,36 @@ export function Logs() { {i18n.t("settings.emergency_kit.logs.download_logs")} + + {error()?.message} + + +
+
+ setPassword(e.currentTarget.value)} + error={""} + onBlur={noop} + onChange={noop} + /> + + {error()?.message} + + +
+
+
); } diff --git a/src/i18n/en/translations.ts b/src/i18n/en/translations.ts index a715229..bf85374 100644 --- a/src/i18n/en/translations.ts +++ b/src/i18n/en/translations.ts @@ -307,7 +307,9 @@ export default { title: "Download debug logs", something_screwy: "Something screwy going on? Check out the logs!", - download_logs: "Download Logs" + download_logs: "Download Logs", + password: "Enter your password to decrypt", + confirm_password_label: "Confirm Password" }, delete_everything: { delete: "Delete Everything",