wallet-core: missing suspended states

This commit is contained in:
Florian Dold 2023-05-28 18:03:28 +02:00
parent bd7ca80ff6
commit 246f914ca6
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
4 changed files with 77 additions and 37 deletions

View File

@ -1839,9 +1839,12 @@ export enum PeerPullPaymentInitiationStatus {
PendingReady = 11 /* ACTIVE_START + 1 */, PendingReady = 11 /* ACTIVE_START + 1 */,
PendingMergeKycRequired = 12 /* ACTIVE_START + 2 */, PendingMergeKycRequired = 12 /* ACTIVE_START + 2 */,
PendingWithdrawing = 13, PendingWithdrawing = 13,
SuspendedCreatePurse = 30, SuspendedCreatePurse = 30,
SuspendedReady = 31, SuspendedReady = 31,
SuspendedWithdrawing = 32, SuspendedMergeKycRequired = 32,
SuspendedWithdrawing = 33,
DonePurseDeposited = 50 /* DORMANT_START */, DonePurseDeposited = 50 /* DORMANT_START */,
} }
@ -1898,14 +1901,20 @@ export interface PeerPullPaymentInitiationRecord {
} }
export enum PeerPushPaymentIncomingStatus { export enum PeerPushPaymentIncomingStatus {
Proposed = 30 /* USER_ATTENTION_START */, PendingMerge = 10 /* ACTIVE_START */,
Accepted = 10 /* ACTIVE_START */,
MergeKycRequired = 11 /* ACTIVE_START + 1 */, MergeKycRequired = 11 /* ACTIVE_START + 1 */,
/** /**
* Merge was successful and withdrawal group has been created, now * Merge was successful and withdrawal group has been created, now
* everything is in the hand of the withdrawal group. * everything is in the hand of the withdrawal group.
*/ */
Withdrawing = 12, PendingWithdrawing = 12,
SuspendedMerge = 20,
SuspendedMergeKycRequired = 21,
SuspendedWithdrawing = 22,
DialogProposed = 30 /* USER_ATTENTION_START */,
Done = 50 /* DORMANT_START */, Done = 50 /* DORMANT_START */,
} }
@ -1956,10 +1965,14 @@ export interface PeerPushPaymentIncomingRecord {
kycInfo?: KycPendingInfo; kycInfo?: KycPendingInfo;
} }
export enum PeerPullPaymentIncomingStatus { export enum PeerPullDebitRecordStatus {
Proposed = 30 /* USER_ATTENTION_START */, PendingDeposit = 10 /* ACTIVE_START */,
Accepted = 10 /* ACTIVE_START */,
Paid = 50 /* DORMANT_START */, SuspendedDeposit = 11,
DialogProposed = 30 /* USER_ATTENTION_START */,
DonePaid = 50 /* DORMANT_START */,
} }
export interface PeerPullPaymentCoinSelection { export interface PeerPullPaymentCoinSelection {
@ -1995,7 +2008,7 @@ export interface PeerPullPaymentIncomingRecord {
/** /**
* Status of the peer push payment incoming initiation. * Status of the peer push payment incoming initiation.
*/ */
status: PeerPullPaymentIncomingStatus; status: PeerPullDebitRecordStatus;
/** /**
* Estimated total cost when the record was created. * Estimated total cost when the record was created.

View File

@ -84,7 +84,7 @@ import { SpendCoinDetails } from "../crypto/cryptoImplementation.js";
import { import {
DenominationRecord, DenominationRecord,
PeerPullPaymentIncomingRecord, PeerPullPaymentIncomingRecord,
PeerPullPaymentIncomingStatus, PeerPullDebitRecordStatus,
PeerPullPaymentInitiationRecord, PeerPullPaymentInitiationRecord,
PeerPullPaymentInitiationStatus, PeerPullPaymentInitiationStatus,
PeerPushPaymentCoinSelection, PeerPushPaymentCoinSelection,
@ -828,7 +828,8 @@ export async function preparePeerPushCredit(
existing.existingPushInc.peerPushPaymentIncomingId, existing.existingPushInc.peerPushPaymentIncomingId,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.PeerPushCredit, tag: TransactionType.PeerPushCredit,
peerPushPaymentIncomingId: existing.existingPushInc.peerPushPaymentIncomingId, peerPushPaymentIncomingId:
existing.existingPushInc.peerPushPaymentIncomingId,
}), }),
}; };
} }
@ -892,7 +893,7 @@ export async function preparePeerPushCredit(
pursePub: pursePub, pursePub: pursePub,
timestamp: TalerPreciseTimestamp.now(), timestamp: TalerPreciseTimestamp.now(),
contractTermsHash, contractTermsHash,
status: PeerPushPaymentIncomingStatus.Proposed, status: PeerPushPaymentIncomingStatus.DialogProposed,
withdrawalGroupId, withdrawalGroupId,
currency: Amounts.currencyOf(purseStatus.balance), currency: Amounts.currencyOf(purseStatus.balance),
estimatedAmountEffective: Amounts.stringify( estimatedAmountEffective: Amounts.stringify(
@ -1120,7 +1121,7 @@ export async function processPeerPushCredit(
return; return;
} }
if ( if (
peerInc.status === PeerPushPaymentIncomingStatus.Accepted || peerInc.status === PeerPushPaymentIncomingStatus.PendingMerge ||
peerInc.status === PeerPushPaymentIncomingStatus.MergeKycRequired peerInc.status === PeerPushPaymentIncomingStatus.MergeKycRequired
) { ) {
peerInc.status = PeerPushPaymentIncomingStatus.Done; peerInc.status = PeerPushPaymentIncomingStatus.Done;
@ -1149,8 +1150,8 @@ export async function confirmPeerPushCredit(
if (!peerInc) { if (!peerInc) {
return; return;
} }
if (peerInc.status === PeerPushPaymentIncomingStatus.Proposed) { if (peerInc.status === PeerPushPaymentIncomingStatus.DialogProposed) {
peerInc.status = PeerPushPaymentIncomingStatus.Accepted; peerInc.status = PeerPushPaymentIncomingStatus.PendingMerge;
} }
await tx.peerPushPaymentIncoming.put(peerInc); await tx.peerPushPaymentIncoming.put(peerInc);
}); });
@ -1185,7 +1186,7 @@ export async function processPeerPullDebit(
if (!peerPullInc) { if (!peerPullInc) {
throw Error("peer pull debit not found"); throw Error("peer pull debit not found");
} }
if (peerPullInc.status === PeerPullPaymentIncomingStatus.Accepted) { if (peerPullInc.status === PeerPullDebitRecordStatus.PendingDeposit) {
const pursePub = peerPullInc.pursePub; const pursePub = peerPullInc.pursePub;
const coinSel = peerPullInc.coinSel; const coinSel = peerPullInc.coinSel;
@ -1231,8 +1232,8 @@ export async function processPeerPullDebit(
if (!pi) { if (!pi) {
throw Error("peer pull payment not found anymore"); throw Error("peer pull payment not found anymore");
} }
if (pi.status === PeerPullPaymentIncomingStatus.Accepted) { if (pi.status === PeerPullDebitRecordStatus.PendingDeposit) {
pi.status = PeerPullPaymentIncomingStatus.Paid; pi.status = PeerPullDebitRecordStatus.DonePaid;
} }
await tx.peerPullPaymentIncoming.put(pi); await tx.peerPullPaymentIncoming.put(pi);
}); });
@ -1311,8 +1312,8 @@ export async function confirmPeerPullDebit(
if (!pi) { if (!pi) {
throw Error(); throw Error();
} }
if (pi.status === PeerPullPaymentIncomingStatus.Proposed) { if (pi.status === PeerPullDebitRecordStatus.DialogProposed) {
pi.status = PeerPullPaymentIncomingStatus.Accepted; pi.status = PeerPullDebitRecordStatus.PendingDeposit;
pi.coinSel = { pi.coinSel = {
coinPubs: sel.coins.map((x) => x.coinPub), coinPubs: sel.coins.map((x) => x.coinPub),
contributions: sel.coins.map((x) => x.contribution), contributions: sel.coins.map((x) => x.contribution),
@ -1374,7 +1375,8 @@ export async function preparePeerPullDebit(
existingPullIncomingRecord.peerPullPaymentIncomingId, existingPullIncomingRecord.peerPullPaymentIncomingId,
transactionId: constructTransactionIdentifier({ transactionId: constructTransactionIdentifier({
tag: TransactionType.PeerPullDebit, tag: TransactionType.PeerPullDebit,
peerPullPaymentIncomingId: existingPullIncomingRecord.peerPullPaymentIncomingId, peerPullPaymentIncomingId:
existingPullIncomingRecord.peerPullPaymentIncomingId,
}), }),
}; };
} }
@ -1453,7 +1455,7 @@ export async function preparePeerPullDebit(
pursePub: pursePub, pursePub: pursePub,
timestampCreated: TalerPreciseTimestamp.now(), timestampCreated: TalerPreciseTimestamp.now(),
contractTerms, contractTerms,
status: PeerPullPaymentIncomingStatus.Proposed, status: PeerPullDebitRecordStatus.DialogProposed,
totalCostEstimated: Amounts.stringify(totalAmount), totalCostEstimated: Amounts.stringify(totalAmount),
}); });
}); });
@ -2249,12 +2251,12 @@ export function computePeerPushCreditTransactionState(
pushCreditRecord: PeerPushPaymentIncomingRecord, pushCreditRecord: PeerPushPaymentIncomingRecord,
): TransactionState { ): TransactionState {
switch (pushCreditRecord.status) { switch (pushCreditRecord.status) {
case PeerPushPaymentIncomingStatus.Proposed: case PeerPushPaymentIncomingStatus.DialogProposed:
return { return {
major: TransactionMajorState.Dialog, major: TransactionMajorState.Dialog,
minor: TransactionMinorState.Proposed, minor: TransactionMinorState.Proposed,
}; };
case PeerPushPaymentIncomingStatus.Accepted: case PeerPushPaymentIncomingStatus.PendingMerge:
return { return {
major: TransactionMajorState.Pending, major: TransactionMajorState.Pending,
minor: TransactionMinorState.Merge, minor: TransactionMinorState.Merge,
@ -2268,11 +2270,26 @@ export function computePeerPushCreditTransactionState(
major: TransactionMajorState.Pending, major: TransactionMajorState.Pending,
minor: TransactionMinorState.KycRequired, minor: TransactionMinorState.KycRequired,
}; };
case PeerPushPaymentIncomingStatus.Withdrawing: case PeerPushPaymentIncomingStatus.PendingWithdrawing:
return { return {
major: TransactionMajorState.Pending, major: TransactionMajorState.Pending,
minor: TransactionMinorState.Withdraw, minor: TransactionMinorState.Withdraw,
}; };
case PeerPushPaymentIncomingStatus.SuspendedMerge:
return {
major: TransactionMajorState.Suspended,
minor: TransactionMinorState.Merge,
};
case PeerPushPaymentIncomingStatus.SuspendedMergeKycRequired:
return {
major: TransactionMajorState.Suspended,
minor: TransactionMinorState.MergeKycRequired,
};
case PeerPushPaymentIncomingStatus.SuspendedWithdrawing:
return {
major: TransactionMajorState.Suspended,
minor: TransactionMinorState.Withdraw,
};
} }
} }
@ -2319,6 +2336,11 @@ export function computePeerPullCreditTransactionState(
major: TransactionMajorState.Pending, major: TransactionMajorState.Pending,
minor: TransactionMinorState.Withdraw, minor: TransactionMinorState.Withdraw,
}; };
case PeerPullPaymentInitiationStatus.SuspendedMergeKycRequired:
return {
major: TransactionMajorState.Suspended,
minor: TransactionMinorState.MergeKycRequired,
};
} }
} }
@ -2326,19 +2348,24 @@ export function computePeerPullDebitTransactionState(
pullDebitRecord: PeerPullPaymentIncomingRecord, pullDebitRecord: PeerPullPaymentIncomingRecord,
): TransactionState { ): TransactionState {
switch (pullDebitRecord.status) { switch (pullDebitRecord.status) {
case PeerPullPaymentIncomingStatus.Proposed: case PeerPullDebitRecordStatus.DialogProposed:
return { return {
major: TransactionMajorState.Dialog, major: TransactionMajorState.Dialog,
minor: TransactionMinorState.Proposed, minor: TransactionMinorState.Proposed,
}; };
case PeerPullPaymentIncomingStatus.Accepted: case PeerPullDebitRecordStatus.PendingDeposit:
return { return {
major: TransactionMajorState.Pending, major: TransactionMajorState.Pending,
minor: TransactionMinorState.Deposit, minor: TransactionMinorState.Deposit,
}; };
case PeerPullPaymentIncomingStatus.Paid: case PeerPullDebitRecordStatus.DonePaid:
return { return {
major: TransactionMajorState.Done, major: TransactionMajorState.Done,
}; };
case PeerPullDebitRecordStatus.SuspendedDeposit:
return {
major: TransactionMajorState.Suspended,
minor: TransactionMinorState.Deposit,
};
} }
} }

View File

@ -29,7 +29,7 @@ import {
OperationStatus, OperationStatus,
OperationStatusRange, OperationStatusRange,
PeerPushPaymentInitiationStatus, PeerPushPaymentInitiationStatus,
PeerPullPaymentIncomingStatus, PeerPullDebitRecordStatus,
PeerPushPaymentIncomingStatus, PeerPushPaymentIncomingStatus,
PeerPullPaymentInitiationStatus, PeerPullPaymentInitiationStatus,
} from "../db.js"; } from "../db.js";
@ -395,11 +395,11 @@ async function gatherPeerPullDebitPending(
): Promise<void> { ): Promise<void> {
await tx.peerPullPaymentIncoming.iter().forEachAsync(async (pi) => { await tx.peerPullPaymentIncoming.iter().forEachAsync(async (pi) => {
switch (pi.status) { switch (pi.status) {
case PeerPullPaymentIncomingStatus.Paid: case PeerPullDebitRecordStatus.DonePaid:
return; return;
case PeerPullPaymentIncomingStatus.Proposed: case PeerPullDebitRecordStatus.DialogProposed:
return; return;
case PeerPullPaymentIncomingStatus.Accepted: case PeerPullDebitRecordStatus.PendingDeposit:
break; break;
} }
const opId = TaskIdentifiers.forPeerPullPaymentDebit(pi); const opId = TaskIdentifiers.forPeerPullPaymentDebit(pi);
@ -452,7 +452,7 @@ async function gatherPeerPushCreditPending(
): Promise<void> { ): Promise<void> {
await tx.peerPushPaymentIncoming.iter().forEachAsync(async (pi) => { await tx.peerPushPaymentIncoming.iter().forEachAsync(async (pi) => {
switch (pi.status) { switch (pi.status) {
case PeerPushPaymentIncomingStatus.Proposed: case PeerPushPaymentIncomingStatus.DialogProposed:
return; return;
case PeerPushPaymentIncomingStatus.Done: case PeerPushPaymentIncomingStatus.Done:
return; return;

View File

@ -48,7 +48,7 @@ import {
ExchangeDetailsRecord, ExchangeDetailsRecord,
OperationRetryRecord, OperationRetryRecord,
PeerPullPaymentIncomingRecord, PeerPullPaymentIncomingRecord,
PeerPullPaymentIncomingStatus, PeerPullDebitRecordStatus,
PeerPullPaymentInitiationRecord, PeerPullPaymentInitiationRecord,
PeerPushPaymentIncomingRecord, PeerPushPaymentIncomingRecord,
PeerPushPaymentIncomingStatus, PeerPushPaymentIncomingStatus,
@ -906,8 +906,8 @@ export async function getTransactions(
return; return;
} }
if ( if (
pi.status !== PeerPullPaymentIncomingStatus.Accepted && pi.status !== PeerPullDebitRecordStatus.PendingDeposit &&
pi.status !== PeerPullPaymentIncomingStatus.Paid pi.status !== PeerPullDebitRecordStatus.DonePaid
) { ) {
return; return;
} }
@ -926,7 +926,7 @@ export async function getTransactions(
if (shouldSkipSearch(transactionsRequest, [])) { if (shouldSkipSearch(transactionsRequest, [])) {
return; return;
} }
if (pi.status === PeerPushPaymentIncomingStatus.Proposed) { if (pi.status === PeerPushPaymentIncomingStatus.DialogProposed) {
// We don't report proposed push credit transactions, user needs // We don't report proposed push credit transactions, user needs
// to scan URI again and confirm to see it. // to scan URI again and confirm to see it.
return; return;