import type { User } from "@tensamin/user/context"; import { Avatar, AvatarFallback, AvatarImage, Button, Tooltip, TooltipContent, TooltipTrigger, } from "@tensamin/ui"; import { toLossySixDigitCode } from "@tensamin/shared/code"; import Text from "@tensamin/markdown/text"; import { ChevronDown, ChevronUp, Info } from "lucide-react"; import { useEffect, useState } from "react"; import { useCrypto } from "@tensamin/crypto/context"; import { useStorage } from "@tensamin/storage/context"; import { useUser } from "@tensamin/user/context"; export default function Profile({ user }: { user: User }) { const [showAdvancedInformation, setShowAdvancedInformation] = useState(false); const [sharedSecret, setSharedSecret] = useState(""); const { getSharedSecret } = useCrypto(); const { load } = useStorage(); const { get } = useUser(); useEffect(() => { let active = true; void (async () => { try { const ownId = await load("user_id"); const privateKey = await load("private_key"); const ownData = await get(ownId); const secret = await getSharedSecret( privateKey, ownData.public_key, user.public_key, ); if (active) { setSharedSecret(secret); } } catch { if (active) { setSharedSecret(""); } } })(); return () => { active = false; }; }, [get, getSharedSecret, load, user.public_key]); const sharedSecretCode = sharedSecret ? toLossySixDigitCode(sharedSecret) : "------"; return (
{user.display.slice(0, 2).toUpperCase()}

{user.display}

{user.username}

{showAdvancedInformation && (

Shared Code: {sharedSecretCode}{" "} } /> You can compare this code with the conversation partner to validate that this chat is E2EE

Iota ID: {user.iota_id}

User ID: {user.user_id}

Public Key: {user.public_key}

)}
); }