diff options
Diffstat (limited to 'src/webex')
-rw-r--r-- | src/webex/messages.ts | 10 | ||||
-rw-r--r-- | src/webex/notify.ts | 24 | ||||
-rw-r--r-- | src/webex/pages/confirm-contract.tsx | 17 | ||||
-rw-r--r-- | src/webex/pages/confirm-create-reserve.tsx | 17 | ||||
-rw-r--r-- | src/webex/pages/error.tsx | 11 | ||||
-rw-r--r-- | src/webex/pages/payback.tsx | 2 | ||||
-rw-r--r-- | src/webex/pages/popup.tsx | 11 | ||||
-rw-r--r-- | src/webex/pages/refund.tsx | 30 | ||||
-rw-r--r-- | src/webex/pages/reset-required.tsx | 17 | ||||
-rw-r--r-- | src/webex/pages/return-coins.tsx | 6 | ||||
-rw-r--r-- | src/webex/renderHtml.tsx | 7 | ||||
-rw-r--r-- | src/webex/wxApi.ts | 19 | ||||
-rw-r--r-- | src/webex/wxBackend.ts | 23 |
13 files changed, 127 insertions, 67 deletions
diff --git a/src/webex/messages.ts b/src/webex/messages.ts index ca51abf1d..0ca903154 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -56,14 +56,14 @@ export interface MessageMap { "create-reserve": { request: { amount: types.AmountJson; - exchange: string + exchange: string }; response: void; - }; + }; "confirm-reserve": { request: { reservePub: string }; response: void; - } + }; "generate-nonce": { request: { } response: string; @@ -99,7 +99,7 @@ export interface MessageMap { "reserve-creation-info": { request: { baseUrl: string, amount: types.AmountJson }; response: types.ReserveCreationInfo; - } + }; "get-history": { request: { }; response: types.HistoryRecord[]; @@ -139,7 +139,7 @@ export interface MessageMap { "withdraw-payback-reserve": { request: { reservePub: string }; response: void; - } + }; "get-precoins": { request: { exchangeBaseUrl: string }; response: types.PreCoinRecord[]; diff --git a/src/webex/notify.ts b/src/webex/notify.ts index 7086ca95d..cc8086ceb 100644 --- a/src/webex/notify.ts +++ b/src/webex/notify.ts @@ -30,7 +30,7 @@ import wxApi = require("./wxApi"); import { QueryPaymentResult } from "../types"; -import axios from 'axios'; +import axios from "axios"; declare var cloneInto: any; @@ -111,17 +111,17 @@ async function handlePaymentResponse(maybeFoundResponse: QueryPaymentResult) { let resp; try { const config = { - timeout: 5000, /* 5 seconds */ headers: { "Content-Type": "application/json;charset=UTF-8" }, - validateStatus: (s: number) => s == 200, - } + timeout: 5000, /* 5 seconds */ + validateStatus: (s: number) => s === 200, + }; resp = await axios.post(walletResp.contractTerms.pay_url, walletResp.payReq, config); } catch (e) { // Gives the user the option to retry / abort and refresh wxApi.logAndDisplayError({ - name: "pay-post-failed", contractTerms: walletResp.contractTerms, message: e.message, + name: "pay-post-failed", response: e.response, }); throw e; @@ -195,11 +195,11 @@ async function downloadContract(url: string, nonce: string): Promise<any> { console.log("downloading contract from '" + url + "'"); let resp; try { - resp = await axios.get(url, { validateStatus: (s) => s == 200 }); + resp = await axios.get(url, { validateStatus: (s) => s === 200 }); } catch (e) { wxApi.logAndDisplayError({ - name: "contract-download-failed", message: e.message, + name: "contract-download-failed", response: e.response, sameTab: true, }); @@ -236,11 +236,11 @@ async function processProposal(proposal: any) { // bad contract / name not included } - let proposalId = await wxApi.saveProposal({ - timestamp: (new Date()).getTime(), + const proposalId = await wxApi.saveProposal({ contractTerms: proposal.data, contractTermsHash: proposal.hash, merchantSig: proposal.sig, + timestamp: (new Date()).getTime(), }); const uri = new URI(chrome.extension.getURL("/src/webex/pages/confirm-contract.html")); @@ -265,13 +265,13 @@ function talerPay(msg: any): Promise<any> { let resp; try { const config = { - validateStatus: (s: number) => s == 200, - } + validateStatus: (s: number) => s === 200, + }; resp = await axios.get(msg.refund_url, config); } catch (e) { wxApi.logAndDisplayError({ - name: "refund-download-failed", message: e.message, + name: "refund-download-failed", response: e.response, sameTab: true, }); diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index 5436cb5a6..f2e22bec4 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -124,9 +124,9 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt alreadyPaid: false, error: null, exchanges: null, - proposal: null, - payDisabled: true, holdCheck: false, + payDisabled: true, + proposal: null, }; } @@ -220,8 +220,11 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt (p: any, i: number) => (<li key={i}>{p.description}: {renderAmount(p.price)}</li>)) } </ul> - {(this.state.payStatus && this.state.payStatus.coinSelection) ? - <p>The total price is <span>{amount}</span> (plus <span>{renderAmount(this.state.payStatus.coinSelection.totalFees)}</span> fees).</p> + {(this.state.payStatus && this.state.payStatus.coinSelection) + ? <p> + The total price is <span>{amount}</span>{" "} + (plus <span>{renderAmount(this.state.payStatus.coinSelection.totalFees)}</span> fees). + </p> : <p>The total price is <span>{amount}</span>.</p> } @@ -232,7 +235,11 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt {i18n.str`Confirm payment`} </button> <div> - {(this.state.alreadyPaid ? <p className="okaybox">You already paid for this, clicking "Confirm payment" will not cost money again.</p> : <p />)} + {(this.state.alreadyPaid + ? <p className="okaybox"> + You already paid for this, clicking "Confirm payment" will not cost money again. + </p> + : <p />)} {(this.state.error ? <p className="errorbox">{this.state.error}</p> : <p />)} </div> <Details exchanges={this.state.exchanges} contractTerms={c} collapsed={!this.state.error}/> diff --git a/src/webex/pages/confirm-create-reserve.tsx b/src/webex/pages/confirm-create-reserve.tsx index 7d543860f..0e1cb17df 100644 --- a/src/webex/pages/confirm-create-reserve.tsx +++ b/src/webex/pages/confirm-create-reserve.tsx @@ -43,10 +43,10 @@ import { import {Collapsible, renderAmount} from "../renderHtml"; +import * as moment from "moment"; import * as React from "react"; import * as ReactDOM from "react-dom"; import URI = require("urijs"); -import * as moment from "moment"; function delay<T>(delayMs: number, value: T): Promise<T> { @@ -80,7 +80,6 @@ class EventTrigger { } - function renderAuditorDetails(rci: ReserveCreationInfo|null) { console.log("rci", rci); if (!rci) { @@ -393,7 +392,7 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { if (rci.versionMatch.compatible) { return null; } - if (rci.versionMatch.currentCmp == -1) { + if (rci.versionMatch.currentCmp === -1) { return ( <p className="errorbox"> Your wallet might be outdated. The exchange has a higher, incompatible @@ -401,7 +400,7 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { </p> ); } - if (rci.versionMatch.currentCmp == 1) { + if (rci.versionMatch.currentCmp === 1) { return ( <p className="errorbox"> The chosen exchange might be outdated. The exchange has a lower, incompatible @@ -522,10 +521,10 @@ class ExchangeSelection extends ImplicitStateComponent<ExchangeSelectionProps> { } async confirmReserveImpl(rci: ReserveCreationInfo, - exchange: string, - amount: AmountJson, - callback_url: string, - sender_wire: object | undefined) { + exchange: string, + amount: AmountJson, + callback_url: string, + sender_wire: object | undefined) { const rawResp = await createReserve({ amount, exchange: canonicalizeBaseUrl(exchange), @@ -612,9 +611,9 @@ async function main() { amount, callback_url, currencyRecord, + sender_wire, suggestedExchangeUrl, wt_types, - sender_wire, }; ReactDOM.render(<ExchangeSelection {...args} />, document.getElementById( diff --git a/src/webex/pages/error.tsx b/src/webex/pages/error.tsx index 2edef5e5b..dee8ce44e 100644 --- a/src/webex/pages/error.tsx +++ b/src/webex/pages/error.tsx @@ -55,9 +55,14 @@ class ErrorView extends React.Component<ErrorProps, { }> { return ( <div id="main"> <h1>Failed to send payment</h1> - <p>Failed to send payment for <strong>{summary}</strong> to merchant <strong>{report.contractTerms.merchant.name}</strong>.</p> - <p>You can <a href={report.contractTerms.fulfillment_url}>retry</a> the payment. If this problem persists, - please contact the mechant with the error details below.</p> + <p> + Failed to send payment for <strong>{summary}</strong>{" "} + to merchant <strong>{report.contractTerms.merchant.name}</strong>. + </p> + <p> + You can <a href={report.contractTerms.fulfillment_url}>retry</a> the payment.{" "} + If this problem persists, please contact the mechant with the error details below. + </p> <Collapsible initiallyCollapsed={true} title="Error Details"> <pre> {JSON.stringify(report, null, " ")} diff --git a/src/webex/pages/payback.tsx b/src/webex/pages/payback.tsx index 51ad8612c..c2a092460 100644 --- a/src/webex/pages/payback.tsx +++ b/src/webex/pages/payback.tsx @@ -24,12 +24,12 @@ /** * Imports. */ -import { renderAmount } from "../renderHtml"; import { ReserveRecord, } from "../../types"; import { ImplicitStateComponent, StateHolder } from "../components"; +import { renderAmount } from "../renderHtml"; import { getPaybackReserves, withdrawPaybackReserve, diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index 4e4e9687c..9c012449c 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -105,12 +105,12 @@ class Router extends React.Component<any, any> { foundChild = child; } }); - const child: React.ReactChild | null = foundChild || defaultChild; - if (!child) { + const c: React.ReactChild | null = foundChild || defaultChild; + if (!c) { throw Error("unknown route"); } - Router.setRoute((child as any).props.route); - return <div>{child}</div>; + Router.setRoute((c as any).props.route); + return <div>{c}</div>; } } @@ -367,7 +367,8 @@ 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.contractTermsHash)}</a>; + Merchant <em>{abbrev(d.merchantName, 15)}</em> offered{" "} + contract <a href={link}>{abbrev(d.contractTermsHash)}</a>. </i18n.Translate> ); } diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index 73bed30ee..e76fdfff3 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -26,10 +26,10 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; import URI = require("urijs"); -import * as wxApi from "../wxApi"; import * as types from "../../types"; import { AmountDisplay } from "../renderHtml"; +import * as wxApi from "../wxApi"; interface RefundStatusViewProps { contractTermsHash: string; @@ -41,25 +41,30 @@ interface RefundStatusViewState { gotResult: boolean; } +interface RefundDetailProps { + purchase: types.PurchaseRecord; + fullRefundFees: types.AmountJson; +} -const RefundDetail = ({purchase, fullRefundFees}: {purchase: types.PurchaseRecord, fullRefundFees: types.AmountJson}) => { +const RefundDetail = ({purchase, fullRefundFees}: RefundDetailProps) => { const pendingKeys = Object.keys(purchase.refundsPending); const doneKeys = Object.keys(purchase.refundsDone); - if (pendingKeys.length == 0 && doneKeys.length == 0) { + if (pendingKeys.length === 0 && doneKeys.length === 0) { return <p>No refunds</p>; } - const currency = { ...purchase.refundsDone, ...purchase.refundsPending }[([...pendingKeys, ...doneKeys][0])].refund_amount.currency; + const firstRefundKey = [...pendingKeys, ...doneKeys][0]; + const currency = { ...purchase.refundsDone, ...purchase.refundsPending }[firstRefundKey].refund_amount.currency; if (!currency) { throw Error("invariant"); } let amountPending = types.Amounts.getZero(currency); - for (let k of pendingKeys) { + for (const k of pendingKeys) { amountPending = types.Amounts.add(amountPending, purchase.refundsPending[k].refund_amount).amount; } let amountDone = types.Amounts.getZero(currency); - for (let k of doneKeys) { + for (const k of doneKeys) { amountDone = types.Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount; } @@ -68,7 +73,9 @@ const RefundDetail = ({purchase, fullRefundFees}: {purchase: types.PurchaseRecor return ( <div> {hasPending ? <p>Refund pending: <AmountDisplay amount={amountPending} /></p> : null} - <p>Refund received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={fullRefundFees} />)</p> + <p> + Refund received: <AmountDisplay amount={amountDone} /> (refund fees: <AmountDisplay amount={fullRefundFees} />) + </p> </div> ); }; @@ -105,9 +112,14 @@ class RefundStatusView extends React.Component<RefundStatusViewProps, RefundStat return ( <div id="main"> <h1>Refund Status</h1> - <p>Status of purchase <strong>{summary}</strong> from merchant <strong>{merchantName}</strong> (order id {purchase.contractTerms.order_id}).</p> + <p> + Status of purchase <strong>{summary}</strong> from merchant <strong>{merchantName}</strong>{" "} + (order id {purchase.contractTerms.order_id}). + </p> <p>Total amount: <AmountDisplay amount={purchase.contractTerms.amount} /></p> - {purchase.finished ? <RefundDetail purchase={purchase} fullRefundFees={this.state.refundFees!} /> : <p>Purchase not completed.</p>} + {purchase.finished + ? <RefundDetail purchase={purchase} fullRefundFees={this.state.refundFees!} /> + : <p>Purchase not completed.</p>} </div> ); } diff --git a/src/webex/pages/reset-required.tsx b/src/webex/pages/reset-required.tsx index 90ea51abe..6631705af 100644 --- a/src/webex/pages/reset-required.tsx +++ b/src/webex/pages/reset-required.tsx @@ -27,7 +27,14 @@ import * as ReactDOM from "react-dom"; import * as wxApi from "../wxApi"; class State { + /** + * Did the user check the confirmation check box? + */ checked: boolean; + + /** + * Do we actually need to reset the db? + */ resetRequired: boolean; } @@ -47,9 +54,15 @@ class ResetNotification extends React.Component<any, State> { return ( <div> <h1>Manual Reset Reqired</h1> - <p>The wallet's database in your browser is incompatible with the currently installed wallet. Please reset manually.</p> + <p> + The wallet's database in your browser is incompatible with the {" "} + currently installed wallet. Please reset manually. + </p> <p>Once the database format has stabilized, we will provide automatic upgrades.</p> - <input id="check" type="checkbox" checked={this.state.checked} onChange={(e) => this.setState({checked: e.target.checked})} />{" "} + <input id="check" + type="checkbox" + checked={this.state.checked} + onChange={(e) => this.setState({checked: e.target.checked})} />{" "} <label htmlFor="check"> I understand that I will lose all my data </label> diff --git a/src/webex/pages/return-coins.tsx b/src/webex/pages/return-coins.tsx index 1fdadd2e9..453ae4784 100644 --- a/src/webex/pages/return-coins.tsx +++ b/src/webex/pages/return-coins.tsx @@ -95,7 +95,7 @@ class ReturnSelectionItem extends React.Component<ReturnSelectionItemProps, Retu <select value={this.state.selectedWire} onChange={(evt) => this.setState({selectedWire: evt.target.value})}> <option style={{display: "none"}}>Select account</option> {this.state.supportedWires.map((w, n) => - <option value={n.toString()} key={JSON.stringify(w)}>{n+1}: {wire.summarizeWire(w)}</option> + <option value={n.toString()} key={JSON.stringify(w)}>{n + 1}: {wire.summarizeWire(w)}</option>, )} </select>. </p> @@ -252,7 +252,9 @@ class ReturnCoins extends React.Component<any, ReturnCoinsState> { <p>You can send coins back into your own bank account. Note that you're acting as a merchant when doing this, and thus the same fees apply.</p> {this.state.lastConfirmedDetail - ? <p className="okaybox">Transfer of {renderAmount(this.state.lastConfirmedDetail.amount)} successfully initiated.</p> + ? <p className="okaybox"> + Transfer of {renderAmount(this.state.lastConfirmedDetail.amount)} successfully initiated. + </p> : null} <ReturnSelectionList selectDetail={(d) => this.selectDetail(d)} diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx index d26f726af..792ba2f2c 100644 --- a/src/webex/renderHtml.tsx +++ b/src/webex/renderHtml.tsx @@ -61,16 +61,21 @@ export function abbrev(s: string, n: number = 5) { } - interface CollapsibleState { collapsed: boolean; } + interface CollapsibleProps { initiallyCollapsed: boolean; title: string; } + +/** + * Component that shows/hides its children when clicking + * a heading. + */ export class Collapsible extends React.Component<CollapsibleProps, CollapsibleState> { constructor(props: CollapsibleProps) { super(props); diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index c1c6eb2d3..7afc116ba 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -40,7 +40,7 @@ import { WalletBalance, } from "../types"; -import { MessageType, MessageMap } from "./messages"; +import { MessageMap, MessageType } from "./messages"; /** @@ -328,18 +328,33 @@ export function logAndDisplayError(args: any): Promise<void> { return callBackend("log-and-display-error", args); } -export function getReport(reportUid: string): Promise<void> { +/** + * Get an error report from the logging database for the + * given report UID. + */ +export function getReport(reportUid: string): Promise<any> { return callBackend("get-report", { reportUid }); } +/** + * Apply a refund that we got from the merchant. + */ export function acceptRefund(refundData: any): Promise<number> { return callBackend("accept-refund", refundData); } +/** + * Look up a purchase in the wallet database from + * the contract terms hash. + */ export function getPurchase(contractTermsHash: string): Promise<PurchaseRecord> { return callBackend("get-purchase", { contractTermsHash }); } +/** + * Get the refund fees for a refund permission, including + * subsequent refresh and unrefreshable coins. + */ export function getFullRefundFees(args: { refundPermissions: RefundPermission[] }): Promise<AmountJson> { return callBackend("get-full-refund-fees", { refundPermissions: args.refundPermissions }); } diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index e7f571b92..7393c8880 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -230,7 +230,7 @@ function handleMessage(sender: MessageSender, if (typeof detail.exchangeBaseUrl !== "string") { return Promise.reject(Error("exchangBaseUrl missing")); } - return needsWallet().getPreCoins(detail.exchangeBaseUrl); + return needsWallet().getPreCoins(detail.exchangeBaseUrl); } case "get-denoms": { if (typeof detail.exchangeBaseUrl !== "string") { @@ -287,10 +287,10 @@ function handleMessage(sender: MessageSender, dbResetRequired = true; } const resp: wxApi.UpgradeResponse = { - dbResetRequired, currentDbVersion: WALLET_DB_VERSION.toString(), + dbResetRequired, oldDbVersion: (oldDbVersion || "unknown").toString(), - } + }; return resp; } case "log-and-display-error": @@ -307,12 +307,13 @@ function handleMessage(sender: MessageSender, return logging.getReport(detail.reportUid); case "accept-refund": return needsWallet().acceptRefund(detail.refund_permissions); - case "get-purchase": + case "get-purchase": { const contractTermsHash = detail.contractTermsHash; if (!contractTermsHash) { throw Error("contractTermsHash missing"); } return needsWallet().getPurchase(contractTermsHash); + } case "get-full-refund-fees": return needsWallet().getFullRefundFees(detail.refundPermissions); default: @@ -452,7 +453,7 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea return; } - if (operation == "confirm-reserve") { + if (operation === "confirm-reserve") { const reservePub = headers["x-taler-reserve-pub"]; if (reservePub !== undefined) { console.log(`confirming reserve ${reservePub} via 201`); @@ -462,7 +463,7 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea return; } - if (operation == "create-reserve") { + if (operation === "create-reserve") { const amount = headers["x-taler-amount"]; if (!amount) { console.log("202 not understood (X-Taler-Amount missing)"); @@ -477,13 +478,13 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea try { amountParsed = JSON.parse(amount); } catch (e) { - const uri = new URI(chrome.extension.getURL("/src/webex/pages/error.html")); + const errUri = new URI(chrome.extension.getURL("/src/webex/pages/error.html")); const p = { message: `Can't parse amount ("${amount}"): ${e.message}`, }; - const redirectUrl = uri.query(p).href(); + const errRedirectUrl = errUri.query(p).href(); // FIXME: use direct redirect when https://bugzilla.mozilla.org/show_bug.cgi?id=707624 is fixed - chrome.tabs.update(tabId, {url: redirectUrl}); + chrome.tabs.update(tabId, {url: errRedirectUrl}); return; } const wtTypes = headers["x-taler-wt-types"]; @@ -495,9 +496,9 @@ function handleBankRequest(wallet: Wallet, headerList: chrome.webRequest.HttpHea amount, bank_url: url, callback_url: new URI(callbackUrl) .absoluteTo(url), + sender_wire: headers["x-taler-sender-wire"], suggested_exchange_url: headers["x-taler-suggested-exchange"], wt_types: wtTypes, - sender_wire: headers["x-taler-sender-wire"], }; const uri = new URI(chrome.extension.getURL("/src/webex/pages/confirm-create-reserve.html")); const redirectUrl = uri.query(params).href(); @@ -584,7 +585,7 @@ export async function wxMain() { chrome.runtime.onUpdateAvailable.addListener((details) => { console.log("update available:", details); chrome.runtime.reload(); - }) + }); window.onerror = (m, source, lineno, colno, error) => { logging.record("error", m + error, undefined, source || "(unknown)", lineno || 0, colno || 0); |