Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

[PAY-1578] Hide USDC-gated tracks if the feature flag is disabled #3752

Merged
merged 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useCallback, useMemo } from 'react'
import {
Chain,
collectiblesSelectors,
isPremiumContentCollectibleGated,
TrackAvailabilityType
} from '@audius/common'
import { useField } from 'formik'
Expand Down Expand Up @@ -106,8 +107,11 @@ export const CollectibleGatedFields = ({
// which makes the dropdown show the placeholder.
// Otherwise, the default value is the nft collection which was previously selected,
// which also includes the collection image.
const defaultCollectionName =
premiumConditionsValue?.nft_collection?.name ?? ''
const defaultCollectionName = isPremiumContentCollectibleGated(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dharit-tan You were correct on the bad merge. There are some new reads of the gating conditions on main that needed to be updated to use the union type.
Starting to wonder if this is actually useful as it requires calling multiple type checker functions each time we're trying to switch on the gate type? 😬

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah sigh.. it's still gives more type safety tho right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does! And it's useful in the cases where you're checking for one specific condition before moving forward. I think it's clunky for the handful of cases where we are handling all of the types of premium content in one place.

premiumConditionsValue
)
? premiumConditionsValue.nft_collection?.name ?? ''
: ''
const defaultCollection = menuItems.find(
(item) => item.text === defaultCollectionName
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
collectiblesSelectors,
FeatureFlags,
FieldVisibility,
isPremiumContentCollectibleGated,
isPremiumContentFollowGated,
isPremiumContentTipGated,
Nullable,
PremiumConditions,
TrackAvailabilityType
Expand Down Expand Up @@ -110,19 +113,21 @@ export const TrackAvailabilityModalForm = () => {
const isRemix = !isEmpty(remixOfValue?.tracks)

const initialValues = useMemo(() => {
const isTipGated = isPremiumContentTipGated(premiumConditionsValue)
const isFollowGated = isPremiumContentFollowGated(premiumConditionsValue)
const isCollectibleGated = isPremiumContentCollectibleGated(
premiumConditionsValue
)
const initialValues = {}
set(initialValues, IS_UNLISTED, isUnlistedValue)
set(initialValues, IS_PREMIUM, isPremiumValue)
set(initialValues, PREMIUM_CONDITIONS, premiumConditionsValue)

let availabilityType = TrackAvailabilityType.PUBLIC
if (
premiumConditionsValue?.follow_user_id ||
premiumConditionsValue?.tip_user_id
) {
if (isFollowGated || isTipGated) {
availabilityType = TrackAvailabilityType.SPECIAL_ACCESS
}
if (premiumConditionsValue?.nft_collection) {
if (isCollectibleGated) {
availabilityType = TrackAvailabilityType.COLLECTIBLE_GATED
}
if (
Expand All @@ -138,9 +143,7 @@ export const TrackAvailabilityModalForm = () => {
set(
initialValues,
SPECIAL_ACCESS_TYPE,
premiumConditionsValue?.tip_user_id
? SpecialAccessType.TIP
: SpecialAccessType.FOLLOW
isTipGated ? SpecialAccessType.TIP : SpecialAccessType.FOLLOW
)
return initialValues as TrackAvailabilityFormValues
}, [
Expand Down Expand Up @@ -254,12 +257,20 @@ const TrackAvailabilityFields = (props: TrackAvailabilityFieldsProps) => {
break
}
case TrackAvailabilityType.SPECIAL_ACCESS: {
if (!accountUserId || premiumConditionsValue?.tip_user_id) break
if (
!accountUserId ||
isPremiumContentTipGated(premiumConditionsValue)
)
break
setPremiumConditionsValue({ follow_user_id: accountUserId })
break
}
case TrackAvailabilityType.COLLECTIBLE_GATED:
if (!accountUserId || premiumConditionsValue?.nft_collection) break
if (
!accountUserId ||
isPremiumContentCollectibleGated(premiumConditionsValue)
)
break
setPremiumConditionsValue(null)
break
case TrackAvailabilityType.HIDDEN:
Expand Down