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