From 47787c0b0b846d5f4a057661efdd05d8786032f1 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Mon, 6 Apr 2020 23:32:01 +0530 Subject: make linter less grumpy --- src/webex/chromeBadge.ts | 22 ++++++---- src/webex/notify.ts | 16 ++++---- src/webex/pages/add-auditor.tsx | 4 +- src/webex/pages/benchmark.tsx | 10 ++--- src/webex/pages/pay.tsx | 10 ++--- src/webex/pages/popup.tsx | 68 +++++++++++------------------- src/webex/pages/refund.tsx | 13 +++--- src/webex/pages/return-coins.tsx | 17 ++++---- src/webex/pages/tip.tsx | 19 ++++----- src/webex/pages/welcome.tsx | 8 ++-- src/webex/pages/withdraw.tsx | 29 ++----------- src/webex/renderHtml.tsx | 28 +++++++------ src/webex/wxApi.ts | 11 +++-- src/webex/wxBackend.ts | 89 ++++++++++++++++++++++------------------ 14 files changed, 158 insertions(+), 186 deletions(-) (limited to 'src/webex') diff --git a/src/webex/chromeBadge.ts b/src/webex/chromeBadge.ts index 330388ca0..7bc5d368d 100644 --- a/src/webex/chromeBadge.ts +++ b/src/webex/chromeBadge.ts @@ -20,7 +20,7 @@ import { isFirefox } from "./compat"; * Polyfill for requestAnimationFrame, which * doesn't work from a background page. */ -function rAF(cb: (ts: number) => void) { +function rAF(cb: (ts: number) => void): void { window.setTimeout(() => { cb(performance.now()); }, 100 /* 100 ms delay between frames */); @@ -99,14 +99,18 @@ export class ChromeBadge { // size in draw() as well! this.canvas.width = 32; this.canvas.height = 32; - this.ctx = this.canvas.getContext("2d")!; + const ctx = this.canvas.getContext("2d"); + if (!ctx) { + throw Error("unable to get canvas context"); + } + this.ctx = ctx; this.draw(); } /** * Draw the badge based on the current state. */ - private draw() { + private draw(): void { this.ctx.setTransform(1, 0, 0, 1, 0, 0); this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); @@ -202,7 +206,7 @@ export class ChromeBadge { } } - private animate() { + private animate(): void { if (this.animationRunning) { return; } @@ -212,7 +216,7 @@ export class ChromeBadge { } this.animationRunning = true; let start: number | undefined; - const step = (timestamp: number) => { + const step = (timestamp: number): void => { if (!this.animationRunning) { return; } @@ -257,7 +261,7 @@ export class ChromeBadge { * Draw the badge such that it shows the * user that something happened (balance changed). */ - showNotification() { + showNotification(): void { this.hasNotification = true; this.draw(); } @@ -265,12 +269,12 @@ export class ChromeBadge { /** * Draw the badge without the notification mark. */ - clearNotification() { + clearNotification(): void { this.hasNotification = false; this.draw(); } - startBusy() { + startBusy(): void { if (this.isBusy) { return; } @@ -278,7 +282,7 @@ export class ChromeBadge { this.animate(); } - stopBusy() { + stopBusy(): void { this.isBusy = false; } } diff --git a/src/webex/notify.ts b/src/webex/notify.ts index 887658ef9..9fb0529db 100644 --- a/src/webex/notify.ts +++ b/src/webex/notify.ts @@ -47,7 +47,7 @@ const handlers: Handler[] = []; let sheet: CSSStyleSheet | null; -function initStyle() { +function initStyle(): void { logVerbose && console.log("taking over styles"); const name = "taler-presence-stylesheet"; const content = "/* Taler stylesheet controlled by JS */"; @@ -78,7 +78,7 @@ function initStyle() { } } -function setStyles(installed: boolean) { +function setStyles(installed: boolean): void { if (!sheet || !sheet.cssRules) { return; } @@ -93,7 +93,7 @@ function setStyles(installed: boolean) { } } -function onceOnComplete(cb: () => void) { +function onceOnComplete(cb: () => void): void { if (document.readyState === "complete") { cb(); } else { @@ -105,7 +105,7 @@ function onceOnComplete(cb: () => void) { } } -function init() { +function init(): void { onceOnComplete(() => { if (document.documentElement.getAttribute("data-taler-nojs")) { initStyle(); @@ -129,13 +129,13 @@ function init() { type HandlerFn = (detail: any, sendResponse: (msg: any) => void) => void; -function registerHandlers() { +function registerHandlers(): void { /** * Add a handler for a DOM event, which automatically * handles adding sequence numbers to responses. */ - function addHandler(type: string, handler: HandlerFn) { - const handlerWrap = (e: Event) => { + function addHandler(type: string, handler: HandlerFn): void { + const handlerWrap = (e: Event): void => { if (!(e instanceof Event)) { console.log("unexpected event", e); throw Error(`invariant violated`); @@ -154,7 +154,7 @@ function registerHandlers() { callId = e.detail.callId; detail = e.detail; } - const responder = (msg?: any) => { + const responder = (msg?: any): void => { const fullMsg = Object.assign({}, msg, { callId }); let opts = { detail: fullMsg }; if ("function" === typeof cloneInto) { diff --git a/src/webex/pages/add-auditor.tsx b/src/webex/pages/add-auditor.tsx index dbe84cde4..4e3f8615c 100644 --- a/src/webex/pages/add-auditor.tsx +++ b/src/webex/pages/add-auditor.tsx @@ -31,10 +31,10 @@ interface ConfirmAuditorProps { expirationStamp: number; } -function ConfirmAuditor(props: ConfirmAuditorProps) { +function ConfirmAuditor(props: ConfirmAuditorProps): JSX.Element { const [addDone, setAddDone] = useState(false); - const add = async () => { + const add = async (): Promise => { const currencies = await getCurrencies(); let currency: CurrencyRecord | undefined; diff --git a/src/webex/pages/benchmark.tsx b/src/webex/pages/benchmark.tsx index bf4c4b04d..eb7193e0c 100644 --- a/src/webex/pages/benchmark.tsx +++ b/src/webex/pages/benchmark.tsx @@ -34,7 +34,7 @@ interface BenchmarkRunnerState { running: boolean; } -function BenchmarkDisplay(props: BenchmarkRunnerState) { +function BenchmarkDisplay(props: BenchmarkRunnerState): JSX.Element { const result = props.result; if (!result) { if (props.running) { @@ -55,7 +55,7 @@ function BenchmarkDisplay(props: BenchmarkRunnerState) { {Object.keys(result.time) .sort() .map((k) => ( - + {k} {result.time[k] / result.repetitions} @@ -75,13 +75,13 @@ class BenchmarkRunner extends React.Component { }; } - async run() { + async run(): Promise { this.setState({ result: undefined, running: true }); const result = await wxApi.benchmarkCrypto(this.state.repetitions); this.setState({ result, running: false }); } - render() { + render(): JSX.Element { return (
@@ -99,6 +99,6 @@ class BenchmarkRunner extends React.Component { } } -export function makeBenchmarkPage() { +export function makeBenchmarkPage(): JSX.Element { return ; } diff --git a/src/webex/pages/pay.tsx b/src/webex/pages/pay.tsx index 09aa595c3..e3dd630b6 100644 --- a/src/webex/pages/pay.tsx +++ b/src/webex/pages/pay.tsx @@ -34,7 +34,7 @@ import React, { useState, useEffect } from "react"; import * as Amounts from "../../util/amounts"; import { codecForContractTerms, ContractTerms } from "../../types/talerTypes"; -function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { +function TalerPayDialog({ talerPayUri }: { talerPayUri: string }): JSX.Element { const [payStatus, setPayStatus] = useState(); const [payErrMsg, setPayErrMsg] = useState(""); const [numTries, setNumTries] = useState(0); @@ -42,7 +42,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { let totalFees: Amounts.AmountJson | undefined = undefined; useEffect(() => { - const doFetch = async () => { + const doFetch = async (): Promise => { const p = await wxApi.preparePay(talerPayUri); setPayStatus(p); }; @@ -108,7 +108,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { {renderAmount(Amounts.parseOrThrow(contractTerms.amount))} ); - const doPayment = async () => { + const doPayment = async (): Promise => { if (payStatus.status !== "payment-possible") { throw Error(`invalid state: ${payStatus.status}`); } @@ -178,11 +178,11 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { ); } -export function makePayPage() { +export function makePayPage(): JSX.Element { const url = new URL(document.location.href); const talerPayUri = url.searchParams.get("talerPayUri"); if (!talerPayUri) { throw Error("invalid parameter"); } return ; -} \ No newline at end of file +} diff --git a/src/webex/pages/popup.tsx b/src/webex/pages/popup.tsx index 6cd7242ff..c2f050e2a 100644 --- a/src/webex/pages/popup.tsx +++ b/src/webex/pages/popup.tsx @@ -46,7 +46,7 @@ import { Timestamp } from "../../util/time"; function onUpdateNotification(f: () => void): () => void { const port = chrome.runtime.connect({ name: "notifications" }); - const listener = () => { + const listener = (): void => { f(); }; port.onMessage.addListener(listener); @@ -75,7 +75,7 @@ class Router extends React.Component { private static routeHandlers: any[] = []; - componentWillMount() { + componentWillMount(): void { console.log("router mounted"); window.onhashchange = () => { this.setState({}); @@ -85,10 +85,6 @@ class Router extends React.Component { }; } - componentWillUnmount() { - console.log("router unmounted"); - } - render(): JSX.Element { const route = window.location.hash.substring(1); console.log("rendering route", route); @@ -120,12 +116,12 @@ interface TabProps { children?: React.ReactNode; } -function Tab(props: TabProps) { +function Tab(props: TabProps): JSX.Element { let cssClass = ""; if (props.target === Router.getRoute()) { cssClass = "active"; } - const onClick = (e: React.MouseEvent) => { + const onClick = (e: React.MouseEvent): void => { Router.setRoute(props.target); e.preventDefault(); }; @@ -139,19 +135,19 @@ function Tab(props: TabProps) { class WalletNavBar extends React.Component { private cancelSubscription: any; - componentWillMount() { + componentWillMount(): void { this.cancelSubscription = Router.onRoute(() => { this.setState({}); }); } - componentWillUnmount() { + componentWillUnmount(): void { if (this.cancelSubscription) { this.cancelSubscription(); } } - render() { + render(): JSX.Element { console.log("rendering nav bar"); return (