From d4fda1eea86ef901d125078f1f4fe0fe4a141afb Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 20 Feb 2023 03:22:43 +0100 Subject: wallet-core: raw/effective amount for push transactions, fix transactions list for push/pull credit --- .../taler-wallet-core/src/operations/pay-peer.ts | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/pay-peer.ts') diff --git a/packages/taler-wallet-core/src/operations/pay-peer.ts b/packages/taler-wallet-core/src/operations/pay-peer.ts index ef2c19c33..6e5f1b89b 100644 --- a/packages/taler-wallet-core/src/operations/pay-peer.ts +++ b/packages/taler-wallet-core/src/operations/pay-peer.ts @@ -31,7 +31,7 @@ import { PreparePeerPullDebitRequest, PreparePeerPullDebitResponse, PreparePeerPushCredit, - CheckPeerPushPaymentResponse, + PreparePeerPushCreditResponse, Codec, codecForAmountString, codecForAny, @@ -100,7 +100,10 @@ import { import { getPeerPaymentBalanceDetailsInTx } from "./balance.js"; import { updateExchangeFromUrl } from "./exchanges.js"; import { getTotalRefreshCost } from "./refresh.js"; -import { internalCreateWithdrawalGroup } from "./withdraw.js"; +import { + getExchangeWithdrawalInfo, + internalCreateWithdrawalGroup, +} from "./withdraw.js"; const logger = new Logger("operations/peer-to-peer.ts"); @@ -623,7 +626,7 @@ export const codecForExchangePurseStatus = (): Codec => export async function preparePeerPushCredit( ws: InternalWalletState, req: PreparePeerPushCredit, -): Promise { +): Promise { const uri = parsePayPushUri(req.talerUri); if (!uri) { @@ -658,6 +661,8 @@ export async function preparePeerPushCredit( if (existing) { return { amount: existing.existingContractTerms.amount, + amountEffective: existing.existingPushInc.estimatedAmountEffective, + amountRaw: existing.existingContractTerms.amount, contractTerms: existing.existingContractTerms, peerPushPaymentIncomingId: existing.existingPushInc.peerPushPaymentIncomingId, @@ -705,6 +710,13 @@ export async function preparePeerPushCredit( const withdrawalGroupId = encodeCrock(getRandomBytes(32)); + const wi = await getExchangeWithdrawalInfo( + ws, + exchangeBaseUrl, + Amounts.parseOrThrow(purseStatus.balance), + undefined, + ); + await ws.db .mktx((x) => [x.contractTerms, x.peerPushPaymentIncoming]) .runReadWrite(async (tx) => { @@ -718,6 +730,10 @@ export async function preparePeerPushCredit( contractTermsHash, status: PeerPushPaymentIncomingStatus.Proposed, withdrawalGroupId, + currency: Amounts.currencyOf(purseStatus.balance), + estimatedAmountEffective: Amounts.stringify( + wi.withdrawalAmountEffective, + ), }); await tx.contractTerms.put({ @@ -728,6 +744,8 @@ export async function preparePeerPushCredit( return { amount: purseStatus.balance, + amountEffective: wi.withdrawalAmountEffective, + amountRaw: purseStatus.balance, contractTerms: dec.contractTerms, peerPushPaymentIncomingId, }; -- cgit v1.2.3