Skip to content

Commit

Permalink
Migrate to Lens v3
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoginth committed Dec 5, 2024
1 parent c09f3ca commit fb2b535
Show file tree
Hide file tree
Showing 21 changed files with 152 additions and 136 deletions.
14 changes: 7 additions & 7 deletions apps/og/src/helpers/getCollectModuleMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -16,35 +16,35 @@ const OpenActionPaidAction: FC<OpenActionPaidActionProps> = ({
}) => {
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 (
<div className="px-5 py-3 text-sm">
{openActions.map((openAction, index) => (
{postActions.map((postAction, index) => (
<div
className="flex items-center space-x-2"
key={`${openAction?.assetAddress}_${index}}`}
key={`${postAction?.assetAddress}_${index}}`}
>
<b>Collected for</b>
<img
alt={openAction?.assetSymbol}
alt={postAction?.assetSymbol}
className="size-5"
src={getTokenImage(openAction?.assetSymbol as string)}
src={getTokenImage(postAction?.assetSymbol as string)}
/>
<span>
{openAction?.amount} {openAction?.assetSymbol}
{postAction?.amount} {postAction?.assetSymbol}
</span>
<span>by</span>
<span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const Mint: FC<MintProps> = ({ onCollectSuccess }) => {
return <Loader className="p-10" message="Loading NFT" />;
}

if (!data?.publication || error) {
if (!data?.post || error) {
return (
<ErrorMessage
className="m-5"
Expand All @@ -40,7 +40,7 @@ const Mint: FC<MintProps> = ({ onCollectSuccess }) => {
}

const post = data?.post as Post;
const openAction = post.openActionModules[0];
const postAction = post.actions[0];

return (
<div className="p-5">
Expand Down Expand Up @@ -87,7 +87,7 @@ const Mint: FC<MintProps> = ({ onCollectSuccess }) => {
</span>
}
onCollectSuccess={onCollectSuccess}
openAction={openAction}
postAction={postAction}
post={post}
/>
</div>
Expand Down
7 changes: 3 additions & 4 deletions apps/web/src/components/Post/Actions/index.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -26,10 +26,9 @@ const PostActions: FC<PostActionsProps> = ({ 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 (
Expand Down
12 changes: 8 additions & 4 deletions apps/web/src/components/Post/OpenAction/Collect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface CollectProps {
const Collect: FC<CollectProps> = ({ 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 =
Expand Down Expand Up @@ -48,8 +48,12 @@ const Collect: FC<CollectProps> = ({ post }) => {
show={showCollectModal}
title="Collect"
>
{openActions?.map((action) => (
<CollectModule key={action.type} openAction={action} post={post} />
{postActions?.map((action) => (
<CollectModule
key={action.__typename}
postAction={action}
post={post}
/>
))}
</Modal>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -31,7 +31,7 @@ interface CollectActionProps {
forceShowCollect?: boolean;
noBalanceErrorMessages?: ReactNode;
onCollectSuccess?: () => void;
openAction: OpenActionModule;
postAction: PostAction;
post: AnyPost;
}

Expand All @@ -42,10 +42,10 @@ const CollectAction: FC<CollectActionProps> = ({
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();
Expand Down Expand Up @@ -75,7 +75,7 @@ const CollectAction: FC<CollectActionProps> = ({
: false;
const isFreeCollectModule = !amount;
const isSimpleFreeCollectModule =
openAction.__typename === "SimpleCollectOpenActionSettings";
postAction.__typename === "SimpleCollectOpenActionSettings";
const isFollowersOnly = collectModule?.followerOnly;
const isFollowedByMe = isFollowersOnly
? post?.author.operations?.isFollowedByMe
Expand Down Expand Up @@ -138,7 +138,7 @@ const CollectAction: FC<CollectActionProps> = ({
toast.success("Collected");
Leafwatch.track(POST.COLLECT_MODULE.COLLECT, {
amount,
collectModule: openAction?.type,
collectModule: postAction?.__typename,
postId: post?.id
});
};
Expand All @@ -157,7 +157,7 @@ const CollectAction: FC<CollectActionProps> = ({
request: {
currencies: assetAddress,
followModules: [],
openActionModules: [openAction.type],
openActionModules: [postAction.__typename],
referenceModules: []
}
}
Expand Down Expand Up @@ -218,7 +218,7 @@ const CollectAction: FC<CollectActionProps> = ({
try {
setIsLoading(true);
const actOnRequest: ActOnOpenActionLensManagerRequest = {
actOn: { [getOpenActionActOnKey(openAction.type)]: true },
actOn: { [getPostActionActOnKey(postAction.__typename)]: true },
for: post?.id
};

Expand Down Expand Up @@ -272,16 +272,16 @@ const CollectAction: FC<CollectActionProps> = ({

if (
!hasAmount &&
(openAction.__typename === "SimpleCollectOpenActionSettings" ||
openAction.__typename === "MultirecipientFeeCollectOpenActionSettings")
(postAction.__typename === "SimpleCollectActionSettings" ||
postAction.__typename === "MultirecipientFeeCollectOpenActionSettings")
) {
return (
<WarningMessage
className="mt-5 w-full"
message={
<NoBalanceError
errorMessage={noBalanceErrorMessages}
moduleAmount={openAction.amount}
moduleAmount={postAction.amount}
/>
}
/>
Expand Down
20 changes: 12 additions & 8 deletions apps/web/src/components/Post/OpenAction/CollectModule/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -36,11 +40,11 @@ import DownloadCollectors from "./DownloadCollectors";
import Splits from "./Splits";

interface CollectModuleProps {
openAction: OpenActionModule;
postAction: PostAction;
post: AnyPost;
}

const CollectModule: FC<CollectModuleProps> = ({ openAction, post }) => {
const CollectModule: FC<CollectModuleProps> = ({ postAction, post }) => {
const { allowedTokens } = useAllowedTokensStore();
const [showCollectorsModal, setShowCollectorsModal] = useState(false);

Expand All @@ -50,9 +54,9 @@ const CollectModule: FC<CollectModuleProps> = ({ 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");
Expand Down Expand Up @@ -124,7 +128,7 @@ const CollectModule: FC<CollectModuleProps> = ({ openAction, post }) => {
<div className="mb-4">
<H4>
{targetPost.__typename} by{" "}
<Slug slug={getAccount(targetPost.by).slugWithPrefix} />
<Slug slug={getAccount(targetPost.author).slugWithPrefix} />
</H4>
</div>
{amount ? (
Expand Down Expand Up @@ -260,7 +264,7 @@ const CollectModule: FC<CollectModuleProps> = ({ openAction, post }) => {
<CollectAction
countOpenActions={countOpenActions}
onCollectSuccess={() => increment()}
openAction={openAction}
postAction={postAction}
post={targetPost}
/>
</div>
Expand Down
12 changes: 8 additions & 4 deletions apps/web/src/components/Post/OpenAction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ interface OpenActionProps {
const OpenAction: FC<OpenActionProps> = ({ 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 (
Expand Down Expand Up @@ -56,8 +56,12 @@ const OpenAction: FC<OpenActionProps> = ({ post }) => {
show={showCollectModal}
title="Collect"
>
{openActions?.map((action) => (
<CollectModule key={action.type} openAction={action} post={post} />
{postActions?.map((action) => (
<CollectModule
key={action.__typename}
postAction={action}
post={post}
/>
))}
</Modal>
</div>
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/components/Settings/Allowance/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -71,7 +72,7 @@ const AllowanceButton: FC<AllowanceButtonProps> = ({
) => {
try {
const isUnknownModule =
module.moduleName === OpenActionModuleType.UnknownOpenActionModule;
module.moduleName === PostActionType.UnknownOpenActionModule;

const { data } = await generateModuleCurrencyApprovalData({
variables: {
Expand Down
9 changes: 5 additions & 4 deletions apps/web/src/components/Shared/GetOpenActionModuleIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<GetOpenActionModuleIconProps> = ({
module
}) => {
switch (module?.type) {
case OpenActionModuleType.SimpleCollectOpenActionModule:
switch (module?.__typename) {
case "SimpleCollectActionSettings":
return <DocumentPlusIcon className="size-5" />;
case OpenActionModuleType.MultirecipientFeeCollectOpenActionModule:
case "MultirecipientFeeCollectActionSettings":
return <UserGroupIcon className="size-5" />;
default:
return <BriefcaseIcon className="size-5" />;
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/components/Shared/NoBalanceError/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Loading

0 comments on commit fb2b535

Please sign in to comment.