DB reset must be async
This commit is contained in:
parent
14d18065f9
commit
5844a3065c
@ -168,6 +168,12 @@ export async function openTalerDatabase(
|
|||||||
return new DbAccess(mainDbHandle, WalletStoresV1);
|
return new DbAccess(mainDbHandle, WalletStoresV1);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteTalerDatabase(idbFactory: IDBFactory): void {
|
export async function deleteTalerDatabase(
|
||||||
idbFactory.deleteDatabase(TALER_DB_NAME);
|
idbFactory: IDBFactory,
|
||||||
|
): Promise<void> {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const req = idbFactory.deleteDatabase(TALER_DB_NAME);
|
||||||
|
req.onerror = () => reject(req.error);
|
||||||
|
req.onsuccess = () => resolve();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,17 @@ import {
|
|||||||
NotificationType,
|
NotificationType,
|
||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
TalerUriType,
|
TalerUriType,
|
||||||
WalletDiagnostics
|
WalletDiagnostics,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
import {
|
import {
|
||||||
DbAccess, deleteTalerDatabase, makeErrorDetails, OpenedPromise,
|
DbAccess,
|
||||||
|
deleteTalerDatabase,
|
||||||
|
makeErrorDetails,
|
||||||
|
OpenedPromise,
|
||||||
openPromise,
|
openPromise,
|
||||||
openTalerDatabase, Wallet, WalletStoresV1
|
openTalerDatabase,
|
||||||
|
Wallet,
|
||||||
|
WalletStoresV1,
|
||||||
} from "@gnu-taler/taler-wallet-core";
|
} from "@gnu-taler/taler-wallet-core";
|
||||||
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
|
import { BrowserCryptoWorkerFactory } from "./browserCryptoWorkerFactory";
|
||||||
import { BrowserHttpLib } from "./browserHttpLib";
|
import { BrowserHttpLib } from "./browserHttpLib";
|
||||||
@ -55,7 +60,7 @@ let currentWallet: Wallet | undefined;
|
|||||||
let currentDatabase: DbAccess<typeof WalletStoresV1> | 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;
|
let outdatedDbVersion: number | undefined;
|
||||||
|
|
||||||
@ -128,9 +133,12 @@ async function dispatch(
|
|||||||
}
|
}
|
||||||
case "wxGetExtendedPermissions": {
|
case "wxGetExtendedPermissions": {
|
||||||
const res = await new Promise((resolve, reject) => {
|
const res = await new Promise((resolve, reject) => {
|
||||||
getPermissionsApi().contains(getReadRequestPermissions(), (result: boolean) => {
|
getPermissionsApi().contains(
|
||||||
resolve(result);
|
getReadRequestPermissions(),
|
||||||
});
|
(result: boolean) => {
|
||||||
|
resolve(result);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
r = wrapResponse({ newValue: res });
|
r = wrapResponse({ newValue: res });
|
||||||
break;
|
break;
|
||||||
@ -257,19 +265,15 @@ async function reinitWallet(): Promise<void> {
|
|||||||
let cryptoWorker;
|
let cryptoWorker;
|
||||||
|
|
||||||
if (chrome.runtime.getManifest().manifest_version === 3) {
|
if (chrome.runtime.getManifest().manifest_version === 3) {
|
||||||
httpLib = new ServiceWorkerHttpLib()
|
httpLib = new ServiceWorkerHttpLib();
|
||||||
cryptoWorker = new SynchronousCryptoWorkerFactory();
|
cryptoWorker = new SynchronousCryptoWorkerFactory();
|
||||||
} else {
|
} else {
|
||||||
httpLib = new BrowserHttpLib()
|
httpLib = new BrowserHttpLib();
|
||||||
cryptoWorker = new BrowserCryptoWorkerFactory()
|
cryptoWorker = new BrowserCryptoWorkerFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("setting wallet");
|
console.log("setting wallet");
|
||||||
const wallet = await Wallet.create(
|
const wallet = await Wallet.create(currentDatabase, httpLib, cryptoWorker);
|
||||||
currentDatabase,
|
|
||||||
httpLib,
|
|
||||||
cryptoWorker,
|
|
||||||
);
|
|
||||||
try {
|
try {
|
||||||
await wallet.handleCoreApiRequest("initWallet", "native-init", {});
|
await wallet.handleCoreApiRequest("initWallet", "native-init", {});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -402,30 +406,33 @@ function setupHeaderListener(): void {
|
|||||||
// }
|
// }
|
||||||
console.log("setting up header listener");
|
console.log("setting up header listener");
|
||||||
// Handlers for catching HTTP requests
|
// Handlers for catching HTTP requests
|
||||||
getPermissionsApi().contains(getReadRequestPermissions(), (result: boolean) => {
|
getPermissionsApi().contains(
|
||||||
if (
|
getReadRequestPermissions(),
|
||||||
"webRequest" in chrome &&
|
(result: boolean) => {
|
||||||
"onHeadersReceived" in chrome.webRequest &&
|
if (
|
||||||
chrome.webRequest.onHeadersReceived.hasListener(headerListener)
|
"webRequest" in chrome &&
|
||||||
) {
|
"onHeadersReceived" in chrome.webRequest &&
|
||||||
chrome.webRequest.onHeadersReceived.removeListener(headerListener);
|
chrome.webRequest.onHeadersReceived.hasListener(headerListener)
|
||||||
}
|
) {
|
||||||
if (result) {
|
chrome.webRequest.onHeadersReceived.removeListener(headerListener);
|
||||||
console.log("actually adding listener");
|
}
|
||||||
chrome.webRequest.onHeadersReceived.addListener(
|
if (result) {
|
||||||
headerListener,
|
console.log("actually adding listener");
|
||||||
{ urls: ["<all_urls>"] },
|
chrome.webRequest.onHeadersReceived.addListener(
|
||||||
["responseHeaders"]
|
headerListener,
|
||||||
);
|
{ urls: ["<all_urls>"] },
|
||||||
}
|
["responseHeaders"],
|
||||||
if ("webRequest" in chrome) {
|
);
|
||||||
chrome.webRequest.handlerBehaviorChanged(() => {
|
}
|
||||||
if (chrome.runtime.lastError) {
|
if ("webRequest" in chrome) {
|
||||||
console.error(chrome.runtime.lastError);
|
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) => {
|
chrome.runtime.onMessage.addListener((req, sender, sendResponse) => {
|
||||||
afterWalletIsInitialized.then(() => {
|
afterWalletIsInitialized.then(() => {
|
||||||
dispatch(req, sender, sendResponse);
|
dispatch(req, sender, sendResponse);
|
||||||
})
|
});
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user