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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .changeset/sdk-error-handling-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
'@audius/sdk': patch
---

Fix several error-handling bugs:

- Uploads now reject when transcode/resize polling fails, instead of never settling, and aborting an upload stops status polling right away.
- The storage node selector no longer raises an unhandled promise rejection when the node list fetch fails, and uses the refreshed node list for selection.
- The request signature middleware no longer attaches a previously cached signature after the wallet is gone (e.g. after logout) or its address changes and signing fails.
- `SolanaRelayWalletAdapter.connect()` resets `connecting` when fetching the fee payer fails.
- `SolanaRelay.relay()` rethrows the original response error when the error body isn't JSON.
- `SolanaClient.buildTransaction()` rounds the percentile-based priority fee, which previously threw on fractional values.
- Chats: a failed public key fetch is no longer cached forever, and errors handling websocket events are logged instead of becoming unhandled rejections.
20 changes: 0 additions & 20 deletions packages/common/src/adapters/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,6 @@ function normalizeActivityItem(
)
}

export const activityFromSDK = (input: Activity) => {
const { timestamp, itemType: item_type, item } = input
if (item_type === ActivityItemTypeEnum.Track) {
const normalized = normalizeActivityItem(item as object, item_type)
return {
timestamp,
item_type,
item: userTrackMetadataFromSDK(normalized as Track)
}
} else if (item_type === ActivityItemTypeEnum.Playlist) {
const normalized = normalizeActivityItem(item as object, item_type)
return {
timestamp,
item_type,
item: userCollectionMetadataFromSDK(normalized as Playlist)
}
}
return undefined
}

export const trackActivityFromSDK = (input: Activity) => {
const { timestamp, itemType: item_type, item } = input
if (item_type === ActivityItemTypeEnum.Track) {
Expand Down
43 changes: 0 additions & 43 deletions packages/common/src/adapters/coin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ export const coinFromSdk = (input: CoinSDK | undefined): Coin | undefined => {
}
}

/**
* Converts a list of SDK `Coin` responses to CoinMetadata list
*/
export const coinMetadataListFromSDK = (input?: CoinSDK[]): CoinMetadata[] =>
input ? input.map(coinMetadataFromCoin).filter(removeNullable) : []

/**
* Converts a SDK `UserCoin` response to UserCoin, parsing ownerId from HashId string to number
*/
Expand Down Expand Up @@ -123,40 +117,3 @@ export const coinListFromSDK = (input?: CoinSDK[]): Coin[] =>
*/
export const userCoinListFromSDK = (input?: UserCoinSdk[]): UserCoin[] =>
input ? input.map(userCoinFromSdk).filter(removeNullable) : []

/**
* Creates a map of coins keyed by ticker symbol
*/
export const coinMapFromSDK = (
input?: CoinSDK[]
): Record<string, CoinMetadata> => {
const coinMap: Record<string, CoinMetadata> = {}

if (input) {
input.forEach((coin) => {
const coinMetadata = coinMetadataFromCoin(coin)
if (coinMetadata.ticker) {
coinMap[coinMetadata.ticker] = coinMetadata
}
})
}

return coinMap
}

/**
* Gets all token symbols from a list of coins
*/
export const getTokenSymbolsFromCoins = (coins: CoinMetadata[]): string[] =>
coins.map((coin) => coin.ticker || '').filter(Boolean)

/**
* Gets token mints by symbol from a list of coins
*/
export const getTokenMintsBySymbolsFromCoins = (
coins: CoinMetadata[],
symbols: string[]
): string[] =>
coins
.filter((coin) => coin.ticker && symbols.includes(coin.ticker))
.map((coin) => coin.mint)
12 changes: 4 additions & 8 deletions packages/common/src/adapters/notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,7 @@ export const notificationFromSDK = (
const data = action.data
entityId = HashId.parse(data.entityId)
commentId = OptionalHashId.parse(data.commentId)
// @ts-ignore
entityType = data.type
entityType = data.type as Entity
return HashId.parse(data.commentUserId)
})
.filter(removeNullable)
Expand Down Expand Up @@ -523,8 +522,7 @@ export const notificationFromSDK = (
entityId = HashId.parse(data.entityId)
entityUserId = HashId.parse(data.entityUserId)
commentId = OptionalHashId.parse(data.commentId)
// @ts-ignore
entityType = data.type
entityType = data.type as Entity
return HashId.parse(data.commentUserId)
})
.filter(removeNullable)
Expand All @@ -551,8 +549,7 @@ export const notificationFromSDK = (
entityId = HashId.parse(data.entityId)
entityUserId = HashId.parse(data.entityUserId)
commentId = OptionalHashId.parse(data.commentId)
// @ts-ignore
entityType = data.type
entityType = data.type as Entity
return HashId.parse(data.commentUserId)
})
.filter(removeNullable)
Expand All @@ -577,8 +574,7 @@ export const notificationFromSDK = (
entityId = HashId.parse(data.entityId)
entityUserId = HashId.parse(data.entityUserId)
commentId = OptionalHashId.parse(data.commentId)
// @ts-ignore
entityType = data.type
entityType = data.type as Entity
return HashId.parse(data.reacterUserId)
})
.filter(removeNullable)
Expand Down
12 changes: 0 additions & 12 deletions packages/common/src/adapters/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,3 @@ export const searchResultsFromSDK = (
saved_albums
}
}

export const AUTOCOMPLETE_TOTAL_RESULTS = 3

export const limitAutocompleteResults = (
results: SearchResults,
maxResults: number = AUTOCOMPLETE_TOTAL_RESULTS
): SearchResults => {
return Object.keys(results).reduce((acc, key) => {
acc[key] = results[key].slice(0, Math.min(maxResults, results[key].length))
return acc
}, {} as SearchResults)
}
1 change: 0 additions & 1 deletion packages/common/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export * from './tan-query/purchases/useSalesAggregate'

// Reactions
export * from './tan-query/reactions/types'
export * from './tan-query/reactions/utils'

// Remixes
export * from './tan-query/remixes/useRemixesLineup'
Expand Down
7 changes: 0 additions & 7 deletions packages/common/src/api/tan-query/coins/useCoinPair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,3 @@ export const useCoinPair = (
data: queryResult.data || createFallbackPair()
}
}

// Hook for getting default AUDIO/USDC pair
export const useDefaultTokenPair = (
options?: Partial<ReturnType<typeof getTokenPairOptions>>
) => {
return useCoinPair({ baseSymbol: 'AUDIO', quoteSymbol: 'USDC' }, options)
}
4 changes: 2 additions & 2 deletions packages/common/src/api/tan-query/coins/useFanClubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ export const useFanClubs = <TData = Coin[]>(
// Otherwise, return the next offset
return allPages.length * pageSize
},
enabled: options?.enabled !== false,
select: options?.select ?? ((data) => data.pages.flat() as TData),
...options
...options,
enabled: options?.enabled !== false
})
}

Expand Down
40 changes: 5 additions & 35 deletions packages/common/src/api/tan-query/coins/useUpdateFanClub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'

import { Coin } from '~/adapters/coin'
import { useCurrentUserId } from '~/api'
import { useQueryContext } from '~/api/tan-query/utils'
import { uploadBackdropImage, useQueryContext } from '~/api/tan-query/utils'

import { QUERY_KEYS } from '../queryKeys'

Expand Down Expand Up @@ -41,29 +41,10 @@ export const useUpdateFanClub = () => {
let bannerImageUrl: string | undefined

if (updateCoinRequest.bannerImageFile) {
const uploadResponse = await sdk.services.storage
.uploadFile({
file: updateCoinRequest.bannerImageFile,
metadata: {
template: 'img_backdrop'
}
})
.start()
const cid = getBannerImageUrl(uploadResponse.results)
if (!cid) {
throw new Error('Failed to process banner image upload')
}

// Convert CID to content node URL (same pattern as logo_uri from relay service)
const contentNodeEndpoint = await (
sdk.services.storage as any
).storageNodeSelector?.getSelectedNode()

if (!contentNodeEndpoint) {
throw new Error('No content node available')
}

bannerImageUrl = `${contentNodeEndpoint}/content/${cid}`
bannerImageUrl = await uploadBackdropImage(
sdk,
updateCoinRequest.bannerImageFile
)
} else if (updateCoinRequest.removeBanner) {
bannerImageUrl = ''
}
Expand Down Expand Up @@ -125,14 +106,3 @@ export const useUpdateFanClub = () => {
}
})
}

const getBannerImageUrl = (results: Record<string, string> = {}) => {
const prioritizedSizes = ['2000x', '1500x', '1280x', '1000x', '640x']
for (const size of prioritizedSizes) {
if (results[size]) {
return results[size]
}
}
const firstResult = Object.values(results)[0]
return firstResult
}
4 changes: 2 additions & 2 deletions packages/common/src/api/tan-query/coins/useWalletCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const useWalletCoins = <TResult = UserCoin[]>(
}
return []
},
enabled: options?.enabled !== false && !!params.walletAddress,
...options
...options,
enabled: options?.enabled !== false && !!params.walletAddress
})
}
Loading