// Copyright 2015, 2016 Parity Technologies (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 BigNumber from 'bignumber.js'; import { pick } from 'lodash'; import { observer } from 'mobx-react'; import React, { Component, PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { toWei } from '~/api/util/wei'; import { BusyStep, Button, CompletedStep, GasPriceEditor, IdentityIcon, Modal, TxHash } from '~/ui'; import { CancelIcon, DoneIcon, NextIcon, PrevIcon } from '~/ui/Icons'; import { MAX_GAS_ESTIMATION } from '~/util/constants'; import { validateAddress, validateUint } from '~/util/validation'; import { parseAbiType } from '~/util/abi'; import AdvancedStep from './AdvancedStep'; import DetailsStep from './DetailsStep'; import { ERROR_CODES } from '~/api/transport/error'; const STEP_DETAILS = 0; const STEP_BUSY_OR_ADVANCED = 1; const STEP_BUSY = 2; const TITLES = { transfer: , sending: , complete: , advanced: , rejected: }; const STAGES_BASIC = [TITLES.transfer, TITLES.sending, TITLES.complete]; const STAGES_ADVANCED = [TITLES.transfer, TITLES.advanced, TITLES.sending, TITLES.complete]; @observer class ExecuteContract extends Component { static contextTypes = { api: PropTypes.object.isRequired, store: PropTypes.object.isRequired } static propTypes = { accounts: PropTypes.object, balances: PropTypes.object, contract: PropTypes.object.isRequired, fromAddress: PropTypes.string, gasLimit: PropTypes.object.isRequired, isTest: PropTypes.bool, onClose: PropTypes.func.isRequired, onFromAddressChange: PropTypes.func.isRequired } gasStore = new GasPriceEditor.Store(this.context.api, { gasLimit: this.props.gasLimit }); state = { advancedOptions: false, amount: '0', amountError: null, busyState: null, fromAddressError: null, func: null, funcError: null, minBlock: '0', minBlockError: null, rejected: false, sending: false, step: STEP_DETAILS, txhash: null, values: [], valuesError: [] } componentDidMount () { const { contract } = this.props; const functions = contract.functions .filter((func) => !func.constant) .sort((a, b) => (a.name || '').localeCompare(b.name || '')); this.onFuncChange(null, functions[0]); } componentWillReceiveProps (newProps) { if (newProps.fromAddress !== this.props.fromAddress) { this.estimateGas(newProps.fromAddress); } } render () { const { advancedOptions, rejected, sending, step } = this.state; const steps = advancedOptions ? STAGES_ADVANCED : STAGES_BASIC; if (rejected) { steps[steps.length - 1] = TITLES.rejected; } return ( { this.renderStep() } ); } renderDialogActions () { const { onClose, fromAddress } = this.props; const { advancedOptions, sending, step, fromAddressError, minBlockError, valuesError } = this.state; const hasError = fromAddressError || minBlockError || valuesError.find((error) => error); const cancelBtn = (