aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-01-20 15:41:08 -0300
committerSebastian <sebasjm@gmail.com>2023-01-20 15:41:55 -0300
commit7ea8321ddd2d56f43dceaa18340f1d1c39a83e76 (patch)
tree9873eeb8fa836778d9c7fce1c6a778e7e8b6acaf /packages/taler-wallet-core/src/operations
parent81dda3b6b1500ed11b6ae539ce52a6c7e9a58951 (diff)
downloadwallet-core-7ea8321ddd2d56f43dceaa18340f1d1c39a83e76.tar.xz
introducing getBalanceDetail for getting all depositable/transferable amount for a currency
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r--packages/taler-wallet-core/src/operations/balance.ts50
-rw-r--r--packages/taler-wallet-core/src/operations/deposits.ts1
2 files changed, 42 insertions, 9 deletions
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<MerchantPaymentBalanceDetails> {
+ const exchanges: { exchangeBaseUrl: string; exchangePub: string }[] = [];
+ const wires = new Array<string>();
+ 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,