Code compilation API working, but not updating state
This commit is contained in:
parent
ddcccb3c2d
commit
1d13c71d83
|
@ -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});
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -35,11 +37,15 @@ class FiddleContainer extends Component {
|
|||
}
|
||||
function mapStateToProps(state) {
|
||||
return {
|
||||
code: state.code,
|
||||
options: state.options
|
||||
compilationResult: state.compilationResult
|
||||
};
|
||||
}
|
||||
|
||||
FiddleContainer.propTypes = {
|
||||
compilationResult: PropTypes.object,
|
||||
fetchCodeCompilation: PropTypes.func
|
||||
};
|
||||
|
||||
export default connect(
|
||||
mapStateToProps,
|
||||
{
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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}));
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue