Skip to content

Commit

Permalink
[PAY-2554, PAY-2555] Purchase album via purchase modal (#7941)
Browse files Browse the repository at this point in the history
  • Loading branch information
amendelsohn authored Mar 27, 2024
1 parent 197c0a0 commit 20fea34
Show file tree
Hide file tree
Showing 55 changed files with 853 additions and 532 deletions.
5 changes: 0 additions & 5 deletions packages/commands/src/create-playlist.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ program
}))
}
}
console.log(chalk.yellow('Playlist Metadata: '), metadata)
if (price) {
if (!album) {
program.error(chalk.red('Price can only be set for albums'))
Expand All @@ -58,10 +57,6 @@ program
price,
audiusLibs
})
console.log(
chalk.yellow('Stream Conditions: '),
metadata.stream_conditions
)
}
const response = await audiusLibs.EntityManager.createPlaylist(metadata)

Expand Down
9 changes: 8 additions & 1 deletion packages/common/src/hooks/purchaseContent/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ComputedCollectionProperties, UserCollectionMetadata } from '~/models'
import {
USDCPurchaseConditions,
UserTrackMetadata,
Expand All @@ -19,6 +20,11 @@ export enum PayExtraPreset {
NONE = 'none'
}

export type PurchaseableAlbumStreamMetadata = UserCollectionMetadata &
ComputedCollectionProperties & {
stream_conditions: USDCPurchaseConditions
}

export type PurchaseableTrackStreamMetadata = UserTrackMetadata &
ComputedTrackProperties & {
stream_conditions: USDCPurchaseConditions
Expand All @@ -29,9 +35,10 @@ export type PurchaseableTrackDownloadMetadata = UserTrackMetadata &
download_conditions: USDCPurchaseConditions
}

export type PurchaseableTrackMetadata =
export type PurchaseableContentMetadata =
| PurchaseableTrackStreamMetadata
| PurchaseableTrackDownloadMetadata
| PurchaseableAlbumStreamMetadata

export type USDCPurchaseConfig = {
minContentPriceCents: number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import { USDC } from '@audius/fixed-decimal'
import BN from 'bn.js'
import { useDispatch, useSelector } from 'react-redux'

import { UserCollectionMetadata } from '~/models'
import { PurchaseMethod, PurchaseVendor } from '~/models/PurchaseContent'
import { UserTrackMetadata } from '~/models/Track'
import {
ContentType,
PurchaseableContentType,
PurchaseContentPage,
isContentPurchaseInProgress,
purchaseContentActions,
Expand Down Expand Up @@ -36,17 +37,18 @@ const {
} = purchaseContentSelectors

export const usePurchaseContentFormConfiguration = ({
track,
metadata,
price,
presetValues,
purchaseVendor
}: {
track?: Nullable<UserTrackMetadata>
metadata?: Nullable<UserTrackMetadata | UserCollectionMetadata>
price: number
presetValues: PayExtraAmountPresetValues
purchaseVendor?: PurchaseVendor
}) => {
const dispatch = useDispatch()
const isAlbum = metadata && 'playlist_id' in metadata
const stage = useSelector(getPurchaseContentFlowStage)
const error = useSelector(getPurchaseContentError)
const page = useSelector(getPurchaseContentPage)
Expand All @@ -71,7 +73,8 @@ export const usePurchaseContentFormConfiguration = ({
purchaseMethod,
purchaseVendor
}: PurchaseContentValues) => {
if (isUnlocking || !track?.track_id) return
const contentId = isAlbum ? metadata?.playlist_id : metadata?.track_id
if (isUnlocking || !contentId) return

if (
purchaseMethod === PurchaseMethod.CRYPTO &&
Expand All @@ -90,13 +93,15 @@ export const usePurchaseContentFormConfiguration = ({
purchaseVendor,
extraAmount,
extraAmountPreset: amountPreset,
contentId: track.track_id,
contentType: ContentType.TRACK
contentId,
contentType: isAlbum
? PurchaseableContentType.ALBUM
: PurchaseableContentType.TRACK
})
)
}
},
[isUnlocking, track, page, presetValues, dispatch]
[isAlbum, isUnlocking, metadata, page, presetValues, dispatch]
)

return {
Expand Down
28 changes: 20 additions & 8 deletions packages/common/src/hooks/purchaseContent/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { UserTrackMetadata, isContentUSDCPurchaseGated } from '~/models/Track'
import { isContentUSDCPurchaseGated } from '~/models/Track'

import {
PayExtraAmountPresetValues,
PayExtraPreset,
PurchaseableAlbumStreamMetadata,
PurchaseableContentMetadata,
PurchaseableTrackDownloadMetadata,
PurchaseableTrackStreamMetadata
} from './types'
Expand Down Expand Up @@ -34,12 +36,22 @@ export const getExtraAmount = ({
return extraAmount
}

export const isTrackStreamPurchaseable = (
track: UserTrackMetadata
): track is PurchaseableTrackStreamMetadata =>
isContentUSDCPurchaseGated(track.stream_conditions)
export const isPurchaseableAlbum = (
metadata?: PurchaseableContentMetadata
): metadata is PurchaseableAlbumStreamMetadata =>
!!metadata &&
'is_album' in metadata &&
isContentUSDCPurchaseGated(metadata.stream_conditions)

export const isStreamPurchaseable = (
metadata: PurchaseableContentMetadata
): metadata is
| PurchaseableTrackStreamMetadata
| PurchaseableAlbumStreamMetadata =>
isContentUSDCPurchaseGated(metadata.stream_conditions)

export const isTrackDownloadPurchaseable = (
track: UserTrackMetadata
): track is PurchaseableTrackDownloadMetadata =>
isContentUSDCPurchaseGated(track.download_conditions)
metadata: PurchaseableContentMetadata
): metadata is PurchaseableTrackDownloadMetadata =>
'download_conditions' in metadata &&
isContentUSDCPurchaseGated(metadata.download_conditions)
4 changes: 1 addition & 3 deletions packages/common/src/hooks/useSelectTierInfo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { ID } from '../models'
import { makeGetTierAndVerifiedForUser } from '../store'
import { getTierAndVerifiedForUser } from '../store'

import { useProxySelector } from './useProxySelector'

const getTierAndVerifiedForUser = makeGetTierAndVerifiedForUser()

/**
* Wraps our reselect tier selector in useMemo and useSelector
* to be safe for use in multiple components
Expand Down
11 changes: 10 additions & 1 deletion packages/common/src/models/Collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Repost } from '../models/Repost'
import { Nullable } from '../utils/typeUtils'

import { Favorite } from './Favorite'
import { UserTrackMetadata, ResourceContributor, Copyright } from './Track'
import {
AccessConditions,
UserTrackMetadata,
ResourceContributor,
Copyright,
AccessPermissions
} from './Track'
import { User, UserMetadata } from './User'

export enum Variant {
Expand Down Expand Up @@ -59,6 +65,9 @@ export type CollectionMetadata = {
local?: boolean
release_date?: string
ddex_app?: string | null
is_stream_gated: boolean
stream_conditions: Nullable<AccessConditions>
access: AccessPermissions
ddex_release_ids?: any | null
artists?: [ResourceContributor] | null
copyright_line?: Copyright | null
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/models/PurchaseContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export enum PurchaseAccess {
STREAM = 'stream',
DOWNLOAD = 'download'
}

export type GatedContentStatus = null | 'UNLOCKING' | 'UNLOCKED' | 'LOCKED'
2 changes: 0 additions & 2 deletions packages/common/src/models/Track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ export type SolCollectionMap = {
}
}

export type GatedTrackStatus = null | 'UNLOCKING' | 'UNLOCKED' | 'LOCKED'

export type ResourceContributor = {
name: string
roles: [string]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,11 @@ export const makePlaylist = (
const total_play_count =
'total_play_count' in playlist ? playlist.total_play_count : 0
const track_count = 'track_count' in playlist ? playlist.track_count : 0
const is_stream_gated =
'is_stream_gated' in playlist ? playlist.is_stream_gated : false
const stream_conditions =
'stream_conditions' in playlist ? playlist.stream_conditions : null
const access = 'access' in playlist ? playlist.access : null

const playlistContents = {
track_ids: playlist.added_timestamps
Expand Down Expand Up @@ -373,6 +378,9 @@ export const makePlaylist = (
track_count,
total_play_count,
playlist_contents: playlistContents,
is_stream_gated,
stream_conditions,
access,

// Fields to prune
id: undefined,
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/services/audius-api-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ export type APIPlaylist = {
cover_art: Nullable<string>
cover_art_sizes: Nullable<string>
cover_art_cids: Nullable<CoverArtSizes>
is_stream_gated: boolean
stream_conditions: Nullable<AccessConditions>
}

export type APISearchPlaylist = Omit<
Expand Down
5 changes: 3 additions & 2 deletions packages/common/src/services/audius-backend/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@solana/web3.js'
import BN from 'bn.js'

import { PurchaseableContentType } from '~/store'
import { BN_USDC_CENT_WEI } from '~/utils/wallet'

import {
Expand Down Expand Up @@ -381,7 +382,7 @@ export type PurchaseContentArgs = {
id: ID
blocknumber: number
extraAmount?: number | BN
type: 'track'
type: PurchaseableContentType
splits: Record<string, number | BN>
purchaserUserId: ID
purchaseAccess: PurchaseAccess
Expand All @@ -397,7 +398,7 @@ export const purchaseContent = async (

export type PurchaseContentWithPaymentRouterArgs = {
id: number
type: 'track'
type: PurchaseableContentType
splits: Record<string, number>
extraAmount?: number
blocknumber: number
Expand Down
Loading

0 comments on commit 20fea34

Please sign in to comment.