diff options
author | Florian Dold <florian@dold.me> | 2023-02-20 03:22:43 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-02-20 03:22:43 +0100 |
commit | d4fda1eea86ef901d125078f1f4fe0fe4a141afb (patch) | |
tree | 58c5ee16db7199eed263e0416ad4fa6ffa8a5765 /packages/taler-wallet-core/src/operations/pay-peer.ts | |
parent | c8b93a37ba78ffe24d9cc0548a1f8a0b3f1fb7de (diff) | |
download | wallet-core-d4fda1eea86ef901d125078f1f4fe0fe4a141afb.tar.xz |
wallet-core: raw/effective amount for push transactions, fix transactions list for push/pull credit
Diffstat (limited to 'packages/taler-wallet-core/src/operations/pay-peer.ts')
-rw-r--r-- | packages/taler-wallet-core/src/operations/pay-peer.ts | 24 |
1 files changed, 21 insertions, 3 deletions
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<ExchangePurseStatus> => export async function preparePeerPushCredit( ws: InternalWalletState, req: PreparePeerPushCredit, -): Promise<CheckPeerPushPaymentResponse> { +): Promise<PreparePeerPushCreditResponse> { 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, }; |