chore: added spinner to resolve, updated rpc
494ffd65
2 file(s) · +12 −1
| 3 | 3 | import { normalize } from "viem/ens"; |
|
| 4 | 4 | import type { ResolveOptions } from "../utils/types"; |
|
| 5 | 5 | import { ensClient } from "../utils/viem"; |
|
| 6 | + | import { spinner } from "../utils/spinner"; |
|
| 6 | 7 | ||
| 7 | 8 | export async function resolve(options: ResolveOptions) { |
|
| 8 | 9 | let name: string | null; |
|
| 9 | 10 | let address: Address | null; |
|
| 10 | 11 | let input: "address" | "name"; |
|
| 12 | + | spinner.start(); |
|
| 11 | 13 | ||
| 12 | 14 | // Handle name or address |
|
| 13 | 15 | if (isHex(options.input)) { |
|
| 31 | 33 | name: normalize(name as string), |
|
| 32 | 34 | key: options.txt, |
|
| 33 | 35 | }); |
|
| 36 | + | spinner.stop(); |
|
| 34 | 37 | console.log(res); |
|
| 35 | 38 | } catch (error) { |
|
| 36 | 39 | const e = error as { shortMessage: string }; |
|
| 40 | + | spinner.stop(); |
|
| 37 | 41 | console.error("Error fetching TXT record:", e.shortMessage); |
|
| 38 | 42 | } |
|
| 39 | 43 | return; |
|
| 45 | 49 | const contentHash = await getContentHashRecord(ensClient, { |
|
| 46 | 50 | name: name as string, |
|
| 47 | 51 | }); |
|
| 52 | + | spinner.stop(); |
|
| 48 | 53 | console.log(contentHash?.decoded || "Not found"); |
|
| 49 | 54 | } catch (error) { |
|
| 50 | 55 | const e = error as { shortMessage: string }; |
|
| 56 | + | spinner.stop(); |
|
| 51 | 57 | console.error("Error fetching content hash:", e.shortMessage); |
|
| 52 | 58 | } |
|
| 53 | 59 | return; |
|
| 59 | 65 | name: name as string, |
|
| 60 | 66 | coins: [options.chain], |
|
| 61 | 67 | }); |
|
| 68 | + | spinner.stop(); |
|
| 62 | 69 | console.log(result.coins[0]?.value || "Not found"); |
|
| 63 | 70 | } catch (error) { |
|
| 64 | 71 | const e = error as { shortMessage: string }; |
|
| 72 | + | spinner.stop(); |
|
| 65 | 73 | console.error("Error fetching chain record:", e.shortMessage); |
|
| 66 | 74 | } |
|
| 75 | + | spinner.stop(); |
|
| 67 | 76 | return; |
|
| 68 | 77 | } |
|
| 69 | 78 | // Print basic resolve if no args passed |
|
| 70 | 79 | if (input === "name") { |
|
| 80 | + | spinner.stop(); |
|
| 71 | 81 | console.log(address); |
|
| 72 | 82 | } else { |
|
| 83 | + | spinner.stop(); |
|
| 73 | 84 | console.log(name); |
|
| 74 | 85 | } |
|
| 75 | 86 | return; |
|
| 4 | 4 | ||
| 5 | 5 | export const ensClient = createPublicClient({ |
|
| 6 | 6 | chain: addEnsContracts(mainnet), |
|
| 7 | - | transport: http("https://eth.llamarpc.com"), |
|
| 7 | + | transport: http(process.env.ETH_RPC_URL || "https://eth.drpc.org"), |
|
| 8 | 8 | }); |