'use client'; import { AddressAvatar } from '@/components/blocks/address-avatar/address-avatar'; import { ThemeMenuItem } from '@/components/blocks/theme/theme-menu-item'; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Skeleton } from '@/components/ui/skeleton'; import { usePollingInterval } from '@/hooks/use-polling-interval'; import { useQueryKeys } from '@/hooks/use-query-keys'; import { authClient } from '@/lib/auth/client'; import { shortHex } from '@/lib/hex'; import { portalClient, portalGraphql } from '@/lib/settlemint/portal'; import { useQuery } from '@tanstack/react-query'; import { BookOpenText, BringToFront, ChevronDown, LogOut } from 'lucide-react'; import Link from 'next/link'; import { useRouter } from 'next/navigation'; import { Suspense, useCallback } from 'react'; import type { Address } from 'viem'; import { Badge } from '../ui/badge'; const GetPendingTransactions = portalGraphql(` query GetPendingTransactions($from: String) { getPendingTransactions(from: $from) { count } } `); export function UserDropdown() { const { data: userSession } = authClient.useSession(); const interval = usePollingInterval(5000); const router = useRouter(); const { keys } = useQueryKeys(); const wallet = userSession?.user.wallet as Address | undefined; const email = userSession?.user.email; const name = userSession?.user.name; const { data: pendingCount } = useQuery({ queryKey: keys.user.transactions({ email, wallet }), queryFn: async () => { const response = await portalClient.request(GetPendingTransactions, { from: wallet, }); if (!response?.getPendingTransactions) { return 0; } return response.getPendingTransactions.count; }, refetchInterval: interval, enabled: !!wallet, initialData: 0, }); const handleSignOut = useCallback(async () => { await authClient.signOut({ fetchOptions: { onSuccess: () => { router.push('/'); // redirect to login page }, }, }); }, [router]); if (!userSession) { return null; } return (
}> 0} />
{name || email ? ( {name ?? email} ) : ( )} {wallet ? ( {shortHex(wallet, { prefixLength: 12, suffixLength: 8 })} ) : ( )}
Pending Transactions {(pendingCount ?? 0) > 0 && ( {pendingCount} )} Documentation Log out
); }