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 all 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
20 changes: 19 additions & 1 deletion packages/web/src/common/store/lineup/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
queueActions,
playerSelectors,
queueSelectors,
getContext
getContext,
FeatureFlags,
isPremiumContentUSDCPurchaseGated
} from '@audius/common'
import {
all,
Expand All @@ -29,6 +31,7 @@ import {

import { getToQueue } from 'common/store/queue/sagas'
import { isMobileWeb } from 'common/utils/isMobileWeb'
import { getFeatureEnabled } from 'services/remote-config/featureFlagHelpers'

const { getSource, getUid, getPositions } = queueSelectors
const { getUid: getCurrentPlayerTrackUid, getPlaying } = playerSelectors
Expand All @@ -46,6 +49,10 @@ function* filterDeletes(tracksMetadata, removeDeleted) {
const remoteConfig = yield getContext('remoteConfigInstance')
yield call(remoteConfig.waitForRemoteConfig)

const isUSDCGatedContentEnabled = yield getFeatureEnabled(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: In the PR I based this on, there was a waitForRead() at this point. Looking into what waitForRead is waiting on (reachability and account), I don't think there's any additional need to wait on that condition here if the original lineup processing wasn't already waiting for it.
But if others can think of a reason why we should, I'm happy to add it.

FeatureFlags.USDC_PURCHASES
)

return tracksMetadata
.map((metadata) => {
// If the incoming metadata is null, return null
Expand All @@ -54,6 +61,17 @@ function* filterDeletes(tracksMetadata, removeDeleted) {
return null
}

// Treat usdc content as deleted if feature is not enabled
// TODO: https://linear.app/audius/issue/PAY-1533/remove-usdc-feature-flag
// Remove this when removing the feature flags
if (
!isUSDCGatedContentEnabled &&
metadata.is_premium &&
isPremiumContentUSDCPurchaseGated(metadata.premium_conditions)
) {
return null
}

// If we said to remove deleted tracks and it is deleted, remove it
if (removeDeleted && metadata.is_delete) return null
// If we said to remove deleted and the track/playlist owner is deactivated, remove it
Expand Down
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