Do not rely on web3 injection with new ethereum provider standard #102
@@ -50,9 +50,9 @@ export default Service.extend({
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function instantiateWithAccount (web3, context) {
|
function instantiateWithAccount (web3Provider, context) {
|
||||||
console.debug('[kredits] Using user-provided instance, e.g. from Mist browser or Metamask');
|
console.debug('[kredits] Using user-provided instance, e.g. from Mist browser or Metamask');
|
||||||
ethProvider = new ethers.providers.Web3Provider(web3.currentProvider);
|
ethProvider = new ethers.providers.Web3Provider(web3Provider);
|
||||||
ethProvider.listAccounts().then(accounts => {
|
ethProvider.listAccounts().then(accounts => {
|
||||||
context.set('currentUserAccounts', accounts);
|
context.set('currentUserAccounts', accounts);
|
||||||
const ethSigner = accounts.length === 0 ? null : ethProvider.getSigner();
|
const ethSigner = accounts.length === 0 ? null : ethProvider.getSigner();
|
||||||
@@ -64,19 +64,18 @@ export default Service.extend({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (window.ethereum) {
|
if (window.ethereum) {
|
||||||
window.web3 = new window.Web3(window.ethereum);
|
|
||||||
try {
|
try {
|
||||||
// Request account access if needed
|
// Request account access if needed
|
||||||
await window.ethereum.enable();
|
await window.ethereum.enable();
|
||||||
// Acccounts now exposed
|
// Acccounts now exposed
|
||||||
instantiateWithAccount(window.web3, this);
|
instantiateWithAccount(window.ethereum, this);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
instantiateWithoutAccount();
|
instantiateWithoutAccount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Legacy dapp browsers...
|
// Legacy dapp browsers...
|
||||||
else if (window.web3) {
|
else if (window.web3) {
|
||||||
instantiateWithAccount(window.web3, this);
|
instantiateWithAccount(window.web3.currentProvider, this);
|
||||||
}
|
}
|
||||||
// Non-dapp browsers...
|
// Non-dapp browsers...
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user