diff options
author | Sebastian <sebasjm@gmail.com> | 2023-03-31 14:51:58 -0300 |
---|---|---|
committer | Sebastian <sebasjm@gmail.com> | 2023-03-31 14:51:58 -0300 |
commit | 0f3b38745b7214abbbe638410a74fe5405ca24bb (patch) | |
tree | fbd701267012f7b7088fcb7a7ac54ff164ed96ba | |
parent | b08bb05a40ac42399bae12d65af4c5489c216786 (diff) |
calculate deposit wire transfer
-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> |