/*
This file is part of TALER
(C) 2016 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
TALER; see the file COPYING. If not, see
*/
/**
* Popup shown to the user when they click
* the Taler browser action button.
*
* @author Florian Dold
*/
/**
* Imports.
*/
import * as i18n from "../i18n";
import {
AmountJson,
Amounts,
BalancesResponse,
Balance,
classifyTalerUri,
TalerUriType,
TransactionsResponse,
Transaction,
TransactionType,
AmountString,
Timestamp,
amountFractionalBase,
} from "@gnu-taler/taler-util";
import { abbrev, renderAmount, PageLink } from "../renderHtml";
import * as wxApi from "../wxApi";
import React, { Fragment, useState, useEffect } from "react";
import moment from "moment";
import { PermissionsCheckbox } from "./welcome";
// FIXME: move to newer react functions
/* eslint-disable react/no-deprecated */
class Router extends React.Component {
static setRoute(s: string): void {
window.location.hash = s;
}
static getRoute(): string {
// Omit the '#' at the beginning
return window.location.hash.substring(1);
}
static onRoute(f: any): () => void {
Router.routeHandlers.push(f);
return () => {
const i = Router.routeHandlers.indexOf(f);
this.routeHandlers = this.routeHandlers.splice(i, 1);
};
}
private static routeHandlers: any[] = [];
componentWillMount(): void {
console.log("router mounted");
window.onhashchange = () => {
this.setState({});
for (const f of Router.routeHandlers) {
f();
}
};
}
render(): JSX.Element {
const route = window.location.hash.substring(1);
console.log("rendering route", route);
let defaultChild: React.ReactChild | null = null;
let foundChild: React.ReactChild | null = null;
React.Children.forEach(this.props.children, (child) => {
const childProps: any = (child as any).props;
if (!childProps) {
return;
}
if (childProps.default) {
defaultChild = child as React.ReactChild;
}
if (childProps.route === route) {
foundChild = child as React.ReactChild;
}
});
const c: React.ReactChild | null = foundChild || defaultChild;
if (!c) {
throw Error("unknown route");
}
Router.setRoute((c as any).props.route);
return