cautpartener / client / src / app / views / recovery.ts
 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
 * Wiped-storage recovery screen. Shown when wipeCheck() says an identity
 * existed on this device but the browser evicted its storage (iOS does this
 * to rarely-used sites). We explain what happened and offer seed import —
 * NEVER a silent new identity: that would orphan the user's contacts and
 * profile without them understanding why. Starting over is available, but
 * only behind an explicit, worded confirmation.
 */

import { abandonLostIdentity, type ActiveIdentity } from "../../core/identity-store";
import { t } from "../i18n";
import { h, sheet } from "../ui-kit";
import { importPanel } from "./identity-onboarding";

export function renderRecovery(
  root: HTMLElement,
  onDone: (id: ActiveIdentity) => void,
  onStartOver: () => void,
): void {
  const startOver = h(
    "button",
    { type: "button", class: "btn ghost danger-ghost", "data-testid": "rec-start-over" },
    t("recStartOver"),
  );
  startOver.addEventListener("click", () => {
    const yes = h("button", { type: "button", class: "btn danger", "data-testid": "rec-start-over-yes" }, t("recStartOverYes"));
    const no = h("button", { type: "button", class: "btn ghost" }, t("cancel"));
    const s = sheet(
      h(
        "div",
        {},
        h("h2", { class: "sheet-title" }, t("recStartOver")),
        h("p", { class: "muted" }, t("recStartOverConfirm")),
        h("div", { class: "btn-row" }, no, yes),
      ),
    );
    no.addEventListener("click", () => s.close());
    yes.addEventListener("click", () => {
      abandonLostIdentity();
      s.close();
      onStartOver();
    });
  });

  root.replaceChildren(
    h(
      "div",
      { class: "onboarding", "data-testid": "recovery" },
      h(
        "div",
        { class: "onb-inner" },
        h("div", { class: "glyph" }, "🌪️"),
        h("h2", {}, t("recTitle")),
        h("p", { class: "muted" }, t("recBody")),
        h("h3", { class: "sub-title" }, t("recImport")),
        importPanel(onDone),
        startOver,
      ),
    ),
  );
}

static mirror of HEAD · about · clone: git clone https://cod-sursa.cautpartener.ro/cautpartener.git