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 = createRequestTypes('FIDDLE');
export const fiddle = { export const fiddle = {
post: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}), post: (codeToCompile) => action(FIDDLE[REQUEST], {codeToCompile}),
success: (fiddle) => { success: (fiddle, payload) => {
return action(FIDDLE[SUCCESS], {fiddles: [fiddle]}); return action(FIDDLE[SUCCESS], {fiddles: [{...fiddle, ...payload}]});
}, },
failure: (error) => action(FIDDLE[FAILURE], {error}) failure: (error) => action(FIDDLE[FAILURE], {error})
}; };
@ -189,14 +189,10 @@ export const fiddleDeploy = {
export const FIDDLE_FILE = createRequestTypes('FIDDLE_FILE'); export const FIDDLE_FILE = createRequestTypes('FIDDLE_FILE');
export const fiddleFile = { export const fiddleFile = {
request: () => action(FIDDLE_FILE[REQUEST]), 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}) 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';

View File

@ -129,7 +129,7 @@ export function webSocketBlockHeader() {
} }
export function postFiddle(payload) { export function postFiddle(payload) {
return post('/contract/compile', {code: payload.codeToCompile}); return post('/contract/compile', payload);
} }
export function postFiddleDeploy(payload) { export function postFiddleDeploy(payload) {

View File

@ -6,14 +6,13 @@ import PropTypes from 'prop-types';
import { import {
fiddle as fiddleAction, fiddle as fiddleAction,
fiddleDeploy as fiddleDeployAction, fiddleDeploy as fiddleDeployAction,
fiddleFile as fiddleFileAction, fiddleFile as fiddleFileAction
putLastFiddle as putLastFiddleAction
} from '../actions'; } 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';
import scrollToComponent from 'react-scroll-to-component'; 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"; import CompilerError from "../components/CompilerError";
class FiddleContainer extends Component { class FiddleContainer extends Component {
@ -32,22 +31,15 @@ class FiddleContainer extends Component {
componentDidMount() { componentDidMount() {
this.setState({loadingMessage: 'Loading saved state...'}); this.setState({loadingMessage: 'Loading saved state...'});
this.props.fetchLastFiddle(); if (!this.props.fiddle) {
} 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);
} }
} }
componentWillUnmount(){ componentDidUpdate() {
//this.props.fetchLastFiddle(); if(!this.state.value && this.props.fiddle) {
this.props.putLastFiddle(this.state.value); // force update on next load this.setState({value: this.props.fiddle.codeToCompile});
}
} }
_onCodeChange(newValue) { _onCodeChange(newValue) {
@ -56,7 +48,6 @@ class FiddleContainer extends Component {
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);
} }
@ -109,7 +100,7 @@ class FiddleContainer extends Component {
} }
render() { render() {
const {fiddle, loading, fiddleError, fiddleDeployError, deployedContracts, lastFiddle} = this.props; const {fiddle, loading, fiddleError, fiddleDeployError, deployedContracts} = this.props;
const {loadingMessage, value, readOnly} = this.state; const {loadingMessage, value, readOnly} = this.state;
let renderings = []; let renderings = [];
let warnings = []; let warnings = [];
@ -131,8 +122,7 @@ class FiddleContainer extends Component {
onDeployClick={(e) => this._onDeployClick(e)} onDeployClick={(e) => this._onDeployClick(e)}
/> />
<Fiddle <Fiddle
// value={fiddle ? this.state.value : lastFiddle} value={value}
value={value !== undefined ? value : lastFiddle}
readOnly={readOnly} readOnly={readOnly}
onCodeChange={(n) => this._onCodeChange(n)} onCodeChange={(n) => this._onCodeChange(n)}
errors={errors} errors={errors}
@ -171,13 +161,11 @@ class FiddleContainer extends Component {
function mapStateToProps(state) { function mapStateToProps(state) {
const fiddle = getFiddle(state); const fiddle = getFiddle(state);
const deployedFiddle = getFiddleDeploy(state); const deployedFiddle = getFiddleDeploy(state);
const lastFiddle = getLastFiddle(state);
return { return {
fiddle: fiddle.data, fiddle: fiddle.data,
deployedContracts: deployedFiddle.data, deployedContracts: deployedFiddle.data,
fiddleError: fiddle.error, fiddleError: fiddle.error,
fiddleDeployError: deployedFiddle.error, fiddleDeployError: deployedFiddle.error,
lastFiddle: (lastFiddle && lastFiddle.source && !lastFiddle.source.error) ? lastFiddle.source : undefined,
loading: state.loading loading: state.loading
}; };
} }
@ -190,9 +178,7 @@ FiddleContainer.propTypes = {
postFiddle: PropTypes.func, postFiddle: PropTypes.func,
postFiddleDeploy: PropTypes.func, postFiddleDeploy: PropTypes.func,
deployedContracts: PropTypes.string, deployedContracts: PropTypes.string,
fetchLastFiddle: PropTypes.func, fetchLastFiddle: PropTypes.func
lastFiddle: PropTypes.string,
putLastFiddle: PropTypes.func
}; };
export default connect( export default connect(
@ -200,7 +186,6 @@ 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);

View File

@ -21,7 +21,6 @@ const entitiesDefaultState = {
messageChannels: [], messageChannels: [],
fiddles: [], fiddles: [],
fiddleDeploys: [], fiddleDeploys: [],
fiddleFiles: [],
versions: [], versions: [],
plugins: [], plugins: [],
ensRecords: [] 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) { export function getEnsRecords(state) {
return state.entities.ensRecords; return state.entities.ensRecords;
} }

View File

@ -17,7 +17,7 @@ const routes = (
<Route path="/embark/processes/" component={ProcessesLayout} /> <Route path="/embark/processes/" component={ProcessesLayout} />
<Route path="/embark/contracts/:contractName" component={ContractContainer} /> <Route path="/embark/contracts/:contractName" component={ContractContainer} />
<Route path="/embark/contracts" component={ContractsContainer} /> <Route path="/embark/contracts" component={ContractsContainer} />
<Route path="/embark/fiddle" component={FiddleContainer} /> <Route path="/embark/fiddle" render={() => <FiddleContainer />} />
<Route component={NoMatch} /> <Route component={NoMatch} />
</Switch> </Switch>
</React.Fragment> </React.Fragment>

View File

@ -138,6 +138,10 @@ export function *watchPostFiddle() {
yield takeEvery(actions.FIDDLE[actions.REQUEST], postFiddle); yield takeEvery(actions.FIDDLE[actions.REQUEST], postFiddle);
} }
export function *watchFetchLastFiddleSuccess() {
yield takeEvery(actions.FIDDLE_FILE[actions.SUCCESS], postFiddle);
}
export function *watchPostFiddleDeploy() { export function *watchPostFiddleDeploy() {
yield takeEvery(actions.FIDDLE_DEPLOY[actions.REQUEST], postFiddleDeploy); yield takeEvery(actions.FIDDLE_DEPLOY[actions.REQUEST], postFiddleDeploy);
} }
@ -230,6 +234,7 @@ export default function *root() {
fork(watchPostFiddle), fork(watchPostFiddle),
fork(watchPostFiddleDeploy), fork(watchPostFiddleDeploy),
fork(watchFetchLastFiddle), fork(watchFetchLastFiddle),
fork(watchFetchLastFiddleSuccess),
fork(watchFetchEnsRecord), fork(watchFetchEnsRecord),
fork(watchPostEnsRecords) fork(watchPostEnsRecords)
]); ]);

View File

@ -52,7 +52,7 @@ class Pipeline {
'/embark-api/files/lastfiddle', '/embark-api/files/lastfiddle',
(req, res) => { (req, res) => {
fs.readFile(fs.dappPath('.embark/fiddles/temp.sol'), 'utf8', (err, source) => { 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); res.send(source);
}); });
} }

View File

@ -20,11 +20,11 @@ class Solidity {
'post', 'post',
'/embark-api/contract/compile', '/embark-api/contract/compile',
(req, res) => { (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) => { this.compile_solidity_code(input, {}, true, (errors, compilationResult) => {
// write code to filesystem so we can view the source after page refresh // write code to filesystem so we can view the source after page refresh
const className = !compilationResult ? 'temp' : Object.keys(compilationResult).join('_'); 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); if(err) this.logger.trace('Error writing fiddle to filesystem: ', err);
}); // async, do not need to wait }); // async, do not need to wait