2022-06-06 05:54:55 +02:00
|
|
|
import { bytesToString, decodeCrock } from "@gnu-taler/taler-util";
|
2021-10-19 15:56:52 +02:00
|
|
|
import { h, VNode } from "preact";
|
2021-11-11 17:22:14 +01:00
|
|
|
import { useEffect, useState } from "preact/hooks";
|
2022-06-06 05:54:55 +02:00
|
|
|
import { QR } from "../../components/QR.js";
|
|
|
|
import { useAnastasisContext } from "../../context/anastasis.js";
|
|
|
|
import { AnastasisClientFrame } from "./index.js";
|
2021-10-19 15:56:52 +02:00
|
|
|
|
2021-10-22 06:31:46 +02:00
|
|
|
export function RecoveryFinishedScreen(): VNode {
|
2021-11-10 14:20:52 +01:00
|
|
|
const reducer = useAnastasisContext();
|
2021-11-12 17:44:10 +01:00
|
|
|
const [copied, setCopied] = useState(false);
|
2021-11-11 17:22:14 +01:00
|
|
|
useEffect(() => {
|
|
|
|
setTimeout(() => {
|
2021-11-12 17:44:10 +01:00
|
|
|
setCopied(false);
|
|
|
|
}, 1000);
|
|
|
|
}, [copied]);
|
2021-10-22 06:31:46 +02:00
|
|
|
|
|
|
|
if (!reducer) {
|
2021-11-10 14:20:52 +01:00
|
|
|
return <div>no reducer in context</div>;
|
2021-10-22 06:31:46 +02:00
|
|
|
}
|
2022-04-13 08:44:37 +02:00
|
|
|
if (reducer.currentReducerState?.reducer_type !== "recovery") {
|
2021-11-10 14:20:52 +01:00
|
|
|
return <div>invalid state</div>;
|
2021-10-22 06:31:46 +02:00
|
|
|
}
|
2021-11-11 17:22:14 +01:00
|
|
|
const secretName = reducer.currentReducerState.recovery_document?.secret_name;
|
2021-11-10 14:20:52 +01:00
|
|
|
const encodedSecret = reducer.currentReducerState.core_secret;
|
2021-10-22 06:31:46 +02:00
|
|
|
if (!encodedSecret) {
|
2021-11-10 14:20:52 +01:00
|
|
|
return (
|
|
|
|
<AnastasisClientFrame title="Recovery Problem" hideNav>
|
|
|
|
<p>Secret not found</p>
|
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
marginTop: "2em",
|
|
|
|
display: "flex",
|
|
|
|
justifyContent: "space-between",
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button class="button" onClick={() => reducer.back()}>
|
|
|
|
Back
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</AnastasisClientFrame>
|
|
|
|
);
|
2021-10-22 06:31:46 +02:00
|
|
|
}
|
2021-11-10 14:20:52 +01:00
|
|
|
const secret = bytesToString(decodeCrock(encodedSecret.value));
|
2021-11-12 17:44:10 +01:00
|
|
|
const contentURI = `data:${encodedSecret.mime},${secret}`;
|
2021-11-11 17:22:14 +01:00
|
|
|
// const fileName = encodedSecret['filename']
|
|
|
|
// data:plain/text;base64,asdasd
|
2021-10-19 15:56:52 +02:00
|
|
|
return (
|
2021-11-11 17:22:14 +01:00
|
|
|
<AnastasisClientFrame title="Recovery Success" hideNav>
|
|
|
|
<h2 class="subtitle">Your secret was recovered</h2>
|
2021-11-12 17:44:10 +01:00
|
|
|
{secretName && (
|
|
|
|
<p class="block">
|
|
|
|
<b>Secret name:</b> {secretName}
|
|
|
|
</p>
|
|
|
|
)}
|
2021-11-11 17:22:14 +01:00
|
|
|
<div class="block buttons" disabled={copied}>
|
2021-11-12 17:44:10 +01:00
|
|
|
<button
|
|
|
|
class="button"
|
|
|
|
onClick={() => {
|
|
|
|
navigator.clipboard.writeText(secret);
|
|
|
|
setCopied(true);
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{!copied ? "Copy" : "Copied"}
|
2021-11-10 14:20:52 +01:00
|
|
|
</button>
|
2021-11-11 17:22:14 +01:00
|
|
|
<a class="button is-info" download="secret.txt" href={contentURI}>
|
|
|
|
<div class="icon is-small ">
|
|
|
|
<i class="mdi mdi-download" />
|
|
|
|
</div>
|
2021-11-12 17:44:10 +01:00
|
|
|
<span>Save as</span>
|
2021-11-11 17:22:14 +01:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
<div class="block">
|
|
|
|
<QR text={secret} />
|
2021-11-04 19:17:57 +01:00
|
|
|
</div>
|
2021-10-19 15:56:52 +02:00
|
|
|
</AnastasisClientFrame>
|
|
|
|
);
|
|
|
|
}
|