diff options
author | Florian Dold <florian@dold.me> | 2024-03-05 01:55:21 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2024-03-05 01:55:21 +0100 |
commit | 2dd1bbebcaed35308105a8470e1aefb9f6f19900 (patch) | |
tree | 143a613f6c2d09b0a86ad16985a1b2637dbfe76f /packages/taler-wallet-core/src | |
parent | a98fe4b00d499b1fc2b9df6a21991e3449853868 (diff) | |
download | wallet-core-2dd1bbebcaed35308105a8470e1aefb9f6f19900.tar.xz |
wallet-core: use state instead of yet another flag
Diffstat (limited to 'packages/taler-wallet-core/src')
-rw-r--r-- | packages/taler-wallet-core/src/db.ts | 8 | ||||
-rw-r--r-- | packages/taler-wallet-core/src/pay-merchant.ts | 25 |
2 files changed, 18 insertions, 15 deletions
diff --git a/packages/taler-wallet-core/src/db.ts b/packages/taler-wallet-core/src/db.ts index 7e4f9fa4a..83b595a8a 100644 --- a/packages/taler-wallet-core/src/db.ts +++ b/packages/taler-wallet-core/src/db.ts @@ -1168,6 +1168,8 @@ export enum PurchaseStatus { */ FailedClaim = 0x0501_0000, + FailedPaidByOther = 0x0501_0001, + /** * Payment was successful. */ @@ -1326,12 +1328,6 @@ export interface PurchaseRecord { * did not picked up yet */ refundAmountAwaiting: AmountString | undefined; - - /** - * When the purchase has been shared to other wallet - * and the other wallet completed before this one. - */ - paidByOther: boolean | undefined; } export enum ConfigRecordKey { diff --git a/packages/taler-wallet-core/src/pay-merchant.ts b/packages/taler-wallet-core/src/pay-merchant.ts index be3f7f106..80336fa76 100644 --- a/packages/taler-wallet-core/src/pay-merchant.ts +++ b/packages/taler-wallet-core/src/pay-merchant.ts @@ -898,8 +898,7 @@ async function createOrReusePurchase( return; } const oldTxState = computePayMerchantTransactionState(p); - p.purchaseStatus = PurchaseStatus.FailedClaim; - p.paidByOther = true; + p.purchaseStatus = PurchaseStatus.FailedPaidByOther; const newTxState = computePayMerchantTransactionState(p); await tx.purchases.put(p); return { oldTxState, newTxState }; @@ -947,7 +946,6 @@ async function createOrReusePurchase( lastSessionId: undefined, merchantPaySig: undefined, payInfo: undefined, - paidByOther: undefined, refundAmountAwaiting: undefined, timestampAccept: undefined, timestampFirstSuccessfulPay: undefined, @@ -1383,7 +1381,7 @@ async function checkPaymentByProposalId( status: PreparePayResultType.AlreadyConfirmed, contractTerms: download.contractTermsRaw, contractTermsHash: download.contractData.contractTermsHash, - paid: purchase.paidByOther === true, + paid: purchase.purchaseStatus === PurchaseStatus.FailedPaidByOther, amountRaw: Amounts.stringify(download.contractData.amount), amountEffective: purchase.payInfo ? Amounts.stringify(purchase.payInfo.totalPayCost) @@ -2036,8 +2034,7 @@ async function processPurchasePay( return; } const oldTxState = computePayMerchantTransactionState(p); - p.purchaseStatus = PurchaseStatus.FailedClaim; - p.paidByOther = true; + p.purchaseStatus = PurchaseStatus.FailedPaidByOther; const newTxState = computePayMerchantTransactionState(p); await tx.purchases.put(p); return { oldTxState, newTxState }; @@ -2386,6 +2383,13 @@ export function computePayMerchantTransactionState( major: TransactionMajorState.Failed, minor: TransactionMinorState.AbortingBank, }; + case PurchaseStatus.FailedPaidByOther: + return { + major: TransactionMajorState.Failed, + minor: TransactionMinorState.PaidByOther, + }; + default: + assertUnreachable(purchaseRecord.purchaseStatus); } } @@ -2452,6 +2456,10 @@ export function computePayMerchantTransactionActions( return [TransactionAction.Delete]; case PurchaseStatus.FailedAbort: return [TransactionAction.Delete]; + case PurchaseStatus.FailedPaidByOther: + return [TransactionAction.Delete]; + default: + assertUnreachable(purchaseRecord.purchaseStatus); } } @@ -2480,7 +2488,7 @@ export async function sharePayment( if (p.purchaseStatus === PurchaseStatus.DialogProposed) { p.purchaseStatus = PurchaseStatus.DialogShared; p.shared = true; - tx.purchases.put(p); + await tx.purchases.put(p); } const newTxState = computePayMerchantTransactionState(p); @@ -2578,8 +2586,7 @@ async function processPurchaseDialogShared( return; } const oldTxState = computePayMerchantTransactionState(p); - p.purchaseStatus = PurchaseStatus.FailedClaim; - p.paidByOther = true; + p.purchaseStatus = PurchaseStatus.FailedPaidByOther; const newTxState = computePayMerchantTransactionState(p); await tx.purchases.put(p); return { oldTxState, newTxState }; |