aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/wallet.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/taler-wallet-core/src/wallet.ts')
-rw-r--r--packages/taler-wallet-core/src/wallet.ts36
1 files changed, 27 insertions, 9 deletions
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
index f743e82b1..9f9b90446 100644
--- a/packages/taler-wallet-core/src/wallet.ts
+++ b/packages/taler-wallet-core/src/wallet.ts
@@ -22,7 +22,7 @@
/**
* Imports.
*/
-import { IDBFactory } from "@gnu-taler/idb-bridge";
+import { IDBDatabase, IDBFactory } from "@gnu-taler/idb-bridge";
import {
AbsoluteTime,
ActiveTask,
@@ -243,7 +243,7 @@ import {
checkPeerPushDebit,
initiatePeerPushDebit,
} from "./pay-peer-push-debit.js";
-import { DbAccess } from "./query.js";
+import { DbAccess, DbAccessImpl } from "./query.js";
import { forceRefresh } from "./refresh.js";
import {
TaskScheduler,
@@ -1020,7 +1020,7 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>(
const tasksInfo = await Promise.all(
allTasksId.map(async (id) => {
- return await wex.ws.db.runReadOnlyTx(
+ return await wex.db.runReadOnlyTx(
["operationRetries"],
async (tx) => {
return tx.operationRetries.get(id);
@@ -1758,15 +1758,19 @@ export class InternalWalletState {
private _config: Readonly<WalletRunConfig> | undefined;
- private _db: DbAccess<typeof WalletStoresV1> | undefined = undefined;
+ private _indexedDbHandle: IDBDatabase | undefined = undefined;
+
+ private _dbAccessHandle: DbAccess<typeof WalletStoresV1> | undefined;
private _http: HttpRequestLibrary | undefined = undefined;
get db(): DbAccess<typeof WalletStoresV1> {
- if (!this._db) {
- throw Error("db not initialized");
+ if (!this._dbAccessHandle) {
+ this._dbAccessHandle = this.createDbAccessHandle(
+ CancellationToken.CONTINUE,
+ );
}
- return this._db;
+ return this._dbAccessHandle;
}
devExperimentState: DevExperimentState = {};
@@ -1791,6 +1795,20 @@ export class InternalWalletState {
}
}
+ createDbAccessHandle(
+ cancellationToken: CancellationToken,
+ ): DbAccess<typeof WalletStoresV1> {
+ if (!this._indexedDbHandle) {
+ throw Error("db not initialized");
+ }
+ return new DbAccessImpl(
+ this._indexedDbHandle,
+ WalletStoresV1,
+ {},
+ cancellationToken,
+ );
+ }
+
get config(): WalletRunConfig {
if (!this._config) {
throw Error("config not initialized");
@@ -1817,7 +1835,7 @@ export class InternalWalletState {
}
async ensureWalletDbOpen(): Promise<void> {
- if (this._db) {
+ if (this._indexedDbHandle) {
return;
}
const myVersionChange = async (): Promise<void> => {
@@ -1825,7 +1843,7 @@ export class InternalWalletState {
};
try {
const myDb = await openTalerDatabase(this.idb, myVersionChange);
- this._db = myDb;
+ this._indexedDbHandle = myDb;
} catch (e) {
logger.error("error writing to database during initialization");
throw TalerError.fromDetail(TalerErrorCode.WALLET_DB_UNAVAILABLE, {