From d9683861f98277e7121ff47d2bd223c2d0c2cd34 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 1 Feb 2018 07:19:03 +0100 Subject: fix performance and UI issues with tipping --- src/webex/pages/tip.tsx | 65 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 19 deletions(-) (limited to 'src/webex/pages/tip.tsx') diff --git a/src/webex/pages/tip.tsx b/src/webex/pages/tip.tsx index 578ae6aa4..f21bc0eaf 100644 --- a/src/webex/pages/tip.tsx +++ b/src/webex/pages/tip.tsx @@ -31,6 +31,7 @@ import * as i18n from "../../i18n"; import { acceptTip, getTipStatus, + getReserveCreationInfo, } from "../wxApi"; import { @@ -40,7 +41,7 @@ import { import * as Amounts from "../../amounts"; import { TipToken } from "../../talerTypes"; -import { TipStatus } from "../../walletTypes"; +import { ReserveCreationInfo, TipStatus } from "../../walletTypes"; interface TipDisplayProps { tipToken: TipToken; @@ -48,18 +49,22 @@ interface TipDisplayProps { interface TipDisplayState { tipStatus?: TipStatus; + rci?: ReserveCreationInfo; working: boolean; + discarded: boolean; } class TipDisplay extends React.Component { constructor(props: TipDisplayProps) { super(props); - this.state = { working: false }; + this.state = { working: false, discarded: false }; } async update() { const tipStatus = await getTipStatus(this.props.tipToken); this.setState({ tipStatus }); + const rci = await getReserveCreationInfo(tipStatus.exchangeUrl, tipStatus.amount); + this.setState({ rci }); } componentDidMount() { @@ -74,8 +79,8 @@ class TipDisplay extends React.Component { this.update(); } - renderExchangeInfo(ts: TipStatus) { - const rci = ts.rci; + renderExchangeInfo() { + const rci = this.state.rci; if (!rci) { return

Waiting for info about exchange ...

; } @@ -99,12 +104,30 @@ class TipDisplay extends React.Component { acceptTip(this.props.tipToken); } - renderButtons() { - return ( + discard() { + this.setState({ discarded: true }); + } + + render(): JSX.Element { + const ts = this.state.tipStatus; + if (!ts) { + return

Processing ...

; + } + + const renderAccepted = () => ( + <> +

You've accepted this tip! Go back to merchant

+ {this.renderExchangeInfo()} + + ); + + const renderButtons = () => ( + <>