aboutsummaryrefslogtreecommitdiff
path: root/packages/taler-wallet-core/src/operations
diff options
context:
space:
mode:
authorFlorian Dold <florian@dold.me>2023-02-14 13:02:59 +0100
committerFlorian Dold <florian@dold.me>2023-02-14 13:02:59 +0100
commit55f868d5e83f577cd20ad6f33e0cf8776b4d0f45 (patch)
treea4bb2803384f558308552bc5606423a52090f79e /packages/taler-wallet-core/src/operations
parent97fac057c2f66cf8c00e50c555b761d5062fb4cf (diff)
downloadwallet-core-55f868d5e83f577cd20ad6f33e0cf8776b4d0f45.tar.xz
wallet-core: allow inclusion of refreshes in transactions list
Diffstat (limited to 'packages/taler-wallet-core/src/operations')
-rw-r--r--packages/taler-wallet-core/src/operations/transactions.ts53
1 files changed, 53 insertions, 0 deletions
diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts
index 8aae2332c..9ebd87cc0 100644
--- a/packages/taler-wallet-core/src/operations/transactions.ts
+++ b/packages/taler-wallet-core/src/operations/transactions.ts
@@ -56,6 +56,8 @@ import {
PeerPullPaymentIncomingStatus,
TransactionStatus,
WithdrawalGroupStatus,
+ RefreshGroupRecord,
+ RefreshOperationStatus,
} from "../db.js";
import { InternalWalletState } from "../internal-wallet-state.js";
import { checkDbInvariant } from "../util/invariants.js";
@@ -580,6 +582,45 @@ function buildTransactionForManualWithdraw(
};
}
+function buildTransactionForRefresh(
+ refreshGroupRecord: RefreshGroupRecord,
+ ort?: OperationRetryRecord,
+): Transaction {
+ let extendedStatus: ExtendedStatus;
+ switch (refreshGroupRecord.operationStatus) {
+ case RefreshOperationStatus.Finished:
+ case RefreshOperationStatus.FinishedWithError:
+ extendedStatus = ExtendedStatus.Done;
+ break;
+ default:
+ extendedStatus = ExtendedStatus.Pending;
+ }
+ return {
+ type: TransactionType.Refresh,
+ refreshReason: refreshGroupRecord.reason,
+ amountEffective: Amounts.stringify(
+ Amounts.zeroOfCurrency(refreshGroupRecord.currency),
+ ),
+ amountRaw: Amounts.stringify(
+ Amounts.zeroOfCurrency(refreshGroupRecord.currency),
+ ),
+ extendedStatus:
+ refreshGroupRecord.operationStatus === RefreshOperationStatus.Finished ||
+ refreshGroupRecord.operationStatus ===
+ RefreshOperationStatus.FinishedWithError
+ ? ExtendedStatus.Done
+ : ExtendedStatus.Pending,
+ pending: extendedStatus == ExtendedStatus.Pending,
+ timestamp: refreshGroupRecord.timestampCreated,
+ transactionId: makeTransactionId(
+ TransactionType.Refresh,
+ refreshGroupRecord.refreshGroupId,
+ ),
+ frozen: false,
+ ...(ort?.lastError ? { error: ort.lastError } : {}),
+ };
+}
+
function buildTransactionForDeposit(
dg: DepositGroupRecord,
ort?: OperationRetryRecord,
@@ -880,6 +921,7 @@ export async function getTransactions(
x.tips,
x.tombstones,
x.withdrawalGroups,
+ x.refreshGroups,
])
.runReadOnly(async (tx) => {
tx.peerPushPaymentInitiations.iter().forEachAsync(async (pi) => {
@@ -916,6 +958,17 @@ export async function getTransactions(
transactions.push(buildTransactionForPullPaymentDebit(pi));
});
+ if (transactionsRequest?.includeRefreshes) {
+ tx.refreshGroups.iter().forEachAsync(async (rg) => {
+ if (shouldSkipCurrency(transactionsRequest, rg.currency)) {
+ return;
+ }
+ const opId = RetryTags.forRefresh(rg);
+ const ort = await tx.operationRetries.get(opId);
+ transactions.push(buildTransactionForRefresh(rg, ort));
+ });
+ }
+
tx.withdrawalGroups.iter().forEachAsync(async (wsr) => {
if (
shouldSkipCurrency(