wallet-core: more notifications
This commit is contained in:
parent
0406160869
commit
5f325aa4d3
@ -552,7 +552,7 @@ async function processDownloadProposal(
|
||||
return {
|
||||
oldTxState,
|
||||
newTxState,
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
@ -659,7 +659,7 @@ async function createPurchase(
|
||||
return {
|
||||
oldTxState,
|
||||
newTxState,
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
const transactionId = constructTransactionIdentifier({
|
||||
@ -730,7 +730,7 @@ async function storeFirstPaySuccess(
|
||||
return {
|
||||
oldTxState,
|
||||
newTxState,
|
||||
}
|
||||
};
|
||||
});
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
}
|
||||
@ -1325,6 +1325,11 @@ export async function confirmPay(
|
||||
throw Error(`proposal with id ${proposalId} not found`);
|
||||
}
|
||||
|
||||
const transactionId = constructTransactionIdentifier({
|
||||
tag: TransactionType.Payment,
|
||||
proposalId,
|
||||
});
|
||||
|
||||
const d = await expectProposalDownload(ws, proposal);
|
||||
if (!d) {
|
||||
throw Error("proposal is in invalid state");
|
||||
@ -1395,7 +1400,7 @@ export async function confirmPay(
|
||||
`recording payment on ${proposal.orderId} with session ID ${sessionId}`,
|
||||
);
|
||||
|
||||
await ws.db
|
||||
const transitionInfo = await ws.db
|
||||
.mktx((x) => [
|
||||
x.purchases,
|
||||
x.coins,
|
||||
@ -1408,6 +1413,7 @@ export async function confirmPay(
|
||||
if (!p) {
|
||||
return;
|
||||
}
|
||||
const oldTxState = computePayMerchantTransactionState(p);
|
||||
switch (p.purchaseStatus) {
|
||||
case PurchaseStatus.Proposed:
|
||||
p.payInfo = {
|
||||
@ -1437,8 +1443,12 @@ export async function confirmPay(
|
||||
default:
|
||||
break;
|
||||
}
|
||||
const newTxState = computePayMerchantTransactionState(p);
|
||||
return { oldTxState, newTxState };
|
||||
});
|
||||
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
|
||||
ws.notify({
|
||||
type: NotificationType.ProposalAccepted,
|
||||
proposalId: proposal.proposalId,
|
||||
@ -1450,7 +1460,6 @@ export async function confirmPay(
|
||||
export async function processPurchase(
|
||||
ws: InternalWalletState,
|
||||
proposalId: string,
|
||||
options: Record<any, never> = {},
|
||||
): Promise<OperationAttemptResult> {
|
||||
const purchase = await ws.db
|
||||
.mktx((x) => [x.purchases])
|
||||
@ -1682,37 +1691,44 @@ export async function refuseProposal(
|
||||
ws: InternalWalletState,
|
||||
proposalId: string,
|
||||
): Promise<void> {
|
||||
const success = await ws.db
|
||||
const transactionId = constructTransactionIdentifier({
|
||||
tag: TransactionType.Payment,
|
||||
proposalId,
|
||||
});
|
||||
const transitionInfo = await ws.db
|
||||
.mktx((x) => [x.purchases])
|
||||
.runReadWrite(async (tx) => {
|
||||
const proposal = await tx.purchases.get(proposalId);
|
||||
if (!proposal) {
|
||||
logger.trace(`proposal ${proposalId} not found, won't refuse proposal`);
|
||||
return false;
|
||||
return undefined;
|
||||
}
|
||||
if (proposal.purchaseStatus !== PurchaseStatus.Proposed) {
|
||||
return false;
|
||||
return undefined;
|
||||
}
|
||||
const oldTxState = computePayMerchantTransactionState(proposal);
|
||||
proposal.purchaseStatus = PurchaseStatus.AbortedProposalRefused;
|
||||
const newTxState = computePayMerchantTransactionState(proposal);
|
||||
await tx.purchases.put(proposal);
|
||||
return true;
|
||||
return { oldTxState, newTxState };
|
||||
});
|
||||
if (success) {
|
||||
ws.notify({
|
||||
type: NotificationType.ProposalRefused,
|
||||
});
|
||||
}
|
||||
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
}
|
||||
|
||||
export async function abortPayMerchant(
|
||||
ws: InternalWalletState,
|
||||
proposalId: string,
|
||||
): Promise<void> {
|
||||
const transactionId = constructTransactionIdentifier({
|
||||
tag: TransactionType.Payment,
|
||||
proposalId,
|
||||
});
|
||||
const opId = constructTaskIdentifier({
|
||||
tag: PendingTaskType.Purchase,
|
||||
proposalId,
|
||||
});
|
||||
await ws.db
|
||||
const transitionInfo = await ws.db
|
||||
.mktx((x) => [
|
||||
x.purchases,
|
||||
x.refreshGroups,
|
||||
@ -1726,6 +1742,7 @@ export async function abortPayMerchant(
|
||||
if (!purchase) {
|
||||
throw Error("purchase not found");
|
||||
}
|
||||
const oldTxState = computePayMerchantTransactionState(purchase);
|
||||
const oldStatus = purchase.purchaseStatus;
|
||||
if (purchase.timestampFirstSuccessfulPay) {
|
||||
// No point in aborting it. We don't even report an error.
|
||||
@ -1757,8 +1774,10 @@ export async function abortPayMerchant(
|
||||
}
|
||||
}
|
||||
await tx.operationRetries.delete(opId);
|
||||
const newTxState = computePayMerchantTransactionState(purchase);
|
||||
return { oldTxState, newTxState };
|
||||
});
|
||||
|
||||
notifyTransition(ws, transactionId, transitionInfo);
|
||||
ws.workAvailable.trigger();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user