commit 4f41156e75b9f76f2a6895133443705aa7023f17
parent 8bdb0a8437aae55ec6ee6cffd3ab01baa3b7c636
Author: Florian Dold <dold@taler.net>
Date: Thu, 26 Nov 2026 04:13:12 +0100
wallet-webui: offer a storage switch when restoring a backup
A wallet using IndexedDB told users to convert a valid SQLite backup.
Offer to switch storage when the browser supports it, keep the selected
file, and ask separately before replacing the wallet.
Diffstat:
8 files changed, 143 insertions(+), 20 deletions(-)
diff --git a/packages/wallet-webui/src/routes/App.tsx b/packages/wallet-webui/src/routes/App.tsx
@@ -5396,11 +5396,31 @@ function SettingsRoute() {
setTestMoneyBusy(false);
}
};
+ const sqliteAvailable =
+ storageStatus?.sqliteAvailable === true &&
+ durability.capability?.sqlite === "available";
if (backupFile && metadata) {
return (
<RestoreBackupRoute
+ key={metadata.backend}
file={backupFile}
backend={metadata.backend}
+ storageMigration={
+ storage && sqliteAvailable
+ ? {
+ backend: metadata.backend === "sqlite" ? "sqlite" : "indexeddb",
+ available: true,
+ durability: durability.capability?.durability ?? "unavailable",
+ busy: storageBusy || storageStatus?.busy === true,
+ stage: storageStage ?? storageStatus?.stage,
+ error: storageError,
+ backupExpiresAt:
+ storageStatus?.metadata.migration.backupExpiresAt,
+ onMigrate: () => void migrateStorage("forward"),
+ onRollback: () => void migrateStorage("rollback"),
+ }
+ : undefined
+ }
onCancel={() => setBackupFile(undefined)}
onDone={() => {
setBackupFile(undefined);
@@ -5427,10 +5447,7 @@ function SettingsRoute() {
busy={busy}
message={message}
error={settingsError}
- sqliteAvailable={
- storageStatus?.sqliteAvailable === true &&
- durability.capability?.sqlite === "available"
- }
+ sqliteAvailable={sqliteAvailable}
storageBusy={storageBusy || storageStatus?.busy === true}
storageStage={storageStage ?? storageStatus?.stage}
storageError={storageError ?? storageStatus?.metadata.migration.error}
@@ -5495,6 +5512,7 @@ function SettingsRoute() {
}
setMessage(undefined);
setSettingsError(undefined);
+ setStorageError(undefined);
setBackupFile(file);
}}
onOpenExchanges={() => navigate("/exchanges")}
diff --git a/packages/wallet-webui/src/routes/RestoreBackupRoute.tsx b/packages/wallet-webui/src/routes/RestoreBackupRoute.tsx
@@ -32,11 +32,13 @@ import {
downloadCurrentWallet,
} from "./backup-review.js";
import { useServices } from "./context.js";
+import type { StorageMigrationCardProps } from "../screens/StorageMigrationCard.js";
import type { BackupReview } from "./import-model.js";
export function RestoreBackupRoute(props: {
file: File;
backend: string;
+ storageMigration?: StorageMigrationCardProps;
onCancel: () => void;
onDone: () => void;
}) {
@@ -67,10 +69,21 @@ export function RestoreBackupRoute(props: {
worker.onerror = failed;
worker.onmessage = ({ data }: MessageEvent<BackupReview>) => {
if (data.stage === "rejected") {
- setState({
- stage: "failure",
- error: localError(backupProblemMessage(data.problem)),
- });
+ if (
+ data.problem === "needs-sqlite" ||
+ data.problem === "needs-indexeddb"
+ ) {
+ setState({
+ stage: "storage-mismatch",
+ required:
+ data.problem === "needs-sqlite" ? "sqlite" : "indexeddb",
+ });
+ } else {
+ setState({
+ stage: "failure",
+ error: localError(backupProblemMessage(data.problem)),
+ });
+ }
} else {
setState(data);
}
@@ -251,7 +264,8 @@ export function RestoreBackupRoute(props: {
state={state}
filename={props.file.name}
bytes={props.file.size}
- busy={busy}
+ busy={busy || props.storageMigration?.busy}
+ storageMigration={props.storageMigration}
message={message}
downloadError={downloadError}
onImport={() => void restore()}
diff --git a/packages/wallet-webui/src/routes/backup-review.ts b/packages/wallet-webui/src/routes/backup-review.ts
@@ -21,20 +21,18 @@ export const backupSchema: BackupSchema = {
tables: NATIVE_DATA_TABLES,
};
-export function backupProblemMessage(problem: ImportProblem): string {
+export function backupProblemMessage(
+ problem: Exclude<ImportProblem, "needs-indexeddb" | "needs-sqlite">,
+): string {
switch (problem) {
case "not-wallet":
return i18n.str`This file is not a wallet database export.`;
- case "needs-indexeddb":
- return i18n.str`This IndexedDB export must be converted before importing into the active backend.`;
case "missing-main":
return i18n.str`This export does not contain a Taler wallet database.`;
case "bad-store":
return i18n.str`This export contains a malformed wallet object store.`;
case "empty":
return i18n.str`This export does not contain wallet object stores.`;
- case "needs-sqlite":
- return i18n.str`This native SQLite export must be converted before importing into IndexedDB.`;
case "bad-version":
return i18n.str`This wallet does not support the backup’s SQLite schema version.`;
case "bad-tables":
diff --git a/packages/wallet-webui/src/routes/import-model.ts b/packages/wallet-webui/src/routes/import-model.ts
@@ -41,7 +41,6 @@ export function inspectImportDump(
): ImportDumpSummary | ImportProblem {
if (!isRecord(dump)) return "not-wallet";
if (isRecord(dump.databases) && !("tables" in dump)) {
- if (activeBackend !== "indexeddb") return "needs-indexeddb";
const mainDatabase = dump.databases[schema.mainDatabase];
if (!isRecord(mainDatabase) || !isRecord(mainDatabase.stores))
return "missing-main";
@@ -55,10 +54,10 @@ export function inspectImportDump(
if (!isRecord(store) || !Array.isArray(store.records)) return "bad-store";
recordCount += store.records.length;
}
+ if (activeBackend !== "indexeddb") return "needs-indexeddb";
return { format: "indexeddb", collectionCount: stores.length, recordCount };
}
if (isRecord(dump.tables) && !("databases" in dump)) {
- if (activeBackend !== "sqlite") return "needs-sqlite";
if (
typeof dump.schemaVersion !== "number" ||
!schema.sqliteVersions.includes(dump.schemaVersion)
@@ -73,6 +72,7 @@ export function inspectImportDump(
if (!Array.isArray(table)) return "bad-tables";
recordCount += table.length;
}
+ if (activeBackend !== "sqlite") return "needs-sqlite";
return {
format: "native-sqlite",
collectionCount: tables.length,
diff --git a/packages/wallet-webui/src/screens/ImportRecoveryScreen.tsx b/packages/wallet-webui/src/screens/ImportRecoveryScreen.tsx
@@ -5,10 +5,16 @@ import type { ErrorPresentation } from "../ui/error.js";
import { i18n } from "../i18n/runtime.js";
import { formatFileSize, type BackupReview } from "../routes/import-model.js";
+import {
+ StorageMigrationCard,
+ type StorageMigrationCardProps,
+} from "./StorageMigrationCard.js";
+
export type RestoreState =
| Exclude<BackupReview, { stage: "rejected" }>
| { stage: "preparing" | "verifying" | "success" }
| { stage: "restoring"; processed: number; total: number }
+ | { stage: "storage-mismatch"; required: "sqlite" | "indexeddb" }
| { stage: "failure"; error: ErrorPresentation }
| { stage: "uncertain"; committed: boolean; error: ErrorPresentation };
@@ -19,13 +25,19 @@ export function ImportRecoveryScreen(props: {
busy?: boolean;
message?: string;
downloadError?: ErrorPresentation;
+ storageMigration?: StorageMigrationCardProps;
onImport: () => void;
onDownload: () => void;
onCancel: () => void;
onDone: () => void;
}) {
const state = props.state;
- const canCancel = ["reading", "checking", "review"].includes(state.stage);
+ const canCancel = [
+ "reading",
+ "checking",
+ "review",
+ "storage-mismatch",
+ ].includes(state.stage);
const stageLabel =
state.stage === "reading"
? i18n.str`Reading backup…`
@@ -71,6 +83,33 @@ export function ImportRecoveryScreen(props: {
{progress && <p class="text-sm text-secondary">{progress.text}</p>}
</Card>
)}
+ {state.stage === "storage-mismatch" && (
+ <>
+ <Card>
+ <h2 class="font-semibold">
+ {state.required === "sqlite"
+ ? i18n.str`This is a SQLite backup`
+ : i18n.str`This is an IndexedDB backup`}
+ </h2>
+ {props.storageMigration ? (
+ <p class="mt-2">
+ {state.required === "sqlite"
+ ? i18n.str`Turn on SQLite storage below to review this file. Switching storage copies your current wallet. You will confirm separately before replacing it.`
+ : i18n.str`Turn off SQLite storage below to review this file. Switching storage copies your current wallet. You will confirm separately before replacing it.`}
+ </p>
+ ) : (
+ <p class="mt-2">
+ {state.required === "sqlite"
+ ? i18n.str`This wallet cannot switch to SQLite. Open a separate Taler wallet PWA that supports SQLite, enable SQLite in Settings and restore this file there. To bring it back here, switch that wallet to IndexedDB and download a new backup.`
+ : i18n.str`Restore this backup in a Taler wallet using IndexedDB. New browser wallets use IndexedDB by default.`}
+ </p>
+ )}
+ </Card>
+ {props.storageMigration && (
+ <StorageMigrationCard {...props.storageMigration} />
+ )}
+ </>
+ )}
{state.stage === "review" && (
<>
<Card>
diff --git a/packages/wallet-webui/src/screens/StorageMigrationCard.tsx b/packages/wallet-webui/src/screens/StorageMigrationCard.tsx
@@ -41,7 +41,7 @@ export function storageDurabilityLabel(
}
}
-export function StorageMigrationCard(props: {
+export interface StorageMigrationCardProps {
backend: "indexeddb" | "sqlite";
available: boolean;
durability: "persistent" | "best-effort" | "unavailable";
@@ -51,7 +51,9 @@ export function StorageMigrationCard(props: {
backupExpiresAt?: number;
onMigrate: () => void;
onRollback: () => void;
-}) {
+}
+
+export function StorageMigrationCard(props: StorageMigrationCardProps) {
return (
<Card>
<div class="flex flex-wrap items-center justify-between gap-2">
diff --git a/packages/wallet-webui/test/import-model.test.ts b/packages/wallet-webui/test/import-model.test.ts
@@ -33,7 +33,10 @@ test("IndexedDB imports report collections and records", () => {
test("cross-backend and malformed imports fail before mutation", () => {
assert.equal(
- inspectImportDump({ schemaVersion: 1, tables: { coins: [] } }, "indexeddb"),
+ inspectImportDump(
+ { schemaVersion: backupSchema.sqliteVersions[0], tables: { coins: [] } },
+ "indexeddb",
+ ),
"needs-sqlite",
);
assert.equal(
@@ -48,6 +51,14 @@ test("cross-backend and malformed imports fail before mutation", () => {
"bad-store",
);
assert.equal(inspectImportDump([], "indexeddb"), "not-wallet");
+ assert.equal(inspectImportDump({ databases: {} }, "sqlite"), "missing-main");
+ assert.equal(
+ inspectImportDump(
+ { schemaVersion: 999, tables: { coins: [] } },
+ "indexeddb",
+ ),
+ "bad-version",
+ );
assert.equal(
inspectImportDump(
{
diff --git a/packages/wallet-webui/test/screens.test.tsx b/packages/wallet-webui/test/screens.test.tsx
@@ -4547,6 +4547,47 @@ test("backup review keeps downloading and replacing the wallet independent", asy
await window.happyDOM.abort();
});
+test("backup format mismatch guides an explicit storage switch on supported wallets", async () => {
+ const window = installDom();
+ const { render, cleanup, act } = await import("@testing-library/preact");
+ let migrations = 0;
+ const common = {
+ state: { stage: "storage-mismatch", required: "sqlite" } as const,
+ filename: "wallet.json",
+ bytes: 1536,
+ onDownload() {},
+ onImport() {
+ assert.fail("unexpected replacement");
+ },
+ onCancel() {},
+ onDone() {},
+ };
+ const view = render(<ImportRecoveryScreen {...common} />);
+ assert(view.getByText(/separate Taler wallet PWA/));
+ assert.equal(view.queryByRole("switch"), null);
+ view.rerender(
+ <ImportRecoveryScreen
+ {...common}
+ storageMigration={{
+ backend: "indexeddb",
+ available: true,
+ durability: "persistent",
+ busy: false,
+ onMigrate() {
+ migrations++;
+ },
+ onRollback() {},
+ }}
+ />,
+ );
+ assert.equal(migrations, 0);
+ assert.equal(view.queryByRole("button", { name: "Replace wallet" }), null);
+ await act(() => view.getByRole("switch").click());
+ assert.equal(migrations, 1);
+ cleanup();
+ await window.happyDOM.abort();
+});
+
test("restore progress exposes actual record counts", async () => {
const window = installDom();
const { render, cleanup } = await import("@testing-library/preact");