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

View File

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

View File

@ -1117,8 +1117,6 @@ export class OfferRecord {
}
/**
* Wire fee for one wire method as stored in the
* 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";
/**
* Possible results for confirmPay.
*/
export type ConfirmPayResult = "paid" | "insufficient-balance";

View File

@ -23,14 +23,14 @@
import { getTalerStampDate } from "../../helpers";
import {
ExchangeRecord,
DenominationRecord,
AuditorRecord,
CurrencyRecord,
ReserveRecord,
CoinRecord,
CurrencyRecord,
Denomination,
DenominationRecord,
ExchangeRecord,
PreCoinRecord,
Denomination
ReserveRecord,
} from "../../types";
import { ImplicitStateComponent, StateHolder } from "../components";
@ -51,17 +51,17 @@ interface ConfirmAuditorProps {
}
class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
addDone: StateHolder<boolean> = this.makeState(false);
private addDone: StateHolder<boolean> = this.makeState(false);
constructor() {
super();
}
async add() {
let currencies = await getCurrencies();
let currency: CurrencyRecord|undefined = undefined;
const currencies = await getCurrencies();
let currency: CurrencyRecord|undefined;
for (let c of currencies) {
if (c.name == this.props.currency) {
for (const c of currencies) {
if (c.name === this.props.currency) {
currency = c;
}
}
@ -70,12 +70,16 @@ class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
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;
for (let idx in currency.auditors) {
let a = currency.auditors[idx];
if (a.baseUrl == this.props.url) {
for (const idx in currency.auditors) {
const a = currency.auditors[idx];
if (a.baseUrl === this.props.url) {
auditorFound = true;
// Update auditor if already found by URL.
currency.auditors[idx] = newAuditor;
@ -99,22 +103,30 @@ class ConfirmAuditor extends ImplicitStateComponent<ConfirmAuditorProps> {
return (
<div id="main">
<p>Do you want to let <strong>{this.props.auditorPub}</strong> audit the currency "{this.props.currency}"?</p>
{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>
<button onClick={() => this.add()} className="pure-button pure-button-primary">Yes</button>
<button onClick={() => this.back()} className="pure-button">No</button>
</div>)
{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>
<button onClick={() => this.add()} className="pure-button pure-button-primary">Yes</button>
<button onClick={() => this.back()} className="pure-button">No</button>
</div>
)
}
</div>
);
}
}
export function main() {
function main() {
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 currency: string = query.currency;
const auditorPub: string = query.auditorPub;

View File

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

View File

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

View File

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