From 1686d23522f8d1ddd8e984982402a67ba4ef733b Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 18 Nov 2016 19:07:13 +0100 Subject: [PATCH] Don't query chain in Signer, use Redux isTest --- .../Signer/components/Account/Account.js | 18 ++++++---- .../Account/AccountLink/AccountLink.js | 14 ++++---- .../RequestFinishedWeb3.js | 9 +++-- .../RequestPendingWeb3/RequestPendingWeb3.js | 9 +++-- .../components/SignRequest/SignRequest.js | 33 +++++++++---------- .../TransactionFinished.js | 27 +++++++-------- .../TransactionMainDetails.js | 30 +++++++++++++---- .../TransactionPending/TransactionPending.js | 21 ++---------- .../TransactionSecondaryDetails.js | 10 ++++-- .../components/TxHashLink/TxHashLink.js | 6 ++-- .../Signer/containers/Embedded/embedded.js | 10 ++++-- .../containers/RequestsPage/RequestsPage.js | 17 ++++++++-- 12 files changed, 117 insertions(+), 87 deletions(-) diff --git a/js/src/views/Signer/components/Account/Account.js b/js/src/views/Signer/components/Account/Account.js index 63a601373..b6e7f2e48 100644 --- a/js/src/views/Signer/components/Account/Account.js +++ b/js/src/views/Signer/components/Account/Account.js @@ -25,7 +25,7 @@ export default class Account extends Component { static propTypes = { className: PropTypes.string, address: PropTypes.string.isRequired, - chain: PropTypes.string.isRequired, + isTest: PropTypes.bool.isRequired, balance: PropTypes.object // eth BigNumber, not required since it mght take time to fetch }; @@ -51,11 +51,13 @@ export default class Account extends Component { } render () { - const { address, chain, className } = this.props; + const { address, isTest, className } = this.props; return (
- + @@ -74,19 +76,23 @@ export default class Account extends Component { } renderName () { - const { address } = this.props; + const { address, isTest } = this.props; const name = ; if (!name) { return ( - + [{ this.shortAddress(address) }] ); } return ( - + { name } [{ this.tinyAddress(address) }] diff --git a/js/src/views/Signer/components/Account/AccountLink/AccountLink.js b/js/src/views/Signer/components/Account/AccountLink/AccountLink.js index 4e3c0a0a9..97ff35ce9 100644 --- a/js/src/views/Signer/components/Account/AccountLink/AccountLink.js +++ b/js/src/views/Signer/components/Account/AccountLink/AccountLink.js @@ -21,7 +21,7 @@ import styles from './AccountLink.css'; export default class AccountLink extends Component { static propTypes = { - chain: PropTypes.string.isRequired, + isTest: PropTypes.bool.isRequired, address: PropTypes.string.isRequired, className: PropTypes.string, children: PropTypes.node @@ -32,15 +32,15 @@ export default class AccountLink extends Component { }; componentWillMount () { - const { address, chain } = this.props; + const { address, isTest } = this.props; - this.updateLink(address, chain); + this.updateLink(address, isTest); } componentWillReceiveProps (nextProps) { - const { address, chain } = nextProps; + const { address, isTest } = nextProps; - this.updateLink(address, chain); + this.updateLink(address, isTest); } render () { @@ -56,8 +56,8 @@ export default class AccountLink extends Component { ); } - updateLink (address, chain) { - const link = addressLink(address, chain === 'morden' || chain === 'testnet'); + updateLink (address, isTest) { + const link = addressLink(address, isTest); this.setState({ link diff --git a/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js b/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js index 7b30d3e93..74a20f625 100644 --- a/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js +++ b/js/src/views/Signer/components/RequestFinishedWeb3/RequestFinishedWeb3.js @@ -31,14 +31,16 @@ export default class RequestFinishedWeb3 extends Component { msg: PropTypes.string, status: PropTypes.string, error: PropTypes.string, - className: PropTypes.string + className: PropTypes.string, + isTest: PropTypes.bool.isRequired } render () { - const { payload, id, result, msg, status, error, date, className } = this.props; + const { payload, id, result, msg, status, error, date, className, isTest } = this.props; if (payload.sign) { const { sign } = payload; + return ( ); } if (payload.transaction) { const { transaction } = payload; + return ( ); } diff --git a/js/src/views/Signer/components/RequestPendingWeb3/RequestPendingWeb3.js b/js/src/views/Signer/components/RequestPendingWeb3/RequestPendingWeb3.js index 97fa43f69..d9e695dbc 100644 --- a/js/src/views/Signer/components/RequestPendingWeb3/RequestPendingWeb3.js +++ b/js/src/views/Signer/components/RequestPendingWeb3/RequestPendingWeb3.js @@ -30,7 +30,8 @@ export default class RequestPendingWeb3 extends Component { PropTypes.shape({ transaction: PropTypes.object.isRequired }), PropTypes.shape({ sign: PropTypes.object.isRequired }) ]).isRequired, - className: PropTypes.string + className: PropTypes.string, + isTest: PropTypes.bool.isRequired }; onConfirm = data => { @@ -41,10 +42,11 @@ export default class RequestPendingWeb3 extends Component { }; render () { - const { payload, id, className, isSending, date, onReject } = this.props; + const { payload, id, className, isSending, date, onReject, isTest } = this.props; if (payload.sign) { const { sign } = payload; + return ( ); } if (payload.transaction) { const { transaction } = payload; + return ( ); } diff --git a/js/src/views/Signer/components/SignRequest/SignRequest.js b/js/src/views/Signer/components/SignRequest/SignRequest.js index 719ddeec9..6fb2b37b7 100644 --- a/js/src/views/Signer/components/SignRequest/SignRequest.js +++ b/js/src/views/Signer/components/SignRequest/SignRequest.js @@ -39,24 +39,15 @@ export default class SignRequest extends Component { onReject: PropTypes.func, status: PropTypes.string, className: PropTypes.string, - chain: nullable(PropTypes.object), + isTest: PropTypes.bool.isRequired, balance: nullable(PropTypes.object) }; state = { - chain: null, balance: null } componentWillMount () { - this.context.api.parity.netChain() - .then((chain) => { - 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 }); @@ -68,6 +59,7 @@ export default class SignRequest extends Component { render () { const { className } = this.props; + return (
{ this.renderDetails() } @@ -77,15 +69,20 @@ export default class SignRequest extends Component { } renderDetails () { - const { address, hash } = this.props; - const { balance, chain } = this.state; + const { address, hash, isTest } = this.props; + const { balance } = this.state; - if (!balance || !chain) return (
); + if (!balance) { + return
; + } return (
- +

Dapp is requesting to sign arbitrary transaction using this account.

@@ -100,15 +97,17 @@ export default class SignRequest extends Component { if (isFinished) { if (status === 'confirmed') { - const { hash } = this.props; - const { chain } = this.state; + const { hash, isTest } = this.props; return (
Confirmed
Transaction hash: - +
); diff --git a/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js b/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js index 00d6a057f..54333115d 100644 --- a/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js +++ b/js/src/views/Signer/components/TransactionFinished/TransactionFinished.js @@ -47,13 +47,12 @@ export default class TransactionFinished extends Component { txHash: PropTypes.string, // undefined if transacation is rejected className: PropTypes.string, data: PropTypes.string, - chain: nullable(PropTypes.object), + isTest: PropTypes.bool.isRequired, fromBalance: nullable(PropTypes.object), toBalance: nullable(PropTypes.object) }; state = { - chain: null, fromBalance: null, toBalance: null }; @@ -64,14 +63,6 @@ export default class TransactionFinished extends Component { const totalValue = tUtil.getTotalValue(fee, value); this.setState({ totalValue }); - this.context.api.parity.netChain() - .then((chain) => { - this.setState({ chain }); - }) - .catch((err) => { - console.error('could not fetch chain', err); - }); - this.fetchBalance(from, 'fromBalance'); if (to) { this.fetchBalance(to, 'toBalance'); @@ -79,8 +70,9 @@ export default class TransactionFinished extends Component { } render () { - const { chain, fromBalance, toBalance } = this.state; - if (!chain || !fromBalance || !toBalance) { + const { fromBalance, toBalance } = this.state; + + if (!fromBalance || !toBalance) { return (
@@ -130,16 +122,19 @@ export default class TransactionFinished extends Component { } renderTxHash () { - const { txHash } = this.props; - const { chain } = this.state; - if (!txHash || !chain) { + const { txHash, isTest } = this.props; + + if (!txHash) { return; } return (
Transaction hash: - +
); } diff --git a/js/src/views/Signer/components/TransactionMainDetails/TransactionMainDetails.js b/js/src/views/Signer/components/TransactionMainDetails/TransactionMainDetails.js index 10b54b10b..4efa567d2 100644 --- a/js/src/views/Signer/components/TransactionMainDetails/TransactionMainDetails.js +++ b/js/src/views/Signer/components/TransactionMainDetails/TransactionMainDetails.js @@ -30,7 +30,7 @@ export default class TransactionMainDetails extends Component { fromBalance: PropTypes.object, // eth BigNumber, not required since it might take time to fetch value: PropTypes.object.isRequired, // wei hex totalValue: PropTypes.object.isRequired, // wei BigNumber - chain: PropTypes.string.isRequired, + isTest: PropTypes.isTest.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 className: PropTypes.string, @@ -39,11 +39,13 @@ export default class TransactionMainDetails extends Component { componentWillMount () { const { value, totalValue } = this.props; + this.updateDisplayValues(value, totalValue); } componentWillReceiveProps (nextProps) { const { value, totalValue } = nextProps; + this.updateDisplayValues(value, totalValue); } @@ -59,6 +61,7 @@ export default class TransactionMainDetails extends Component { render () { const { className, children } = this.props; + return (
{ this.renderTransfer() } @@ -69,7 +72,8 @@ export default class TransactionMainDetails extends Component { } renderTransfer () { - const { from, fromBalance, to, toBalance, chain } = this.props; + const { from, fromBalance, to, toBalance, isTest } = this.props; + if (!to) { return; } @@ -78,7 +82,10 @@ export default class TransactionMainDetails extends Component {
- +
@@ -88,7 +95,10 @@ export default class TransactionMainDetails extends Component {
- +
@@ -96,15 +106,20 @@ export default class TransactionMainDetails extends Component { } renderContract () { - const { from, fromBalance, to, chain } = this.props; + const { from, fromBalance, to, isTest } = this.props; + if (to) { return; } + return (
- +
@@ -126,6 +141,7 @@ export default class TransactionMainDetails extends Component { renderValue () { const { id } = this.props; const { valueDisplay, valueDisplayWei } = this.state; + return (
); } - } diff --git a/js/src/views/Signer/components/TransactionPending/TransactionPending.js b/js/src/views/Signer/components/TransactionPending/TransactionPending.js index 55e4f6405..55f09ac97 100644 --- a/js/src/views/Signer/components/TransactionPending/TransactionPending.js +++ b/js/src/views/Signer/components/TransactionPending/TransactionPending.js @@ -16,7 +16,6 @@ import React, { Component, PropTypes } from 'react'; -import CircularProgress from 'material-ui/CircularProgress'; import TransactionMainDetails from '../TransactionMainDetails'; import TransactionPendingForm from '../TransactionPendingForm'; import TransactionSecondaryDetails from '../TransactionSecondaryDetails'; @@ -43,7 +42,8 @@ export default class TransactionPending extends Component { onConfirm: PropTypes.func.isRequired, onReject: PropTypes.func.isRequired, isSending: PropTypes.bool.isRequired, - className: PropTypes.string + className: PropTypes.string, + isTest: PropTypes.bool.isRequired }; static defaultProps = { @@ -51,7 +51,6 @@ export default class TransactionPending extends Component { }; state = { - chain: null, fromBalance: null, toBalance: null }; @@ -64,28 +63,12 @@ export default class TransactionPending extends Component { const gasToDisplay = tUtil.getGasDisplay(gas); this.setState({ gasPriceEthmDisplay, totalValue, gasToDisplay }); - this.context.api.parity.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 () { - if (!this.state.chain) { - return ( -
- -
- ); - } - const { totalValue, gasPriceEthmDisplay, gasToDisplay } = this.state; const { className, id, date, data, from } = this.props; diff --git a/js/src/views/Signer/components/TransactionSecondaryDetails/TransactionSecondaryDetails.js b/js/src/views/Signer/components/TransactionSecondaryDetails/TransactionSecondaryDetails.js index 61c1260d4..fb0a329e0 100644 --- a/js/src/views/Signer/components/TransactionSecondaryDetails/TransactionSecondaryDetails.js +++ b/js/src/views/Signer/components/TransactionSecondaryDetails/TransactionSecondaryDetails.js @@ -59,10 +59,13 @@ export default class TransactionSecondaryDetails extends Component { } renderGasPrice () { - if (!this.props.gasPriceEthmDisplay && !this.props.gasToDisplay) return null; + if (!this.props.gasPriceEthmDisplay && !this.props.gasToDisplay) { + return null; + } const { id } = this.props; const { gasPriceEthmDisplay, gasToDisplay } = this.props; + return (
{ children || txHash } diff --git a/js/src/views/Signer/containers/Embedded/embedded.js b/js/src/views/Signer/containers/Embedded/embedded.js index be3a65d61..e06eaf274 100644 --- a/js/src/views/Signer/containers/Embedded/embedded.js +++ b/js/src/views/Signer/containers/Embedded/embedded.js @@ -35,7 +35,8 @@ class Embedded extends Component { actions: PropTypes.shape({ startConfirmRequest: PropTypes.func.isRequired, startRejectRequest: PropTypes.func.isRequired - }).isRequired + }).isRequired, + isTest: PropTypes.bool.isRequired }; render () { @@ -70,7 +71,7 @@ class Embedded extends Component { } renderPending = (data) => { - const { actions } = this.props; + const { actions, isTest } = this.props; const { payload, id, isSending, date } = data; return ( @@ -83,6 +84,7 @@ class Embedded extends Component { id={ id } payload={ payload } date={ date } + isTest={ isTest } /> ); } @@ -93,11 +95,13 @@ class Embedded extends Component { } function mapStateToProps (state) { + const { isTest } = state.nodeStatus; const { actions, signer } = state; return { actions, - signer + signer, + isTest }; } diff --git a/js/src/views/Signer/containers/RequestsPage/RequestsPage.js b/js/src/views/Signer/containers/RequestsPage/RequestsPage.js index 2a0d087e3..bf4968610 100644 --- a/js/src/views/Signer/containers/RequestsPage/RequestsPage.js +++ b/js/src/views/Signer/containers/RequestsPage/RequestsPage.js @@ -35,7 +35,8 @@ class RequestsPage extends Component { actions: PropTypes.shape({ startConfirmRequest: PropTypes.func.isRequired, startRejectRequest: PropTypes.func.isRequired - }).isRequired + }).isRequired, + isTest: PropTypes.bool.isRequired }; render () { @@ -96,7 +97,7 @@ class RequestsPage extends Component { } renderPending = (data) => { - const { actions } = this.props; + const { actions, isTest } = this.props; const { payload, id, isSending, date } = data; return ( @@ -109,11 +110,13 @@ class RequestsPage extends Component { id={ id } payload={ payload } date={ date } + isTest={ isTest } /> ); } renderFinished = (data) => { + const { isTest } = this.props; const { payload, id, result, msg, status, error, date } = data; return ( @@ -127,6 +130,7 @@ class RequestsPage extends Component { error={ error } payload={ payload } date={ date } + isTest={ isTest } /> ); } @@ -143,7 +147,14 @@ class RequestsPage extends Component { } function mapStateToProps (state) { - return state; + const { isTest } = state.nodeStatus; + const { actions, signer } = state; + + return { + actions, + signer, + isTest + }; } function mapDispatchToProps (dispatch) {