commit 1bddebd52d916c2e871ed6422446075f1b2d3335
parent 1a2737fd98b1ab7a9314394c9f1b04870b1a3b14
Author: Florian Dold <florian@dold.me>
Date: Fri, 22 Nov 2024 21:12:27 +0100
wallet-core: allow replacing known bank accounts with new payto URI
Diffstat:
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts
@@ -2005,13 +2005,31 @@ export const codecForListKnownBankAccounts =
.build("ListKnownBankAccountsRequest");
export interface AddKnownBankAccountRequest {
+ /**
+ * Payto URI of the bank account that should be added.
+ */
paytoUri: string;
+
+ /**
+ * Human-readable alias / label for the account.
+ */
alias: string;
+
+ /**
+ * Currencies supported by the bank (if known).
+ */
currencies?: string[] | undefined;
+
+ /**
+ * Bank account that this new account should replace.
+ */
+ replacePaytoUri?: string;
}
+
export const codecForAddKnownBankAccounts =
(): Codec<AddKnownBankAccountRequest> =>
buildCodecForObject<AddKnownBankAccountRequest>()
+ .property("replacePaytoUri", codecOptional(codecForString()))
.property("paytoUri", codecForString())
.property("alias", codecForString())
.property("currencies", codecOptional(codecForList(codecForString())))
diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts
@@ -946,7 +946,10 @@ async function handleAddKnownBankAccount(
req: AddKnownBankAccountRequest,
): Promise<EmptyObject> {
await wex.db.runReadWriteTx({ storeNames: ["bankAccounts"] }, async (tx) => {
- tx.bankAccounts.put({
+ if (req.replacePaytoUri) {
+ await tx.bankAccounts.delete(req.replacePaytoUri);
+ }
+ await tx.bankAccounts.put({
uri: req.paytoUri,
alias: req.alias,
currencies: req.currencies,