Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions game/.env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
NEXT_PUBLIC_API_BASE_URL=http://localhost:3012
NEXT_PUBLIC_PRIVY_APP_ID=
NEXT_PUBLIC_ETHEREUM_RPC=
87 changes: 52 additions & 35 deletions game/src/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think ethers is dep in game. You might have to use viem or install this.


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<string | null>(null);

return (
<div className="flex justify-between flex-wrap p-6 px-4 m-auto w-full lg:w-[1500px]">
<Link
href={"/"}
className="text-4xl font-bold select-none cursor-pointer"
>
<Image
src={"https://chess.stf.xyz/logo-white.svg"}
width={150}
height={150}
alt="dchess-logo"
/>
</Link>
<div className="flex gap-4 place-items-center">
{!!walletAddress && (
<div className="flex gap-4 items-center">
<p className="font-mono">
<b>AA Wallet:</b> {formatHash(user?.wallet?.address || "...")}
</p>
<Button onClick={logout} variant="outline" size="icon">
<LogOut />
</Button>
</div>
)}
{/* <ThemeToggle /> */}
</div>
</div>
);
};
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 (
<div className="flex justify-between flex-wrap p-6 px-4 m-auto w-full lg:w-[1500px]">
<Link
href={"/"}
className="text-4xl font-bold select-none cursor-pointer"
>
<Image
src={"https://chess.stf.xyz/logo-white.svg"}
width={150}
height={150}
alt="dchess-logo"
/>
</Link>
<div className="flex gap-4 place-items-center">
{!!walletAddress && (
<div className="flex gap-4 items-center">
<p className="font-mono">
<b>AA Wallet:</b> {ensName || formatHash(walletAddress)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few changes here, the walletAddress will be the user's non-custodial wallet address.
So you might have to show it like here

Since this wallet is Injected and the one with connectorType as embedded is AA Wallet.

</p>
<Button onClick={logout} variant="outline" size="icon">
<LogOut />
</Button>
</div>
)}
{/* <ThemeToggle /> */}
</div>
</div>
);
};