aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/taler-wallet-core/src/db.ts52
-rw-r--r--packages/taler-wallet-webextension/src/wallet/History.tsx5
2 files changed, 51 insertions, 6 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts
index 832bbb9ac..da566ff24 100644
--- a/packages/taler-wallet-core/src/db.ts
+++ b/packages/taler-wallet-core/src/db.ts
@@ -2024,11 +2024,11 @@ export interface DatabaseDump {
version: string;
}
-export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
+async function recoverFromDump(db: IDBDatabase, dump: DatabaseDump): Promise<void> {
return new Promise((resolve, reject) => {
const tx = db.transaction(Array.from(db.objectStoreNames), "readwrite");
tx.addEventListener("complete", () => {
- resolve(db);
+ resolve();
});
for (let i = 0; i < db.objectStoreNames.length; i++) {
const name = db.objectStoreNames[i];
@@ -2041,5 +2041,51 @@ export function importDb(db: IDBDatabase, dump: DatabaseDump): Promise<any> {
});
}
tx.commit();
- });
+ })
+}
+
+export async function importDb(db: IDBDatabase, object: any): Promise<void> {
+ if ("name" in object && "stores" in object && "version" in object) {
+ // looks like a database dump
+ const dump = object as DatabaseDump
+ return recoverFromDump(db, dump);
+ }
+
+ if ("databases" in object && "$types" in object) {
+ // looks like a IDBDatabase
+ const someDatabase = object.databases;
+
+ if (TALER_META_DB_NAME in someDatabase) {
+ //looks like a taler database
+ const currentMainDbValue = someDatabase[TALER_META_DB_NAME].objectStores.metaConfig.records[0].value.value
+
+ if (currentMainDbValue !== TALER_DB_NAME) {
+ console.log("not the current database version")
+ }
+
+ const talerDb = someDatabase[currentMainDbValue];
+
+ const objectStoreNames = Object.keys(talerDb.objectStores);
+
+ const dump: DatabaseDump = {
+ name: talerDb.schema.databaseName,
+ version: talerDb.schema.databaseVersion,
+ stores: {},
+ }
+
+ for (let i = 0; i < objectStoreNames.length; i++) {
+ const name = objectStoreNames[i];
+ const storeDump = {} as { [s: string]: any };
+ dump.stores[name] = storeDump;
+ talerDb.objectStores[name].records.map((r: any) => {
+ const pkey = r.primaryKey
+ const key = typeof pkey === "string" ? pkey : pkey.join(",")
+ storeDump[key] = r.value;
+ })
+ }
+
+ return recoverFromDump(db, dump);
+ }
+ }
+ throw Error("could not import database");
}
diff --git a/packages/taler-wallet-webextension/src/wallet/History.tsx b/packages/taler-wallet-webextension/src/wallet/History.tsx
index 6a8362ddb..53913501d 100644
--- a/packages/taler-wallet-webextension/src/wallet/History.tsx
+++ b/packages/taler-wallet-webextension/src/wallet/History.tsx
@@ -25,7 +25,6 @@ import { useEffect, useState } from "preact/hooks";
import { Loading } from "../components/Loading.js";
import { LoadingError } from "../components/LoadingError.js";
import {
- ButtonBoxPrimary,
CenteredBoldText,
CenteredText,
DateSeparator,
@@ -37,6 +36,8 @@ import { useTranslationContext } from "../context/translation.js";
import { useAsyncAsHook } from "../hooks/useAsyncAsHook.js";
import { Button } from "../mui/Button.js";
import { NoBalanceHelp } from "../popup/NoBalanceHelp.js";
+import DownloadIcon from "../svg/download_24px.svg";
+import UploadIcon from "../svg/upload_24px.svg";
import * as wxApi from "../wxApi.js";
interface Props {
@@ -96,8 +97,6 @@ const term = 1000 * 60 * 60 * 24;
function normalizeToDay(x: number): number {
return Math.round(x / term) * term;
}
-import DownloadIcon from "../svg/download_24px.svg";
-import UploadIcon from "../svg/upload_24px.svg";
export function HistoryView({
defaultCurrency,