1- import { USDC } from '@audius/fixed-decimal'
21import { HashId , Id , type UploadResponse } from '@audius/sdk'
32import { useMutation , useQueryClient } from '@tanstack/react-query'
43
@@ -29,7 +28,6 @@ type PublishTracksContext = Pick<
2928 'audiusSdk' | 'analytics' | 'dispatch' | 'reportToSentry'
3029> & {
3130 userId : number
32- wallet : string
3331 kind ?: 'tracks' | 'album' | 'playlist'
3432}
3533
@@ -47,29 +45,22 @@ export const publishTracks = async (
4745) => {
4846 const {
4947 userId,
50- wallet,
5148 kind,
5249 audiusSdk,
5350 dispatch,
5451 reportToSentry,
5552 analytics : { make, track }
5653 } = context
5754
58- if ( ! context . userId || ! context . wallet ) {
55+ if ( ! context . userId ) {
5956 throw new Error ( 'User ID and wallet are required to publish tracks' )
6057 }
6158
6259 const sdk = await audiusSdk ( )
63- const userBank = await sdk . services . claimableTokensClient . deriveUserBank ( {
64- ethWallet : wallet ,
65- mint : 'USDC'
66- } )
60+
6761 return await Promise . all (
6862 params . map ( async ( param ) => {
69- const snakeMetadata = addPremiumMetadata (
70- userBank . toString ( ) ,
71- param . metadata
72- )
63+ const snakeMetadata = addPremiumMetadata ( userId , param . metadata )
7364
7465 const trackId = await sdk . tracks . generateTrackId ( )
7566 const camelMetadata = trackMetadataForUploadToSdk ( {
@@ -191,15 +182,13 @@ export const usePublishTracks = (
191182 const { data : account } = useCurrentAccount ( )
192183 const { data : accountUser } = useCurrentAccountUser ( )
193184 const userId = account ?. userId ?? undefined
194- const wallet = account ?. walletAddresses . currentUser ?? undefined
195185 const kind = options ?. kind ?? 'tracks'
196186
197187 return useMutation ( {
198188 ...options ,
199189 ...getPublishTracksOptions ( {
200190 ...queryContext ,
201191 userId : userId ! ,
202- wallet : wallet ! ,
203192 kind
204193 } ) ,
205194 onSuccess : async ( data ) => {
@@ -235,11 +224,10 @@ export const usePublishTracks = (
235224 * returns updated conditions with price in WEI and splits in the new array format.
236225 */
237226export function getUSDCMetadata (
238- userBank : string ,
227+ userId : number ,
239228 stream_conditions : USDCPurchaseConditions
240229) : USDCPurchaseConditions {
241230 const priceCents = stream_conditions . usdc_purchase . price
242- const priceWei = Number ( USDC ( priceCents / 100 ) . value . toString ( ) )
243231 return {
244232 usdc_purchase : {
245233 price : priceCents ,
@@ -248,9 +236,8 @@ export function getUSDCMetadata(
248236 } ) ,
249237 splits : [
250238 {
251- payout_wallet : userBank ?. toString ( ) ?? '' ,
252- percentage : 100 ,
253- amount : priceWei
239+ user_id : userId ,
240+ percentage : 100
254241 }
255242 ]
256243 }
@@ -262,24 +249,21 @@ export function getUSDCMetadata(
262249 * Converts prices to WEI and adds splits for USDC purchasable content.
263250 */
264251export function addPremiumMetadata < T extends TrackMetadataForUpload > (
265- userBank : string ,
252+ userId : number ,
266253 track : T
267254) {
268255 // download_conditions could be set separately from stream_conditions, so we check for them first
269256 if ( isContentUSDCPurchaseGated ( track . download_conditions ) ) {
270257 track . download_conditions = getUSDCMetadata (
271- userBank ,
258+ userId ,
272259 track . download_conditions
273260 )
274261 }
275262
276263 if ( isContentUSDCPurchaseGated ( track . stream_conditions ) ) {
277- track . stream_conditions = getUSDCMetadata ( userBank , track . stream_conditions )
264+ track . stream_conditions = getUSDCMetadata ( userId , track . stream_conditions )
278265 // If stream_conditions are set, download_conditions should always match
279- track . download_conditions = getUSDCMetadata (
280- userBank ,
281- track . stream_conditions
282- )
266+ track . download_conditions = getUSDCMetadata ( userId , track . stream_conditions )
283267 }
284268
285269 return track
0 commit comments