Handle use cases that were failing
1) hanlde case when temp.sol doesn’t exist 2) delete all code - shouldn’t return last fiddle 3) Switch to different tab (ie contracts) then back to fiddle - fiddle should now remain.
This commit is contained in:
parent
68957f5dc8
commit
cd176a5f95
|
@ -171,7 +171,9 @@ export const ensRecords = {
|
||||||
export const FIDDLE = createRequestTypes('FIDDLE');
|
export const FIDDLE = createRequestTypes('FIDDLE');
|
||||||
export const fiddle = {
|
export const fiddle = {
|
||||||
post: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}),
|
post: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}),
|
||||||
success: (fiddle) => action(FIDDLE[SUCCESS], {fiddles: [fiddle]}),
|
success: (fiddle) => {
|
||||||
|
return action(FIDDLE[SUCCESS], {fiddles: [fiddle]});
|
||||||
|
},
|
||||||
failure: (error) => action(FIDDLE[FAILURE], {error})
|
failure: (error) => action(FIDDLE[FAILURE], {error})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -191,6 +193,10 @@ export const fiddleFile = {
|
||||||
failure: (error) => action(FIDDLE_FILE[FAILURE], {error})
|
failure: (error) => action(FIDDLE_FILE[FAILURE], {error})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const putLastFiddle = (lastFiddleValue) => {
|
||||||
|
return ({ type: FIDDLE_FILE[SUCCESS], fiddleFiles: [{source: lastFiddleValue, filename: 'temp'}] });
|
||||||
|
};
|
||||||
|
|
||||||
// Web Socket
|
// Web Socket
|
||||||
export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS';
|
export const WATCH_NEW_PROCESS_LOGS = 'WATCH_NEW_PROCESS_LOGS';
|
||||||
export const WATCH_NEW_CONTRACT_LOGS = 'WATCH_NEW_CONTRACT_LOGS';
|
export const WATCH_NEW_CONTRACT_LOGS = 'WATCH_NEW_CONTRACT_LOGS';
|
||||||
|
|
|
@ -3,7 +3,12 @@
|
||||||
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 PropTypes from 'prop-types';
|
||||||
import {fiddle as fiddleAction, fiddleDeploy as fiddleDeployAction, fiddleFile as fiddleFileAction} from '../actions';
|
import {
|
||||||
|
fiddle as fiddleAction,
|
||||||
|
fiddleDeploy as fiddleDeployAction,
|
||||||
|
fiddleFile as fiddleFileAction,
|
||||||
|
putLastFiddle as putLastFiddleAction
|
||||||
|
} from '../actions';
|
||||||
import Fiddle from '../components/Fiddle';
|
import Fiddle from '../components/Fiddle';
|
||||||
import FiddleResults from '../components/FiddleResults';
|
import FiddleResults from '../components/FiddleResults';
|
||||||
import FiddleResultsSummary from '../components/FiddleResultsSummary';
|
import FiddleResultsSummary from '../components/FiddleResultsSummary';
|
||||||
|
@ -16,8 +21,9 @@ class FiddleContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
value: '',
|
value: undefined,
|
||||||
loadingMessage: ''
|
loadingMessage: 'Loading...',
|
||||||
|
readOnly: true
|
||||||
};
|
};
|
||||||
this.compileTimeout = null;
|
this.compileTimeout = null;
|
||||||
this.ace = null;
|
this.ace = null;
|
||||||
|
@ -25,21 +31,32 @@ class FiddleContainer extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
this.setState({loadingMessage: 'Loading saved state...'});
|
||||||
this.props.fetchLastFiddle();
|
this.props.fetchLastFiddle();
|
||||||
|
|
||||||
}
|
}
|
||||||
componentDidUpdate(prevProps){
|
componentDidUpdate(prevProps){
|
||||||
if(this.props.lastFiddle && (prevProps.lastFiddle !== this.props.lastFiddle)){
|
if(this.props.lastFiddle && //!(this.props.fiddle && this.state.value === '') &&
|
||||||
|
(
|
||||||
|
(prevProps.lastFiddle !== this.props.lastFiddle)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
this._onCodeChange(this.props.lastFiddle);
|
this._onCodeChange(this.props.lastFiddle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillUnmount(){
|
||||||
|
//this.props.fetchLastFiddle();
|
||||||
|
this.props.putLastFiddle(this.state.value); // force update on next load
|
||||||
|
}
|
||||||
|
|
||||||
_onCodeChange(newValue) {
|
_onCodeChange(newValue) {
|
||||||
this.setState({value: newValue});
|
this.setState({readOnly: false, value: newValue});
|
||||||
if (this.compileTimeout) clearTimeout(this.compileTimeout);
|
if (this.compileTimeout) clearTimeout(this.compileTimeout);
|
||||||
this.compileTimeout = setTimeout(() => {
|
this.compileTimeout = setTimeout(() => {
|
||||||
this.setState({loadingMessage: 'Compiling...'});
|
this.setState({loadingMessage: 'Compiling...'});
|
||||||
this.props.postFiddle(newValue);
|
this.props.postFiddle(newValue);
|
||||||
|
//this.props.putLastFiddle(newValue);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -93,7 +110,7 @@ class FiddleContainer extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {fiddle, loading, fiddleError, fiddleDeployError, deployedContracts, lastFiddle} = this.props;
|
const {fiddle, loading, fiddleError, fiddleDeployError, deployedContracts, lastFiddle} = this.props;
|
||||||
const {loadingMessage} = this.state;
|
const {loadingMessage, value, readOnly} = this.state;
|
||||||
let renderings = [];
|
let renderings = [];
|
||||||
let warnings = [];
|
let warnings = [];
|
||||||
let errors = [];
|
let errors = [];
|
||||||
|
@ -114,7 +131,9 @@ class FiddleContainer extends Component {
|
||||||
onDeployClick={(e) => this._onDeployClick(e)}
|
onDeployClick={(e) => this._onDeployClick(e)}
|
||||||
/>
|
/>
|
||||||
<Fiddle
|
<Fiddle
|
||||||
value={this.state.value || lastFiddle}
|
// value={fiddle ? this.state.value : lastFiddle}
|
||||||
|
value={value !== undefined ? value : lastFiddle}
|
||||||
|
readOnly={readOnly}
|
||||||
onCodeChange={(n) => this._onCodeChange(n)}
|
onCodeChange={(n) => this._onCodeChange(n)}
|
||||||
errors={errors}
|
errors={errors}
|
||||||
warnings={warnings}
|
warnings={warnings}
|
||||||
|
@ -158,7 +177,7 @@ function mapStateToProps(state) {
|
||||||
deployedContracts: deployedFiddle.data,
|
deployedContracts: deployedFiddle.data,
|
||||||
fiddleError: fiddle.error,
|
fiddleError: fiddle.error,
|
||||||
fiddleDeployError: deployedFiddle.error,
|
fiddleDeployError: deployedFiddle.error,
|
||||||
lastFiddle: lastFiddle ? lastFiddle.source : '',
|
lastFiddle: (lastFiddle && lastFiddle.source && !lastFiddle.source.error) ? lastFiddle.source : undefined,
|
||||||
loading: state.loading
|
loading: state.loading
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -172,7 +191,8 @@ FiddleContainer.propTypes = {
|
||||||
postFiddleDeploy: PropTypes.func,
|
postFiddleDeploy: PropTypes.func,
|
||||||
deployedContracts: PropTypes.string,
|
deployedContracts: PropTypes.string,
|
||||||
fetchLastFiddle: PropTypes.func,
|
fetchLastFiddle: PropTypes.func,
|
||||||
lastFiddle: PropTypes.string
|
lastFiddle: PropTypes.string,
|
||||||
|
putLastFiddle: PropTypes.func
|
||||||
};
|
};
|
||||||
|
|
||||||
export default connect(
|
export default connect(
|
||||||
|
@ -180,6 +200,7 @@ export default connect(
|
||||||
{
|
{
|
||||||
postFiddle: fiddleAction.post,
|
postFiddle: fiddleAction.post,
|
||||||
postFiddleDeploy: fiddleDeployAction.post,
|
postFiddleDeploy: fiddleDeployAction.post,
|
||||||
fetchLastFiddle: fiddleFileAction.request
|
fetchLastFiddle: fiddleFileAction.request,
|
||||||
|
putLastFiddle: putLastFiddleAction
|
||||||
},
|
},
|
||||||
)(FiddleContainer);
|
)(FiddleContainer);
|
||||||
|
|
|
@ -138,7 +138,7 @@ class Solidity {
|
||||||
return callback(new Error(__("error compiling for unknown reasons")));
|
return callback(new Error(__("error compiling for unknown reasons")));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Object.keys(output.contracts).length === 0 && output.sourceList.length > 0) {
|
if (Object.keys(output.contracts).length === 0 && output.sourceList && output.sourceList.length > 0) {
|
||||||
return callback(new Error(__("error compiling. There are sources available but no code could be compiled, likely due to fatal errors in the solidity code")).message);
|
return callback(new Error(__("error compiling. There are sources available but no code could be compiled, likely due to fatal errors in the solidity code")).message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue