From 69b66e715eae039330898f470a8993d1d154b583 Mon Sep 17 00:00:00 2001
From: Sebastian <sebasjm@gmail.com>
Date: Fri, 26 May 2023 16:52:30 -0300
Subject: account as hook

---
 .../src/pages/HandleAccountNotReady.tsx            | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 packages/exchange-backoffice-ui/src/pages/HandleAccountNotReady.tsx

(limited to 'packages/exchange-backoffice-ui/src/pages/HandleAccountNotReady.tsx')

diff --git a/packages/exchange-backoffice-ui/src/pages/HandleAccountNotReady.tsx b/packages/exchange-backoffice-ui/src/pages/HandleAccountNotReady.tsx
new file mode 100644
index 000000000..b0c430875
--- /dev/null
+++ b/packages/exchange-backoffice-ui/src/pages/HandleAccountNotReady.tsx
@@ -0,0 +1,31 @@
+import { VNode, h } from "preact";
+import { OfficerNotReady } from "../hooks/useOfficer.js";
+import { CreateAccount } from "./CreateAccount.js";
+import { UnlockAccount } from "./UnlockAccount.js";
+
+export function HandleAccountNotReady({
+  officer,
+}: {
+  officer: OfficerNotReady;
+}): VNode {
+  if (officer.state === "not-found") {
+    return (
+      <CreateAccount
+        onNewAccount={(password) => {
+          officer.create(password);
+        }}
+      />
+    );
+  }
+
+  if (officer.state === "locked") {
+    return (
+      <UnlockAccount
+        onAccountUnlocked={(pwd) => {
+          officer.tryUnlock(pwd);
+        }}
+      />
+    );
+  }
+  throw Error(`unexpected account state ${(officer as any).state}`);
+}
-- 
cgit v1.2.3

