From 7e1a6848ae900ae7a5614a0e39bf1c0ef065db10 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Thu, 25 Oct 2018 09:43:50 +0100 Subject: [PATCH] Add function to contract deployment --- .../src/components/ContractsDeployment.js | 67 ++++++++++++++----- .../containers/TextEditorAsideContainer.js | 10 +-- 2 files changed, 57 insertions(+), 20 deletions(-) diff --git a/embark-ui/src/components/ContractsDeployment.js b/embark-ui/src/components/ContractsDeployment.js index 70df96ed..dcdca38c 100644 --- a/embark-ui/src/components/ContractsDeployment.js +++ b/embark-ui/src/components/ContractsDeployment.js @@ -17,6 +17,7 @@ import { import classNames from 'classnames'; import {DEPLOYMENT_PIPELINES} from '../constants'; import Description from './Description'; +import ContractOverviewContainer from '../containers/ContractOverviewContainer'; const orderClassName = (address) => { return classNames('mr-4', { @@ -157,12 +158,12 @@ class Web3Contract extends React.Component { } } -const EmbarkContract = ({contract}) => ( +const EmbarkContract = ({contract, toggleContractOverview}) => ( + toggleContractOverview(contract)}> {contract.address && `${contract.className} deployed at ${contract.address}`} {!contract.address && `${contract.className} not deployed`} - + }> {contract.address &&

Arguments: {JSON.stringify(contract.args)}

} {contract.transactionHash && @@ -214,12 +215,12 @@ const ContractsHeader = ({deploymentPipeline, updateDeploymentPipeline}) => ( ); -const Contract = ({web3, contract, deploymentPipeline, web3Deploy, web3EstimateGas, web3Deployments, web3GasEstimates}) => { +const Contract = ({web3, contract, deploymentPipeline, web3Deploy, web3EstimateGas, web3Deployments, web3GasEstimates, toggleContractOverview}) => { const deployment = web3Deployments[contract.className]; const gasEstimate = web3GasEstimates[contract.className]; switch (deploymentPipeline) { case DEPLOYMENT_PIPELINES.embark: - return ; + return ; case DEPLOYMENT_PIPELINES.injectedWeb3: return ( - - - {props.contracts.sort((a, b) => a.index - b.index).map(contract => )} - -); +class ContractsDeployment extends React.Component { + constructor(props) { + super(props); + this.state = { currentContractOverview: null } + } -Contracts.propTypes = { + toggleContractOverview(contract) { + if (this.state.currentContractOverview && this.state.currentContractOverview.className === contract.className) { + return this.setState({currentContractOverview: null}); + } + this.setState({currentContractOverview: contract}); + } + + isContractOverviewOpen() { + return this.state.currentContractOverview && this.props.deploymentPipeline === DEPLOYMENT_PIPELINES.embark; + } + + render() { + return ( + + + + {this.props.contracts.sort((a, b) => a.index - b.index).map(contract => ( + this.toggleContractOverview(contract)} + {...this.props} /> + ))} + + {this.isContractOverviewOpen() && + + + +

{this.state.currentContractOverview.className} - Overview

+ +
+
+ + } +
+ ) + } +} + +ContractsDeployment.propTypes = { contracts: PropTypes.array, deploymentPipeline: PropTypes.string, updateDeploymentPipeline: PropTypes.func, @@ -252,5 +289,5 @@ Contracts.propTypes = { web3EstimateGas: PropTypes.func }; -export default Contracts; +export default ContractsDeployment; diff --git a/embark-ui/src/containers/TextEditorAsideContainer.js b/embark-ui/src/containers/TextEditorAsideContainer.js index 6c7d3c07..84456220 100644 --- a/embark-ui/src/containers/TextEditorAsideContainer.js +++ b/embark-ui/src/containers/TextEditorAsideContainer.js @@ -1,7 +1,7 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; import PropTypes from 'prop-types'; -import { Card, CardBody, CardTitle } from 'reactstrap'; +import {Card, CardBody} from 'reactstrap'; import Preview from '../components/Preview'; import {contracts as contractsAction} from '../actions'; @@ -25,7 +25,7 @@ class TextEditorAsideContainer extends Component { return ( - {contract.className} - Details +

{contract.className} - Details

@@ -36,7 +36,7 @@ class TextEditorAsideContainer extends Component { return ( - {contract.className} - Details +

{contract.className} - Details

@@ -47,7 +47,7 @@ class TextEditorAsideContainer extends Component { return ( - {contract.className} - Transactions +

{contract.className} - Transactions

)
@@ -58,7 +58,7 @@ class TextEditorAsideContainer extends Component { return ( - {contract.className} - Overview +

{contract.className} - Overview