wallet-core: remove legacy non-DD37 tx status fields

This commit is contained in:
Florian Dold 2023-05-24 14:46:03 +02:00
parent f475f98f86
commit a2ef2e391a
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
9 changed files with 40 additions and 150 deletions

View File

@ -24,6 +24,7 @@ import {
withdrawViaBank, withdrawViaBank,
makeTestPayment, makeTestPayment,
} from "../harness/helpers.js"; } from "../harness/helpers.js";
import { TransactionMajorState } from "@gnu-taler/taler-util";
/** /**
* Run test for a payment for a "free" order with * Run test for a payment for a "free" order with
@ -61,7 +62,7 @@ export async function runPaymentZeroTest(t: GlobalTestState) {
); );
for (const tr of transactions.transactions) { for (const tr of transactions.transactions) {
t.assertDeepEqual(tr.pending, false); t.assertDeepEqual(tr.txState.major, TransactionMajorState.Done);
} }
} }

View File

@ -17,7 +17,7 @@
/** /**
* Imports. * Imports.
*/ */
import { Duration, TransactionType } from "@gnu-taler/taler-util"; import { Duration, TransactionMajorState, TransactionType } from "@gnu-taler/taler-util";
import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; import { WalletApiOperation } from "@gnu-taler/taler-wallet-core";
import { GlobalTestState } from "../harness/harness.js"; import { GlobalTestState } from "../harness/harness.js";
import { import {
@ -83,7 +83,7 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) {
t.assertDeepEqual(types, ["withdrawal", "withdrawal"]); t.assertDeepEqual(types, ["withdrawal", "withdrawal"]);
const wtrans = transactions.transactions[1]; const wtrans = transactions.transactions[1];
t.assertTrue(wtrans.type === TransactionType.Withdrawal); t.assertTrue(wtrans.type === TransactionType.Withdrawal);
t.assertTrue(wtrans.pending); t.assertTrue(wtrans.txState.major === TransactionMajorState.Pending);
} }
// Now we also let the wallet time travel // Now we also let the wallet time travel

View File

@ -29,6 +29,7 @@ import {
getWireMethodForTest, getWireMethodForTest,
} from "../harness/harness.js"; } from "../harness/harness.js";
import { createSimpleTestkudosEnvironment } from "../harness/helpers.js"; import { createSimpleTestkudosEnvironment } from "../harness/helpers.js";
import { TransactionMajorState } from "@gnu-taler/taler-util";
/** /**
* Run test for basic, bank-integrated withdrawal. * Run test for basic, bank-integrated withdrawal.
@ -127,7 +128,7 @@ export async function runTippingTest(t: GlobalTestState) {
console.log("Transactions:", JSON.stringify(txns, undefined, 2)); console.log("Transactions:", JSON.stringify(txns, undefined, 2));
t.assertDeepEqual(txns.transactions[0].type, "tip"); t.assertDeepEqual(txns.transactions[0].type, "tip");
t.assertDeepEqual(txns.transactions[0].pending, false); t.assertDeepEqual(txns.transactions[0].txState.major, TransactionMajorState.Done);
t.assertAmountEquals( t.assertAmountEquals(
txns.transactions[0].amountEffective, txns.transactions[0].amountEffective,
"TESTKUDOS:4.85", "TESTKUDOS:4.85",

View File

@ -17,7 +17,6 @@
import { import {
TransactionType, TransactionType,
PaymentStatus, PaymentStatus,
ExtendedStatus,
TransactionMajorState, TransactionMajorState,
} from "./transactions-types.js"; } from "./transactions-types.js";
import { RefreshReason } from "./wallet-types.js"; import { RefreshReason } from "./wallet-types.js";
@ -36,7 +35,6 @@ export const sampleWalletCoreTransactions = [
totalRefundRaw: "KUDOS:0", totalRefundRaw: "KUDOS:0",
totalRefundEffective: "KUDOS:0", totalRefundEffective: "KUDOS:0",
status: PaymentStatus.Paid, status: PaymentStatus.Paid,
extendedStatus: ExtendedStatus.Done,
refundPending: undefined, refundPending: undefined,
posConfirmation: undefined, posConfirmation: undefined,
pending: false, pending: false,
@ -85,7 +83,6 @@ export const sampleWalletCoreTransactions = [
refreshOutputAmount: "KUDOS:1.4", refreshOutputAmount: "KUDOS:1.4",
originatingTransactionId: originatingTransactionId:
"txn:proposal:ZCGBZFE8KZ1CBYYGSC3ZC8E40KVJWV16VYCTHGC8FFSVZ5HD24BG", "txn:proposal:ZCGBZFE8KZ1CBYYGSC3ZC8E40KVJWV16VYCTHGC8FFSVZ5HD24BG",
extendedStatus: ExtendedStatus.Pending,
pending: true, pending: true,
timestamp: { timestamp: {
t_s: 1681376214, t_s: 1681376214,

View File

@ -50,14 +50,6 @@ import {
TransactionIdStr, TransactionIdStr,
} from "./wallet-types.js"; } from "./wallet-types.js";
export enum ExtendedStatus {
Pending = "pending",
Done = "done",
Aborting = "aborting",
Aborted = "aborted",
Failed = "failed",
KycRequired = "kyc-required",
}
export interface TransactionsRequest { export interface TransactionsRequest {
/** /**
@ -158,28 +150,6 @@ export interface TransactionCommon {
*/ */
txState: TransactionState; txState: TransactionState;
/**
* @deprecated in favor of statusMajor and statusMinor
*/
extendedStatus: ExtendedStatus;
/**
* true if the transaction is still pending, false otherwise
* If a transaction is not longer pending, its timestamp will be updated,
* but its transactionId will remain unchanged
*
* @deprecated show extendedStatus
*/
pending: boolean;
/**
* True if the transaction encountered a problem that might be
* permanent. A frozen transaction won't be automatically retried.
*
* @deprecated show extendedStatus
*/
frozen: boolean;
/** /**
* Raw amount of the transaction (exclusive of fees or other extra costs). * Raw amount of the transaction (exclusive of fees or other extra costs).
*/ */
@ -468,13 +438,6 @@ export interface TransactionPayment extends TransactionCommon {
*/ */
proposalId: string; proposalId: string;
/**
* How far did the wallet get with processing the payment?
*
* @deprecated use extendedStatus
*/
status: PaymentStatus;
/** /**
* Amount that must be paid for the contract * Amount that must be paid for the contract
*/ */

View File

@ -20,9 +20,6 @@
import { import {
AbsoluteTime, AbsoluteTime,
Amounts, Amounts,
constructPayPullUri,
constructPayPushUri,
ExtendedStatus,
j2s, j2s,
Logger, Logger,
NotificationType, NotificationType,
@ -413,12 +410,6 @@ function buildTransactionForPushPaymentDebit(
expiration: contractTerms.purse_expiration, expiration: contractTerms.purse_expiration,
summary: contractTerms.summary, summary: contractTerms.summary,
}, },
frozen: false,
extendedStatus:
pi.status != PeerPushPaymentInitiationStatus.Done
? ExtendedStatus.Pending
: ExtendedStatus.Done,
pending: pi.status != PeerPushPaymentInitiationStatus.Done,
timestamp: pi.timestampCreated, timestamp: pi.timestampCreated,
talerUri: stringifyPayPushUri({ talerUri: stringifyPayPushUri({
exchangeBaseUrl: pi.exchangeBaseUrl, exchangeBaseUrl: pi.exchangeBaseUrl,
@ -444,9 +435,6 @@ function buildTransactionForPullPaymentDebit(
: Amounts.stringify(pi.contractTerms.amount), : Amounts.stringify(pi.contractTerms.amount),
amountRaw: Amounts.stringify(pi.contractTerms.amount), amountRaw: Amounts.stringify(pi.contractTerms.amount),
exchangeBaseUrl: pi.exchangeBaseUrl, exchangeBaseUrl: pi.exchangeBaseUrl,
frozen: false,
pending: false,
extendedStatus: ExtendedStatus.Done,
info: { info: {
expiration: pi.contractTerms.purse_expiration, expiration: pi.contractTerms.purse_expiration,
summary: pi.contractTerms.summary, summary: pi.contractTerms.summary,
@ -492,10 +480,6 @@ function buildTransactionForPeerPullCredit(
amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue), amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue),
amountRaw: Amounts.stringify(wsr.instructedAmount), amountRaw: Amounts.stringify(wsr.instructedAmount),
exchangeBaseUrl: wsr.exchangeBaseUrl, exchangeBaseUrl: wsr.exchangeBaseUrl,
extendedStatus: wsr.timestampFinish
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: !wsr.timestampFinish,
// Old transactions don't have it! // Old transactions don't have it!
timestamp: pullCredit.mergeTimestamp ?? TalerProtocolTimestamp.now(), timestamp: pullCredit.mergeTimestamp ?? TalerProtocolTimestamp.now(),
info: { info: {
@ -510,7 +494,6 @@ function buildTransactionForPeerPullCredit(
tag: TransactionType.PeerPullCredit, tag: TransactionType.PeerPullCredit,
pursePub: pullCredit.pursePub, pursePub: pullCredit.pursePub,
}), }),
frozen: false,
...(wsrOrt?.lastError ...(wsrOrt?.lastError
? { ? {
error: silentWithdrawalErrorForInvoice error: silentWithdrawalErrorForInvoice
@ -527,8 +510,6 @@ function buildTransactionForPeerPullCredit(
amountEffective: Amounts.stringify(pullCredit.estimatedAmountEffective), amountEffective: Amounts.stringify(pullCredit.estimatedAmountEffective),
amountRaw: Amounts.stringify(peerContractTerms.amount), amountRaw: Amounts.stringify(peerContractTerms.amount),
exchangeBaseUrl: pullCredit.exchangeBaseUrl, exchangeBaseUrl: pullCredit.exchangeBaseUrl,
extendedStatus: ExtendedStatus.Pending,
pending: true,
// Old transactions don't have it! // Old transactions don't have it!
timestamp: pullCredit.mergeTimestamp ?? TalerProtocolTimestamp.now(), timestamp: pullCredit.mergeTimestamp ?? TalerProtocolTimestamp.now(),
info: { info: {
@ -543,7 +524,6 @@ function buildTransactionForPeerPullCredit(
tag: TransactionType.PeerPullCredit, tag: TransactionType.PeerPullCredit,
pursePub: pullCredit.pursePub, pursePub: pullCredit.pursePub,
}), }),
frozen: false,
...(pullCreditOrt?.lastError ? { error: pullCreditOrt.lastError } : {}), ...(pullCreditOrt?.lastError ? { error: pullCreditOrt.lastError } : {}),
}; };
} }
@ -570,16 +550,11 @@ function buildTransactionForPeerPushCredit(
expiration: wsr.wgInfo.contractTerms.purse_expiration, expiration: wsr.wgInfo.contractTerms.purse_expiration,
summary: wsr.wgInfo.contractTerms.summary, summary: wsr.wgInfo.contractTerms.summary,
}, },
extendedStatus: wsr.timestampFinish
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: !wsr.timestampFinish,
timestamp: wsr.timestampStart, timestamp: wsr.timestampStart,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.PeerPushCredit, tag: TransactionType.PeerPushCredit,
peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId, peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId,
}), }),
frozen: false,
...(wsrOrt?.lastError ? { error: wsrOrt.lastError } : {}), ...(wsrOrt?.lastError ? { error: wsrOrt.lastError } : {}),
}; };
} }
@ -595,14 +570,11 @@ function buildTransactionForPeerPushCredit(
expiration: peerContractTerms.purse_expiration, expiration: peerContractTerms.purse_expiration,
summary: peerContractTerms.summary, summary: peerContractTerms.summary,
}, },
extendedStatus: ExtendedStatus.Pending,
pending: true,
timestamp: pushInc.timestamp, timestamp: pushInc.timestamp,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.PeerPushCredit, tag: TransactionType.PeerPushCredit,
peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId, peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId,
}), }),
frozen: false,
...(pushOrt?.lastError ? { error: pushOrt.lastError } : {}), ...(pushOrt?.lastError ? { error: pushOrt.lastError } : {}),
}; };
} }
@ -629,16 +601,11 @@ function buildTransactionForBankIntegratedWithdraw(
wgRecord.status === WithdrawalGroupStatus.PendingReady, wgRecord.status === WithdrawalGroupStatus.PendingReady,
}, },
exchangeBaseUrl: wgRecord.exchangeBaseUrl, exchangeBaseUrl: wgRecord.exchangeBaseUrl,
extendedStatus: wgRecord.timestampFinish
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: !wgRecord.timestampFinish,
timestamp: wgRecord.timestampStart, timestamp: wgRecord.timestampStart,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.Withdrawal, tag: TransactionType.Withdrawal,
withdrawalGroupId: wgRecord.withdrawalGroupId, withdrawalGroupId: wgRecord.withdrawalGroupId,
}), }),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}), ...(ort?.lastError ? { error: ort.lastError } : {}),
}; };
} }
@ -676,16 +643,11 @@ function buildTransactionForManualWithdraw(
withdrawalGroup.status === WithdrawalGroupStatus.PendingReady, withdrawalGroup.status === WithdrawalGroupStatus.PendingReady,
}, },
exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl, exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl,
extendedStatus: withdrawalGroup.timestampFinish
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: !withdrawalGroup.timestampFinish,
timestamp: withdrawalGroup.timestampStart, timestamp: withdrawalGroup.timestampStart,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.Withdrawal, tag: TransactionType.Withdrawal,
withdrawalGroupId: withdrawalGroup.withdrawalGroupId, withdrawalGroupId: withdrawalGroup.withdrawalGroupId,
}), }),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}), ...(ort?.lastError ? { error: ort.lastError } : {}),
}; };
} }
@ -718,9 +680,6 @@ function buildTransactionForRefund(
refundGroupId: refundRecord.refundGroupId, refundGroupId: refundRecord.refundGroupId,
}), }),
txState: computeRefundTransactionState(refundRecord), txState: computeRefundTransactionState(refundRecord),
extendedStatus: ExtendedStatus.Done,
frozen: false,
pending: false,
paymentInfo, paymentInfo,
}; };
} }
@ -729,15 +688,6 @@ function buildTransactionForRefresh(
refreshGroupRecord: RefreshGroupRecord, refreshGroupRecord: RefreshGroupRecord,
ort?: OperationRetryRecord, ort?: OperationRetryRecord,
): Transaction { ): Transaction {
let extendedStatus: ExtendedStatus;
switch (refreshGroupRecord.operationStatus) {
case RefreshOperationStatus.Finished:
case RefreshOperationStatus.FinishedWithError:
extendedStatus = ExtendedStatus.Done;
break;
default:
extendedStatus = ExtendedStatus.Pending;
}
const inputAmount = Amounts.sumOrZero( const inputAmount = Amounts.sumOrZero(
refreshGroupRecord.currency, refreshGroupRecord.currency,
refreshGroupRecord.inputPerCoin, refreshGroupRecord.inputPerCoin,
@ -760,19 +710,11 @@ function buildTransactionForRefresh(
refreshOutputAmount: Amounts.stringify(outputAmount), refreshOutputAmount: Amounts.stringify(outputAmount),
originatingTransactionId: originatingTransactionId:
refreshGroupRecord.reasonDetails?.originatingTransactionId, refreshGroupRecord.reasonDetails?.originatingTransactionId,
extendedStatus:
refreshGroupRecord.operationStatus === RefreshOperationStatus.Finished ||
refreshGroupRecord.operationStatus ===
RefreshOperationStatus.FinishedWithError
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: extendedStatus == ExtendedStatus.Pending,
timestamp: refreshGroupRecord.timestampCreated, timestamp: refreshGroupRecord.timestampCreated,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.Refresh, tag: TransactionType.Refresh,
refreshGroupId: refreshGroupRecord.refreshGroupId, refreshGroupId: refreshGroupRecord.refreshGroupId,
}), }),
frozen: false,
...(ort?.lastError ? { error: ort.lastError } : {}), ...(ort?.lastError ? { error: ort.lastError } : {}),
}; };
} }
@ -793,11 +735,6 @@ function buildTransactionForDeposit(
txState: computeDepositTransactionStatus(dg), txState: computeDepositTransactionStatus(dg),
amountRaw: Amounts.stringify(dg.effectiveDepositAmount), amountRaw: Amounts.stringify(dg.effectiveDepositAmount),
amountEffective: Amounts.stringify(dg.totalPayCost), amountEffective: Amounts.stringify(dg.totalPayCost),
extendedStatus: dg.timestampFinished
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: !dg.timestampFinished,
frozen: false,
timestamp: dg.timestampCreated, timestamp: dg.timestampCreated,
targetPaytoUri: dg.wire.payto_uri, targetPaytoUri: dg.wire.payto_uri,
wireTransferDeadline: dg.contractTermsRaw.wire_transfer_deadline, wireTransferDeadline: dg.contractTermsRaw.wire_transfer_deadline,
@ -830,11 +767,6 @@ function buildTransactionForTip(
txState: computeTipTransactionStatus(tipRecord), txState: computeTipTransactionStatus(tipRecord),
amountEffective: Amounts.stringify(tipRecord.tipAmountEffective), amountEffective: Amounts.stringify(tipRecord.tipAmountEffective),
amountRaw: Amounts.stringify(tipRecord.tipAmountRaw), amountRaw: Amounts.stringify(tipRecord.tipAmountRaw),
extendedStatus: tipRecord.pickedUpTimestamp
? ExtendedStatus.Done
: ExtendedStatus.Pending,
pending: !tipRecord.pickedUpTimestamp,
frozen: false,
timestamp: tipRecord.acceptedTimestamp, timestamp: tipRecord.acceptedTimestamp,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.Tip, tag: TransactionType.Tip,
@ -899,32 +831,6 @@ async function buildTransactionForPurchase(
checkDbInvariant(!!timestamp); checkDbInvariant(!!timestamp);
checkDbInvariant(!!purchaseRecord.payInfo); checkDbInvariant(!!purchaseRecord.payInfo);
let status: ExtendedStatus;
switch (purchaseRecord.purchaseStatus) {
case PurchaseStatus.AbortingWithRefund:
status = ExtendedStatus.Aborting;
break;
case PurchaseStatus.Done:
case PurchaseStatus.RepurchaseDetected:
status = ExtendedStatus.Done;
break;
case PurchaseStatus.DownloadingProposal:
case PurchaseStatus.QueryingRefund:
case PurchaseStatus.Proposed:
case PurchaseStatus.Paying:
status = ExtendedStatus.Pending;
break;
case PurchaseStatus.FailedClaim:
status = ExtendedStatus.Failed;
break;
case PurchaseStatus.AbortedIncompletePayment:
status = ExtendedStatus.Aborted;
break;
default:
// FIXME: Should we have some unknown status?
status = ExtendedStatus.Pending;
}
return { return {
type: TransactionType.Payment, type: TransactionType.Payment,
txState: computePayMerchantTransactionState(purchaseRecord), txState: computePayMerchantTransactionState(purchaseRecord),
@ -936,11 +842,6 @@ async function buildTransactionForPurchase(
purchaseRecord.refundAmountAwaiting === undefined purchaseRecord.refundAmountAwaiting === undefined
? undefined ? undefined
: Amounts.stringify(purchaseRecord.refundAmountAwaiting), : Amounts.stringify(purchaseRecord.refundAmountAwaiting),
status: purchaseRecord.timestampFirstSuccessfulPay
? PaymentStatus.Paid
: PaymentStatus.Accepted,
extendedStatus: status,
pending: purchaseRecord.purchaseStatus === PurchaseStatus.Paying,
refunds, refunds,
posConfirmation: purchaseRecord.posConfirmation, posConfirmation: purchaseRecord.posConfirmation,
timestamp, timestamp,
@ -952,9 +853,6 @@ async function buildTransactionForPurchase(
info, info,
refundQueryActive: refundQueryActive:
purchaseRecord.purchaseStatus === PurchaseStatus.QueryingRefund, purchaseRecord.purchaseStatus === PurchaseStatus.QueryingRefund,
frozen:
purchaseRecord.purchaseStatus ===
PurchaseStatus.AbortedIncompletePayment ?? false,
...(ort?.lastError ? { error: ort.lastError } : {}), ...(ort?.lastError ? { error: ort.lastError } : {}),
}; };
} }
@ -1272,8 +1170,13 @@ export async function getTransactions(
} }
} }
const txPending = transactions.filter((x) => x.pending); const isPending = (x: Transaction) =>
const txNotPending = transactions.filter((x) => !x.pending); x.txState.major === TransactionMajorState.Pending ||
x.txState.major === TransactionMajorState.Aborting ||
x.txState.major === TransactionMajorState.Dialog;
const txPending = transactions.filter((x) => isPending(x));
const txNotPending = transactions.filter((x) => !isPending(x));
const txCmp = (h1: Transaction, h2: Transaction) => { const txCmp = (h1: Transaction, h2: Transaction) => {
const tsCmp = AbsoluteTime.cmp( const tsCmp = AbsoluteTime.cmp(

View File

@ -69,6 +69,29 @@ export function TransactionItem(props: { tx: Transaction }): VNode {
} }
/> />
); );
case TransactionType.InternalWithdrawal:
return (
<TransactionLayout
id={tx.transactionId}
amount={tx.amountEffective}
debitCreditIndicator={"credit"}
title={new URL(tx.exchangeBaseUrl).hostname}
timestamp={AbsoluteTime.fromTimestamp(tx.timestamp)}
iconPath={"I"}
pending={
tx.txState.major === TransactionMajorState.Pending
? tx.withdrawalDetails.type ===
WithdrawalType.TalerBankIntegrationApi
? !tx.withdrawalDetails.confirmed
? i18n.str`Need approval in the Bank`
: i18n.str`Exchange is waiting the wire transfer`
: tx.withdrawalDetails.type === WithdrawalType.ManualTransfer
? i18n.str`Exchange is waiting the wire transfer`
: "" //pending but no message
: undefined
}
/>
);
case TransactionType.Payment: case TransactionType.Payment:
return ( return (
<TransactionLayout <TransactionLayout

View File

@ -52,7 +52,6 @@ const commonTransaction = (): TransactionCommon =>
({ ({
amountRaw: "USD:10", amountRaw: "USD:10",
amountEffective: "USD:9", amountEffective: "USD:9",
pending: false,
txState: { txState: {
major: TransactionMajorState.Done, major: TransactionMajorState.Done,
}, },

View File

@ -398,7 +398,10 @@ export function TransactionView({
const raw = Amounts.parseOrThrow(transaction.amountRaw); const raw = Amounts.parseOrThrow(transaction.amountRaw);
const effective = Amounts.parseOrThrow(transaction.amountEffective); const effective = Amounts.parseOrThrow(transaction.amountEffective);
if (transaction.type === TransactionType.Withdrawal) { if (
transaction.type === TransactionType.Withdrawal ||
transaction.type === TransactionType.InternalWithdrawal
) {
return ( return (
<TransactionTemplate <TransactionTemplate
transaction={transaction} transaction={transaction}