From ff46a080e55bff821f823256bed1bcebdcc1efe9 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 27 Feb 2024 12:28:39 -0300 Subject: forget tos operation and some pretty format --- packages/taler-wallet-core/src/exchanges.ts | 32 ++++++++++++++++++++++ packages/taler-wallet-core/src/query.ts | 4 +-- packages/taler-wallet-core/src/remote.ts | 4 ++- packages/taler-wallet-core/src/wallet-api-types.ts | 11 ++++++++ packages/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 index 65a9625c8..932df721d 100644 --- a/packages/taler-wallet-core/src/exchanges.ts +++ b/packages/taler-wallet-core/src/exchanges.ts @@ -411,6 +411,38 @@ export async function acceptExchangeTermsOfService( } } +/** + * Mark the current ToS version as accepted by the user. + */ +export async function forgetExchangeTermsOfService( + ws: InternalWalletState, + exchangeBaseUrl: string, +): Promise { + 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. * diff --git a/packages/taler-wallet-core/src/query.ts b/packages/taler-wallet-core/src/query.ts index 90a3cac70..4c169946c 100644 --- a/packages/taler-wallet-core/src/query.ts +++ b/packages/taler-wallet-core/src/query.ts @@ -795,9 +795,7 @@ export class DbAccess { runReadWriteTx>>( storeNames: StoreNameArray, - txf: ( - tx: DbReadWriteTransaction, - ) => Promise, + txf: (tx: DbReadWriteTransaction) => Promise, ): Promise { const accessibleStores: { [x: string]: StoreWithIndexes } = {}; diff --git a/packages/taler-wallet-core/src/remote.ts b/packages/taler-wallet-core/src/remote.ts index 030b7a943..b81c56e0c 100644 --- 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 index 1ed1eef87..9cd8e0135 100644 --- 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", @@ -678,6 +679,15 @@ export type SetExchangeTosAcceptedOp = { response: EmptyObject; }; +/** + * 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. */ @@ -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 index 779eefe26..f21ba6ec1 100644 --- 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( 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); -- cgit v1.2.3