From 098a81a82d41aee464e2bfc87394d2fb02e94a65 Mon Sep 17 00:00:00 2001 From: rndquu Date: Wed, 9 Oct 2024 23:52:09 +0300 Subject: [PATCH 1/2] 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) { From 043252cba911249b3c6c55599e17a029005744a8 Mon Sep 17 00:00:00 2001 From: rndquu Date: Thu, 10 Oct 2024 01:02:29 +0300 Subject: [PATCH 2/2] refactor: return null on ens lookup error --- static/scripts/rewards/cirip/query-reverse-ens.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/scripts/rewards/cirip/query-reverse-ens.ts b/static/scripts/rewards/cirip/query-reverse-ens.ts index e1ded258..db836177 100644 --- a/static/scripts/rewards/cirip/query-reverse-ens.ts +++ b/static/scripts/rewards/cirip/query-reverse-ens.ts @@ -21,14 +21,14 @@ export async function queryReverseEns(address: string, networkId: number) { const mainnetProvider = await useHandler(1).getFirstAvailableRpcProvider(); if (mainnetProvider === null) { console.error("ENS lookup failed: no available mainnet RPC providers"); - return ""; + 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