Skip to content
Open
Changes from all 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
46 changes: 46 additions & 0 deletions src/components/NavbarWallet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"use client";

import { useState } from "react";

/** Navbar wallet button + network switcher (GFI). */
export function NavbarWallet({
address,
network,
networks = ["TESTNET", "PUBLIC"],
onConnect,
onSwitchNetwork,
}: {
address?: string | null;
network?: string | null;
networks?: string[];
onConnect?: () => void;
onSwitchNetwork?: (n: string) => void;
}) {
const [open, setOpen] = useState(false);
const short = address ? `${address.slice(0, 4)}…${address.slice(-4)}` : null;
return (
<div style={{ display: "flex", gap: 8, alignItems: "center" }}>
<button type="button" onClick={() => (address ? setOpen((v) => !v) : onConnect?.())}>
{short || "Connect wallet"}
</button>
{address ? (
<select
aria-label="Network"
value={network || networks[0]}
onChange={(e) => onSwitchNetwork?.(e.target.value)}
>
{networks.map((n) => (
<option key={n} value={n}>
{n}
</option>
))}
</select>
) : null}
{open && address ? (
<div role="status" style={{ fontSize: 12 }}>
{address}
</div>
) : null}
</div>
);
}