mirror of
https://github.com/aljazceru/mutiny-web.git
synced 2026-01-07 16:24:29 +01:00
Fix downloading logs with a password set
This commit is contained in:
committed by
Tony Giorgio
parent
058f4c402b
commit
fdf879f123
@@ -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<Error>();
|
||||
const [exportDecrypt, setExportDecrypt] = createSignal(false);
|
||||
const [password, setPassword] = createSignal<string>();
|
||||
|
||||
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 (
|
||||
<InnerCard title={i18n.t("settings.emergency_kit.logs.title")}>
|
||||
<VStack>
|
||||
@@ -30,6 +62,36 @@ export function Logs() {
|
||||
{i18n.t("settings.emergency_kit.logs.download_logs")}
|
||||
</Button>
|
||||
</VStack>
|
||||
<Show when={error()}>
|
||||
<InfoBox accent="red">{error()?.message}</InfoBox>
|
||||
</Show>
|
||||
<SimpleDialog
|
||||
title={i18n.t("settings.emergency_kit.logs.password")}
|
||||
open={exportDecrypt()}
|
||||
>
|
||||
<form onSubmit={savePassword}>
|
||||
<div class="flex flex-col gap-4">
|
||||
<TextField
|
||||
name="password"
|
||||
type="password"
|
||||
ref={noop}
|
||||
value={password()}
|
||||
onInput={(e) => setPassword(e.currentTarget.value)}
|
||||
error={""}
|
||||
onBlur={noop}
|
||||
onChange={noop}
|
||||
/>
|
||||
<Show when={error()}>
|
||||
<InfoBox accent="red">{error()?.message}</InfoBox>
|
||||
</Show>
|
||||
<Button intent="blue" onClick={savePassword}>
|
||||
{i18n.t(
|
||||
"settings.emergency_kit.logs.confirm_password_label"
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</form>
|
||||
</SimpleDialog>
|
||||
</InnerCard>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user