diff options
Diffstat (limited to 'packages/taler-wallet-core')
-rw-r--r-- | packages/taler-wallet-core/src/operations/balance.ts | 50 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/operations/deposits.ts | 1 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet-api-types.ts | 21 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/wallet.ts | 21 |
4 files changed, 73 insertions, 20 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, diff --git a/packages/taler-wallet-core/src/wallet-api-types.ts b/packages/taler-wallet-core/src/wallet-api-types.ts index 88ae3a5c1..f14018401 100644 --- a/packages/taler-wallet-core/src/wallet-api-types.ts +++ b/packages/taler-wallet-core/src/wallet-api-types.ts @@ -24,7 +24,7 @@ * Imports. */ import { - AbortTransactionRequest as AbortTransactionRequest, + AbortTransactionRequest, AcceptBankIntegratedWithdrawalRequest, AcceptExchangeTosRequest, AcceptManualWithdrawalRequest, @@ -56,6 +56,7 @@ import { ExchangesListResponse, ForceRefreshRequest, ForgetKnownBankAccountsRequest, + GetBalanceDetailRequest, GetContractTermsDetailsRequest, GetExchangeTosRequest, GetExchangeTosResult, @@ -66,14 +67,12 @@ import { InitiatePeerPullPaymentResponse, InitiatePeerPushPaymentRequest, InitiatePeerPushPaymentResponse, + InitRequest, InitResponse, IntegrationTestArgs, KnownBankAccounts, ListKnownBankAccountsRequest, ManualWithdrawalDetails, - UserAttentionsCountResponse, - UserAttentionsRequest, - UserAttentionsResponse, PrepareDepositRequest, PrepareDepositResponse, PreparePayRequest, @@ -99,14 +98,16 @@ import { TransactionByIdRequest, TransactionsRequest, TransactionsResponse, + UserAttentionByIdRequest, + UserAttentionsCountResponse, + UserAttentionsRequest, + UserAttentionsResponse, WalletBackupContentV1, WalletCoreVersion, WalletCurrencyInfo, WithdrawFakebankRequest, WithdrawTestBalanceRequest, WithdrawUriInfoResponse, - UserAttentionByIdRequest, - InitRequest, } from "@gnu-taler/taler-util"; import { WalletContractData } from "./db.js"; import { @@ -116,6 +117,7 @@ import { RemoveBackupProviderRequest, RunBackupCycleRequest, } from "./operations/backup/index.js"; +import { MerchantPaymentBalanceDetails } from "./operations/balance.js"; import { PendingOperationsResponse as PendingTasksResponse } from "./pending-types.js"; export enum WalletApiOperation { @@ -138,6 +140,7 @@ export enum WalletApiOperation { GetWithdrawalDetailsForAmount = "getWithdrawalDetailsForAmount", AcceptManualWithdrawal = "acceptManualWithdrawal", GetBalances = "getBalances", + GetBalanceDetail = "getBalanceDetail", GetUserAttentionRequests = "getUserAttentionRequests", GetUserAttentionUnreadCount = "getUserAttentionUnreadCount", MarkAttentionRequestAsRead = "markAttentionRequestAsRead", @@ -221,6 +224,11 @@ export type GetBalancesOp = { request: EmptyObject; response: BalancesResponse; }; +export type GetBalancesDetailOp = { + op: WalletApiOperation.GetBalanceDetail; + request: GetBalanceDetailRequest; + response: MerchantPaymentBalanceDetails; +}; // group: Managing Transactions @@ -831,6 +839,7 @@ export type WalletOperations = { [WalletApiOperation.ConfirmPay]: ConfirmPayOp; [WalletApiOperation.AbortTransaction]: AbortTransactionOp; [WalletApiOperation.GetBalances]: GetBalancesOp; + [WalletApiOperation.GetBalanceDetail]: GetBalancesDetailOp; [WalletApiOperation.GetTransactions]: GetTransactionsOp; [WalletApiOperation.GetTransactionById]: GetTransactionByIdOp; [WalletApiOperation.RetryPendingNow]: RetryPendingNowOp; diff --git a/packages/taler-wallet-core/src/wallet.ts b/packages/taler-wallet-core/src/wallet.ts index 24c7f7b9e..f1ed592bd 100644 --- a/packages/taler-wallet-core/src/wallet.ts +++ b/packages/taler-wallet-core/src/wallet.ts @@ -45,6 +45,7 @@ import { codecForDeleteTransactionRequest, codecForForceRefreshRequest, codecForForgetKnownBankAccounts, + codecForGetBalanceDetailRequest, codecForGetContractTermsDetails, codecForGetExchangeTosRequest, codecForGetFeeForDeposit, @@ -87,6 +88,7 @@ import { ExchangesListResponse, ExchangeTosStatusDetails, FeeDescription, + GetBalanceDetailRequest, GetExchangeTosResult, InitResponse, j2s, @@ -154,7 +156,11 @@ import { runBackupCycle, } from "./operations/backup/index.js"; import { setWalletDeviceId } from "./operations/backup/state.js"; -import { getBalances } from "./operations/balance.js"; +import { + getBalanceDetail, + getBalances, + getMerchantPaymentBalanceDetails, +} from "./operations/balance.js"; import { getExchangeTosStatus, makeExchangeListItem, @@ -948,9 +954,9 @@ async function dumpCoins(ws: InternalWalletState): Promise<CoinDumpJson> { ageCommitmentProof: c.ageCommitmentProof, spend_allocation: c.spendAllocation ? { - amount: c.spendAllocation.amount, - id: c.spendAllocation.id, - } + amount: c.spendAllocation.amount, + id: c.spendAllocation.id, + } : undefined, }); } @@ -1111,6 +1117,10 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( case WalletApiOperation.GetBalances: { return await getBalances(ws); } + case WalletApiOperation.GetBalanceDetail: { + const req = codecForGetBalanceDetailRequest().decode(payload); + return await getBalanceDetail(ws, req); + } case WalletApiOperation.GetUserAttentionRequests: { const req = codecForUserAttentionsRequest().decode(payload); return await getUserAttentions(ws, req); @@ -1350,7 +1360,8 @@ async function dispatchRequestInternal<Op extends WalletApiOperation>( { amount: Amounts.stringify(amount), reserve_pub: wres.reservePub, - debit_account: "payto://x-taler-bank/localhost/testdebtor?receiver-name=Foo", + debit_account: + "payto://x-taler-bank/localhost/testdebtor?receiver-name=Foo", }, ); const fbResp = await readSuccessResponseJsonOrThrow(fbReq, codecForAny()); |