fix(@embark/embarkjs): change enableEthereum to not rely on returned accounts array

Some ethereum providers (e.g. Opera implementation) do not return the accounts array in the 'enable' call.
This commit is contained in:
Marc 2020-01-22 20:11:37 +01:00 committed by Michael Bradley
parent df2aaabfc3
commit b8f93ea2ad
1 changed files with 16 additions and 10 deletions

View File

@ -208,17 +208,23 @@ Blockchain.doConnect = function(connectionList, opts, doneCb) {
});
};
Blockchain.enableEthereum = function() {
if (typeof window !== 'undefined' && window.ethereum) {
return ethereum.enable().then((accounts) => {
// See https://eips.ethereum.org/EIPS/eip-1102
Blockchain.enableEthereum = async function() {
if (typeof window === 'undefined' || !window.ethereum) {
throw new Error('ethereum not available in this browser');
}
await ethereum.enable();
this.blockchainConnector.setProvider(ethereum);
const accounts = await this.blockchainConnector.getAccounts();
this.blockchainConnector.setDefaultAccount(accounts[0]);
contracts.forEach(contract => {
contract.options.from = this.blockchainConnector.getDefaultAccount();
});
return accounts;
});
}
};
Blockchain.execWhenReady = function(cb) {