"use client"; import { FragmentType, graphql, useFragment } from "@/generated/gql/whisk"; import { HTMLAttributes, useMemo } from "react"; import { Address } from "viem"; import { AvatarUi } from "../avatar"; import { NameUi } from "../name"; import { CONFIG } from "@/config"; import { formatAddress } from "@/format"; import { cn } from "@/ui"; import { Skeleton } from "@/ui/skeleton"; const SOCIALS_IMAGE_BASE_URL = CONFIG.whiskServerUrl + "/static/img/social"; export const Profile_IdentityFragment = graphql(/* GraphQL */ ` fragment Profile_IdentityFragment on Identity { aggregate { name avatar bio website x github discord telegram } ens { name } farcaster { name } nns { name } base { name } uni { name } lens { name } world { name } } `); interface ProfileUi extends HTMLAttributes { address: Address; fragment: FragmentType | undefined; } export function ProfileUi({ address, fragment, className, ...props }: ProfileUi) { const identity = useFragment(Profile_IdentityFragment, fragment); return (
{formatAddress({ address })}
{identity ? ( <> {identity.aggregate.bio && {identity.aggregate.bio}} {identity.aggregate.website && ( {identity.aggregate.website} )} ) : ( )}
Connected accounts
); } function SocialItems({ fragment }: Pick) { const identity = useFragment(Profile_IdentityFragment, fragment); if (!identity) return Array(3) .fill(0) .map((_, i) => ); const socialItems: { logoPath: string; baseUrl?: string; username?: string | null }[] = useMemo(() => { return [ { logoPath: "/farcaster.png", baseUrl: "https://warpcast.com", username: identity.farcaster.name }, { logoPath: "/lens.png", baseUrl: "https://hey.xyz/u", username: identity.lens.name }, { logoPath: "/x.png", baseUrl: "https://x.com", username: identity.aggregate.x }, { logoPath: "/base.png", baseUrl: "https://www.base.org/name", username: identity.base.name }, { logoPath: "/uninames.png", baseUrl: undefined, username: identity.uni.name }, { logoPath: "/ens.png", baseUrl: "https://app.ens.domains", username: identity.ens.name }, { logoPath: "/discord.png", baseUrl: undefined, username: identity.aggregate.discord }, { logoPath: "/telegram.png", baseUrl: undefined, username: identity.aggregate.telegram }, { logoPath: "/github.png", baseUrl: "https://github.com", username: identity.aggregate.github }, { logoPath: "/nns.png", baseUrl: "https://nns.xyz/domains", username: identity.nns.name }, { logoPath: "/world-id.png", baseUrl: undefined, username: identity.world.name }, ].filter((item) => item.username); }, [identity]); return socialItems.length == 0 ? (
None found
) : ( <> {socialItems.map((item, i) => ( {/* TODO: allow user to pass in their custom image component in the provider */} {item.logoPath.split(".")[0]} {item.username} ))} ); }