From 098a81a82d41aee464e2bfc87394d2fb02e94a65 Mon Sep 17 00:00:00 2001 From: rndquu Date: Wed, 9 Oct 2024 23:52:09 +0300 Subject: [PATCH] refactor: use rpc-handler for ENS lookups --- static/scripts/rewards/cirip/query-reverse-ens.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/static/scripts/rewards/cirip/query-reverse-ens.ts b/static/scripts/rewards/cirip/query-reverse-ens.ts index b294c1db..e1ded258 100644 --- a/static/scripts/rewards/cirip/query-reverse-ens.ts +++ b/static/scripts/rewards/cirip/query-reverse-ens.ts @@ -1,9 +1,7 @@ import { app } from "../app-state"; -import { useRpcHandler } from "../web3/use-rpc-handler"; +import { useHandler, useRpcHandler } from "../web3/use-rpc-handler"; import { ethers } from "ethers"; -const mainnetRpcUrl = "https://eth.drpc.org"; - export async function queryReverseEns(address: string, networkId: number) { // Try to get the ENS name from localStorage const cachedEnsName = localStorage.getItem(address); @@ -20,7 +18,12 @@ export async function queryReverseEns(address: string, networkId: number) { return cachedEnsName; } else { // If the ENS name is not in localStorage, fetch it from the API - const web3Provider = new ethers.providers.JsonRpcProvider(mainnetRpcUrl); + const mainnetProvider = await useHandler(1).getFirstAvailableRpcProvider(); + if (mainnetProvider === null) { + console.error("ENS lookup failed: no available mainnet RPC providers"); + return ""; + } + const web3Provider = new ethers.providers.JsonRpcProvider(mainnetProvider.connection.url); const ensName = await web3Provider.lookupAddress(address); if (ensName === null) {