diff --git a/src/components/subscribe-to-unlock-card.tsx b/src/components/subscribe-to-unlock-card.tsx index 2ed40875f..33811e411 100644 --- a/src/components/subscribe-to-unlock-card.tsx +++ b/src/components/subscribe-to-unlock-card.tsx @@ -5,6 +5,7 @@ import { useGetPolicyTerms } from '@src/hooks/use-get-policy-terms.ts'; import { Address } from 'viem'; import LoadingButton from '@mui/lab/LoadingButton'; import { GLOBAL_CONSTANTS } from '@src/config-global.ts'; +import { useIsPolicyAuthorized } from '@src/hooks/use-is-policy-authorized.ts'; interface Props { post: any; @@ -18,10 +19,12 @@ export const SubscribeToUnlockCard = ({ loadingSubscribe, post, }: Props) => { + const ownerAddress = post?.by?.ownedBy?.address as Address const { terms } = useGetPolicyTerms( GLOBAL_CONSTANTS.SUBSCRIPTION_POLICY_ADDRESS as Address, - post?.by?.ownedBy?.address as Address + ownerAddress ); + const { isAuthorized } = useIsPolicyAuthorized(GLOBAL_CONSTANTS.SUBSCRIPTION_POLICY_ADDRESS, ownerAddress); const durationDays = 30; // a month const totalCostWei = terms?.amount ? terms?.amount * BigInt(durationDays) : 0; // Calculate total cost in Wei: DAILY_COST_WEI * durationDays const totalCostMMC = ethers.formatUnits(totalCostWei, 18); // Converts Wei to MMC @@ -50,24 +53,28 @@ export const SubscribeToUnlockCard = ({ This content is exclusively for members. Become part of our growing community to access behind-the-scenes content, exclusive posts, and much more! - - - Join - - - - Join now for just {totalCostMMC} MMC/month and access to{' '} - {post?.by?.stats?.posts} exclusive posts from{' '} - {post?.by?.metadata?.displayName ?? post?.handle?.localName}! - - + {isAuthorized && ( + <> + + + Join + + + + Join now for just {totalCostMMC} MMC/month and access to{' '} + {post?.by?.stats?.posts} exclusive posts from{' '} + {post?.by?.metadata?.displayName ?? post?.handle?.localName}! + + + + )} ); diff --git a/src/sections/publication/view/publication-details-view.tsx b/src/sections/publication/view/publication-details-view.tsx index df918bb7c..b1599758d 100644 --- a/src/sections/publication/view/publication-details-view.tsx +++ b/src/sections/publication/view/publication-details-view.tsx @@ -33,6 +33,8 @@ import LoadingButton from '@mui/lab/LoadingButton'; import { useDispatch, useSelector } from 'react-redux'; import { openLoginModal } from '@redux/auth'; import { appId, PublicationType, usePublications } from '@lens-protocol/react-web'; +import { useIsPolicyAuthorized } from '@src/hooks/use-is-policy-authorized.ts'; +import { GLOBAL_CONSTANTS } from '@src/config-global.ts'; const MAX_LINES = 5; @@ -68,6 +70,7 @@ export default function PublicationDetailsView({ id }: Props) { fetching: accessFetchingLoading, refetch: refetchAccess, } = useHasAccess(ownerAddress); + const { isAuthorized } = useIsPolicyAuthorized(GLOBAL_CONSTANTS.SUBSCRIPTION_POLICY_ADDRESS, ownerAddress); const getMediaUri = (cid: string): string => `${cid}`; @@ -223,26 +226,28 @@ export default function PublicationDetailsView({ id }: Props) { }} /> - - - - Join - - + {isAuthorized && ( + + + + Join + + + )} )} diff --git a/src/sections/user/view/user-profile-view.tsx b/src/sections/user/view/user-profile-view.tsx index ac857b72d..9bf94c91b 100644 --- a/src/sections/user/view/user-profile-view.tsx +++ b/src/sections/user/view/user-profile-view.tsx @@ -22,6 +22,10 @@ import { RootState } from '@src/redux/store'; import { setFollowers, setFollowings } from '@redux/followers'; import ProfileReferrals from "@src/sections/user/profile-referrals.tsx"; import useReferrals from "@src/hooks/use-referrals.ts"; +import Alert from '@mui/material/Alert'; +import { useIsPolicyAuthorized } from '@src/hooks/use-is-policy-authorized.ts'; +import { GLOBAL_CONSTANTS } from '@src/config-global.ts'; +import { Address } from 'viem'; // ---------------------------------------------------------------------- @@ -47,6 +51,10 @@ const UserProfileView = ({ id }: any) => { metadata: { publishedOn: [appId('watchit')] }, }, }); + const { isAuthorized, loading: authorizedLoading } = useIsPolicyAuthorized( + GLOBAL_CONSTANTS.SUBSCRIPTION_POLICY_ADDRESS, + profile?.ownedBy?.address as Address + ); const { invitations: referrals, fetchInvitations, loading: loadingReferrals } = useReferrals(); @@ -115,8 +123,20 @@ const UserProfileView = ({ id }: any) => { ); + const showSubscriptionAlert = + sessionData?.authenticated && + sessionData?.profile?.id === profile?.id && + (publications?.length ?? 0) >= 1 && + !isAuthorized && + !authorizedLoading; + return ( + {showSubscriptionAlert && ( + + Set your subscription prices so users can access your content. Click 'Set Joining Prices' next to your profile picture. + + )}