From eb84d5747aac0de781d64fb9cdbf2da13006d85e Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Sun, 13 Nov 2016 10:17:39 +0100 Subject: fix small react issues --- pages/confirm-contract.tsx | 62 ++++++++++++++++++++++++++++++++-------------- pages/tree.html | 3 +++ pages/tree.tsx | 13 +++++----- 3 files changed, 54 insertions(+), 24 deletions(-) (limited to 'pages') diff --git a/pages/confirm-contract.tsx b/pages/confirm-contract.tsx index a356b25a5..b5ada6045 100644 --- a/pages/confirm-contract.tsx +++ b/pages/confirm-contract.tsx @@ -24,6 +24,7 @@ import {substituteFulfillmentUrl} from "../lib/wallet/helpers"; import {Contract, AmountJson, IExchangeInfo} from "../lib/wallet/types"; +import {Offer} from "../lib/wallet/wallet"; import {renderContract, prettyAmount} from "../lib/wallet/renderHtml"; "use strict"; import {getExchanges} from "../lib/wallet/wxApi"; @@ -43,20 +44,17 @@ interface DetailProps { class Details extends React.Component { constructor(props: DetailProps) { super(props); - this.setState({ + console.log("new Details component created"); + this.state = { collapsed: props.collapsed, exchanges: null - }); + }; console.log("initial state:", this.state); this.update(); } - componentWillReceiveProps(props: DetailProps) { - this.setState({collapsed: props.collapsed} as any); - } - async update() { let exchanges = await getExchanges(); this.setState({exchanges} as any); @@ -100,10 +98,11 @@ class Details extends React.Component { } interface ContractPromptProps { - offer: any; + offerId: number; } interface ContractPromptState { + offer: any; error: string|null; payDisabled: boolean; } @@ -112,12 +111,14 @@ class ContractPrompt extends React.Component { + return new Promise((resolve, reject) => { + let msg = { + type: 'get-offer', + detail: { + offerId: this.props.offerId + } + }; + chrome.runtime.sendMessage(msg, (resp) => { + resolve(resp); + }); + }) + } + checkPayment() { let msg = { type: 'check-pay', detail: { - offer: this.props.offer + offer: this.state.offer } }; chrome.runtime.sendMessage(msg, (resp) => { @@ -149,12 +170,12 @@ class ContractPrompt extends React.Component this.checkPayment(), 300); + window.setTimeout(() => this.checkPayment(), 500); }); } doPayment() { - let d = {offer: this.props.offer}; + let d = {offer: this.state.offer}; chrome.runtime.sendMessage({type: 'confirm-pay', detail: d}, (resp) => { if (resp.error) { console.log("confirm-pay error", JSON.stringify(resp)); @@ -173,22 +194,29 @@ class ContractPrompt extends React.Component...; + } + let c = this.state.offer.contract; return (
- {renderContract(c)} +
+ {renderContract(c)} +
- {(this.state.error ?

{this.state.error}

:

)} +

+ {(this.state.error ?

{this.state.error}

:

)} +

); @@ -199,10 +227,8 @@ class ContractPrompt extends React.Component, document.getElementById( + ReactDOM.render(, document.getElementById( "contract")!); } diff --git a/pages/tree.html b/pages/tree.html index 1075655f6..05022e158 100644 --- a/pages/tree.html +++ b/pages/tree.html @@ -30,4 +30,7 @@ } + +
+ diff --git a/pages/tree.tsx b/pages/tree.tsx index c8a67dac2..6ff15600f 100644 --- a/pages/tree.tsx +++ b/pages/tree.tsx @@ -358,7 +358,7 @@ class ExchangeView extends React.Component { } interface ExchangesListState { - exchanges: IExchangeInfo[]; + exchanges?: IExchangeInfo[]; } class ExchangesList extends React.Component { @@ -371,8 +371,8 @@ class ExchangesList extends React.Component { this.update(); } }); - this.update(); + this.state = {} as any; } async update() { @@ -382,18 +382,19 @@ class ExchangesList extends React.Component { } render(): JSX.Element { - if (!this.state.exchanges) { + let exchanges = this.state.exchanges; + if (!exchanges) { return ...; } return (
- Exchanges ({this.state.exchanges.length.toString()}): - {this.state.exchanges.map(e => )} + Exchanges ({exchanges.length.toString()}): + {exchanges.map(e => )}
); } } export function main() { - ReactDOM.render(, document.body); + ReactDOM.render(, document.getElementById("container")!); } -- cgit v1.2.3