diff options
Diffstat (limited to 'src/webex/pages')
-rw-r--r-- | src/webex/pages/add-auditor.tsx | 4 | ||||
-rw-r--r-- | src/webex/pages/benchmark.tsx | 10 | ||||
-rw-r--r-- | src/webex/pages/pay.tsx | 10 | ||||
-rw-r--r-- | src/webex/pages/popup.tsx | 68 | ||||
-rw-r--r-- | src/webex/pages/refund.tsx | 13 | ||||
-rw-r--r-- | src/webex/pages/return-coins.tsx | 17 | ||||
-rw-r--r-- | src/webex/pages/tip.tsx | 19 | ||||
-rw-r--r-- | src/webex/pages/welcome.tsx | 8 | ||||
-rw-r--r-- | src/webex/pages/withdraw.tsx | 29 |
9 files changed, 65 insertions, 113 deletions
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<void> => { 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) => ( - <tr> + <tr key={k}> <td>{k}</td> <td>{result.time[k] / result.repetitions}</td> </tr> @@ -75,13 +75,13 @@ class BenchmarkRunner extends React.Component<any, BenchmarkRunnerState> { }; } - async run() { + async run(): Promise<void> { this.setState({ result: undefined, running: true }); const result = await wxApi.benchmarkCrypto(this.state.repetitions); this.setState({ result, running: false }); } - render() { + render(): JSX.Element { return ( <div> <label>Repetitions:</label> @@ -99,6 +99,6 @@ class BenchmarkRunner extends React.Component<any, BenchmarkRunnerState> { } } -export function makeBenchmarkPage() { +export function makeBenchmarkPage(): JSX.Element { return <BenchmarkRunner />; } 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<PreparePayResult | undefined>(); const [payErrMsg, setPayErrMsg] = useState<string | undefined>(""); 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<void> => { const p = await wxApi.preparePay(talerPayUri); setPayStatus(p); }; @@ -108,7 +108,7 @@ function TalerPayDialog({ talerPayUri }: { talerPayUri: string }) { <strong>{renderAmount(Amounts.parseOrThrow(contractTerms.amount))}</strong> ); - const doPayment = async () => { + const doPayment = async (): Promise<void> => { 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 <TalerPayDialog talerPayUri={talerPayUri} />; -}
\ 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<any, any> { private static routeHandlers: any[] = []; - componentWillMount() { + componentWillMount(): void { console.log("router mounted"); window.onhashchange = () => { this.setState({}); @@ -85,10 +85,6 @@ class Router extends React.Component<any, any> { }; } - 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<HTMLAnchorElement>) => { + const onClick = (e: React.MouseEvent<HTMLAnchorElement>): void => { Router.setRoute(props.target); e.preventDefault(); }; @@ -139,19 +135,19 @@ function Tab(props: TabProps) { class WalletNavBar extends React.Component<any, any> { 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 ( <div className="nav" id="header"> @@ -163,20 +159,6 @@ class WalletNavBar extends React.Component<any, any> { } } -function ExtensionLink(props: any) { - const onClick = (e: React.MouseEvent<HTMLAnchorElement>) => { - chrome.tabs.create({ - url: chrome.extension.getURL(props.target), - }); - e.preventDefault(); - }; - return ( - <a onClick={onClick} href={props.target}> - {props.children} - </a> - ); -} - /** * Render an amount as a large number with a small currency symbol. */ @@ -190,7 +172,7 @@ function bigAmount(amount: AmountJson): JSX.Element { ); } -function EmptyBalanceView() { +function EmptyBalanceView(): JSX.Element { return ( <i18n.Translate wrap="p"> You have no balance to show. Need some{" "} @@ -205,12 +187,12 @@ class WalletBalanceView extends React.Component<any, any> { private canceler: (() => void) | undefined = undefined; private unmount = false; - componentWillMount() { + componentWillMount(): void { this.canceler = onUpdateNotification(() => this.updateBalance()); this.updateBalance(); } - componentWillUnmount() { + componentWillUnmount(): void { console.log("component WalletBalanceView will unmount"); if (this.canceler) { this.canceler(); @@ -218,7 +200,7 @@ class WalletBalanceView extends React.Component<any, any> { this.unmount = true; } - async updateBalance() { + async updateBalance(): Promise<void> { let balance: WalletBalance; try { balance = await wxApi.getBalance(); @@ -325,11 +307,11 @@ class WalletBalanceView extends React.Component<any, any> { } } -function Icon({ l }: { l: string }) { +function Icon({ l }: { l: string }): JSX.Element { return <div className={"icon"}>{l}</div>; } -function formatAndCapitalize(text: string) { +function formatAndCapitalize(text: string): string { text = text.replace("-", " "); text = text.replace(/^./, text[0].toUpperCase()); return text; @@ -357,8 +339,8 @@ function HistoryItem({ timestamp, icon, negative = false, -}: HistoryItemProps) { - function formatDate(timestamp: number | "never") { +}: HistoryItemProps): JSX.Element { + function formatDate(timestamp: number | "never"): string | null { if (timestamp !== "never") { const itemDate = moment(timestamp); if (itemDate.isBetween(moment().subtract(2, "days"), moment())) { @@ -444,7 +426,7 @@ function parseSummary(summary: string) { }; } -function formatHistoryItem(historyItem: HistoryEvent) { +function formatHistoryItem(historyItem: HistoryEvent): JSX.Element { switch (historyItem.type) { case "refreshed": { return ( @@ -637,7 +619,7 @@ function formatHistoryItem(historyItem: HistoryEvent) { } } -const HistoryComponent = (props: any) => { +const HistoryComponent = (props: any): JSX.Element => { const record = props.record; return formatHistoryItem(record); }; @@ -655,18 +637,18 @@ class WalletHistory extends React.Component<any, any> { "exchange-added", ]; - componentWillMount() { + componentWillMount(): void { this.update(); this.setState({ filter: true }); onUpdateNotification(() => this.update()); } - componentWillUnmount() { + componentWillUnmount(): void { console.log("history component unmounted"); this.unmounted = true; } - update() { + update(): void { chrome.runtime.sendMessage({ type: "get-history" }, (resp) => { if (this.unmounted) { return; @@ -727,7 +709,7 @@ class WalletHistory extends React.Component<any, any> { } } -function reload() { +function reload(): void { try { chrome.runtime.reload(); window.close(); @@ -736,7 +718,7 @@ function reload() { } } -function confirmReset() { +function confirmReset(): void { if ( confirm( "Do you want to IRREVOCABLY DESTROY everything inside your" + @@ -748,7 +730,7 @@ function confirmReset() { } } -function WalletDebug(props: any) { +function WalletDebug(props: any): JSX.Element { return ( <div> <p>Debug tools:</p> @@ -791,7 +773,7 @@ function openTab(page: string) { }; } -function WalletPopup() { +function WalletPopup(): JSX.Element { return ( <div> <WalletNavBar /> @@ -806,7 +788,7 @@ function WalletPopup() { ); } -export function createPopup() { +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 8263ceace..4a13317cd 100644 --- a/src/webex/pages/refund.tsx +++ b/src/webex/pages/refund.tsx @@ -21,13 +21,12 @@ */ import React, { useEffect, useState } from "react"; -import ReactDOM from "react-dom"; import * as wxApi from "../wxApi"; import { PurchaseDetails } from "../../types/walletTypes"; import { AmountView } from "../renderHtml"; -function RefundStatusView(props: { talerRefundUri: string }) { +function RefundStatusView(props: { talerRefundUri: string }): JSX.Element { const [applied, setApplied] = useState(false); const [purchaseDetails, setPurchaseDetails] = useState< PurchaseDetails | undefined @@ -35,7 +34,7 @@ function RefundStatusView(props: { talerRefundUri: string }) { const [errMsg, setErrMsg] = useState<string | undefined>(undefined); useEffect(() => { - const doFetch = async () => { + const doFetch = async (): Promise<void> => { try { const hc = await wxApi.applyRefund(props.talerRefundUri); setApplied(true); @@ -73,19 +72,17 @@ function RefundStatusView(props: { talerRefundUri: string }) { ); } -export function createRefundPage() { +export function createRefundPage(): JSX.Element { const url = new URL(document.location.href); const container = document.getElementById("container"); if (!container) { - console.error("fatal: can't mount component, container missing"); - return; + throw Error("fatal: can't mount component, container missing") } const talerRefundUri = url.searchParams.get("talerRefundUri"); if (!talerRefundUri) { - console.error("taler refund URI requred"); - return; + throw Error("taler refund URI requred"); } return <RefundStatusView talerRefundUri={talerRefundUri} />; diff --git a/src/webex/pages/return-coins.tsx b/src/webex/pages/return-coins.tsx index 06a3ba169..7d759705f 100644 --- a/src/webex/pages/return-coins.tsx +++ b/src/webex/pages/return-coins.tsx @@ -38,7 +38,6 @@ import { getBalance, getSenderWireInfos, returnCoins } from "../wxApi"; import { renderAmount } from "../renderHtml"; import * as React from "react"; -import * as ReactDOM from "react-dom"; interface ReturnSelectionItemProps extends ReturnSelectionListProps { exchangeUrl: string; @@ -129,7 +128,7 @@ class ReturnSelectionItem extends React.Component< ); } - select() { + select(): void { let val: number; let selectedWire: number; try { @@ -188,7 +187,7 @@ interface ReturnConfirmationProps { } class ReturnConfirmation extends React.Component<ReturnConfirmationProps, {}> { - render() { + render(): JSX.Element { return ( <div> <p> @@ -238,7 +237,7 @@ class ReturnCoins extends React.Component<{}, ReturnCoinsState> { this.state = {} as any; } - async update() { + async update(): Promise<void> { const balance = await getBalance(); const senderWireInfos = await getSenderWireInfos(); console.log("got swi", senderWireInfos); @@ -246,11 +245,11 @@ class ReturnCoins extends React.Component<{}, ReturnCoinsState> { this.setState({ balance, senderWireInfos }); } - selectDetail(d: SelectedDetail) { + selectDetail(d: SelectedDetail): void { this.setState({ selectedReturn: d }); } - async confirm() { + async confirm(): Promise<void> { const selectedReturn = this.state.selectedReturn; if (!selectedReturn) { return; @@ -263,14 +262,14 @@ class ReturnCoins extends React.Component<{}, ReturnCoinsState> { }); } - async cancel() { + async cancel(): Promise<void> { this.setState({ selectedReturn: undefined, lastConfirmedDetail: undefined, }); } - render() { + render(): JSX.Element { const balance = this.state.balance; const senderWireInfos = this.state.senderWireInfos; if (!balance || !senderWireInfos) { @@ -310,6 +309,6 @@ class ReturnCoins extends React.Component<{}, ReturnCoinsState> { } } -export function createReturnCoinsPage() { +export function createReturnCoinsPage(): JSX.Element { return <ReturnCoins />; } diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx index 10e12d590..9c797f50d 100644 --- a/src/webex/pages/tip.tsx +++ b/src/webex/pages/tip.tsx @@ -22,30 +22,25 @@ */ import * as React from "react"; -import * as ReactDOM from "react-dom"; -import * as i18n from "../i18n"; - -import { acceptTip, getReserveCreationInfo, getTipStatus } from "../wxApi"; +import { acceptTip, getTipStatus } from "../wxApi"; import { - WithdrawDetailView, renderAmount, ProgressButton, } from "../renderHtml"; -import * as Amounts from "../../util/amounts"; import { useState, useEffect } from "react"; import { TipStatus } from "../../types/walletTypes"; -function TipDisplay(props: { talerTipUri: string }) { +function TipDisplay(props: { talerTipUri: string }): JSX.Element { const [tipStatus, setTipStatus] = useState<TipStatus | undefined>(undefined); const [discarded, setDiscarded] = useState(false); const [loading, setLoading] = useState(false); const [finished, setFinished] = useState(false); useEffect(() => { - const doFetch = async () => { + const doFetch = async (): Promise<void> => { const ts = await getTipStatus(props.talerTipUri); setTipStatus(ts); }; @@ -53,7 +48,7 @@ function TipDisplay(props: { talerTipUri: string }) { }, []); if (discarded) { - return <span>You've discarded the tip.</span>; + return <span>You've discarded the tip.</span>; } if (finished) { @@ -64,11 +59,11 @@ function TipDisplay(props: { talerTipUri: string }) { return <span>Loading ...</span>; } - const discard = () => { + const discard = (): void => { setDiscarded(true); }; - const accept = async () => { + const accept = async (): Promise<void> => { setLoading(true); await acceptTip(tipStatus.tipId); setFinished(true); @@ -100,7 +95,7 @@ function TipDisplay(props: { talerTipUri: string }) { ); } -export function createTipPage() { +export function createTipPage(): JSX.Element { const url = new URL(document.location.href); const talerTipUri = url.searchParams.get("talerTipUri"); if (typeof talerTipUri !== "string") { diff --git a/src/webex/pages/welcome.tsx b/src/webex/pages/welcome.tsx index 8510ad383..a99cadb05 100644 --- a/src/webex/pages/welcome.tsx +++ b/src/webex/pages/welcome.tsx @@ -25,7 +25,7 @@ import { getDiagnostics } from "../wxApi"; import { PageLink } from "../renderHtml"; import { WalletDiagnostics } from "../../types/walletTypes"; -function Diagnostics() { +function Diagnostics(): JSX.Element { const [timedOut, setTimedOut] = useState(false); const [diagnostics, setDiagnostics] = useState<WalletDiagnostics | undefined>( undefined, @@ -39,7 +39,7 @@ function Diagnostics() { setTimedOut(true); } }, 1000); - const doFetch = async () => { + const doFetch = async (): Promise<void> => { const d = await getDiagnostics(); console.log("got diagnostics", d); gotDiagnostics = true; @@ -95,7 +95,7 @@ function Diagnostics() { return <p>Running diagnostics ...</p>; } -function Welcome() { +function Welcome(): JSX.Element { return ( <> <p>Thank you for installing the wallet.</p> @@ -110,6 +110,6 @@ function Welcome() { ); } -export function createWelcomePage() { +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 e071dc8ba..9020ddb0b 100644 --- a/src/webex/pages/withdraw.tsx +++ b/src/webex/pages/withdraw.tsx @@ -28,10 +28,9 @@ import { WithdrawDetails } from "../../types/walletTypes"; import { WithdrawDetailView, renderAmount } from "../renderHtml"; import React, { useState, useEffect } from "react"; -import * as ReactDOM from "react-dom"; import { getWithdrawDetails, acceptWithdrawal } from "../wxApi"; -function NewExchangeSelection(props: { talerWithdrawUri: string }) { +function NewExchangeSelection(props: { talerWithdrawUri: string }): JSX.Element { const [details, setDetails] = useState<WithdrawDetails | undefined>(); const [selectedExchange, setSelectedExchange] = useState< string | undefined @@ -43,7 +42,7 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }) { const [errMsg, setErrMsg] = useState<string | undefined>(""); useEffect(() => { - const fetchData = async () => { + const fetchData = async (): Promise<void> => { console.log("getting from", talerWithdrawUri); let d: WithdrawDetails | undefined = undefined; try { @@ -145,7 +144,7 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }) { ); } - const accept = async () => { + const accept = async (): Promise<void> => { console.log("accepting exchange", selectedExchange); const res = await acceptWithdrawal(talerWithdrawUri, selectedExchange!); console.log("accept withdrawal response", res); @@ -197,27 +196,7 @@ function NewExchangeSelection(props: { talerWithdrawUri: string }) { ); } -async function main() { - try { - const url = new URL(document.location.href); - const talerWithdrawUri = url.searchParams.get("talerWithdrawUri"); - if (!talerWithdrawUri) { - throw Error("withdraw URI required"); - } - - ReactDOM.render( - <NewExchangeSelection talerWithdrawUri={talerWithdrawUri} />, - document.getElementById("exchange-selection")!, - ); - } catch (e) { - // TODO: provide more context information, maybe factor it out into a - // TODO:generic error reporting function or component. - document.body.innerText = i18n.str`Fatal error: "${e.message}".`; - console.error("got error", e); - } -} - -export function createWithdrawPage() { +export function createWithdrawPage(): JSX.Element { const url = new URL(document.location.href); const talerWithdrawUri = url.searchParams.get("talerWithdrawUri"); if (!talerWithdrawUri) { |