// Copyright 2015-2017 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 React, { PropTypes, Component } from 'react'; import { FormattedMessage } from 'react-intl'; import { observer } from 'mobx-react'; import { connect } from 'react-redux'; import moment from 'moment'; import { throttle } from 'lodash'; import { Actionbar, ActionbarExport, ActionbarImport, Button, Dropdown, Input, Loading, Page, Toggle } from '~/ui'; import { CancelIcon, ListIcon, SaveIcon, SendIcon, SettingsIcon } from '~/ui/Icons'; import Editor from '~/ui/Editor'; import DeployContract from '../Contracts/DeployContract'; import LoadContract from './LoadContract'; import SaveContract from './SaveContract'; import ContractDevelopStore from './store'; import styles from './contractDevelop.css'; @observer class ContractDevelop extends Component { static propTypes = { accounts: PropTypes.object.isRequired, worker: PropTypes.object, workerError: PropTypes.any }; store = ContractDevelopStore.get(); state = { resizing: false, size: 65 }; componentWillMount () { const { worker } = this.props; if (worker !== undefined) { this.store.setWorker(worker); } this.throttledResize = throttle(this.applyResize, 100, { leading: true }); } componentDidMount () { this.store.setEditor(this.refs.editor); if (this.props.workerError) { this.store.setWorkerError(this.props.workerError); } // Wait for editor to be loaded window.setTimeout(() => { this.store.resizeEditor(); }, 2000); } // Set the worker if not set before (eg. first page loading) componentWillReceiveProps (nextProps) { if (this.props.worker === undefined && nextProps.worker !== undefined) { this.store.setWorker(nextProps.worker); } if (this.props.workerError !== nextProps.workerError) { this.store.setWorkerError(nextProps.workerError); } } render () { const { sourcecode } = this.store; const { size, resizing } = this.state; const annotations = this.store.annotations .slice() .filter((a) => a.contract === ''); return (
{ this.renderDeployModal() } { this.renderSaveModal() } { this.renderLoadModal() } { this.renderActionBar() }

{ this.renderTitle() }

{ this.renderParameters() }
); } renderTitle () { const { selectedContract } = this.store; if (!selectedContract || !selectedContract.name) { return ( ); } return ( { selectedContract.name } } > ); } renderActionBar () { const { sourcecode, selectedContract } = this.store; const filename = selectedContract && selectedContract.name ? selectedContract.name .replace(/[^a-z0-9]+/gi, '-') .replace(/-$/, '') .toLowerCase() : 'contract.sol'; const extension = /\.sol$/.test(filename) ? '' : '.sol'; const buttons = [