aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2022-02-03 14:36:37 +0100
committerFlorian Dold <florian@dold.me>2022-02-03 14:36:37 +0100
commit5844a3065c8de9a676a19d13d8cf455f67b4ca10 (patch)
tree689717bbd6e5f6c68ad6ae538e9cba525d4de06e /packages
parent14d18065f9acb3e348de296b735e90fc73771439 (diff)
DB reset must be async
Diffstat (limited to 'packages')
-rw-r--r--packages/taler-wallet-core/src/db-utils.ts10
-rw-r--r--packages/taler-wallet-webextension/src/wxBackend.ts87
2 files changed, 55 insertions, 42 deletions
diff --git a/packages/taler-wallet-core/src/db-utils.ts b/packages/taler-wallet-core/src/db-utils.ts
index 336c7de27..af337d573 100644
--- a/packages/taler-wallet-core/src/db-utils.ts
+++ b/packages/taler-wallet-core/src/db-utils.ts
@@ -168,6 +168,12 @@ export async function openTalerDatabase(
return new DbAccess(mainDbHandle, WalletStoresV1);
}
-export function deleteTalerDatabase(idbFactory: IDBFactory): void {
- idbFactory.deleteDatabase(TALER_DB_NAME);
+export async function deleteTalerDatabase(
+ idbFactory: IDBFactory,
+): Promise<void> {
+ return new Promise((resolve, reject) => {
+ const req = idbFactory.deleteDatabase(TALER_DB_NAME);
+ req.onerror = () => reject(req.error);
+ req.onsuccess = () => resolve();
+ });
}
diff --git a/packages/taler-wallet-webextension/src/wxBackend.ts b/packages/taler-wallet-webextension/src/wxBackend.ts
index 085d7045e..a242e8a08 100644
--- a/packages/taler-wallet-webextension/src/wxBackend.ts
+++ b/packages/taler-wallet-webextension/src/wxBackend.ts
@@ -30,12 +30,17 @@ import {
NotificationType,
TalerErrorCode,
TalerUriType,
- WalletDiagnostics
+ WalletDiagnostics,
} from "@gnu-taler/taler-util";
import {
- DbAccess, deleteTalerDatabase, makeErrorDetails, OpenedPromise,
+ DbAccess,
+ deleteTalerDatabase,
+ makeErrorDetails,
+ OpenedPromise,
openPromise,
- openTalerDatabase, Wallet, WalletStoresV1
+ openTalerDatabase,
+ Wallet,
+ WalletStoresV1,
} from "@gnu-taler/taler-wallet-core";
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
import { BrowserHttpLib } from "./browserHttpLib";
@@ -55,7 +60,7 @@ let currentWallet: Wallet | undefined;
let currentDatabase: DbAccess<typeof WalletStoresV1> | undefined;
/**
- * Last version if an outdated DB, if applicable.
+ * Last version of an outdated DB, if applicable.
*/
let outdatedDbVersion: number | undefined;
@@ -128,9 +133,12 @@ async function dispatch(
}
case "wxGetExtendedPermissions": {
const res = await new Promise((resolve, reject) => {
- getPermissionsApi().contains(getReadRequestPermissions(), (result: boolean) => {
- resolve(result);
- });
+ getPermissionsApi().contains(
+ getReadRequestPermissions(),
+ (result: boolean) => {
+ resolve(result);
+ },
+ );
});
r = wrapResponse({ newValue: res });
break;
@@ -257,19 +265,15 @@ async function reinitWallet(): Promise<void> {
let cryptoWorker;
if (chrome.runtime.getManifest().manifest_version === 3) {
- httpLib = new ServiceWorkerHttpLib()
+ httpLib = new ServiceWorkerHttpLib();
cryptoWorker = new SynchronousCryptoWorkerFactory();
} else {
- httpLib = new BrowserHttpLib()
- cryptoWorker = new BrowserCryptoWorkerFactory()
+ httpLib = new BrowserHttpLib();
+ cryptoWorker = new BrowserCryptoWorkerFactory();
}
console.log("setting wallet");
- const wallet = await Wallet.create(
- currentDatabase,
- httpLib,
- cryptoWorker,
- );
+ const wallet = await Wallet.create(currentDatabase, httpLib, cryptoWorker);
try {
await wallet.handleCoreApiRequest("initWallet", "native-init", {});
} catch (e) {
@@ -402,30 +406,33 @@ function setupHeaderListener(): void {
// }
console.log("setting up header listener");
// Handlers for catching HTTP requests
- getPermissionsApi().contains(getReadRequestPermissions(), (result: boolean) => {
- if (
- "webRequest" in chrome &&
- "onHeadersReceived" in chrome.webRequest &&
- chrome.webRequest.onHeadersReceived.hasListener(headerListener)
- ) {
- chrome.webRequest.onHeadersReceived.removeListener(headerListener);
- }
- if (result) {
- console.log("actually adding listener");
- chrome.webRequest.onHeadersReceived.addListener(
- headerListener,
- { urls: ["<all_urls>"] },
- ["responseHeaders"]
- );
- }
- if ("webRequest" in chrome) {
- chrome.webRequest.handlerBehaviorChanged(() => {
- if (chrome.runtime.lastError) {
- console.error(chrome.runtime.lastError);
- }
- });
- }
- });
+ getPermissionsApi().contains(
+ getReadRequestPermissions(),
+ (result: boolean) => {
+ if (
+ "webRequest" in chrome &&
+ "onHeadersReceived" in chrome.webRequest &&
+ chrome.webRequest.onHeadersReceived.hasListener(headerListener)
+ ) {
+ chrome.webRequest.onHeadersReceived.removeListener(headerListener);
+ }
+ if (result) {
+ console.log("actually adding listener");
+ chrome.webRequest.onHeadersReceived.addListener(
+ headerListener,
+ { urls: ["<all_urls>"] },
+ ["responseHeaders"],
+ );
+ }
+ if ("webRequest" in chrome) {
+ chrome.webRequest.handlerBehaviorChanged(() => {
+ if (chrome.runtime.lastError) {
+ console.error(chrome.runtime.lastError);
+ }
+ });
+ }
+ },
+ );
}
/**
@@ -447,7 +454,7 @@ export async function wxMain(): Promise<void> {
chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
afterWalletIsInitialized.then(() => {
dispatch(req, sender, sendResponse);
- })
+ });
return true;
});