diff options
author | Florian Dold <florian@dold.me> | 2023-05-24 14:20:48 +0200 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2023-05-24 14:20:48 +0200 |
commit | f475f98f86d03e808d2c88c13eafa712c2013fe3 (patch) | |
tree | 41bf18a150d4ae8cbe9f1ec33d72634ad1bf5e9e /packages/taler-wallet-core/src | |
parent | f14c7e5f2a1495613c16bcf1acf74d08fd91fb48 (diff) | |
download | wallet-core-f475f98f86d03e808d2c88c13eafa712c2013fe3.tar.xz |
wallet-core: fix getTransactionById for refunds
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/operations/transactions.ts | 71 |
1 files changed, 51 insertions, 20 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index 2e42eb8d8..b5a6ba74e 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -111,6 +111,7 @@ import { computeWithdrawalTransactionStatus, processWithdrawalGroup, } from "./withdraw.js"; +import { GetReadOnlyAccess, WalletStoresV1 } from "../index.js"; const logger = new Logger("taler-wallet-core:transactions.ts"); @@ -155,6 +156,7 @@ const txOrder: { [t in TransactionType]: number } = { [TransactionType.Deposit]: 9, [TransactionType.Refresh]: 10, [TransactionType.Tip]: 11, + [TransactionType.InternalWithdrawal]: 12, }; export async function getTransactionById( @@ -271,9 +273,23 @@ export async function getTransactionById( }); } - case TransactionType.Refund: - // FIXME! - throw Error("not implemented"); + case TransactionType.Refund: { + return await ws.db + .mktx((x) => [x.refundGroups, x.contractTerms, x.purchases]) + .runReadOnly(async (tx) => { + const refundRecord = await tx.refundGroups.get( + parsedTx.refundGroupId, + ); + if (!refundRecord) { + throw Error("not found"); + } + const contractData = await lookupMaybeContractData( + tx, + refundRecord?.proposalId, + ); + return buildTransactionForRefund(refundRecord, contractData); + }); + } case TransactionType.PeerPullDebit: { return await ws.db .mktx((x) => [x.peerPullPaymentIncoming]) @@ -829,6 +845,33 @@ function buildTransactionForTip( }; } +async function lookupMaybeContractData( + tx: GetReadOnlyAccess<{ + purchases: typeof WalletStoresV1.purchases; + contractTerms: typeof WalletStoresV1.contractTerms; + }>, + proposalId: string, +): Promise<WalletContractData | undefined> { + let contractData: WalletContractData | undefined = undefined; + const purchaseTx = await tx.purchases.get(proposalId); + if (purchaseTx && purchaseTx.download) { + const download = purchaseTx.download; + const contractTermsRecord = await tx.contractTerms.get( + download.contractTermsHash, + ); + if (!contractTermsRecord) { + return; + } + contractData = extractContractData( + contractTermsRecord?.contractTermsRaw, + download.contractTermsHash, + download.contractTermsMerchantSig, + ); + } + + return contractData; +} + async function buildTransactionForPurchase( purchaseRecord: PurchaseRecord, contractData: WalletContractData, @@ -1061,22 +1104,10 @@ export async function getTransactions( if (shouldSkipCurrency(transactionsRequest, currency)) { return; } - let contractData: WalletContractData | undefined = undefined; - const purchaseTx = await tx.purchases.get(refundGroup.proposalId); - if (purchaseTx && purchaseTx.download) { - const download = purchaseTx.download; - const contractTermsRecord = await tx.contractTerms.get( - download.contractTermsHash, - ); - if (!contractTermsRecord) { - return; - } - contractData = extractContractData( - contractTermsRecord?.contractTermsRaw, - download.contractTermsHash, - download.contractTermsMerchantSig, - ); - } + const contractData = await lookupMaybeContractData( + tx, + refundGroup.proposalId, + ); transactions.push(buildTransactionForRefund(refundGroup, contractData)); }); @@ -1704,7 +1735,7 @@ export async function deleteTransaction( } }); - return; + return; } case TransactionType.PeerPushDebit: { |