taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit 0fdd0c48dc747d16a5a5fe4752873c91b353e614
parent f842f45f7ad89fcb3017ffcf1fb952b9cae0670b
Author: Florian Dold <florian@dold.me>
Date:   Fri,  4 Oct 2024 17:00:52 +0200

wallet-core: rudimentary support for showing KYC limits

See https://bugs.taler.net/n/9135

Diffstat:
Mpackages/taler-util/src/types-taler-wallet.ts | 8++++++++
Mpackages/taler-wallet-core/src/deposits.ts | 16+++++++++++++++-
Mpackages/taler-wallet-core/src/exchanges.ts | 2++
Mpackages/taler-wallet-core/src/pay-peer-push-credit.ts | 8+++++++-
Mpackages/taler-wallet-core/src/withdraw.ts | 4++++
5 files changed, 36 insertions(+), 2 deletions(-)

diff --git a/packages/taler-util/src/types-taler-wallet.ts b/packages/taler-util/src/types-taler-wallet.ts @@ -2358,6 +2358,14 @@ export interface CheckDepositResponse { totalDepositCost: AmountString; effectiveDepositAmount: AmountString; fees: DepositGroupFees; + + kycSoftLimit?: AmountString; + kycHardLimit?: AmountString; + + /** + * Base URL of exchanges that would likely require soft KYC. + */ + kycExchanges?: string[]; } export const codecForCreateDepositGroupRequest = diff --git a/packages/taler-wallet-core/src/deposits.ts b/packages/taler-wallet-core/src/deposits.ts @@ -42,7 +42,6 @@ import { KycAuthTransferInfo, Logger, MerchantContractTerms, - NotificationType, RefreshReason, SelectedProspectiveCoin, TalerError, @@ -109,11 +108,14 @@ import { timestampProtocolToDb, } from "./db.js"; import { + ReadyExchangeSummary, + fetchFreshExchange, getExchangeWireDetailsInTx, getExchangeWireFee, getScopeForAllExchanges, } from "./exchanges.js"; import { EddsaKeyPairStrings } from "./index.js"; +import { getDepositLimitInfo } from "./kyc.js"; import { extractContractData, generateDepositPermissions, @@ -1927,6 +1929,17 @@ export async function internalCheckDepositGroup( selCoins, ); + const usedExchangesSet = new Set<string>(); + for (const c of selCoins) { + usedExchangesSet.add(c.exchangeBaseUrl); + } + + const exchanges: ReadyExchangeSummary[] = []; + + for (const exchangeBaseUrl of usedExchangesSet) { + exchanges.push(await fetchFreshExchange(wex, exchangeBaseUrl)); + } + const fees = await getTotalFeesForDepositAmount( wex, p.targetType, @@ -1938,6 +1951,7 @@ export async function internalCheckDepositGroup( totalDepositCost: Amounts.stringify(totalDepositCost), effectiveDepositAmount: Amounts.stringify(effectiveDepositAmount), fees, + ...getDepositLimitInfo(exchanges, effectiveDepositAmount), }; } diff --git a/packages/taler-wallet-core/src/exchanges.ts b/packages/taler-wallet-core/src/exchanges.ts @@ -1265,6 +1265,7 @@ export interface ReadyExchangeSummary { protocolVersionRange: string; tosAcceptedTimestamp: TalerPreciseTimestamp | undefined; scopeInfo: ScopeInfo; + walletBalanceLimitWithoutKyc: AmountString[] | undefined; zeroLimits: ZeroLimitedOperation[]; hardLimits: AccountLimit[]; } @@ -1431,6 +1432,7 @@ async function waitReadyExchange( exchange.tosAcceptedTimestamp, ), scopeInfo, + walletBalanceLimitWithoutKyc: exchangeDetails.walletBalanceLimits, hardLimits: exchangeDetails.hardLimits ?? [], zeroLimits: exchangeDetails.zeroLimits ?? [], }; diff --git a/packages/taler-wallet-core/src/pay-peer-push-credit.ts b/packages/taler-wallet-core/src/pay-peer-push-credit.ts @@ -91,6 +91,7 @@ import { getScopeForAllExchanges, handleStartExchangeWalletKyc, } from "./exchanges.js"; +import { getPeerCreditLimitInfo } from "./kyc.js"; import { codecForExchangePurseStatus, getMergeReserveInfo, @@ -597,7 +598,7 @@ export async function preparePeerPushCredit( // add exchange entry if it doesn't exist already! const exchangeBaseUrl = uri.exchangeBaseUrl; - await fetchFreshExchange(wex, exchangeBaseUrl); + const exchange = await fetchFreshExchange(wex, exchangeBaseUrl); const existing = await wex.db.runReadOnlyTx( { storeNames: ["contractTerms", "peerPushCredit"] }, @@ -637,6 +638,10 @@ export async function preparePeerPushCredit( peerPushCreditId: existing.existingPushInc.peerPushCreditId, }), exchangeBaseUrl: existing.existingPushInc.exchangeBaseUrl, + ...getPeerCreditLimitInfo( + exchange, + existing.existingContractTerms.amount, + ), }; } @@ -749,6 +754,7 @@ export async function preparePeerPushCredit( peerPushCreditId, transactionId, exchangeBaseUrl, + ...getPeerCreditLimitInfo(exchange, purseStatus.balance), }; } diff --git a/packages/taler-wallet-core/src/withdraw.ts b/packages/taler-wallet-core/src/withdraw.ts @@ -173,6 +173,7 @@ import { lookupExchangeByUri, markExchangeUsed, } from "./exchanges.js"; +import { getWithdrawalLimitInfo } from "./kyc.js"; import { DbAccess } from "./query.js"; import { TransitionInfo, @@ -2581,6 +2582,7 @@ export async function getExchangeWithdrawalInfo( ? AGE_MASK_GROUPS : undefined, scopeInfo: exchange.scopeInfo, + ...getWithdrawalLimitInfo(exchange, instructedAmount), }; return ret; } @@ -4048,6 +4050,8 @@ export async function internalGetWithdrawalDetailsForAmount( withdrawalAccountsList: wi.exchangeCreditAccountDetails, numCoins, scopeInfo: wi.scopeInfo, + kycHardLimit: wi.kycHardLimit, + kycSoftLimit: wi.kycSoftLimit, }; return resp; }