wallet-core: derive DD37 for tipping
This commit is contained in:
parent
e2e56332e2
commit
ce41337bd1
@ -103,6 +103,8 @@ export enum TransactionMinorState {
|
|||||||
KycRequired = "kyc-required",
|
KycRequired = "kyc-required",
|
||||||
Track = "track",
|
Track = "track",
|
||||||
Refresh = "refresh",
|
Refresh = "refresh",
|
||||||
|
Pickup = "pickup",
|
||||||
|
User = "user",
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TransactionsResponse {
|
export interface TransactionsResponse {
|
||||||
|
@ -35,6 +35,9 @@ import {
|
|||||||
TalerErrorCode,
|
TalerErrorCode,
|
||||||
TalerProtocolTimestamp,
|
TalerProtocolTimestamp,
|
||||||
TipPlanchetDetail,
|
TipPlanchetDetail,
|
||||||
|
TransactionMajorState,
|
||||||
|
TransactionMinorState,
|
||||||
|
TransactionState,
|
||||||
TransactionType,
|
TransactionType,
|
||||||
URL,
|
URL,
|
||||||
} from "@gnu-taler/taler-util";
|
} from "@gnu-taler/taler-util";
|
||||||
@ -67,6 +70,30 @@ import { selectWithdrawalDenominations } from "../util/coinSelection.js";
|
|||||||
|
|
||||||
const logger = new Logger("operations/tip.ts");
|
const logger = new Logger("operations/tip.ts");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the (DD37-style) transaction status based on the
|
||||||
|
* database record of a tip.
|
||||||
|
*/
|
||||||
|
export function computeTipTransactionStatus(
|
||||||
|
tipRecord: TipRecord,
|
||||||
|
): TransactionState {
|
||||||
|
if (tipRecord.pickedUpTimestamp) {
|
||||||
|
return {
|
||||||
|
major: TransactionMajorState.Done,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (tipRecord.acceptedTimestamp) {
|
||||||
|
return {
|
||||||
|
major: TransactionMajorState.Pending,
|
||||||
|
minor: TransactionMinorState.Pickup,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
major: TransactionMajorState.Pending,
|
||||||
|
minor: TransactionMinorState.User,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function prepareTip(
|
export async function prepareTip(
|
||||||
ws: InternalWalletState,
|
ws: InternalWalletState,
|
||||||
talerTipUri: string,
|
talerTipUri: string,
|
||||||
|
@ -68,7 +68,7 @@ import {
|
|||||||
import { InternalWalletState } from "../internal-wallet-state.js";
|
import { InternalWalletState } from "../internal-wallet-state.js";
|
||||||
import { PendingTaskType } from "../pending-types.js";
|
import { PendingTaskType } from "../pending-types.js";
|
||||||
import { assertUnreachable } from "../util/assertUnreachable.js";
|
import { assertUnreachable } from "../util/assertUnreachable.js";
|
||||||
import { checkDbInvariant } from "../util/invariants.js";
|
import { checkDbInvariant, checkLogicInvariant } from "../util/invariants.js";
|
||||||
import { constructTaskIdentifier, TaskIdentifiers } from "../util/retries.js";
|
import { constructTaskIdentifier, TaskIdentifiers } from "../util/retries.js";
|
||||||
import {
|
import {
|
||||||
makeTombstoneId,
|
makeTombstoneId,
|
||||||
@ -92,7 +92,7 @@ import {
|
|||||||
} from "./pay-merchant.js";
|
} from "./pay-merchant.js";
|
||||||
import { processPeerPullCredit } from "./pay-peer.js";
|
import { processPeerPullCredit } from "./pay-peer.js";
|
||||||
import { processRefreshGroup } from "./refresh.js";
|
import { processRefreshGroup } from "./refresh.js";
|
||||||
import { processTip } from "./tip.js";
|
import { computeTipTransactionStatus, processTip } from "./tip.js";
|
||||||
import {
|
import {
|
||||||
augmentPaytoUrisForWithdrawal,
|
augmentPaytoUrisForWithdrawal,
|
||||||
processWithdrawalGroup,
|
processWithdrawalGroup,
|
||||||
@ -823,11 +823,11 @@ function buildTransactionForTip(
|
|||||||
tipRecord: TipRecord,
|
tipRecord: TipRecord,
|
||||||
ort?: OperationRetryRecord,
|
ort?: OperationRetryRecord,
|
||||||
): Transaction {
|
): Transaction {
|
||||||
if (!tipRecord.acceptedTimestamp) throw Error("");
|
checkLogicInvariant(!!tipRecord.acceptedTimestamp);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: TransactionType.Tip,
|
type: TransactionType.Tip,
|
||||||
txState: mkTxStateUnknown(),
|
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: tipRecord.pickedUpTimestamp
|
||||||
|
Loading…
Reference in New Issue
Block a user