more flexible detection of network

This commit is contained in:
Moody Salem 2021-04-19 12:55:54 -05:00
parent b669ec6976
commit 48ad8e529f
No known key found for this signature in database
GPG Key ID: 8CB5CD10385138DB

@ -1,12 +1,15 @@
import { Web3Provider } from '@ethersproject/providers'
import { MiniRpcProvider } from '../connectors/NetworkConnector'
export default function getLibrary(provider: any): Web3Provider {
// ethers tries to detect the network which fails and is unnecessary with our mini rpc provider if we do not pass the correct network id
if (provider instanceof MiniRpcProvider) {
return new Web3Provider(provider as any, provider.chainId)
}
const library = new Web3Provider(provider, 'any')
// latest ethers version tries to detect the network which fails
const library = new Web3Provider(
provider,
typeof provider.chainId === 'number'
? provider.chainId
: typeof provider.chainId === 'string'
? parseInt(provider.chainId)
: 'any'
)
library.pollingInterval = 15000
return library
}