also merge refund when getting transactionById
This commit is contained in:
parent
7ea8321ddd
commit
5f31dad2d3
@ -286,11 +286,6 @@ export async function getTransactionById(
|
|||||||
const purchase = await tx.purchases.get(proposalId);
|
const purchase = await tx.purchases.get(proposalId);
|
||||||
if (!purchase) throw Error("not found");
|
if (!purchase) throw Error("not found");
|
||||||
|
|
||||||
const theRefund = Object.values(purchase.refunds).find(
|
|
||||||
(r) => `${r.executionTime.t_s}` === executionTimeStr,
|
|
||||||
);
|
|
||||||
if (!theRefund) throw Error("not found");
|
|
||||||
|
|
||||||
const t = await tx.tombstones.get(
|
const t = await tx.tombstones.get(
|
||||||
makeTombstoneId(
|
makeTombstoneId(
|
||||||
TombstoneTag.DeleteRefund,
|
TombstoneTag.DeleteRefund,
|
||||||
@ -299,17 +294,41 @@ export async function getTransactionById(
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (t) throw Error("deleted");
|
if (t) throw Error("deleted");
|
||||||
|
|
||||||
|
const filteredRefunds = await Promise.all(
|
||||||
|
Object.values(purchase.refunds).map(async (r) => {
|
||||||
|
const t = await tx.tombstones.get(
|
||||||
|
makeTombstoneId(
|
||||||
|
TombstoneTag.DeleteRefund,
|
||||||
|
purchase.proposalId,
|
||||||
|
`${r.executionTime.t_s}`,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (!t) return r;
|
||||||
|
return undefined;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const cleanRefunds = filteredRefunds.filter(
|
||||||
|
(x): x is WalletRefundItem => !!x,
|
||||||
|
);
|
||||||
|
|
||||||
const download = await expectProposalDownload(ws, purchase, tx);
|
const download = await expectProposalDownload(ws, purchase, tx);
|
||||||
const contractData = download.contractData;
|
const contractData = download.contractData;
|
||||||
const refunds = mergeRefundByExecutionTime(
|
const refunds = mergeRefundByExecutionTime(
|
||||||
[theRefund],
|
cleanRefunds,
|
||||||
Amounts.zeroOfAmount(contractData.amount),
|
Amounts.zeroOfAmount(contractData.amount),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const theRefund = refunds.find(
|
||||||
|
(r) => `${r.executionTime.t_s}` === executionTimeStr,
|
||||||
|
);
|
||||||
|
if (!theRefund) throw Error("not found");
|
||||||
|
|
||||||
return buildTransactionForRefund(
|
return buildTransactionForRefund(
|
||||||
purchase,
|
purchase,
|
||||||
contractData,
|
contractData,
|
||||||
refunds[0],
|
theRefund,
|
||||||
undefined,
|
undefined,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user