From a2ef2e391a8f030857d0f9cd56c6157cffb33659 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 24 May 2023 14:46:03 +0200 Subject: [PATCH] wallet-core: remove legacy non-DD37 tx status fields --- .../src/integrationtests/test-payment-zero.ts | 3 +- .../test-timetravel-withdraw.ts | 4 +- .../src/integrationtests/test-tipping.ts | 3 +- .../taler-util/src/transaction-test-data.ts | 3 - packages/taler-util/src/transactions-types.ts | 37 ------ .../src/operations/transactions.ts | 111 ++---------------- .../src/components/TransactionItem.tsx | 23 ++++ .../src/wallet/History.stories.tsx | 1 - .../src/wallet/Transaction.tsx | 5 +- 9 files changed, 40 insertions(+), 150 deletions(-) diff --git a/packages/taler-harness/src/integrationtests/test-payment-zero.ts b/packages/taler-harness/src/integrationtests/test-payment-zero.ts index 6c28da30c..264cffd06 100644 --- a/packages/taler-harness/src/integrationtests/test-payment-zero.ts +++ b/packages/taler-harness/src/integrationtests/test-payment-zero.ts @@ -24,6 +24,7 @@ import { withdrawViaBank, makeTestPayment, } from "../harness/helpers.js"; +import { TransactionMajorState } from "@gnu-taler/taler-util"; /** * 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) { - t.assertDeepEqual(tr.pending, false); + t.assertDeepEqual(tr.txState.major, TransactionMajorState.Done); } } diff --git a/packages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts b/packages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts index 9335af9f5..ca3e67647 100644 --- a/packages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts +++ b/packages/taler-harness/src/integrationtests/test-timetravel-withdraw.ts @@ -17,7 +17,7 @@ /** * 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 { GlobalTestState } from "../harness/harness.js"; import { @@ -83,7 +83,7 @@ export async function runTimetravelWithdrawTest(t: GlobalTestState) { t.assertDeepEqual(types, ["withdrawal", "withdrawal"]); const wtrans = transactions.transactions[1]; 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 diff --git a/packages/taler-harness/src/integrationtests/test-tipping.ts b/packages/taler-harness/src/integrationtests/test-tipping.ts index bbf729420..ff6fc9ceb 100644 --- a/packages/taler-harness/src/integrationtests/test-tipping.ts +++ b/packages/taler-harness/src/integrationtests/test-tipping.ts @@ -29,6 +29,7 @@ import { getWireMethodForTest, } from "../harness/harness.js"; import { createSimpleTestkudosEnvironment } from "../harness/helpers.js"; +import { TransactionMajorState } from "@gnu-taler/taler-util"; /** * 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)); 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( txns.transactions[0].amountEffective, "TESTKUDOS:4.85", diff --git a/packages/taler-util/src/transaction-test-data.ts b/packages/taler-util/src/transaction-test-data.ts index dc0903f53..378028144 100644 --- a/packages/taler-util/src/transaction-test-data.ts +++ b/packages/taler-util/src/transaction-test-data.ts @@ -17,7 +17,6 @@ import { TransactionType, PaymentStatus, - ExtendedStatus, TransactionMajorState, } from "./transactions-types.js"; import { RefreshReason } from "./wallet-types.js"; @@ -36,7 +35,6 @@ export const sampleWalletCoreTransactions = [ totalRefundRaw: "KUDOS:0", totalRefundEffective: "KUDOS:0", status: PaymentStatus.Paid, - extendedStatus: ExtendedStatus.Done, refundPending: undefined, posConfirmation: undefined, pending: false, @@ -85,7 +83,6 @@ export const sampleWalletCoreTransactions = [ refreshOutputAmount: "KUDOS:1.4", originatingTransactionId: "txn:proposal:ZCGBZFE8KZ1CBYYGSC3ZC8E40KVJWV16VYCTHGC8FFSVZ5HD24BG", - extendedStatus: ExtendedStatus.Pending, pending: true, timestamp: { t_s: 1681376214, diff --git a/packages/taler-util/src/transactions-types.ts b/packages/taler-util/src/transactions-types.ts index 30178b7c7..84c60a847 100644 --- a/packages/taler-util/src/transactions-types.ts +++ b/packages/taler-util/src/transactions-types.ts @@ -50,14 +50,6 @@ import { TransactionIdStr, } from "./wallet-types.js"; -export enum ExtendedStatus { - Pending = "pending", - Done = "done", - Aborting = "aborting", - Aborted = "aborted", - Failed = "failed", - KycRequired = "kyc-required", -} export interface TransactionsRequest { /** @@ -158,28 +150,6 @@ export interface TransactionCommon { */ 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). */ @@ -468,13 +438,6 @@ export interface TransactionPayment extends TransactionCommon { */ 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 */ diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index b5a6ba74e..41c74f4d1 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -20,9 +20,6 @@ import { AbsoluteTime, Amounts, - constructPayPullUri, - constructPayPushUri, - ExtendedStatus, j2s, Logger, NotificationType, @@ -413,12 +410,6 @@ function buildTransactionForPushPaymentDebit( expiration: contractTerms.purse_expiration, summary: contractTerms.summary, }, - frozen: false, - extendedStatus: - pi.status != PeerPushPaymentInitiationStatus.Done - ? ExtendedStatus.Pending - : ExtendedStatus.Done, - pending: pi.status != PeerPushPaymentInitiationStatus.Done, timestamp: pi.timestampCreated, talerUri: stringifyPayPushUri({ exchangeBaseUrl: pi.exchangeBaseUrl, @@ -444,9 +435,6 @@ function buildTransactionForPullPaymentDebit( : Amounts.stringify(pi.contractTerms.amount), amountRaw: Amounts.stringify(pi.contractTerms.amount), exchangeBaseUrl: pi.exchangeBaseUrl, - frozen: false, - pending: false, - extendedStatus: ExtendedStatus.Done, info: { expiration: pi.contractTerms.purse_expiration, summary: pi.contractTerms.summary, @@ -492,10 +480,6 @@ function buildTransactionForPeerPullCredit( amountEffective: Amounts.stringify(wsr.denomsSel.totalCoinValue), amountRaw: Amounts.stringify(wsr.instructedAmount), exchangeBaseUrl: wsr.exchangeBaseUrl, - extendedStatus: wsr.timestampFinish - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: !wsr.timestampFinish, // Old transactions don't have it! timestamp: pullCredit.mergeTimestamp ?? TalerProtocolTimestamp.now(), info: { @@ -510,7 +494,6 @@ function buildTransactionForPeerPullCredit( tag: TransactionType.PeerPullCredit, pursePub: pullCredit.pursePub, }), - frozen: false, ...(wsrOrt?.lastError ? { error: silentWithdrawalErrorForInvoice @@ -527,8 +510,6 @@ function buildTransactionForPeerPullCredit( amountEffective: Amounts.stringify(pullCredit.estimatedAmountEffective), amountRaw: Amounts.stringify(peerContractTerms.amount), exchangeBaseUrl: pullCredit.exchangeBaseUrl, - extendedStatus: ExtendedStatus.Pending, - pending: true, // Old transactions don't have it! timestamp: pullCredit.mergeTimestamp ?? TalerProtocolTimestamp.now(), info: { @@ -543,7 +524,6 @@ function buildTransactionForPeerPullCredit( tag: TransactionType.PeerPullCredit, pursePub: pullCredit.pursePub, }), - frozen: false, ...(pullCreditOrt?.lastError ? { error: pullCreditOrt.lastError } : {}), }; } @@ -570,16 +550,11 @@ function buildTransactionForPeerPushCredit( expiration: wsr.wgInfo.contractTerms.purse_expiration, summary: wsr.wgInfo.contractTerms.summary, }, - extendedStatus: wsr.timestampFinish - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: !wsr.timestampFinish, timestamp: wsr.timestampStart, transactionId: constructTransactionIdentifier({ tag: TransactionType.PeerPushCredit, peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId, }), - frozen: false, ...(wsrOrt?.lastError ? { error: wsrOrt.lastError } : {}), }; } @@ -595,14 +570,11 @@ function buildTransactionForPeerPushCredit( expiration: peerContractTerms.purse_expiration, summary: peerContractTerms.summary, }, - extendedStatus: ExtendedStatus.Pending, - pending: true, timestamp: pushInc.timestamp, transactionId: constructTransactionIdentifier({ tag: TransactionType.PeerPushCredit, peerPushPaymentIncomingId: pushInc.peerPushPaymentIncomingId, }), - frozen: false, ...(pushOrt?.lastError ? { error: pushOrt.lastError } : {}), }; } @@ -629,16 +601,11 @@ function buildTransactionForBankIntegratedWithdraw( wgRecord.status === WithdrawalGroupStatus.PendingReady, }, exchangeBaseUrl: wgRecord.exchangeBaseUrl, - extendedStatus: wgRecord.timestampFinish - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: !wgRecord.timestampFinish, timestamp: wgRecord.timestampStart, transactionId: constructTransactionIdentifier({ tag: TransactionType.Withdrawal, withdrawalGroupId: wgRecord.withdrawalGroupId, }), - frozen: false, ...(ort?.lastError ? { error: ort.lastError } : {}), }; } @@ -676,16 +643,11 @@ function buildTransactionForManualWithdraw( withdrawalGroup.status === WithdrawalGroupStatus.PendingReady, }, exchangeBaseUrl: withdrawalGroup.exchangeBaseUrl, - extendedStatus: withdrawalGroup.timestampFinish - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: !withdrawalGroup.timestampFinish, timestamp: withdrawalGroup.timestampStart, transactionId: constructTransactionIdentifier({ tag: TransactionType.Withdrawal, withdrawalGroupId: withdrawalGroup.withdrawalGroupId, }), - frozen: false, ...(ort?.lastError ? { error: ort.lastError } : {}), }; } @@ -718,9 +680,6 @@ function buildTransactionForRefund( refundGroupId: refundRecord.refundGroupId, }), txState: computeRefundTransactionState(refundRecord), - extendedStatus: ExtendedStatus.Done, - frozen: false, - pending: false, paymentInfo, }; } @@ -729,15 +688,6 @@ 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; - } const inputAmount = Amounts.sumOrZero( refreshGroupRecord.currency, refreshGroupRecord.inputPerCoin, @@ -760,19 +710,11 @@ function buildTransactionForRefresh( refreshOutputAmount: Amounts.stringify(outputAmount), originatingTransactionId: refreshGroupRecord.reasonDetails?.originatingTransactionId, - extendedStatus: - refreshGroupRecord.operationStatus === RefreshOperationStatus.Finished || - refreshGroupRecord.operationStatus === - RefreshOperationStatus.FinishedWithError - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: extendedStatus == ExtendedStatus.Pending, timestamp: refreshGroupRecord.timestampCreated, transactionId: constructTransactionIdentifier({ tag: TransactionType.Refresh, refreshGroupId: refreshGroupRecord.refreshGroupId, }), - frozen: false, ...(ort?.lastError ? { error: ort.lastError } : {}), }; } @@ -793,11 +735,6 @@ function buildTransactionForDeposit( txState: computeDepositTransactionStatus(dg), amountRaw: Amounts.stringify(dg.effectiveDepositAmount), amountEffective: Amounts.stringify(dg.totalPayCost), - extendedStatus: dg.timestampFinished - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: !dg.timestampFinished, - frozen: false, timestamp: dg.timestampCreated, targetPaytoUri: dg.wire.payto_uri, wireTransferDeadline: dg.contractTermsRaw.wire_transfer_deadline, @@ -830,11 +767,6 @@ function buildTransactionForTip( txState: computeTipTransactionStatus(tipRecord), amountEffective: Amounts.stringify(tipRecord.tipAmountEffective), amountRaw: Amounts.stringify(tipRecord.tipAmountRaw), - extendedStatus: tipRecord.pickedUpTimestamp - ? ExtendedStatus.Done - : ExtendedStatus.Pending, - pending: !tipRecord.pickedUpTimestamp, - frozen: false, timestamp: tipRecord.acceptedTimestamp, transactionId: constructTransactionIdentifier({ tag: TransactionType.Tip, @@ -899,32 +831,6 @@ async function buildTransactionForPurchase( checkDbInvariant(!!timestamp); 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 { type: TransactionType.Payment, txState: computePayMerchantTransactionState(purchaseRecord), @@ -936,11 +842,6 @@ async function buildTransactionForPurchase( purchaseRecord.refundAmountAwaiting === undefined ? undefined : Amounts.stringify(purchaseRecord.refundAmountAwaiting), - status: purchaseRecord.timestampFirstSuccessfulPay - ? PaymentStatus.Paid - : PaymentStatus.Accepted, - extendedStatus: status, - pending: purchaseRecord.purchaseStatus === PurchaseStatus.Paying, refunds, posConfirmation: purchaseRecord.posConfirmation, timestamp, @@ -952,9 +853,6 @@ async function buildTransactionForPurchase( info, refundQueryActive: purchaseRecord.purchaseStatus === PurchaseStatus.QueryingRefund, - frozen: - purchaseRecord.purchaseStatus === - PurchaseStatus.AbortedIncompletePayment ?? false, ...(ort?.lastError ? { error: ort.lastError } : {}), }; } @@ -1272,8 +1170,13 @@ export async function getTransactions( } } - const txPending = transactions.filter((x) => x.pending); - const txNotPending = transactions.filter((x) => !x.pending); + const isPending = (x: Transaction) => + 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 tsCmp = AbsoluteTime.cmp( diff --git a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx index dc11c4b7e..124729349 100644 --- a/packages/taler-wallet-webextension/src/components/TransactionItem.tsx +++ b/packages/taler-wallet-webextension/src/components/TransactionItem.tsx @@ -69,6 +69,29 @@ export function TransactionItem(props: { tx: Transaction }): VNode { } /> ); + case TransactionType.InternalWithdrawal: + return ( + + ); case TransactionType.Payment: return ( ({ amountRaw: "USD:10", amountEffective: "USD:9", - pending: false, txState: { major: TransactionMajorState.Done, }, diff --git a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx index f4c50a8d5..9541cc33f 100644 --- a/packages/taler-wallet-webextension/src/wallet/Transaction.tsx +++ b/packages/taler-wallet-webextension/src/wallet/Transaction.tsx @@ -398,7 +398,10 @@ export function TransactionView({ const raw = Amounts.parseOrThrow(transaction.amountRaw); const effective = Amounts.parseOrThrow(transaction.amountEffective); - if (transaction.type === TransactionType.Withdrawal) { + if ( + transaction.type === TransactionType.Withdrawal || + transaction.type === TransactionType.InternalWithdrawal + ) { return (