Code compilation API working, but not updating state

This commit is contained in:
emizzle 2018-08-07 16:20:32 +10:00 committed by Pascal Precht
parent ddcccb3c2d
commit 1d13c71d83
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
4 changed files with 19 additions and 12 deletions

View File

@ -96,6 +96,6 @@ export function webSocketBlockHeader() {
return new WebSocket(`${constants.wsEndpoint}/blockchain/blockHeader`); return new WebSocket(`${constants.wsEndpoint}/blockchain/blockHeader`);
} }
export function fetchCodeCompilation() { export function fetchCodeCompilation(codeToCompile) {
return axios.post('http://localhost:8000/embark-api/contract/compile'); return axios.post(constants.httpEndpoint + '/contract/compile', {code: codeToCompile});
} }

View File

@ -1,5 +1,6 @@
import React, {Component} from 'react'; import React, {Component} from 'react';
import {connect} from 'react-redux'; import {connect} from 'react-redux';
import PropTypes from 'prop-types';
import {fetchCodeCompilation} from '../actions'; import {fetchCodeCompilation} from '../actions';
import Fiddle from '../components/Fiddle'; import Fiddle from '../components/Fiddle';
@ -13,10 +14,11 @@ class FiddleContainer extends Component {
const { compilationResult } = this.props; const { compilationResult } = this.props;
const code = 'hello world'; const code = 'hello world';
console.log('rendering fiddle, compilation result = ' + compilationResult);
return ( return (
<React.Fragment> <React.Fragment>
<Fiddle code={code} onCodeChange={this.props.fetchCodeCompilation} /> <Fiddle onCodeChange={this.props.fetchCodeCompilation} />
<h2>Result</h2> <h2>Result</h2>
{ {
!compilationResult !compilationResult
@ -35,11 +37,15 @@ class FiddleContainer extends Component {
} }
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
code: state.code, compilationResult: state.compilationResult
options: state.options
}; };
} }
FiddleContainer.propTypes = {
compilationResult: PropTypes.object,
fetchCodeCompilation: PropTypes.func
};
export default connect( export default connect(
mapStateToProps, mapStateToProps,
{ {

View File

@ -157,9 +157,9 @@ export function *watchCommunicationVersion() {
yield takeEvery(actions.MESSAGE_VERSION[actions.REQUEST], fetchCommunicationVersion); yield takeEvery(actions.MESSAGE_VERSION[actions.REQUEST], fetchCommunicationVersion);
} }
export function* fetchCodeCompilation() { export function* fetchCodeCompilation(action) {
try { try {
const codeCompilationResult = yield call(api.fetchCodeCompilation); const codeCompilationResult = yield call(api.fetchCodeCompilation, action.codeToCompile);
yield put(actions.receiveCodeCompilation(codeCompilationResult)); yield put(actions.receiveCodeCompilation(codeCompilationResult));
} catch (e) { } catch (e) {
yield put(actions.receiveCodeCompilationError(e)); yield put(actions.receiveCodeCompilationError(e));

View File

@ -17,16 +17,17 @@ class Solidity {
this.events.setCommandHandler("contract:compile", (contractCode, cb) => { this.events.setCommandHandler("contract:compile", (contractCode, cb) => {
let input = []; const input = {'fiddler': {content: contractCode.replace(/\r\n/g, '\n')}};
input['fiddler'] = {content: contractCode.replace(/\r\n/g, '\n')}; this.compile_solidity_code(input, {}, cb);
this.compile_solidity_code(input, cb);
}); });
embark.registerAPICall( embark.registerAPICall(
'post', 'post',
'/embark-api/contract/compile', '/embark-api/contract/compile',
(req, res) => { (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})); res.send(JSON.stringify({compilationResult: compilationResult}));
}); });
} }