From fb2b5359e60a9288fe0dee19d9fad32c1e7ac6ab Mon Sep 17 00:00:00 2001 From: Yoginth Date: Thu, 5 Dec 2024 08:56:08 +0530 Subject: [PATCH] Migrate to Lens v3 --- .../src/helpers/getCollectModuleMetadata.ts | 14 +++--- .../Home/PaidActions/OpenActionPaidAction.tsx | 18 ++++---- .../Home/Sidebar/HeyMembershipNft/Mint.tsx | 6 +-- .../web/src/components/Post/Actions/index.tsx | 7 ++- .../components/Post/OpenAction/Collect.tsx | 12 +++-- .../CollectModule/CollectAction.tsx | 24 +++++----- .../Post/OpenAction/CollectModule/index.tsx | 20 +++++---- .../src/components/Post/OpenAction/index.tsx | 12 +++-- .../components/Settings/Allowance/Button.tsx | 3 +- .../Shared/GetOpenActionModuleIcon.tsx | 9 ++-- .../Shared/NoBalanceError/WrapWmatic.tsx | 1 + .../Shared/NoBalanceError/index.tsx | 1 + .../src/helpers/getAllowanceModule.spec.ts | 7 ++- apps/web/src/helpers/getAllowanceModule.ts | 6 ++- packages/helpers/allowedPostActionModules.ts | 6 +-- ....spec.ts => getPostActionActOnKey.spec.ts} | 11 ++--- ...onActOnKey.ts => getPostActionActOnKey.ts} | 10 +++-- packages/helpers/isOpenActionAllowed.spec.ts | 43 ------------------ packages/helpers/isOpenActionAllowed.ts | 18 -------- packages/helpers/isPostActionAllowed.spec.ts | 44 +++++++++++++++++++ packages/helpers/isPostActionAllowed.ts | 16 +++++++ 21 files changed, 152 insertions(+), 136 deletions(-) rename packages/helpers/{getOpenActionActOnKey.spec.ts => getPostActionActOnKey.spec.ts} (80%) rename packages/helpers/{getOpenActionActOnKey.ts => getPostActionActOnKey.ts} (58%) delete mode 100644 packages/helpers/isOpenActionAllowed.spec.ts delete mode 100644 packages/helpers/isOpenActionAllowed.ts create mode 100644 packages/helpers/isPostActionAllowed.spec.ts create mode 100644 packages/helpers/isPostActionAllowed.ts diff --git a/apps/og/src/helpers/getCollectModuleMetadata.ts b/apps/og/src/helpers/getCollectModuleMetadata.ts index 0ac5be6fdc9c..e9366482dfc1 100644 --- a/apps/og/src/helpers/getCollectModuleMetadata.ts +++ b/apps/og/src/helpers/getCollectModuleMetadata.ts @@ -2,21 +2,21 @@ import getPostOGImages from "@helpers/getPostOGImages"; import { APP_NAME } from "@hey/data/constants"; import allowedPostActionModules from "@hey/helpers/allowedPostActionModules"; import getAccount from "@hey/helpers/getAccount"; -import type { AnyPost } from "@hey/indexer"; +import type { Post } from "@hey/indexer"; -const getCollectModuleMetadata = (post: AnyPost) => { - const { openActionModules } = post; +const getCollectModuleMetadata = (post: Post) => { + const { actions } = post; - if (!openActionModules) { + if (!actions) { return; } - const openAction = openActionModules.filter((module) => - allowedPostActionModules.includes(module.type) + const postAction = actions.filter((action) => + allowedPostActionModules.includes(action.__typename) ); // 0 th index is the collect module - const collectModule = openAction.length ? openAction[0] : null; + const collectModule = postAction.length ? postAction[0] : null; if (!collectModule) { return; diff --git a/apps/web/src/components/Home/PaidActions/OpenActionPaidAction.tsx b/apps/web/src/components/Home/PaidActions/OpenActionPaidAction.tsx index 75be04f49426..ff480014b142 100644 --- a/apps/web/src/components/Home/PaidActions/OpenActionPaidAction.tsx +++ b/apps/web/src/components/Home/PaidActions/OpenActionPaidAction.tsx @@ -2,7 +2,7 @@ import SmallSingleAccount from "@components/Shared/SmallSingleAccount"; import getCollectModuleData from "@hey/helpers/getCollectModuleData"; import getTokenImage from "@hey/helpers/getTokenImage"; import { isRepost } from "@hey/helpers/postHelpers"; -import type { AnyPost } from "@hey/indexer"; +import type { AnyPost, SimpleCollectActionSettings } from "@hey/indexer"; import type { FC } from "react"; interface OpenActionPaidActionProps { @@ -16,35 +16,35 @@ const OpenActionPaidAction: FC = ({ }) => { const targetPost = isRepost(post) ? post.repostOf : post; - const openActions = targetPost.openActionModules + const postActions = targetPost.actions .filter( (module) => module.__typename === "MultirecipientFeeCollectOpenActionSettings" || - module.__typename === "SimpleCollectOpenActionSettings" + module.__typename === "SimpleCollectActionSettings" ) .map((module) => getCollectModuleData( module as | MultirecipientFeeCollectOpenActionSettings - | SimpleCollectOpenActionSettings + | SimpleCollectActionSettings ) ); return (
- {openActions.map((openAction, index) => ( + {postActions.map((postAction, index) => (
Collected for {openAction?.assetSymbol} - {openAction?.amount} {openAction?.assetSymbol} + {postAction?.amount} {postAction?.assetSymbol} by diff --git a/apps/web/src/components/Home/Sidebar/HeyMembershipNft/Mint.tsx b/apps/web/src/components/Home/Sidebar/HeyMembershipNft/Mint.tsx index 0170145b3504..4ccac9c34971 100644 --- a/apps/web/src/components/Home/Sidebar/HeyMembershipNft/Mint.tsx +++ b/apps/web/src/components/Home/Sidebar/HeyMembershipNft/Mint.tsx @@ -24,7 +24,7 @@ const Mint: FC = ({ onCollectSuccess }) => { return ; } - if (!data?.publication || error) { + if (!data?.post || error) { return ( = ({ onCollectSuccess }) => { } const post = data?.post as Post; - const openAction = post.openActionModules[0]; + const postAction = post.actions[0]; return (
@@ -87,7 +87,7 @@ const Mint: FC = ({ onCollectSuccess }) => { } onCollectSuccess={onCollectSuccess} - openAction={openAction} + postAction={postAction} post={post} />
diff --git a/apps/web/src/components/Post/Actions/index.tsx b/apps/web/src/components/Post/Actions/index.tsx index 31935d3e5b8c..791bff96810f 100644 --- a/apps/web/src/components/Post/Actions/index.tsx +++ b/apps/web/src/components/Post/Actions/index.tsx @@ -1,6 +1,6 @@ import { FeatureFlag } from "@hey/data/feature-flags"; import getPostViewCountById from "@hey/helpers/getPostViewCountById"; -import isOpenActionAllowed from "@hey/helpers/isOpenActionAllowed"; +import isPostActionAllowed from "@hey/helpers/isPostActionAllowed"; import { isRepost } from "@hey/helpers/postHelpers"; import stopEventPropagation from "@hey/helpers/stopEventPropagation"; import type { AnyPost } from "@hey/indexer"; @@ -26,10 +26,9 @@ const PostActions: FC = ({ post, showCount = false }) => { const targetPost = isRepost(post) ? post.repostOf : post; const { postViews } = useImpressionsStore(); const isGardener = useFlag(FeatureFlag.Gardener); - const hasOpenAction = (targetPost.openActionModules?.length || 0) > 0; + const hasPostAction = (targetPost.actions?.length || 0) > 0; - const canAct = - hasOpenAction && isOpenActionAllowed(targetPost.openActionModules); + const canAct = hasPostAction && isPostActionAllowed(targetPost.actions); const views = getPostViewCountById(postViews, targetPost.id); return ( diff --git a/apps/web/src/components/Post/OpenAction/Collect.tsx b/apps/web/src/components/Post/OpenAction/Collect.tsx index 9c6743669c2b..fb2af4076a82 100644 --- a/apps/web/src/components/Post/OpenAction/Collect.tsx +++ b/apps/web/src/components/Post/OpenAction/Collect.tsx @@ -17,8 +17,8 @@ interface CollectProps { const Collect: FC = ({ post }) => { const enabled = useFlag(FeatureFlag.Collect); const [showCollectModal, setShowCollectModal] = useState(false); - const openActions = post.openActionModules.filter((module) => - allowedPostActionModules.includes(module.type) + const postActions = post.actions.filter((action) => + allowedPostActionModules.includes(action.__typename) ); const hasActed = @@ -48,8 +48,12 @@ const Collect: FC = ({ post }) => { show={showCollectModal} title="Collect" > - {openActions?.map((action) => ( - + {postActions?.map((action) => ( + ))} diff --git a/apps/web/src/components/Post/OpenAction/CollectModule/CollectAction.tsx b/apps/web/src/components/Post/OpenAction/CollectModule/CollectAction.tsx index fc977945b4ee..fe22363d0e58 100644 --- a/apps/web/src/components/Post/OpenAction/CollectModule/CollectAction.tsx +++ b/apps/web/src/components/Post/OpenAction/CollectModule/CollectAction.tsx @@ -10,8 +10,8 @@ import hasOptimisticallyCollected from "@helpers/optimistic/hasOptimisticallyCol import { Errors } from "@hey/data/errors"; import { POST } from "@hey/data/tracking"; import getCollectModuleData from "@hey/helpers/getCollectModuleData"; -import getOpenActionActOnKey from "@hey/helpers/getOpenActionActOnKey"; -import type { AnyPost } from "@hey/indexer"; +import getPostActionActOnKey from "@hey/helpers/getPostActionActOnKey"; +import type { AnyPost, PostAction } from "@hey/indexer"; import { OptmisticPostType } from "@hey/types/enums"; import type { OptimisticTransaction } from "@hey/types/misc"; import { Button, WarningMessage } from "@hey/ui"; @@ -31,7 +31,7 @@ interface CollectActionProps { forceShowCollect?: boolean; noBalanceErrorMessages?: ReactNode; onCollectSuccess?: () => void; - openAction: OpenActionModule; + postAction: PostAction; post: AnyPost; } @@ -42,10 +42,10 @@ const CollectAction: FC = ({ forceShowCollect = false, noBalanceErrorMessages, onCollectSuccess = () => {}, - openAction, + postAction, post }) => { - const collectModule = getCollectModuleData(openAction as any); + const collectModule = getCollectModuleData(postAction as any); const { id: sessionAccountId } = getCurrentSession(); const { isSuspended } = useAccountStatus(); @@ -75,7 +75,7 @@ const CollectAction: FC = ({ : false; const isFreeCollectModule = !amount; const isSimpleFreeCollectModule = - openAction.__typename === "SimpleCollectOpenActionSettings"; + postAction.__typename === "SimpleCollectOpenActionSettings"; const isFollowersOnly = collectModule?.followerOnly; const isFollowedByMe = isFollowersOnly ? post?.author.operations?.isFollowedByMe @@ -138,7 +138,7 @@ const CollectAction: FC = ({ toast.success("Collected"); Leafwatch.track(POST.COLLECT_MODULE.COLLECT, { amount, - collectModule: openAction?.type, + collectModule: postAction?.__typename, postId: post?.id }); }; @@ -157,7 +157,7 @@ const CollectAction: FC = ({ request: { currencies: assetAddress, followModules: [], - openActionModules: [openAction.type], + openActionModules: [postAction.__typename], referenceModules: [] } } @@ -218,7 +218,7 @@ const CollectAction: FC = ({ try { setIsLoading(true); const actOnRequest: ActOnOpenActionLensManagerRequest = { - actOn: { [getOpenActionActOnKey(openAction.type)]: true }, + actOn: { [getPostActionActOnKey(postAction.__typename)]: true }, for: post?.id }; @@ -272,8 +272,8 @@ const CollectAction: FC = ({ if ( !hasAmount && - (openAction.__typename === "SimpleCollectOpenActionSettings" || - openAction.__typename === "MultirecipientFeeCollectOpenActionSettings") + (postAction.__typename === "SimpleCollectActionSettings" || + postAction.__typename === "MultirecipientFeeCollectOpenActionSettings") ) { return ( = ({ message={ } /> diff --git a/apps/web/src/components/Post/OpenAction/CollectModule/index.tsx b/apps/web/src/components/Post/OpenAction/CollectModule/index.tsx index e7fbff39e3fd..92186f88728f 100644 --- a/apps/web/src/components/Post/OpenAction/CollectModule/index.tsx +++ b/apps/web/src/components/Post/OpenAction/CollectModule/index.tsx @@ -24,7 +24,11 @@ import getTokenImage from "@hey/helpers/getTokenImage"; import humanize from "@hey/helpers/humanize"; import nFormatter from "@hey/helpers/nFormatter"; import { isRepost } from "@hey/helpers/postHelpers"; -import type { AnyPost } from "@hey/indexer"; +import type { + AnyPost, + PostAction, + SimpleCollectActionSettings +} from "@hey/indexer"; import { H3, H4, HelpTooltip, Modal, Tooltip, WarningMessage } from "@hey/ui"; import { useCounter } from "@uidotdev/usehooks"; import Link from "next/link"; @@ -36,11 +40,11 @@ import DownloadCollectors from "./DownloadCollectors"; import Splits from "./Splits"; interface CollectModuleProps { - openAction: OpenActionModule; + postAction: PostAction; post: AnyPost; } -const CollectModule: FC = ({ openAction, post }) => { +const CollectModule: FC = ({ postAction, post }) => { const { allowedTokens } = useAllowedTokensStore(); const [showCollectorsModal, setShowCollectorsModal] = useState(false); @@ -50,9 +54,9 @@ const CollectModule: FC = ({ openAction, post }) => { targetPost.stats.countOpenActions ); - const collectModule = openAction as - | MultirecipientFeeCollectOpenActionSettings - | SimpleCollectOpenActionSettings; + const collectModule = postAction as + | MultirecipientFeeCollectActionSettings + | SimpleCollectActionSettings; const endTimestamp = collectModule?.endsAt; const collectLimit = Number.parseInt(collectModule?.collectLimit || "0"); @@ -124,7 +128,7 @@ const CollectModule: FC = ({ openAction, post }) => {

{targetPost.__typename} by{" "} - +

{amount ? ( @@ -260,7 +264,7 @@ const CollectModule: FC = ({ openAction, post }) => { increment()} - openAction={openAction} + postAction={postAction} post={targetPost} />
diff --git a/apps/web/src/components/Post/OpenAction/index.tsx b/apps/web/src/components/Post/OpenAction/index.tsx index 65ac4bb1bc6d..ae82924eec7f 100644 --- a/apps/web/src/components/Post/OpenAction/index.tsx +++ b/apps/web/src/components/Post/OpenAction/index.tsx @@ -17,8 +17,8 @@ interface OpenActionProps { const OpenAction: FC = ({ post }) => { const [showCollectModal, setShowCollectModal] = useState(false); const { countOpenActions } = post.stats; - const openActions = post.openActionModules.filter((module) => - allowedPostActionModules.includes(module.type) + const postActions = post.actions.filter((action) => + allowedPostActionModules.includes(action.__typename) ); return ( @@ -56,8 +56,12 @@ const OpenAction: FC = ({ post }) => { show={showCollectModal} title="Collect" > - {openActions?.map((action) => ( - + {postActions?.map((action) => ( + ))}
diff --git a/apps/web/src/components/Settings/Allowance/Button.tsx b/apps/web/src/components/Settings/Allowance/Button.tsx index c35ffb73d57e..c7fea2f2aa85 100644 --- a/apps/web/src/components/Settings/Allowance/Button.tsx +++ b/apps/web/src/components/Settings/Allowance/Button.tsx @@ -2,6 +2,7 @@ import errorToast from "@helpers/errorToast"; import getAllowanceModule from "@helpers/getAllowanceModule"; import { Leafwatch } from "@helpers/leafwatch"; import { SETTINGS } from "@hey/data/tracking"; +import { PostActionType } from "@hey/indexer"; import { Button, Modal, WarningMessage } from "@hey/ui"; import type { Dispatch, FC, SetStateAction } from "react"; import { useEffect, useState } from "react"; @@ -71,7 +72,7 @@ const AllowanceButton: FC = ({ ) => { try { const isUnknownModule = - module.moduleName === OpenActionModuleType.UnknownOpenActionModule; + module.moduleName === PostActionType.UnknownOpenActionModule; const { data } = await generateModuleCurrencyApprovalData({ variables: { diff --git a/apps/web/src/components/Shared/GetOpenActionModuleIcon.tsx b/apps/web/src/components/Shared/GetOpenActionModuleIcon.tsx index 9e773afcd3e6..df8365544090 100644 --- a/apps/web/src/components/Shared/GetOpenActionModuleIcon.tsx +++ b/apps/web/src/components/Shared/GetOpenActionModuleIcon.tsx @@ -3,19 +3,20 @@ import { DocumentPlusIcon, UserGroupIcon } from "@heroicons/react/24/outline"; +import type { PostAction } from "@hey/indexer"; import type { FC } from "react"; interface GetOpenActionModuleIconProps { - module?: OpenActionModule; + module?: PostAction; } const GetOpenActionModuleIcon: FC = ({ module }) => { - switch (module?.type) { - case OpenActionModuleType.SimpleCollectOpenActionModule: + switch (module?.__typename) { + case "SimpleCollectActionSettings": return ; - case OpenActionModuleType.MultirecipientFeeCollectOpenActionModule: + case "MultirecipientFeeCollectActionSettings": return ; default: return ; diff --git a/apps/web/src/components/Shared/NoBalanceError/WrapWmatic.tsx b/apps/web/src/components/Shared/NoBalanceError/WrapWmatic.tsx index 6d12bfb719c5..252aab995ed4 100644 --- a/apps/web/src/components/Shared/NoBalanceError/WrapWmatic.tsx +++ b/apps/web/src/components/Shared/NoBalanceError/WrapWmatic.tsx @@ -1,4 +1,5 @@ import errorToast from "@helpers/errorToast"; +import type { Amount } from "@hey/indexer"; import { Button } from "@hey/ui"; import type { FC, ReactNode } from "react"; import { useState } from "react"; diff --git a/apps/web/src/components/Shared/NoBalanceError/index.tsx b/apps/web/src/components/Shared/NoBalanceError/index.tsx index 42f2d860e15e..2dedaec20a23 100644 --- a/apps/web/src/components/Shared/NoBalanceError/index.tsx +++ b/apps/web/src/components/Shared/NoBalanceError/index.tsx @@ -2,6 +2,7 @@ import { Leafwatch } from "@helpers/leafwatch"; import { STATIC_IMAGES_URL } from "@hey/data/constants"; import { POST } from "@hey/data/tracking"; import getUniswapURL from "@hey/helpers/getUniswapURL"; +import type { Amount } from "@hey/indexer"; import Link from "next/link"; import type { FC, ReactNode } from "react"; import WrapWmatic from "./WrapWmatic"; diff --git a/apps/web/src/helpers/getAllowanceModule.spec.ts b/apps/web/src/helpers/getAllowanceModule.spec.ts index 8c109edcd632..555213611915 100644 --- a/apps/web/src/helpers/getAllowanceModule.spec.ts +++ b/apps/web/src/helpers/getAllowanceModule.spec.ts @@ -1,11 +1,10 @@ +import { PostActionType } from "@hey/indexer"; import { describe, expect, test } from "vitest"; import getAllowanceModule from "./getAllowanceModule"; describe("getAllowanceModule", () => { test("should return Simple collect module info for SimpleCollectOpenActionModule", () => { - const result = getAllowanceModule( - OpenActionModuleType.SimpleCollectOpenActionModule - ); + const result = getAllowanceModule(PostActionType.SimpleCollectAction); expect(result).toEqual({ field: "openActionModule", name: "Simple collect" @@ -14,7 +13,7 @@ describe("getAllowanceModule", () => { test("should return Multirecipient collect module info for MultirecipientFeeCollectOpenActionModule", () => { const result = getAllowanceModule( - OpenActionModuleType.MultirecipientFeeCollectOpenActionModule + PostActionType.MultirecipientFeeCollectOpenActionModule ); expect(result).toEqual({ field: "openActionModule", diff --git a/apps/web/src/helpers/getAllowanceModule.ts b/apps/web/src/helpers/getAllowanceModule.ts index 8c537713e67f..7f901c066708 100644 --- a/apps/web/src/helpers/getAllowanceModule.ts +++ b/apps/web/src/helpers/getAllowanceModule.ts @@ -1,3 +1,5 @@ +import { PostActionType } from "@hey/indexer"; + /** * Returns the name and field of the specified module. * @@ -12,9 +14,9 @@ const getAllowanceModule = ( } => { switch (name) { // Collect Modules - case OpenActionModuleType.SimpleCollectOpenActionModule: + case PostActionType.SimpleCollectAction: return { field: "openActionModule", name: "Simple collect" }; - case OpenActionModuleType.MultirecipientFeeCollectOpenActionModule: + case PostActionType.MultirecipientFeeCollectAction: return { field: "openActionModule", name: "Multirecipient paid collect" }; // Follow modules case FollowModuleType.FeeFollowModule: diff --git a/packages/helpers/allowedPostActionModules.ts b/packages/helpers/allowedPostActionModules.ts index b2431844d54b..9cdae03e24fc 100644 --- a/packages/helpers/allowedPostActionModules.ts +++ b/packages/helpers/allowedPostActionModules.ts @@ -1,8 +1,6 @@ -import { PostActionType } from "@hey/indexer"; - const allowedPostActionModules = [ - PostActionType.SimpleCollectAction, - PostActionType.MultirecipientFeeCollectOpenActionModule + "SimpleCollectActionSettings", + "MultirecipientFeeCollectActionSettings" ]; export default allowedPostActionModules; diff --git a/packages/helpers/getOpenActionActOnKey.spec.ts b/packages/helpers/getPostActionActOnKey.spec.ts similarity index 80% rename from packages/helpers/getOpenActionActOnKey.spec.ts rename to packages/helpers/getPostActionActOnKey.spec.ts index bff8c0a650a5..ee2f11a3ced6 100644 --- a/packages/helpers/getOpenActionActOnKey.spec.ts +++ b/packages/helpers/getPostActionActOnKey.spec.ts @@ -1,17 +1,18 @@ +import { PostActionType } from "@hey/indexer"; import { describe, expect, test } from "vitest"; -import getOpenActionActOnKey from "./getOpenActionActOnKey"; +import getOpenActionActOnKey from "./getPostActionActOnKey"; describe("getOpenActionActOnKey", () => { test('should return "simpleCollectOpenAction" for SimpleCollectOpenActionModule', () => { - expect( - getOpenActionActOnKey(OpenActionModuleType.SimpleCollectOpenActionModule) - ).toBe("simpleCollectOpenAction"); + expect(getOpenActionActOnKey(PostActionType.SimpleCollectAction)).toBe( + "simpleCollectOpenAction" + ); }); test('should return "multirecipientCollectOpenAction" for MultirecipientFeeCollectOpenActionModule', () => { expect( getOpenActionActOnKey( - OpenActionModuleType.MultirecipientFeeCollectOpenActionModule + PostActionType.MultirecipientFeeCollectOpenActionModule ) ).toBe("multirecipientCollectOpenAction"); }); diff --git a/packages/helpers/getOpenActionActOnKey.ts b/packages/helpers/getPostActionActOnKey.ts similarity index 58% rename from packages/helpers/getOpenActionActOnKey.ts rename to packages/helpers/getPostActionActOnKey.ts index 4a382f4f8bc9..ae835293b27d 100644 --- a/packages/helpers/getOpenActionActOnKey.ts +++ b/packages/helpers/getPostActionActOnKey.ts @@ -1,18 +1,20 @@ +import { PostActionType } from "@hey/indexer"; + /** * Returns the name of the specified module to be used in the actOn key. * * @param name Name of the module. * @returns Name of the module to be used in the actOn key. */ -const getOpenActionActOnKey = (name: string): string => { +const getPostActionActOnKey = (name: string): string => { switch (name) { - case OpenActionModuleType.SimpleCollectOpenActionModule: + case PostActionType.SimpleCollectAction: return "simpleCollectOpenAction"; - case OpenActionModuleType.MultirecipientFeeCollectOpenActionModule: + case PostActionType.MultirecipientFeeCollectAction: return "multirecipientCollectOpenAction"; default: return "unknownOpenAction"; } }; -export default getOpenActionActOnKey; +export default getPostActionActOnKey; diff --git a/packages/helpers/isOpenActionAllowed.spec.ts b/packages/helpers/isOpenActionAllowed.spec.ts deleted file mode 100644 index 0dc09f29c847..000000000000 --- a/packages/helpers/isOpenActionAllowed.spec.ts +++ /dev/null @@ -1,43 +0,0 @@ -import { describe, expect, test } from "vitest"; -import isOpenActionAllowed from "./isOpenActionAllowed"; - -describe("isOpenActionAllowed", () => { - test("should return false if openActions is undefined", () => { - const result = isOpenActionAllowed(undefined); - expect(result).toBe(false); - }); - - test("should return false if openActions is null", () => { - const result = isOpenActionAllowed(null); - expect(result).toBe(false); - }); - - test("should return false if openActions is an empty array", () => { - const result = isOpenActionAllowed([]); - expect(result).toBe(false); - }); - - test("should return false if no openActions are allowed", () => { - const openActions = [ - { type: "SomeOtherActionModule" }, - { type: "AnotherActionModule" } - ]; - const result = isOpenActionAllowed(openActions as any); - expect(result).toBe(false); - }); - - test("should return true if some openActions are allowed and some are not", () => { - const openActions = [ - { type: "SomeOtherActionModule" }, - { type: OpenActionModuleType.SimpleCollectOpenActionModule } - ]; - const result = isOpenActionAllowed(openActions as any); - expect(result).toBe(true); - }); - - test("should return false if the openAction type is undefined", () => { - const openActions = [{ type: undefined }]; - const result = isOpenActionAllowed(openActions as any); - expect(result).toBe(false); - }); -}); diff --git a/packages/helpers/isOpenActionAllowed.ts b/packages/helpers/isOpenActionAllowed.ts deleted file mode 100644 index 7a22edf6916f..000000000000 --- a/packages/helpers/isOpenActionAllowed.ts +++ /dev/null @@ -1,18 +0,0 @@ -import type { Maybe, OpenActionModule } from "@hey/indexer"; -import allowedPostActionModules from "./allowedPostActionModules"; - -const isOpenActionAllowed = ( - openActions?: Maybe -): boolean => { - if (!openActions?.length) { - return false; - } - - return openActions.some((openAction) => { - const { type } = openAction; - - return allowedPostActionModules.includes(type); - }); -}; - -export default isOpenActionAllowed; diff --git a/packages/helpers/isPostActionAllowed.spec.ts b/packages/helpers/isPostActionAllowed.spec.ts new file mode 100644 index 000000000000..79e547bfaba8 --- /dev/null +++ b/packages/helpers/isPostActionAllowed.spec.ts @@ -0,0 +1,44 @@ +import { PostActionType } from "@hey/indexer"; +import { describe, expect, test } from "vitest"; +import isOpenActionAllowed from "./isPostActionAllowed"; + +describe("isOpenActionAllowed", () => { + test("should return false if postActions is undefined", () => { + const result = isOpenActionAllowed(undefined); + expect(result).toBe(false); + }); + + test("should return false if postActions is null", () => { + const result = isOpenActionAllowed(null); + expect(result).toBe(false); + }); + + test("should return false if postActions is an empty array", () => { + const result = isOpenActionAllowed([]); + expect(result).toBe(false); + }); + + test("should return false if no postActions are allowed", () => { + const postActions = [ + { type: "SomeOtherActionModule" }, + { type: "AnotherActionModule" } + ]; + const result = isOpenActionAllowed(postActions as any); + expect(result).toBe(false); + }); + + test("should return true if some postActions are allowed and some are not", () => { + const postActions = [ + { type: "SomeOtherActionModule" }, + { type: PostActionType.SimpleCollectAction } + ]; + const result = isOpenActionAllowed(postActions as any); + expect(result).toBe(true); + }); + + test("should return false if the postAction type is undefined", () => { + const postActions = [{ type: undefined }]; + const result = isOpenActionAllowed(postActions as any); + expect(result).toBe(false); + }); +}); diff --git a/packages/helpers/isPostActionAllowed.ts b/packages/helpers/isPostActionAllowed.ts new file mode 100644 index 000000000000..becef60bee4b --- /dev/null +++ b/packages/helpers/isPostActionAllowed.ts @@ -0,0 +1,16 @@ +import type { Maybe, PostAction } from "@hey/indexer"; +import allowedPostActionModules from "./allowedPostActionModules"; + +const isPostActionAllowed = (postActions?: Maybe): boolean => { + if (!postActions?.length) { + return false; + } + + return postActions.some((postAction) => { + const { __typename } = postAction; + + return allowedPostActionModules.includes(__typename); + }); +}; + +export default isPostActionAllowed;