From 6f2b03021d7946a61d6b8e53dbba7fc10e5f9a4d Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 8 Jan 2024 21:17:00 +0100 Subject: wallet-core: exchange management cleanup --- packages/taler-wallet-core/src/util/coinSelection.ts | 7 +++++-- .../src/util/instructedAmountConversion.ts | 18 +++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) (limited to 'packages/taler-wallet-core/src/util') diff --git a/packages/taler-wallet-core/src/util/coinSelection.ts b/packages/taler-wallet-core/src/util/coinSelection.ts index e3fbffe98..f24184609 100644 --- a/packages/taler-wallet-core/src/util/coinSelection.ts +++ b/packages/taler-wallet-core/src/util/coinSelection.ts @@ -57,7 +57,7 @@ import { import { DenominationRecord } from "../db.js"; import { getAutoRefreshExecuteThreshold, - getExchangeDetails, + getExchangeWireDetailsInTx, isWithdrawableDenom, WalletDbReadOnlyTransaction, } from "../index.js"; @@ -615,7 +615,10 @@ async function selectPayMerchantCandidates( const exchanges = await tx.exchanges.iter().toArray(); const wfPerExchange: Record = {}; for (const exchange of exchanges) { - const exchangeDetails = await getExchangeDetails(tx, exchange.baseUrl); + const exchangeDetails = await getExchangeWireDetailsInTx( + tx, + exchange.baseUrl, + ); // 1.- exchange has same currency if (exchangeDetails?.currency !== req.contractTermsAmount.currency) { continue; diff --git a/packages/taler-wallet-core/src/util/instructedAmountConversion.ts b/packages/taler-wallet-core/src/util/instructedAmountConversion.ts index 4365e6d32..caa3fdca5 100644 --- a/packages/taler-wallet-core/src/util/instructedAmountConversion.ts +++ b/packages/taler-wallet-core/src/util/instructedAmountConversion.ts @@ -33,7 +33,7 @@ import { import { DenominationRecord, InternalWalletState, - getExchangeDetails, + getExchangeWireDetailsInTx, timestampProtocolFromDb, } from "../index.js"; import { CoinInfo } from "./coinSelection.js"; @@ -61,8 +61,8 @@ function getOperationType(txType: TransactionType): OperationType { txType === TransactionType.Withdrawal ? OperationType.Credit : txType === TransactionType.Deposit - ? OperationType.Debit - : undefined; + ? OperationType.Debit + : undefined; if (!operationType) { throw Error(`operation type ${txType} not yet supported`); } @@ -155,7 +155,10 @@ async function getAvailableDenoms( filters.exchanges ?? databaseExchanges.map((e) => e.baseUrl); for (const exchangeBaseUrl of filteredExchanges) { - const exchangeDetails = await getExchangeDetails(tx, exchangeBaseUrl); + const exchangeDetails = await getExchangeWireDetailsInTx( + tx, + exchangeBaseUrl, + ); // 1.- exchange has same currency if (exchangeDetails?.currency !== currency) { continue; @@ -221,9 +224,10 @@ async function getAvailableDenoms( //4.- filter coins restricted by age if (operationType === OperationType.Credit) { // FIXME: Use denom groups instead of querying all denominations! - const ds = await tx.denominations.indexes.byExchangeBaseUrl.getAll( - exchangeBaseUrl, - ); + const ds = + await tx.denominations.indexes.byExchangeBaseUrl.getAll( + exchangeBaseUrl, + ); for (const denom of ds) { const expiresWithdraw = AbsoluteTime.fromProtocolTimestamp( timestampProtocolFromDb(denom.stampExpireWithdraw), -- cgit v1.2.3