"use client"; import { Cross2Icon } from "@radix-ui/react-icons"; import type { ThirdwebClient } from "../../../../../client/client.js"; import { useUnlinkProfile } from "../../../../../react/web/hooks/wallets/useUnlinkProfile.js"; import { shortenAddress } from "../../../../../utils/address.js"; import type { Profile } from "../../../../../wallets/in-app/core/authentication/types.js"; import { fontSize, iconSize } from "../../../../core/design-system/index.js"; import { useSocialProfiles } from "../../../../core/social/useSocialProfiles.js"; import { getSocialIcon } from "../../../../core/utils/walletIcon.js"; import { useProfiles } from "../../../hooks/wallets/useProfiles.js"; import { LoadingScreen } from "../../../wallets/shared/LoadingScreen.js"; import { Container, Line, ModalHeader } from "../../components/basic.js"; import { IconButton } from "../../components/buttons.js"; import { Img } from "../../components/Img.js"; import { Spacer } from "../../components/Spacer.js"; import { Text } from "../../components/text.js"; import { Blobbie } from "../Blobbie.js"; import { AddUserIcon } from "../icons/AddUserIcon.js"; import { EmailIcon } from "../icons/EmailIcon.js"; import { FingerPrintIcon } from "../icons/FingerPrintIcon.js"; import { PhoneIcon } from "../icons/PhoneIcon.js"; import type { ConnectLocale } from "../locale/types.js"; import { MenuButton } from "../MenuButton.js"; import type { WalletDetailsModalScreen } from "./types.js"; function getProfileDisplayName(profile: Profile) { switch (true) { case profile.type === "email" && profile.details.email !== undefined: return profile.details.email; case profile.type === "google" && profile.details.email !== undefined: return profile.details.email; case profile.type === "phone" && profile.details.phone !== undefined: return profile.details.phone; case profile.details.address !== undefined: return shortenAddress(profile.details.address, 6); case (profile.type as string) === "cognito" && profile.details.email !== undefined: return profile.details.email; case (profile.type as string).toLowerCase() === "custom_auth_endpoint": return "Custom Profile"; default: return profile.type.slice(0, 1).toUpperCase() + profile.type.slice(1); } } /** * @internal */ export function LinkedProfilesScreen(props: { onBack: () => void; setScreen: (screen: WalletDetailsModalScreen) => void; locale: ConnectLocale; client: ThirdwebClient; }) { const { data: connectedProfiles, isLoading } = useProfiles({ client: props.client, }); if (isLoading) { return ; } return ( { props.setScreen("link-profile"); }} style={{ fontSize: fontSize.sm, }} > {props.locale.manageWallet.linkProfile} {/* Exclude guest as a profile */} {connectedProfiles ?.filter( (profile) => profile.type.toLowerCase() !== "guest" && profile.type.toLowerCase() !== "custom_jwt" && profile.type.toLowerCase() !== "custom_auth_endpoint", ) .map((profile) => ( 1} key={`${JSON.stringify(profile)}`} profile={profile} /> ))} ); } function LinkedProfile({ profile, enableUnlinking, client, }: { profile: Profile; enableUnlinking: boolean; client: ThirdwebClient; }) { const { data: socialProfiles } = useSocialProfiles({ address: profile.details.address, client, }); const { mutate: unlinkProfileMutation, isPending } = useUnlinkProfile(); return ( {socialProfiles?.some((p) => p.avatar) ? ( p.avatar)?.avatar} style={{ borderRadius: "100%", }} width={iconSize.lg} /> ) : profile.details.address !== undefined ? ( ) : profile.type === "passkey" ? ( ) : profile.type === "email" ? ( ) : profile.type === "phone" ? ( ) : ( )}
{socialProfiles?.find((p) => p.avatar)?.name || getProfileDisplayName(profile)}
{socialProfiles?.find((p) => p.avatar)?.name && profile.details.address && ( {shortenAddress(profile.details.address, 4)} )} {enableUnlinking && ( unlinkProfileMutation({ client, profileToUnlink: profile, }) } style={{ pointerEvents: "auto", }} type="button" > )}
); }