/*
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 { renderAmount, PageLink } from "../renderHtml";
import * as wxApi from "../wxApi";
import { useState, useEffect } from "preact/hooks";
import { PermissionsCheckbox } from "./welcome";
import { JSXInternal } from "preact/src/jsx";
import { Component, ComponentChild, ComponentChildren, JSX, toChildArray, VNode } from "preact";
// FIXME: move to newer react functions
class Router extends 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: ComponentChild | null = null;
let foundChild: ComponentChild | null = null;
toChildArray(this.props.children).forEach((child) => {
const childProps: any = (child as any).props;
if (!childProps) {
return;
}
if (childProps.default) {
defaultChild = child;
}
if (childProps.route === route) {
foundChild = child;
}
});
const c: ComponentChild | null = foundChild || defaultChild;
if (!c) {
throw Error("unknown route");
}
Router.setRoute((c as any).props.route);
return