feat(wallet): redesign drawer wallet states to match Figma 4476-15287/15669
Disconnected state (Figma 4476-15287): bump the compact CTA to the
spec'd dimensions — h-12 (48px), text-[15px], font-medium — so the
yellow 链接钱包 button matches the Figma pill exactly while leaving
the desktop header pill (compact=false) untouched.
Connected state (Figma 4476-15669/16024): rebuild the compact branch as
the spec'd info card + danger button:
- A transparent 登录地址 label (text-[13px] font-bold #E5E5E5) with an
8px gap to the full 0x… address, which uses Figma's character-level
styling: first 5 and last 5 chars rendered bold white, middle 32
chars rendered #A8A9AE / font-medium, replicating Figma's
characterStyleOverrides.
- A full-width 48px disconnect pill at bg-[#2A1B20] with #F36161 text
and the LogOut glyph on the right at 15px font-medium.
Add a new walletLoginAddress i18n key across all 7 locales (en, zh-CN,
ja, ko, vi, id, ms) for the new 登录地址 label.
2026-06-05 12:22:41 +08:00
|
|
|
import { Heart, LogOut } from "lucide-react";
|
2026-06-02 00:32:46 +08:00
|
|
|
import { useEffect, useRef, useState } from "react";
|
2026-06-02 03:43:13 +08:00
|
|
|
import { Link } from "react-router-dom";
|
2026-06-03 21:59:38 +08:00
|
|
|
import { WalletIcon } from "../components/icons/WalletIcon";
|
2026-06-02 00:32:46 +08:00
|
|
|
import { useI18n } from "../i18n";
|
2026-06-02 03:43:13 +08:00
|
|
|
import { useLocalizedPath } from "../useLocalizedPath";
|
2026-06-02 00:32:46 +08:00
|
|
|
import { shortenAddress, useWallet } from "./WalletProvider";
|
|
|
|
|
|
2026-06-02 00:45:58 +08:00
|
|
|
export function WalletButton({
|
|
|
|
|
compact = false,
|
|
|
|
|
onOpenLogin,
|
|
|
|
|
}: {
|
|
|
|
|
compact?: boolean;
|
|
|
|
|
onOpenLogin?: () => void;
|
|
|
|
|
}) {
|
2026-06-02 00:32:46 +08:00
|
|
|
const { t } = useI18n();
|
2026-06-02 03:43:13 +08:00
|
|
|
const lp = useLocalizedPath();
|
2026-06-02 00:32:46 +08:00
|
|
|
const wallet = useWallet();
|
|
|
|
|
const [open, setOpen] = useState(false);
|
|
|
|
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (!open) return;
|
|
|
|
|
const closeOnOutside = (event: MouseEvent | TouchEvent) => {
|
|
|
|
|
if (!rootRef.current?.contains(event.target as Node)) setOpen(false);
|
|
|
|
|
};
|
|
|
|
|
const closeOnEscape = (event: KeyboardEvent) => {
|
|
|
|
|
if (event.key === "Escape") setOpen(false);
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener("mousedown", closeOnOutside);
|
|
|
|
|
document.addEventListener("touchstart", closeOnOutside);
|
|
|
|
|
window.addEventListener("keydown", closeOnEscape);
|
|
|
|
|
return () => {
|
|
|
|
|
document.removeEventListener("mousedown", closeOnOutside);
|
|
|
|
|
document.removeEventListener("touchstart", closeOnOutside);
|
|
|
|
|
window.removeEventListener("keydown", closeOnEscape);
|
|
|
|
|
};
|
|
|
|
|
}, [open]);
|
|
|
|
|
|
|
|
|
|
if (wallet.status === "loggedIn" && wallet.address) {
|
2026-06-02 21:05:01 +08:00
|
|
|
if (compact) {
|
|
|
|
|
return (
|
feat(wallet): redesign drawer wallet states to match Figma 4476-15287/15669
Disconnected state (Figma 4476-15287): bump the compact CTA to the
spec'd dimensions — h-12 (48px), text-[15px], font-medium — so the
yellow 链接钱包 button matches the Figma pill exactly while leaving
the desktop header pill (compact=false) untouched.
Connected state (Figma 4476-15669/16024): rebuild the compact branch as
the spec'd info card + danger button:
- A transparent 登录地址 label (text-[13px] font-bold #E5E5E5) with an
8px gap to the full 0x… address, which uses Figma's character-level
styling: first 5 and last 5 chars rendered bold white, middle 32
chars rendered #A8A9AE / font-medium, replicating Figma's
characterStyleOverrides.
- A full-width 48px disconnect pill at bg-[#2A1B20] with #F36161 text
and the LogOut glyph on the right at 15px font-medium.
Add a new walletLoginAddress i18n key across all 7 locales (en, zh-CN,
ja, ko, vi, id, ms) for the new 登录地址 label.
2026-06-05 12:22:41 +08:00
|
|
|
<div className="flex w-full flex-col gap-1">
|
|
|
|
|
<div className="flex flex-col gap-2 px-4 py-3">
|
|
|
|
|
<div className="text-[13px] font-bold leading-[21px] text-[#E5E5E5]">
|
|
|
|
|
{t("walletLoginAddress")}
|
|
|
|
|
</div>
|
|
|
|
|
<div className="break-all text-[13px] leading-[21px]">
|
|
|
|
|
<span className="font-bold text-white">
|
|
|
|
|
{wallet.address.slice(0, 5)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-medium text-[#A8A9AE]">
|
|
|
|
|
{wallet.address.slice(5, -5)}
|
|
|
|
|
</span>
|
|
|
|
|
<span className="font-bold text-white">
|
|
|
|
|
{wallet.address.slice(-5)}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
2026-06-02 21:05:01 +08:00
|
|
|
</div>
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => wallet.logout()}
|
feat(wallet): redesign drawer wallet states to match Figma 4476-15287/15669
Disconnected state (Figma 4476-15287): bump the compact CTA to the
spec'd dimensions — h-12 (48px), text-[15px], font-medium — so the
yellow 链接钱包 button matches the Figma pill exactly while leaving
the desktop header pill (compact=false) untouched.
Connected state (Figma 4476-15669/16024): rebuild the compact branch as
the spec'd info card + danger button:
- A transparent 登录地址 label (text-[13px] font-bold #E5E5E5) with an
8px gap to the full 0x… address, which uses Figma's character-level
styling: first 5 and last 5 chars rendered bold white, middle 32
chars rendered #A8A9AE / font-medium, replicating Figma's
characterStyleOverrides.
- A full-width 48px disconnect pill at bg-[#2A1B20] with #F36161 text
and the LogOut glyph on the right at 15px font-medium.
Add a new walletLoginAddress i18n key across all 7 locales (en, zh-CN,
ja, ko, vi, id, ms) for the new 登录地址 label.
2026-06-05 12:22:41 +08:00
|
|
|
className="flex h-12 w-full items-center justify-center gap-2 rounded-full bg-[#2A1B20] px-4 text-[15px] font-medium text-[#F36161] outline-none transition hover:bg-[#3a242a] focus-visible:ring-2 focus-visible:ring-[#F36161]/60"
|
2026-06-02 21:05:01 +08:00
|
|
|
>
|
feat(wallet): redesign drawer wallet states to match Figma 4476-15287/15669
Disconnected state (Figma 4476-15287): bump the compact CTA to the
spec'd dimensions — h-12 (48px), text-[15px], font-medium — so the
yellow 链接钱包 button matches the Figma pill exactly while leaving
the desktop header pill (compact=false) untouched.
Connected state (Figma 4476-15669/16024): rebuild the compact branch as
the spec'd info card + danger button:
- A transparent 登录地址 label (text-[13px] font-bold #E5E5E5) with an
8px gap to the full 0x… address, which uses Figma's character-level
styling: first 5 and last 5 chars rendered bold white, middle 32
chars rendered #A8A9AE / font-medium, replicating Figma's
characterStyleOverrides.
- A full-width 48px disconnect pill at bg-[#2A1B20] with #F36161 text
and the LogOut glyph on the right at 15px font-medium.
Add a new walletLoginAddress i18n key across all 7 locales (en, zh-CN,
ja, ko, vi, id, ms) for the new 登录地址 label.
2026-06-05 12:22:41 +08:00
|
|
|
<span>{t("walletDisconnect")}</span>
|
|
|
|
|
<LogOut className="h-4 w-4" strokeWidth={2.3} aria-hidden />
|
2026-06-02 21:05:01 +08:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 00:32:46 +08:00
|
|
|
return (
|
|
|
|
|
<div ref={rootRef} className="relative">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => setOpen((value) => !value)}
|
|
|
|
|
className={[
|
|
|
|
|
"inline-flex h-10 items-center justify-center rounded-full border border-ark-gold/45 bg-ark-gold/10 px-3 text-sm font-semibold text-ark-gold2 outline-none transition hover:bg-ark-gold/15 focus-visible:ring-2 focus-visible:ring-ark-gold/80 focus-visible:ring-offset-2 focus-visible:ring-offset-ark-bg",
|
|
|
|
|
compact ? "w-full" : "",
|
|
|
|
|
].join(" ")}
|
|
|
|
|
aria-label={t("walletConnectedAs")}
|
|
|
|
|
aria-expanded={open}
|
|
|
|
|
>
|
|
|
|
|
<span className="mr-2 h-2 w-2 rounded-full bg-emerald-400" />
|
|
|
|
|
{shortenAddress(wallet.address)}
|
|
|
|
|
</button>
|
|
|
|
|
{open ? (
|
|
|
|
|
<div className="absolute right-0 top-[calc(100%+0.5rem)] z-50 w-52 rounded-2xl border border-white/10 bg-[#1c1c21]/95 p-2 shadow-2xl shadow-black/70 ring-1 ring-ark-line/80 backdrop-blur-xl">
|
|
|
|
|
<div className="truncate px-3 py-2 text-xs text-neutral-400">
|
|
|
|
|
{wallet.address}
|
|
|
|
|
</div>
|
2026-06-02 03:43:13 +08:00
|
|
|
<Link
|
|
|
|
|
to={lp("/favorites")}
|
|
|
|
|
onClick={() => setOpen(false)}
|
|
|
|
|
className="flex w-full items-center gap-2 rounded-xl px-3 py-2 text-left text-sm font-medium text-neutral-100 transition hover:bg-ark-gold/10 hover:text-ark-gold"
|
|
|
|
|
>
|
|
|
|
|
<Heart size={16} strokeWidth={2} />
|
|
|
|
|
{t("favorites")}
|
|
|
|
|
</Link>
|
2026-06-02 00:32:46 +08:00
|
|
|
<button
|
|
|
|
|
type="button"
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setOpen(false);
|
|
|
|
|
wallet.logout();
|
|
|
|
|
}}
|
|
|
|
|
className="w-full rounded-xl px-3 py-2 text-left text-sm font-medium text-red-200 transition hover:bg-red-500/10"
|
|
|
|
|
>
|
|
|
|
|
{t("walletDisconnect")}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2026-06-02 00:45:58 +08:00
|
|
|
onClick={() => {
|
|
|
|
|
onOpenLogin?.();
|
|
|
|
|
wallet.openLoginModal();
|
|
|
|
|
}}
|
2026-06-02 00:32:46 +08:00
|
|
|
className={[
|
feat(wallet): redesign drawer wallet states to match Figma 4476-15287/15669
Disconnected state (Figma 4476-15287): bump the compact CTA to the
spec'd dimensions — h-12 (48px), text-[15px], font-medium — so the
yellow 链接钱包 button matches the Figma pill exactly while leaving
the desktop header pill (compact=false) untouched.
Connected state (Figma 4476-15669/16024): rebuild the compact branch as
the spec'd info card + danger button:
- A transparent 登录地址 label (text-[13px] font-bold #E5E5E5) with an
8px gap to the full 0x… address, which uses Figma's character-level
styling: first 5 and last 5 chars rendered bold white, middle 32
chars rendered #A8A9AE / font-medium, replicating Figma's
characterStyleOverrides.
- A full-width 48px disconnect pill at bg-[#2A1B20] with #F36161 text
and the LogOut glyph on the right at 15px font-medium.
Add a new walletLoginAddress i18n key across all 7 locales (en, zh-CN,
ja, ko, vi, id, ms) for the new 登录地址 label.
2026-06-05 12:22:41 +08:00
|
|
|
"inline-flex items-center justify-center gap-2 rounded-full border border-ark-gold bg-ark-gold px-4 text-black outline-none transition hover:bg-ark-gold2 focus-visible:ring-2 focus-visible:ring-ark-gold/80 focus-visible:ring-offset-2 focus-visible:ring-offset-ark-bg",
|
|
|
|
|
compact
|
|
|
|
|
? "h-12 w-full text-[15px] font-medium"
|
|
|
|
|
: "h-10 min-w-[124px] shrink-0 whitespace-nowrap text-sm font-bold",
|
2026-06-02 00:32:46 +08:00
|
|
|
].join(" ")}
|
|
|
|
|
>
|
2026-06-03 21:59:38 +08:00
|
|
|
<WalletIcon className="h-[18px] w-[18px]" />
|
2026-06-03 08:18:05 +08:00
|
|
|
<span>
|
|
|
|
|
{wallet.status === "loading" ? t("loading") : t("walletConnect")}
|
|
|
|
|
</span>
|
2026-06-02 00:32:46 +08:00
|
|
|
</button>
|
|
|
|
|
);
|
|
|
|
|
}
|