aboutsummaryrefslogtreecommitdiff
path: root/src/webex
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2020-04-07 13:37:32 +0530
committerFlorian Dold <florian.dold@gmail.com>2020-04-07 13:37:32 +0530
commitfb2e2f89935240666de66e4b2c11125cb3b2943d (patch)
tree7b7e148e6cce7bf7639a5e35102f5269f5920ab5 /src/webex
parent1471aae8927c20d646cc2aa5ab0e20c1a7f2c0ca (diff)
downloadwallet-core-fb2e2f89935240666de66e4b2c11125cb3b2943d.tar.xz
more lint fixes
Diffstat (limited to 'src/webex')
-rw-r--r--src/webex/compat.ts2
-rw-r--r--src/webex/i18n.tsx12
-rw-r--r--src/webex/messages.ts20
-rw-r--r--src/webex/pageEntryPoint.ts2
-rw-r--r--src/webex/pages/add-auditor.tsx4
-rw-r--r--src/webex/pages/auditors.tsx21
-rw-r--r--src/webex/pages/pay.tsx2
-rw-r--r--src/webex/pages/payback.tsx2
-rw-r--r--src/webex/pages/popup.tsx26
-rw-r--r--src/webex/pages/refund.tsx6
-rw-r--r--src/webex/pages/reset-required.tsx8
-rw-r--r--src/webex/pages/return-coins.tsx5
-rw-r--r--src/webex/pages/tip.tsx19
-rw-r--r--src/webex/pages/welcome.tsx4
-rw-r--r--src/webex/pages/withdraw.tsx23
-rw-r--r--src/webex/renderHtml.tsx68
16 files changed, 106 insertions, 118 deletions
diff --git a/src/webex/compat.ts b/src/webex/compat.ts
index f1a68f33e..1cbf34a2c 100644
--- a/src/webex/compat.ts
+++ b/src/webex/compat.ts
@@ -30,6 +30,6 @@ export function isFirefox(): boolean {
/**
* Check if we are running under nodejs.
*/
-export function isNode() {
+export function isNode(): boolean {
return typeof process !== "undefined" && process.release.name === "node";
}
diff --git a/src/webex/i18n.tsx b/src/webex/i18n.tsx
index ed6fe868f..3f23267d5 100644
--- a/src/webex/i18n.tsx
+++ b/src/webex/i18n.tsx
@@ -57,7 +57,7 @@ function setupJed(): any {
/**
* Convert template strings to a msgid
*/
-function toI18nString(stringSeq: ReadonlyArray<string>) {
+function toI18nString(stringSeq: ReadonlyArray<string>): string {
let s = "";
for (let i = 0; i < stringSeq.length; i++) {
s += stringSeq[i];
@@ -71,7 +71,7 @@ function toI18nString(stringSeq: ReadonlyArray<string>) {
/**
* Internationalize a string template with arbitrary serialized values.
*/
-export function str(stringSeq: TemplateStringsArray, ...values: any[]) {
+export function str(stringSeq: TemplateStringsArray, ...values: any[]): string {
const s = toI18nString(stringSeq);
const tr = jed
.translate(s)
@@ -226,8 +226,8 @@ export class TranslatePlural extends React.Component<
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);
}
}
@@ -267,8 +267,8 @@ export class TranslateSingular extends React.Component<
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);
}
}
diff --git a/src/webex/messages.ts b/src/webex/messages.ts
index b695b4ab6..19d125a89 100644
--- a/src/webex/messages.ts
+++ b/src/webex/messages.ts
@@ -23,7 +23,6 @@
import { AmountJson } from "../util/amounts";
import * as dbTypes from "../types/dbTypes";
-import * as talerTypes from "../types/talerTypes";
import * as walletTypes from "../types/walletTypes";
import { UpgradeResponse } from "./wxApi";
@@ -172,22 +171,3 @@ export interface MessageMap {
*/
export type MessageType = keyof MessageMap;
-/**
- * Make a request whose details match the request type.
- */
-export function makeRequest<T extends MessageType>(
- type: T,
- details: MessageMap[T]["request"],
-) {
- return { type, details };
-}
-
-/**
- * Make a response that matches the request type.
- */
-export function makeResponse<T extends MessageType>(
- type: T,
- response: MessageMap[T]["response"],
-) {
- return response;
-}
diff --git a/src/webex/pageEntryPoint.ts b/src/webex/pageEntryPoint.ts
index 04e3dd8d1..dd9c13031 100644
--- a/src/webex/pageEntryPoint.ts
+++ b/src/webex/pageEntryPoint.ts
@@ -25,7 +25,7 @@ import { createPopup } from "./pages/popup";
import { createWithdrawPage } from "./pages/withdraw";
import { createWelcomePage } from "./pages/welcome";
-function main() {
+function main(): void {
try {
let mainElement;
const m = location.pathname.match(/([^/]+)$/);
diff --git a/src/webex/pages/add-auditor.tsx b/src/webex/pages/add-auditor.tsx
index fc7de920f..c28d15cad 100644
--- a/src/webex/pages/add-auditor.tsx
+++ b/src/webex/pages/add-auditor.tsx
@@ -91,9 +91,7 @@ function ConfirmAuditor(props: ConfirmAuditorProps): JSX.Element {
{addDone ? (
<div>
Auditor was added! You can also{" "}
- <a href={chrome.extension.getURL("/auditors.html")}>
- view and edit
- </a>{" "}
+ <a href={chrome.extension.getURL("/auditors.html")}>view and edit</a>{" "}
auditors.
</div>
) : (
diff --git a/src/webex/pages/auditors.tsx b/src/webex/pages/auditors.tsx
index e933aeace..ac93afd31 100644
--- a/src/webex/pages/auditors.tsx
+++ b/src/webex/pages/auditors.tsx
@@ -29,7 +29,6 @@ import {
import { getCurrencies, updateCurrency } from "../wxApi";
import * as React from "react";
-import * as ReactDOM from "react-dom";
interface CurrencyListState {
currencies?: CurrencyRecord[];
@@ -49,13 +48,16 @@ class CurrencyList extends React.Component<{}, CurrencyListState> {
this.state = {} as any;
}
- async update() {
+ async update(): Promise<void> {
const currencies = await getCurrencies();
console.log("currencies: ", currencies);
this.setState({ currencies });
}
- async confirmRemoveAuditor(c: CurrencyRecord, a: AuditorRecord) {
+ async confirmRemoveAuditor(
+ c: CurrencyRecord,
+ a: AuditorRecord,
+ ): Promise<void> {
if (
window.confirm(
`Do you really want to remove auditor ${a.baseUrl} for currency ${c.name}?`,
@@ -66,7 +68,10 @@ class CurrencyList extends React.Component<{}, CurrencyListState> {
}
}
- async confirmRemoveExchange(c: CurrencyRecord, e: ExchangeForCurrencyRecord) {
+ async confirmRemoveExchange(
+ c: CurrencyRecord,
+ e: ExchangeForCurrencyRecord,
+ ): Promise<void> {
if (
window.confirm(
`Do you really want to remove exchange ${e.baseUrl} for currency ${c.name}?`,
@@ -86,7 +91,7 @@ class CurrencyList extends React.Component<{}, CurrencyListState> {
<p>Trusted Auditors:</p>
<ul>
{c.auditors.map((a) => (
- <li>
+ <li key={a.baseUrl}>
{a.baseUrl}{" "}
<button
className="pure-button button-destructive"
@@ -114,7 +119,7 @@ class CurrencyList extends React.Component<{}, CurrencyListState> {
<p>Trusted Exchanges:</p>
<ul>
{c.exchanges.map((e) => (
- <li>
+ <li key={e.baseUrl}>
{e.baseUrl}{" "}
<button
className="pure-button button-destructive"
@@ -137,7 +142,7 @@ class CurrencyList extends React.Component<{}, CurrencyListState> {
return (
<div id="main">
{currencies.map((c) => (
- <div>
+ <div key={c.name}>
<h1>Currency {c.name}</h1>
<p>Displayed with {c.fractionalDigits} fractional digits.</p>
<h2>Auditors</h2>
@@ -151,6 +156,6 @@ class CurrencyList extends React.Component<{}, CurrencyListState> {
}
}
-function makeAuditorsPage() {
+export function makeAuditorsPage(): JSX.Element {
return <CurrencyList />;
}
diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx
index e3dd630b6..61f287708 100644
--- a/src/webex/pages/pay.tsx
+++ b/src/webex/pages/pay.tsx
@@ -47,7 +47,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element {
setPayStatus(p);
};
doFetch();
- }, [numTries]);
+ }, [numTries, talerPayUri]);
if (!payStatus) {
return <span>Loading payment information ...</span>;
diff --git a/src/webex/pages/payback.tsx b/src/webex/pages/payback.tsx
index 9c53aac91..5d42f5f47 100644
--- a/src/webex/pages/payback.tsx
+++ b/src/webex/pages/payback.tsx
@@ -25,6 +25,6 @@
*/
import * as React from "react";
-export function makePaybackPage() {
+export function makePaybackPage(): JSX.Element {
return <div>not implemented</div>;
}
diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx
index f62f64b73..cdb09d444 100644
--- a/src/webex/pages/popup.tsx
+++ b/src/webex/pages/popup.tsx
@@ -31,11 +31,7 @@ import * as Amounts from "../../util/amounts";
import { WalletBalance, WalletBalanceEntry } from "../../types/walletTypes";
-import {
- abbrev,
- renderAmount,
- PageLink,
-} from "../renderHtml";
+import { abbrev, renderAmount, PageLink } from "../renderHtml";
import * as wxApi from "../wxApi";
import React, { Fragment } from "react";
@@ -671,7 +667,7 @@ class WalletHistory extends React.Component<any, any> {
console.log("rendering history");
const history: HistoryEvent[] = this.myHistory;
if (this.gotError) {
- return i18n.str`Error: could not retrieve event history`;
+ return <span>i18n.str`Error: could not retrieve event history`</span>;
}
if (!history) {
@@ -734,18 +730,10 @@ function WalletDebug(props: any): JSX.Element {
return (
<div>
<p>Debug tools:</p>
- <button onClick={openExtensionPage("/popup.html")}>
- wallet tab
- </button>
- <button onClick={openExtensionPage("/benchmark.html")}>
- benchmark
- </button>
- <button onClick={openExtensionPage("/show-db.html")}>
- show db
- </button>
- <button onClick={openExtensionPage("/tree.html")}>
- show tree
- </button>
+ <button onClick={openExtensionPage("/popup.html")}>wallet tab</button>
+ <button onClick={openExtensionPage("/benchmark.html")}>benchmark</button>
+ <button onClick={openExtensionPage("/show-db.html")}>show db</button>
+ <button onClick={openExtensionPage("/tree.html")}>show tree</button>
<br />
<button onClick={confirmReset}>reset</button>
<button onClick={reload}>reload chrome extension</button>
@@ -788,4 +776,4 @@ function WalletPopup(): JSX.Element {
export function createPopup(): JSX.Element {
chrome.runtime.connect({ name: "popup" });
return <WalletPopup />;
-} \ No newline at end of file
+}
diff --git a/src/webex/pages/refund.tsx b/src/webex/pages/refund.tsx
index 4a13317cd..621a286bb 100644
--- a/src/webex/pages/refund.tsx
+++ b/src/webex/pages/refund.tsx
@@ -47,7 +47,7 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
}
};
doFetch();
- }, []);
+ }, [props.talerRefundUri]);
console.log("rendering");
@@ -63,7 +63,7 @@ function RefundStatusView(props: { talerRefundUri: string }): JSX.Element {
<>
<h2>Refund Status</h2>
<p>
- The product <em>{purchaseDetails.contractTerms.summary!}</em> has
+ The product <em>{purchaseDetails.contractTerms.summary}</em> has
received a total refund of{" "}
<AmountView amount={purchaseDetails.totalRefundAmount} />.
</p>
@@ -77,7 +77,7 @@ export function createRefundPage(): JSX.Element {
const container = document.getElementById("container");
if (!container) {
- throw Error("fatal: can't mount component, container missing")
+ throw Error("fatal: can't mount component, container missing");
}
const talerRefundUri = url.searchParams.get("talerRefundUri");
diff --git a/src/webex/pages/reset-required.tsx b/src/webex/pages/reset-required.tsx
index e58243b34..9e40e7981 100644
--- a/src/webex/pages/reset-required.tsx
+++ b/src/webex/pages/reset-required.tsx
@@ -42,17 +42,17 @@ class ResetNotification extends React.Component<any, State> {
this.state = { checked: false, resetRequired: true };
setInterval(() => this.update(), 500);
}
- async update() {
+ async update(): Promise<void> {
const res = await wxApi.checkUpgrade();
this.setState({ resetRequired: res.dbResetRequired });
}
- render() {
+ render(): JSX.Element {
if (this.state.resetRequired) {
return (
<div>
<h1>Manual Reset Reqired</h1>
<p>
- The wallet's database in your browser is incompatible with the{" "}
+ The wallet&apos;s database in your browser is incompatible with the{" "}
currently installed wallet. Please reset manually.
</p>
<p>
@@ -88,6 +88,6 @@ class ResetNotification extends React.Component<any, State> {
}
}
-export function createResetRequiredPage() {
+export function createResetRequiredPage(): JSX.Element {
return <ResetNotification />;
}
diff --git a/src/webex/pages/return-coins.tsx b/src/webex/pages/return-coins.tsx
index 7d759705f..ccdb6db53 100644
--- a/src/webex/pages/return-coins.tsx
+++ b/src/webex/pages/return-coins.tsx
@@ -290,8 +290,9 @@ class ReturnCoins extends React.Component<{}, ReturnCoinsState> {
<div id="main">
<h1>Wire electronic cash back to own bank account</h1>
<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.
+ You can send coins back into your own bank account. Note that
+ you&apos;re acting as a merchant when doing this, and thus the same
+ fees apply.
</p>
{this.state.lastConfirmedDetail ? (
<p className="okaybox">
diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx
index 9c797f50d..4a1d3743a 100644
--- a/src/webex/pages/tip.tsx
+++ b/src/webex/pages/tip.tsx
@@ -25,10 +25,7 @@ import * as React from "react";
import { acceptTip, getTipStatus } from "../wxApi";
-import {
- renderAmount,
- ProgressButton,
-} from "../renderHtml";
+import { renderAmount, ProgressButton } from "../renderHtml";
import { useState, useEffect } from "react";
import { TipStatus } from "../../types/walletTypes";
@@ -45,7 +42,7 @@ function TipDisplay(props: { talerTipUri: string }): JSX.Element {
setTipStatus(ts);
};
doFetch();
- }, []);
+ }, [props.talerTipUri]);
if (discarded) {
return <span>You&apos;ve discarded the tip.</span>;
@@ -96,11 +93,11 @@ function TipDisplay(props: { talerTipUri: string }): JSX.Element {
}
export function createTipPage(): JSX.Element {
- const url = new URL(document.location.href);
- const talerTipUri = url.searchParams.get("talerTipUri");
- if (typeof talerTipUri !== "string") {
- throw Error("talerTipUri must be a string");
- }
+ const url = new URL(document.location.href);
+ const talerTipUri = url.searchParams.get("talerTipUri");
+ if (typeof talerTipUri !== "string") {
+ throw Error("talerTipUri must be a string");
+ }
- return <TipDisplay talerTipUri={talerTipUri} />;
+ return <TipDisplay talerTipUri={talerTipUri} />;
}
diff --git a/src/webex/pages/welcome.tsx b/src/webex/pages/welcome.tsx
index a99cadb05..eecbe2be5 100644
--- a/src/webex/pages/welcome.tsx
+++ b/src/webex/pages/welcome.tsx
@@ -69,7 +69,7 @@ function Diagnostics(): JSX.Element {
<p>Problems detected:</p>
<ol>
{diagnostics.errors.map((errMsg) => (
- <li>{errMsg}</li>
+ <li key={errMsg}>{errMsg}</li>
))}
</ol>
{diagnostics.firefoxIdbProblem ? (
@@ -112,4 +112,4 @@ function Welcome(): JSX.Element {
export function createWelcomePage(): JSX.Element {
return <Welcome />;
-} \ No newline at end of file
+}
diff --git a/src/webex/pages/withdraw.tsx b/src/webex/pages/withdraw.tsx
index 9020ddb0b..efd0adc86 100644
--- a/src/webex/pages/withdraw.tsx
+++ b/src/webex/pages/withdraw.tsx
@@ -30,7 +30,9 @@ import { WithdrawDetailView, renderAmount } from "../renderHtml";
import React, { useState, useEffect } from "react";
import { getWithdrawDetails, acceptWithdrawal } from "../wxApi";
-function NewExchangeSelection(props: { talerWithdrawUri: string }): JSX.Element {
+function NewExchangeSelection(props: {
+ talerWithdrawUri: string;
+}): JSX.Element {
const [details, setDetails] = useState<WithdrawDetails | undefined>();
const [selectedExchange, setSelectedExchange] = useState<
string | undefined
@@ -63,7 +65,7 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }): JSX.Element
setDetails(d);
};
fetchData();
- }, [selectedExchange, errMsg, selecting]);
+ }, [selectedExchange, errMsg, selecting, talerWithdrawUri]);
if (errMsg) {
return (
@@ -145,8 +147,11 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }): JSX.Element
}
const accept = async (): Promise<void> => {
+ if (!selectedExchange) {
+ throw Error("can't accept, no exchange selected");
+ }
console.log("accepting exchange", selectedExchange);
- const res = await acceptWithdrawal(talerWithdrawUri, selectedExchange!);
+ const res = await acceptWithdrawal(talerWithdrawUri, selectedExchange);
console.log("accept withdrawal response", res);
if (res.confirmTransferUrl) {
document.location.href = res.confirmTransferUrl;
@@ -198,9 +203,9 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }): JSX.Element
export function createWithdrawPage(): JSX.Element {
const url = new URL(document.location.href);
- const talerWithdrawUri = url.searchParams.get("talerWithdrawUri");
- if (!talerWithdrawUri) {
- throw Error("withdraw URI required");
- }
- return <NewExchangeSelection talerWithdrawUri={talerWithdrawUri} />;
-} \ No newline at end of file
+ const talerWithdrawUri = url.searchParams.get("talerWithdrawUri");
+ if (!talerWithdrawUri) {
+ throw Error("withdraw URI required");
+ }
+ return <NewExchangeSelection talerWithdrawUri={talerWithdrawUri} />;
+}
diff --git a/src/webex/renderHtml.tsx b/src/webex/renderHtml.tsx
index f5a6a7e4d..b1363abfb 100644
--- a/src/webex/renderHtml.tsx
+++ b/src/webex/renderHtml.tsx
@@ -127,6 +127,37 @@ export class Collapsible extends React.Component<
}
}
+function WireFee(props: {
+ s: string;
+ rci: ExchangeWithdrawDetails;
+}): JSX.Element {
+ return (
+ <>
+ <thead>
+ <tr>
+ <th colSpan={3}>Wire Method {props.s}</th>
+ </tr>
+ <tr>
+ <th>Applies Until</th>
+ <th>Wire Fee</th>
+ <th>Closing Fee</th>
+ </tr>
+ </thead>
+ ,
+ <tbody>
+ {props.rci.wireFees.feesForType[props.s].map((f) => (
+ <tr key={f.sig}>
+ <td>{stringifyTimestamp(f.endStamp)}</td>
+ <td>{renderAmount(f.wireFee)}</td>
+ <td>{renderAmount(f.closingFee)}</td>
+ </tr>
+ ))}
+ </tbody>
+ ,
+ </>
+ );
+}
+
function AuditorDetailsView(props: {
rci: ExchangeWithdrawDetails | null;
}): JSX.Element {
@@ -145,7 +176,7 @@ function AuditorDetailsView(props: {
return (
<div>
{(rci.exchangeInfo.details?.auditors ?? []).map((a) => (
- <div>
+ <div key={a.auditor_pub}>
<h3>Auditor {a.auditor_url}</h3>
<p>
Public key: <ExpanderText text={a.auditor_pub} />
@@ -202,30 +233,6 @@ function FeeDetailsView(props: {
);
}
- function wireFee(s: string) {
- return [
- <thead>
- <tr>
- <th colSpan={3}>Wire Method {s}</th>
- </tr>
- <tr>
- <th>Applies Until</th>
- <th>Wire Fee</th>
- <th>Closing Fee</th>
- </tr>
- </thead>,
- <tbody>
- {rci!.wireFees.feesForType[s].map((f) => (
- <tr>
- <td>{stringifyTimestamp(f.endStamp)}</td>
- <td>{renderAmount(f.wireFee)}</td>
- <td>{renderAmount(f.closingFee)}</td>
- </tr>
- ))}
- </tbody>,
- ];
- }
-
const withdrawFee = renderAmount(rci.withdrawFee);
const overhead = renderAmount(rci.overhead);
@@ -265,7 +272,9 @@ function FeeDetailsView(props: {
<h3>Wire Fees</h3>
<div style={{ overflow: "auto" }}>
<table className="pure-table">
- {Object.keys(rci.wireFees.feesForType).map(wireFee)}
+ {Object.keys(rci.wireFees.feesForType).map((s) => (
+ <WireFee key={s} s={s} rci={rci} />
+ ))}
</table>
</div>
</div>
@@ -337,7 +346,12 @@ export function PageLink(
): JSX.Element {
const url = chrome.extension.getURL(`/${props.pageName}`);
return (
- <a className="actionLink" href={url} target="_blank" rel="noopener noreferrer">
+ <a
+ className="actionLink"
+ href={url}
+ target="_blank"
+ rel="noopener noreferrer"
+ >
{props.children}
</a>
);