diff options
-rw-r--r-- | packages/taler-wallet-webextension/src/wallet/Transaction.tsx | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index d95b10297..58e50e7b6 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -1571,6 +1571,38 @@ function RefundDetails({ amount }: { amount: AmountWithFee }): VNode { ); } +type AmountAmountByWireTransferByWire = { + id: string; + amount: string; +}[]; + +function calculateAmountByWireTransfer( + state: TransactionDeposit["trackingState"], +): AmountAmountByWireTransferByWire { + const allTracking = Object.values(state ?? {}); + + //group tracking by wtid, sum amounts + const trackByWtid = allTracking.reduce((prev, cur) => { + const fee = Amounts.parseOrThrow(cur.wireFee); + const raw = Amounts.parseOrThrow(cur.amountRaw); + const total = !prev[cur.wireTransferId] + ? raw + : Amounts.add(prev[cur.wireTransferId].total, raw).amount; + + prev[cur.wireTransferId] = { + total, + fee, + }; + return prev; + }, {} as Record<string, { total: AmountJson; fee: AmountJson }>); + + //remove wire fee from total amount + return Object.entries(trackByWtid).map(([id, info]) => ({ + id, + amount: Amounts.stringify(Amounts.sub(info.total, info.fee).amount), + })); +} + function TrackingDepositDetails({ trackingState, }: { @@ -1578,18 +1610,7 @@ function TrackingDepositDetails({ }): VNode { const { i18n } = useTranslationContext(); - const trackByWtid = Object.values(trackingState ?? {}).reduce((prev, cur) => { - const am = Amounts.parseOrThrow(cur.amountEffective); - const sum = !prev[cur.wireTransferId] - ? am - : Amounts.add(prev[cur.wireTransferId], am).amount; - prev[cur.wireTransferId] = sum; - return prev; - }, {} as Record<string, AmountJson>); - const wireTransfers = Object.entries(trackByWtid).map(([id, amountJson]) => ({ - id, - amount: Amounts.stringify(amountJson), - })); + const wireTransfers = calculateAmountByWireTransfer(trackingState); return ( <PurchaseDetailsTable> |