Skip to main content
Glama
deso-protocol

DeSo MCP Server

Official
messaging-display-avatar.tsx2.86 kB
import { buildProfilePictureUrl } from "deso-protocol"; import toMaterialStyle from "material-color-hash"; import { FC, ReactElement, useEffect, useState } from "react"; import { getProfileURL } from "../utils/helpers"; function ConditionalLink({ children, condition, href, target, className, style, onClick, }: { children: ReactElement; condition: boolean; href: string; target: string; className: string; style: any; onClick: (e: any) => void; }) { return condition ? ( <a href={href} target={target} rel="noreferrer" className={`w-full ${className}`} style={style} onClick={onClick} > {children} </a> ) : ( <div className={className} style={style}> {children} </div> ); } const DEFAULT_PROFILE_PIC_URL = "/assets/default-profile-pic.png"; export const MessagingDisplayAvatar: FC<{ publicKey?: string; username?: string; borderColor?: string; diameter: number; classNames?: string; groupChat?: boolean; }> = ({ publicKey, username, diameter, borderColor = "border-white", classNames = "", groupChat = false, }) => { const [profilePicUrl, setProfilePicUrl] = useState(""); useEffect(() => { let profilePicUrl = ""; if (!publicKey) { setProfilePicUrl(DEFAULT_PROFILE_PIC_URL); return; } if (groupChat) { const keyFirstLast = `${publicKey.charAt(0)}${publicKey.charAt( publicKey.length - 1 )}`; const bgColor = toMaterialStyle(keyFirstLast, 200); const key = publicKey.replace(/[^a-zA-Z0-9]+/g, ""); profilePicUrl = `https://ui-avatars.com/api/?name=${key}&background=${bgColor.backgroundColor.slice( 1 )}`; } else { profilePicUrl = getProfilePicture(); } setProfilePicUrl(profilePicUrl); }, [publicKey, groupChat]); const getProfilePicture = () => { if (!publicKey) { return DEFAULT_PROFILE_PIC_URL; } return buildProfilePictureUrl(publicKey, { fallbackImageUrl: `${window.location.href}${DEFAULT_PROFILE_PIC_URL}`, }); }; if (!profilePicUrl) { return <></>; } return ( <ConditionalLink className={`block ${classNames}`} style={{ width: `${diameter}px`, maxWidth: `${diameter}px`, minWidth: `${diameter}px`, }} href={getProfileURL(username)} condition={!!username} target="_blank" onClick={(e) => e.stopPropagation()} > <img src={profilePicUrl} style={{ height: `${diameter}px`, width: `${diameter}px` }} className={`w-12 h-12 bg-white bg-no-repeat bg-center bg-cover rounded-full ${borderColor}`} alt={publicKey} title={publicKey} onError={() => { setProfilePicUrl(DEFAULT_PROFILE_PIC_URL); }} /> </ConditionalLink> ); };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deso-protocol/deso-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server