From 8677c3b91f05fd625bf949c0ab0457b58f743a1d Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Wed, 28 Dec 2016 18:09:54 +0100 Subject: [PATCH] Cleanup AddContract with store (#3981) * Splits (WIP) * Expand getters & setters * Initial abi type set * Expand * Don't rely on passed api * Store tests in place * Allow RadioButtons to accept MobX arrays * Fixes for manual testing --- js/src/modals/AddContract/addContract.js | 283 ++++++++---------- js/src/modals/AddContract/addContract.spec.js | 55 ++++ js/src/modals/AddContract/addContract.test.js | 38 +++ js/src/modals/AddContract/store.js | 126 ++++++++ js/src/modals/AddContract/store.spec.js | 171 +++++++++++ js/src/modals/AddContract/types.js | 81 +++++ js/src/ui/Form/RadioButtons/radioButtons.js | 39 ++- js/src/util/proptypes.js | 7 + js/src/util/validation.js | 14 +- 9 files changed, 634 insertions(+), 180 deletions(-) create mode 100644 js/src/modals/AddContract/addContract.spec.js create mode 100644 js/src/modals/AddContract/addContract.test.js create mode 100644 js/src/modals/AddContract/store.js create mode 100644 js/src/modals/AddContract/store.spec.js create mode 100644 js/src/modals/AddContract/types.js diff --git a/js/src/modals/AddContract/addContract.js b/js/src/modals/AddContract/addContract.js index 0d04438c3..c5e7aac61 100644 --- a/js/src/modals/AddContract/addContract.js +++ b/js/src/modals/AddContract/addContract.js @@ -14,38 +14,17 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +import { observer } from 'mobx-react'; import React, { Component, PropTypes } from 'react'; -import ContentAdd from 'material-ui/svg-icons/content/add'; -import ContentClear from 'material-ui/svg-icons/content/clear'; -import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward'; -import NavigationArrowBack from 'material-ui/svg-icons/navigation/arrow-back'; +import { FormattedMessage } from 'react-intl'; +import { newError } from '~/redux/actions'; import { Button, Modal, Form, Input, InputAddress, RadioButtons } from '~/ui'; -import { ERRORS, validateAbi, validateAddress, validateName } from '~/util/validation'; +import { AddIcon, CancelIcon, NextIcon, PrevIcon } from '~/ui/Icons'; -import { eip20, wallet } from '~/contracts/abi'; - -const ABI_TYPES = [ - { - label: 'Token', readOnly: true, value: JSON.stringify(eip20), - type: 'token', - description: (A standard ERC 20 token) - }, - { - label: 'Multisig Wallet', readOnly: true, - type: 'multisig', - value: JSON.stringify(wallet), - description: (Official Multisig contract: see contract code) - }, - { - label: 'Custom Contract', value: '', - type: 'custom', - description: 'Contract created from custom ABI' - } -]; - -const STEPS = [ 'choose a contract type', 'enter contract details' ]; +import Store from './store'; +@observer export default class AddContract extends Component { static contextTypes = { api: PropTypes.object.isRequired @@ -56,219 +35,217 @@ export default class AddContract extends Component { onClose: PropTypes.func }; - state = { - abi: '', - abiError: ERRORS.invalidAbi, - abiType: ABI_TYPES[2], - abiTypeIndex: 2, - abiParsed: null, - address: '', - addressError: ERRORS.invalidAddress, - name: '', - nameError: ERRORS.invalidName, - description: '', - step: 0 - }; - - componentDidMount () { - this.onChangeABIType(null, this.state.abiTypeIndex); - } + store = new Store(this.context.api, this.props.contracts); render () { - const { step } = this.state; + const { step } = this.store; return ( - { this.renderStep(step) } + steps={ [ + , + + ] } + visible> + { this.renderStep() } ); } - renderStep (step) { + renderStep () { + const { step } = this.store; + switch (step) { case 0: return this.renderContractTypeSelector(); + default: return this.renderFields(); } } renderContractTypeSelector () { - const { abiTypeIndex } = this.state; + const { abiTypeIndex, abiTypes } = this.store; return ( ); } renderDialogActions () { - const { addressError, nameError, step } = this.state; - const hasError = !!(addressError || nameError); + const { step } = this.store; const cancelBtn = (