diff --git a/.gitignore b/.gitignore index 21b594e6..41b3861e 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ build_storybook/ .DS_Store build/ yarn-error.log -.env.* \ No newline at end of file +.env* \ No newline at end of file diff --git a/src/components/ConnectButton/index.jsx b/src/components/ConnectButton/index.jsx index b066fe0d..85723ed4 100644 --- a/src/components/ConnectButton/index.jsx +++ b/src/components/ConnectButton/index.jsx @@ -13,8 +13,6 @@ import Button from '~/components/layout/Button' import { fetchProvider } from '~/logic/wallets/store/actions' import { getNetwork } from '~/config' -console.log(process.env) - const web3Connect = new Web3Connect.Core({ network: getNetwork().toLowerCase(), providerOptions: { diff --git a/src/logic/wallets/ethTransactions.js b/src/logic/wallets/ethTransactions.js index f8673ad6..9f1ad16a 100644 --- a/src/logic/wallets/ethTransactions.js +++ b/src/logic/wallets/ethTransactions.js @@ -1,7 +1,7 @@ // @flow import { BigNumber } from 'bignumber.js' import axios from 'axios' -import { getWeb3 } from '~/logic/wallets/getWeb3' +import { getWeb3, web3RO } from '~/logic/wallets/getWeb3' // const MAINNET_NETWORK = 1 export const EMPTY_DATA = '0x' @@ -11,8 +11,7 @@ export const checkReceiptStatus = async (hash: string) => { return Promise.reject(new Error('No valid Tx hash to get receipt from')) } - const web3 = getWeb3() - const txReceipt = await web3.eth.getTransactionReceipt(hash) + const txReceipt = await web3RO.eth.getTransactionReceipt(hash) const { status } = txReceipt if (!status) { diff --git a/src/logic/wallets/getWeb3.js b/src/logic/wallets/getWeb3.js index b01a81ae..98f97819 100644 --- a/src/logic/wallets/getWeb3.js +++ b/src/logic/wallets/getWeb3.js @@ -22,6 +22,7 @@ export const WALLET_PROVIDER = { PORTIS: 'PORTIS', FORTMATIC: 'FORTMATIC', SQUARELINK: 'SQUARELINK', + WALLETCONNECT: 'WALLETCONNECT', } export const ETHEREUM_NETWORK_IDS = { @@ -49,9 +50,18 @@ export const getEtherScanLink = (type: 'address' | 'tx', value: string) => { let web3 export const getWeb3 = () => web3 || (window.web3 && new Web3(window.web3.currentProvider)) || (window.ethereum && new Web3(window.ethereum)) +export const getInfuraUrl = () => { + const isMainnet = getNetwork() === ETHEREUM_NETWORK.MAINNET + + return `https://${isMainnet ? '' : 'rinkeby.'}infura.io:443/v3/${process.env.REACT_APP_INFURA_TOKEN}` +} + +// With some wallets from web3connect you have to use their provider instance only for signing +// And our own one to fetch data +export const web3RO = new Web3(new Web3.providers.HttpProvider(getInfuraUrl())) + const getProviderName: Function = (web3Provider): string => { let name - console.log(web3Provider) switch (web3Provider.currentProvider.constructor.name) { case 'SafeWeb3Provider': @@ -80,6 +90,10 @@ const getProviderName: Function = (web3Provider): string => { name = WALLET_PROVIDER.SQUARELINK } + if (web3Provider.currentProvider.isWalletConnect) { + name = WALLET_PROVIDER.WALLETCONNECT + } + return name }