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`);
|
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});
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
||||||
{
|
{
|
||||||
|
|
|
@ -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));
|
||||||
|
|
|
@ -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}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue