From acf7970dc4166132d7818993d7071f24488fabaa Mon Sep 17 00:00:00 2001 From: madhusgowda Date: Fri, 30 Aug 2024 00:45:17 +0530 Subject: [PATCH 1/3] added ens support --- game/src/components/navbar.tsx | 87 ++++++++++++++++++++-------------- 1 file changed, 52 insertions(+), 35 deletions(-) diff --git a/game/src/components/navbar.tsx b/game/src/components/navbar.tsx index 2edbbd1..0b2a9ad 100644 --- a/game/src/components/navbar.tsx +++ b/game/src/components/navbar.tsx @@ -5,42 +5,59 @@ import { LogOut } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import { Button } from "./ui/button"; +import { useEffect, useState } from "react"; +import { ethers } from "ethers"; export const Navbar = () => { - const { user, logout } = usePrivy(); - const walletAddress = (user?.linkedAccounts as WalletWithMetadata[])?.find( - (a) => a.connectorType !== "embedded" - )?.address; + const { user, logout } = usePrivy(); + const walletAddress = (user?.linkedAccounts as WalletWithMetadata[])?.find( + (a) => a.connectorType !== "embedded" + )?.address; - // const { resolvedTheme } = useTheme(); - // const theme = resolvedTheme === "dark" ? "dark" : "light"; + const [ensName, setEnsName] = useState(null); - return ( -
- - dchess-logo - -
- {!!walletAddress && ( -
-

- AA Wallet: {formatHash(user?.wallet?.address || "...")} -

- -
- )} - {/* */} -
-
- ); -}; + const mainnetProvider = new ethers.providers.JsonRpcProvider(process.env.NEXT_PUBLIC_ETHEREUM_RPC); + + useEffect(() => { + const resolveEnsName = async () => { + if (walletAddress) { + try { + const resolvedName = await mainnetProvider.lookupAddress(walletAddress); + setEnsName(resolvedName || formatHash(walletAddress)); + } catch (error) { + setEnsName(formatHash(walletAddress)); + } + } + }; + resolveEnsName(); + }, [walletAddress]); + + return ( +
+ + dchess-logo + +
+ {!!walletAddress && ( +
+

+ AA Wallet: {ensName || formatHash(walletAddress)} +

+ +
+ )} + {/* */} +
+
+ ); +}; \ No newline at end of file From 81edc2ab46b1c0b03928f24da109969270195ae7 Mon Sep 17 00:00:00 2001 From: madhusgowda Date: Fri, 30 Aug 2024 00:46:57 +0530 Subject: [PATCH 2/3] added ens support --- game/.env.sample | 1 + 1 file changed, 1 insertion(+) diff --git a/game/.env.sample b/game/.env.sample index a7923c7..e4aadcd 100644 --- a/game/.env.sample +++ b/game/.env.sample @@ -1,2 +1,3 @@ NEXT_PUBLIC_API_BASE_URL=http://localhost:3012 NEXT_PUBLIC_PRIVY_APP_ID= +NEXT_PUBLIC_ETHEREUM_RPC= \ No newline at end of file From 7ddf1585894eac37b519058415200ef707f19bbe Mon Sep 17 00:00:00 2001 From: Madhu S Gowda <100760680+madhusgowda@users.noreply.github.com> Date: Fri, 25 Oct 2024 18:09:19 +0530 Subject: [PATCH 3/3] Update game/.env.sample Co-authored-by: Aashutosh Rathi --- game/.env.sample | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/.env.sample b/game/.env.sample index e4aadcd..db122fa 100644 --- a/game/.env.sample +++ b/game/.env.sample @@ -1,3 +1,3 @@ NEXT_PUBLIC_API_BASE_URL=http://localhost:3012 NEXT_PUBLIC_PRIVY_APP_ID= -NEXT_PUBLIC_ETHEREUM_RPC= \ No newline at end of file +NEXT_PUBLIC_ETHEREUM_RPC=