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`);
}
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});
}

View File

@ -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 (
<React.Fragment>
<Fiddle code={code} onCodeChange={this.props.fetchCodeCompilation} />
<Fiddle onCodeChange={this.props.fetchCodeCompilation} />
<h2>Result</h2>
{
!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,
{

View File

@ -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));

View File

@ -17,16 +17,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}));
});
}