diff options
Diffstat (limited to 'src/webex')
-rw-r--r-- | src/webex/messages.ts | 4 | ||||
-rw-r--r-- | src/webex/notify.ts | 16 | ||||
-rw-r--r-- | src/webex/pages/popup.tsx | 23 | ||||
-rw-r--r-- | src/webex/pages/refund.tsx | 6 | ||||
-rw-r--r-- | src/webex/pages/tree.tsx | 2 | ||||
-rw-r--r-- | src/webex/wxApi.ts | 9 | ||||
-rw-r--r-- | src/webex/wxBackend.ts | 12 |
7 files changed, 23 insertions, 49 deletions
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<any> { } 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) { </i18n.Translate> ); 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 ( <i18n.Translate wrap="p"> @@ -369,7 +367,7 @@ function formatHistoryItem(historyItem: HistoryRecord) { const link = chrome.extension.getURL("view-contract.html"); return ( <i18n.Translate wrap="p"> - Merchant <em>{abbrev(d.merchantName, 15)}</em> offered contract <a href={link}>{abbrev(d.contractHash)}</a>; + Merchant <em>{abbrev(d.merchantName, 15)}</em> offered contract <a href={link}>{abbrev(d.contractTermsHash)}</a>; </i18n.Translate> ); } @@ -395,6 +393,14 @@ function formatHistoryItem(historyItem: HistoryRecord) { </i18n.Translate> ); } + case "refund": { + const merchantElem = <em>{abbrev(d.merchantName, 15)}</em>; + return ( + <i18n.Translate wrap="p"> + Merchant <span>{merchantElem}</span> gave a refund over <span>{renderAmount(d.refundAmount)}</span>. + </i18n.Translate> + ); + } default: return (<p>{i18n.str`Unknown event (${historyItem.type})`}</p>); } @@ -447,17 +453,8 @@ class WalletHistory extends React.Component<any, any> { return <span />; } - 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 = ( <div className="historyItem"> <div className="historyDate"> 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 ( <div> - <p>Refund fully received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={fullRefundFees} />)</p> - <p>Refund incoming: <AmountDisplay amount={amountPending} /></p> + {hasPending ? <p>Refund pending: <AmountDisplay amount={amountPending} /></p> : null} + <p>Refund received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={fullRefundFees} />)</p> </div> ); }; 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<ReserveViewProps, {}> { <li>Created: {(new Date(r.created * 1000).toString())}</li> <li>Current: {r.current_amount ? renderAmount(r.current_amount!) : "null"}</li> <li>Requested: {renderAmount(r.requested_amount)}</li> - <li>Confirmed: {r.confirmed}</li> + <li>Confirmed: {r.timestamp_confirmed}</li> </ul> </div> ); 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<string> { * the proposal is stored under. */ export function saveProposal(proposal: any): Promise<number> { - return callBackend("save-proposal", proposal); + return callBackend("save-proposal", { proposal }); } /** @@ -244,13 +244,6 @@ export function queryPayment(url: string): Promise<QueryPaymentResult> { } /** - * Add a new history item. - */ -export function putHistory(historyEntry: any): Promise<void> { - return callBackend("put-history-entry", { historyEntry }); -} - -/** * Mark a payment as succeeded. */ export function paymentSucceeded(contractTermsHash: string, merchantSig: string): Promise<void> { 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": { |