From 8144b0f5535c3d00c1e508cddce3cd88a153a581 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 5 Sep 2019 16:10:53 +0200 Subject: welcome page with error diagnostics / react refactoring --- src/webex/pages/add-auditor.tsx | 119 ++++++++++++++++++++-------------------- 1 file changed, 60 insertions(+), 59 deletions(-) (limited to 'src/webex/pages/add-auditor.tsx') diff --git a/src/webex/pages/add-auditor.tsx b/src/webex/pages/add-auditor.tsx index 1ab6fdf9c..7e3e06322 100644 --- a/src/webex/pages/add-auditor.tsx +++ b/src/webex/pages/add-auditor.tsx @@ -20,20 +20,11 @@ * @author Florian Dold */ - -import { - CurrencyRecord, -} from "../../dbTypes"; - -import { ImplicitStateComponent, StateHolder } from "../components"; -import { - getCurrencies, - updateCurrency, -} from "../wxApi"; - -import * as React from "react"; -import * as ReactDOM from "react-dom"; +import { CurrencyRecord } from "../../dbTypes"; +import { getCurrencies, updateCurrency } from "../wxApi"; +import React, { useState } from "react"; import URI = require("urijs"); +import { registerMountPage } from "../renderHtml"; interface ConfirmAuditorProps { url: string; @@ -42,36 +33,39 @@ interface ConfirmAuditorProps { expirationStamp: number; } -class ConfirmAuditor extends ImplicitStateComponent { - private addDone: StateHolder = this.makeState(false); - constructor(props: ConfirmAuditorProps) { - super(props); - } +function ConfirmAuditor(props: ConfirmAuditorProps) { + const [addDone, setAddDone] = useState(false); + - async add() { + const add = async() => { const currencies = await getCurrencies(); - let currency: CurrencyRecord|undefined; + let currency: CurrencyRecord | undefined; for (const c of currencies) { - if (c.name === this.props.currency) { + if (c.name === props.currency) { currency = c; } } if (!currency) { - currency = { name: this.props.currency, auditors: [], fractionalDigits: 2, exchanges: [] }; + currency = { + name: props.currency, + auditors: [], + fractionalDigits: 2, + exchanges: [], + }; } const newAuditor = { - auditorPub: this.props.auditorPub, - baseUrl: this.props.url, - expirationStamp: this.props.expirationStamp, + auditorPub: props.auditorPub, + baseUrl: props.url, + expirationStamp: props.expirationStamp, }; let auditorFound = false; for (const idx in currency.auditors) { const a = currency.auditors[idx]; - if (a.baseUrl === this.props.url) { + if (a.baseUrl === props.url) { auditorFound = true; // Update auditor if already found by URL. currency.auditors[idx] = newAuditor; @@ -84,47 +78,54 @@ class ConfirmAuditor extends ImplicitStateComponent { await updateCurrency(currency); - this.addDone(true); + setAddDone(true); } - back() { + const back = () => { window.history.back(); - } - - render(): JSX.Element { - return ( -
-

Do you want to let {this.props.auditorPub} audit the currency "{this.props.currency}"?

- {this.addDone() ? - ( -
- Auditor was added! You can also{" "} - view and edit{" "} - auditors. -
- ) - : - ( -
- - -
- ) - } -
- ); - } + }; + + return ( +
+

+ Do you want to let {props.auditorPub} audit the + currency "{props.currency}"? +

+ {addDone ? ( +
+ Auditor was added! You can also{" "} + + view and edit + {" "} + auditors. +
+ ) : ( +
+ + +
+ )} +
+ ); } -function main() { + +registerMountPage(() => { 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; const expirationStamp = Number.parseInt(query.expirationStamp); const args = { url, currency, auditorPub, expirationStamp }; - ReactDOM.render(, document.getElementById("container")!); -} - -document.addEventListener("DOMContentLoaded", main); + return ; +}); -- cgit v1.2.3