fix remaining lint warnings

This commit is contained in:
Florian Dold 2017-05-29 16:58:03 +02:00
parent 1c3346cd53
commit b5c90d1221
No known key found for this signature in database
GPG Key ID: D2E4F00F29D02A4B
7 changed files with 114 additions and 87 deletions

View File

@ -21,8 +21,9 @@
/** /**
* Imports. * Imports.
*/ */
import * as jedLib from "jed";
import {strings} from "./i18n/strings"; import {strings} from "./i18n/strings";
import * as jedLib from "jed";
import * as React from "react"; import * as React from "react";
let lang: string; let lang: string;
@ -111,15 +112,15 @@ interface TranslateProps {
* </Translate> * </Translate>
* ``` * ```
*/ */
export class Translate extends React.Component<TranslateProps,void> { export class Translate extends React.Component<TranslateProps, void> {
render(): JSX.Element { render(): JSX.Element {
const s = stringifyChildren(this.props.children); const s = stringifyChildren(this.props.children);
const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 == 0); const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 === 0);
const childArray = React.Children.toArray(this.props.children!); const childArray = React.Children.toArray(this.props.children!);
for (let i = 0; i < childArray.length - 1; ++i) { for (let i = 0; i < childArray.length - 1; ++i) {
if ((typeof childArray[i]) == "string" && (typeof childArray[i+1]) == "string") { if ((typeof childArray[i]) === "string" && (typeof childArray[i + 1]) === "string") {
childArray[i+1] = (childArray[i] as string).concat(childArray[i+1] as string); childArray[i + 1] = (childArray[i] as string).concat(childArray[i + 1] as string);
childArray.splice(i,1); childArray.splice(i, 1);
} }
} }
const result = []; const result = [];
@ -155,20 +156,20 @@ export class Translate extends React.Component<TranslateProps,void> {
* </TranslateSwitch> * </TranslateSwitch>
* ``` * ```
*/ */
export class TranslateSwitch extends React.Component<TranslateSwitchProps,void>{ export class TranslateSwitch extends React.Component<TranslateSwitchProps, void> {
render(): JSX.Element { render(): JSX.Element {
let singular: React.ReactElement<TranslationPluralProps> | undefined; let singular: React.ReactElement<TranslationPluralProps> | undefined;
let plural: React.ReactElement<TranslationPluralProps> | undefined; let plural: React.ReactElement<TranslationPluralProps> | undefined;
const children = this.props.children; const children = this.props.children;
if (children) { if (children) {
React.Children.forEach(children, (child: any) => { React.Children.forEach(children, (child: any) => {
if (child.type == TranslatePlural) { if (child.type === TranslatePlural) {
plural = child; plural = child;
} }
if (child.type == TranslateSingular) { if (child.type === TranslateSingular) {
singular = child; singular = child;
} }
}); });
} }
if ((!singular) || (!plural)) { if ((!singular) || (!plural)) {
console.error("translation not found"); console.error("translation not found");
@ -190,15 +191,15 @@ interface TranslationPluralProps {
/** /**
* See [[TranslateSwitch]]. * See [[TranslateSwitch]].
*/ */
export class TranslatePlural extends React.Component<TranslationPluralProps,void> { export class TranslatePlural extends React.Component<TranslationPluralProps, void> {
render(): JSX.Element { render(): JSX.Element {
const s = stringifyChildren(this.props.children); const s = stringifyChildren(this.props.children);
const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 == 0); const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 === 0);
const childArray = React.Children.toArray(this.props.children!); const childArray = React.Children.toArray(this.props.children!);
for (let i = 0; i < childArray.length - 1; ++i) { for (let i = 0; i < childArray.length - 1; ++i) {
if ((typeof childArray[i]) == "string" && (typeof childArray[i + 1]) == "string") { if ((typeof childArray[i]) === "string" && (typeof childArray[i + 1]) === "string") {
childArray[i+i] = childArray[i] as string + childArray[i + 1] as string; childArray[i + i] = childArray[i] as string + childArray[i + 1] as string;
childArray.splice(i,1); childArray.splice(i, 1);
} }
} }
const result = []; const result = [];
@ -222,15 +223,15 @@ export class TranslatePlural extends React.Component<TranslationPluralProps,void
/** /**
* See [[TranslateSwitch]]. * See [[TranslateSwitch]].
*/ */
export class TranslateSingular extends React.Component<TranslationPluralProps,void> { export class TranslateSingular extends React.Component<TranslationPluralProps, void> {
render(): JSX.Element { render(): JSX.Element {
const s = stringifyChildren(this.props.children); const s = stringifyChildren(this.props.children);
const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 == 0); const tr = jed.ngettext(s, s, 1).split(/%(\d+)\$s/).filter((e: any, i: number) => i % 2 === 0);
const childArray = React.Children.toArray(this.props.children!); const childArray = React.Children.toArray(this.props.children!);
for (let i = 0; i < childArray.length - 1; ++i) { for (let i = 0; i < childArray.length - 1; ++i) {
if ((typeof childArray[i]) == "string" && (typeof childArray[i + 1]) == "string") { if ((typeof childArray[i]) === "string" && (typeof childArray[i + 1]) === "string") {
childArray[i+i] = childArray[i] as string + childArray[i + 1] as string; childArray[i + i] = childArray[i] as string + childArray[i + 1] as string;
childArray.splice(i,1); childArray.splice(i, 1);
} }
} }
const result = []; const result = [];

View File

@ -18,6 +18,9 @@
* In-memory implementation of the IndexedDB interface. * In-memory implementation of the IndexedDB interface.
*/ */
/* work in progres ... */
/* tslint:disable */
interface StoredObject { interface StoredObject {
key: any; key: any;

View File

@ -1117,8 +1117,6 @@ export class OfferRecord {
} }
/** /**
* Wire fee for one wire method as stored in the * Wire fee for one wire method as stored in the
* wallet's database. * wallet's database.
@ -1380,8 +1378,11 @@ export function mkAmount(value: number, fraction: number, currency: string): Amo
} }
/** /**
* Possible responses for checkPay. * Possible results for checkPay.
*/ */
export type CheckPayResult = "paid" | "payment-possible" | "insufficient-balance"; export type CheckPayResult = "paid" | "payment-possible" | "insufficient-balance";
/**
* Possible results for confirmPay.
*/
export type ConfirmPayResult = "paid" | "insufficient-balance"; export type ConfirmPayResult = "paid" | "insufficient-balance";

View File

@ -23,14 +23,14 @@
import { getTalerStampDate } from "../../helpers"; import { getTalerStampDate } from "../../helpers";
import { import {
ExchangeRecord,
DenominationRecord,
AuditorRecord, AuditorRecord,
CurrencyRecord,
ReserveRecord,
CoinRecord, CoinRecord,
CurrencyRecord,
Denomination,
DenominationRecord,
ExchangeRecord,
PreCoinRecord, PreCoinRecord,
Denomination ReserveRecord,
} from "../../types"; } from "../../types";
import { ImplicitStateComponent, StateHolder } from "../components"; import { ImplicitStateComponent, StateHolder } from "../components";
@ -51,17 +51,17 @@ interface ConfirmAuditorProps {
} }
class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> { class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
addDone: StateHolder<boolean> = this.makeState(false); private addDone: StateHolder<boolean> = this.makeState(false);
constructor() { constructor() {
super(); super();
} }
async add() { async add() {
let currencies = await getCurrencies(); const currencies = await getCurrencies();
let currency: CurrencyRecord|undefined = undefined; let currency: CurrencyRecord|undefined;
for (let c of currencies) { for (const c of currencies) {
if (c.name == this.props.currency) { if (c.name === this.props.currency) {
currency = c; currency = c;
} }
} }
@ -70,12 +70,16 @@ class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
currency = { name: this.props.currency, auditors: [], fractionalDigits: 2, exchanges: [] }; currency = { name: this.props.currency, auditors: [], fractionalDigits: 2, exchanges: [] };
} }
let newAuditor = { auditorPub: this.props.auditorPub, baseUrl: this.props.url, expirationStamp: this.props.expirationStamp }; const newAuditor = {
auditorPub: this.props.auditorPub,
baseUrl: this.props.url,
expirationStamp: this.props.expirationStamp,
};
let auditorFound = false; let auditorFound = false;
for (let idx in currency.auditors) { for (const idx in currency.auditors) {
let a = currency.auditors[idx]; const a = currency.auditors[idx];
if (a.baseUrl == this.props.url) { if (a.baseUrl === this.props.url) {
auditorFound = true; auditorFound = true;
// Update auditor if already found by URL. // Update auditor if already found by URL.
currency.auditors[idx] = newAuditor; currency.auditors[idx] = newAuditor;
@ -99,22 +103,30 @@ class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
return ( return (
<div id="main"> <div id="main">
<p>Do you want to let <strong>{this.props.auditorPub}</strong> audit the currency "{this.props.currency}"?</p> <p>Do you want to let <strong>{this.props.auditorPub}</strong> audit the currency "{this.props.currency}"?</p>
{this.addDone() ? {this.addDone() ?
(<div>Auditor was added! You can also <a href={chrome.extension.getURL("/src/webex/pages/auditors.html")}>view and edit</a> auditors.</div>) (
: <div>
(<div> Auditor was added! You can also{" "}
<button onClick={() => this.add()} className="pure-button pure-button-primary">Yes</button> <a href={chrome.extension.getURL("/src/webex/pages/auditors.html")}>view and edit</a>{" "}
<button onClick={() => this.back()} className="pure-button">No</button> auditors.
</div>) </div>
)
:
(
<div>
<button onClick={() => this.add()} className="pure-button pure-button-primary">Yes</button>
<button onClick={() => this.back()} className="pure-button">No</button>
</div>
)
} }
</div> </div>
); );
} }
} }
export function main() { function main() {
const walletPageUrl = new URI(document.location.href); const walletPageUrl = new URI(document.location.href);
const query: any = JSON.parse((URI.parseQuery(walletPageUrl.query()) as any)["req"]); const query: any = JSON.parse((URI.parseQuery(walletPageUrl.query()) as any).req);
const url = query.url; const url = query.url;
const currency: string = query.currency; const currency: string = query.currency;
const auditorPub: string = query.auditorPub; const auditorPub: string = query.auditorPub;

View File

@ -23,15 +23,15 @@
import { getTalerStampDate } from "../../helpers"; import { getTalerStampDate } from "../../helpers";
import { import {
ExchangeRecord,
ExchangeForCurrencyRecord,
DenominationRecord,
AuditorRecord, AuditorRecord,
CurrencyRecord,
ReserveRecord,
CoinRecord, CoinRecord,
CurrencyRecord,
Denomination,
DenominationRecord,
ExchangeForCurrencyRecord,
ExchangeRecord,
PreCoinRecord, PreCoinRecord,
Denomination ReserveRecord,
} from "../../types"; } from "../../types";
import { ImplicitStateComponent, StateHolder } from "../components"; import { ImplicitStateComponent, StateHolder } from "../components";
@ -39,6 +39,7 @@ import {
getCurrencies, getCurrencies,
updateCurrency, updateCurrency,
} from "../wxApi"; } from "../wxApi";
import * as React from "react"; import * as React from "react";
import * as ReactDOM from "react-dom"; import * as ReactDOM from "react-dom";
@ -49,7 +50,7 @@ interface CurrencyListState {
class CurrencyList extends React.Component<any, CurrencyListState> { class CurrencyList extends React.Component<any, CurrencyListState> {
constructor() { constructor() {
super(); super();
let port = chrome.runtime.connect(); const port = chrome.runtime.connect();
port.onMessage.addListener((msg: any) => { port.onMessage.addListener((msg: any) => {
if (msg.notify) { if (msg.notify) {
console.log("got notified"); console.log("got notified");
@ -61,35 +62,39 @@ class CurrencyList extends React.Component<any, CurrencyListState> {
} }
async update() { async update() {
let currencies = await getCurrencies(); const currencies = await getCurrencies();
console.log("currencies: ", currencies); console.log("currencies: ", currencies);
this.setState({ currencies }); this.setState({ currencies });
} }
async confirmRemoveAuditor(c: CurrencyRecord, a: AuditorRecord) { async confirmRemoveAuditor(c: CurrencyRecord, a: AuditorRecord) {
if (window.confirm(`Do you really want to remove auditor ${a.baseUrl} for currency ${c.name}?`)) { if (window.confirm(`Do you really want to remove auditor ${a.baseUrl} for currency ${c.name}?`)) {
c.auditors = c.auditors.filter((x) => x.auditorPub != a.auditorPub); c.auditors = c.auditors.filter((x) => x.auditorPub !== a.auditorPub);
await updateCurrency(c); await updateCurrency(c);
} }
} }
async confirmRemoveExchange(c: CurrencyRecord, e: ExchangeForCurrencyRecord) { async confirmRemoveExchange(c: CurrencyRecord, e: ExchangeForCurrencyRecord) {
if (window.confirm(`Do you really want to remove exchange ${e.baseUrl} for currency ${c.name}?`)) { if (window.confirm(`Do you really want to remove exchange ${e.baseUrl} for currency ${c.name}?`)) {
c.exchanges = c.exchanges.filter((x) => x.baseUrl != e.baseUrl); c.exchanges = c.exchanges.filter((x) => x.baseUrl !== e.baseUrl);
await updateCurrency(c); await updateCurrency(c);
} }
} }
renderAuditors(c: CurrencyRecord): any { renderAuditors(c: CurrencyRecord): any {
if (c.auditors.length == 0) { if (c.auditors.length === 0) {
return <p>No trusted auditors for this currency.</p> return <p>No trusted auditors for this currency.</p>;
} }
return ( return (
<div> <div>
<p>Trusted Auditors:</p> <p>Trusted Auditors:</p>
<ul> <ul>
{c.auditors.map(a => ( {c.auditors.map((a) => (
<li>{a.baseUrl} <button className="pure-button button-destructive" onClick={() => this.confirmRemoveAuditor(c, a)}>Remove</button> <li>
{a.baseUrl}{" "}
<button className="pure-button button-destructive" onClick={() => this.confirmRemoveAuditor(c, a)}>
Remove
</button>
<ul> <ul>
<li>valid until {new Date(a.expirationStamp).toString()}</li> <li>valid until {new Date(a.expirationStamp).toString()}</li>
<li>public key {a.auditorPub}</li> <li>public key {a.auditorPub}</li>
@ -102,15 +107,19 @@ class CurrencyList extends React.Component<any, CurrencyListState> {
} }
renderExchanges(c: CurrencyRecord): any { renderExchanges(c: CurrencyRecord): any {
if (c.exchanges.length == 0) { if (c.exchanges.length === 0) {
return <p>No trusted exchanges for this currency.</p> return <p>No trusted exchanges for this currency.</p>;
} }
return ( return (
<div> <div>
<p>Trusted Exchanges:</p> <p>Trusted Exchanges:</p>
<ul> <ul>
{c.exchanges.map(e => ( {c.exchanges.map((e) => (
<li>{e.baseUrl} <button className="pure-button button-destructive" onClick={() => this.confirmRemoveExchange(c, e)}>Remove</button> <li>
{e.baseUrl}{" "}
<button className="pure-button button-destructive" onClick={() => this.confirmRemoveExchange(c, e)}>
Remove
</button>
</li> </li>
))} ))}
</ul> </ul>
@ -119,13 +128,13 @@ class CurrencyList extends React.Component<any, CurrencyListState> {
} }
render(): JSX.Element { render(): JSX.Element {
let currencies = this.state.currencies; const currencies = this.state.currencies;
if (!currencies) { if (!currencies) {
return <span>...</span>; return <span>...</span>;
} }
return ( return (
<div id="main"> <div id="main">
{currencies.map(c => ( {currencies.map((c) => (
<div> <div>
<h1>Currency {c.name}</h1> <h1>Currency {c.name}</h1>
<p>Displayed with {c.fractionalDigits} fractional digits.</p> <p>Displayed with {c.fractionalDigits} fractional digits.</p>
@ -140,7 +149,7 @@ class CurrencyList extends React.Component<any, CurrencyListState> {
} }
} }
export function main() { function main() {
ReactDOM.render(<CurrencyList />, document.getElementById("container")!); ReactDOM.render(<CurrencyList />, document.getElementById("container")!);
} }

View File

@ -44,8 +44,8 @@ interface DetailState {
} }
interface DetailProps { interface DetailProps {
contract: Contract contract: Contract;
collapsed: boolean collapsed: boolean;
exchanges: null|ExchangeRecord[]; exchanges: null|ExchangeRecord[];
} }
@ -66,7 +66,7 @@ class Details extends React.Component<DetailProps, DetailState> {
return ( return (
<div> <div>
<button className="linky" <button className="linky"
onClick={() => { this.setState({collapsed: false} as any)}}> onClick={() => { this.setState({collapsed: false} as any); }}>
<i18n.Translate wrap="span"> <i18n.Translate wrap="span">
show more details show more details
</i18n.Translate> </i18n.Translate>
@ -84,7 +84,7 @@ class Details extends React.Component<DetailProps, DetailState> {
{i18n.str`Accepted exchanges:`} {i18n.str`Accepted exchanges:`}
<ul> <ul>
{this.props.contract.exchanges.map( {this.props.contract.exchanges.map(
e => <li>{`${e.url}: ${e.master_pub}`}</li>)} (e) => <li>{`${e.url}: ${e.master_pub}`}</li>)}
</ul> </ul>
{i18n.str`Exchanges in the wallet:`} {i18n.str`Exchanges in the wallet:`}
<ul> <ul>
@ -113,11 +113,11 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
constructor() { constructor() {
super(); super();
this.state = { this.state = {
offer: null,
error: null, error: null,
exchanges: null,
offer: null,
payDisabled: true, payDisabled: true,
exchanges: null };
}
} }
componentWillMount() { componentWillMount() {
@ -129,26 +129,27 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
} }
async update() { async update() {
let offer = await wxApi.getOffer(this.props.offerId); const offer = await wxApi.getOffer(this.props.offerId);
this.setState({offer} as any); this.setState({offer} as any);
this.checkPayment(); this.checkPayment();
let exchanges = await wxApi.getExchanges(); const exchanges = await wxApi.getExchanges();
this.setState({exchanges} as any); this.setState({exchanges} as any);
} }
async checkPayment() { async checkPayment() {
let offer = this.state.offer; const offer = this.state.offer;
if (!offer) { if (!offer) {
return; return;
} }
const payStatus = await wxApi.checkPay(offer); const payStatus = await wxApi.checkPay(offer);
if (payStatus === "insufficient-balance") { if (payStatus === "insufficient-balance") {
let msgInsufficient = i18n.str`You have insufficient funds of the requested currency in your wallet.`; const msgInsufficient = i18n.str`You have insufficient funds of the requested currency in your wallet.`;
let msgNoMatch = i18n.str`You do not have any funds from an exchange that is accepted by this merchant. None of the exchanges accepted by the merchant is known to your wallet.`; // tslint:disable-next-line:max-line-length
const msgNoMatch = i18n.str`You do not have any funds from an exchange that is accepted by this merchant. None of the exchanges accepted by the merchant is known to your wallet.`;
if (this.state.exchanges && this.state.offer) { if (this.state.exchanges && this.state.offer) {
let acceptedExchangePubs = this.state.offer.contract.exchanges.map((e) => e.master_pub); const acceptedExchangePubs = this.state.offer.contract.exchanges.map((e) => e.master_pub);
let ex = this.state.exchanges.find((e) => acceptedExchangePubs.indexOf(e.masterPublicKey) >= 0); const ex = this.state.exchanges.find((e) => acceptedExchangePubs.indexOf(e.masterPublicKey) >= 0);
if (ex) { if (ex) {
this.setState({error: msgInsufficient}); this.setState({error: msgInsufficient});
} else { } else {
@ -165,7 +166,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
} }
async doPayment() { async doPayment() {
let offer = this.state.offer; const offer = this.state.offer;
if (!offer) { if (!offer) {
return; return;
} }
@ -186,7 +187,7 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
if (!this.state.offer) { if (!this.state.offer) {
return <span>...</span>; return <span>...</span>;
} }
let c = this.state.offer.contract; const c = this.state.offer.contract;
return ( return (
<div> <div>
<div> <div>
@ -208,9 +209,9 @@ class ContractPrompt extends React.Component<ContractPromptProps, ContractPrompt
document.addEventListener("DOMContentLoaded", () => { document.addEventListener("DOMContentLoaded", () => {
let url = new URI(document.location.href); const url = new URI(document.location.href);
let query: any = URI.parseQuery(url.query()); const query: any = URI.parseQuery(url.query());
let offerId = JSON.parse(query.offerId); const offerId = JSON.parse(query.offerId);
ReactDOM.render(<ContractPrompt offerId={offerId}/>, document.getElementById( ReactDOM.render(<ContractPrompt offerId={offerId}/>, document.getElementById(
"contract")!); "contract")!);

View File

@ -25,8 +25,8 @@
import { import {
AmountJson, AmountJson,
CheckPayResult, CheckPayResult,
ConfirmPayResult,
CoinRecord, CoinRecord,
ConfirmPayResult,
CurrencyRecord, CurrencyRecord,
DenominationRecord, DenominationRecord,
ExchangeRecord, ExchangeRecord,