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
This commit is contained in:
Jonathan Rainville 2020-01-17 16:35:34 -05:00 committed by Michael Bradley
parent 3ceffa8454
commit e0ac539930
4 changed files with 11 additions and 5 deletions

View File

@ -306,7 +306,7 @@ function Contract(options) {
}); });
return ContractClass; return ContractClass;
}; }
Contract.prototype.deploy = function(args, _options) { Contract.prototype.deploy = function(args, _options) {
var self = this; var self = this;

View File

@ -172,7 +172,9 @@ function connectHttp(web3, endpoint, callback) {
async function connectWeb3(web3, callback) { async function connectWeb3(web3, callback) {
if (typeof window !== 'undefined' && window.ethereum) { if (typeof window !== 'undefined' && window.ethereum) {
try { try {
await ethereum.enable(); if (this.dappAutoEnable) {
await ethereum.enable();
}
web3.setProvider(ethereum); web3.setProvider(ethereum);
return checkConnection(callback); return checkConnection(callback);
} catch (e) { } catch (e) {
@ -207,6 +209,7 @@ __embarkENS.setProvider = function(config) {
this.registration = config.registration; this.registration = config.registration;
this.env = config.env; this.env = config.env;
this.ready = false; this.ready = false;
this.dappAutoEnable = config.dappAutoEnable;
reduce(config.dappConnection, false, (result, connectionString, next) => { reduce(config.dappConnection, false, (result, connectionString, next) => {
if (result.connected) { if (result.connected) {

View File

@ -140,6 +140,7 @@ class ENS {
path: [this.config.embarkConfig.generationDir, 'config'], path: [this.config.embarkConfig.generationDir, 'config'],
file: 'namesystem.json', file: 'namesystem.json',
format: 'json', format: 'json',
dappAutoEnable: this.config.contractsConfig.dappAutoEnable,
content: Object.assign({}, this.embark.config.namesystemConfig, config) content: Object.assign({}, this.embark.config.namesystemConfig, config)
}, cb); }, cb);
}); });

View File

@ -4,7 +4,7 @@ const {Utils} = require('embarkjs');
const secureSend = Utils.secureSend; const secureSend = Utils.secureSend;
describe('embark-ens', () => { describe('embark-ens', () => {
let ens, doneCb; let ens;
const { embark } = fakeEmbark(); const { embark } = fakeEmbark();
@ -22,8 +22,9 @@ describe('embark-ens', () => {
rootDomain: 'root.eth' rootDomain: 'root.eth'
}, },
dappConnection: [] dappConnection: []
} },
}; contractsConfig: {dappAutoEnable: true}
}
}); });
afterEach(() => { afterEach(() => {
@ -37,6 +38,7 @@ describe('embark-ens', () => {
path: ['test-dir', 'config'], path: ['test-dir', 'config'],
file: 'namesystem.json', file: 'namesystem.json',
format: 'json', format: 'json',
dappAutoEnable: true,
content: Object.assign({}, embark.config.namesystemConfig, config) content: Object.assign({}, embark.config.namesystemConfig, config)
}); });
cb(); cb();