From e2a49b7d0198203e02c326c01e08343c01481011 Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 7 Aug 2018 09:40:20 +0100 Subject: [PATCH] Display compilation result --- embark-ui/src/components/Fiddle.js | 5 ++-- embark-ui/src/containers/FiddleContainer.js | 33 ++++++++------------- embark-ui/src/reducers/index.js | 5 ++-- lib/modules/solidity/index.js | 4 +-- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/embark-ui/src/components/Fiddle.js b/embark-ui/src/components/Fiddle.js index 81525d17..fe1730ed 100644 --- a/embark-ui/src/components/Fiddle.js +++ b/embark-ui/src/components/Fiddle.js @@ -4,7 +4,7 @@ import 'brace/mode/javascript'; import 'brace/theme/tomorrow_night_blue'; import 'ace-mode-solidity/build/remix-ide/mode-solidity'; -const Fiddle = ({onCodeChange}) => { +const Fiddle = ({onCodeChange, value}) => { return ( @@ -16,7 +16,8 @@ const Fiddle = ({onCodeChange}) => { name="blah1" height="60em" width="100%" - onChange={(e) => onCodeChange(e)} + onChange={onCodeChange} + value={value} /> ); diff --git a/embark-ui/src/containers/FiddleContainer.js b/embark-ui/src/containers/FiddleContainer.js index 5c9ce81d..def691d9 100644 --- a/embark-ui/src/containers/FiddleContainer.js +++ b/embark-ui/src/containers/FiddleContainer.js @@ -5,44 +5,37 @@ import {fetchCodeCompilation} from '../actions'; import Fiddle from '../components/Fiddle'; class FiddleContainer extends Component { - componentWillMount() { - + + constructor(props){ + super(props) + this.state = { value: ''}; } + onCodeChange(newValue) { + this.setState({value: newValue}); + this.props.fetchCodeCompilation(newValue); + } render() { - const { compilationResult } = this.props; - - const code = 'hello world'; - console.log('rendering fiddle, compilation result = ' + compilationResult); + const { fiddles } = this.props; return ( - + this.onCodeChange(n)} />

Result

- { - !compilationResult - ? - 'No compilation results yet' - : - compilationResult.error - ? - Error API... - : - compilationResult - } +

{ fiddles.data ? JSON.stringify(fiddles.data) : 'No compilation results yet'}

); } } function mapStateToProps(state) { return { - compilationResult: state.compilationResult + fiddles: state.fiddles }; } FiddleContainer.propTypes = { - compilationResult: PropTypes.object, + fiddles: PropTypes.object, fetchCodeCompilation: PropTypes.func }; diff --git a/embark-ui/src/reducers/index.js b/embark-ui/src/reducers/index.js index 19275d67..3b941247 100644 --- a/embark-ui/src/reducers/index.js +++ b/embark-ui/src/reducers/index.js @@ -1,5 +1,6 @@ import {combineReducers} from 'redux'; import {REQUEST} from "../actions"; +import fiddleRecuder from './fiddleReducer'; const BN_FACTOR = 10000; @@ -86,7 +87,6 @@ function entities(state = entitiesDefaultState, action) { } function errorMessage(state = null, action) { - return action.error || state; } function loading(_state = false, action) { @@ -96,7 +96,8 @@ function loading(_state = false, action) { const rootReducer = combineReducers({ entities, loading, - errorMessage + errorMessage, + fiddles: fiddleRecuder }); export default rootReducer; diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 53767912..76af3e39 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -26,9 +26,9 @@ class Solidity { '/embark-api/contract/compile', (req, res) => { console.log('=====> POST contract/compile, req = ' + JSON.stringify(req.body)); - this.events.request("contract:compile", req.body.code, (compilationResult) => { + this.events.request("contract:compile", req.body.code, (error, compilationResult) => { console.log('=====> POST contract/compile, result = ' + JSON.stringify(compilationResult)); - res.send(JSON.stringify({compilationResult: compilationResult})); + res.send(JSON.stringify({compilationResult})); }); } );