Skip to content
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 10 additions & 6 deletions packages/common/src/adapters/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export const coinFromSdk = (input: CoinSDK | undefined): Coin | undefined => {
// Fall back to dynamic bonding curve data if so.
const defaultSupply = 1e9

const { isMigrated, priceUSD, address } = input.dynamicBondingCurve
const dbc = input.dynamicBondingCurve
const isMigrated = dbc?.isMigrated ?? true
const priceUSD = dbc?.priceUSD ?? 0
const address = dbc?.address
const hasBirdeyeSupply =
input.totalSupply !== undefined && input.totalSupply > 0
const hasBirdeyePrice = input.price !== undefined && input.price > 0
Expand All @@ -66,15 +69,16 @@ export const coinFromSdk = (input: CoinSDK | undefined): Coin | undefined => {

// For price, use the bonding curve price if the input hasn't graduated or we have no birdeye data
const displayPrice =
(!isMigrated && hasBondingCurveData) || !hasBirdeyePrice
((!isMigrated && hasBondingCurveData) || !hasBirdeyePrice
? priceUSD
: input.price
: input.price) ?? 0

// For market cap, use the bonding curve market cap if the input hasn't graduated or we have no birdeye data
const displayMarketCap =
(!isMigrated && hasBondingCurveData) || !hasBirdeyeSupply
? displayPrice * (hasBirdeyeSupply ? input.totalSupply : defaultSupply)
: input.marketCap
((!isMigrated && hasBondingCurveData) || !hasBirdeyeSupply
? displayPrice *
(hasBirdeyeSupply ? (input.totalSupply ?? 0) : defaultSupply)
: input.marketCap) ?? 0

const { ownerId: _ignored, ...rest } = input
return {
Expand Down
7 changes: 6 additions & 1 deletion packages/common/src/adapters/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
full,
Id,
OptionalHashId,
type Playlist as PlaylistV1,
UpdateAlbumRequest,
UpdatePlaylistRequest
} from '@audius/sdk'
Expand Down Expand Up @@ -51,6 +52,7 @@ export const userCollectionMetadataFromSDK = (
| full.PlaylistFullWithoutTracks
| full.SearchPlaylistFull
| full.PlaylistFull
| PlaylistV1
): UserCollectionMetadata | undefined => {
try {
const decodedPlaylistId = OptionalHashId.parse(input.id)
Expand All @@ -74,7 +76,10 @@ export const userCollectionMetadataFromSDK = (
'150x150': input.artwork._150x150,
'480x480': input.artwork._480x480,
'1000x1000': input.artwork._1000x1000,
mirrors: input.artwork.mirrors
mirrors:
'mirrors' in input.artwork
? (input.artwork as { mirrors?: string[] }).mirrors
: undefined
}
: {},
variant: Variant.USER_GENERATED,
Expand Down
2 changes: 2 additions & 0 deletions packages/common/src/adapters/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,5 +641,7 @@ export const notificationFromSDK = (
...formatBaseNotification(notification)
}
}
default:
return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,22 @@ describe('getCollectionsBatcher', () => {
allowAiAttribution: false,
supporterCount: 0,
supportingCount: 0,
artistCoinBadge: undefined,
splUsdcWallet: undefined,
artistCoinBadge: {},
splUsdcWallet: '',
hasCollectibles: false
}
})

const mockSdk = {
full: {
playlists: {
getBulkPlaylists: vi
.fn()
.mockImplementation((params: GetBulkPlaylistsRequest) => {
const collections = params.id?.map((collectionId) =>
createMockSdkCollection(HashId.parse(collectionId))
)
return Promise.resolve({ data: collections })
})
}
playlists: {
getBulkPlaylists: vi
.fn()
.mockImplementation((params: GetBulkPlaylistsRequest) => {
const collections = params.id?.map((collectionId) =>
createMockSdkCollection(HashId.parse(collectionId))
)
return Promise.resolve({ data: collections })
})
}
} as unknown as BatchContext['sdk']

Expand All @@ -144,7 +142,7 @@ describe('getCollectionsBatcher', () => {
const id = 1
const result = await batcher.fetch(id)

expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenCalledWith({
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenCalledWith({
id: [Id.parse(id)],
userId: OptionalId.parse(null)
})
Expand All @@ -165,8 +163,8 @@ describe('getCollectionsBatcher', () => {
const results = await Promise.all(ids.map((id) => batcher.fetch(id)))

// Verify single bulk request was made
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenCalledTimes(1)
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenCalledWith({
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenCalledTimes(1)
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenCalledWith({
id: ids.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down Expand Up @@ -202,12 +200,12 @@ describe('getCollectionsBatcher', () => {
)

// Verify two separate bulk requests were made
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenCalledTimes(2)
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenNthCalledWith(1, {
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenCalledTimes(2)
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenNthCalledWith(1, {
id: firstBatchIds.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenNthCalledWith(2, {
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenNthCalledWith(2, {
id: secondBatchIds.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down Expand Up @@ -244,7 +242,7 @@ describe('getCollectionsBatcher', () => {
const missingId = 999

// Mock API to only return data for existingId
const mockBulkPlaylists = mockSdk.full.playlists
const mockBulkPlaylists = mockSdk.playlists
.getBulkPlaylists as unknown as MockInstance<
[GetBulkPlaylistsRequest],
Promise<{ data: full.PlaylistFull[] }>
Expand Down Expand Up @@ -278,8 +276,8 @@ describe('getCollectionsBatcher', () => {
expect(missingResult).toBeNull()

// Verify single batch request was made with both IDs
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenCalledTimes(1)
expect(mockSdk.full.playlists.getBulkPlaylists).toHaveBeenCalledWith({
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenCalledTimes(1)
expect(mockSdk.playlists.getBulkPlaylists).toHaveBeenCalledWith({
id: [missingId, existingId].map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,12 @@ describe('getTracksBatcher', () => {
profilePictureCids: undefined,
profilePictureLegacy: undefined,
playlistLibrary: undefined,
allowAiAttribution: false
allowAiAttribution: false,
artistCoinBadge: {},
splUsdcWallet: '',
supporterCount: 0,
supportingCount: 0,
hasCollectibles: false
},
origFileCid: undefined,
origFilename: undefined,
Expand All @@ -157,17 +162,15 @@ describe('getTracksBatcher', () => {
})

const mockSdk = {
full: {
tracks: {
getBulkTracks: vi
.fn()
.mockImplementation((params: GetBulkTracksRequest) => {
const tracks = params.id?.map((trackId) =>
createMockSdkTrack(HashId.parse(trackId))
)
return Promise.resolve({ data: tracks })
})
}
tracks: {
getBulkTracks: vi
.fn()
.mockImplementation((params: GetBulkTracksRequest) => {
const tracks = params.id?.map((trackId) =>
createMockSdkTrack(HashId.parse(trackId))
)
return Promise.resolve({ data: tracks })
})
}
} as unknown as BatchContext['sdk']

Expand All @@ -187,7 +190,7 @@ describe('getTracksBatcher', () => {
const id = 1
const result = await batcher.fetch(id)

expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenCalledWith({
expect(mockSdk.tracks.getBulkTracks).toHaveBeenCalledWith({
id: [Id.parse(id)],
userId: OptionalId.parse(null)
})
Expand All @@ -204,8 +207,8 @@ describe('getTracksBatcher', () => {
const results = await Promise.all(ids.map((id) => batcher.fetch(id)))

// Verify single bulk request was made
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenCalledTimes(1)
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenCalledWith({
expect(mockSdk.tracks.getBulkTracks).toHaveBeenCalledTimes(1)
expect(mockSdk.tracks.getBulkTracks).toHaveBeenCalledWith({
id: ids.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down Expand Up @@ -237,12 +240,12 @@ describe('getTracksBatcher', () => {
)

// Verify two separate bulk requests were made
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenCalledTimes(2)
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenNthCalledWith(1, {
expect(mockSdk.tracks.getBulkTracks).toHaveBeenCalledTimes(2)
expect(mockSdk.tracks.getBulkTracks).toHaveBeenNthCalledWith(1, {
id: firstBatchIds.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenNthCalledWith(2, {
expect(mockSdk.tracks.getBulkTracks).toHaveBeenNthCalledWith(2, {
id: secondBatchIds.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down Expand Up @@ -273,7 +276,7 @@ describe('getTracksBatcher', () => {
const missingId = 999

// Mock API to only return data for existingId
const mockBulkTracks = mockSdk.full.tracks
const mockBulkTracks = mockSdk.tracks
.getBulkTracks as unknown as MockInstance<
[GetBulkTracksRequest],
Promise<{ data: full.TrackFull[] }>
Expand Down Expand Up @@ -301,8 +304,8 @@ describe('getTracksBatcher', () => {
expect(missingResult).toBeNull()

// Verify single batch request was made with both IDs
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenCalledTimes(1)
expect(mockSdk.full.tracks.getBulkTracks).toHaveBeenCalledWith({
expect(mockSdk.tracks.getBulkTracks).toHaveBeenCalledTimes(1)
expect(mockSdk.tracks.getBulkTracks).toHaveBeenCalledWith({
id: [missingId, existingId].map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,24 @@ describe('getUsersBatcher', () => {
blocknumber: 0,
isStorageV2: false,
doesCurrentUserSubscribe: false,
allowAiAttribution: false
allowAiAttribution: false,
artistCoinBadge: {},
splUsdcWallet: '',
supporterCount: 0,
supportingCount: 0,
hasCollectibles: false
})

const mockSdk = {
full: {
users: {
getBulkUsers: vi
.fn()
.mockImplementation((params: GetBulkUsersRequest) => {
const users = params.id?.map((userId) =>
createMockSdkUser(HashId.parse(userId))
)
return Promise.resolve({ data: users })
})
}
users: {
getBulkUsers: vi
.fn()
.mockImplementation((params: GetBulkUsersRequest) => {
const users = params.id?.map((userId) =>
createMockSdkUser(HashId.parse(userId))
)
return Promise.resolve({ data: users })
})
}
} as unknown as BatchContext['sdk']

Expand All @@ -91,7 +94,7 @@ describe('getUsersBatcher', () => {
const id = 1
const result = await batcher.fetch(id)

expect(mockSdk.full.users.getBulkUsers).toHaveBeenCalledWith({
expect(mockSdk.users.getBulkUsers).toHaveBeenCalledWith({
id: [Id.parse(id)],
userId: OptionalId.parse(null)
})
Expand All @@ -108,8 +111,8 @@ describe('getUsersBatcher', () => {
const results = await Promise.all(ids.map((id) => batcher.fetch(id)))

// Verify single bulk request was made
expect(mockSdk.full.users.getBulkUsers).toHaveBeenCalledTimes(1)
expect(mockSdk.full.users.getBulkUsers).toHaveBeenCalledWith({
expect(mockSdk.users.getBulkUsers).toHaveBeenCalledTimes(1)
expect(mockSdk.users.getBulkUsers).toHaveBeenCalledWith({
id: ids.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down Expand Up @@ -141,12 +144,12 @@ describe('getUsersBatcher', () => {
)

// Verify two separate bulk requests were made
expect(mockSdk.full.users.getBulkUsers).toHaveBeenCalledTimes(2)
expect(mockSdk.full.users.getBulkUsers).toHaveBeenNthCalledWith(1, {
expect(mockSdk.users.getBulkUsers).toHaveBeenCalledTimes(2)
expect(mockSdk.users.getBulkUsers).toHaveBeenNthCalledWith(1, {
id: firstBatchIds.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
expect(mockSdk.full.users.getBulkUsers).toHaveBeenNthCalledWith(2, {
expect(mockSdk.users.getBulkUsers).toHaveBeenNthCalledWith(2, {
id: secondBatchIds.map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand All @@ -171,8 +174,7 @@ describe('getUsersBatcher', () => {
const missingId = 999

// Mock API to only return data for existingId
const mockBulkUsers = mockSdk.full.users
.getBulkUsers as unknown as MockInstance<
const mockBulkUsers = mockSdk.users.getBulkUsers as unknown as MockInstance<
[GetBulkUsersRequest],
Promise<{ data: full.UserFull[] }>
>
Expand All @@ -199,8 +201,8 @@ describe('getUsersBatcher', () => {
expect(missingResult).toBeNull()

// Verify single batch request was made with both IDs
expect(mockSdk.full.users.getBulkUsers).toHaveBeenCalledTimes(1)
expect(mockSdk.full.users.getBulkUsers).toHaveBeenCalledWith({
expect(mockSdk.users.getBulkUsers).toHaveBeenCalledTimes(1)
expect(mockSdk.users.getBulkUsers).toHaveBeenCalledWith({
id: [missingId, existingId].map((id) => Id.parse(id)),
userId: OptionalId.parse(null)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getCollectionsBatcher = memoize(
const { sdk, currentUserId, queryClient } = context
if (!ids.length) return []

const { data } = await sdk.full.playlists.getBulkPlaylists({
const { data } = await sdk.playlists.getBulkPlaylists({
id: ids.map((id) => Id.parse(id)),
userId: OptionalId.parse(currentUserId)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const getTracksBatcher = memoize(
const { sdk, currentUserId, queryClient } = context
if (!ids.length) return []

const { data } = await sdk.full.tracks.getBulkTracks({
const { data } = await sdk.tracks.getBulkTracks({
id: ids.map((id) => Id.parse(id)),
userId: OptionalId.parse(currentUserId)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const getUsersBatcher = memoize(
fetcher: async (ids: ID[]): Promise<UserMetadata[]> => {
const { sdk, currentUserId } = context
if (!ids.length) return []
const { data } = await sdk.full.users.getBulkUsers({
const { data } = await sdk.users.getBulkUsers({
id: ids.map((id) => Id.parse(id)),
userId: OptionalId.parse(currentUserId)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ export const getCollectionByPermalinkQueryFn = async (
sdk: any
) => {
const { handle, slug } = playlistPermalinkToHandleAndSlug(permalink)
const { data = [] } = await sdk.full.playlists.getPlaylistByHandleAndSlug({
const playlistRes = await sdk.playlists.getPlaylistByHandleAndSlug({
handle,
slug,
userId: OptionalId.parse(currentUserId)
})

const collection = userCollectionMetadataFromSDK(data[0])
const playlist = playlistRes?.data?.[0]
const collection = playlist ? userCollectionMetadataFromSDK(playlist) : null

if (collection) {
// Prime related entities
Expand Down
Loading
Loading