Remove last fiddle, and use code to compile

This commit is contained in:
Anthony Laibe 2018-08-28 16:42:44 +01:00 committed by Pascal Precht
parent cd176a5f95
commit 4ecb092ed3
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
9 changed files with 44 additions and 63 deletions

View File

@ -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';

View File

@ -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) {

View File

@ -6,14 +6,13 @@ import PropTypes from 'prop-types';
import {
fiddle as fiddleAction,
fiddleDeploy as fiddleDeployAction,
fiddleFile as fiddleFileAction,
putLastFiddle as putLastFiddleAction
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);
}
@ -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 = [];
@ -131,8 +122,7 @@ 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}
@ -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,
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);

View File

@ -21,7 +21,6 @@ const entitiesDefaultState = {
messageChannels: [],
fiddles: [],
fiddleDeploys: [],
fiddleFiles: [],
versions: [],
plugins: [],
ensRecords: []

View File

@ -122,10 +122,6 @@ export function getFiddleDeploy(state) {
};
}
export function getLastFiddle(state) {
return state.entities.fiddleFiles.find((fiddleFile => fiddleFile.filename === 'temp'));
}
export function getEnsRecords(state) {
return state.entities.ensRecords;
}

View File

@ -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>

View File

@ -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)
]);

View File

@ -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);
});
}

View File

@ -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