mirror of https://github.com/embarklabs/embark.git
Remove last fiddle, and use code to compile
This commit is contained in:
parent
cd176a5f95
commit
4ecb092ed3
|
@ -171,8 +171,8 @@ export const ensRecords = {
|
|||
export const FIDDLE = createRequestTypes('FIDDLE');
|
||||
export const fiddle = {
|
||||
post: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}),
|
||||
success: (fiddle) => {
|
||||
return action(FIDDLE[SUCCESS], {fiddles: [fiddle]});
|
||||
success: (fiddle, payload) => {
|
||||
return action(FIDDLE[SUCCESS], {fiddles: [{...fiddle, ...payload}]});
|
||||
},
|
||||
failure: (error) => action(FIDDLE[FAILURE], {error})
|
||||
};
|
||||
|
@ -189,14 +189,10 @@ export const fiddleDeploy = {
|
|||
export const FIDDLE_FILE = createRequestTypes('FIDDLE_FILE');
|
||||
export const fiddleFile = {
|
||||
request: () => action(FIDDLE_FILE[REQUEST]),
|
||||
success: (source) => action(FIDDLE_FILE[SUCCESS], {fiddleFiles: [{source, filename: 'temp'}]}),
|
||||
success: (codeToCompile) => action(FIDDLE_FILE[SUCCESS], {codeToCompile}),
|
||||
failure: (error) => action(FIDDLE_FILE[FAILURE], {error})
|
||||
};
|
||||
|
||||
export const putLastFiddle = (lastFiddleValue) => {
|
||||
return ({ type: FIDDLE_FILE[SUCCESS], fiddleFiles: [{source: lastFiddleValue, filename: 'temp'}] });
|
||||
};
|
||||
|
||||
// Web Socket
|
||||
export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS';
|
||||
export const WATCH_NEW_CONTRACT_LOGS = 'WATCH_NEW_CONTRACT_LOGS';
|
||||
|
|
|
@ -129,7 +129,7 @@ export function webSocketBlockHeader() {
|
|||
}
|
||||
|
||||
export function postFiddle(payload) {
|
||||
return post('/contract/compile', {code: payload.codeToCompile});
|
||||
return post('/contract/compile', payload);
|
||||
}
|
||||
|
||||
export function postFiddleDeploy(payload) {
|
||||
|
|
|
@ -4,16 +4,15 @@ import React, {Component} from 'react';
|
|||
import {connect} from 'react-redux';
|
||||
import PropTypes from 'prop-types';
|
||||
import {
|
||||
fiddle as fiddleAction,
|
||||
fiddleDeploy as fiddleDeployAction,
|
||||
fiddleFile as fiddleFileAction,
|
||||
putLastFiddle as putLastFiddleAction
|
||||
fiddle as fiddleAction,
|
||||
fiddleDeploy as fiddleDeployAction,
|
||||
fiddleFile as fiddleFileAction
|
||||
} from '../actions';
|
||||
import Fiddle from '../components/Fiddle';
|
||||
import FiddleResults from '../components/FiddleResults';
|
||||
import FiddleResultsSummary from '../components/FiddleResultsSummary';
|
||||
import scrollToComponent from 'react-scroll-to-component';
|
||||
import {getFiddle, getFiddleDeploy, getLastFiddle} from "../reducers/selectors";
|
||||
import {getFiddle, getFiddleDeploy} from "../reducers/selectors";
|
||||
import CompilerError from "../components/CompilerError";
|
||||
|
||||
class FiddleContainer extends Component {
|
||||
|
@ -32,22 +31,15 @@ class FiddleContainer extends Component {
|
|||
|
||||
componentDidMount() {
|
||||
this.setState({loadingMessage: 'Loading saved state...'});
|
||||
this.props.fetchLastFiddle();
|
||||
}
|
||||
componentDidUpdate(prevProps){
|
||||
if(this.props.lastFiddle && //!(this.props.fiddle && this.state.value === '') &&
|
||||
(
|
||||
(prevProps.lastFiddle !== this.props.lastFiddle)
|
||||
)
|
||||
)
|
||||
{
|
||||
this._onCodeChange(this.props.lastFiddle);
|
||||
if (!this.props.fiddle) {
|
||||
this.props.fetchLastFiddle();
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount(){
|
||||
//this.props.fetchLastFiddle();
|
||||
this.props.putLastFiddle(this.state.value); // force update on next load
|
||||
componentDidUpdate() {
|
||||
if(!this.state.value && this.props.fiddle) {
|
||||
this.setState({value: this.props.fiddle.codeToCompile});
|
||||
}
|
||||
}
|
||||
|
||||
_onCodeChange(newValue) {
|
||||
|
@ -56,7 +48,6 @@ class FiddleContainer extends Component {
|
|||
this.compileTimeout = setTimeout(() => {
|
||||
this.setState({loadingMessage: 'Compiling...'});
|
||||
this.props.postFiddle(newValue);
|
||||
//this.props.putLastFiddle(newValue);
|
||||
}, 1000);
|
||||
|
||||
}
|
||||
|
@ -74,7 +65,7 @@ class FiddleContainer extends Component {
|
|||
});
|
||||
errors.push({
|
||||
solcError: error,
|
||||
node:
|
||||
node:
|
||||
<CompilerError
|
||||
onClick={(e) => { this._onErrorClick(e, annotation); }}
|
||||
key={`${errorType}_${index}`}
|
||||
|
@ -109,7 +100,7 @@ class FiddleContainer extends Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const {fiddle, loading, fiddleError, fiddleDeployError, deployedContracts, lastFiddle} = this.props;
|
||||
const {fiddle, loading, fiddleError, fiddleDeployError, deployedContracts} = this.props;
|
||||
const {loadingMessage, value, readOnly} = this.state;
|
||||
let renderings = [];
|
||||
let warnings = [];
|
||||
|
@ -121,7 +112,7 @@ class FiddleContainer extends Component {
|
|||
renderings.push(
|
||||
<React.Fragment key="fiddle">
|
||||
<FiddleResultsSummary
|
||||
errors={errors}
|
||||
errors={errors}
|
||||
warnings={warnings}
|
||||
isLoading={loading}
|
||||
loadingMessage={loadingMessage}
|
||||
|
@ -131,27 +122,26 @@ class FiddleContainer extends Component {
|
|||
onDeployClick={(e) => this._onDeployClick(e)}
|
||||
/>
|
||||
<Fiddle
|
||||
// value={fiddle ? this.state.value : lastFiddle}
|
||||
value={value !== undefined ? value : lastFiddle}
|
||||
value={value}
|
||||
readOnly={readOnly}
|
||||
onCodeChange={(n) => this._onCodeChange(n)}
|
||||
errors={errors}
|
||||
onCodeChange={(n) => this._onCodeChange(n)}
|
||||
errors={errors}
|
||||
warnings={warnings}
|
||||
ref={(fiddle) => {
|
||||
ref={(fiddle) => {
|
||||
if(fiddle) {
|
||||
this.editor = fiddle.ace.editor;
|
||||
this.editor = fiddle.ace.editor;
|
||||
this.ace = fiddle.ace;
|
||||
}
|
||||
}}
|
||||
}}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
if (fiddle || (this.state.value && (fiddleError || fiddleDeployError))) {
|
||||
renderings.push(
|
||||
<FiddleResults
|
||||
key="results"
|
||||
errors={errors}
|
||||
warnings={warnings}
|
||||
<FiddleResults
|
||||
key="results"
|
||||
errors={errors}
|
||||
warnings={warnings}
|
||||
fatalFiddle={fiddleError}
|
||||
fatalFiddleDeploy={fiddleDeployError}
|
||||
isLoading={loading}
|
||||
|
@ -171,13 +161,11 @@ class FiddleContainer extends Component {
|
|||
function mapStateToProps(state) {
|
||||
const fiddle = getFiddle(state);
|
||||
const deployedFiddle = getFiddleDeploy(state);
|
||||
const lastFiddle = getLastFiddle(state);
|
||||
return {
|
||||
fiddle: fiddle.data,
|
||||
return {
|
||||
fiddle: fiddle.data,
|
||||
deployedContracts: deployedFiddle.data,
|
||||
fiddleError: fiddle.error,
|
||||
fiddleDeployError: deployedFiddle.error,
|
||||
lastFiddle: (lastFiddle && lastFiddle.source && !lastFiddle.source.error) ? lastFiddle.source : undefined,
|
||||
loading: state.loading
|
||||
};
|
||||
}
|
||||
|
@ -190,9 +178,7 @@ FiddleContainer.propTypes = {
|
|||
postFiddle: PropTypes.func,
|
||||
postFiddleDeploy: PropTypes.func,
|
||||
deployedContracts: PropTypes.string,
|
||||
fetchLastFiddle: PropTypes.func,
|
||||
lastFiddle: PropTypes.string,
|
||||
putLastFiddle: PropTypes.func
|
||||
fetchLastFiddle: PropTypes.func
|
||||
};
|
||||
|
||||
export default connect(
|
||||
|
@ -200,7 +186,6 @@ export default connect(
|
|||
{
|
||||
postFiddle: fiddleAction.post,
|
||||
postFiddleDeploy: fiddleDeployAction.post,
|
||||
fetchLastFiddle: fiddleFileAction.request,
|
||||
putLastFiddle: putLastFiddleAction
|
||||
fetchLastFiddle: fiddleFileAction.request
|
||||
},
|
||||
)(FiddleContainer);
|
||||
|
|
|
@ -21,7 +21,6 @@ const entitiesDefaultState = {
|
|||
messageChannels: [],
|
||||
fiddles: [],
|
||||
fiddleDeploys: [],
|
||||
fiddleFiles: [],
|
||||
versions: [],
|
||||
plugins: [],
|
||||
ensRecords: []
|
||||
|
|
|
@ -110,22 +110,18 @@ export function getMessages(state) {
|
|||
|
||||
export function getFiddle(state) {
|
||||
return {
|
||||
data: _.last(state.entities.fiddles),
|
||||
data: _.last(state.entities.fiddles),
|
||||
error: state.errorEntities.fiddles
|
||||
};
|
||||
}
|
||||
|
||||
export function getFiddleDeploy(state) {
|
||||
return {
|
||||
data: _.last(state.entities.fiddleDeploys),
|
||||
data: _.last(state.entities.fiddleDeploys),
|
||||
error: state.errorEntities.fiddleDeploys
|
||||
};
|
||||
}
|
||||
|
||||
export function getLastFiddle(state) {
|
||||
return state.entities.fiddleFiles.find((fiddleFile => fiddleFile.filename === 'temp'));
|
||||
}
|
||||
|
||||
export function getEnsRecords(state) {
|
||||
return state.entities.ensRecords;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ const routes = (
|
|||
<Route path="/embark/processes/" component={ProcessesLayout} />
|
||||
<Route path="/embark/contracts/:contractName" component={ContractContainer} />
|
||||
<Route path="/embark/contracts" component={ContractsContainer} />
|
||||
<Route path="/embark/fiddle" component={FiddleContainer} />
|
||||
<Route path="/embark/fiddle" render={() => <FiddleContainer />} />
|
||||
<Route component={NoMatch} />
|
||||
</Switch>
|
||||
</React.Fragment>
|
||||
|
|
|
@ -138,6 +138,10 @@ export function *watchPostFiddle() {
|
|||
yield takeEvery(actions.FIDDLE[actions.REQUEST], postFiddle);
|
||||
}
|
||||
|
||||
export function *watchFetchLastFiddleSuccess() {
|
||||
yield takeEvery(actions.FIDDLE_FILE[actions.SUCCESS], postFiddle);
|
||||
}
|
||||
|
||||
export function *watchPostFiddleDeploy() {
|
||||
yield takeEvery(actions.FIDDLE_DEPLOY[actions.REQUEST], postFiddleDeploy);
|
||||
}
|
||||
|
@ -230,6 +234,7 @@ export default function *root() {
|
|||
fork(watchPostFiddle),
|
||||
fork(watchPostFiddleDeploy),
|
||||
fork(watchFetchLastFiddle),
|
||||
fork(watchFetchLastFiddleSuccess),
|
||||
fork(watchFetchEnsRecord),
|
||||
fork(watchPostEnsRecords)
|
||||
]);
|
||||
|
|
|
@ -52,7 +52,7 @@ class Pipeline {
|
|||
'/embark-api/files/lastfiddle',
|
||||
(req, res) => {
|
||||
fs.readFile(fs.dappPath('.embark/fiddles/temp.sol'), 'utf8', (err, source) => {
|
||||
if (err) return res.send({error: err});
|
||||
if (err) return res.send({error: err.message});
|
||||
res.send(source);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ class Solidity {
|
|||
'post',
|
||||
'/embark-api/contract/compile',
|
||||
(req, res) => {
|
||||
const input = {'fiddle': {content: req.body.code.replace(/\r\n/g, '\n')}};
|
||||
const input = {'fiddle': {content: req.body.codeToCompile.replace(/\r\n/g, '\n')}};
|
||||
this.compile_solidity_code(input, {}, true, (errors, compilationResult) => {
|
||||
// write code to filesystem so we can view the source after page refresh
|
||||
const className = !compilationResult ? 'temp' : Object.keys(compilationResult).join('_');
|
||||
this._writeFiddleToFile(req.body.code, className, Boolean(compilationResult), (err) => {
|
||||
this._writeFiddleToFile(req.body.codeToCompile, className, Boolean(compilationResult), (err) => {
|
||||
if(err) this.logger.trace('Error writing fiddle to filesystem: ', err);
|
||||
}); // async, do not need to wait
|
||||
|
||||
|
@ -39,11 +39,11 @@ class Solidity {
|
|||
_writeFiddleToFile(code, className, isCompiled, cb){
|
||||
fs.mkdirp('.embark/fiddles', (err) => {
|
||||
if(err) return cb(err);
|
||||
|
||||
|
||||
// always write to temp.sol file
|
||||
const filePath = Solidity._getFiddlePath('temp');
|
||||
fs.writeFile(filePath, code, 'utf8', cb);
|
||||
|
||||
|
||||
// if it's compiled, also write to [classname].sol
|
||||
if(isCompiled){
|
||||
const filePath = Solidity._getFiddlePath(className);
|
||||
|
|
Loading…
Reference in New Issue