taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit ff46a080e55bff821f823256bed1bcebdcc1efe9
parent a32836935be4638d5252dbaef3fea17d8e2bee6a
Author: Sebastian <sebasjm@gmail.com>
Date:   Tue, 27 Feb 2024 12:28:39 -0300

forget tos operation and some pretty format

Diffstat:
Mpackages/taler-wallet-core/src/exchanges.ts | 32++++++++++++++++++++++++++++++++
Mpackages/taler-wallet-core/src/query.ts | 4+---
Mpackages/taler-wallet-core/src/remote.ts | 4+++-
Mpackages/taler-wallet-core/src/wallet-api-types.ts | 11+++++++++++
Mpackages/taler-wallet-core/src/wallet.ts | 6++++++
5 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts @@ -412,6 +412,38 @@ export async function acceptExchangeTermsOfService( } /** + * Mark the current ToS version as accepted by the user. + */ +export async function forgetExchangeTermsOfService( + ws: InternalWalletState, + exchangeBaseUrl: string, +): Promise<void> { + const notif = await ws.db.runReadWriteTx( + ["exchangeDetails", "exchanges"], + async (tx) => { + const exch = await tx.exchanges.get(exchangeBaseUrl); + if (exch) { + const oldExchangeState = getExchangeState(exch); + exch.tosAcceptedEtag = undefined; + exch.tosAcceptedTimestamp = undefined; + await tx.exchanges.put(exch); + const newExchangeState = getExchangeState(exch); + return { + type: NotificationType.ExchangeStateTransition, + exchangeBaseUrl, + newExchangeState: newExchangeState, + oldExchangeState: oldExchangeState, + } satisfies WalletNotification; + } + return undefined; + }, + ); + if (notif) { + ws.notify(notif); + } +} + +/** * Validate wire fees and wire accounts. * * Throw an exception if they are invalid. diff --git a/packages/taler-wallet-core/src/query.ts b/packages/taler-wallet-core/src/query.ts @@ -795,9 +795,7 @@ export class DbAccess<StoreMap> { runReadWriteTx<T, StoreNameArray extends Array<StoreNames<StoreMap>>>( storeNames: StoreNameArray, - txf: ( - tx: DbReadWriteTransaction<StoreMap, StoreNameArray>, - ) => Promise<T>, + txf: (tx: DbReadWriteTransaction<StoreMap, StoreNameArray>) => Promise<T>, ): Promise<T> { const accessibleStores: { [x: string]: StoreWithIndexes<any, any, any> } = {}; diff --git a/packages/taler-wallet-core/src/remote.ts b/packages/taler-wallet-core/src/remote.ts @@ -108,7 +108,9 @@ export async function createRemoteWallet( } const h = requestMap.get(id); if (!h) { - logger.warn(`${args.name}: no handler registered for response id ${id}`); + logger.warn( + `${args.name}: no handler registered for response id ${id}`, + ); return; } h.promiseCapability.resolve(m as any); diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -185,6 +185,7 @@ export enum WalletApiOperation { MarkAttentionRequestAsRead = "markAttentionRequestAsRead", GetPendingOperations = "getPendingOperations", SetExchangeTosAccepted = "setExchangeTosAccepted", + SetExchangeTosForgotten = "SetExchangeTosForgotten", StartRefundQueryForUri = "startRefundQueryForUri", StartRefundQuery = "startRefundQuery", AcceptBankIntegratedWithdrawal = "acceptBankIntegratedWithdrawal", @@ -679,6 +680,15 @@ export type SetExchangeTosAcceptedOp = { }; /** + * Accept a particular version of the exchange terms of service. + */ +export type SetExchangeTosForgottenOp = { + op: WalletApiOperation.SetExchangeTosForgotten; + request: AcceptExchangeTosRequest; + response: EmptyObject; +}; + +/** * Get the current terms of a service of an exchange. */ export type GetExchangeTosOp = { @@ -1197,6 +1207,7 @@ export type WalletOperations = { [WalletApiOperation.AddKnownBankAccounts]: AddKnownBankAccountsOp; [WalletApiOperation.ForgetKnownBankAccounts]: ForgetKnownBankAccountsOp; [WalletApiOperation.SetExchangeTosAccepted]: SetExchangeTosAcceptedOp; + [WalletApiOperation.SetExchangeTosForgotten]: SetExchangeTosForgottenOp; [WalletApiOperation.GetExchangeTos]: GetExchangeTosOp; [WalletApiOperation.GetExchangeDetailedInfo]: GetExchangeDetailedInfoOp; [WalletApiOperation.GetExchangeEntryByUrl]: GetExchangeEntryByUrlOp; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts @@ -184,6 +184,7 @@ import { addPresetExchangeEntry, deleteExchange, fetchFreshExchange, + forgetExchangeTermsOfService, getExchangeDetailedInfo, getExchangeResources, getExchangeTos, @@ -871,6 +872,11 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( await acceptExchangeTermsOfService(ws, req.exchangeBaseUrl); return {}; } + case WalletApiOperation.SetExchangeTosForgotten: { + const req = codecForAcceptExchangeTosRequest().decode(payload); + await forgetExchangeTermsOfService(ws, req.exchangeBaseUrl); + return {}; + } case WalletApiOperation.AcceptBankIntegratedWithdrawal: { const req = codecForAcceptBankIntegratedWithdrawalRequest().decode(payload);