diff options
author | Sebastian <sebasjm@gmail.com> | 2021-06-04 12:42:15 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2021-06-04 12:42:35 -0300 |
commit | e1b363c7dd210f2e684bc220ced25a255d00f331 (patch) | |
tree | 5d92d4150df22bf69f6296a5f1ae49c9a6405325 | |
parent | e223c012751857fbd048ff8f0503ce8570f495ee (diff) |
delete database when pressing reset-db
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 4 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/util/query.ts | 17 | ||||
-rw-r--r-- | packages/taler-wallet-webextension/src/wxBackend.ts | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index c457d0ffc..687418097 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -180,8 +180,8 @@ export async function openTalerDatabase( return new Database(mainDbHandle, Stores); } -export function deleteTalerDatabase(idbFactory: IDBFactory): void { - Database.deleteDatabase(idbFactory, TALER_DB_NAME); +export function deleteTalerDatabase(idbFactory: IDBFactory): Promise<void> { + return Database.deleteDatabase(idbFactory, TALER_DB_NAME); } export enum ReserveRecordStatus { diff --git a/packages/taler-wallet-core/src/util/query.ts b/packages/taler-wallet-core/src/util/query.ts index 1ef75a420..7c2aea783 100644 --- a/packages/taler-wallet-core/src/util/query.ts +++ b/packages/taler-wallet-core/src/util/query.ts @@ -372,7 +372,17 @@ function runWithTransaction<T, StoreTypes extends Store<string, {}>>( const stack = Error("Failed transaction was started here."); return new Promise((resolve, reject) => { const storeName = stores.map((x) => x.name); - const tx = db.transaction(storeName, mode); + + let txOrUndef: IDBTransaction | undefined = undefined + try { + txOrUndef = db.transaction(storeName, mode); + } catch (e) { + logger.error("error opening transaction"); + logger.error(`${e}`); + return + } + const tx = txOrUndef; + let funResult: any = undefined; let gotFunResult = false; tx.oncomplete = () => { @@ -513,8 +523,9 @@ export function openDatabase( export class Database<StoreMap extends AnyStoreMap> { constructor(private db: IDBDatabase, stores: StoreMap) {} - static deleteDatabase(idbFactory: IDBFactory, dbName: string): void { - idbFactory.deleteDatabase(dbName); + static deleteDatabase(idbFactory: IDBFactory, dbName: string): Promise<void> { + const req = idbFactory.deleteDatabase(dbName) + return requestToPromise(req) } async exportDatabase(): Promise<any> { diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts index cb7b9295f..745fe0366 100644 --- a/packages/taler-wallet-webextension/src/wxBackend.ts +++ b/packages/taler-wallet-webextension/src/wxBackend.ts @@ -33,6 +33,7 @@ import { Database, Stores, makeErrorDetails, + deleteTalerDatabase, } from "@gnu-taler/taler-wallet-core"; import { classifyTalerUri, @@ -121,6 +122,7 @@ async function dispatch( break; } case "reset-db": { + await deleteTalerDatabase(indexedDB); r = wrapResponse(await reinitWallet()); break; } |