repo_description: Hey is a decentralized and permissionless social media app built with Lens Protocol 🌿
repo_topics: blockchain crypto dapp graphql hacktoberfest lens-protocol nextjs react social-media tailwindcss turborepo typescript vitest wagmi web3
code: import { DEFAULT_AVATAR, TRANSFORMS } from "@/data/constants";
  import imageKit from "./imageKit";
  import sanitizeDStorageUrl from "./sanitizeDStorageUrl";
  
  interface EntityWithAvatar {
    metadata?: {
      picture?: string | null;
      icon?: string | null;
    } | null;
  }
  
  const getAvatar = (
    entity: EntityWithAvatar | null | undefined,
    namedTransform: (typeof TRANSFORMS)[keyof typeof TRANSFORMS] = TRANSFORMS.AVATAR_SMALL
  ): string => {
    if (!entity) {
      return DEFAULT_AVATAR;
    }
  
    const avatarUrl =
      entity?.metadata?.picture || entity?.metadata?.icon || DEFAULT_AVATAR;
  
    const sanitized = sanitizeDStorageUrl(avatarUrl);
  
    if (!sanitized || !/^https?:\/\//.test(sanitized)) {
      return DEFAULT_AVATAR;
    }
  
    return imageKit(sanitized, namedTransform);
  };
  
  export default getAvatar;
  