summaryrefslogtreecommitdiff
path: root/src/operations/pay.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-15 16:59:00 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-15 16:59:00 +0100
commit4966376839365536923cd6cfbb86d15071432e1a (patch)
tree6658b4a84df5ba6a0189e6d79e37fb0cc7fb597a /src/operations/pay.ts
parentf4043a0f8114b1b8612e01a5cdf65b8d6ffc6f00 (diff)
downloadwallet-core-4966376839365536923cd6cfbb86d15071432e1a.tar.gz
wallet-core-4966376839365536923cd6cfbb86d15071432e1a.tar.bz2
wallet-core-4966376839365536923cd6cfbb86d15071432e1a.zip
group refresh sessions into groups for nicer history
Diffstat (limited to 'src/operations/pay.ts')
-rw-r--r--src/operations/pay.ts20
1 files changed, 8 insertions, 12 deletions
diff --git a/src/operations/pay.ts b/src/operations/pay.ts
index 27f0e4404..ccb55305d 100644
--- a/src/operations/pay.ts
+++ b/src/operations/pay.ts
@@ -34,6 +34,7 @@ import {
PreparePayResult,
ConfirmPayResult,
OperationError,
+ RefreshReason,
} from "../types/walletTypes";
import {
Database
@@ -65,7 +66,7 @@ import {
parseRefundUri,
getOrderDownloadUrl,
} from "../util/taleruri";
-import { getTotalRefreshCost, refresh } from "./refresh";
+import { getTotalRefreshCost, createRefreshGroup } from "./refresh";
import { encodeCrock, getRandomBytes } from "../crypto/talerCrypto";
import { guardOperationException } from "./errors";
import { assertUnreachable } from "../util/assertUnreachable";
@@ -782,26 +783,21 @@ export async function submitPay(
console.error("coin not found");
throw Error("coin used in payment not found");
}
- c.status = CoinStatus.Dirty;
+ c.status = CoinStatus.Dormant;
modifiedCoins.push(c);
}
await ws.db.runWithWriteTransaction(
- [Stores.coins, Stores.purchases],
+ [Stores.coins, Stores.purchases, Stores.refreshGroups],
async tx => {
for (let c of modifiedCoins) {
await tx.put(Stores.coins, c);
}
+ await createRefreshGroup(tx, modifiedCoins.map((x) => ({ coinPub: x.coinPub })), RefreshReason.Pay);
await tx.put(Stores.purchases, purchase);
},
);
- for (const c of purchase.payReq.coins) {
- refresh(ws, c.coin_pub).catch(e => {
- console.log("error in refreshing after payment:", e);
- });
- }
-
const nextUrl = getNextUrl(purchase.contractTerms);
ws.cachedNextUrl[purchase.contractTerms.fulfillment_url] = {
nextUrl,
@@ -1433,7 +1429,7 @@ async function processPurchaseApplyRefundImpl(
let allRefundsProcessed = false;
await ws.db.runWithWriteTransaction(
- [Stores.purchases, Stores.coins],
+ [Stores.purchases, Stores.coins, Stores.refreshGroups],
async tx => {
const p = await tx.get(Stores.purchases, proposalId);
if (!p) {
@@ -1456,10 +1452,11 @@ async function processPurchaseApplyRefundImpl(
}
const refundAmount = Amounts.parseOrThrow(perm.refund_amount);
const refundFee = Amounts.parseOrThrow(perm.refund_fee);
- c.status = CoinStatus.Dirty;
+ c.status = CoinStatus.Dormant;
c.currentAmount = Amounts.add(c.currentAmount, refundAmount).amount;
c.currentAmount = Amounts.sub(c.currentAmount, refundFee).amount;
await tx.put(Stores.coins, c);
+ await createRefreshGroup(tx, [{ coinPub: perm.coin_pub }], RefreshReason.Refund);
},
);
if (allRefundsProcessed) {
@@ -1467,7 +1464,6 @@ async function processPurchaseApplyRefundImpl(
type: NotificationType.RefundFinished,
});
}
- await refresh(ws, perm.coin_pub);
}
ws.notify({