tipping transaction list entry, integration test and DB simplifications
This commit is contained in:
parent
b9e43e652e
commit
043a5f89fe
@ -109,4 +109,13 @@ runTest(async (t: GlobalTestState) => {
|
||||
console.log(bal);
|
||||
|
||||
t.assertAmountEquals(bal.balances[0].available, "TESTKUDOS:4.85");
|
||||
|
||||
const txns = await wallet.getTransactions();
|
||||
|
||||
console.log("Transactions:", JSON.stringify(txns, undefined, 2));
|
||||
|
||||
t.assertDeepEqual(txns.transactions[0].type, "tip");
|
||||
t.assertDeepEqual(txns.transactions[0].pending, false);
|
||||
t.assertAmountEquals(txns.transactions[0].amountEffective, "TESTKUDOS:4.85");
|
||||
t.assertAmountEquals(txns.transactions[0].amountRaw, "TESTKUDOS:5.0");
|
||||
});
|
||||
|
@ -351,7 +351,7 @@ async function gatherTipPending(
|
||||
onlyDue = false,
|
||||
): Promise<void> {
|
||||
await tx.iter(Stores.tips).forEach((tip) => {
|
||||
if (tip.pickedUp) {
|
||||
if (tip.pickedUpTimestamp) {
|
||||
return;
|
||||
}
|
||||
resp.nextRetryDelay = updateRetryDelay(
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
});
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
@ -950,16 +950,6 @@ export interface TipRecord {
|
||||
*/
|
||||
acceptedTimestamp: Timestamp | undefined;
|
||||
|
||||
/**
|
||||
* Has the user rejected the tip?
|
||||
*/
|
||||
rejectedTimestamp: Timestamp | undefined;
|
||||
|
||||
/**
|
||||
* Have we picked up the tip record from the merchant already?
|
||||
*/
|
||||
pickedUp: boolean;
|
||||
|
||||
/**
|
||||
* The tipped amount.
|
||||
*/
|
||||
@ -970,12 +960,12 @@ export interface TipRecord {
|
||||
/**
|
||||
* Timestamp, the tip can't be picked up anymore after this deadline.
|
||||
*/
|
||||
deadline: Timestamp;
|
||||
tipExpiration: Timestamp;
|
||||
|
||||
/**
|
||||
* The exchange that will sign our coins, chosen by the merchant.
|
||||
*/
|
||||
exchangeUrl: string;
|
||||
exchangeBaseUrl: string;
|
||||
|
||||
/**
|
||||
* Base URL of the merchant that is giving us the tip.
|
||||
@ -990,12 +980,6 @@ export interface TipRecord {
|
||||
|
||||
denomsSel: DenomSelectionState;
|
||||
|
||||
/**
|
||||
* Response if the merchant responded,
|
||||
* undefined otherwise.
|
||||
*/
|
||||
response?: TipResponse[];
|
||||
|
||||
/**
|
||||
* Tip ID chosen by the wallet.
|
||||
*/
|
||||
@ -1006,13 +990,14 @@ export interface TipRecord {
|
||||
*/
|
||||
merchantTipId: string;
|
||||
|
||||
/**
|
||||
* URL to go to once the tip has been accepted.
|
||||
*/
|
||||
nextUrl?: string;
|
||||
|
||||
createdTimestamp: Timestamp;
|
||||
|
||||
/**
|
||||
* Timestamp for when the wallet finished picking up the tip
|
||||
* from the merchant.
|
||||
*/
|
||||
pickedUpTimestamp: Timestamp | undefined;
|
||||
|
||||
/**
|
||||
* Retry info, even present when the operation isn't active to allow indexing
|
||||
* on the next retry timestamp.
|
||||
|
@ -278,18 +278,6 @@ interface TransactionRefund extends TransactionCommon {
|
||||
interface TransactionTip extends TransactionCommon {
|
||||
type: TransactionType.Tip;
|
||||
|
||||
// true if the user still needs to accept/decline this tip
|
||||
waiting: boolean;
|
||||
|
||||
// true if the user has accepted this top, false otherwise
|
||||
accepted: boolean;
|
||||
|
||||
// Exchange that the tip will be (or was) withdrawn from
|
||||
exchangeBaseUrl: string;
|
||||
|
||||
// More information about the merchant that sent the tip
|
||||
merchant: any;
|
||||
|
||||
// Raw amount of the tip, without extra fees that apply
|
||||
amountRaw: AmountString;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user