Commit 48ad8e52 authored by Moody Salem's avatar Moody Salem

more flexible detection of network

parent b669ec69
import { Web3Provider } from '@ethersproject/providers' import { Web3Provider } from '@ethersproject/providers'
import { MiniRpcProvider } from '../connectors/NetworkConnector'
export default function getLibrary(provider: any): Web3Provider { 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 // latest ethers version tries to detect the network which fails
if (provider instanceof MiniRpcProvider) { const library = new Web3Provider(
return new Web3Provider(provider as any, provider.chainId) provider,
} typeof provider.chainId === 'number'
const library = new Web3Provider(provider, 'any') ? provider.chainId
: typeof provider.chainId === 'string'
? parseInt(provider.chainId)
: 'any'
)
library.pollingInterval = 15000 library.pollingInterval = 15000
return library return library
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment