From 4ea9ae87cb11439877286b9d9ac78a3ed85403bf Mon Sep 17 00:00:00 2001 From: emizzle Date: Tue, 7 Aug 2018 16:20:32 +1000 Subject: [PATCH] Code compilation API working, but not updating state --- embark-ui/src/api/index.js | 4 ++-- embark-ui/src/containers/FiddleContainer.js | 14 ++++++++++---- embark-ui/src/sagas/index.js | 4 ++-- lib/modules/solidity/index.js | 9 +++++---- 4 files changed, 19 insertions(+), 12 deletions(-) diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 51673720..1b159d60 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -96,6 +96,6 @@ export function webSocketBlockHeader() { return new WebSocket(`${constants.wsEndpoint}/blockchain/blockHeader`); } -export function fetchCodeCompilation() { - return axios.post('http://localhost:8000/embark-api/contract/compile'); +export function fetchCodeCompilation(codeToCompile) { + return axios.post(constants.httpEndpoint + '/contract/compile', {code: codeToCompile}); } diff --git a/embark-ui/src/containers/FiddleContainer.js b/embark-ui/src/containers/FiddleContainer.js index f65b66d0..5c9ce81d 100644 --- a/embark-ui/src/containers/FiddleContainer.js +++ b/embark-ui/src/containers/FiddleContainer.js @@ -1,5 +1,6 @@ import React, {Component} from 'react'; import {connect} from 'react-redux'; +import PropTypes from 'prop-types'; import {fetchCodeCompilation} from '../actions'; import Fiddle from '../components/Fiddle'; @@ -13,10 +14,11 @@ class FiddleContainer extends Component { const { compilationResult } = this.props; const code = 'hello world'; + console.log('rendering fiddle, compilation result = ' + compilationResult); return ( - +

Result

{ !compilationResult @@ -34,12 +36,16 @@ class FiddleContainer extends Component { } } function mapStateToProps(state) { - return { - code: state.code, - options: state.options + return { + compilationResult: state.compilationResult }; } +FiddleContainer.propTypes = { + compilationResult: PropTypes.object, + fetchCodeCompilation: PropTypes.func +}; + export default connect( mapStateToProps, { diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index 6b661d45..b28fe19f 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -157,9 +157,9 @@ export function *watchCommunicationVersion() { yield takeEvery(actions.MESSAGE_VERSION[actions.REQUEST], fetchCommunicationVersion); } -export function* fetchCodeCompilation() { +export function* fetchCodeCompilation(action) { try { - const codeCompilationResult = yield call(api.fetchCodeCompilation); + const codeCompilationResult = yield call(api.fetchCodeCompilation, action.codeToCompile); yield put(actions.receiveCodeCompilation(codeCompilationResult)); } catch (e) { yield put(actions.receiveCodeCompilationError(e)); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 5851f0ec..740fa652 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -16,16 +16,17 @@ class Solidity { this.events.setCommandHandler("contract:compile", (contractCode, cb) => { - let input = []; - input['fiddler'] = {content: contractCode.replace(/\r\n/g, '\n')}; - this.compile_solidity_code(input, cb); + const input = {'fiddler': {content: contractCode.replace(/\r\n/g, '\n')}}; + this.compile_solidity_code(input, {}, cb); }); embark.registerAPICall( 'post', '/embark-api/contract/compile', (req, res) => { - this.events.request("contract:compile", req.body.contractCode, (compilationResult) => { + console.log('=====> POST contract/compile, req = ' + JSON.stringify(req.body)); + this.events.request("contract:compile", req.body.code, (compilationResult) => { + console.log('=====> POST contract/compile, result = ' + JSON.stringify(compilationResult)); res.send(JSON.stringify({compilationResult: compilationResult})); }); }