Skip to content

Commit

Permalink
feat: enable ethereum manually
Browse files Browse the repository at this point in the history
  • Loading branch information
alaibe authored and iurimatias committed Dec 7, 2018
1 parent 72f8701 commit 5a375d9
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ Config.prototype.loadContractsConfigFile = function() {
"$WEB3",
"localhost:8545"
],
"dappAutoEnable": true,
"strategy": constants.deploymentStrategy.implicit,
"gas": "auto",
"contracts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
EmbarkJS.Blockchain.autoEnable = <%= autoEnable %>;
EmbarkJS.Blockchain.connect(<%- connectionList %>, {warnAboutMetamask: <%= warnAboutMetamask %>}, function(err) {
<%- done %>
});
7 changes: 6 additions & 1 deletion src/lib/modules/code_generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ class CodeGenerator {
} else {
let connectionList = "[" + this.contractsConfig.dappConnection.map((x) => '"' + x + '"').join(',') + "]";
let isDev = (self.env === 'development');
web3Load = Templates.web3_connector({connectionList: connectionList, done: 'done(err);', warnAboutMetamask: isDev});
web3Load = Templates.web3_connector({
autoEnable: this.contractsConfig.dappAutoEnable,
connectionList: connectionList,
done: 'done(err);',
warnAboutMetamask: isDev
});
}

result += Templates.do_when_loaded({block: web3Load, environment: this.env});
Expand Down
2 changes: 2 additions & 0 deletions src/test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ describe('embark.Config', function () {
versions: {'web3': '1.0.0-beta', solc: '0.5.0'},
deployment: {host: 'localhost', port: 8545, type: 'rpc', "accounts": [{"mnemonic": "12 word mnemonic", "balance": "5000000000"}]},
dappConnection: ['$WEB3', 'localhost:8545'],
dappAutoEnable: true,
"gas": "400000",
"strategy": "implicit",
"contracts": {
Expand All @@ -136,6 +137,7 @@ describe('embark.Config', function () {
versions: {'web3': '1.0.0-beta', solc: '0.5.0'},
deployment: {host: 'localhost', port: 8545, type: 'rpc'},
dappConnection: ['$WEB3', 'localhost:8545'],
dappAutoEnable: true,
"gas": "auto",
"strategy": "implicit",
"contracts": {
Expand Down
5 changes: 5 additions & 0 deletions templates/boilerplate/config/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module.exports = {
"http://localhost:8545"
],

// Automatically call `ethereum.enable` if true.
// If false, the following code must run before sending any transaction: `await EmbarkJS.enableEthereum();`
// Default value is true.
// dappAutoEnable: true,

gas: "auto",

// Strategy for the deployment of the contracts:
Expand Down
6 changes: 3 additions & 3 deletions templates/demo/app/components/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Blockchain extends React.Component {
valueSet: 10,
valueGet: "",
logs: []
}
};
}

handleChange(e) {
Expand All @@ -27,9 +27,9 @@ class Blockchain extends React.Component {
func.apply(this, [e]);
}

setValue(e) {
async setValue(e) {
e.preventDefault();

await EmbarkJS.enableEthereum();
var value = parseInt(this.state.valueSet, 10);

SimpleStorage.methods.set(value).send();
Expand Down
5 changes: 5 additions & 0 deletions templates/demo/config/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module.exports = {
"http://localhost:8545"
],

// Automatically call `ethereum.enable` if true.
// If false, the following code must run before sending any transaction: `await EmbarkJS.enableEthereum();`
// Default value is true.
// dappAutoEnable: true,

gas: "auto",

// Strategy for the deployment of the contracts:
Expand Down
5 changes: 5 additions & 0 deletions templates/simple/contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ module.exports = {
"http://localhost:8545"
],

// Automatically call `ethereum.enable` if true.
// If false, the following code must run before sending any transaction: `await EmbarkJS.enableEthereum();`
// Default value is true.
// dappAutoEnable: true,

gas: "auto",

// Strategy for the deployment of the contracts:
Expand Down

0 comments on commit 5a375d9

Please sign in to comment.