diff --git a/static/scripts/rewards/cirip/query-reverse-ens.ts b/static/scripts/rewards/cirip/query-reverse-ens.ts index b294c1db..db836177 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,12 +18,17 @@ 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 null; + } + const web3Provider = new ethers.providers.JsonRpcProvider(mainnetProvider.connection.url); const ensName = await web3Provider.lookupAddress(address); if (ensName === null) { console.error("ENS lookup failed: API request failed"); - return ""; + return null; } // Store the ENS name in localStorage for future use