From d2e4bafaa50a9a686ad520273c9e2354ef798928 Mon Sep 17 00:00:00 2001 From: Jannis Redmann Date: Thu, 20 Oct 2016 11:31:23 +0200 Subject: [PATCH] refactor signer components (#2691) * remove TransactionPendingWeb3 * remove TransactionFinishedWeb3 * remove SignRequestWeb3 --- .../RequestFinishedWeb3.js | 8 +- .../RequestPendingWeb3/RequestPendingWeb3.js | 8 +- .../components/SignRequest/SignRequest.js | 29 ++++- .../SignRequestWeb3/SignRequestWeb3.js | 95 ---------------- .../components/SignRequestWeb3/index.js | 17 --- .../TransactionFinished.js | 47 +++++++- .../TransactionFinishedWeb3.js | 92 --------------- .../TransactionFinishedWeb3/index.js | 17 --- .../TransactionPending/TransactionPending.js | 51 +++++++-- .../TransactionPendingWeb3.js | 106 ------------------ .../TransactionPendingWeb3/index.js | 17 --- 11 files changed, 116 insertions(+), 371 deletions(-) delete mode 100644 js/src/views/Signer/components/SignRequestWeb3/SignRequestWeb3.js delete mode 100644 js/src/views/Signer/components/SignRequestWeb3/index.js delete mode 100644 js/src/views/Signer/components/TransactionFinishedWeb3/TransactionFinishedWeb3.js delete mode 100644 js/src/views/Signer/components/TransactionFinishedWeb3/index.js delete mode 100644 js/src/views/Signer/components/TransactionPendingWeb3/TransactionPendingWeb3.js delete mode 100644 js/src/views/Signer/components/TransactionPendingWeb3/index.js diff --git a/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js b/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js index 167ab92d1..168d306d3 100644 --- a/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js +++ b/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js @@ -16,8 +16,8 @@ import React, { Component, PropTypes } from 'react'; -import TransactionFinishedWeb3 from '../TransactionFinishedWeb3'; -import SignWeb3 from '../SignRequestWeb3'; +import TransactionFinished from '../TransactionFinished'; +import SignRequest from '../SignRequest'; export default class RequestFinishedWeb3 extends Component { static propTypes = { @@ -40,7 +40,7 @@ export default class RequestFinishedWeb3 extends Component { if (payload.sign) { const { sign } = payload; return ( - { + this.setState({ chain }); + }) + .catch((err) => { + console.error('could not fetch chain', err); + }); + + this.context.api.eth.getBalance(this.props.address) + .then((balance) => { + this.setState({ balance }); + }) + .catch((err) => { + console.error('could not fetch balance', err); + }); + } + render () { - const className = this.props.className || ''; + const { chain, balance, className } = this.props; return ( -
+
{ this.renderDetails() } { this.renderActions() }
diff --git a/js/src/views/Signer/components/SignRequestWeb3/SignRequestWeb3.js b/js/src/views/Signer/components/SignRequestWeb3/SignRequestWeb3.js deleted file mode 100644 index 139957ccf..000000000 --- a/js/src/views/Signer/components/SignRequestWeb3/SignRequestWeb3.js +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity 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 of the License, or -// (at your option) any later version. - -// Parity 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 Parity. If not, see . - -import React, { Component, PropTypes } from 'react'; - -import SignRequest from '../SignRequest'; - -export default class SignRequestWeb3 extends Component { - static contextTypes = { - api: PropTypes.object.isRequired - } - - static propTypes = { - id: PropTypes.string.isRequired, - address: PropTypes.string.isRequired, - hash: PropTypes.string.isRequired, - isFinished: PropTypes.bool.isRequired, - isSending: PropTypes.bool, - onConfirm: PropTypes.func, - onReject: PropTypes.func, - status: PropTypes.string, - className: PropTypes.string - }; - - state = { - chain: 'homestead', - balance: null // avoid required prop loading warning - } - - componentDidMount () { - this.fetchChain(); - this.fetchBalance(); - } - - render () { - const { balance, chain } = this.state; - const { address, onConfirm, onReject, isSending, isFinished, hash, className, id, status } = this.props; - - return ( - - ); - } - - fetchChain () { - const { api } = this.context; - - api.ethcore - .getNetChain() - .then((chain) => { - this.setState({ chain }); - }) - .catch((error) => { - console.error('fetchChain', error); - }); - } - - fetchBalance () { - const { api } = this.context; - const { address } = this.props; - - api.eth - .getBalance(address) - .then((balance) => { - this.setState({ balance }); - }) - .catch((error) => { - console.error('fetchBalance', error); - }); - } -} diff --git a/js/src/views/Signer/components/SignRequestWeb3/index.js b/js/src/views/Signer/components/SignRequestWeb3/index.js deleted file mode 100644 index d07d1d7e3..000000000 --- a/js/src/views/Signer/components/SignRequestWeb3/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity 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 of the License, or -// (at your option) any later version. - -// Parity 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 Parity. If not, see . - -export default from './SignRequestWeb3'; diff --git a/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js b/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js index ffd0bb731..080436a37 100644 --- a/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js +++ b/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js @@ -16,6 +16,7 @@ import React, { Component, PropTypes } from 'react'; +import CircularProgress from 'material-ui/CircularProgress'; import TransactionMainDetails from '../TransactionMainDetails'; import TxHashLink from '../TxHashLink'; import TransactionSecondaryDetails from '../TransactionSecondaryDetails'; @@ -26,25 +27,28 @@ import * as tUtil from '../util/transaction'; import { capitalize } from '../util/util'; export default class TransactionFinished extends Component { + static contextTypes = { + api: PropTypes.object.isRequired + }; + static propTypes = { id: PropTypes.object.isRequired, from: PropTypes.string.isRequired, - fromBalance: PropTypes.object, // eth BigNumber, not required since it might take time to fetch value: PropTypes.object.isRequired, // wei hex - chain: PropTypes.string.isRequired, gasPrice: PropTypes.object.isRequired, // wei hex gas: PropTypes.object.isRequired, // hex status: PropTypes.string.isRequired, // rejected, confirmed date: PropTypes.instanceOf(Date).isRequired, to: PropTypes.string, // undefined if it's a contract - toBalance: PropTypes.object, // eth BigNumber - undefined if it's a contract or until it's fetched txHash: PropTypes.string, // undefined if transacation is rejected className: PropTypes.string, data: PropTypes.string }; - static defaultProps = { - value: '0x0' // todo [adgo] - remove after resolving https://github.com/ethcore/parity/issues/1458 + state = { + chain: null, + fromBalance: null, + toBalance: null }; componentWillMount () { @@ -52,9 +56,30 @@ export default class TransactionFinished extends Component { const fee = tUtil.getFee(gas, gasPrice); // BigNumber object const totalValue = tUtil.getTotalValue(fee, value); this.setState({ totalValue }); + + this.context.api.ethcore.netChain() + .then((chain) => { + this.setState({ chain }); + }) + .catch((err) => { + console.error('could not fetch chain', err); + }); + + const { from, to } = this.props; + this.fetchBalance(from, 'fromBalance'); + if (to) this.fetchBalance(to, 'toBalance'); } render () { + const { chain, fromBalance, toBalance } = this.state; + if (!chain || !fromBalance || !toBalance) { + return ( +
+ +
+ ); + } + const { className, date, id } = this.props; const { totalValue } = this.state; @@ -63,7 +88,7 @@ export default class TransactionFinished extends Component {
{ + this.setState({ [key]: balance }); + }) + .catch((err) => { + console.error('could not fetch balance', err); + }); + } + } diff --git a/js/src/views/Signer/components/TransactionFinishedWeb3/TransactionFinishedWeb3.js b/js/src/views/Signer/components/TransactionFinishedWeb3/TransactionFinishedWeb3.js deleted file mode 100644 index dded9f146..000000000 --- a/js/src/views/Signer/components/TransactionFinishedWeb3/TransactionFinishedWeb3.js +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity 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 of the License, or -// (at your option) any later version. - -// Parity 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 Parity. If not, see . - -import React, { Component, PropTypes } from 'react'; - -import TransactionFinished from '../TransactionFinished'; - -export default class TransactionFinishedWeb3 extends Component { - static contextTypes = { - api: PropTypes.object.isRequired - } - - static propTypes = { - from: PropTypes.string.isRequired, - to: PropTypes.string // undefined if it's a contract - } - - state = { - chain: 'homestead' - } - - componentDidMount () { - this.fetchChain(); - this.fetchBalances(); - } - - render () { - const { fromBalance, toBalance, chain } = this.state; - const { from, to } = this.props; - - return ( - - ); - } - - fetchChain () { - const { api } = this.context; - - api.ethcore - .netChain() - .then((chain) => { - this.setState({ chain }); - }) - .catch((error) => { - console.error('fetchChain', error); - }); - } - - fetchBalances () { - const { from, to } = this.props; - this.fetchBalance(from, 'from'); - - if (!to) { - return; - } - - this.fetchBalance(to, 'to'); - } - - fetchBalance (address, owner) { - const { api } = this.context; - - api.eth - .getBalance(address) - .then((balance) => { - this.setState({ [owner + 'Balance']: balance }); - }) - .catch((error) => { - console.error('fetchBalance', error); - }); - } -} diff --git a/js/src/views/Signer/components/TransactionFinishedWeb3/index.js b/js/src/views/Signer/components/TransactionFinishedWeb3/index.js deleted file mode 100644 index 2638e8eab..000000000 --- a/js/src/views/Signer/components/TransactionFinishedWeb3/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity 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 of the License, or -// (at your option) any later version. - -// Parity 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 Parity. If not, see . - -export default from './TransactionFinishedWeb3'; diff --git a/js/src/views/Signer/components/TransactionPending/TransactionPending.js b/js/src/views/Signer/components/TransactionPending/TransactionPending.js index 2193cf6eb..fe5d2077c 100644 --- a/js/src/views/Signer/components/TransactionPending/TransactionPending.js +++ b/js/src/views/Signer/components/TransactionPending/TransactionPending.js @@ -16,6 +16,7 @@ import React, { Component, PropTypes } from 'react'; +import CircularProgress from 'material-ui/CircularProgress'; import TransactionMainDetails from '../TransactionMainDetails'; import TransactionPendingForm from '../TransactionPendingForm'; import TransactionSecondaryDetails from '../TransactionSecondaryDetails'; @@ -25,17 +26,18 @@ import styles from './TransactionPending.css'; import * as tUtil from '../util/transaction'; export default class TransactionPending extends Component { + static contextTypes = { + api: PropTypes.object.isRequired + }; + static propTypes = { id: PropTypes.object.isRequired, - chain: PropTypes.string.isRequired, from: PropTypes.string.isRequired, - fromBalance: PropTypes.object, // eth BigNumber, not required since it mght take time to fetch value: PropTypes.object.isRequired, // wei hex gasPrice: PropTypes.object.isRequired, // wei hex gas: PropTypes.object.isRequired, // hex date: PropTypes.instanceOf(Date).isRequired, to: PropTypes.string, // undefined if it's a contract - toBalance: PropTypes.object, // eth BigNumber - undefined if it's a contract or until it's fetched data: PropTypes.string, // hex nonce: PropTypes.number, onConfirm: PropTypes.func.isRequired, @@ -49,7 +51,9 @@ export default class TransactionPending extends Component { }; state = { - isDataExpanded: false + chain: null, + fromBalance: null, + toBalance: null }; componentWillMount () { @@ -59,20 +63,39 @@ export default class TransactionPending extends Component { const gasPriceEthmDisplay = tUtil.getEthmFromWeiDisplay(gasPrice); const gasToDisplay = tUtil.getGasDisplay(gas); this.setState({ gasPriceEthmDisplay, totalValue, gasToDisplay }); + + this.context.api.ethcore.netChain() + .then((chain) => { + this.setState({ chain }); + }) + .catch((err) => { + console.error('could not fetch chain', err); + }); + + const { from, to } = this.props; + this.fetchBalance(from, 'fromBalance'); + if (to) this.fetchBalance(to, 'toBalance'); } render () { - const { totalValue } = this.state; - const className = this.props.className || ''; + const { chain, fromBalance, toBalance } = this.state; + if (!chain || !fromBalance || !toBalance) { + return ( +
+ +
+ ); + } - const { gasPriceEthmDisplay, gasToDisplay } = this.state; - const { id, date, data, from } = this.props; + const { totalValue, gasPriceEthmDisplay, gasToDisplay } = this.state; + const { className, id, date, data, from } = this.props; return ( -
+
{ + this.setState({ [key]: balance }); + }) + .catch((err) => { + console.error('could not fetch balance', err); + }); + } + } diff --git a/js/src/views/Signer/components/TransactionPendingWeb3/TransactionPendingWeb3.js b/js/src/views/Signer/components/TransactionPendingWeb3/TransactionPendingWeb3.js deleted file mode 100644 index 0d095e07c..000000000 --- a/js/src/views/Signer/components/TransactionPendingWeb3/TransactionPendingWeb3.js +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity 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 of the License, or -// (at your option) any later version. - -// Parity 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 Parity. If not, see . - -import React, { Component, PropTypes } from 'react'; - -import TransactionPending from '../TransactionPending'; - -export default class TransactionPendingWeb3 extends Component { - static contextTypes = { - api: PropTypes.object.isRequired - }; - - static propTypes = { - id: PropTypes.object.isRequired, - from: PropTypes.string.isRequired, - value: PropTypes.object.isRequired, // wei hex - gasPrice: PropTypes.object.isRequired, // wei hex - gas: PropTypes.object.isRequired, // hex - onConfirm: PropTypes.func.isRequired, - onReject: PropTypes.func.isRequired, - isSending: PropTypes.bool.isRequired, - date: PropTypes.instanceOf(Date).isRequired, - to: PropTypes.string, // undefined if it's a contract - data: PropTypes.string, // hex - nonce: PropTypes.number, - className: PropTypes.string - }; - - state = { - chain: 'homestead', - fromBalance: null, // avoid required prop loading warning - toBalance: null // avoid required prop loading warning in case there's a to address - } - - componentDidMount () { - this.fetchChain(); - this.fetchBalances(); - } - - render () { - const { fromBalance, toBalance, chain } = this.state; - const { from, to, date } = this.props; - - return ( - - ); - } - - fetchChain () { - const { api } = this.context; - - api.ethcore - .netChain() - .then((chain) => { - this.setState({ chain }); - }) - .catch((error) => { - console.error('fetchChain', error); - }); - } - - fetchBalances () { - const { from, to } = this.props; - this.fetchBalance(from, 'from'); - - if (!to) { - return; - } - - this.fetchBalance(to, 'to'); - } - - fetchBalance (address, owner) { - const { api } = this.context; - - api.eth - .getBalance(address) - .then((balance) => { - this.setState({ [owner + 'Balance']: balance }); - }) - .catch((error) => { - console.error('fetchBalance', error); - }); - } -} diff --git a/js/src/views/Signer/components/TransactionPendingWeb3/index.js b/js/src/views/Signer/components/TransactionPendingWeb3/index.js deleted file mode 100644 index 2765bbc1c..000000000 --- a/js/src/views/Signer/components/TransactionPendingWeb3/index.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2015, 2016 Ethcore (UK) Ltd. -// This file is part of Parity. - -// Parity 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 of the License, or -// (at your option) any later version. - -// Parity 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 Parity. If not, see . - -export default from './TransactionPendingWeb3';