calculate deposit wire transfer
This commit is contained in:
parent
b08bb05a40
commit
0f3b38745b
@ -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({
|
function TrackingDepositDetails({
|
||||||
trackingState,
|
trackingState,
|
||||||
}: {
|
}: {
|
||||||
@ -1578,18 +1610,7 @@ function TrackingDepositDetails({
|
|||||||
}): VNode {
|
}): VNode {
|
||||||
const { i18n } = useTranslationContext();
|
const { i18n } = useTranslationContext();
|
||||||
|
|
||||||
const trackByWtid = Object.values(trackingState ?? {}).reduce((prev, cur) => {
|
const wireTransfers = calculateAmountByWireTransfer(trackingState);
|
||||||
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),
|
|
||||||
}));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PurchaseDetailsTable>
|
<PurchaseDetailsTable>
|
||||||
|
Loading…
Reference in New Issue
Block a user