Add optimize and autocompile toggles

This commit is contained in:
Nicolas Gotchac 2016-12-20 02:11:04 +01:00
parent f70e808056
commit 5886034265
4 changed files with 46 additions and 6 deletions

View File

@ -19,7 +19,7 @@ import solc from 'solc/browser-wrapper';
export default class SolidityUtils { export default class SolidityUtils {
static compile (data, compiler) { static compile (data, compiler) {
const { sourcecode, build, optimized = 1 } = data; const { sourcecode, build, optimize } = data;
const start = Date.now(); const start = Date.now();
console.log('[solidity] compiling...'); console.log('[solidity] compiling...');
@ -28,7 +28,7 @@ export default class SolidityUtils {
'': sourcecode '': sourcecode
}; };
const compiled = compiler.compile({ sources: input }, optimized); const compiled = compiler.compile({ sources: input }, optimize ? 1 : 0);
const time = Math.round((Date.now() - start) / 100) / 10; const time = Math.round((Date.now() - start) / 100) / 10;
console.log(`[solidity] done compiling in ${time}s`); console.log(`[solidity] done compiling in ${time}s`);

View File

@ -26,6 +26,16 @@
color: #ccc; color: #ccc;
} }
.toggles {
display: flex;
flex-direction: row;
margin: 1em 0 0;
> * {
flex: 1;
}
}
.container { .container {
padding: 1em 0; padding: 1em 0;
display: flex; display: flex;

View File

@ -16,7 +16,7 @@
import React, { PropTypes, Component } from 'react'; import React, { PropTypes, Component } from 'react';
import { observer } from 'mobx-react'; import { observer } from 'mobx-react';
import { MenuItem } from 'material-ui'; import { MenuItem, Toggle } from 'material-ui';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { bindActionCreators } from 'redux'; import { bindActionCreators } from 'redux';
import CircularProgress from 'material-ui/CircularProgress'; import CircularProgress from 'material-ui/CircularProgress';
@ -283,6 +283,24 @@ class WriteContract extends Component {
: null : null
} }
</div> </div>
<div className={ styles.toggles }>
<div>
<Toggle
label='Optimize'
labelPosition='right'
onToggle={ this.store.handleOptimizeToggle }
toggled={ this.store.optimize }
/>
</div>
<div>
<Toggle
label='Auto-Compile'
labelPosition='right'
onToggle={ this.store.handleAutocompileToggle }
toggled={ this.store.autocompile }
/>
</div>
</div>
{ this.renderSolidityVersions() } { this.renderSolidityVersions() }
{ this.renderCompilation() } { this.renderCompilation() }
</div> </div>

View File

@ -66,6 +66,9 @@ export default class WriteContractStore {
@observable builds = []; @observable builds = [];
@observable selectedBuild = -1; @observable selectedBuild = -1;
@observable autocompile = false;
@observable optimize = false;
@observable showDeployModal = false; @observable showDeployModal = false;
@observable showSaveModal = false; @observable showSaveModal = false;
@observable showLoadModal = false; @observable showLoadModal = false;
@ -278,7 +281,7 @@ export default class WriteContractStore {
const build = this.builds[this.selectedBuild]; const build = this.builds[this.selectedBuild];
const version = build.longVersion; const version = build.longVersion;
const sourcecode = this.sourcecode.replace(/\n+/g, '\n').replace(/\s(\s+)/g, ' '); const sourcecode = this.sourcecode.replace(/\n+/g, '\n').replace(/\s(\s+)/g, ' ');
const hash = sha3(JSON.stringify({ version, sourcecode })); const hash = sha3(JSON.stringify({ version, sourcecode, optimize: this.optimize }));
let promise = Promise.resolve(null); let promise = Promise.resolve(null);
@ -297,7 +300,8 @@ export default class WriteContractStore {
.then(() => { .then(() => {
return this.compile({ return this.compile({
sourcecode: sourcecode, sourcecode: sourcecode,
build: build build: build,
optimize: this.optimize
}); });
}) })
.then((data) => { .then((data) => {
@ -337,6 +341,14 @@ export default class WriteContractStore {
}); });
} }
@action handleAutocompileToggle = () => {
this.autocompile = !this.autocompile;
}
@action handleOptimizeToggle = () => {
this.optimize = !this.optimize;
}
@action parseCompiled = (data) => { @action parseCompiled = (data) => {
const { contracts } = data; const { contracts } = data;
@ -395,7 +407,7 @@ export default class WriteContractStore {
if (compile) { if (compile) {
this.handleCompile(); this.handleCompile();
} else { } else if (this.autocompile) {
this.debouncedCompile(); this.debouncedCompile();
} }
} }