// 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 moment from 'moment'; import React, { Component, PropTypes } from 'react'; import { FormattedMessage } from 'react-intl'; import { Button, List, Portal, Tabs } from '@parity/ui'; import Editor from '@parity/ui/Editor'; import { CancelIcon, CheckIcon, DeleteIcon } from '@parity/ui/Icons'; import styles from './loadContract.css'; const REMOVAL_STYLE = { backgroundColor: 'none', cursor: 'default' }; // const SELECTED_STYLE = { // backgroundColor: 'rgba(255, 255, 255, 0.1)' // }; export default class LoadContract extends Component { static propTypes = { onClose: PropTypes.func.isRequired, onLoad: PropTypes.func.isRequired, onDelete: PropTypes.func.isRequired, contracts: PropTypes.object.isRequired, snippets: PropTypes.object.isRequired }; state = { activeTab: -1, selected: -1, deleteRequest: false, deleteId: -1 }; render () { const { deleteRequest } = this.state; return ( ) : ( ) } > { this.renderBody() } ); } renderBody () { const { activeTab, deleteRequest } = this.state; if (deleteRequest) { return this.renderConfirmRemoval(); } const { contracts, snippets } = this.props; const contractsTab = Object.keys(contracts).length === 0 ? null : ( ); return (
] } /> { this.renderEditor() } { this.state.activeTab === 0 ? ( } onChange={ this.onClickContract } items={ this.renderContracts(contracts) } /> ) : ( } onClick={ this.onClickContract } items={ this.renderContracts(snippets, false) } /> ) }
); } renderConfirmRemoval () { const { deleteId } = this.state; const { name, timestamp, sourcecode } = this.props.contracts[deleteId]; return (

} style={ REMOVAL_STYLE } />
); } renderEditor () { const { contracts, snippets } = this.props; const { selected } = this.state; const mergedContracts = Object.assign({}, contracts, snippets); if (selected === -1 || !mergedContracts[selected]) { return null; } const { sourcecode, name } = mergedContracts[selected]; return (

{ name }

); } renderContracts (contracts, removable = true) { return Object .values(contracts) .map((contract) => { const { id, name, timestamp, description } = contract; const onDelete = () => this.onDeleteRequest(id); return { key: id, label: name, buttons: removable && (