Skip to content

Commit

Permalink
fix: return eip1193bridge chainId as hexa (#3332)
Browse files Browse the repository at this point in the history
  • Loading branch information
zzmp authored Feb 17, 2022
1 parent 0e709c2 commit 90c59f3
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/lib/hooks/useEip1193Provider.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import { Provider as EthersProvider } from '@ethersproject/abstract-provider'
import { Signer as EthersSigner } from '@ethersproject/abstract-signer'
import { VoidSigner } from '@ethersproject/abstract-signer'
import { Eip1193Bridge } from '@ethersproject/experimental'
import { Eip1193Bridge as ExperimentalEip1193Bridge } from '@ethersproject/experimental'
import { JsonRpcProvider } from '@ethersproject/providers'
import { Provider as Eip1193Provider } from '@web3-react/types'
import { ZERO_ADDRESS } from 'constants/misc'
import { useMemo } from 'react'

const voidSigner = new VoidSigner(ZERO_ADDRESS)

class Eip1193Bridge extends ExperimentalEip1193Bridge {
async send(method: string, params?: Array<any>): Promise<any> {
switch (method) {
case 'eth_chainId': {
// TODO(https://github.com/ethers-io/ethers.js/pull/2711): Returns eth_chainId as a hexadecimal.
const result = await this.provider.getNetwork()
return '0x' + result.chainId.toString(16)
}
default:
return super.send(method, params)
}
}
}

export default function useEip1193Provider(
provider?: Eip1193Provider | EthersProvider | JsonRpcProvider | { provider: EthersProvider; signer: EthersSigner }
): Eip1193Provider | undefined {
Expand Down

0 comments on commit 90c59f3

Please sign in to comment.