From 7ea8321ddd2d56f43dceaa18340f1d1c39a83e76 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 20 Jan 2023 15:41:08 -0300 Subject: introducing getBalanceDetail for getting all depositable/transferable amount for a currency --- .../taler-wallet-core/src/operations/balance.ts | 50 ++++++++++++++++++---- .../taler-wallet-core/src/operations/deposits.ts | 1 - 2 files changed, 42 insertions(+), 9 deletions(-) (limited to 'packages/taler-wallet-core/src/operations') diff --git a/packages/taler-wallet-core/src/operations/balance.ts b/packages/taler-wallet-core/src/operations/balance.ts index 27b801804..50613d0aa 100644 --- a/packages/taler-wallet-core/src/operations/balance.ts +++ b/packages/taler-wallet-core/src/operations/balance.ts @@ -48,14 +48,12 @@ */ import { AmountJson, - BalancesResponse, Amounts, - Logger, - AuditorHandle, - ExchangeHandle, + BalancesResponse, canonicalizeBaseUrl, + GetBalanceDetailRequest, + Logger, parsePaytoUri, - TalerErrorCode, } from "@gnu-taler/taler-util"; import { AllowedAuditorInfo, @@ -63,11 +61,10 @@ import { RefreshGroupRecord, WalletStoresV1, } from "../db.js"; -import { GetReadOnlyAccess } from "../util/query.js"; import { InternalWalletState } from "../internal-wallet-state.js"; -import { getExchangeDetails } from "./exchanges.js"; import { checkLogicInvariant } from "../util/invariants.js"; -import { TalerError } from "../errors.js"; +import { GetReadOnlyAccess } from "../util/query.js"; +import { getExchangeDetails } from "./exchanges.js"; /** * Logger. @@ -429,6 +426,43 @@ export async function getMerchantPaymentBalanceDetails( return d; } +export async function getBalanceDetail( + ws: InternalWalletState, + req: GetBalanceDetailRequest, +): Promise { + const exchanges: { exchangeBaseUrl: string; exchangePub: string }[] = []; + const wires = new Array(); + await ws.db + .mktx((x) => [x.exchanges, x.exchangeDetails]) + .runReadOnly(async (tx) => { + const allExchanges = await tx.exchanges.iter().toArray(); + for (const e of allExchanges) { + const details = await getExchangeDetails(tx, e.baseUrl); + if (!details || req.currency !== details.currency) { + continue; + } + details.wireInfo.accounts.forEach((a) => { + const payto = parsePaytoUri(a.payto_uri); + if (payto && !wires.includes(payto.targetType)) { + wires.push(payto.targetType); + } + }); + exchanges.push({ + exchangePub: details.masterPublicKey, + exchangeBaseUrl: e.baseUrl, + }); + } + }); + + return await getMerchantPaymentBalanceDetails(ws, { + currency: req.currency, + acceptedAuditors: [], + acceptedExchanges: exchanges, + acceptedWireMethods: wires, + minAge: 0, + }); +} + export interface PeerPaymentRestrictionsForBalance { currency: string; restrictExchangeTo?: string; diff --git a/packages/taler-wallet-core/src/operations/deposits.ts b/packages/taler-wallet-core/src/operations/deposits.ts index f3ec81686..e97738b55 100644 --- a/packages/taler-wallet-core/src/operations/deposits.ts +++ b/packages/taler-wallet-core/src/operations/deposits.ts @@ -457,7 +457,6 @@ export async function prepareDepositGroup( }; } - export async function createDepositGroup( ws: InternalWalletState, req: CreateDepositGroupRequest, -- cgit v1.2.3