From e69b7f66a3a530812a01e6ba9b05190c4066d4e6 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 18 Nov 2016 14:18:50 +0100 Subject: [PATCH 01/12] Gas calculation & limit errors --- .../DetailsStep/detailsStep.js | 16 +++++ .../ExecuteContract/executeContract.css | 8 +++ .../modals/ExecuteContract/executeContract.js | 72 +++++++++++++++++-- js/src/modals/Transfer/errors.js | 4 +- js/src/modals/Transfer/transfer.css | 9 +++ js/src/modals/Transfer/transfer.js | 57 +++++++++++++-- js/src/util/constants.js | 26 +++++++ 7 files changed, 180 insertions(+), 12 deletions(-) create mode 100644 js/src/util/constants.js diff --git a/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js b/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js index b549abb18..aad54e360 100644 --- a/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js +++ b/js/src/modals/ExecuteContract/DetailsStep/detailsStep.js @@ -36,6 +36,7 @@ export default class DetailsStep extends Component { onFuncChange: PropTypes.func, values: PropTypes.array.isRequired, valuesError: PropTypes.array.isRequired, + warning: PropTypes.string, onValueChange: PropTypes.func.isRequired } @@ -44,6 +45,7 @@ export default class DetailsStep extends Component { return (
+ { this.renderWarning() } + { warning } + + ); + } + onFuncChange = (event, index, signature) => { const { contract, onFuncChange } = this.props; diff --git a/js/src/modals/ExecuteContract/executeContract.css b/js/src/modals/ExecuteContract/executeContract.css index cdebfef32..55135a92e 100644 --- a/js/src/modals/ExecuteContract/executeContract.css +++ b/js/src/modals/ExecuteContract/executeContract.css @@ -33,3 +33,11 @@ .txhash { word-break: break-all; } + +.warning { + border-radius: 0.5em; + background: #f80; + color: white; + padding: 0.75em; + text-align: center; +} diff --git a/js/src/modals/ExecuteContract/executeContract.js b/js/src/modals/ExecuteContract/executeContract.js index a57c18a1d..8022690f5 100644 --- a/js/src/modals/ExecuteContract/executeContract.js +++ b/js/src/modals/ExecuteContract/executeContract.js @@ -15,17 +15,21 @@ // along with Parity. If not, see . import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; import ActionDoneAll from 'material-ui/svg-icons/action/done-all'; import ContentClear from 'material-ui/svg-icons/content/clear'; import { BusyStep, CompletedStep, Button, IdentityIcon, Modal, TxHash } from '../../ui'; +import { MAX_GAS_ESTIMATION } from '../../util/constants'; import { validateAddress, validateUint } from '../../util/validation'; import DetailsStep from './DetailsStep'; +import ERRORS from '../Transfer/errors'; import { ERROR_CODES } from '../../api/transport/error'; -export default class ExecuteContract extends Component { +class ExecuteContract extends Component { static contextTypes = { api: PropTypes.object.isRequired, store: PropTypes.object.isRequired @@ -36,6 +40,7 @@ export default class ExecuteContract extends Component { fromAddress: PropTypes.string, accounts: PropTypes.object, contract: PropTypes.object, + gasLimit: PropTypes.object.isRequired, onClose: PropTypes.func.isRequired, onFromAddressChange: PropTypes.func.isRequired } @@ -46,6 +51,8 @@ export default class ExecuteContract extends Component { fromAddressError: null, func: null, funcError: null, + gas: null, + gasLimitError: null, values: [], valuesError: [], step: 0, @@ -119,7 +126,7 @@ export default class ExecuteContract extends Component { renderStep () { const { onFromAddressChange } = this.props; - const { step, busyState, txhash, rejected } = this.state; + const { step, busyState, gasLimitError, txhash, rejected } = this.state; if (rejected) { return ( @@ -135,6 +142,7 @@ export default class ExecuteContract extends Component { { + this.estimateGas(); this.setState({ amount }); } @@ -179,6 +188,7 @@ export default class ExecuteContract extends Component { } }); + this.estimateGas(); this.setState({ func, values @@ -208,17 +218,54 @@ export default class ExecuteContract extends Component { values[index] = value; valuesError[index] = valueError; + if (!valueError) { + this.estimateGas(); + } + this.setState({ values: [].concat(values), valuesError: [].concat(valuesError) }); } + estimateGas = () => { + const { api } = this.context; + const { fromAddress, gasLimit } = this.props; + const { amount, func, values } = this.state; + const options = { + gas: MAX_GAS_ESTIMATION, + from: fromAddress, + value: api.util.toWei(amount || 0) + }; + + func + .estimateGas(options, values) + .then((gasEst) => { + const gas = gasEst.mul(1.2); + let gasLimitError = null; + + if (gas.gte(MAX_GAS_ESTIMATION)) { + gasLimitError = ERRORS.gasException; + } else if (gas.gt(gasLimit)) { + gasLimitError = ERRORS.gasBlockLimit; + } + + this.setState({ + gas, + gasLimitError + }); + }) + .catch((error) => { + console.warn('estimateGas', error); + }); + } + postTransaction = () => { const { api, store } = this.context; const { fromAddress } = this.props; const { amount, func, values } = this.state; const options = { + gas: MAX_GAS_ESTIMATION, from: fromAddress, value: api.util.toWei(amount || 0) }; @@ -237,13 +284,13 @@ export default class ExecuteContract extends Component { return api .pollMethod('parity_checkRequest', requestId) - .catch((e) => { - if (e.code === ERROR_CODES.REQUEST_REJECTED) { + .catch((error) => { + if (error.code === ERROR_CODES.REQUEST_REJECTED) { this.setState({ rejected: true }); return false; } - throw e; + throw error; }); }) .then((txhash) => { @@ -255,3 +302,18 @@ export default class ExecuteContract extends Component { }); } } + +function mapStateToProps (state) { + const { gasLimit } = state.status; + + return { gasLimit }; +} + +function mapDispatchToProps (dispatch) { + return bindActionCreators({}, dispatch); +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(ExecuteContract); diff --git a/js/src/modals/Transfer/errors.js b/js/src/modals/Transfer/errors.js index a6456c785..c35d82636 100644 --- a/js/src/modals/Transfer/errors.js +++ b/js/src/modals/Transfer/errors.js @@ -19,7 +19,9 @@ const ERRORS = { invalidAddress: 'the supplied address is an invalid network address', invalidAmount: 'the supplied amount should be a valid positive number', invalidDecimals: 'the supplied amount exceeds the allowed decimals', - largeAmount: 'the transaction total is higher than the available balance' + largeAmount: 'the transaction total is higher than the available balance', + gasException: 'the transaction indicates a thrown exception', + gasBlockLimit: 'the transaction will exceed the block gas limit' }; export default ERRORS; diff --git a/js/src/modals/Transfer/transfer.css b/js/src/modals/Transfer/transfer.css index 89b58666e..76f83c62b 100644 --- a/js/src/modals/Transfer/transfer.css +++ b/js/src/modals/Transfer/transfer.css @@ -14,6 +14,7 @@ /* You should have received a copy of the GNU General Public License /* along with Parity. If not, see . */ + .info { line-height: 1.618em; width: 100%; @@ -151,3 +152,11 @@ .gasPriceDesc { font-size: 0.9em; } + +.warning { + border-radius: 0.5em; + background: #f80; + color: white; + padding: 0.75em; + text-align: center; +} diff --git a/js/src/modals/Transfer/transfer.js b/js/src/modals/Transfer/transfer.js index e41ea08f9..196307923 100644 --- a/js/src/modals/Transfer/transfer.js +++ b/js/src/modals/Transfer/transfer.js @@ -16,12 +16,15 @@ import BigNumber from 'bignumber.js'; import React, { Component, PropTypes } from 'react'; +import { connect } from 'react-redux'; +import { bindActionCreators } from 'redux'; import ActionDoneAll from 'material-ui/svg-icons/action/done-all'; import ContentClear from 'material-ui/svg-icons/content/clear'; import NavigationArrowBack from 'material-ui/svg-icons/navigation/arrow-back'; import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward'; import { BusyStep, CompletedStep, Button, IdentityIcon, Modal, TxHash } from '../../ui'; +import { DEFAULT_GAS, DEFAULT_GASPRICE, MAX_GAS_ESTIMATION } from '../../util/constants'; import Details from './Details'; import Extras from './Extras'; @@ -30,8 +33,6 @@ import styles from './transfer.css'; import { ERROR_CODES } from '../../api/transport/error'; -const DEFAULT_GAS = '21000'; -const DEFAULT_GASPRICE = '20000000000'; const TITLES = { transfer: 'transfer details', sending: 'sending', @@ -42,7 +43,7 @@ const TITLES = { const STAGES_BASIC = [TITLES.transfer, TITLES.sending, TITLES.complete]; const STAGES_EXTRA = [TITLES.transfer, TITLES.extras, TITLES.sending, TITLES.complete]; -export default class Transfer extends Component { +class Transfer extends Component { static contextTypes = { api: PropTypes.object.isRequired, store: PropTypes.object.isRequired @@ -52,6 +53,7 @@ export default class Transfer extends Component { account: PropTypes.object, balance: PropTypes.object, balances: PropTypes.object, + gasLimit: PropTypes.object.isRequired, images: PropTypes.object.isRequired, onClose: PropTypes.func } @@ -64,6 +66,7 @@ export default class Transfer extends Component { gas: DEFAULT_GAS, gasEst: '0', gasError: null, + gasLimitError: null, gasPrice: DEFAULT_GASPRICE, gasPriceHistogram: {}, gasPriceError: null, @@ -103,6 +106,7 @@ export default class Transfer extends Component { visible scroll > + { this.renderWarning() } { this.renderPage() } ); @@ -264,6 +268,20 @@ export default class Transfer extends Component { } } + renderWarning () { + const { gasLimitError } = this.state; + + if (!gasLimitError) { + return null; + } + + return ( +
+ { gasLimitError } +
+ ); + } + isValid () { const detailsValid = !this.state.recipientError && !this.state.valueError && !this.state.totalError; const extrasValid = !this.state.gasError && !this.state.gasPriceError && !this.state.totalError; @@ -519,6 +537,7 @@ export default class Transfer extends Component { return token.contract.instance.transfer .estimateGas({ + gas: MAX_GAS_ESTIMATION, from: account.address, to: token.address }, [ @@ -532,6 +551,7 @@ export default class Transfer extends Component { const { account } = this.props; const { data, recipient, value } = this.state; const options = { + gas: MAX_GAS_ESTIMATION, from: account.address, to: recipient, value: api.util.toWei(value || 0) @@ -552,19 +572,29 @@ export default class Transfer extends Component { return; } + const { gasLimit } = this.props; + (this.state.isEth ? this._estimateGasEth() : this._estimateGasToken() - ).then((_value) => { - let gas = _value; + ).then((gasEst) => { + let gas = gasEst; + let gasLimitError = null; if (gas.gt(DEFAULT_GAS)) { gas = gas.mul(1.2); } + if (gas.gte(MAX_GAS_ESTIMATION)) { + gasLimitError = ERRORS.gasException; + } else if (gas.gt(gasLimit)) { + gasLimitError = ERRORS.gasBlockLimit; + } + this.setState({ gas: gas.toFixed(0), - gasEst: _value.toFormat() + gasEst: gasEst.toFormat(), + gasLimitError }, this.recalculate); }) .catch((error) => { @@ -649,3 +679,18 @@ export default class Transfer extends Component { store.dispatch({ type: 'newError', error }); } } + +function mapStateToProps (state) { + const { gasLimit } = state.status; + + return { gasLimit }; +} + +function mapDispatchToProps (dispatch) { + return bindActionCreators({}, dispatch); +} + +export default connect( + mapStateToProps, + mapDispatchToProps +)(Transfer); diff --git a/js/src/util/constants.js b/js/src/util/constants.js new file mode 100644 index 000000000..87ca59668 --- /dev/null +++ b/js/src/util/constants.js @@ -0,0 +1,26 @@ +// 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 . + +const DEFAULT_GAS = '21000'; +const DEFAULT_GASPRICE = '20000000000'; + +const MAX_GAS_ESTIMATION = '50000000'; + +export default { + DEFAULT_GAS, + DEFAULT_GASPRICE, + MAX_GAS_ESTIMATION +}; From b433e7e9a0207b6d3c6b7403ea9c54dee6787fc9 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 18 Nov 2016 15:05:02 +0100 Subject: [PATCH 02/12] Updated, contract execution in-place --- .../ExecuteContract/executeContract.css | 1 + .../modals/ExecuteContract/executeContract.js | 31 ++++++++++++------- js/src/modals/Transfer/errors.js | 4 +-- js/src/modals/Transfer/transfer.css | 1 + js/src/modals/Transfer/transfer.js | 2 +- js/src/util/constants.js | 2 +- 6 files changed, 26 insertions(+), 15 deletions(-) diff --git a/js/src/modals/ExecuteContract/executeContract.css b/js/src/modals/ExecuteContract/executeContract.css index 55135a92e..a83b373ee 100644 --- a/js/src/modals/ExecuteContract/executeContract.css +++ b/js/src/modals/ExecuteContract/executeContract.css @@ -38,6 +38,7 @@ border-radius: 0.5em; background: #f80; color: white; + font-size: 0.75em; padding: 0.75em; text-align: center; } diff --git a/js/src/modals/ExecuteContract/executeContract.js b/js/src/modals/ExecuteContract/executeContract.js index 8022690f5..1354e8543 100644 --- a/js/src/modals/ExecuteContract/executeContract.js +++ b/js/src/modals/ExecuteContract/executeContract.js @@ -71,6 +71,12 @@ class ExecuteContract extends Component { this.onFuncChange(null, functions[0]); } + componentWillReceiveProps (newProps) { + if (newProps.fromAddress !== this.props.fromAddress) { + this.estimateGas(newProps.fromAddress); + } + } + render () { const { sending } = this.state; @@ -164,8 +170,7 @@ class ExecuteContract extends Component { } onAmountChange = (amount) => { - this.estimateGas(); - this.setState({ amount }); + this.setState({ amount }, this.estimateGas); } onFuncChange = (event, func) => { @@ -188,11 +193,10 @@ class ExecuteContract extends Component { } }); - this.estimateGas(); this.setState({ func, values - }); + }, this.estimateGas); } onValueChange = (event, index, _value) => { @@ -218,29 +222,34 @@ class ExecuteContract extends Component { values[index] = value; valuesError[index] = valueError; - if (!valueError) { - this.estimateGas(); - } - this.setState({ values: [].concat(values), valuesError: [].concat(valuesError) + }, () => { + if (!valueError) { + this.estimateGas(); + } }); } - estimateGas = () => { + estimateGas = (_fromAddress) => { const { api } = this.context; const { fromAddress, gasLimit } = this.props; const { amount, func, values } = this.state; const options = { gas: MAX_GAS_ESTIMATION, - from: fromAddress, + from: _fromAddress || fromAddress, value: api.util.toWei(amount || 0) }; + if (!func) { + return; + } + func .estimateGas(options, values) .then((gasEst) => { + console.log(gasEst.toFormat(0)); const gas = gasEst.mul(1.2); let gasLimitError = null; @@ -304,7 +313,7 @@ class ExecuteContract extends Component { } function mapStateToProps (state) { - const { gasLimit } = state.status; + const { gasLimit } = state.nodeStatus; return { gasLimit }; } diff --git a/js/src/modals/Transfer/errors.js b/js/src/modals/Transfer/errors.js index c35d82636..3a6bd63ae 100644 --- a/js/src/modals/Transfer/errors.js +++ b/js/src/modals/Transfer/errors.js @@ -20,8 +20,8 @@ const ERRORS = { invalidAmount: 'the supplied amount should be a valid positive number', invalidDecimals: 'the supplied amount exceeds the allowed decimals', largeAmount: 'the transaction total is higher than the available balance', - gasException: 'the transaction indicates a thrown exception', - gasBlockLimit: 'the transaction will exceed the block gas limit' + gasException: 'the transaction will throw an exception with the current values', + gasBlockLimit: 'the transaction execution will exceed the block gas limit' }; export default ERRORS; diff --git a/js/src/modals/Transfer/transfer.css b/js/src/modals/Transfer/transfer.css index 76f83c62b..b7f478b4f 100644 --- a/js/src/modals/Transfer/transfer.css +++ b/js/src/modals/Transfer/transfer.css @@ -157,6 +157,7 @@ border-radius: 0.5em; background: #f80; color: white; + font-size: 0.75em; padding: 0.75em; text-align: center; } diff --git a/js/src/modals/Transfer/transfer.js b/js/src/modals/Transfer/transfer.js index 196307923..e906e45d7 100644 --- a/js/src/modals/Transfer/transfer.js +++ b/js/src/modals/Transfer/transfer.js @@ -681,7 +681,7 @@ class Transfer extends Component { } function mapStateToProps (state) { - const { gasLimit } = state.status; + const { gasLimit } = state.nodeStatus; return { gasLimit }; } diff --git a/js/src/util/constants.js b/js/src/util/constants.js index 87ca59668..d0664d25e 100644 --- a/js/src/util/constants.js +++ b/js/src/util/constants.js @@ -19,7 +19,7 @@ const DEFAULT_GASPRICE = '20000000000'; const MAX_GAS_ESTIMATION = '50000000'; -export default { +export { DEFAULT_GAS, DEFAULT_GASPRICE, MAX_GAS_ESTIMATION From 8d339ad379239f1968693952f39c3340dbbd8bf2 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 18 Nov 2016 15:13:37 +0100 Subject: [PATCH 03/12] Adjust styling --- js/src/modals/Transfer/transfer.css | 1 + 1 file changed, 1 insertion(+) diff --git a/js/src/modals/Transfer/transfer.css b/js/src/modals/Transfer/transfer.css index b7f478b4f..3bd17ba96 100644 --- a/js/src/modals/Transfer/transfer.css +++ b/js/src/modals/Transfer/transfer.css @@ -158,6 +158,7 @@ background: #f80; color: white; font-size: 0.75em; + margin-bottom: 1em; padding: 0.75em; text-align: center; } From f827ade6161caca36ec7cecffb7e1eba2b0da762 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Fri, 18 Nov 2016 16:32:57 +0100 Subject: [PATCH 04/12] debug log removal --- js/src/modals/ExecuteContract/executeContract.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/src/modals/ExecuteContract/executeContract.js b/js/src/modals/ExecuteContract/executeContract.js index 1354e8543..97d44a029 100644 --- a/js/src/modals/ExecuteContract/executeContract.js +++ b/js/src/modals/ExecuteContract/executeContract.js @@ -249,7 +249,6 @@ class ExecuteContract extends Component { func .estimateGas(options, values) .then((gasEst) => { - console.log(gasEst.toFormat(0)); const gas = gasEst.mul(1.2); let gasLimitError = null; From ca5fd0b23d5616ac523e7825bfe526db47fd4787 Mon Sep 17 00:00:00 2001 From: Nicolas Gotchac Date: Mon, 21 Nov 2016 14:14:25 +0100 Subject: [PATCH 05/12] React Perf in dev mode // Smarter background component #3240 --- js/package.json | 1 + js/src/index.js | 6 +++ .../ui/ParityBackground/parityBackground.js | 43 ++++++++++--------- .../views/Application/Container/container.js | 7 ++- js/src/views/ParityBar/parityBar.js | 11 ++++- .../views/Settings/Background/background.js | 5 ++- 6 files changed, 49 insertions(+), 24 deletions(-) diff --git a/js/package.json b/js/package.json index 7f4157cad..f8705f1a1 100644 --- a/js/package.json +++ b/js/package.json @@ -102,6 +102,7 @@ "postcss-nested": "^1.0.0", "postcss-simple-vars": "^3.0.0", "raw-loader": "^0.5.1", + "react-addons-perf": "~15.3.2", "react-addons-test-utils": "~15.3.2", "react-copy-to-clipboard": "^4.2.3", "react-dom": "~15.3.2", diff --git a/js/src/index.js b/js/src/index.js index fda785842..0e0433c1e 100644 --- a/js/src/index.js +++ b/js/src/index.js @@ -46,6 +46,12 @@ import './index.html'; injectTapEventPlugin(); +if (process.env.NODE_ENV === 'development') { + // Expose the React Performance Tools on the`window` object + const Perf = require('react-addons-perf'); + window.Perf = Perf; +} + const AUTH_HASH = '#/auth?'; const parityUrl = process.env.PARITY_URL || ( diff --git a/js/src/ui/ParityBackground/parityBackground.js b/js/src/ui/ParityBackground/parityBackground.js index 0916d3a85..5198195c0 100644 --- a/js/src/ui/ParityBackground/parityBackground.js +++ b/js/src/ui/ParityBackground/parityBackground.js @@ -16,26 +16,17 @@ import React, { Component, PropTypes } from 'react'; import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; class ParityBackground extends Component { - static contextTypes = { - muiTheme: PropTypes.object.isRequired - } - static propTypes = { + style: PropTypes.object.isRequired, children: PropTypes.node, className: PropTypes.string, - gradient: PropTypes.string, - seed: PropTypes.any, - settings: PropTypes.object.isRequired, onClick: PropTypes.func - } + }; render () { - const { muiTheme } = this.context; - const { children, className, gradient, seed, settings, onClick } = this.props; - const style = muiTheme.parity.getBackgroundStyle(gradient, seed || settings.backgroundSeed); + const { children, className, style, onClick } = this.props; return (
{ + const { backgroundSeed } = state.settings; + const { seed } = props; + + const newSeed = seed || backgroundSeed; + + if (newSeed === _seed) { + return _props; + } + + _seed = newSeed; + _props = { style: muiTheme.parity.getBackgroundStyle(gradient, newSeed) }; + + return _props; + }; } export default connect( - mapStateToProps, - mapDispatchToProps + mapStateToProps )(ParityBackground); diff --git a/js/src/views/Application/Container/container.js b/js/src/views/Application/Container/container.js index a1b9124c7..d3908f570 100644 --- a/js/src/views/Application/Container/container.js +++ b/js/src/views/Application/Container/container.js @@ -22,6 +22,10 @@ import { Errors, ParityBackground, Tooltips } from '../../../ui'; import styles from '../application.css'; export default class Container extends Component { + static contextTypes = { + muiTheme: PropTypes.object.isRequired + }; + static propTypes = { children: PropTypes.node.isRequired, showFirstRun: PropTypes.bool, @@ -30,9 +34,10 @@ export default class Container extends Component { render () { const { children, showFirstRun, onCloseFirstRun } = this.props; + const { muiTheme } = this.context; return ( - + diff --git a/js/src/views/ParityBar/parityBar.js b/js/src/views/ParityBar/parityBar.js index 0f3380ca0..40fe659ad 100644 --- a/js/src/views/ParityBar/parityBar.js +++ b/js/src/views/ParityBar/parityBar.js @@ -28,6 +28,10 @@ import imagesEthcoreBlock from '../../../assets/images/parity-logo-white-no-text import styles from './parityBar.css'; class ParityBar extends Component { + static contextTypes = { + muiTheme: PropTypes.object.isRequired + }; + static propTypes = { pending: PropTypes.array, dapp: PropTypes.bool @@ -62,6 +66,7 @@ class ParityBar extends Component { renderBar () { const { dapp } = this.props; + const { muiTheme } = this.context; if (!dapp) { return null; @@ -75,7 +80,7 @@ class ParityBar extends Component { return (
- +
); } From bd6f343cbe1f70c4ef5084af4c8d4d8e23297808 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Tue, 22 Nov 2016 11:54:20 +0100 Subject: [PATCH 09/12] DappRegistry (#3405) * Initial version, just loading * Warning dialog * Retrive & show applications * Display completed * Edit/New mode start * Display distry state, resolve hashes to urls * Move buttons to top-level * Rework display * Update error handling & dirty checks * Formatting * Split sections into components * Styling updates * Slight styling adjustments * Start delete modal * Add modals for register & update * Flesh-out register modal * Register error handling * Register registers * List refresh on add & remove * Update operational * Simplify, remove bg image * Really remove bg * fix case * Collapse text-only components --- js/src/dapps/dappreg.html | 17 + js/src/dapps/dappreg.js | 35 ++ .../dapps/dappreg/Application/application.css | 58 +++ .../dapps/dappreg/Application/application.js | 64 +++ js/src/dapps/dappreg/Application/index.js | 17 + js/src/dapps/dappreg/Button/button.css | 38 ++ js/src/dapps/dappreg/Button/button.js | 52 ++ js/src/dapps/dappreg/Button/index.js | 17 + js/src/dapps/dappreg/ButtonBar/buttonBar.css | 21 + js/src/dapps/dappreg/ButtonBar/buttonBar.js | 101 ++++ js/src/dapps/dappreg/ButtonBar/index.js | 17 + js/src/dapps/dappreg/Dapp/dapp.css | 19 + js/src/dapps/dappreg/Dapp/dapp.js | 162 ++++++ js/src/dapps/dappreg/Dapp/index.js | 17 + js/src/dapps/dappreg/Input/index.js | 17 + js/src/dapps/dappreg/Input/input.css | 92 ++++ js/src/dapps/dappreg/Input/input.js | 47 ++ js/src/dapps/dappreg/Modal/index.js | 17 + js/src/dapps/dappreg/Modal/modal.css | 116 +++++ js/src/dapps/dappreg/Modal/modal.js | 66 +++ js/src/dapps/dappreg/ModalDelete/index.js | 17 + .../dapps/dappreg/ModalDelete/modalDelete.js | 159 ++++++ js/src/dapps/dappreg/ModalRegister/index.js | 17 + .../dappreg/ModalRegister/modalRegister.js | 159 ++++++ js/src/dapps/dappreg/ModalUpdate/index.js | 17 + .../dapps/dappreg/ModalUpdate/modalUpdate.js | 169 ++++++ js/src/dapps/dappreg/SelectAccount/index.js | 17 + .../dappreg/SelectAccount/selectAccount.js | 49 ++ js/src/dapps/dappreg/SelectDapp/index.js | 17 + js/src/dapps/dappreg/SelectDapp/selectDapp.js | 76 +++ js/src/dapps/dappreg/Warning/index.js | 17 + js/src/dapps/dappreg/Warning/warning.css | 36 ++ js/src/dapps/dappreg/Warning/warning.js | 51 ++ js/src/dapps/dappreg/dappsStore.js | 482 ++++++++++++++++++ js/src/dapps/dappreg/modalStore.js | 266 ++++++++++ js/src/dapps/dappreg/parity.js | 53 ++ js/webpack.config.js | 1 + 37 files changed, 2593 insertions(+) create mode 100644 js/src/dapps/dappreg.html create mode 100644 js/src/dapps/dappreg.js create mode 100644 js/src/dapps/dappreg/Application/application.css create mode 100644 js/src/dapps/dappreg/Application/application.js create mode 100644 js/src/dapps/dappreg/Application/index.js create mode 100644 js/src/dapps/dappreg/Button/button.css create mode 100644 js/src/dapps/dappreg/Button/button.js create mode 100644 js/src/dapps/dappreg/Button/index.js create mode 100644 js/src/dapps/dappreg/ButtonBar/buttonBar.css create mode 100644 js/src/dapps/dappreg/ButtonBar/buttonBar.js create mode 100644 js/src/dapps/dappreg/ButtonBar/index.js create mode 100644 js/src/dapps/dappreg/Dapp/dapp.css create mode 100644 js/src/dapps/dappreg/Dapp/dapp.js create mode 100644 js/src/dapps/dappreg/Dapp/index.js create mode 100644 js/src/dapps/dappreg/Input/index.js create mode 100644 js/src/dapps/dappreg/Input/input.css create mode 100644 js/src/dapps/dappreg/Input/input.js create mode 100644 js/src/dapps/dappreg/Modal/index.js create mode 100644 js/src/dapps/dappreg/Modal/modal.css create mode 100644 js/src/dapps/dappreg/Modal/modal.js create mode 100644 js/src/dapps/dappreg/ModalDelete/index.js create mode 100644 js/src/dapps/dappreg/ModalDelete/modalDelete.js create mode 100644 js/src/dapps/dappreg/ModalRegister/index.js create mode 100644 js/src/dapps/dappreg/ModalRegister/modalRegister.js create mode 100644 js/src/dapps/dappreg/ModalUpdate/index.js create mode 100644 js/src/dapps/dappreg/ModalUpdate/modalUpdate.js create mode 100644 js/src/dapps/dappreg/SelectAccount/index.js create mode 100644 js/src/dapps/dappreg/SelectAccount/selectAccount.js create mode 100644 js/src/dapps/dappreg/SelectDapp/index.js create mode 100644 js/src/dapps/dappreg/SelectDapp/selectDapp.js create mode 100644 js/src/dapps/dappreg/Warning/index.js create mode 100644 js/src/dapps/dappreg/Warning/warning.css create mode 100644 js/src/dapps/dappreg/Warning/warning.js create mode 100644 js/src/dapps/dappreg/dappsStore.js create mode 100644 js/src/dapps/dappreg/modalStore.js create mode 100644 js/src/dapps/dappreg/parity.js diff --git a/js/src/dapps/dappreg.html b/js/src/dapps/dappreg.html new file mode 100644 index 000000000..89c95c472 --- /dev/null +++ b/js/src/dapps/dappreg.html @@ -0,0 +1,17 @@ + + + + + + + + Dapp Registry + + +
+ + + + + + diff --git a/js/src/dapps/dappreg.js b/js/src/dapps/dappreg.js new file mode 100644 index 000000000..243576a34 --- /dev/null +++ b/js/src/dapps/dappreg.js @@ -0,0 +1,35 @@ +// 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 from 'react'; +import ReactDOM from 'react-dom'; +import injectTapEventPlugin from 'react-tap-event-plugin'; +import { useStrict } from 'mobx'; + +injectTapEventPlugin(); +useStrict(true); + +import Application from './dappreg/Application'; + +import '../../assets/fonts/Roboto/font.css'; +import '../../assets/fonts/RobotoMono/font.css'; +import './style.css'; +import './dappreg.html'; + +ReactDOM.render( + , + document.querySelector('#container') +); diff --git a/js/src/dapps/dappreg/Application/application.css b/js/src/dapps/dappreg/Application/application.css new file mode 100644 index 000000000..f171d8127 --- /dev/null +++ b/js/src/dapps/dappreg/Application/application.css @@ -0,0 +1,58 @@ +/* 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 . +*/ + +.body { + color: #333; + background: #eee; + padding: 4.5em 0; + text-align: center; +} + +.apps { + background: #fff; + border-radius: 0.5em; + margin: 0 auto; + max-width: 980px; + padding: 1.5em; + text-align: left; +} + +.footer { + font-size: 0.75em; + margin: 1em; + padding: 1.5em; + text-align: center; +} + +.header { + background: #44e; + border-radius: 0 0 0.25em 0.25em; + color: #fff; + left: 0; + padding: 1em; + position: fixed; + right: 0; + top: 0; + z-index: 25; +} + +.loading { + text-align: center; + padding-top: 5em; + font-size: 2em; + color: #999; +} diff --git a/js/src/dapps/dappreg/Application/application.js b/js/src/dapps/dappreg/Application/application.js new file mode 100644 index 000000000..b5e4d5a97 --- /dev/null +++ b/js/src/dapps/dappreg/Application/application.js @@ -0,0 +1,64 @@ +// 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 } from 'react'; +import { observer } from 'mobx-react'; + +import DappsStore from '../dappsStore'; + +import ButtonBar from '../ButtonBar'; +import Dapp from '../Dapp'; +import ModalDelete from '../ModalDelete'; +import ModalRegister from '../ModalRegister'; +import ModalUpdate from '../ModalUpdate'; +import SelectDapp from '../SelectDapp'; +import Warning from '../Warning'; +import styles from './application.css'; + +@observer +export default class Application extends Component { + dappsStore = DappsStore.instance(); + + render () { + if (this.dappsStore.isLoading) { + return ( +
+ Loading application +
+ ); + } + + return ( +
+
+ DAPP REGISTRY, a global view of distributed applications available on the network. Putting the puzzle together. +
+
+ + + +
+
+ { this.dappsStore.count } applications registered, { this.dappsStore.ownedCount } owned by user +
+ + + + +
+ ); + } +} diff --git a/js/src/dapps/dappreg/Application/index.js b/js/src/dapps/dappreg/Application/index.js new file mode 100644 index 000000000..236578226 --- /dev/null +++ b/js/src/dapps/dappreg/Application/index.js @@ -0,0 +1,17 @@ +// 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 './application'; diff --git a/js/src/dapps/dappreg/Button/button.css b/js/src/dapps/dappreg/Button/button.css new file mode 100644 index 000000000..a66736e46 --- /dev/null +++ b/js/src/dapps/dappreg/Button/button.css @@ -0,0 +1,38 @@ +/* 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 . +*/ + +.button { + background: #44e; + border: none; + border-radius: 0.25em; + color: #fff; + cursor: pointer; + font-size: 1em; + margin: 1em 0.375em; + opacity: 0.85; + padding: 0.75em 2em; + + &[disabled] { + opacity: 0.5; + cursor: default; + background: #aaa; + } + + &[data-warning="true"] { + background: #e44; + } +} diff --git a/js/src/dapps/dappreg/Button/button.js b/js/src/dapps/dappreg/Button/button.js new file mode 100644 index 000000000..1f3b67b4c --- /dev/null +++ b/js/src/dapps/dappreg/Button/button.js @@ -0,0 +1,52 @@ +// 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 styles from './button.css'; + +export default class Button extends Component { + static propTypes = { + className: PropTypes.string, + disabled: PropTypes.bool, + label: PropTypes.string.isRequired, + warning: PropTypes.bool, + onClick: PropTypes.func.isRequired + } + + render () { + const { className, disabled, label, warning } = this.props; + const classes = `${styles.button} ${className}`; + + return ( + + ); + } + + onClick = (event) => { + if (this.props.disabled) { + return; + } + + this.props.onClick(event); + } +} diff --git a/js/src/dapps/dappreg/Button/index.js b/js/src/dapps/dappreg/Button/index.js new file mode 100644 index 000000000..f69a65e3d --- /dev/null +++ b/js/src/dapps/dappreg/Button/index.js @@ -0,0 +1,17 @@ +// 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 './button'; diff --git a/js/src/dapps/dappreg/ButtonBar/buttonBar.css b/js/src/dapps/dappreg/ButtonBar/buttonBar.css new file mode 100644 index 000000000..0aa84ee29 --- /dev/null +++ b/js/src/dapps/dappreg/ButtonBar/buttonBar.css @@ -0,0 +1,21 @@ +/* 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 . +*/ + +.buttonbar { + text-align: center; + margin: 1em 0 0 0; +} diff --git a/js/src/dapps/dappreg/ButtonBar/buttonBar.js b/js/src/dapps/dappreg/ButtonBar/buttonBar.js new file mode 100644 index 000000000..289def0ea --- /dev/null +++ b/js/src/dapps/dappreg/ButtonBar/buttonBar.js @@ -0,0 +1,101 @@ +// 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 } from 'react'; +import { observer } from 'mobx-react'; + +import DappsStore from '../dappsStore'; +import ModalStore from '../modalStore'; + +import Button from '../Button'; +import styles from './buttonBar.css'; + +@observer +export default class ButtonBar extends Component { + dappsStore = DappsStore.instance(); + modalStore = ModalStore.instance(); + + render () { + let buttons = []; + + if (this.dappsStore.isEditing || this.dappsStore.isNew) { + buttons = [ +