From a5db2d4ed6e0f022089a349aa376dfc12d183f8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Mart=C3=ADnez?= Date: Thu, 16 May 2019 18:18:26 +0200 Subject: [PATCH] Allow Metamask in private mode --- src/logic/wallets/getWeb3.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/logic/wallets/getWeb3.js b/src/logic/wallets/getWeb3.js index aecfaaa4..724c5b41 100644 --- a/src/logic/wallets/getWeb3.js +++ b/src/logic/wallets/getWeb3.js @@ -57,7 +57,14 @@ const getNetworkIdFrom = async (web3Provider) => { } export const getProviderInfo: Function = async (): Promise => { - if (typeof window.web3 === 'undefined') { + let web3Provider + + if (window.ethereum) { + web3Provider = window.ethereum + await web3Provider.enable() + } else if (window.web3) { + web3Provider = window.web3.currentProvider + } else { return { name: '', available: false, @@ -67,15 +74,9 @@ export const getProviderInfo: Function = async (): Promise => { } } - // Use MetaMask's provider. - web3 = new Web3(window.web3.currentProvider) + web3 = new Web3(web3Provider) - if (process.env.NODE_ENV !== 'test') { - // eslint-disable-next-line - console.log('Injected web3 detected.') - } - - const name = isMetamask(window.web3) ? WALLET_PROVIDER.METAMASK : 'UNKNOWN' + const name = isMetamask(web3) ? WALLET_PROVIDER.METAMASK : 'UNKNOWN' const account = await getAccountFrom(web3) const network = await getNetworkIdFrom(web3)