diff --git a/apps/og/src/helpers/getCollectModuleMetadata.spec.ts b/apps/og/src/helpers/getCollectModuleMetadata.spec.ts index bbb6933044d8..845017853fcb 100644 --- a/apps/og/src/helpers/getCollectModuleMetadata.spec.ts +++ b/apps/og/src/helpers/getCollectModuleMetadata.spec.ts @@ -1,6 +1,6 @@ import getPostOGImages from "@helpers/getPostOGImages"; import { APP_NAME } from "@hey/data/constants"; -import allowedOpenActionModules from "@hey/helpers/allowedOpenActionModules"; +import allowedPostActionModules from "@hey/helpers/allowedPostActionModules"; import getAccount from "@hey/helpers/getAccount"; import { beforeEach, describe, expect, test, vi } from "vitest"; import getCollectModuleMetadata from "./getCollectModuleMetadata"; @@ -36,7 +36,7 @@ describe("getCollectModuleMetadata", () => { }, openActionModules: [ { - type: allowedOpenActionModules[0], + type: allowedPostActionModules[0], contract: { address: "0xabcdefabcdef" } } ], diff --git a/apps/og/src/helpers/getCollectModuleMetadata.ts b/apps/og/src/helpers/getCollectModuleMetadata.ts index 5c78c2c2564c..0ac5be6fdc9c 100644 --- a/apps/og/src/helpers/getCollectModuleMetadata.ts +++ b/apps/og/src/helpers/getCollectModuleMetadata.ts @@ -1,6 +1,6 @@ import getPostOGImages from "@helpers/getPostOGImages"; import { APP_NAME } from "@hey/data/constants"; -import allowedOpenActionModules from "@hey/helpers/allowedOpenActionModules"; +import allowedPostActionModules from "@hey/helpers/allowedPostActionModules"; import getAccount from "@hey/helpers/getAccount"; import type { AnyPost } from "@hey/indexer"; @@ -12,7 +12,7 @@ const getCollectModuleMetadata = (post: AnyPost) => { } const openAction = openActionModules.filter((module) => - allowedOpenActionModules.includes(module.type) + allowedPostActionModules.includes(module.type) ); // 0 th index is the collect module diff --git a/apps/web/src/components/Account/index.tsx b/apps/web/src/components/Account/index.tsx index b12023d3c116..1bb59f2bc661 100644 --- a/apps/web/src/components/Account/index.tsx +++ b/apps/web/src/components/Account/index.tsx @@ -116,7 +116,7 @@ const ViewProfile: NextPage = () => { cover={ isSuspended ? `${STATIC_IMAGES_URL}/patterns/2.svg` - : account?.metadata?.coverPicture?.optimized?.uri || + : account?.metadata?.coverPicture || `${STATIC_IMAGES_URL}/patterns/2.svg` } /> diff --git a/apps/web/src/components/Post/OpenAction/Collect.tsx b/apps/web/src/components/Post/OpenAction/Collect.tsx index 3c4c95e479f6..9c6743669c2b 100644 --- a/apps/web/src/components/Post/OpenAction/Collect.tsx +++ b/apps/web/src/components/Post/OpenAction/Collect.tsx @@ -2,7 +2,7 @@ import { Leafwatch } from "@helpers/leafwatch"; import hasOptimisticallyCollected from "@helpers/optimistic/hasOptimisticallyCollected"; import { FeatureFlag } from "@hey/data/feature-flags"; import { POST } from "@hey/data/tracking"; -import allowedOpenActionModules from "@hey/helpers/allowedOpenActionModules"; +import allowedPostActionModules from "@hey/helpers/allowedPostActionModules"; import type { Post } from "@hey/indexer"; import { Button, Modal } from "@hey/ui"; import { useFlag } from "@unleash/proxy-client-react"; @@ -18,7 +18,7 @@ const Collect: FC = ({ post }) => { const enabled = useFlag(FeatureFlag.Collect); const [showCollectModal, setShowCollectModal] = useState(false); const openActions = post.openActionModules.filter((module) => - allowedOpenActionModules.includes(module.type) + allowedPostActionModules.includes(module.type) ); const hasActed = diff --git a/apps/web/src/components/Post/OpenAction/index.tsx b/apps/web/src/components/Post/OpenAction/index.tsx index 444d0c16352e..65ac4bb1bc6d 100644 --- a/apps/web/src/components/Post/OpenAction/index.tsx +++ b/apps/web/src/components/Post/OpenAction/index.tsx @@ -1,7 +1,7 @@ import { Leafwatch } from "@helpers/leafwatch"; import { ShoppingBagIcon } from "@heroicons/react/24/outline"; import { POST } from "@hey/data/tracking"; -import allowedOpenActionModules from "@hey/helpers/allowedOpenActionModules"; +import allowedPostActionModules from "@hey/helpers/allowedPostActionModules"; import humanize from "@hey/helpers/humanize"; import nFormatter from "@hey/helpers/nFormatter"; import type { Post } from "@hey/indexer"; @@ -18,7 +18,7 @@ const OpenAction: FC = ({ post }) => { const [showCollectModal, setShowCollectModal] = useState(false); const { countOpenActions } = post.stats; const openActions = post.openActionModules.filter((module) => - allowedOpenActionModules.includes(module.type) + allowedPostActionModules.includes(module.type) ); return ( diff --git a/apps/web/src/components/Settings/Allowance/CollectModules.tsx b/apps/web/src/components/Settings/Allowance/CollectModules.tsx index 2df533aac61c..96e37ebf6cb7 100644 --- a/apps/web/src/components/Settings/Allowance/CollectModules.tsx +++ b/apps/web/src/components/Settings/Allowance/CollectModules.tsx @@ -1,6 +1,6 @@ import Loader from "@components/Shared/Loader"; import { DEFAULT_COLLECT_TOKEN, STATIC_IMAGES_URL } from "@hey/data/constants"; -import allowedOpenActionModules from "@hey/helpers/allowedOpenActionModules"; +import allowedPostActionModules from "@hey/helpers/allowedPostActionModules"; import { CardHeader, ErrorMessage, Select } from "@hey/ui"; import type { FC } from "react"; import { useState } from "react"; @@ -12,7 +12,7 @@ const getAllowancePayload = (currency: string) => { return { currencies: [currency], followModules: [FollowModuleType.FeeFollowModule], - openActionModules: allowedOpenActionModules + openActionModules: allowedPostActionModules }; }; diff --git a/packages/abis/Graph.ts b/packages/abis/Graph.ts new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/packages/helpers/allowedOpenActionModules.ts b/packages/helpers/allowedOpenActionModules.ts deleted file mode 100644 index 5639a28d499a..000000000000 --- a/packages/helpers/allowedOpenActionModules.ts +++ /dev/null @@ -1,6 +0,0 @@ -const allowedOpenActionModules = [ - OpenActionModuleType.SimpleCollectOpenActionModule, - OpenActionModuleType.MultirecipientFeeCollectOpenActionModule -]; - -export default allowedOpenActionModules; diff --git a/packages/helpers/allowedPostActionModules.ts b/packages/helpers/allowedPostActionModules.ts new file mode 100644 index 000000000000..b2431844d54b --- /dev/null +++ b/packages/helpers/allowedPostActionModules.ts @@ -0,0 +1,8 @@ +import { PostActionType } from "@hey/indexer"; + +const allowedPostActionModules = [ + PostActionType.SimpleCollectAction, + PostActionType.MultirecipientFeeCollectOpenActionModule +]; + +export default allowedPostActionModules; diff --git a/packages/helpers/getAttachmentsData.spec.ts b/packages/helpers/getAttachmentsData.spec.ts deleted file mode 100644 index d4015bb11729..000000000000 --- a/packages/helpers/getAttachmentsData.spec.ts +++ /dev/null @@ -1,142 +0,0 @@ -import { describe, expect, test } from "vitest"; -import getAttachmentsData from "./getAttachmentsData"; - -describe("getAttachmentsData", () => { - test("should return an empty array when attachments are not provided", () => { - const result = getAttachmentsData(); - expect(result).toEqual([]); - }); - - test("should return an array of image attachments", () => { - const attachments: PublicationMetadataMedia[] = [ - { - __typename: "PublicationMetadataMediaImage", - image: { optimized: { uri: "image-uri" }, raw: { uri: "raw-uri" } } - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([{ type: "Image", uri: "image-uri" }]); - }); - - test("should return an array of video attachments", () => { - const attachments: PublicationMetadataMedia[] = [ - { - __typename: "PublicationMetadataMediaVideo", - cover: { - optimized: { uri: "cover-uri" }, - raw: { uri: "raw-cover-uri" } - }, - video: { - optimized: { uri: "video-uri" }, - raw: { uri: "raw-video-uri" } - } - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([ - { coverUri: "cover-uri", type: "Video", uri: "video-uri" } - ]); - }); - - test("should return an array of audio attachments", () => { - const attachments: PublicationMetadataMedia[] = [ - { - __typename: "PublicationMetadataMediaAudio", - artist: "John Doe", - audio: { - optimized: { uri: "audio-uri" }, - raw: { uri: "raw-audio-uri" } - }, - cover: { - optimized: { uri: "cover-uri" }, - raw: { uri: "raw-video-uri" } - } - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([ - { - artist: "John Doe", - coverUri: "cover-uri", - type: "Audio", - uri: "audio-uri" - } - ]); - }); - - test("should return an empty array for unknown attachment types", () => { - const attachments: any[] = [{ __typename: "UnknownAttachmentType" }]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([[]]); - }); - - test("should handle multiple attachments of different types", () => { - const attachments: PublicationMetadataMedia[] = [ - { - __typename: "PublicationMetadataMediaImage", - image: { optimized: { uri: "image-uri-1" }, raw: { uri: "raw-uri-1" } } - }, - { - __typename: "PublicationMetadataMediaVideo", - cover: { - optimized: { uri: "cover-uri" }, - raw: { uri: "raw-cover-uri" } - }, - video: { - optimized: { uri: "video-uri" }, - raw: { uri: "raw-video-uri" } - } - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([ - { type: "Image", uri: "image-uri-1" }, - { coverUri: "cover-uri", type: "Video", uri: "video-uri" } - ]); - }); - - test("should return an array with 'null' values if optimized URIs are missing", () => { - const attachments: PublicationMetadataMedia[] = [ - { - __typename: "PublicationMetadataMediaImage", - image: { optimized: { uri: null }, raw: { uri: "raw-uri" } } - }, - { - __typename: "PublicationMetadataMediaAudio", - artist: "John Doe", - audio: { optimized: { uri: null }, raw: { uri: "raw-audio-uri" } }, - cover: { optimized: { uri: null }, raw: { uri: "raw-cover-uri" } } - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([ - { type: "Image", uri: null }, - { artist: "John Doe", coverUri: null, type: "Audio", uri: null } - ]); - }); - - test("should return an empty array when optimized and raw URIs are missing", () => { - const attachments: PublicationMetadataMedia[] = [ - { - __typename: "PublicationMetadataMediaImage", - image: { optimized: { uri: null }, raw: { uri: null } } - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([{ type: "Image", uri: null }]); - }); - - test("should handle attachments with missing properties", () => { - const attachments: any[] = [ - { - __typename: "PublicationMetadataMediaVideo", - video: { optimized: { uri: "video-uri" } } - // Missing cover and raw URIs - } - ]; - const result = getAttachmentsData(attachments); - expect(result).toEqual([ - { type: "Video", uri: "video-uri", coverUri: undefined } - ]); - }); -}); diff --git a/packages/helpers/getAttachmentsData.ts b/packages/helpers/getAttachmentsData.ts index f2bc7546fbf3..03b5a48f2640 100644 --- a/packages/helpers/getAttachmentsData.ts +++ b/packages/helpers/getAttachmentsData.ts @@ -1,31 +1,29 @@ -import type { Maybe, PublicationMetadataMedia } from "@hey/indexer"; +import type { AnyMedia, Maybe } from "@hey/indexer"; -const getAttachmentsData = ( - attachments?: Maybe -): any => { +const getAttachmentsData = (attachments?: Maybe): any => { if (!attachments) { return []; } return attachments.map((attachment) => { switch (attachment.__typename) { - case "PublicationMetadataMediaImage": + case "MediaImage": return { type: "Image", - uri: attachment.image.optimized?.uri + uri: attachment.item }; - case "PublicationMetadataMediaVideo": + case "MediaVideo": return { - coverUri: attachment.cover?.optimized?.uri, + coverUri: attachment.cover, type: "Video", - uri: attachment.video.optimized?.uri + uri: attachment.item }; - case "PublicationMetadataMediaAudio": + case "MediaAudio": return { artist: attachment.artist, - coverUri: attachment.cover?.optimized?.uri, + coverUri: attachment.cover, type: "Audio", - uri: attachment.audio.optimized?.uri + uri: attachment.item }; default: return []; diff --git a/packages/helpers/getAvatar.ts b/packages/helpers/getAvatar.ts index 7d3a5048b1ca..71421e4d5a2c 100644 --- a/packages/helpers/getAvatar.ts +++ b/packages/helpers/getAvatar.ts @@ -10,16 +10,8 @@ import sanitizeDStorageUrl from "./sanitizeDStorageUrl"; * @param namedTransform The named transform to use. * @returns The avatar image URL. */ -const getAvatar = (profile: any, namedTransform = AVATAR): string => { - const avatarUrl = - // Lens NFT Avatar fallbacks - profile?.metadata?.picture?.image?.optimized?.uri || - profile?.metadata?.picture?.image?.raw?.uri || - // Lens Account Avatar fallbacks - profile?.metadata?.picture?.optimized?.uri || - profile?.metadata?.picture?.raw?.uri || - // Stamp.fyi Avatar fallbacks - getLennyURL(profile.id); +const getAvatar = (account: any, namedTransform = AVATAR): string => { + const avatarUrl = account?.metadata?.picture || getLennyURL(account.address); return imageKit(sanitizeDStorageUrl(avatarUrl), namedTransform); }; diff --git a/packages/helpers/getThumbnailUrl.spec.ts b/packages/helpers/getThumbnailUrl.spec.ts deleted file mode 100644 index 57d395e98bb5..000000000000 --- a/packages/helpers/getThumbnailUrl.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { STATIC_IMAGES_URL } from "@hey/data/constants"; -import { describe, expect, test } from "vitest"; -import getThumbnailUrl from "./getThumbnailUrl"; - -describe("getThumbnailUrl", () => { - const mockMetadata = { - cover: { - optimized: { uri: "https://example.com/cover.png" }, - raw: { uri: null } - } - }; - - test("should return the thumbnail fallback URL if no metadata is provided", () => { - const metadata = undefined; - const result = getThumbnailUrl(metadata); - const expectedUrl = `${STATIC_IMAGES_URL}/thumbnail.png`; - expect(result).toEqual(expectedUrl); - }); - - test("should return the original cover URL if available", () => { - const metadata = mockMetadata; - const result = getThumbnailUrl(metadata as any); - expect(result).toEqual("https://example.com/cover.png"); - }); - - test("should return the fallback thumbnail URL if no cover URL is available", () => { - const metadata = { ...mockMetadata, cover: undefined }; - const result = getThumbnailUrl(metadata as any); - const expectedUrl = `${STATIC_IMAGES_URL}/thumbnail.png`; - expect(result).toEqual(expectedUrl); - }); - - test("should return fallback thumbnail if cover's optimized uri is null", () => { - const metadata = { - cover: { - optimized: { uri: null }, - raw: { uri: "https://example.com/cover-raw.png" } - } - }; - const result = getThumbnailUrl(metadata as any); - const expectedUrl = `${STATIC_IMAGES_URL}/thumbnail.png`; - expect(result).toEqual(expectedUrl); - }); - - test("should return fallback thumbnail if optimized uri is an empty string", () => { - const metadata = { - cover: { - optimized: { uri: "" }, - raw: { uri: "https://example.com/cover-raw.png" } - } - }; - const result = getThumbnailUrl(metadata as any); - const expectedUrl = `${STATIC_IMAGES_URL}/thumbnail.png`; - expect(result).toEqual(expectedUrl); - }); -}); diff --git a/packages/helpers/getThumbnailUrl.ts b/packages/helpers/getThumbnailUrl.ts deleted file mode 100644 index 415e3b658a86..000000000000 --- a/packages/helpers/getThumbnailUrl.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { STATIC_IMAGES_URL } from "@hey/data/constants"; -import sanitizeDStorageUrl from "./sanitizeDStorageUrl"; - -/** - * Returns the thumbnail URL for the specified post metadata. - * - * @param metadata The post metadata. - * @returns The thumbnail URL. - */ -const getThumbnailUrl = ( - metadata?: PublicationMetadataMediaAudio | PublicationMetadataMediaVideo -): string => { - const fallbackUrl = `${STATIC_IMAGES_URL}/thumbnail.png`; - - if (!metadata) { - return fallbackUrl; - } - - const { cover } = metadata; - const url = cover?.optimized?.uri || fallbackUrl; - - return sanitizeDStorageUrl(url); -}; - -export default getThumbnailUrl; diff --git a/packages/helpers/isOpenActionAllowed.ts b/packages/helpers/isOpenActionAllowed.ts index 5678a0dc7746..7a22edf6916f 100644 --- a/packages/helpers/isOpenActionAllowed.ts +++ b/packages/helpers/isOpenActionAllowed.ts @@ -1,5 +1,5 @@ import type { Maybe, OpenActionModule } from "@hey/indexer"; -import allowedOpenActionModules from "./allowedOpenActionModules"; +import allowedPostActionModules from "./allowedPostActionModules"; const isOpenActionAllowed = ( openActions?: Maybe @@ -11,7 +11,7 @@ const isOpenActionAllowed = ( return openActions.some((openAction) => { const { type } = openAction; - return allowedOpenActionModules.includes(type); + return allowedPostActionModules.includes(type); }); };