aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations/transactions.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-04-22 14:17:49 +0200
committerFlorian Dold <florian@dold.me>2023-04-22 14:17:49 +0200
commit15feebecfeeda4758a96d1da99a98d9494c4bd2b (patch)
tree54a7536b93673202137927e097d4e5b5dcbc85eb /packages/taler-wallet-core/src/operations/transactions.ts
parente331012c9f8efef86c6a8a9297b44a67ba8cda66 (diff)
downloadwallet-core-15feebecfeeda4758a96d1da99a98d9494c4bd2b.tar.xz
wallet-core: towards DD37 for deposits
Diffstat (limited to 'packages/taler-wallet-core/src/operations/transactions.ts')
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts56
1 files changed, 25 insertions, 31 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 6a71b5c1e..884844ba6 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -35,10 +35,9 @@ import {
Transaction,
TransactionByIdRequest,
TransactionIdStr,
+ TransactionMajorState,
TransactionsRequest,
TransactionsResponse,
- TransactionState,
- TransactionSubstate,
TransactionType,
WithdrawalType,
} from "@gnu-taler/taler-util";
@@ -58,7 +57,7 @@ import {
WalletContractData,
PeerPushPaymentInitiationStatus,
PeerPullPaymentIncomingStatus,
- TransactionStatus,
+ DepositElementStatus,
WithdrawalGroupStatus,
RefreshGroupRecord,
RefreshOperationStatus,
@@ -79,7 +78,10 @@ import {
runOperationWithErrorReporting,
TombstoneTag,
} from "./common.js";
-import { processDepositGroup } from "./deposits.js";
+import {
+ computeDepositTransactionStatus,
+ processDepositGroup,
+} from "./deposits.js";
import { getExchangeDetails } from "./exchanges.js";
import {
abortPay,
@@ -425,6 +427,11 @@ export async function getTransactionById(
}
}
+// FIXME: Just a marker helper for unknown states until DD37 is fully implemented.
+const mkTxStateUnknown = () => ({
+ major: TransactionMajorState.Unknown,
+});
+
function buildTransactionForPushPaymentDebit(
pi: PeerPushPaymentInitiationRecord,
contractTerms: PeerContractTerms,
@@ -432,8 +439,7 @@ function buildTransactionForPushPaymentDebit(
): Transaction {
return {
type: TransactionType.PeerPushDebit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: pi.totalCost,
amountRaw: pi.amount,
exchangeBaseUrl: pi.exchangeBaseUrl,
@@ -466,8 +472,7 @@ function buildTransactionForPullPaymentDebit(
): Transaction {
return {
type: TransactionType.PeerPullDebit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: pi.coinSel?.totalCost
? pi.coinSel?.totalCost
: Amounts.stringify(pi.contractTerms.amount),
@@ -517,8 +522,7 @@ function buildTransactionForPeerPullCredit(
});
return {
type: TransactionType.PeerPullCredit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
amountRaw: Amounts.stringify(wsr.instructedAmount),
exchangeBaseUrl: wsr.exchangeBaseUrl,
@@ -553,8 +557,7 @@ function buildTransactionForPeerPullCredit(
return {
type: TransactionType.PeerPullCredit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: Amounts.stringify(pullCredit.estimatedAmountEffective),
amountRaw: Amounts.stringify(peerContractTerms.amount),
exchangeBaseUrl: pullCredit.exchangeBaseUrl,
@@ -593,8 +596,7 @@ function buildTransactionForPeerPushCredit(
return {
type: TransactionType.PeerPushCredit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
amountRaw: Amounts.stringify(wsr.instructedAmount),
exchangeBaseUrl: wsr.exchangeBaseUrl,
@@ -618,8 +620,7 @@ function buildTransactionForPeerPushCredit(
return {
type: TransactionType.PeerPushCredit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
// FIXME: This is wrong, needs to consider fees!
amountEffective: Amounts.stringify(peerContractTerms.amount),
amountRaw: Amounts.stringify(peerContractTerms.amount),
@@ -649,8 +650,7 @@ function buildTransactionForBankIntegratedWithdraw(
return {
type: TransactionType.Withdrawal,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
amountRaw: Amounts.stringify(wsr.instructedAmount),
withdrawalDetails: {
@@ -696,8 +696,7 @@ function buildTransactionForManualWithdraw(
return {
type: TransactionType.Withdrawal,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: Amounts.stringify(
withdrawalGroup.denomsSel.totalCoinValue,
),
@@ -748,8 +747,7 @@ function buildTransactionForRefresh(
).amount;
return {
type: TransactionType.Refresh,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
refreshReason: refreshGroupRecord.reason,
amountEffective: Amounts.stringify(
Amounts.zeroOfCurrency(refreshGroupRecord.currency),
@@ -791,8 +789,7 @@ function buildTransactionForDeposit(
return {
type: TransactionType.Deposit,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: computeDepositTransactionStatus(dg),
amountRaw: Amounts.stringify(dg.effectiveDepositAmount),
amountEffective: Amounts.stringify(dg.totalPayCost),
extendedStatus: dg.timestampFinished
@@ -810,7 +807,7 @@ function buildTransactionForDeposit(
wireTransferProgress:
(100 *
dg.transactionPerCoin.reduce(
- (prev, cur) => prev + (cur === TransactionStatus.Wired ? 1 : 0),
+ (prev, cur) => prev + (cur === DepositElementStatus.Wired ? 1 : 0),
0,
)) /
dg.transactionPerCoin.length,
@@ -829,8 +826,7 @@ function buildTransactionForTip(
return {
type: TransactionType.Tip,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountEffective: Amounts.stringify(tipRecord.tipAmountEffective),
amountRaw: Amounts.stringify(tipRecord.tipAmountRaw),
extendedStatus: tipRecord.pickedUpTimestamp
@@ -926,8 +922,7 @@ async function buildTransactionForRefund(
return {
type: TransactionType.Refund,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
info,
refundedTransactionId: makeTransactionId(
TransactionType.Payment,
@@ -1030,8 +1025,7 @@ async function buildTransactionForPurchase(
return {
type: TransactionType.Payment,
- txState: TransactionState.Unknown,
- txSubstate: TransactionSubstate.Unknown,
+ txState: mkTxStateUnknown(),
amountRaw: Amounts.stringify(contractData.amount),
amountEffective: Amounts.stringify(purchaseRecord.payInfo.totalPayCost),
totalRefundRaw: Amounts.stringify(totalRefund.raw),