Skip to content

Commit

Permalink
Fix primary name resolution
Browse files Browse the repository at this point in the history
fix primary names
  • Loading branch information
nenadmitt authored Dec 7, 2024
2 parents 94fa0e8 + 9657fc0 commit bb039ce
Show file tree
Hide file tree
Showing 4 changed files with 258 additions and 91 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"dependencies": {
"@ensdomains/address-encoder": "^1.1.2",
"@ensdomains/ensjs": "^4.0.2",
"@rainbow-me/rainbowkit": "^2.2.0",
"@tanstack/react-query": "^5.59.20",
"@types/lodash.merge": "^4.6.9",
Expand All @@ -25,7 +26,7 @@
"react-icons": "^5.3.0",
"react-toastify": "^10.0.6",
"sass": "^1.80.7",
"viem": "2.x",
"viem": "^2.21.54",
"wagmi": "^2.12.31"
},
"devDependencies": {
Expand Down
20 changes: 17 additions & 3 deletions src/components/MintForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Link from "next/link";
import { useConnectModal } from "@rainbow-me/rainbowkit";
import { SideModal } from "./SideModal";
import { TbAlertSquare } from "react-icons/tb";
import { normalise } from "@ensdomains/ensjs/utils";

const namespaceClient = createNamespaceClient({
chainId: optimism.id,
Expand Down Expand Up @@ -88,11 +89,23 @@ export const MintForm = () => {
}, []);

const handleSearch = async (value: string) => {
setSearchLabel(value);

const _value = value.toLocaleLowerCase();

if (value.length > 0) {
if (_value.includes(".")) {
return;
}

try {
normalise(_value);
} catch (err) {
return;
}
setSearchLabel(_value);

if (_value.length > 0) {
setIndicator({ isAvailable: false, isChecking: true });
debouncedCheckAvailable(value);
debouncedCheckAvailable(_value);
}
};

Expand Down Expand Up @@ -284,6 +297,7 @@ export const MintForm = () => {
onChange={(e) => handleSearch(e.target.value)}
placeholder="Your name here...."
className="tech-input"
value={searchLabel}
></input>
<div className="loader-cont">
{indicator.isChecking && <Spinner />}
Expand Down
30 changes: 25 additions & 5 deletions src/components/UserProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,23 @@
import Link from "next/link";
import { useEffect, useState } from "react";
import { useAccount, useDisconnect, usePublicClient } from "wagmi";
import {
addEnsContracts,
ensPublicActions,
ensSubgraphActions,
} from "@ensdomains/ensjs";
import { mainnet } from "viem/chains";
import { createPublicClient, http } from "viem";

const cacheExpiration = 60 * 1000;
const ensMainnetClient = createPublicClient({
chain: {
...addEnsContracts(mainnet),
},
// Temp solution
transport: http("https://appv2.namespace.ninja/rpc/mainnet"),
})
.extend(ensSubgraphActions)
.extend(ensPublicActions);

export const UserProfile = () => {
const publicClient = usePublicClient({ chainId: 1 });
Expand All @@ -19,14 +34,19 @@ export const UserProfile = () => {
});

useEffect(() => {
("");
publicClient?.getEnsName;
if (address && publicClient) {
const init = async () => {
let ensName: string;
let ensAvatar: string;
const name = await publicClient.getEnsName({ address });
if (name && name.length > 0) {
ensName = name;
const avatar = await publicClient.getEnsAvatar({ name });
const name = await ensMainnetClient.getName({ address });
if (name?.match) {
ensName = name.name;
const avatar = await ensMainnetClient.getTextRecord({
name: ensName,
key: "avatar",
});
if (avatar) {
ensAvatar = avatar;
}
Expand Down
Loading

0 comments on commit bb039ce

Please sign in to comment.