taler-typescript-core

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

commit 3bf07a819c805b2c1df8afa995c2de4fd02b4257
parent b5c97cd5e0e743d48cbae3c62e423efb6f327e8c
Author: Florian Dold <florian@dold.me>
Date:   Wed,  2 Oct 2024 10:46:18 +0200

wallet-core: notify on exchange deletion

Diffstat:
Mpackages/taler-harness/src/integrationtests/test-wallet-dd48.ts | 9++++++---
Mpackages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts | 2+-
Mpackages/taler-util/src/notifications.ts | 4+++-
Mpackages/taler-wallet-core/src/exchanges.ts | 13++++++++++++-
Mpackages/taler-wallet-webextension/src/components/WalletActivity.tsx | 12++++++------
5 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-wallet-dd48.ts b/packages/taler-harness/src/integrationtests/test-wallet-dd48.ts @@ -29,7 +29,7 @@ import { import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { CoinConfig, defaultCoinConfig } from "../harness/denomStructures.js"; import { - BankService, + BankService, ExchangeService, GlobalTestState, WalletClient, @@ -69,7 +69,10 @@ export async function runWalletDd48Test(t: GlobalTestState) { await exchange.addBankAccount("1", { accountName: exchangeBankUsername, accountPassword: exchangeBankPassword, - wireGatewayApiBaseUrl: new URL("accounts/exchange/taler-wire-gateway/", bank.baseUrl).href, + wireGatewayApiBaseUrl: new URL( + "accounts/exchange/taler-wire-gateway/", + bank.baseUrl, + ).href, accountPaytoUri: exchangePaytoUri, }); @@ -178,7 +181,7 @@ export async function runWalletDd48Test(t: GlobalTestState) { (x) => x.type === NotificationType.ExchangeStateTransition && x.oldExchangeState == null && - x.newExchangeState.exchangeEntryStatus === + x.newExchangeState?.exchangeEntryStatus === ExchangeEntryStatus.Ephemeral, ), ); diff --git a/packages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts b/packages/taler-harness/src/integrationtests/test-wallet-exchange-update.ts @@ -180,7 +180,7 @@ export async function runWalletExchangeUpdateTest( console.log(`got notif ${j2s(n)}`); return ( n.type === NotificationType.ExchangeStateTransition && - n.newExchangeState.exchangeUpdateStatus === ExchangeUpdateStatus.Ready + n.newExchangeState?.exchangeUpdateStatus === ExchangeUpdateStatus.Ready ); }); diff --git a/packages/taler-util/src/notifications.ts b/packages/taler-util/src/notifications.ts @@ -85,8 +85,10 @@ export interface ExchangeStateTransitionNotification { /** * New state of the exchange. + * + * If missing, exchange got deleted. */ - newExchangeState: ExchangeEntryState; + newExchangeState?: ExchangeEntryState; /** * Summary of the error that occurred when trying to update the exchange entry, diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts @@ -2868,13 +2868,14 @@ export async function deleteExchange( ): Promise<void> { let inUse: boolean = false; const exchangeBaseUrl = req.exchangeBaseUrl; - await wex.db.runAllStoresReadWriteTx({}, async (tx) => { + const notif = await wex.db.runAllStoresReadWriteTx({}, async (tx) => { const exchangeRec = await tx.exchanges.get(exchangeBaseUrl); if (!exchangeRec) { // Nothing to delete! logger.info("no exchange found to delete"); return; } + const oldExchangeState = getExchangeState(exchangeRec); const res = await internalGetExchangeResources(wex, tx, exchangeBaseUrl); if (res.hasResources && !req.purge) { inUse = true; @@ -2882,6 +2883,13 @@ export async function deleteExchange( } await purgeExchange(wex, tx, exchangeBaseUrl); wex.ws.exchangeCache.clear(); + + return { + type: NotificationType.ExchangeStateTransition, + oldExchangeState, + newExchangeState: undefined, + exchangeBaseUrl, + } satisfies WalletNotification; }); if (inUse) { @@ -2890,6 +2898,9 @@ export async function deleteExchange( hint: "Exchange in use.", }); } + if (notif) { + wex.ws.notify(notif); + } } export async function getExchangeResources( diff --git a/packages/taler-wallet-webextension/src/components/WalletActivity.tsx b/packages/taler-wallet-webextension/src/components/WalletActivity.tsx @@ -312,34 +312,34 @@ function ShowExchangeStateTransition({ events }: MoreInfoPRops): VNode { <dt>Exchange</dt> <dd>{not.exchangeBaseUrl}</dd> {not.oldExchangeState && - not.newExchangeState.exchangeEntryStatus !== + not.newExchangeState?.exchangeEntryStatus !== not.oldExchangeState?.exchangeEntryStatus && ( <Fragment> <dt>Entry status</dt> <dd> from {not.oldExchangeState.exchangeEntryStatus} to{" "} - {not.newExchangeState.exchangeEntryStatus} + {not.newExchangeState?.exchangeEntryStatus} </dd> </Fragment> )} {not.oldExchangeState && - not.newExchangeState.exchangeUpdateStatus !== + not.newExchangeState?.exchangeUpdateStatus !== not.oldExchangeState?.exchangeUpdateStatus && ( <Fragment> <dt>Update status</dt> <dd> from {not.oldExchangeState.exchangeUpdateStatus} to{" "} - {not.newExchangeState.exchangeUpdateStatus} + {not.newExchangeState?.exchangeUpdateStatus} </dd> </Fragment> )} {not.oldExchangeState && - not.newExchangeState.tosStatus !== not.oldExchangeState?.tosStatus && ( + not.newExchangeState?.tosStatus !== not.oldExchangeState?.tosStatus && ( <Fragment> <dt>Tos status</dt> <dd> from {not.oldExchangeState.tosStatus} to{" "} - {not.newExchangeState.tosStatus} + {not.newExchangeState?.tosStatus} </dd> </Fragment> )}