summaryrefslogtreecommitdiff
path: root/src/operations/history.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-12-13 13:10:20 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-12-13 13:10:20 +0100
commit04a60770ee6a282f4833b8bfe72525ea36b8e295 (patch)
treeefb2289bec715369ada44624a134cdc15f395295 /src/operations/history.ts
parentf3329ecf062b217b2e062b92034152f623685a87 (diff)
downloadwallet-core-04a60770ee6a282f4833b8bfe72525ea36b8e295.tar.gz
wallet-core-04a60770ee6a282f4833b8bfe72525ea36b8e295.tar.bz2
wallet-core-04a60770ee6a282f4833b8bfe72525ea36b8e295.zip
new history schema
Diffstat (limited to 'src/operations/history.ts')
-rw-r--r--src/operations/history.ts165
1 files changed, 3 insertions, 162 deletions
diff --git a/src/operations/history.ts b/src/operations/history.ts
index b8d756cc6..64f5b21cc 100644
--- a/src/operations/history.ts
+++ b/src/operations/history.ts
@@ -17,12 +17,11 @@
/**
* Imports.
*/
-import { Database } from "../util/query";
import { InternalWalletState } from "./state";
import { Stores, TipRecord } from "../types/dbTypes";
import * as Amounts from "../util/amounts";
import { AmountJson } from "../util/amounts";
-import { HistoryQuery, HistoryEvent } from "../types/history";
+import { HistoryQuery, HistoryEvent, HistoryEventType } from "../types/history";
/**
* Retrive the full event history for this wallet.
@@ -52,166 +51,8 @@ export async function getHistory(
Stores.withdrawalSession,
],
async tx => {
- await tx.iter(Stores.proposals).forEach(p => {
- history.push({
- detail: {},
- timestamp: p.timestamp,
- type: "claim-order",
- explicit: false,
- });
- });
-
- await tx.iter(Stores.withdrawalSession).forEach(w => {
- history.push({
- detail: {
- withdrawalAmount: w.rawWithdrawalAmount,
- },
- timestamp: w.startTimestamp,
- type: "withdraw-started",
- explicit: false,
- });
- if (w.finishTimestamp) {
- history.push({
- detail: {
- withdrawalAmount: w.rawWithdrawalAmount,
- },
- timestamp: w.finishTimestamp,
- type: "withdraw-finished",
- explicit: false,
- });
- }
- });
-
- await tx.iter(Stores.purchases).forEach(p => {
- history.push({
- detail: {
- amount: p.contractTerms.amount,
- contractTermsHash: p.contractTermsHash,
- fulfillmentUrl: p.contractTerms.fulfillment_url,
- merchantName: p.contractTerms.merchant.name,
- },
- timestamp: p.acceptTimestamp,
- type: "pay-started",
- explicit: false,
- });
- if (p.firstSuccessfulPayTimestamp) {
- history.push({
- detail: {
- amount: p.contractTerms.amount,
- contractTermsHash: p.contractTermsHash,
- fulfillmentUrl: p.contractTerms.fulfillment_url,
- merchantName: p.contractTerms.merchant.name,
- },
- timestamp: p.firstSuccessfulPayTimestamp,
- type: "pay-finished",
- explicit: false,
- });
- }
- if (p.lastRefundStatusTimestamp) {
- const contractAmount = Amounts.parseOrThrow(p.contractTerms.amount);
- const amountsPending = Object.keys(p.refundsPending).map(x =>
- Amounts.parseOrThrow(p.refundsPending[x].refund_amount),
- );
- const amountsDone = Object.keys(p.refundsDone).map(x =>
- Amounts.parseOrThrow(p.refundsDone[x].refund_amount),
- );
- const amounts: AmountJson[] = amountsPending.concat(amountsDone);
- const amount = Amounts.add(
- Amounts.getZero(contractAmount.currency),
- ...amounts,
- ).amount;
-
- history.push({
- detail: {
- contractTermsHash: p.contractTermsHash,
- fulfillmentUrl: p.contractTerms.fulfillment_url,
- merchantName: p.contractTerms.merchant.name,
- refundAmount: amount,
- },
- timestamp: p.lastRefundStatusTimestamp,
- type: "refund",
- explicit: false,
- });
- }
- });
-
- await tx.iter(Stores.reserves).forEach(r => {
- const reserveType = r.bankWithdrawStatusUrl ? "taler-bank" : "manual";
- history.push({
- detail: {
- exchangeBaseUrl: r.exchangeBaseUrl,
- requestedAmount: Amounts.toString(r.initiallyRequestedAmount),
- reservePub: r.reservePub,
- reserveType,
- bankWithdrawStatusUrl: r.bankWithdrawStatusUrl,
- },
- timestamp: r.created,
- type: "reserve-created",
- explicit: false,
- });
- if (r.timestampConfirmed) {
- history.push({
- detail: {
- exchangeBaseUrl: r.exchangeBaseUrl,
- requestedAmount: Amounts.toString(r.initiallyRequestedAmount),
- reservePub: r.reservePub,
- reserveType,
- bankWithdrawStatusUrl: r.bankWithdrawStatusUrl,
- },
- timestamp: r.created,
- type: "reserve-confirmed",
- explicit: false,
- });
- }
- });
-
- await tx.iter(Stores.tips).forEach(tip => {
- history.push({
- detail: {
- accepted: tip.accepted,
- amount: tip.amount,
- merchantBaseUrl: tip.merchantBaseUrl,
- tipId: tip.merchantTipId,
- },
- timestamp: tip.createdTimestamp,
- explicit: false,
- type: "tip",
- });
- });
-
- await tx.iter(Stores.exchanges).forEach(exchange => {
- history.push({
- type: "exchange-added",
- explicit: false,
- timestamp: exchange.timestampAdded,
- detail: {
- exchangeBaseUrl: exchange.baseUrl,
- },
- });
- });
-
- await tx.iter(Stores.refresh).forEach((r) => {
- history.push({
- type: "refresh-started",
- explicit: false,
- timestamp: r.created,
- detail: {
- refreshSessionId: r.refreshSessionId,
- },
- });
- if (r.finishedTimestamp) {
- history.push({
- type: "refresh-finished",
- explicit: false,
- timestamp: r.finishedTimestamp,
- detail: {
- refreshSessionId: r.refreshSessionId,
- },
- });
- }
-
- });
- },
+ // FIXME: implement new history schema!!
+ }
);
history.sort((h1, h2) => Math.sign(h1.timestamp.t_ms - h2.timestamp.t_ms));