Skip to content

Commit

Permalink
fix chain ID
Browse files Browse the repository at this point in the history
  • Loading branch information
jribbink committed Feb 7, 2025
1 parent ade3a6b commit b9c932f
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 181 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {formatChainId} from "../../util/eth"
import {NetworkManager} from "../../network/network-manager"
import {ethChainId} from "./eth-chain-id"

jest.mock("../../util/eth", () => ({
Expand All @@ -13,7 +13,7 @@ describe("eth_chainId handler", () => {
}
networkManagerMock.getChainId.mockResolvedValue(747)

const chainId = await ethChainId(networkManagerMock as any)()
const chainId = await ethChainId(networkManagerMock as any)

expect(chainId).toEqual("0x747")
expect(networkManagerMock.getChainId).toHaveBeenCalled()
Expand All @@ -22,10 +22,10 @@ describe("eth_chainId handler", () => {
test("should throw an error if no chain id is available", async () => {
const networkManagerMock = {
getChainId: jest.fn(),
}
} as unknown as jest.Mocked<NetworkManager>
networkManagerMock.getChainId.mockResolvedValue(null)

await expect(ethChainId(networkManagerMock as any)()).rejects.toThrow(
await expect(ethChainId(networkManagerMock)).rejects.toThrow(
"No active chain"
)
expect(networkManagerMock.getChainId).toHaveBeenCalled()
Expand Down
12 changes: 5 additions & 7 deletions packages/fcl-ethereum-provider/src/rpc/handlers/eth-chain-id.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import {NetworkManager} from "../../network/network-manager"
import {formatChainId} from "../../util/eth"

export function ethChainId(networkManager: NetworkManager) {
return async function () {
const chainId = await networkManager.getChainId()
if (!chainId) {
throw new Error("No active chain")
}
return formatChainId(chainId)
export async function ethChainId(networkManager: NetworkManager) {
const chainId = await networkManager.getChainId()
if (!chainId) {
throw new Error("No active chain")
}
return formatChainId(chainId)
}
2 changes: 1 addition & 1 deletion packages/fcl-ethereum-provider/src/rpc/rpc-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export class RpcProcessor {
const switchParams = params[0] as SwitchEthereumChainParams
return await this.networkManager.switchChain(switchParams)
case "eth_chainId":
return ethChainId(this.networkManager)
return await ethChainId(this.networkManager)
default:
return await this.gateway.request({
chainId,
Expand Down
Loading

0 comments on commit b9c932f

Please sign in to comment.