Add optimize and autocompile toggles
This commit is contained in:
parent
f70e808056
commit
5886034265
@ -19,7 +19,7 @@ import solc from 'solc/browser-wrapper';
|
||||
export default class SolidityUtils {
|
||||
|
||||
static compile (data, compiler) {
|
||||
const { sourcecode, build, optimized = 1 } = data;
|
||||
const { sourcecode, build, optimize } = data;
|
||||
|
||||
const start = Date.now();
|
||||
console.log('[solidity] compiling...');
|
||||
@ -28,7 +28,7 @@ export default class SolidityUtils {
|
||||
'': 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;
|
||||
console.log(`[solidity] done compiling in ${time}s`);
|
||||
|
@ -26,6 +26,16 @@
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.toggles {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
margin: 1em 0 0;
|
||||
|
||||
> * {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 1em 0;
|
||||
display: flex;
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
import React, { PropTypes, Component } from 'react';
|
||||
import { observer } from 'mobx-react';
|
||||
import { MenuItem } from 'material-ui';
|
||||
import { MenuItem, Toggle } from 'material-ui';
|
||||
import { connect } from 'react-redux';
|
||||
import { bindActionCreators } from 'redux';
|
||||
import CircularProgress from 'material-ui/CircularProgress';
|
||||
@ -283,6 +283,24 @@ class WriteContract extends Component {
|
||||
: null
|
||||
}
|
||||
</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.renderCompilation() }
|
||||
</div>
|
||||
|
@ -66,6 +66,9 @@ export default class WriteContractStore {
|
||||
@observable builds = [];
|
||||
@observable selectedBuild = -1;
|
||||
|
||||
@observable autocompile = false;
|
||||
@observable optimize = false;
|
||||
|
||||
@observable showDeployModal = false;
|
||||
@observable showSaveModal = false;
|
||||
@observable showLoadModal = false;
|
||||
@ -278,7 +281,7 @@ export default class WriteContractStore {
|
||||
const build = this.builds[this.selectedBuild];
|
||||
const version = build.longVersion;
|
||||
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);
|
||||
|
||||
@ -297,7 +300,8 @@ export default class WriteContractStore {
|
||||
.then(() => {
|
||||
return this.compile({
|
||||
sourcecode: sourcecode,
|
||||
build: build
|
||||
build: build,
|
||||
optimize: this.optimize
|
||||
});
|
||||
})
|
||||
.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) => {
|
||||
const { contracts } = data;
|
||||
|
||||
@ -395,7 +407,7 @@ export default class WriteContractStore {
|
||||
|
||||
if (compile) {
|
||||
this.handleCompile();
|
||||
} else {
|
||||
} else if (this.autocompile) {
|
||||
this.debouncedCompile();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user