From 03782f8aea043042aaa069de0b91cdb80fbb4679 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 15 Oct 2017 18:30:02 +0200 Subject: derive history from db instead of storing it --- src/webex/messages.ts | 4 ---- src/webex/notify.ts | 16 ++++++---------- src/webex/pages/popup.tsx | 23 ++++++++++------------- src/webex/pages/refund.tsx | 6 ++++-- src/webex/pages/tree.tsx | 2 +- src/webex/wxApi.ts | 9 +-------- src/webex/wxBackend.ts | 12 +----------- 7 files changed, 23 insertions(+), 49 deletions(-) (limited to 'src/webex') diff --git a/src/webex/messages.ts b/src/webex/messages.ts index 122bd8fe2..ca51abf1d 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -92,10 +92,6 @@ export interface MessageMap { request: { contract: object }; response: string; }; - "put-history-entry": { - request: { historyEntry: types.HistoryRecord }; - response: void; - }; "save-proposal": { request: { proposal: types.ProposalRecord }; response: void; diff --git a/src/webex/notify.ts b/src/webex/notify.ts index 5e024d619..7086ca95d 100644 --- a/src/webex/notify.ts +++ b/src/webex/notify.ts @@ -210,6 +210,7 @@ async function downloadContract(url: string, nonce: string): Promise { } async function processProposal(proposal: any) { + if (!proposal.data) { console.error("field proposal.data field missing"); return; @@ -235,17 +236,12 @@ async function processProposal(proposal: any) { // bad contract / name not included } - const historyEntry = { - detail: { - contractHash, - merchantName, - }, - subjectId: `contract-${contractHash}`, + let proposalId = await wxApi.saveProposal({ timestamp: (new Date()).getTime(), - type: "offer-contract", - }; - await wxApi.putHistory(historyEntry); - let proposalId = await wxApi.saveProposal(proposal); + contractTerms: proposal.data, + contractTermsHash: proposal.hash, + merchantSig: proposal.sig, + }); const uri = new URI(chrome.extension.getURL("/src/webex/pages/confirm-contract.html")); const params = { diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index 7d12d365e..4e4e9687c 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -29,7 +29,6 @@ import * as i18n from "../../i18n"; import { AmountJson, Amounts, - HistoryLevel, HistoryRecord, WalletBalance, WalletBalanceEntry, @@ -354,8 +353,7 @@ function formatHistoryItem(historyItem: HistoryRecord) { ); case "confirm-reserve": { - // FIXME: eventually remove compat fix - const exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??"; + const exchange = (new URI(d.exchangeBaseUrl)).host(); const pub = abbrev(d.reservePub); return ( @@ -369,7 +367,7 @@ function formatHistoryItem(historyItem: HistoryRecord) { const link = chrome.extension.getURL("view-contract.html"); return ( - Merchant {abbrev(d.merchantName, 15)} offered contract {abbrev(d.contractHash)}; + Merchant {abbrev(d.merchantName, 15)} offered contract {abbrev(d.contractTermsHash)}; ); } @@ -395,6 +393,14 @@ function formatHistoryItem(historyItem: HistoryRecord) { ); } + case "refund": { + const merchantElem = {abbrev(d.merchantName, 15)}; + return ( + + Merchant {merchantElem} gave a refund over {renderAmount(d.refundAmount)}. + + ); + } default: return (

{i18n.str`Unknown event (${historyItem.type})`}

); } @@ -447,17 +453,8 @@ class WalletHistory extends React.Component { return ; } - const subjectMemo: {[s: string]: boolean} = {}; const listing: any[] = []; for (const record of history.reverse()) { - if (record.subjectId && subjectMemo[record.subjectId]) { - continue; - } - if (record.level !== undefined && record.level < HistoryLevel.User) { - continue; - } - subjectMemo[record.subjectId as string] = true; - const item = (
diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index d2c21c2f4..73bed30ee 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -63,10 +63,12 @@ const RefundDetail = ({purchase, fullRefundFees}: {purchase: types.PurchaseRecor amountDone = types.Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount; } + const hasPending = amountPending.fraction !== 0 || amountPending.value !== 0; + return (
-

Refund fully received: (refund fees: )

-

Refund incoming:

+ {hasPending ?

Refund pending:

: null} +

Refund received: (refund fees: )

); }; diff --git a/src/webex/pages/tree.tsx b/src/webex/pages/tree.tsx index 2d542f01d..072150312 100644 --- a/src/webex/pages/tree.tsx +++ b/src/webex/pages/tree.tsx @@ -61,7 +61,7 @@ class ReserveView extends React.Component {
  • Created: {(new Date(r.created * 1000).toString())}
  • Current: {r.current_amount ? renderAmount(r.current_amount!) : "null"}
  • Requested: {renderAmount(r.requested_amount)}
  • -
  • Confirmed: {r.confirmed}
  • +
  • Confirmed: {r.timestamp_confirmed}
  • ); diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index 096d855e0..c1c6eb2d3 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -226,7 +226,7 @@ export function hashContract(contract: object): Promise { * the proposal is stored under. */ export function saveProposal(proposal: any): Promise { - return callBackend("save-proposal", proposal); + return callBackend("save-proposal", { proposal }); } /** @@ -243,13 +243,6 @@ export function queryPayment(url: string): Promise { return callBackend("query-payment", { url }); } -/** - * Add a new history item. - */ -export function putHistory(historyEntry: any): Promise { - return callBackend("put-history-entry", { historyEntry }); -} - /** * Mark a payment as succeeded. */ diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 16da3d97d..e7f571b92 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -177,19 +177,9 @@ function handleMessage(sender: MessageSender, return hash; }); } - case "put-history-entry": { - if (!detail.historyEntry) { - return Promise.resolve({ error: "historyEntry missing" }); - } - return needsWallet().putHistory(detail.historyEntry); - } case "save-proposal": { console.log("handling save-proposal", detail); - const checkedRecord = ProposalRecord.checked({ - contractTerms: detail.data, - contractTermsHash: detail.hash, - merchantSig: detail.sig, - }); + const checkedRecord = ProposalRecord.checked(detail.proposal); return needsWallet().saveProposal(checkedRecord); } case "reserve-creation-info": { -- cgit v1.2.3