Skip to content

Commit

Permalink
fix(@embark/embarkjs): change enableEthereum to not rely on returned …
Browse files Browse the repository at this point in the history
…accounts array

Some ethereum providers (e.g. Opera implementation) do not return the accounts array in the 'enable' call.
  • Loading branch information
frozenpomelo authored and michaelsbradleyjr committed Jan 23, 2020
1 parent df2aaab commit b8f93ea
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/embarkjs/embarkjs/src/lib/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,23 @@ Blockchain.doConnect = function(connectionList, opts, doneCb) {
});
};

Blockchain.enableEthereum = function() {
if (typeof window !== 'undefined' && window.ethereum) {
return ethereum.enable().then((accounts) => {
this.blockchainConnector.setProvider(ethereum);
this.blockchainConnector.setDefaultAccount(accounts[0]);
contracts.forEach(contract => {
contract.options.from = this.blockchainConnector.getDefaultAccount();
});
return 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) {
Expand Down

0 comments on commit b8f93ea

Please sign in to comment.