Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add shop button to collect on the secondary marketplace #318

Merged
merged 6 commits into from
Nov 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 36 additions & 30 deletions src/components/Watch/CollectVideo/CollectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ type Props = {
fetchingCollectModule: boolean
collectModule: LenstubeCollectModule
collectNow: () => void
shopCollects: () => void
}

const CollectModal: FC<Props> = ({
showModal,
setShowModal,
video,
collectNow,
shopCollects,
collecting,
collectModule,
fetchingCollectModule
Expand Down Expand Up @@ -177,37 +179,41 @@ const CollectModal: FC<Props> = ({
</div>
) : null}
<div className="flex justify-end">
{isAllowed ? (
collectModule?.followerOnly && !video.profile.isFollowedByMe ? (
<div className="flex-1">
<Alert variant="warning">
<div className="flex px-2">
Only {isMembershipActive ? 'Members' : 'Subscribers'}{' '}
can collect this publication
</div>
</Alert>
</div>
) : balanceLoading && !haveEnoughBalance ? (
<div className="flex justify-center w-full py-2">
<Loader />
</div>
) : haveEnoughBalance ? (
<Button disabled={collecting} onClick={() => collectNow()}>
{isFreeCollect ? 'Collect for free' : 'Collect Now'}
</Button>
<span className="flex items-center space-x-2">
{isAllowed ? (
collectModule?.followerOnly &&
!video.profile.isFollowedByMe ? (
<div className="flex-1">
<Alert variant="warning">
<div className="flex px-2">
Only {isMembershipActive ? 'Members' : 'Subscribers'}{' '}
can collect this publication
</div>
</Alert>
</div>
) : balanceLoading && !haveEnoughBalance ? (
<div className="flex justify-center w-full py-2">
<Loader />
</div>
) : haveEnoughBalance ? (
<Button disabled={collecting} onClick={() => collectNow()}>
{isFreeCollect ? 'Collect for free' : 'Collect Now'}
</Button>
) : (
<BalanceAlert collectModule={collectModule} />
)
) : (
<BalanceAlert collectModule={collectModule} />
)
) : (
<PermissionAlert
isAllowed={isAllowed}
setIsAllowed={setIsAllowed}
allowanceModule={
allowanceData
?.approvedModuleAllowanceAmount[0] as ApprovedAllowanceAmount
}
/>
)}
<PermissionAlert
isAllowed={isAllowed}
setIsAllowed={setIsAllowed}
allowanceModule={
allowanceData
?.approvedModuleAllowanceAmount[0] as ApprovedAllowanceAmount
}
/>
)}
<Button onClick={() => shopCollects()}>Shop Collects</Button>
ahomentc marked this conversation as resolved.
Show resolved Hide resolved
</span>
</div>
</>
) : (
Expand Down
21 changes: 21 additions & 0 deletions src/components/Watch/CollectVideo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,26 @@ const CollectVideo: FC<Props> = ({ video, variant = 'primary' }) => {
})
}

const shopCollects = () => {
if (!video) {
return
}
var pubId = ''
ahomentc marked this conversation as resolved.
Show resolved Hide resolved
if (video.__typename === 'Mirror') {
if (!video.mirrorOf) {
return
}
pubId = video.mirrorOf.id
} else {
pubId = video.id
}
const decimalProfileId = parseInt(pubId.split('-')[0], 16)
const decimalPubId = parseInt(pubId.split('-')[1], 16)
const marketplacePublicationId = decimalProfileId + '_' + decimalPubId
const marketplaceUrl = 'http://lensport.io/p/' + marketplacePublicationId
ahomentc marked this conversation as resolved.
Show resolved Hide resolved
window.open(marketplaceUrl)
}

const onClickCollect = () => {
if (!selectedChannelId) return toast.error(SIGN_IN_REQUIRED_MESSAGE)
return setShowCollectModal(true)
Expand All @@ -182,6 +202,7 @@ const CollectVideo: FC<Props> = ({ video, variant = 'primary' }) => {
showModal={showCollectModal}
setShowModal={setShowCollectModal}
collectNow={collectNow}
shopCollects={shopCollects}
collecting={loading}
collectModule={collectModule}
fetchingCollectModule={fetchingCollectModule}
Expand Down