diff --git a/embark-ui/src/actions/index.js b/embark-ui/src/actions/index.js index 7a826915..94f87b50 100644 --- a/embark-ui/src/actions/index.js +++ b/embark-ui/src/actions/index.js @@ -170,7 +170,7 @@ export const ensRecords = { export const FIDDLE = createRequestTypes('FIDDLE'); export const fiddle = { - post: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}), + post: (codeToCompile, timestamp) => action(FIDDLE[REQUEST], {codeToCompile, timestamp}), success: (fiddle, payload) => { return action(FIDDLE[SUCCESS], {fiddles: [{...fiddle, ...payload}]}); }, diff --git a/embark-ui/src/api/index.js b/embark-ui/src/api/index.js index 27294eb6..a4ac1641 100644 --- a/embark-ui/src/api/index.js +++ b/embark-ui/src/api/index.js @@ -4,7 +4,7 @@ import constants from '../constants'; function get(path, params) { return axios.get(constants.httpEndpoint + path, params) .then((response) => { - return {response}; + return {response, error: null}; }).catch((error) => { return {response: null, error: error.message || 'Something bad happened'}; }); @@ -13,7 +13,7 @@ function get(path, params) { function post(path, params) { return axios.post(constants.httpEndpoint + path, params) .then((response) => { - return {response}; + return {response, error: null}; }) .catch((error) => { return {response: null, error: error.message || 'Something bad happened'}; diff --git a/embark-ui/src/containers/FiddleContainer.js b/embark-ui/src/containers/FiddleContainer.js index bca56569..b406c62a 100644 --- a/embark-ui/src/containers/FiddleContainer.js +++ b/embark-ui/src/containers/FiddleContainer.js @@ -22,6 +22,7 @@ class FiddleContainer extends Component { this.state = { value: undefined, loadingMessage: 'Loading...', + readOnly: true }; this.compileTimeout = null; @@ -31,24 +32,24 @@ class FiddleContainer extends Component { componentDidMount() { this.setState({loadingMessage: 'Loading saved state...'}); - if (!this.props.fiddle) { - this.props.fetchLastFiddle(); + this.props.fetchLastFiddle(); + } + + componentDidUpdate(prevProps) { + const {lastFiddle} = this.props; + if(this.state.value === '' && prevProps.lastFiddle === lastFiddle) return; + if((!this.state.value && lastFiddle && !lastFiddle.error) && this.state.value !== lastFiddle) { + this._onCodeChange(lastFiddle, true); } } - componentDidUpdate() { - if(!this.state.value && this.props.fiddle) { - this.setState({value: this.props.fiddle.codeToCompile}); - } - } - - _onCodeChange(newValue) { + _onCodeChange(newValue, immediate = false) { this.setState({readOnly: false, value: newValue}); if (this.compileTimeout) clearTimeout(this.compileTimeout); this.compileTimeout = setTimeout(() => { this.setState({loadingMessage: 'Compiling...'}); - this.props.postFiddle(newValue); - }, 1000); + this.props.postFiddle(newValue, Date.now()); + }, immediate ? 0 : 1000); } @@ -166,7 +167,8 @@ function mapStateToProps(state) { deployedContracts: deployedFiddle.data, fiddleError: fiddle.error, fiddleDeployError: deployedFiddle.error, - loading: state.loading + loading: state.loading, + lastFiddle: fiddle.data ? fiddle.data.codeToCompile : undefined }; } @@ -178,7 +180,8 @@ FiddleContainer.propTypes = { postFiddle: PropTypes.func, postFiddleDeploy: PropTypes.func, deployedContracts: PropTypes.string, - fetchLastFiddle: PropTypes.func + fetchLastFiddle: PropTypes.func, + lastFiddle: PropTypes.any }; export default connect( diff --git a/embark-ui/src/general.css b/embark-ui/src/general.css index 934ac06f..9bdf0438 100644 --- a/embark-ui/src/general.css +++ b/embark-ui/src/general.css @@ -22,7 +22,8 @@ } .text__new-line, .card.warnings-card .list-group-item, .card.errors-card .list-group-item { - white-space: pre-line; + white-space: pre-wrap; + font-family: monospace; } .card.card-fullscreen{ z-index: 6; diff --git a/embark-ui/src/reducers/selectors.js b/embark-ui/src/reducers/selectors.js index 361e49fd..a4b032e5 100644 --- a/embark-ui/src/reducers/selectors.js +++ b/embark-ui/src/reducers/selectors.js @@ -109,9 +109,11 @@ export function getMessages(state) { } export function getFiddle(state) { + const fiddleCompilation = _.last(state.entities.fiddles.sort((a, b) => { return (a.timestamp || 0) - (b.timestamp || 0); })); + const isNoTempFileError = Boolean(fiddleCompilation && fiddleCompilation.codeToCompile && fiddleCompilation.codeToCompile.error && fiddleCompilation.codeToCompile.error.indexOf('ENOENT') > -1); return { - data: _.last(state.entities.fiddles), - error: state.errorEntities.fiddles + data: fiddleCompilation, + error: isNoTempFileError ? undefined : state.errorEntities.fiddles }; } diff --git a/lib/modules/deployment/contract_deployer.js b/lib/modules/deployment/contract_deployer.js index ae97e002..658f0623 100644 --- a/lib/modules/deployment/contract_deployer.js +++ b/lib/modules/deployment/contract_deployer.js @@ -199,7 +199,7 @@ class ContractDeployer { // TODO: can be moved into a afterDeploy event // just need to figure out the gasLimit coupling issue - self.events.request('code-generator:contract:vanilla', contract, contract._gasLimit, (contractCode) => { + self.events.request('code-generator:contract:vanilla', contract, contract._gasLimit || false, (contractCode) => { self.events.request('runcode:eval', contractCode, () => {}, true); return callback(); }); diff --git a/lib/modules/solidity/index.js b/lib/modules/solidity/index.js index 4b6e9765..48cfd4c0 100644 --- a/lib/modules/solidity/index.js +++ b/lib/modules/solidity/index.js @@ -20,6 +20,9 @@ class Solidity { 'post', '/embark-api/contract/compile', (req, res) => { + if(typeof req.body.codeToCompile !== 'string'){ + return res.send({error: 'Body parameter \'codeToCompile\' must be a string'}); + } 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