Changed state handling on template and engine initialization

This commit is contained in:
Richard Ramos 2018-10-05 16:17:16 -04:00 committed by Pascal Precht
parent d3961783b4
commit deb9c9a838
No known key found for this signature in database
GPG Key ID: 0EE28D8D6FD85D7D
2 changed files with 34 additions and 58 deletions

View File

@ -431,80 +431,51 @@ class EmbarkController {
}
scaffold(options) {
this.context = options.context || [constants.contexts.build];
this.context = options.context || [constants.contexts.scaffold];
options.onlyCompile = true;
const Scaffolding = require('../lib/cmds/scaffolding.js');
const Engine = require('../lib/core/engine.js');
const engine = new Engine({
env: options.env,
client: options.client,
locale: options.locale,
version: this.version,
embarkConfig: 'embark.json',
interceptLogs: false,
embarkConfig: options.embarkConfig || 'embark.json',
logFile: options.logFile,
logLevel: options.logLevel,
events: options.events,
logger: options.logger,
config: options.config,
plugins: options.plugins,
context: this.context,
webpackConfigName: options.webpackConfigName
context: this.context
});
async.waterfall([
function initEngine(callback) {
function (callback) {
engine.init({}, callback);
},
function startServices(callback) {
function (callback) {
let pluginList = engine.plugins.listPlugins();
if (pluginList.length > 0) {
engine.logger.info(__("loaded plugins") + ": " + pluginList.join(", "));
}
engine.startService("processManager");
engine.startService("serviceMonitor");
engine.startService("libraryManager");
engine.startService("codeRunner");
engine.startService("web3");
if (!options.onlyCompile) {
engine.startService("pipeline");
}
engine.startService("deployment", {onlyCompile: options.onlyCompile});
if (!options.onlyCompile) {
engine.startService("storage");
engine.startService("deployment", {onlyCompile: true});
engine.startService("web3");
engine.startService("codeGenerator");
engine.events.request('deploy:contracts', callback);
}
callback();
},
function deploy(callback) {
engine.events.request('deploy:contracts', function (err) {
callback(err);
});
},
function waitForWriteFinish(callback) {
if (options.onlyCompile) {
engine.logger.info("Finished compiling".underline);
return callback(null, true);
}
engine.events.on('outputDone', (err) => {
], (err) => {
if (err) {
engine.logger.error(err.message);
engine.logger.info(err.stack);
} else {
let scaffold = new Scaffolding(engine, options);
scaffold.generate(options.contract, options.overwrite);
callback(err, true);
});
}
], function (_err, canExit) {
// TODO: this should be moved out and determined somewhere else
if (canExit || !engine.config.contractsConfig.afterDeploy || !engine.config.contractsConfig.afterDeploy.length) {
process.exit();
}
engine.logger.info(__('Waiting for after deploy to finish...'));
engine.logger.info(__('You can exit with CTRL+C when after deploy completes'));
});
}

View File

@ -30,22 +30,27 @@ class {{capitalize name}}Form{{@index}} extends Component {
}
handleChange(e, name){
this.state.input[name] = e.target.value;
this.setState(this.state);
const {input} = this.state;
input[name] = e.target.value;
this.setState({input});
}
handleCheckbox(e, name){
this.state.input[name] = e.target.checked;
this.setState(this.state);
const {input} = this.state;
input[name] = e.target.checked;
this.setState({input});
}
async handleClick(e){
e.preventDefault();
const {input, value} = this.state;
this.setState({output: null, error: null, receipt: null});
try {
{{#ifview stateMutability}}
const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call()
const result = await {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}}).call()
{{#iflengthgt outputs 1}}
this.setState({output: {
{{#each outputs}}
@ -56,13 +61,13 @@ class {{capitalize name}}Form{{@index}} extends Component {
this.setState({output: result});
{{/iflengthgt}}
{{else}}
const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}this.state.input.{{name}}{{#unless @last}}, {{/unless}}{{/each}});
const toSend = {{../contractName}}.methods{{methodname ../functions name inputs}}({{#each inputs}}input.{{name}}{{#unless @last}}, {{/unless}}{{/each}});
const estimatedGas = await toSend.estimateGas({from: web3.eth.defaultAccount});
const receipt = await toSend.send({
{{#if payable}}
value: this.state.value,
value: value,
{{/if}}
from: web3.eth.defaultAccount,
gasLimit: estimatedGas