From 4ecb092ed356fb597825968caaa3819434b857cf Mon Sep 17 00:00:00 2001 From: Anthony Laibe Date: Tue, 28 Aug 2018 16:42:44 +0100 Subject: [PATCH] Remove last fiddle, and use code to compile --- embark-ui/src/actions/index.js | 10 +-- embark-ui/src/api/index.js | 2 +- embark-ui/src/containers/FiddleContainer.js | 69 ++++++++------------- embark-ui/src/reducers/index.js | 1 - embark-ui/src/reducers/selectors.js | 8 +-- embark-ui/src/routes.js | 2 +- embark-ui/src/sagas/index.js | 5 ++ lib/modules/pipeline/index.js | 2 +- lib/modules/solidity/index.js | 8 +-- 9 files changed, 44 insertions(+), 63 deletions(-) diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 8c512550..7a826915 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -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'; diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 09833a8f..27294eb6 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -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) { diff --git a/embark-ui/src/containers/FiddleContainer.js b/embark-ui/src/containers/FiddleContainer.js index b50c6ef7..bca56569 100644 --- a/embark-ui/src/containers/FiddleContainer.js +++ b/embark-ui/src/containers/FiddleContainer.js @@ -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: { 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( this._onDeployClick(e)} /> 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; } - }} + }} /> ); if (fiddle || (this.state.value && (fiddleError || fiddleDeployError))) { renderings.push( - fiddleFile.filename === 'temp')); -} - export function getEnsRecords(state) { return state.entities.ensRecords; } diff --git a/embark-ui/src/routes.js b/embark-ui/src/routes.js index b41316ba..dbae205f 100644 --- a/embark-ui/src/routes.js +++ b/embark-ui/src/routes.js @@ -17,7 +17,7 @@ const routes = ( - + } /> diff --git a/embark-ui/src/sagas/index.js b/embark-ui/src/sagas/index.js index e1f8a9d4..5df868e2 100644 --- a/embark-ui/src/sagas/index.js +++ b/embark-ui/src/sagas/index.js @@ -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) ]); diff --git a/lib/modules/pipeline/index.js b/lib/modules/pipeline/index.js index a05409c5..9d24fb01 100644 --- a/lib/modules/pipeline/index.js +++ b/lib/modules/pipeline/index.js @@ -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); }); } diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 318a500e..4b6e9765 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -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);