From d4be3906e32ac7d9933c6030d6493f2f2152bdd9 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 12 Oct 2016 02:55:53 +0200 Subject: tree view of wallet db --- pages/tree.tsx | 305 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 pages/tree.tsx (limited to 'pages/tree.tsx') diff --git a/pages/tree.tsx b/pages/tree.tsx new file mode 100644 index 000000000..acc470216 --- /dev/null +++ b/pages/tree.tsx @@ -0,0 +1,305 @@ +/* + This file is part of TALER + (C) 2016 Inria + + 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 + */ + +/** + * Show contents of the wallet as a tree. + * + * @author Florian Dold + */ + +/// + +import { IExchangeInfo } from "../lib/wallet/types"; +import { Reserve, Coin, PreCoin, Denomination } from "../lib/wallet/types"; +import { ImplicitStateComponent, StateHolder } from "../lib/components"; +import { getReserves, getExchanges, getCoins, getPreCoins } from "../lib/wallet/wxApi"; +import { prettyAmount, abbrev } from "../lib/wallet/renderHtml"; + +interface ReserveViewProps { + reserve: Reserve; +} + +class ReserveView extends preact.Component { + render(): JSX.Element { + let r: Reserve = this.props.reserve; + return ( +
+
    +
  • Key: {r.reserve_pub}
  • +
  • Created: {(new Date(r.created * 1000).toString())}
  • +
+
+ ); + } +} + +interface ReserveListProps { + exchangeBaseUrl: string; +} + +interface ToggleProps { + expanded: StateHolder; +} + +class Toggle extends ImplicitStateComponent { + renderButton() { + let show = () => { + this.props.expanded(true); + this.setState({}); + }; + let hide = () => { + this.props.expanded(false); + this.setState({}); + }; + if (this.props.expanded()) { + return ; + } + return ; + + } + render() { + return ( +
+ {this.renderButton()} + {this.props.expanded() ? this.props.children : []} +
); + } +} + + +interface CoinViewProps { + coin: Coin; +} + +class CoinView extends preact.Component { + render() { + let c = this.props.coin; + return ( +
+
    +
  • Key: {c.coinPub}
  • +
  • Current amount: {prettyAmount(c.currentAmount)}
  • +
  • Denomination: {abbrev(c.denomPub, 20)}
  • +
  • Suspended: {(c.suspended || false).toString()}
  • +
+
+ ); + } +} + + + +interface PreCoinViewProps { + precoin: PreCoin; +} + +class PreCoinView extends preact.Component { + render() { + let c = this.props.precoin; + return ( +
+
    +
  • Key: {c.coinPub}
  • +
+
+ ); + } +} + +interface CoinListProps { + exchangeBaseUrl: string; +} + +class CoinList extends ImplicitStateComponent { + coins = this.makeState(null); + expanded = this.makeState(false); + + constructor(props: CoinListProps) { + super(props); + this.update(); + } + + async update() { + let coins = await getCoins(this.props.exchangeBaseUrl); + this.coins(coins); + } + + render(): JSX.Element { + if (!this.coins()) { + return
...
; + } + return ( +
+ Coins ({this.coins() !.length.toString()}) + {" "} + + {this.coins() !.map((c) => )} + +
+ ); + } +} + + +interface PreCoinListProps { + exchangeBaseUrl: string; +} + +class PreCoinList extends ImplicitStateComponent { + precoins = this.makeState(null); + expanded = this.makeState(false); + + constructor(props: PreCoinListProps) { + super(props); + this.update(); + } + + async update() { + let precoins = await getPreCoins(this.props.exchangeBaseUrl); + this.precoins(precoins); + } + + render(): JSX.Element { + if (!this.precoins()) { + return
...
; + } + return ( +
+ Pre-Coins ({this.precoins() !.length.toString()}) + {" "} + + {this.precoins() !.map((c) => )} + +
+ ); + } +} + +interface DenominationListProps { + exchange: IExchangeInfo; +} + +class DenominationList extends ImplicitStateComponent { + expanded = this.makeState(false); + + renderDenom(d: Denomination) { + return ( +
+
    +
  • Value: {prettyAmount(d.value)}
  • +
  • Withdraw fee: {prettyAmount(d.fee_withdraw)}
  • +
  • Refresh fee: {prettyAmount(d.fee_refresh)}
  • +
  • Deposit fee: {prettyAmount(d.fee_deposit)}
  • +
  • Refund fee: {prettyAmount(d.fee_refund)}
  • +
+
+ ); + } + + render(): JSX.Element { + return ( +
+ Denominations ({this.props.exchange.active_denoms.length.toString()}) + {" "} + + {this.props.exchange.active_denoms.map((d) => this.renderDenom(d))} + +
+ ); + } +} + +class ReserveList extends ImplicitStateComponent { + reserves = this.makeState(null); + expanded = this.makeState(false); + + constructor(props: ReserveListProps) { + super(props); + this.update(); + } + + async update() { + let reserves = await getReserves(this.props.exchangeBaseUrl); + this.reserves(reserves); + } + + render(): JSX.Element { + if (!this.reserves()) { + return
...
; + } + return ( +
+ Reserves ({this.reserves() !.length.toString()}) + {" "} + + {this.reserves() !.map((r) => )} + +
+ ); + } +} + +interface ExchangeProps { + exchange: IExchangeInfo; +} + +class ExchangeView extends preact.Component { + render(): JSX.Element { + let e = this.props.exchange; + return ( +
+ Url: {this.props.exchange.baseUrl} + + + + +
+ ); + } +} + +interface ExchangesListState { + exchanges: IExchangeInfo[]; +} + +class ExchangesList extends preact.Component { + constructor() { + super(); + this.update(); + } + + async update() { + let exchanges = await getExchanges(); + console.log("exchanges: ", exchanges); + this.setState({ exchanges }); + } + + render(): JSX.Element { + if (!this.state.exchanges) { + return ...; + } + return ( +
+ Exchanges ({this.state.exchanges.length.toString()}): + {this.state.exchanges.map(e => )} +
+ ); + } +} + +export function main() { + preact.render(, document.body); +} -- cgit v1.2.3