From fd2cd9c383b07cd681c18137396deae025d98047 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 Jan 2018 14:42:06 +0100 Subject: fix lint issues and separate message types into multiple files --- src/webex/messages.ts | 51 ++++++++++++++++-------------- src/webex/notify.ts | 14 +++++--- src/webex/pages/add-auditor.tsx | 2 +- src/webex/pages/auditors.tsx | 2 +- src/webex/pages/confirm-contract.tsx | 9 ++++-- src/webex/pages/confirm-create-reserve.tsx | 27 ++++++++++------ src/webex/pages/payback.tsx | 2 +- src/webex/pages/popup.tsx | 11 ++++--- src/webex/pages/refund.tsx | 21 ++++++------ src/webex/pages/return-coins.tsx | 7 ++-- src/webex/pages/tip.tsx | 27 ++++++++++------ src/webex/pages/tree.tsx | 3 +- src/webex/renderHtml.tsx | 17 +++++++--- src/webex/wxApi.ts | 40 +++++++++++++++++------ src/webex/wxBackend.ts | 19 +++++++---- 15 files changed, 162 insertions(+), 90 deletions(-) (limited to 'src/webex') diff --git a/src/webex/messages.ts b/src/webex/messages.ts index 44c9f166c..0d0329808 100644 --- a/src/webex/messages.ts +++ b/src/webex/messages.ts @@ -21,7 +21,10 @@ // Messages are already documented in wxApi. /* tslint:disable:completed-docs */ -import * as types from "../types"; +import { AmountJson } from "../amounts"; +import * as dbTypes from "../dbTypes"; +import * as talerTypes from "../talerTypes"; +import * as walletTypes from "../walletTypes"; /** * Message type information. @@ -29,7 +32,7 @@ import * as types from "../types"; export interface MessageMap { "balances": { request: { }; - response: types.WalletBalance; + response: walletTypes.WalletBalance; }; "dump-db": { request: { }; @@ -55,7 +58,7 @@ export interface MessageMap { }; "create-reserve": { request: { - amount: types.AmountJson; + amount: AmountJson; exchange: string }; response: void; @@ -70,11 +73,11 @@ export interface MessageMap { }; "confirm-pay": { request: { proposalId: number; }; - response: types.ConfirmPayResult; + response: walletTypes.ConfirmPayResult; }; "check-pay": { request: { proposalId: number; }; - response: types.CheckPayResult; + response: walletTypes.CheckPayResult; }; "query-payment": { request: { }; @@ -82,31 +85,31 @@ export interface MessageMap { }; "exchange-info": { request: { baseUrl: string }; - response: types.ExchangeRecord; + response: dbTypes.ExchangeRecord; }; "currency-info": { request: { name: string }; - response: types.CurrencyRecord; + response: dbTypes.CurrencyRecord; }; "hash-contract": { request: { contract: object }; response: string; }; "save-proposal": { - request: { proposal: types.ProposalRecord }; + request: { proposal: dbTypes.ProposalRecord }; response: void; }; "reserve-creation-info": { - request: { baseUrl: string, amount: types.AmountJson }; - response: types.ReserveCreationInfo; + request: { baseUrl: string, amount: AmountJson }; + response: walletTypes.ReserveCreationInfo; }; "get-history": { request: { }; - response: types.HistoryRecord[]; + response: walletTypes.HistoryRecord[]; }; "get-proposal": { request: { proposalId: number }; - response: types.ProposalRecord | undefined; + response: dbTypes.ProposalRecord | undefined; }; "get-coins": { request: { exchangeBaseUrl: string }; @@ -118,23 +121,23 @@ export interface MessageMap { }; "get-currencies": { request: { }; - response: types.CurrencyRecord[]; + response: dbTypes.CurrencyRecord[]; }; "update-currency": { - request: { currencyRecord: types.CurrencyRecord }; + request: { currencyRecord: dbTypes.CurrencyRecord }; response: void; }; "get-exchanges": { request: { }; - response: types.ExchangeRecord[]; + response: dbTypes.ExchangeRecord[]; }; "get-reserves": { request: { exchangeBaseUrl: string }; - response: types.ReserveRecord[]; + response: dbTypes.ReserveRecord[]; }; "get-payback-reserves": { request: { }; - response: types.ReserveRecord[]; + response: dbTypes.ReserveRecord[]; }; "withdraw-payback-reserve": { request: { reservePub: string }; @@ -142,11 +145,11 @@ export interface MessageMap { }; "get-precoins": { request: { exchangeBaseUrl: string }; - response: types.PreCoinRecord[]; + response: dbTypes.PreCoinRecord[]; }; "get-denoms": { request: { exchangeBaseUrl: string }; - response: types.DenominationRecord[]; + response: dbTypes.DenominationRecord[]; }; "payback-coin": { request: { coinPub: string }; @@ -189,23 +192,23 @@ export interface MessageMap { response: void; }; "get-full-refund-fees": { - request: { refundPermissions: types.RefundPermission[] }; + request: { refundPermissions: talerTypes.RefundPermission[] }; response: void; }; "get-tip-planchets": { - request: types.GetTipPlanchetsRequest; + request: walletTypes.GetTipPlanchetsRequest; response: void; }; "process-tip-response": { - request: types.ProcessTipResponseRequest; + request: walletTypes.ProcessTipResponseRequest; response: void; }; "accept-tip": { - request: types.AcceptTipRequest; + request: walletTypes.AcceptTipRequest; response: void; }; "get-tip-status": { - request: types.TipStatusRequest; + request: walletTypes.TipStatusRequest; response: void; }; "clear-notification": { diff --git a/src/webex/notify.ts b/src/webex/notify.ts index 05883e8bb..1a447c0ac 100644 --- a/src/webex/notify.ts +++ b/src/webex/notify.ts @@ -29,7 +29,8 @@ import URI = require("urijs"); import wxApi = require("./wxApi"); import { getTalerStampSec } from "../helpers"; -import { TipToken, QueryPaymentResult } from "../types"; +import { TipToken } from "../talerTypes"; +import { QueryPaymentResult } from "../walletTypes"; import axios from "axios"; @@ -272,7 +273,12 @@ function talerPay(msg: any): Promise { const merchantDomain = new URI(document.location.href).origin(); let walletResp; try { - walletResp = await wxApi.getTipPlanchets(merchantDomain, tipToken.tip_id, tipToken.amount, deadlineSec, tipToken.exchange_url, tipToken.next_url); + walletResp = await wxApi.getTipPlanchets(merchantDomain, + tipToken.tip_id, + tipToken.amount, + deadlineSec, + tipToken.exchange_url, + tipToken.next_url); } catch (e) { wxApi.logAndDisplayError({ message: e.message, @@ -283,12 +289,12 @@ function talerPay(msg: any): Promise { throw e; } - let planchets = walletResp; + const planchets = walletResp; if (!planchets) { wxApi.logAndDisplayError({ - message: "processing tip failed", detail: walletResp, + message: "processing tip failed", name: "tipping-failed", sameTab: true, }); diff --git a/src/webex/pages/add-auditor.tsx b/src/webex/pages/add-auditor.tsx index 4b898b13c..1ab6fdf9c 100644 --- a/src/webex/pages/add-auditor.tsx +++ b/src/webex/pages/add-auditor.tsx @@ -23,7 +23,7 @@ import { CurrencyRecord, -} from "../../types"; +} from "../../dbTypes"; import { ImplicitStateComponent, StateHolder } from "../components"; import { diff --git a/src/webex/pages/auditors.tsx b/src/webex/pages/auditors.tsx index 9d57218ad..276a7e8e1 100644 --- a/src/webex/pages/auditors.tsx +++ b/src/webex/pages/auditors.tsx @@ -25,7 +25,7 @@ import { AuditorRecord, CurrencyRecord, ExchangeForCurrencyRecord, -} from "../../types"; +} from "../../dbTypes"; import { getCurrencies, diff --git a/src/webex/pages/confirm-contract.tsx b/src/webex/pages/confirm-contract.tsx index e41b0a1df..83de738b9 100644 --- a/src/webex/pages/confirm-contract.tsx +++ b/src/webex/pages/confirm-contract.tsx @@ -24,12 +24,15 @@ * Imports. */ import * as i18n from "../../i18n"; + import { - CheckPayResult, - ContractTerms, ExchangeRecord, ProposalRecord, -} from "../../types"; +} from "../../dbTypes"; +import { ContractTerms } from "../../talerTypes"; +import { + CheckPayResult, +} from "../../walletTypes"; import { renderAmount } from "../renderHtml"; import * as wxApi from "../wxApi"; diff --git a/src/webex/pages/confirm-create-reserve.tsx b/src/webex/pages/confirm-create-reserve.tsx index 48bcd97c9..903975c6e 100644 --- a/src/webex/pages/confirm-create-reserve.tsx +++ b/src/webex/pages/confirm-create-reserve.tsx @@ -24,13 +24,17 @@ import { canonicalizeBaseUrl } from "../../helpers"; import * as i18n from "../../i18n"; + +import { AmountJson } from "../../amounts"; +import * as Amounts from "../../amounts"; + import { - AmountJson, - Amounts, - CreateReserveResponse, CurrencyRecord, +} from "../../dbTypes"; +import { + CreateReserveResponse, ReserveCreationInfo, -} from "../../types"; +} from "../../walletTypes"; import { ImplicitStateComponent, StateHolder } from "../components"; import { @@ -40,7 +44,10 @@ import { getReserveCreationInfo, } from "../wxApi"; -import { renderAmount, WithdrawDetailView } from "../renderHtml"; +import { + WithdrawDetailView, + renderAmount, +} from "../renderHtml"; import * as React from "react"; import * as ReactDOM from "react-dom"; @@ -78,8 +85,6 @@ class EventTrigger { } - - interface ExchangeSelectionProps { suggestedExchangeUrl: string; amount: AmountJson; @@ -273,7 +278,8 @@ class ExchangeSelection extends ImplicitStateComponent { if (rci.versionMatch.currentCmp === -1) { return (

- Your wallet (protocol version {rci.walletVersion}) might be outdated. The exchange has a higher, incompatible + Your wallet (protocol version {rci.walletVersion}) might be outdated. + The exchange has a higher, incompatible protocol version ({rci.exchangeVersion}).

); @@ -281,7 +287,8 @@ class ExchangeSelection extends ImplicitStateComponent { if (rci.versionMatch.currentCmp === 1) { return (

- The chosen exchange (protocol version {rci.exchangeVersion} might be outdated. The exchange has a lower, incompatible + The chosen exchange (protocol version {rci.exchangeVersion} might be outdated. + The exchange has a lower, incompatible protocol version than your wallet (protocol version {rci.walletVersion}).

); @@ -429,8 +436,8 @@ class ExchangeSelection extends ImplicitStateComponent { amount_fraction: amount.fraction, amount_value: amount.value, exchange: resp.exchange, - reserve_pub: resp.reservePub, exchange_wire_details: JSON.stringify(filteredWireDetails), + reserve_pub: resp.reservePub, }; const url = new URI(callback_url).addQuery(q); if (!url.is("absolute")) { diff --git a/src/webex/pages/payback.tsx b/src/webex/pages/payback.tsx index a380a33d0..f69a33493 100644 --- a/src/webex/pages/payback.tsx +++ b/src/webex/pages/payback.tsx @@ -26,7 +26,7 @@ */ import { ReserveRecord, -} from "../../types"; +} from "../../dbTypes"; import { ImplicitStateComponent, StateHolder } from "../components"; import { renderAmount } from "../renderHtml"; diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index ded430d2b..134ee6dea 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -26,13 +26,15 @@ * Imports. */ import * as i18n from "../../i18n"; + +import { AmountJson } from "../../amounts"; +import * as Amounts from "../../amounts"; + import { - AmountJson, - Amounts, HistoryRecord, WalletBalance, WalletBalanceEntry, -} from "../../types"; +} from "../../walletTypes"; import { abbrev, renderAmount } from "../renderHtml"; import * as wxApi from "../wxApi"; @@ -407,7 +409,8 @@ function formatHistoryItem(historyItem: HistoryRecord) { const url = tipPageUrl.query(params).href(); return ( - Merchant {d.merchantDomain} gave a tip of {renderAmount(d.amount)}. + Merchant {d.merchantDomain} gave + a tip of {renderAmount(d.amount)}. { d.accepted ? null : You did not accept the tip yet. } diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx index e76fdfff3..3e82f3667 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -26,7 +26,10 @@ import * as React from "react"; import * as ReactDOM from "react-dom"; import URI = require("urijs"); -import * as types from "../../types"; +import * as dbTypes from "../../dbTypes"; + +import { AmountJson } from "../../amounts"; +import * as Amounts from "../../amounts"; import { AmountDisplay } from "../renderHtml"; import * as wxApi from "../wxApi"; @@ -36,14 +39,14 @@ interface RefundStatusViewProps { } interface RefundStatusViewState { - purchase?: types.PurchaseRecord; - refundFees?: types.AmountJson; + purchase?: dbTypes.PurchaseRecord; + refundFees?: AmountJson; gotResult: boolean; } interface RefundDetailProps { - purchase: types.PurchaseRecord; - fullRefundFees: types.AmountJson; + purchase: dbTypes.PurchaseRecord; + fullRefundFees: AmountJson; } const RefundDetail = ({purchase, fullRefundFees}: RefundDetailProps) => { @@ -59,13 +62,13 @@ const RefundDetail = ({purchase, fullRefundFees}: RefundDetailProps) => { throw Error("invariant"); } - let amountPending = types.Amounts.getZero(currency); + let amountPending = Amounts.getZero(currency); for (const k of pendingKeys) { - amountPending = types.Amounts.add(amountPending, purchase.refundsPending[k].refund_amount).amount; + amountPending = Amounts.add(amountPending, purchase.refundsPending[k].refund_amount).amount; } - let amountDone = types.Amounts.getZero(currency); + let amountDone = Amounts.getZero(currency); for (const k of doneKeys) { - amountDone = types.Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount; + amountDone = Amounts.add(amountDone, purchase.refundsDone[k].refund_amount).amount; } const hasPending = amountPending.fraction !== 0 || amountPending.value !== 0; diff --git a/src/webex/pages/return-coins.tsx b/src/webex/pages/return-coins.tsx index 5bcb2252a..26db52ef4 100644 --- a/src/webex/pages/return-coins.tsx +++ b/src/webex/pages/return-coins.tsx @@ -25,12 +25,13 @@ * Imports. */ +import { AmountJson } from "../../amounts"; +import * as Amounts from "../../amounts"; + import { - AmountJson, - Amounts, SenderWireInfos, WalletBalance, -} from "../../types"; +} from "../../walletTypes"; import * as i18n from "../../i18n"; diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx index 678c0dfdd..7f96401c5 100644 --- a/src/webex/pages/tip.tsx +++ b/src/webex/pages/tip.tsx @@ -33,9 +33,13 @@ import { getTipStatus, } from "../wxApi"; -import { renderAmount, WithdrawDetailView } from "../renderHtml"; +import { + WithdrawDetailView, + renderAmount, +} from "../renderHtml"; -import { Amounts, TipStatus } from "../../types"; +import * as Amounts from "../../amounts"; +import { TipStatus } from "../../walletTypes"; interface TipDisplayProps { merchantDomain: string; @@ -54,7 +58,7 @@ class TipDisplay extends React.Component { } async update() { - let tipStatus = await getTipStatus(this.props.merchantDomain, this.props.tipId); + const tipStatus = await getTipStatus(this.props.merchantDomain, this.props.tipId); this.setState({ tipStatus }); } @@ -73,7 +77,7 @@ class TipDisplay extends React.Component { renderExchangeInfo(ts: TipStatus) { const rci = ts.rci; if (!rci) { - return

Waiting for info about exchange ...

+ return

Waiting for info about exchange ...

; } const totalCost = Amounts.add(rci.overhead, rci.withdrawFee).amount; return ( @@ -102,7 +106,9 @@ class TipDisplay extends React.Component { className="pure-button pure-button-primary" type="button" onClick={() => this.accept()}> - { this.state.working ? : null } + { this.state.working + ? + : null } Accept tip {" "} @@ -119,7 +125,8 @@ class TipDisplay extends React.Component { return (

Tip Received!

-

You received a tip of {renderAmount(ts.tip.amount)} from {this.props.merchantDomain}.

+

You received a tip of {renderAmount(ts.tip.amount)} from + {this.props.merchantDomain}.

{ts.tip.accepted ?

You've accepted this tip! Go back to merchant

: this.renderButtons() @@ -134,10 +141,10 @@ async function main() { try { const url = new URI(document.location.href); const query: any = URI.parseQuery(url.query()); - - let merchantDomain = query.merchant_domain; - let tipId = query.tip_id; - let props: TipDisplayProps = { tipId, merchantDomain }; + + const merchantDomain = query.merchant_domain; + const tipId = query.tip_id; + const props: TipDisplayProps = { tipId, merchantDomain }; ReactDOM.render(, document.getElementById("container")!); diff --git a/src/webex/pages/tree.tsx b/src/webex/pages/tree.tsx index 2ac0b8631..67e58a1df 100644 --- a/src/webex/pages/tree.tsx +++ b/src/webex/pages/tree.tsx @@ -22,6 +22,7 @@ import { getTalerStampDate } from "../../helpers"; + import { CoinRecord, CoinStatus, @@ -29,7 +30,7 @@ import { ExchangeRecord, PreCoinRecord, ReserveRecord, -} from "../../types"; +} from "../../dbTypes"; import { ImplicitStateComponent, StateHolder } from "../components"; import { diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx index d225cef0c..2e21932b0 100644 --- a/src/webex/renderHtml.tsx +++ b/src/webex/renderHtml.tsx @@ -24,12 +24,16 @@ /** * Imports. */ +import { AmountJson } from "../amounts"; +import * as Amounts from "../amounts"; + import { - AmountJson, - Amounts, DenominationRecord, +} from "../dbTypes"; +import { ReserveCreationInfo, -} from "../types"; +} from "../walletTypes"; + import { ImplicitStateComponent } from "./components"; @@ -239,7 +243,9 @@ function FeeDetailsView(props: {rci: ReserveCreationInfo|null}): JSX.Element { ); } - +/** + * Shows details about a withdraw request. + */ export function WithdrawDetailView(props: {rci: ReserveCreationInfo | null}): JSX.Element { const rci = props.rci; return ( @@ -259,6 +265,9 @@ interface ExpanderTextProps { text: string; } +/** + * Show a heading with a toggle to show/hide the expandable content. + */ export class ExpanderText extends ImplicitStateComponent { private expanded = this.makeState(false); private textArea: any = undefined; diff --git a/src/webex/wxApi.ts b/src/webex/wxApi.ts index 2575eec90..2f7a13c48 100644 --- a/src/webex/wxApi.ts +++ b/src/webex/wxApi.ts @@ -22,26 +22,31 @@ /** * Imports. */ +import { AmountJson } from "../amounts"; import { - AmountJson, - CheckPayResult, CoinRecord, - ConfirmPayResult, CurrencyRecord, DenominationRecord, ExchangeRecord, PreCoinRecord, PurchaseRecord, + ReserveRecord, +} from "../dbTypes"; +import { + CheckPayResult, + ConfirmPayResult, QueryPaymentResult, - RefundPermission, ReserveCreationInfo, - ReserveRecord, SenderWireInfos, - TipResponse, - TipPlanchetDetail, TipStatus, WalletBalance, -} from "../types"; +} from "../walletTypes"; + +import { + RefundPermission, + TipPlanchetDetail, + TipResponse, +} from "../talerTypes"; import { MessageMap, MessageType } from "./messages"; @@ -366,22 +371,39 @@ export function getFullRefundFees(args: { refundPermissions: RefundPermission[] /** * Get or generate planchets to give the merchant that wants to tip us. */ -export function getTipPlanchets(merchantDomain: string, tipId: string, amount: AmountJson, deadline: number, exchangeUrl: string, nextUrl: string): Promise { +export function getTipPlanchets(merchantDomain: string, + tipId: string, + amount: AmountJson, + deadline: number, + exchangeUrl: string, + nextUrl: string): Promise { return callBackend("get-tip-planchets", { merchantDomain, tipId, amount, deadline, exchangeUrl, nextUrl }); } +/** + * Get the status of processing a tip. + */ export function getTipStatus(merchantDomain: string, tipId: string): Promise { return callBackend("get-tip-status", { merchantDomain, tipId }); } +/** + * Mark a tip as accepted by the user. + */ export function acceptTip(merchantDomain: string, tipId: string): Promise { return callBackend("accept-tip", { merchantDomain, tipId }); } +/** + * Process a response from the merchant for a tip request. + */ export function processTipResponse(merchantDomain: string, tipId: string, tipResponse: TipResponse): Promise { return callBackend("process-tip-response", { merchantDomain, tipId, tipResponse }); } +/** + * Clear notifications that the wallet shows to the user. + */ export function clearNotification(): Promise { return callBackend("clear-notification", { }); } diff --git a/src/webex/wxBackend.ts b/src/webex/wxBackend.ts index 213d234d4..a8ce5eebc 100644 --- a/src/webex/wxBackend.ts +++ b/src/webex/wxBackend.ts @@ -30,18 +30,21 @@ import { Index, Store, } from "../query"; + +import { AmountJson } from "../amounts"; + +import { ProposalRecord } from "../dbTypes"; import { AcceptTipRequest, - AmountJson, ConfirmReserveRequest, CreateReserveRequest, GetTipPlanchetsRequest, Notifier, ProcessTipResponseRequest, - ProposalRecord, ReturnCoinsRequest, TipStatusRequest, -} from "../types"; +} from "../walletTypes"; + import { Stores, WALLET_DB_VERSION, @@ -335,7 +338,12 @@ function handleMessage(sender: MessageSender, } case "get-tip-planchets": { const req = GetTipPlanchetsRequest.checked(detail); - return needsWallet().getTipPlanchets(req.merchantDomain, req.tipId, req.amount, req.deadline, req.exchangeUrl, req.nextUrl); + return needsWallet().getTipPlanchets(req.merchantDomain, + req.tipId, + req.amount, + req.deadline, + req.exchangeUrl, + req.nextUrl); } case "clear-notification": { return needsWallet().clearNotification(); @@ -702,11 +710,10 @@ export async function wxMain() { }); - // Clear notifications both when the popop opens, // as well when it closes. chrome.runtime.onConnect.addListener((port) => { - if (port.name == "popup") { + if (port.name === "popup") { if (currentWallet) { currentWallet.clearNotification(); } -- cgit v1.2.3