Skip to content

Commit e0ac539

Browse files
jrainvillemichaelsbradleyjr
authored andcommitted
fix(@embark/ens): connect to web3 only with dappAutoEnable is true
When we introduced dappConnection to ENS, we didn't add the concept of auto connection, like we do in the "normal" connection. This means that when using $WEB3, the contracts connection waited for the user to click on a button, but the ENS part called `ethereum.enable` directly, which is confusing for the dev, because we specified to NOT automatically connect to ethreum. This fixes it by checking the dappAutoEnable property in contracts config and adds it to the namesystemConfig artifact
1 parent 3ceffa8 commit e0ac539

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

packages/embarkjs/embarkjs/src/lib/blockchain.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ function Contract(options) {
306306
});
307307

308308
return ContractClass;
309-
};
309+
}
310310

311311
Contract.prototype.deploy = function(args, _options) {
312312
var self = this;

packages/embarkjs/ens/src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ function connectHttp(web3, endpoint, callback) {
172172
async function connectWeb3(web3, callback) {
173173
if (typeof window !== 'undefined' && window.ethereum) {
174174
try {
175-
await ethereum.enable();
175+
if (this.dappAutoEnable) {
176+
await ethereum.enable();
177+
}
176178
web3.setProvider(ethereum);
177179
return checkConnection(callback);
178180
} catch (e) {
@@ -207,6 +209,7 @@ __embarkENS.setProvider = function(config) {
207209
this.registration = config.registration;
208210
this.env = config.env;
209211
this.ready = false;
212+
this.dappAutoEnable = config.dappAutoEnable;
210213

211214
reduce(config.dappConnection, false, (result, connectionString, next) => {
212215
if (result.connected) {

packages/plugins/ens/src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ class ENS {
140140
path: [this.config.embarkConfig.generationDir, 'config'],
141141
file: 'namesystem.json',
142142
format: 'json',
143+
dappAutoEnable: this.config.contractsConfig.dappAutoEnable,
143144
content: Object.assign({}, this.embark.config.namesystemConfig, config)
144145
}, cb);
145146
});

packages/plugins/ens/test/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const {Utils} = require('embarkjs');
44
const secureSend = Utils.secureSend;
55

66
describe('embark-ens', () => {
7-
let ens, doneCb;
7+
let ens;
88

99
const { embark } = fakeEmbark();
1010

@@ -22,8 +22,9 @@ describe('embark-ens', () => {
2222
rootDomain: 'root.eth'
2323
},
2424
dappConnection: []
25-
}
26-
};
25+
},
26+
contractsConfig: {dappAutoEnable: true}
27+
}
2728
});
2829

2930
afterEach(() => {
@@ -37,6 +38,7 @@ describe('embark-ens', () => {
3738
path: ['test-dir', 'config'],
3839
file: 'namesystem.json',
3940
format: 'json',
41+
dappAutoEnable: true,
4042
content: Object.assign({}, embark.config.namesystemConfig, config)
4143
});
4244
cb();

0 commit comments

Comments
 (0)