mirror of
https://github.com/status-im/safe-react.git
synced 2025-02-18 20:46:29 +00:00
Use our own web3 instance to fetch data from blockchain because of limitations in web3connect
This commit is contained in:
parent
1c6581e496
commit
2b19c61beb
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,4 +4,4 @@ build_storybook/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
build/
|
build/
|
||||||
yarn-error.log
|
yarn-error.log
|
||||||
.env.*
|
.env*
|
@ -13,8 +13,6 @@ import Button from '~/components/layout/Button'
|
|||||||
import { fetchProvider } from '~/logic/wallets/store/actions'
|
import { fetchProvider } from '~/logic/wallets/store/actions'
|
||||||
import { getNetwork } from '~/config'
|
import { getNetwork } from '~/config'
|
||||||
|
|
||||||
console.log(process.env)
|
|
||||||
|
|
||||||
const web3Connect = new Web3Connect.Core({
|
const web3Connect = new Web3Connect.Core({
|
||||||
network: getNetwork().toLowerCase(),
|
network: getNetwork().toLowerCase(),
|
||||||
providerOptions: {
|
providerOptions: {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { BigNumber } from 'bignumber.js'
|
import { BigNumber } from 'bignumber.js'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
import { getWeb3, web3RO } from '~/logic/wallets/getWeb3'
|
||||||
|
|
||||||
// const MAINNET_NETWORK = 1
|
// const MAINNET_NETWORK = 1
|
||||||
export const EMPTY_DATA = '0x'
|
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'))
|
return Promise.reject(new Error('No valid Tx hash to get receipt from'))
|
||||||
}
|
}
|
||||||
|
|
||||||
const web3 = getWeb3()
|
const txReceipt = await web3RO.eth.getTransactionReceipt(hash)
|
||||||
const txReceipt = await web3.eth.getTransactionReceipt(hash)
|
|
||||||
|
|
||||||
const { status } = txReceipt
|
const { status } = txReceipt
|
||||||
if (!status) {
|
if (!status) {
|
||||||
|
@ -22,6 +22,7 @@ export const WALLET_PROVIDER = {
|
|||||||
PORTIS: 'PORTIS',
|
PORTIS: 'PORTIS',
|
||||||
FORTMATIC: 'FORTMATIC',
|
FORTMATIC: 'FORTMATIC',
|
||||||
SQUARELINK: 'SQUARELINK',
|
SQUARELINK: 'SQUARELINK',
|
||||||
|
WALLETCONNECT: 'WALLETCONNECT',
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ETHEREUM_NETWORK_IDS = {
|
export const ETHEREUM_NETWORK_IDS = {
|
||||||
@ -49,9 +50,18 @@ export const getEtherScanLink = (type: 'address' | 'tx', value: string) => {
|
|||||||
let web3
|
let web3
|
||||||
export const getWeb3 = () => web3 || (window.web3 && new Web3(window.web3.currentProvider)) || (window.ethereum && new Web3(window.ethereum))
|
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 => {
|
const getProviderName: Function = (web3Provider): string => {
|
||||||
let name
|
let name
|
||||||
console.log(web3Provider)
|
|
||||||
|
|
||||||
switch (web3Provider.currentProvider.constructor.name) {
|
switch (web3Provider.currentProvider.constructor.name) {
|
||||||
case 'SafeWeb3Provider':
|
case 'SafeWeb3Provider':
|
||||||
@ -80,6 +90,10 @@ const getProviderName: Function = (web3Provider): string => {
|
|||||||
name = WALLET_PROVIDER.SQUARELINK
|
name = WALLET_PROVIDER.SQUARELINK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (web3Provider.currentProvider.isWalletConnect) {
|
||||||
|
name = WALLET_PROVIDER.WALLETCONNECT
|
||||||
|
}
|
||||||
|
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user