From 671bbf29548e2ec078b29e75e368d77ee7bdb81f Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 2 Oct 2023 22:48:29 +0200 Subject: [PATCH] wallet-core: implement explicit updateExchangeEntry request --- packages/taler-util/src/wallet-types.ts | 9 +++++++++ packages/taler-wallet-core/src/wallet-api-types.ts | 12 ++++++++++++ packages/taler-wallet-core/src/wallet.ts | 9 +++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/taler-util/src/wallet-types.ts b/packages/taler-util/src/wallet-types.ts index c5c2c375c..8fff8ae55 100644 --- a/packages/taler-util/src/wallet-types.ts +++ b/packages/taler-util/src/wallet-types.ts @@ -1601,6 +1601,15 @@ export const codecForAddExchangeRequest = (): Codec => .property("masterPub", codecOptional(codecForString())) .build("AddExchangeRequest"); +export interface UpdateExchangeEntryRequest { + exchangeBaseUrl: string; +} + +export const codecForUpdateExchangeEntryRequest = (): Codec => + buildCodecForObject() + .property("exchangeBaseUrl", codecForString()) + .build("UpdateExchangeEntryRequest"); + export interface ForceExchangeUpdateRequest { exchangeBaseUrl: string; } diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 6d66e7ad3..26e86f43f 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -110,6 +110,7 @@ import { TransactionsRequest, TransactionsResponse, TxIdResponse, + UpdateExchangeEntryRequest, UserAttentionByIdRequest, UserAttentionsCountResponse, UserAttentionsRequest, @@ -222,6 +223,7 @@ export enum WalletApiOperation { CreateStoredBackup = "createStoredBackup", DeleteStoredBackup = "deleteStoredBackup", RecoverStoredBackup = "recoverStoredBackup", + UpdateExchangeEntry = "updateExchangeEntry", } // group: Initialization @@ -557,6 +559,15 @@ export type AddExchangeOp = { response: EmptyObject; }; +/** + * Update an exchange entry. + */ +export type UpdateExchangeEntryOp = { + op: WalletApiOperation.UpdateExchangeEntry; + request: UpdateExchangeEntryRequest; + response: EmptyObject; +}; + export type ListKnownBankAccountsOp = { op: WalletApiOperation.ListKnownBankAccounts; request: ListKnownBankAccountsRequest; @@ -1125,6 +1136,7 @@ export type WalletOperations = { [WalletApiOperation.ListStoredBackups]: ListStoredBackupsOp; [WalletApiOperation.DeleteStoredBackup]: DeleteStoredBackupOp; [WalletApiOperation.RecoverStoredBackup]: RecoverStoredBackupsOp; + [WalletApiOperation.UpdateExchangeEntry]: UpdateExchangeEntryOp; }; export type WalletCoreRequestType< diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 496297021..44076667d 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -128,6 +128,7 @@ import { codecForTestingSetTimetravelRequest, setDangerousTimetravel, TestingWaitTransactionRequest, + codecForUpdateExchangeEntryRequest, } from "@gnu-taler/taler-util"; import type { HttpRequestLibrary } from "@gnu-taler/taler-util/http"; import { readSuccessResponseJsonOrThrow } from "@gnu-taler/taler-util/http"; @@ -1071,8 +1072,7 @@ async function dispatchRequestInternal( case WalletApiOperation.WithdrawTestkudos: { await withdrawTestBalance(ws, { amount: "TESTKUDOS:10", - bankAccessApiBaseUrl: - "https://bank.test.taler.net/", + bankAccessApiBaseUrl: "https://bank.test.taler.net/", exchangeBaseUrl: "https://exchange.test.taler.net/", }); return { @@ -1122,6 +1122,11 @@ async function dispatchRequestInternal( }); return {}; } + case WalletApiOperation.UpdateExchangeEntry: { + const req = codecForUpdateExchangeEntryRequest().decode(payload); + await updateExchangeFromUrl(ws, req.exchangeBaseUrl, {}); + return {}; + } case WalletApiOperation.ListExchanges: { return await getExchanges(ws); }