gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-wallet-core] 02/03: also merge refund when getting transactionByI


From: gnunet
Subject: [taler-wallet-core] 02/03: also merge refund when getting transactionById
Date: Fri, 20 Jan 2023 19:45:16 +0100

This is an automated email from the git hooks/post-receive script.

sebasjm pushed a commit to branch master
in repository wallet-core.

commit 5f31dad2d3af80ab0f53cc52a8740f9a37ca0e75
Author: Sebastian <sebasjm@gmail.com>
AuthorDate: Fri Jan 20 15:43:37 2023 -0300

    also merge refund when getting transactionById
---
 .../src/operations/transactions.ts                 | 33 +++++++++++++++++-----
 1 file changed, 26 insertions(+), 7 deletions(-)

diff --git a/packages/taler-wallet-core/src/operations/transactions.ts 
b/packages/taler-wallet-core/src/operations/transactions.ts
index 083b6618a..9951fd6b2 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -286,11 +286,6 @@ export async function getTransactionById(
         const purchase = await tx.purchases.get(proposalId);
         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(
           makeTombstoneId(
             TombstoneTag.DeleteRefund,
@@ -299,17 +294,41 @@ export async function getTransactionById(
           ),
         );
         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 contractData = download.contractData;
         const refunds = mergeRefundByExecutionTime(
-          [theRefund],
+          cleanRefunds,
           Amounts.zeroOfAmount(contractData.amount),
         );
 
+        const theRefund = refunds.find(
+          (r) => `${r.executionTime.t_s}` === executionTimeStr,
+        );
+        if (!theRefund) throw Error("not found");
+
         return buildTransactionForRefund(
           purchase,
           contractData,
-          refunds[0],
+          theRefund,
           undefined,
         );
       });

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]