aboutsummaryrefslogtreecommitdiff
path: root/src/operations/history.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-01-20 11:53:21 +0100
committerFlorian Dold <florian.dold@gmail.com>2020-01-20 11:53:21 +0100
commitc5906abf106d22cc35b8facdda4313b6125160b9 (patch)
treec66f888d567f17733e8e7c1882156c83a515e707 /src/operations/history.ts
parenta76219b8debfc3f7e932ec9ad996248e431f437e (diff)
downloadwallet-core-c5906abf106d22cc35b8facdda4313b6125160b9.tar.xz
verboseDetails for pay and withdraw
Diffstat (limited to 'src/operations/history.ts')
-rw-r--r--src/operations/history.ts45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/operations/history.ts b/src/operations/history.ts
index 4eb626d6c..54874f64f 100644
--- a/src/operations/history.ts
+++ b/src/operations/history.ts
@@ -23,6 +23,8 @@ import {
TipRecord,
ProposalStatus,
ProposalRecord,
+ PlanchetRecord,
+ CoinRecord,
} from "../types/dbTypes";
import * as Amounts from "../util/amounts";
import { AmountJson } from "../util/amounts";
@@ -33,6 +35,8 @@ import {
OrderShortInfo,
ReserveType,
ReserveCreationDetail,
+ VerbosePayCoinDetails,
+ VerboseWithdrawDetails,
} from "../types/history";
import { assertUnreachable } from "../util/assertUnreachable";
import { TransactionHandle, Store } from "../util/query";
@@ -203,6 +207,22 @@ export async function getHistory(
tx.iter(Stores.withdrawalSession).forEach(wsr => {
if (wsr.timestampFinish) {
+ const cs: PlanchetRecord[] = [];
+ wsr.planchets.forEach((x) => {
+ if (x) {
+ cs.push(x);
+ }
+ });
+ const verboseDetails: VerboseWithdrawDetails = {
+ coins: cs.map((x) => ({
+ value: Amounts.toString(x.coinValue),
+ denomPub: x.denomPub,
+ })),
+ };
+ const coins = cs.map((x) => ({
+ value: x.coinValue
+ }));
+
history.push({
type: HistoryEventType.Withdrawn,
withdrawSessionId: wsr.withdrawSessionId,
@@ -215,6 +235,7 @@ export async function getHistory(
exchangeBaseUrl: wsr.exchangeBaseUrl,
timestamp: wsr.timestampFinish,
withdrawalSource: wsr.source,
+ verboseDetails,
});
}
});
@@ -234,6 +255,29 @@ export async function getHistory(
if (!orderShortInfo) {
return;
}
+ const coins: {
+ value: string,
+ contribution: string;
+ denomPub: string;
+ }[] = [];
+ for (const x of purchase.payReq.coins) {
+ const c = await tx.get(Stores.coins, x.coin_pub);
+ if (!c) {
+ // FIXME: what to do here??
+ continue;
+ }
+ const d = await tx.get(Stores.denominations, [c.exchangeBaseUrl, c.denomPub]);
+ if (!d) {
+ // FIXME: what to do here??
+ continue;
+ }
+ coins.push({
+ contribution: x.contribution,
+ denomPub: c.denomPub,
+ value: Amounts.toString(d.value),
+ });
+ }
+ const verboseDetails: VerbosePayCoinDetails = { coins };
const amountPaidWithFees = Amounts.sum(
purchase.payReq.coins.map(x => Amounts.parseOrThrow(x.contribution)),
).amount;
@@ -246,6 +290,7 @@ export async function getHistory(
timestamp: pe.timestamp,
numCoins: purchase.payReq.coins.length,
amountPaidWithFees: Amounts.toString(amountPaidWithFees),
+ verboseDetails,
});
});