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

[PAY-1573] Convert premium content type to union #3711

Merged
merged 7 commits into from
Jul 11, 2023

Conversation

dharit-tan
Copy link
Contributor

@dharit-tan dharit-tan commented Jul 7, 2023

Description

Check the type of a premiumConditions by using the in operator instead of whether or not a field like nft_collection exists in premiumConditions. Also included some typeguards without which ternaries complain.

Dragons

Is there anything the reviewer should be on the lookout for? Are there any dangerous changes?

How Has This Been Tested?

Tested by uploading/attempting to edit collectible + SA tracks on both web and mobile.

How will this change be monitored?

For features that are critical or could fail silently please describe the monitoring/alerting being added.

Feature Flags

Are all new features properly feature flagged? Describe added feature flags.

@dharit-tan dharit-tan changed the base branch from main to gated-content-updates July 7, 2023 07:12
: null
const nftCollection = isPremiumContentCollectibleGated(premiumConditions)
? premiumConditions?.nft_collection
: null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ternaries here

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's because of ?? {} ; if we had a branch that checked if premiumConditions was null first and then returned early we'd probably be good, tho would be tricky given hooks here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

still getting type errors even if I null check first. gonna stick with the type guard for now but let's chat about it tmr.

Copy link
Contributor

Choose a reason for hiding this comment

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

I can live with the type guards!

Copy link
Contributor

@piazzatron piazzatron left a comment

Choose a reason for hiding this comment

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

This looks great 🔥 Few small things around the typeguards but this generally looks super good

packages/common/src/models/Track.ts Outdated Show resolved Hide resolved
: null
const nftCollection = isPremiumContentCollectibleGated(premiumConditions)
? premiumConditions?.nft_collection
: null

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's because of ?? {} ; if we had a branch that checked if premiumConditions was null first and then returned early we'd probably be good, tho would be tricky given hooks here

packages/common/src/store/premium-content/sagas.ts Outdated Show resolved Hide resolved
@dharit-tan dharit-tan marked this pull request as ready for review July 10, 2023 20:37
Copy link
Contributor

@schottra schottra left a comment

Choose a reason for hiding this comment

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

Generally looks good! Just think it might need a cleanup pass.

packages/common/src/hooks/usePremiumContent.ts Outdated Show resolved Hide resolved
packages/common/src/store/premium-content/sagas.ts Outdated Show resolved Hide resolved
const shouldDisplay =
!!premiumConditions.nft_collection || followee || tippedUser
isPremiumContentCollectibleGated(premiumConditions) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Eek, somehow made it more verbose.
I would have thought that if our type is a union of types that are all valid, we just need to check if it's not null here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah good point. Probably good to keep it this way for now tho bc usdc_purchase is a valid option but I haven't written the logic to exclude that yet?

<View>
<Text style={styles.ownersOf}>{messages.ownersOf}</Text>
<View style={styles.collection}>
{premiumConditions.nft_collection.imageUrl && (
{premiumConditions.nft_collection?.imageUrl && (
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ? necessary here? I would expect that the type guard function narrows it to a type here where we know that nft_collection is defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately @saliou and I discovered that nft_collection specifically can be undefined, bc during upload flow user could set the track to collectible gated without specifying a collection yet. Kind of awkward because at every point afterwards all the fields should be defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will include comment

Copy link
Contributor

Choose a reason for hiding this comment

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

Ouch. That does make this whole change a little less useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah it was a bummer :( couldn't think of a way around it. still gonna be useful for usdc tho.

@audius-infra
Copy link
Collaborator

Preview this change https://demo.audius.co/rt-prem-type-2

Copy link
Contributor

@sddioulde sddioulde left a comment

Choose a reason for hiding this comment

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

slightly more verbose but conditions look cleaner imo.

my only worry is the question marks e.g. premiumConditions.nft_collection?.name which used to be premiumConditions.nft_collection.name, meaning it is theoretically possible that some component not display text when it's supposed to be. We should be careful with it and hopefully find a way to avoid it in the future. not sure just how yet

@dharit-tan dharit-tan merged commit 54371aa into gated-content-updates Jul 11, 2023
2 checks passed
@dharit-tan dharit-tan deleted the rt-prem-type-2 branch July 11, 2023 07:23
schottra added a commit that referenced this pull request Jul 11, 2023
…1560-usdc-tiles

* origin/gated-content-updates:
  [PAY-1573] Convert premium content type to union (#3711)
@AudiusProject AudiusProject deleted a comment from linear bot Sep 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants