diff --git a/apps/mobile/src/app/delete.tsx b/apps/mobile/src/app/delete.tsx index 148a2d1..e761627 100644 --- a/apps/mobile/src/app/delete.tsx +++ b/apps/mobile/src/app/delete.tsx @@ -7,12 +7,13 @@ import { reloadAppAsync } from "expo"; import { Stack } from "expo-router"; import { useCallback, useEffect, useReducer, useRef, useState } from "react"; -import { BackHandler, View } from "react-native"; +import { BackHandler, Platform, View } from "react-native"; import { eraseReducer, initialErase, confirmationMatches, type EraseScreen } from "@hermit/runtime"; import { notificationAccessEnabled, openNotificationAccessSettings } from "../adapters"; import { confirmErase, eraseEverything, phoneHasLock, walletBalance } from "../adapters/erase"; import { Icon } from "../components/Icon"; import { Btn, Card, Empty, Failed, Input, Note as NoteLine, Notice, Page, T } from "../components/kit"; +import { eraseLines } from "../delete-view"; import { useHermit } from "../hermit-context"; import { t } from "../i18n"; import { radius, s } from "../theme"; @@ -20,7 +21,6 @@ import { usePalette } from "../use-palette"; // Read at use, not at import: the word follows the app language (HM-SET-05). const word = () => t("HM-SET-03.confirmWord"); -const LIST = ["listData", "listMessages", "listKeys", "listCache", "listModel"] as const; interface Facts { initial: EraseScreen; @@ -103,6 +103,7 @@ function Flow({ initial, hasLock, notifAccess }: Facts) { function Body(props: { screen: EraseScreen; hasLock: boolean; notifAccess: boolean; onType(text: string): void; onSubmit(): void; onWalletAck(): void; onRetry(): void }) { const p = usePalette(); + const lines = eraseLines(Platform.OS); const { screen } = props; switch (screen.kind) { case "wallet_warning": @@ -126,11 +127,12 @@ function Body(props: { screen: EraseScreen; hasLock: boolean; notifAccess: boole return ( {t("HM-SET-03.body")} - {/* What goes, on the page color with coral marks. */} + {/* What goes, on the page color with coral marks. On iOS the captured-messages line is not there: + capture is Android-only, and so is the permissions note under the list. */} - {LIST.map((k) => )} + {lines.list.map((k) => )} - + {lines.permissionsStay ? : null} {props.notifAccess ? : null} { + const lines = eraseLines("android"); + assert.deepEqual(lines.list, ["listData", "listMessages", "listKeys", "listCache", "listModel"]); + assert.equal(lines.permissionsStay, true); +}); + +test("on iOS the list leaves out the captured messages line and the permissions note is gone", () => { + const lines = eraseLines("ios"); + assert.deepEqual(lines.list, ["listData", "listKeys", "listCache", "listModel"]); + assert.equal(lines.permissionsStay, false); +}); + +test("only Android gets the Android lines", () => { + for (const os of ["web", "macos", "windows"]) { + const lines = eraseLines(os); + assert.ok(!lines.list.includes("listMessages"), os); + assert.equal(lines.permissionsStay, false, os); + } +}); diff --git a/apps/mobile/src/delete-view.ts b/apps/mobile/src/delete-view.ts new file mode 100644 index 0000000..6c3af99 --- /dev/null +++ b/apps/mobile/src/delete-view.ts @@ -0,0 +1,16 @@ +// HM-SET-03: which of the erase screen's lines apply on this OS. Pure: tested under Node with node --test +// (delete-view.test.ts). WhatsApp capture reads Android notifications, so its line and the Android permissions +// note only apply on Android; iOS has no capture and no such permissions to mention. + +export const ERASE_LIST = ["listData", "listMessages", "listKeys", "listCache", "listModel"] as const; + +export type EraseListKey = (typeof ERASE_LIST)[number]; + +/** The "what goes" list keys and whether the permissions note shows, for React Native's `Platform.OS` (or any OS string). */ +export function eraseLines(os: string): { list: readonly EraseListKey[]; permissionsStay: boolean } { + const android = os === "android"; + return { + list: android ? ERASE_LIST : ERASE_LIST.filter((k) => k !== "listMessages"), + permissionsStay: android, + }; +}