summaryrefslogtreecommitdiff
path: root/src/operations/transactions.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/operations/transactions.ts')
-rw-r--r--src/operations/transactions.ts110
1 files changed, 80 insertions, 30 deletions
diff --git a/src/operations/transactions.ts b/src/operations/transactions.ts
index 9a3d48bb3..f2845cb18 100644
--- a/src/operations/transactions.ts
+++ b/src/operations/transactions.ts
@@ -32,7 +32,10 @@ import {
Transaction,
TransactionType,
PaymentStatus,
+ WithdrawalType,
+ WithdrawalDetails,
} from "../types/transactions";
+import { WithdrawalDetailsResponse } from "../types/walletTypes";
/**
* Create an event ID from the type and the primary key for the event.
@@ -156,6 +159,7 @@ export async function getTransactions(
Stores.reserveUpdatedEvents,
Stores.recoupGroups,
],
+ // Report withdrawals that are currently in progress.
async (tx) => {
tx.iter(Stores.withdrawalGroups).forEachAsync(async (wsr) => {
if (
@@ -171,34 +175,62 @@ export async function getTransactions(
return;
}
- let amountRaw: AmountJson | undefined = undefined;
-
- if (wsr.source.type === WithdrawalSourceType.Reserve) {
- const r = await tx.get(Stores.reserves, wsr.source.reservePub);
- if (r?.bankInfo?.amount) {
- amountRaw = r.bankInfo.amount;
+ switch (wsr.source.type) {
+ case WithdrawalSourceType.Reserve: {
+ const r = await tx.get(Stores.reserves, wsr.source.reservePub);
+ if (!r) {
+ break;
+ }
+ let amountRaw: AmountJson | undefined = undefined;
+ if (wsr.withdrawalGroupId === r.initialWithdrawalGroupId) {
+ amountRaw = r.instructedAmount;
+ } else {
+ amountRaw = wsr.denomsSel.totalWithdrawCost;
+ }
+ let withdrawalDetails: WithdrawalDetails;
+ if (r.bankInfo) {
+ withdrawalDetails = {
+ type: WithdrawalType.TalerBankIntegrationApi,
+ confirmed: true,
+ bankConfirmationUrl: r.bankInfo.confirmUrl,
+ };
+ } else {
+ const exchange = await tx.get(Stores.exchanges, r.exchangeBaseUrl);
+ if (!exchange) {
+ // FIXME: report somehow
+ break;
+ }
+ withdrawalDetails = {
+ type: WithdrawalType.ManualTransfer,
+ reservePublicKey: r.reservePub,
+ exchangePaytoUris: exchange.wireInfo?.accounts.map((x) => x.payto_uri) ?? [],
+ };
+ }
+ transactions.push({
+ type: TransactionType.Withdrawal,
+ amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
+ amountRaw: Amounts.stringify(amountRaw),
+ withdrawalDetails,
+ exchangeBaseUrl: wsr.exchangeBaseUrl,
+ pending: !wsr.timestampFinish,
+ timestamp: wsr.timestampStart,
+ transactionId: makeEventId(
+ TransactionType.Withdrawal,
+ wsr.withdrawalGroupId,
+ ),
+ });
}
+ break;
+ default:
+ // Tips are reported via their own event
+ break;
}
- if (!amountRaw) {
- amountRaw = wsr.denomsSel.totalWithdrawCost;
- }
-
- transactions.push({
- type: TransactionType.Withdrawal,
- amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
- amountRaw: Amounts.stringify(amountRaw),
- confirmed: true,
- exchangeBaseUrl: wsr.exchangeBaseUrl,
- pending: !wsr.timestampFinish,
- timestamp: wsr.timestampStart,
- transactionId: makeEventId(
- TransactionType.Withdrawal,
- wsr.withdrawalGroupId,
- ),
- });
});
- tx.iter(Stores.reserves).forEach((r) => {
+ // Report pending withdrawals based on reserves that
+ // were created, but where the actual withdrawal group has
+ // not started yet.
+ tx.iter(Stores.reserves).forEachAsync(async (r) => {
if (shouldSkipCurrency(transactionsRequest, r.currency)) {
return;
}
@@ -213,23 +245,41 @@ export async function getTransactions(
default:
return;
}
- if (!r.bankInfo) {
+ if (r.initialWithdrawalStarted) {
return;
}
+ let withdrawalDetails: WithdrawalDetails;
+ if (r.bankInfo) {
+ withdrawalDetails = {
+ type: WithdrawalType.TalerBankIntegrationApi,
+ confirmed: false,
+ bankConfirmationUrl: r.bankInfo.confirmUrl,
+ }
+ } else {
+ const exchange = await tx.get(Stores.exchanges, r.exchangeBaseUrl);
+ if (!exchange) {
+ // FIXME: report somehow
+ return;
+ }
+ withdrawalDetails = {
+ type: WithdrawalType.ManualTransfer,
+ reservePublicKey: r.reservePub,
+ exchangePaytoUris: exchange.wireInfo?.accounts.map((x) => x.payto_uri) ?? [],
+ };
+ }
transactions.push({
type: TransactionType.Withdrawal,
- confirmed: false,
- amountRaw: Amounts.stringify(r.bankInfo.amount),
+ amountRaw: Amounts.stringify(r.instructedAmount),
amountEffective: Amounts.stringify(
- r.bankInfo.denomSel.totalCoinValue,
+ r.initialDenomSel.totalCoinValue,
),
exchangeBaseUrl: r.exchangeBaseUrl,
pending: true,
timestamp: r.timestampCreated,
- bankConfirmationUrl: r.bankInfo.confirmUrl,
+ withdrawalDetails: withdrawalDetails,
transactionId: makeEventId(
TransactionType.Withdrawal,
- r.bankInfo.bankWithdrawalGroupId,
+ r.initialWithdrawalGroupId,
),
});
});