From 043a5f89fe020bbb55170a9fc355c3d699ad8761 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Tue, 8 Sep 2020 19:54:23 +0530 Subject: tipping transaction list entry, integration test and DB simplifications --- .../taler-wallet-core/src/operations/pending.ts | 2 +- packages/taler-wallet-core/src/operations/tip.ts | 22 ++++++++------------ .../src/operations/transactions.ts | 24 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) (limited to 'packages/taler-wallet-core/src/operations') diff --git a/packages/taler-wallet-core/src/operations/pending.ts b/packages/taler-wallet-core/src/operations/pending.ts index 7dda1214d..7338ac77d 100644 --- a/packages/taler-wallet-core/src/operations/pending.ts +++ b/packages/taler-wallet-core/src/operations/pending.ts @@ -351,7 +351,7 @@ async function gatherTipPending( onlyDue = false, ): Promise { await tx.iter(Stores.tips).forEach((tip) => { - if (tip.pickedUp) { + if (tip.pickedUpTimestamp) { return; } resp.nextRetryDelay = updateRetryDelay( diff --git a/packages/taler-wallet-core/src/operations/tip.ts b/packages/taler-wallet-core/src/operations/tip.ts index 6ccd262b0..248ea2cd1 100644 --- a/packages/taler-wallet-core/src/operations/tip.ts +++ b/packages/taler-wallet-core/src/operations/tip.ts @@ -25,11 +25,8 @@ import { import * as Amounts from "../util/amounts"; import { Stores, - PlanchetRecord, - WithdrawalGroupRecord, initRetryInfo, updateRetryInfoTimeout, - WithdrawalSourceType, TipPlanchet, CoinRecord, CoinSourceType, @@ -38,7 +35,6 @@ import { import { getExchangeWithdrawalInfo, selectWithdrawalDenoms, - processWithdrawGroup, denomSelectionInfoToState, } from "./withdraw"; import { updateExchangeFromUrl } from "./exchanges"; @@ -102,15 +98,11 @@ export async function prepareTip( tipRecord = { walletTipId: walletTipId, acceptedTimestamp: undefined, - rejectedTimestamp: undefined, tipAmountRaw: amount, - deadline: tipPickupStatus.expiration, - exchangeUrl: tipPickupStatus.exchange_url, + tipExpiration: tipPickupStatus.expiration, + exchangeBaseUrl: tipPickupStatus.exchange_url, merchantBaseUrl: res.merchantBaseUrl, - nextUrl: undefined, - pickedUp: false, planchets: undefined, - response: undefined, createdTimestamp: getTimestampNow(), merchantTipId: res.merchantTipId, tipAmountEffective: Amounts.sub(amount, Amounts.add( @@ -120,6 +112,7 @@ export async function prepareTip( retryInfo: initRetryInfo(), lastError: undefined, denomsSel: denomSelectionInfoToState(selectedDenoms), + pickedUpTimestamp: undefined, }; await ws.db.put(Stores.tips, tipRecord); } @@ -197,7 +190,7 @@ async function processTipImpl( return; } - if (tipRecord.pickedUp) { + if (tipRecord.pickedUpTimestamp) { logger.warn("tip already picked up"); return; } @@ -302,7 +295,7 @@ async function processTipImpl( denomPub: planchet.denomPub, denomPubHash: planchet.denomPubHash, denomSig: denomSig, - exchangeBaseUrl: tipRecord.exchangeUrl, + exchangeBaseUrl: tipRecord.exchangeBaseUrl, status: CoinStatus.Fresh, suspended: false, }); @@ -315,10 +308,11 @@ async function processTipImpl( if (!tr) { return; } - if (tr.pickedUp) { + if (tr.pickedUpTimestamp) { return; } - tr.pickedUp = true; + tr.pickedUpTimestamp = getTimestampNow(); + tr.lastError = undefined; tr.retryInfo = initRetryInfo(false); await tx.put(Stores.tips, tr); for (const cr of newCoinRecords) { diff --git a/packages/taler-wallet-core/src/operations/transactions.ts b/packages/taler-wallet-core/src/operations/transactions.ts index b5f77a190..026a91ef3 100644 --- a/packages/taler-wallet-core/src/operations/transactions.ts +++ b/packages/taler-wallet-core/src/operations/transactions.ts @@ -38,6 +38,7 @@ import { OrderShortInfo, } from "../types/transactions"; import { getFundingPaytoUris } from "./reserves"; +import { TipResponse } from "../types/talerTypes"; /** * Create an event ID from the type and the primary key for the event. @@ -308,6 +309,29 @@ export async function getTransactions( }); }); }); + + tx.iter(Stores.tips).forEachAsync(async (tipRecord) => { + if ( + shouldSkipCurrency( + transactionsRequest, + tipRecord.tipAmountRaw.currency, + ) + ) { + return; + } + if (!tipRecord.acceptedTimestamp) { + return; + } + transactions.push({ + type: TransactionType.Tip, + amountEffective: Amounts.stringify(tipRecord.tipAmountEffective), + amountRaw: Amounts.stringify(tipRecord.tipAmountRaw), + pending: !tipRecord.pickedUpTimestamp, + timestamp: tipRecord.acceptedTimestamp, + transactionId: makeEventId(TransactionType.Tip, tipRecord.walletTipId), + error: tipRecord.lastError, + }); + }); }, ); -- cgit v1.2.3