Skip to content

Commit

Permalink
Merge pull request #330 from rndquu/feat/305
Browse files Browse the repository at this point in the history
refactor: use rpc-handler for ENS lookups
  • Loading branch information
ubiquity-os[bot] authored Oct 21, 2024
2 parents 0ad1138 + 043252c commit 625a74b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions static/scripts/rewards/cirip/query-reverse-ens.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 625a74b

Please sign in to comment.