Use our own web3 instance to fetch data from blockchain because of limitations in web3connect

This commit is contained in:
mmv 2019-10-23 17:49:22 +04:00
parent 1c6581e496
commit 2b19c61beb
4 changed files with 18 additions and 7 deletions

2
.gitignore vendored
View File

@ -4,4 +4,4 @@ build_storybook/
.DS_Store
build/
yarn-error.log
.env.*
.env*

View File

@ -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: {

View File

@ -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) {

View File

@ -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
}