Adds global interface for window.web3

This commit is contained in:
Agustin Pane 2020-06-25 12:27:38 -03:00
parent 8625684b2a
commit d7d2305b9c
3 changed files with 15 additions and 6 deletions

View File

@ -3,7 +3,16 @@ import Web3 from 'web3'
import { sameAddress } from './ethAddresses'
import { EMPTY_DATA } from './ethTransactions'
import { getNetwork } from 'src/config/index'
import { getNetwork } from '../../config'
declare global {
interface Window {
web3: {
currentProvider: any
}
testAccountIndex: string
}
}
export const ETHEREUM_NETWORK = {
MAINNET: 'MAINNET',
@ -64,7 +73,7 @@ export const getInfuraUrl = () => {
export const web3ReadOnly =
process.env.NODE_ENV !== 'test'
? new Web3(new Web3.providers.HttpProvider(getInfuraUrl()))
: new Web3((window as any).web3?.currentProvider || 'ws://localhost:8545')
: new Web3(window.web3?.currentProvider || 'ws://localhost:8545')
let web3 = web3ReadOnly
export const getWeb3 = () => web3
@ -76,8 +85,8 @@ export const resetWeb3 = () => {
export const getAccountFrom = async (web3Provider) => {
const accounts = await web3Provider.eth.getAccounts()
if (process.env.NODE_ENV === 'test' && (window as any).testAccountIndex) {
return accounts[(window as any).testAccountIndex]
if (process.env.NODE_ENV === 'test' && window.testAccountIndex) {
return accounts[window.testAccountIndex]
}
return accounts && accounts.length > 0 ? accounts[0] : null

View File

@ -72,7 +72,7 @@ export const aMinedSafe = async (
threshold = 1,
name = 'Safe Name',
) => {
const provider = await getProviderInfo((window as any).web3?.currentProvider || 'ws://localhost:8545')
const provider = await getProviderInfo(window.web3?.currentProvider || 'ws://localhost:8545')
const walletRecord = makeProvider(provider)
store.dispatch(addProvider(walletRecord))

View File

@ -29,7 +29,7 @@ afterAll(() => {
})
const renderLoadSafe = async (localStore) => {
const provider = await getProviderInfo((window as any).web3.currentProvider || 'ws://localhost:8545')
const provider = await getProviderInfo(window.web3.currentProvider || 'ws://localhost:8545')
const walletRecord = makeProvider(provider)
localStore.dispatch(addProvider(walletRecord))