aboutsummaryrefslogtreecommitdiff
path: root/packages/aml-backoffice-ui/src/pages/HandleAccountNotReady.tsx
blob: b3d04d97efbae4bd5925d2ac9e360465d1c339ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
        onRemoveAccount={() => {
          officer.forget();
        }}
        onAccountUnlocked={(pwd) => {
          officer.tryUnlock(pwd);
        }}
      />
    );
  }
  return <div>
    some
  </div>
  throw Error(`unexpected account state ${(officer as any).state}`);
}