commit 020ec4b9859295c04b5debef7069352739ace8c2
parent 9027bda3becfe59cde4e9db6f2ad06802746b2c8
Author: Florian Dold <dold@taler.net>
Date: Sat, 22 Aug 2026 14:13:06 +0200
wallet-core: notify balance changes for global currency configuration
Diffstat:
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/packages/taler-wallet-core/src/requests.test.ts b/packages/taler-wallet-core/src/requests.test.ts
@@ -188,6 +188,7 @@ test("removing one global exchange retains shared currency metadata", async () =
},
];
let currencyInfoDeletes = 0;
+ let balanceNotifications = 0;
const tx = {
async getGlobalCurrencyExchange(
currency: string,
@@ -218,7 +219,12 @@ test("removing one global exchange retains shared currency metadata", async () =
): Promise<T> {
return f(tx);
},
- ws: { exchangeCache: { clear() {} } },
+ ws: {
+ exchangeCache: { clear() {} },
+ notify(notification) {
+ if (notification.type === "balance-change") balanceNotifications++;
+ },
+ },
} as WalletExecutionContext;
await handleRemoveGlobalCurrencyExchange(wex, {
@@ -234,6 +240,7 @@ test("removing one global exchange retains shared currency metadata", async () =
exchangeMasterPub: "master-two",
});
assert.strictEqual(currencyInfoDeletes, 1);
+ assert.strictEqual(balanceNotifications, 2);
});
function makeCoinSuspensionContext(
diff --git a/packages/taler-wallet-core/src/requests.ts b/packages/taler-wallet-core/src/requests.ts
@@ -1672,14 +1672,14 @@ export async function handleAddGlobalCurrencyExchange(
wex: WalletExecutionContext,
req: AddGlobalCurrencyExchangeRequest,
): Promise<EmptyObject> {
- await wex.runWalletDbTx(async (tx) => {
+ const changed = await wex.runWalletDbTx(async (tx) => {
const existingRec = await tx.getGlobalCurrencyExchange(
req.currency,
req.exchangeBaseUrl,
req.exchangeMasterPub,
);
if (existingRec) {
- return;
+ return false;
}
wex.ws.exchangeCache.clear();
// Re-scope currency info from exchange scope to global scope. The scope
@@ -1702,7 +1702,13 @@ export async function handleAddGlobalCurrencyExchange(
exchangeBaseUrl: req.exchangeBaseUrl,
exchangeMasterPub: req.exchangeMasterPub,
});
+ return true;
});
+ if (changed)
+ wex.ws.notify({
+ type: NotificationType.BalanceChange,
+ hintTransactionId: "global-currency-config",
+ });
return {};
}
@@ -1710,14 +1716,14 @@ async function handleRemoveGlobalCurrencyAuditor(
wex: WalletExecutionContext,
req: RemoveGlobalCurrencyAuditorRequest,
): Promise<EmptyObject> {
- await wex.runWalletDbTx(async (tx) => {
+ const changed = await wex.runWalletDbTx(async (tx) => {
const existingRec = await tx.getGlobalCurrencyAuditor(
req.currency,
req.auditorBaseUrl,
req.auditorPub,
);
if (!existingRec) {
- return;
+ return false;
}
checkDbInvariant(
!!existingRec.id,
@@ -1725,7 +1731,13 @@ async function handleRemoveGlobalCurrencyAuditor(
);
await tx.deleteGlobalCurrencyAuditor(existingRec.id);
wex.ws.exchangeCache.clear();
+ return true;
});
+ if (changed)
+ wex.ws.notify({
+ type: NotificationType.BalanceChange,
+ hintTransactionId: "global-currency-config",
+ });
return {};
}
@@ -1733,14 +1745,14 @@ export async function handleRemoveGlobalCurrencyExchange(
wex: WalletExecutionContext,
req: RemoveGlobalCurrencyExchangeRequest,
): Promise<EmptyObject> {
- await wex.runWalletDbTx(async (tx) => {
+ const changed = await wex.runWalletDbTx(async (tx) => {
const existingRec = await tx.getGlobalCurrencyExchange(
req.currency,
req.exchangeBaseUrl,
req.exchangeMasterPub,
);
if (!existingRec) {
- return;
+ return false;
}
wex.ws.exchangeCache.clear();
checkDbInvariant(
@@ -1755,7 +1767,13 @@ export async function handleRemoveGlobalCurrencyExchange(
currency: req.currency,
});
}
+ return true;
});
+ if (changed)
+ wex.ws.notify({
+ type: NotificationType.BalanceChange,
+ hintTransactionId: "global-currency-config",
+ });
return {};
}
@@ -1763,14 +1781,14 @@ async function handleAddGlobalCurrencyAuditor(
wex: WalletExecutionContext,
req: AddGlobalCurrencyAuditorRequest,
): Promise<EmptyObject> {
- await wex.runWalletDbTx(async (tx) => {
+ const changed = await wex.runWalletDbTx(async (tx) => {
const existingRec = await tx.getGlobalCurrencyAuditor(
req.currency,
req.auditorBaseUrl,
req.auditorPub,
);
if (existingRec) {
- return;
+ return false;
}
await tx.upsertGlobalCurrencyAuditor({
currency: req.currency,
@@ -1778,7 +1796,13 @@ async function handleAddGlobalCurrencyAuditor(
auditorPub: req.auditorPub,
});
wex.ws.exchangeCache.clear();
+ return true;
});
+ if (changed)
+ wex.ws.notify({
+ type: NotificationType.BalanceChange,
+ hintTransactionId: "global-currency-config",
+ });
return {};
}