Skip to content
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
15 changes: 10 additions & 5 deletions packages/common/src/adapters/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ export const coinFromSdk = (input: CoinSDK | undefined): Coin | undefined => {
// Birdeye data may not be available right after launch.
// Fall back to dynamic bonding curve data if so.
const defaultSupply = 1e9
const dbc = input.dynamicBondingCurve
if (!dbc) {
return undefined
}

const { isMigrated, priceUSD, address } = input.dynamicBondingCurve
const { isMigrated, priceUSD, address } = dbc
const hasBirdeyeSupply =
input.totalSupply !== undefined && input.totalSupply > 0
const hasBirdeyePrice = input.price !== undefined && input.price > 0
Expand All @@ -67,14 +71,15 @@ 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
? priceUSD
: input.price
? (priceUSD ?? 0)
: (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
? displayPrice *
(hasBirdeyeSupply ? (input.totalSupply ?? 0) : defaultSupply)
: (input.marketCap ?? 0)

const { ownerId: _ignored, ...rest } = input
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/adapters/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const playlistMetadataForUpdateWithSDK = (
? input.playlist_contents.track_ids.map((t) => ({
timestamp: t.time,
trackId: Id.parse(t.track),
metadataTimestamp: t.metadata_time
metadataTimestamp: t.metadata_time ?? 0
}))
: undefined,
playlistName: input.playlist_name ?? '',
Expand Down
6 changes: 3 additions & 3 deletions packages/common/src/adapters/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Genre,
Mood,
type NativeFile,
type TrackMetadata,
type UpdateTrackRequestBody,
HashId,
Id,
OptionalHashId,
Expand Down Expand Up @@ -260,7 +260,7 @@ const DEFAULT_GENRE = Genre.Electronic

export const trackMetadataForUploadToSdk = (
input: TrackMetadataForUpload
): TrackMetadata => {
): UpdateTrackRequestBody => {
const sdkGenre = toSdkGenre(input.genre)
const genre = sdkGenre ?? DEFAULT_GENRE
return {
Expand Down Expand Up @@ -348,7 +348,7 @@ export const trackMetadataForUploadToSdk = (
camelcaseKeys(contributor)
)
: undefined
} as TrackMetadata
} as UpdateTrackRequestBody
}

export const fileToSdk = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const useUpdateArtistCoin = () => {
const response = await sdk.coins.updateCoin({
mint,
userId: Id.parse(currentUserId),
metadata: {
updateCoinRequest: {
description: updateCoinRequest.description,
link1: updateCoinRequest.links?.[0] ?? '',
link2: updateCoinRequest.links?.[1] ?? '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const useFavoritedTracks = (
queryKey: getFavoritedTracksQueryKey(userId),
queryFn: async () => {
const sdk = await audiusSdk()
const { data } = await sdk.users.getFavorites({
const { data } = await sdk.users.getUserFavorites({
id: Id.parse(userId)
})

Expand Down
10 changes: 6 additions & 4 deletions packages/common/src/api/tan-query/upload/usePublishCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ const getPublishCollectionOptions = (context: PublishCollectionContext) =>
params.collectionMetadata
)
metadata.playlistContents = publishedTracks.map((t) => ({
timestamp: Date.now() / 1000,
trackId: Id.parse(t.trackId)
timestamp: Math.round(Date.now() / 1000),
trackId: Id.parse(t.trackId),
metadataTimestamp: Math.round(Date.now() / 1000)
}))
return await sdk.albums.createAlbum({
userId: Id.parse(userId),
Expand All @@ -122,8 +123,9 @@ const getPublishCollectionOptions = (context: PublishCollectionContext) =>
params.collectionMetadata
)
metadata.playlistContents = publishedTracks.map((t) => ({
timestamp: Date.now() / 1000,
trackId: Id.parse(t.trackId)
timestamp: Math.round(Date.now() / 1000),
trackId: Id.parse(t.trackId),
metadataTimestamp: Math.round(Date.now() / 1000)
}))
return await sdk.playlists.createPlaylist({
userId: Id.parse(userId),
Expand Down
15 changes: 9 additions & 6 deletions packages/common/src/hooks/chats/useAudiusLinkResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ export const useAudiusLinkResolver = ({
data: res.data[0]
}
} else if (instanceOfUserResponse(res)) {
const human = formatUserName({ user: res.data })
linkToHuman[match] = human
humanToData[human] = {
link: match,
type: 'user',
data: res.data
const user = Array.isArray(res.data) ? res.data[0] : res.data
if (user) {
const human = formatUserName({ user })
linkToHuman[match] = human
humanToData[human] = {
link: match,
type: 'user',
data: user
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions packages/common/src/utils/coinMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,21 @@ export const createCoinMetrics = (coin: Coin): MetricData[] => {
createMetric({
value: formatCurrencyWithSubscript(coin.displayPrice),
label: messages.pricePerCoin,
changePercent: coin.priceChange24hPercent,
changePercent:
(coin as Coin & { priceChange24hPercent?: number })
.priceChange24hPercent ?? undefined,
rawValue: formatCurrency(coin.displayPrice)
}),
createMetric({
value: `$${formatCount(coin.displayMarketCap, 2)}`,
value: `$${formatCount(coin.displayMarketCap ?? 0, 2)}`,
label: messages.marketCap
}),
createMetric({
value: `$${formatCount(coin.totalVolumeUSD, 2)}`,
value: `$${formatCount(coin.totalVolumeUSD ?? 0, 2)}`,
label: messages.totalVolume
}),
createMetric({
value: formatCount(coin.holder),
value: formatCount(coin.holder ?? 0),
label: messages.uniqueHolders
}),
createMetric({
Expand Down
13 changes: 8 additions & 5 deletions packages/mobile/src/components/core/UserGeneratedText.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,14 @@ const Link = ({
params: { id: HashId.parse(res.data[0].id) }
})
} else if (instanceOfUserResponse(res)) {
setUnfurledContent(formatUserName({ user: res.data }))
setTo({
screen: 'Profile',
params: { id: HashId.parse(res.data.id) }
})
const user = Array.isArray(res.data) ? res.data[0] : res.data
if (user) {
setUnfurledContent(formatUserName({ user }))
setTo({
screen: 'Profile',
params: { id: HashId.parse(user.id) }
})
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export const BuyScreen = ({
onAmountChange={handleOutputAmountChange}
availableBalance={0}
exchangeRate={currentExchangeRate}
tokenPrice={tokenPriceData?.price.toString() ?? null}
tokenPrice={tokenPriceData?.price?.toString() ?? null}
isTokenPriceLoading={isTokenPriceLoading}
tokenPriceDecimalPlaces={decimalPlaces}
availableTokens={availableOutputTokens ?? artistCoins}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const ConvertScreen = ({
onAmountChange={handleOutputAmountChange}
availableBalance={0}
exchangeRate={currentExchangeRate}
tokenPrice={tokenPriceData?.price.toString() ?? null}
tokenPrice={tokenPriceData?.price?.toString() ?? null}
isTokenPriceLoading={isTokenPriceLoading}
tokenPriceDecimalPlaces={decimalPlaces}
availableTokens={filteredAvailableOutputTokens}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ export const useBuySellFlow = ({
swapTokens.outputTokenInfo?.address
)
const pricePerBaseToken = useMemo(() => {
return outputCoin?.price
? outputCoin?.price
: (outputCoin?.dynamicBondingCurve.priceUSD ?? 0)
return outputCoin?.price !== undefined && outputCoin.price !== 0
? outputCoin.price
: (outputCoin?.dynamicBondingCurve?.priceUSD ?? 0)
}, [outputCoin])

const handleContinueClick = useCallback(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ function* syncFavoritesCollection() {
const sdk = yield* getSDK()
const offlineTrackMetadata = yield* select(getOfflineTrackMetadata)

const { data } = yield* call([sdk.users, sdk.users.getFavorites], {
const { data } = (yield* call([sdk.users, sdk.users.getUserFavorites], {
id: Id.parse(currentUserId)
})
})) as import('@audius/sdk').FavoritesResponse

const latestFavoritedTracks = transformAndCleanList(data, favoriteFromSDK)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function* downloadAllFavorites() {
// Add favorited tracks from api
const sdk = yield* getSDK()

const { data } = yield* call([sdk.users, sdk.users.getFavorites], {
const { data } = (yield* call([sdk.users, sdk.users.getUserFavorites], {
id: Id.parse(currentUserId)
})
})) as import('@audius/sdk').FavoritesResponse
const allFavoritedTracks = transformAndCleanList(data, favoriteFromSDK)

if (allFavoritedTracks) {
Expand Down
26 changes: 13 additions & 13 deletions packages/sdk/src/sdk/api/albums/AlbumsApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Storage } from '../../services/Storage'
import { StorageNodeSelector } from '../../services/StorageNodeSelector'
import { Configuration, Genre, Mood } from '../generated/default'
import { PlaylistsApi as GeneratedPlaylistsApi } from '../generated/default/apis/PlaylistsApi'
import type { PlaylistResponse } from '../generated/default/models/PlaylistResponse'
import { TrackUploadHelper } from '../tracks/TrackUploadHelper'

import { AlbumsApi } from './AlbumsApi'
Expand Down Expand Up @@ -89,21 +90,20 @@ vitest
} as any
})

const mockPlaylistResponse: PlaylistResponse = {
latestChainBlock: 0,
latestIndexedBlock: 0,
latestChainSlotPlays: 0,
latestIndexedSlotPlays: 0,
signature: '',
timestamp: '',
version: { service: 'api', version: '1.0' },
data: []
}

vitest
.spyOn(GeneratedPlaylistsApi.prototype, 'getPlaylist')
.mockImplementation(async () => {
return {
data: [
{
playlistName: 'test',
playlistContents: [
{ trackId: 'yyNwXq7', timestamp: 1 },
{ trackId: 'yyNwXq7', timestamp: 1 }
]
} as any
]
}
})
.mockImplementation(async () => mockPlaylistResponse)

describe('AlbumsApi', () => {
// TODO: Remove this setup in describe
Expand Down
Loading
Loading