From d0e0c6baf274aab378233a7ae0d67307c03b3a7c Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 29 May 2017 15:18:48 +0200 Subject: fix linter errors --- src/i18n.tsx | 10 +-- src/i18n/de.po | 36 ++++----- src/i18n/en-US.po | 36 ++++----- src/i18n/fr.po | 36 ++++----- src/i18n/it.po | 36 ++++----- src/i18n/taler-wallet-webex.pot | 36 ++++----- src/webex/pages/popup.tsx | 173 +++++++++++++++++++++------------------- src/webex/pages/tree.tsx | 70 ++++++++-------- src/webex/renderHtml.tsx | 10 ++- webpack.config.js | 3 + 10 files changed, 234 insertions(+), 212 deletions(-) diff --git a/src/i18n.tsx b/src/i18n.tsx index 48631afb2..e5b9c398a 100644 --- a/src/i18n.tsx +++ b/src/i18n.tsx @@ -51,7 +51,7 @@ function toI18nString(strings: ReadonlyArray) { for (let i = 0; i < strings.length; i++) { str += strings[i]; if (i < strings.length - 1) { - str += "%"+ (i+1) +"$s"; + str += `%${i + 1}$s`; } } return str; @@ -196,8 +196,8 @@ export class TranslatePlural extends React.Component i % 2 == 0); let childArray = React.Children.toArray(this.props.children!); for (let i = 0; i < childArray.length - 1; ++i) { - if ((typeof childArray[i]) == "string" && (typeof childArray[i+1]) == "string") { - childArray[i+i] = childArray[i] as string + childArray[i+1] as string; + if ((typeof childArray[i]) == "string" && (typeof childArray[i + 1]) == "string") { + childArray[i+i] = childArray[i] as string + childArray[i + 1] as string; childArray.splice(i,1); } } @@ -228,8 +228,8 @@ export class TranslateSingular extends React.Component i % 2 == 0); let childArray = React.Children.toArray(this.props.children!); for (let i = 0; i < childArray.length - 1; ++i) { - if ((typeof childArray[i]) == "string" && (typeof childArray[i+1]) == "string") { - childArray[i+i] = childArray[i] as string + childArray[i+1] as string; + if ((typeof childArray[i]) == "string" && (typeof childArray[i + 1]) == "string") { + childArray[i+i] = childArray[i] as string + childArray[i + 1] as string; childArray.splice(i,1); } } diff --git a/src/i18n/de.po b/src/i18n/de.po index 39daf9b23..a76705b9a 100644 --- a/src/i18n/de.po +++ b/src/i18n/de.po @@ -197,91 +197,91 @@ msgstr "" msgid "Fatal error: \"%1$s\"." msgstr "" -#: src/webex/pages/popup.tsx:160 +#: src/webex/pages/popup.tsx:163 #, c-format msgid "Balance" msgstr "Saldo" -#: src/webex/pages/popup.tsx:163 +#: src/webex/pages/popup.tsx:166 #, c-format msgid "History" msgstr "Verlauf" -#: src/webex/pages/popup.tsx:166 +#: src/webex/pages/popup.tsx:169 #, c-format msgid "Debug" msgstr "Debug" -#: src/webex/pages/popup.tsx:238 +#: src/webex/pages/popup.tsx:241 #, c-format msgid "help" msgstr "" -#: src/webex/pages/popup.tsx:243 +#: src/webex/pages/popup.tsx:246 #, fuzzy, c-format msgid "" "You have no balance to show. Need some\n" " %1$s getting started?\n" msgstr "Sie haben kein Digitalgeld. Wollen Sie %1$s? abheben?" -#: src/webex/pages/popup.tsx:260 +#: src/webex/pages/popup.tsx:263 #, c-format msgid "%1$s incoming\n" msgstr "" -#: src/webex/pages/popup.tsx:273 +#: src/webex/pages/popup.tsx:276 #, c-format msgid "%1$s being spent\n" msgstr "" -#: src/webex/pages/popup.tsx:299 +#: src/webex/pages/popup.tsx:302 #, c-format msgid "Error: could not retrieve balance information." msgstr "" -#: src/webex/pages/popup.tsx:340 +#: src/webex/pages/popup.tsx:343 #, fuzzy, c-format msgid "Bank requested reserve (%1$s) for%2$s.\n" msgstr "Bank bestätig anlegen der Reserve (%1$s) bei %2$s" -#: src/webex/pages/popup.tsx:349 +#: src/webex/pages/popup.tsx:352 #, fuzzy, c-format msgid "" "Started to withdraw\n" " %1$s from%2$s(%3$s).\n" msgstr "Reserve (%1$s) mit %2$s bei %3$s erzeugt" -#: src/webex/pages/popup.tsx:361 +#: src/webex/pages/popup.tsx:364 #, c-format msgid "Merchant%1$soffered contract%2$s;\n" msgstr "" -#: src/webex/pages/popup.tsx:371 +#: src/webex/pages/popup.tsx:374 #, fuzzy, c-format msgid "Withdrew%1$sfrom%2$s(%3$s).\n" msgstr "Reserve (%1$s) mit %2$s bei %3$s erzeugt" -#: src/webex/pages/popup.tsx:381 +#: src/webex/pages/popup.tsx:384 #, fuzzy, c-format msgid "Paid%1$sto merchant%2$s. (%3$s)\n" msgstr "Reserve (%1$s) mit %2$s bei %3$s erzeugt" -#: src/webex/pages/popup.tsx:388 +#: src/webex/pages/popup.tsx:391 #, c-format msgid "Unknown event (%1$s)" msgstr "" -#: src/webex/pages/popup.tsx:431 +#: src/webex/pages/popup.tsx:434 #, c-format msgid "Error: could not retrieve event history" msgstr "" -#: src/webex/pages/popup.tsx:465 +#: src/webex/pages/popup.tsx:468 #, c-format msgid "Your wallet has no events recorded." msgstr "Ihre Geldbörse verzeichnet keine Vorkommnisse." -#: src/webex/renderHtml.tsx:49 +#: src/webex/renderHtml.tsx:51 #, fuzzy, c-format msgid "The merchant%1$swants to enter a contract over%2$s with you.\n" msgstr "" @@ -289,7 +289,7 @@ msgstr "" " möchte einen Vertrag über %2$s\n" " mit Ihnen abschließen." -#: src/webex/renderHtml.tsx:54 +#: src/webex/renderHtml.tsx:56 #, fuzzy, c-format msgid "You are about to purchase:" msgstr "Sie sind dabei, Folgendes zu kaufen:" diff --git a/src/i18n/en-US.po b/src/i18n/en-US.po index 502bfae34..86ca8ccca 100644 --- a/src/i18n/en-US.po +++ b/src/i18n/en-US.po @@ -197,96 +197,96 @@ msgstr "" msgid "Fatal error: \"%1$s\"." msgstr "" -#: src/webex/pages/popup.tsx:160 +#: src/webex/pages/popup.tsx:163 #, c-format msgid "Balance" msgstr "" -#: src/webex/pages/popup.tsx:163 +#: src/webex/pages/popup.tsx:166 #, c-format msgid "History" msgstr "" -#: src/webex/pages/popup.tsx:166 +#: src/webex/pages/popup.tsx:169 #, c-format msgid "Debug" msgstr "" -#: src/webex/pages/popup.tsx:238 +#: src/webex/pages/popup.tsx:241 #, c-format msgid "help" msgstr "" -#: src/webex/pages/popup.tsx:243 +#: src/webex/pages/popup.tsx:246 #, c-format msgid "" "You have no balance to show. Need some\n" " %1$s getting started?\n" msgstr "" -#: src/webex/pages/popup.tsx:260 +#: src/webex/pages/popup.tsx:263 #, c-format msgid "%1$s incoming\n" msgstr "" -#: src/webex/pages/popup.tsx:273 +#: src/webex/pages/popup.tsx:276 #, c-format msgid "%1$s being spent\n" msgstr "" -#: src/webex/pages/popup.tsx:299 +#: src/webex/pages/popup.tsx:302 #, c-format msgid "Error: could not retrieve balance information." msgstr "" -#: src/webex/pages/popup.tsx:340 +#: src/webex/pages/popup.tsx:343 #, c-format msgid "Bank requested reserve (%1$s) for%2$s.\n" msgstr "" -#: src/webex/pages/popup.tsx:349 +#: src/webex/pages/popup.tsx:352 #, c-format msgid "" "Started to withdraw\n" " %1$s from%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:361 +#: src/webex/pages/popup.tsx:364 #, c-format msgid "Merchant%1$soffered contract%2$s;\n" msgstr "" -#: src/webex/pages/popup.tsx:371 +#: src/webex/pages/popup.tsx:374 #, c-format msgid "Withdrew%1$sfrom%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:381 +#: src/webex/pages/popup.tsx:384 #, c-format msgid "Paid%1$sto merchant%2$s. (%3$s)\n" msgstr "" -#: src/webex/pages/popup.tsx:388 +#: src/webex/pages/popup.tsx:391 #, c-format msgid "Unknown event (%1$s)" msgstr "" -#: src/webex/pages/popup.tsx:431 +#: src/webex/pages/popup.tsx:434 #, c-format msgid "Error: could not retrieve event history" msgstr "" -#: src/webex/pages/popup.tsx:465 +#: src/webex/pages/popup.tsx:468 #, c-format msgid "Your wallet has no events recorded." msgstr "" -#: src/webex/renderHtml.tsx:49 +#: src/webex/renderHtml.tsx:51 #, c-format msgid "The merchant%1$swants to enter a contract over%2$s with you.\n" msgstr "" -#: src/webex/renderHtml.tsx:54 +#: src/webex/renderHtml.tsx:56 #, c-format msgid "You are about to purchase:" msgstr "" diff --git a/src/i18n/fr.po b/src/i18n/fr.po index cdf657b10..71e273b23 100644 --- a/src/i18n/fr.po +++ b/src/i18n/fr.po @@ -197,96 +197,96 @@ msgstr "" msgid "Fatal error: \"%1$s\"." msgstr "" -#: src/webex/pages/popup.tsx:160 +#: src/webex/pages/popup.tsx:163 #, c-format msgid "Balance" msgstr "" -#: src/webex/pages/popup.tsx:163 +#: src/webex/pages/popup.tsx:166 #, c-format msgid "History" msgstr "" -#: src/webex/pages/popup.tsx:166 +#: src/webex/pages/popup.tsx:169 #, c-format msgid "Debug" msgstr "" -#: src/webex/pages/popup.tsx:238 +#: src/webex/pages/popup.tsx:241 #, c-format msgid "help" msgstr "" -#: src/webex/pages/popup.tsx:243 +#: src/webex/pages/popup.tsx:246 #, c-format msgid "" "You have no balance to show. Need some\n" " %1$s getting started?\n" msgstr "" -#: src/webex/pages/popup.tsx:260 +#: src/webex/pages/popup.tsx:263 #, c-format msgid "%1$s incoming\n" msgstr "" -#: src/webex/pages/popup.tsx:273 +#: src/webex/pages/popup.tsx:276 #, c-format msgid "%1$s being spent\n" msgstr "" -#: src/webex/pages/popup.tsx:299 +#: src/webex/pages/popup.tsx:302 #, c-format msgid "Error: could not retrieve balance information." msgstr "" -#: src/webex/pages/popup.tsx:340 +#: src/webex/pages/popup.tsx:343 #, c-format msgid "Bank requested reserve (%1$s) for%2$s.\n" msgstr "" -#: src/webex/pages/popup.tsx:349 +#: src/webex/pages/popup.tsx:352 #, c-format msgid "" "Started to withdraw\n" " %1$s from%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:361 +#: src/webex/pages/popup.tsx:364 #, c-format msgid "Merchant%1$soffered contract%2$s;\n" msgstr "" -#: src/webex/pages/popup.tsx:371 +#: src/webex/pages/popup.tsx:374 #, c-format msgid "Withdrew%1$sfrom%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:381 +#: src/webex/pages/popup.tsx:384 #, c-format msgid "Paid%1$sto merchant%2$s. (%3$s)\n" msgstr "" -#: src/webex/pages/popup.tsx:388 +#: src/webex/pages/popup.tsx:391 #, c-format msgid "Unknown event (%1$s)" msgstr "" -#: src/webex/pages/popup.tsx:431 +#: src/webex/pages/popup.tsx:434 #, c-format msgid "Error: could not retrieve event history" msgstr "" -#: src/webex/pages/popup.tsx:465 +#: src/webex/pages/popup.tsx:468 #, c-format msgid "Your wallet has no events recorded." msgstr "" -#: src/webex/renderHtml.tsx:49 +#: src/webex/renderHtml.tsx:51 #, c-format msgid "The merchant%1$swants to enter a contract over%2$s with you.\n" msgstr "" -#: src/webex/renderHtml.tsx:54 +#: src/webex/renderHtml.tsx:56 #, c-format msgid "You are about to purchase:" msgstr "" diff --git a/src/i18n/it.po b/src/i18n/it.po index cdf657b10..71e273b23 100644 --- a/src/i18n/it.po +++ b/src/i18n/it.po @@ -197,96 +197,96 @@ msgstr "" msgid "Fatal error: \"%1$s\"." msgstr "" -#: src/webex/pages/popup.tsx:160 +#: src/webex/pages/popup.tsx:163 #, c-format msgid "Balance" msgstr "" -#: src/webex/pages/popup.tsx:163 +#: src/webex/pages/popup.tsx:166 #, c-format msgid "History" msgstr "" -#: src/webex/pages/popup.tsx:166 +#: src/webex/pages/popup.tsx:169 #, c-format msgid "Debug" msgstr "" -#: src/webex/pages/popup.tsx:238 +#: src/webex/pages/popup.tsx:241 #, c-format msgid "help" msgstr "" -#: src/webex/pages/popup.tsx:243 +#: src/webex/pages/popup.tsx:246 #, c-format msgid "" "You have no balance to show. Need some\n" " %1$s getting started?\n" msgstr "" -#: src/webex/pages/popup.tsx:260 +#: src/webex/pages/popup.tsx:263 #, c-format msgid "%1$s incoming\n" msgstr "" -#: src/webex/pages/popup.tsx:273 +#: src/webex/pages/popup.tsx:276 #, c-format msgid "%1$s being spent\n" msgstr "" -#: src/webex/pages/popup.tsx:299 +#: src/webex/pages/popup.tsx:302 #, c-format msgid "Error: could not retrieve balance information." msgstr "" -#: src/webex/pages/popup.tsx:340 +#: src/webex/pages/popup.tsx:343 #, c-format msgid "Bank requested reserve (%1$s) for%2$s.\n" msgstr "" -#: src/webex/pages/popup.tsx:349 +#: src/webex/pages/popup.tsx:352 #, c-format msgid "" "Started to withdraw\n" " %1$s from%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:361 +#: src/webex/pages/popup.tsx:364 #, c-format msgid "Merchant%1$soffered contract%2$s;\n" msgstr "" -#: src/webex/pages/popup.tsx:371 +#: src/webex/pages/popup.tsx:374 #, c-format msgid "Withdrew%1$sfrom%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:381 +#: src/webex/pages/popup.tsx:384 #, c-format msgid "Paid%1$sto merchant%2$s. (%3$s)\n" msgstr "" -#: src/webex/pages/popup.tsx:388 +#: src/webex/pages/popup.tsx:391 #, c-format msgid "Unknown event (%1$s)" msgstr "" -#: src/webex/pages/popup.tsx:431 +#: src/webex/pages/popup.tsx:434 #, c-format msgid "Error: could not retrieve event history" msgstr "" -#: src/webex/pages/popup.tsx:465 +#: src/webex/pages/popup.tsx:468 #, c-format msgid "Your wallet has no events recorded." msgstr "" -#: src/webex/renderHtml.tsx:49 +#: src/webex/renderHtml.tsx:51 #, c-format msgid "The merchant%1$swants to enter a contract over%2$s with you.\n" msgstr "" -#: src/webex/renderHtml.tsx:54 +#: src/webex/renderHtml.tsx:56 #, c-format msgid "You are about to purchase:" msgstr "" diff --git a/src/i18n/taler-wallet-webex.pot b/src/i18n/taler-wallet-webex.pot index cdf657b10..71e273b23 100644 --- a/src/i18n/taler-wallet-webex.pot +++ b/src/i18n/taler-wallet-webex.pot @@ -197,96 +197,96 @@ msgstr "" msgid "Fatal error: \"%1$s\"." msgstr "" -#: src/webex/pages/popup.tsx:160 +#: src/webex/pages/popup.tsx:163 #, c-format msgid "Balance" msgstr "" -#: src/webex/pages/popup.tsx:163 +#: src/webex/pages/popup.tsx:166 #, c-format msgid "History" msgstr "" -#: src/webex/pages/popup.tsx:166 +#: src/webex/pages/popup.tsx:169 #, c-format msgid "Debug" msgstr "" -#: src/webex/pages/popup.tsx:238 +#: src/webex/pages/popup.tsx:241 #, c-format msgid "help" msgstr "" -#: src/webex/pages/popup.tsx:243 +#: src/webex/pages/popup.tsx:246 #, c-format msgid "" "You have no balance to show. Need some\n" " %1$s getting started?\n" msgstr "" -#: src/webex/pages/popup.tsx:260 +#: src/webex/pages/popup.tsx:263 #, c-format msgid "%1$s incoming\n" msgstr "" -#: src/webex/pages/popup.tsx:273 +#: src/webex/pages/popup.tsx:276 #, c-format msgid "%1$s being spent\n" msgstr "" -#: src/webex/pages/popup.tsx:299 +#: src/webex/pages/popup.tsx:302 #, c-format msgid "Error: could not retrieve balance information." msgstr "" -#: src/webex/pages/popup.tsx:340 +#: src/webex/pages/popup.tsx:343 #, c-format msgid "Bank requested reserve (%1$s) for%2$s.\n" msgstr "" -#: src/webex/pages/popup.tsx:349 +#: src/webex/pages/popup.tsx:352 #, c-format msgid "" "Started to withdraw\n" " %1$s from%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:361 +#: src/webex/pages/popup.tsx:364 #, c-format msgid "Merchant%1$soffered contract%2$s;\n" msgstr "" -#: src/webex/pages/popup.tsx:371 +#: src/webex/pages/popup.tsx:374 #, c-format msgid "Withdrew%1$sfrom%2$s(%3$s).\n" msgstr "" -#: src/webex/pages/popup.tsx:381 +#: src/webex/pages/popup.tsx:384 #, c-format msgid "Paid%1$sto merchant%2$s. (%3$s)\n" msgstr "" -#: src/webex/pages/popup.tsx:388 +#: src/webex/pages/popup.tsx:391 #, c-format msgid "Unknown event (%1$s)" msgstr "" -#: src/webex/pages/popup.tsx:431 +#: src/webex/pages/popup.tsx:434 #, c-format msgid "Error: could not retrieve event history" msgstr "" -#: src/webex/pages/popup.tsx:465 +#: src/webex/pages/popup.tsx:468 #, c-format msgid "Your wallet has no events recorded." msgstr "" -#: src/webex/renderHtml.tsx:49 +#: src/webex/renderHtml.tsx:51 #, c-format msgid "The merchant%1$swants to enter a contract over%2$s with you.\n" msgstr "" -#: src/webex/renderHtml.tsx:54 +#: src/webex/renderHtml.tsx:56 #, c-format msgid "You are about to purchase:" msgstr "" diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index f710156a5..a1a3f6b2b 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -22,18 +22,21 @@ * @author Florian Dold */ - -"use strict"; - +/** + * Imports. + */ +import { amountToPretty } from "../../helpers"; +import * as i18n from "../../i18n"; import { AmountJson, Amounts, WalletBalance, - WalletBalanceEntry + WalletBalanceEntry, } from "../../types"; -import { HistoryRecord, HistoryLevel } from "../../wallet"; -import { amountToPretty } from "../../helpers"; -import * as i18n from "../../i18n"; +import { + HistoryLevel, + HistoryRecord, +} from "../../wallet"; import { abbrev } from "../renderHtml"; @@ -42,18 +45,18 @@ import * as ReactDOM from "react-dom"; import URI = require("urijs"); function onUpdateNotification(f: () => void): () => void { - let port = chrome.runtime.connect({name: "notifications"}); - let listener = (msg: any, port: any) => { + const port = chrome.runtime.connect({name: "notifications"}); + const listener = () => { f(); }; port.onMessage.addListener(listener); return () => { port.onMessage.removeListener(listener); - } + }; } -class Router extends React.Component { +class Router extends React.Component { static setRoute(s: string): void { window.location.hash = s; } @@ -66,21 +69,21 @@ class Router extends React.Component { static onRoute(f: any): () => void { Router.routeHandlers.push(f); return () => { - let i = Router.routeHandlers.indexOf(f); + const i = Router.routeHandlers.indexOf(f); this.routeHandlers = this.routeHandlers.splice(i, 1); - } + }; } - static routeHandlers: any[] = []; + private static routeHandlers: any[] = []; componentWillMount() { console.log("router mounted"); window.onhashchange = () => { this.setState({}); - for (let f of Router.routeHandlers) { + for (const f of Router.routeHandlers) { f(); } - } + }; } componentWillUnmount() { @@ -89,27 +92,27 @@ class Router extends React.Component { render(): JSX.Element { - let route = window.location.hash.substring(1); + const route = window.location.hash.substring(1); console.log("rendering route", route); let defaultChild: React.ReactChild|null = null; let foundChild: React.ReactChild|null = null; React.Children.forEach(this.props.children, (child) => { - let childProps: any = (child as any).props; + const childProps: any = (child as any).props; if (!childProps) { return; } - if (childProps["default"]) { + if (childProps.default) { defaultChild = child; } - if (childProps["route"] == route) { + if (childProps.route === route) { foundChild = child; } - }) - let child: React.ReactChild | null = foundChild || defaultChild; + }); + const child: React.ReactChild | null = foundChild || defaultChild; if (!child) { throw Error("unknown route"); } - Router.setRoute((child as any).props["route"]); + Router.setRoute((child as any).props.route); return
{child}
; } } @@ -122,10 +125,10 @@ interface TabProps { function Tab(props: TabProps) { let cssClass = ""; - if (props.target == Router.getRoute()) { + if (props.target === Router.getRoute()) { cssClass = "active"; } - let onClick = (e: React.MouseEvent) => { + const onClick = (e: React.MouseEvent) => { Router.setRoute(props.target); e.preventDefault(); }; @@ -137,8 +140,8 @@ function Tab(props: TabProps) { } -class WalletNavBar extends React.Component { - cancelSubscription: any; +class WalletNavBar extends React.Component { + private cancelSubscription: any; componentWillMount() { this.cancelSubscription = Router.onRoute(() => { @@ -171,21 +174,25 @@ class WalletNavBar extends React.Component { function ExtensionLink(props: any) { - let onClick = (e: React.MouseEvent) => { + const onClick = (e: React.MouseEvent) => { chrome.tabs.create({ - "url": chrome.extension.getURL(props.target) - }); + url: chrome.extension.getURL(props.target), + }); e.preventDefault(); }; return ( {props.children} - ) + + ); } -export function bigAmount(amount: AmountJson): JSX.Element { - let v = amount.value + amount.fraction / Amounts.fractionalBase; +/** + * Render an amount as a large number with a small currency symbol. + */ +function bigAmount(amount: AmountJson): JSX.Element { + const v = amount.value + amount.fraction / Amounts.fractionalBase; return ( {v} @@ -196,10 +203,10 @@ export function bigAmount(amount: AmountJson): JSX.Element { } class WalletBalanceView extends React.Component { - balance: WalletBalance; - gotError = false; - canceler: (() => void) | undefined = undefined; - unmount = false; + private balance: WalletBalance; + private gotError = false; + private canceler: (() => void) | undefined = undefined; + private unmount = false; componentWillMount() { this.canceler = onUpdateNotification(() => this.updateBalance()); @@ -233,7 +240,7 @@ class WalletBalanceView extends React.Component { } renderEmpty(): JSX.Element { - let helpLink = ( + const helpLink = ( {i18n.str`help`} @@ -281,20 +288,20 @@ class WalletBalanceView extends React.Component { ); } - let l = [incoming, payment].filter((x) => x !== undefined); - if (l.length == 0) { + const l = [incoming, payment].filter((x) => x !== undefined); + if (l.length === 0) { return ; } - if (l.length == 1) { - return ({l}) + if (l.length === 1) { + return ({l}); } return ({l[0]}, {l[1]}); } render(): JSX.Element { - let wallet = this.balance; + const wallet = this.balance; if (this.gotError) { return i18n.str`Error: could not retrieve balance information.`; } @@ -303,9 +310,9 @@ class WalletBalanceView extends React.Component { } console.log(wallet); let paybackAvailable = false; - let listing = Object.keys(wallet).map((key) => { - let entry: WalletBalanceEntry = wallet[key]; - if (entry.paybackAmount.value != 0 || entry.paybackAmount.fraction != 0) { + const listing = Object.keys(wallet).map((key) => { + const entry: WalletBalanceEntry = wallet[key]; + if (entry.paybackAmount.value !== 0 || entry.paybackAmount.fraction !== 0) { paybackAvailable = true; } return ( @@ -316,10 +323,10 @@ class WalletBalanceView extends React.Component {

); }); - let link = chrome.extension.getURL("/src/webex/pages/auditors.html"); - let linkElem = Trusted Auditors and Exchanges; - let paybackLink = chrome.extension.getURL("/src/webex/pages/payback.html"); - let paybackLinkElem = Trusted Auditors and Exchanges; + const link = chrome.extension.getURL("/src/webex/pages/auditors.html"); + const linkElem = Trusted Auditors and Exchanges; + const paybackLink = chrome.extension.getURL("/src/webex/pages/payback.html"); + const paybackLinkElem = Trusted Auditors and Exchanges; return (
{listing.length > 0 ? listing : this.renderEmpty()} @@ -339,13 +346,15 @@ function formatHistoryItem(historyItem: HistoryRecord) { case "create-reserve": return ( - Bank requested reserve ({abbrev(d.reservePub)}) for {amountToPretty(d.requestedAmount)}. + Bank requested reserve ({abbrev(d.reservePub)}) for + {" "} + {amountToPretty(d.requestedAmount)}. ); case "confirm-reserve": { // FIXME: eventually remove compat fix - let exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??"; - let pub = abbrev(d.reservePub); + const exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??"; + const pub = abbrev(d.reservePub); return ( Started to withdraw @@ -355,9 +364,9 @@ function formatHistoryItem(historyItem: HistoryRecord) { ); } case "offer-contract": { - let link = chrome.extension.getURL("view-contract.html"); - let linkElem = {abbrev(d.contractHash)}; - let merchantElem = {abbrev(d.merchantName, 15)}; + const link = chrome.extension.getURL("view-contract.html"); + const linkElem = {abbrev(d.contractHash)}; + const merchantElem = {abbrev(d.merchantName, 15)}; return ( Merchant {abbrev(d.merchantName, 15)} offered contract {abbrev(d.contractHash)}; @@ -365,9 +374,9 @@ function formatHistoryItem(historyItem: HistoryRecord) { ); } case "depleted-reserve": { - let exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??"; - let amount = amountToPretty(d.requestedAmount); - let pub = abbrev(d.reservePub); + const exchange = d.exchangeBaseUrl ? (new URI(d.exchangeBaseUrl)).host() : "??"; + const amount = amountToPretty(d.requestedAmount); + const pub = abbrev(d.reservePub); return ( Withdrew {amount} from {exchange} ({pub}). @@ -375,12 +384,14 @@ function formatHistoryItem(historyItem: HistoryRecord) { ); } case "pay": { - let url = d.fulfillmentUrl; - let merchantElem = {abbrev(d.merchantName, 15)}; - let fulfillmentLinkElem = view product; + const url = d.fulfillmentUrl; + const merchantElem = {abbrev(d.merchantName, 15)}; + const fulfillmentLinkElem = view product; return ( - Paid {amountToPretty(d.amount)} to merchant {merchantElem}. ({fulfillmentLinkElem}) + Paid {amountToPretty(d.amount)} to merchant {merchantElem}. + {" "} + ({fulfillmentLinkElem}) ); } @@ -391,9 +402,9 @@ function formatHistoryItem(historyItem: HistoryRecord) { class WalletHistory extends React.Component { - myHistory: any[]; - gotError = false; - unmounted = false; + private myHistory: any[]; + private gotError = false; + private unmounted = false; componentWillMount() { this.update(); @@ -426,7 +437,7 @@ class WalletHistory extends React.Component { render(): JSX.Element { console.log("rendering history"); - let history: HistoryRecord[] = this.myHistory; + const history: HistoryRecord[] = this.myHistory; if (this.gotError) { return i18n.str`Error: could not retrieve event history`; } @@ -436,18 +447,18 @@ class WalletHistory extends React.Component { return ; } - let subjectMemo: {[s: string]: boolean} = {}; - let listing: any[] = []; - for (let record of history.reverse()) { + 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) { + if (record.level !== undefined && record.level < HistoryLevel.User) { continue; } subjectMemo[record.subjectId as string] = true; - let item = ( + const item = (
{(new Date(record.timestamp)).toString()} @@ -462,7 +473,7 @@ class WalletHistory extends React.Component { if (listing.length > 0) { return
{listing}
; } - return

{i18n.str`Your wallet has no events recorded.`}

+ return

{i18n.str`Your wallet has no events recorded.`}

; } } @@ -513,24 +524,24 @@ function WalletDebug(props: any) { function openExtensionPage(page: string) { - return function() { + return () => { chrome.tabs.create({ - "url": chrome.extension.getURL(page) + url: chrome.extension.getURL(page), }); - } + }; } function openTab(page: string) { - return function() { + return () => { chrome.tabs.create({ - "url": page + url: page, }); - } + }; } -let el = ( +const el = (
@@ -545,4 +556,4 @@ let el = ( document.addEventListener("DOMContentLoaded", () => { ReactDOM.render(el, document.getElementById("content")!); -}) +}); diff --git a/src/webex/pages/tree.tsx b/src/webex/pages/tree.tsx index ddf8f2dbc..850a3c46d 100644 --- a/src/webex/pages/tree.tsx +++ b/src/webex/pages/tree.tsx @@ -34,9 +34,15 @@ import { import { ImplicitStateComponent, StateHolder } from "../components"; import { - getReserves, getExchanges, getCoins, getPreCoins, - refresh, getDenoms, payback, + getCoins, + getDenoms, + getExchanges, + getPreCoins, + getReserves, + payback, + refresh, } from "../wxApi"; + import * as React from "react"; import * as ReactDOM from "react-dom"; @@ -46,7 +52,7 @@ interface ReserveViewProps { class ReserveView extends React.Component { render(): JSX.Element { - let r: ReserveRecord = this.props.reserve; + const r: ReserveRecord = this.props.reserve; return (
    @@ -71,11 +77,11 @@ interface ToggleProps { class Toggle extends ImplicitStateComponent { renderButton() { - let show = () => { + const show = () => { this.props.expanded(true); this.setState({}); }; - let hide = () => { + const hide = () => { this.props.expanded(false); this.setState({}); }; @@ -104,7 +110,7 @@ interface RefreshDialogProps { } class RefreshDialog extends ImplicitStateComponent { - refreshRequested = this.makeState(false); + private refreshRequested = this.makeState(false); render(): JSX.Element { if (!this.refreshRequested()) { return ( @@ -125,7 +131,7 @@ class RefreshDialog extends ImplicitStateComponent { class CoinView extends React.Component { render() { - let c = this.props.coin; + const c = this.props.coin; return (
      @@ -143,14 +149,13 @@ class CoinView extends React.Component { } - interface PreCoinViewProps { precoin: PreCoinRecord; } class PreCoinView extends React.Component { render() { - let c = this.props.precoin; + const c = this.props.precoin; return (
        @@ -166,8 +171,8 @@ interface CoinListProps { } class CoinList extends ImplicitStateComponent { - coins = this.makeState(null); - expanded = this.makeState(false); + private coins = this.makeState(null); + private expanded = this.makeState(false); constructor(props: CoinListProps) { super(props); @@ -175,7 +180,7 @@ class CoinList extends ImplicitStateComponent { } async update(props: CoinListProps) { - let coins = await getCoins(props.exchangeBaseUrl); + const coins = await getCoins(props.exchangeBaseUrl); this.coins(coins); } @@ -205,8 +210,8 @@ interface PreCoinListProps { } class PreCoinList extends ImplicitStateComponent { - precoins = this.makeState(null); - expanded = this.makeState(false); + private precoins = this.makeState(null); + private expanded = this.makeState(false); constructor(props: PreCoinListProps) { super(props); @@ -214,7 +219,7 @@ class PreCoinList extends ImplicitStateComponent { } async update() { - let precoins = await getPreCoins(this.props.exchangeBaseUrl); + const precoins = await getPreCoins(this.props.exchangeBaseUrl); this.precoins(precoins); } @@ -243,8 +248,8 @@ interface ExpanderTextProps { } class ExpanderText extends ImplicitStateComponent { - expanded = this.makeState(false); - textArea: any = undefined; + private expanded = this.makeState(false); + private textArea: any = undefined; componentDidUpdate() { if (this.expanded() && this.textArea) { @@ -258,10 +263,10 @@ class ExpanderText extends ImplicitStateComponent { return ( { this.expanded(true); }}> {(this.props.text.length <= 10) - ? this.props.text + ? this.props.text : ( - {this.props.text.substring(0,10)} + {this.props.text.substring(0, 10)} ... ) @@ -282,8 +287,8 @@ class ExpanderText extends ImplicitStateComponent { } class DenominationList extends ImplicitStateComponent { - expanded = this.makeState(false); - denoms = this.makeState(undefined); + private expanded = this.makeState(false); + private denoms = this.makeState(undefined); constructor(props: DenominationListProps) { super(props); @@ -291,7 +296,7 @@ class DenominationList extends ImplicitStateComponent { } async update() { - let d = await getDenoms(this.props.exchange.baseUrl); + const d = await getDenoms(this.props.exchange.baseUrl); this.denoms(d); } @@ -316,7 +321,7 @@ class DenominationList extends ImplicitStateComponent { } render(): JSX.Element { - let denoms = this.denoms() + const denoms = this.denoms(); if (!denoms) { return (
        @@ -340,9 +345,10 @@ class DenominationList extends ImplicitStateComponent { } } + class ReserveList extends ImplicitStateComponent { - reserves = this.makeState(null); - expanded = this.makeState(false); + private reserves = this.makeState(null); + private expanded = this.makeState(false); constructor(props: ReserveListProps) { super(props); @@ -350,7 +356,7 @@ class ReserveList extends ImplicitStateComponent { } async update() { - let reserves = await getReserves(this.props.exchangeBaseUrl); + const reserves = await getReserves(this.props.exchangeBaseUrl); this.reserves(reserves); } @@ -376,7 +382,7 @@ interface ExchangeProps { class ExchangeView extends React.Component { render(): JSX.Element { - let e = this.props.exchange; + const e = this.props.exchange; return (
          @@ -399,7 +405,7 @@ interface ExchangesListState { class ExchangesList extends React.Component { constructor() { super(); - let port = chrome.runtime.connect(); + const port = chrome.runtime.connect(); port.onMessage.addListener((msg: any) => { if (msg.notify) { console.log("got notified"); @@ -411,26 +417,26 @@ class ExchangesList extends React.Component { } async update() { - let exchanges = await getExchanges(); + const exchanges = await getExchanges(); console.log("exchanges: ", exchanges); this.setState({ exchanges }); } render(): JSX.Element { - let exchanges = this.state.exchanges; + const exchanges = this.state.exchanges; if (!exchanges) { return ...; } return (
          Exchanges ({exchanges.length.toString()}): - {exchanges.map(e => )} + {exchanges.map((e) => )}
          ); } } -export function main() { +function main() { ReactDOM.render(, document.getElementById("container")!); } diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx index 440cd5789..d6f923aa1 100644 --- a/src/webex/renderHtml.tsx +++ b/src/webex/renderHtml.tsx @@ -24,17 +24,19 @@ /** * Imports. */ +import { amountToPretty } from "../helpers"; +import * as i18n from "../i18n"; import { AmountJson, Amounts, Contract, } from "../types"; -import * as i18n from "../i18n"; -import { amountToPretty } from "../helpers"; import * as React from "react"; - +/** + * Render contract terms for the end user to view. + */ export function renderContract(contract: Contract): JSX.Element { let merchantName; if (contract.merchant && contract.merchant.name) { @@ -42,7 +44,7 @@ export function renderContract(contract: Contract): JSX.Element { } else { merchantName = (pub: {contract.merchant_pub}); } - let amount = {amountToPretty(contract.amount)}; + const amount = {amountToPretty(contract.amount)}; return (
          diff --git a/webpack.config.js b/webpack.config.js index 49a7b865f..d86379d57 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -33,6 +33,9 @@ module.exports = function (env) { if (env.prod) { base.plugins.push(new webpack.optimize.UglifyJsPlugin()); base.plugins.push(new webpack.LoaderOptionsPlugin({minimize: true})); + base.plugins.push(new webpack.DefinePlugin({ + "process.env.NODE_ENV": JSON.stringify("production") + })); } const configWebWorker = { entry: {"cryptoWorker": "./src/crypto/cryptoWorker.ts"}, -- cgit v1.2.3