diff --git a/packages/common/src/services/audius-backend/AudiusBackend.ts b/packages/common/src/services/audius-backend/AudiusBackend.ts index 3e322cbdb14..e150b1ed9fc 100644 --- a/packages/common/src/services/audius-backend/AudiusBackend.ts +++ b/packages/common/src/services/audius-backend/AudiusBackend.ts @@ -35,7 +35,6 @@ import { CoverPhotoSizes, DefaultSizes, FailureReason, - FeedFilter, ID, Name, PlaylistTrackId, @@ -44,8 +43,7 @@ import { Track, TrackMetadata, User, - UserMetadata, - UserTrack + UserMetadata } from '../../models' import { AnalyticsEvent } from '../../models/Analytics' import { ReportToSentryArgs } from '../../models/ErrorReporting' @@ -847,16 +845,6 @@ export const audiusBackend = ({ return audiusLibs.creatorNode.setEndpoint(endpoint) } - async function isCreatorNodeSyncing(endpoint: string) { - try { - const { isBehind, isConfigured } = - await audiusLibs.creatorNode.getSyncStatus(endpoint) - return isBehind && isConfigured - } catch (e) { - return true - } - } - async function listCreatorNodes() { return audiusLibs.ServiceProvider.listCreatorNodes() } @@ -878,11 +866,12 @@ export const audiusBackend = ({ async function getAccount() { await waitForLibsInit() try { + // TODO: Non-v1 const account = audiusLibs.Account.getCurrentUser() if (!account) return null try { - const body = await getCreatorSocialHandle(account.handle) + const body = await getSocialHandles(account.handle) account.twitter_handle = body.twitterHandle || null account.instagram_handle = body.instagramHandle || null account.tiktok_handle = body.tikTokHandle || null @@ -911,178 +900,7 @@ export const audiusBackend = ({ } } - async function getAllTracks({ - offset, - limit, - idsArray, - withUsers = true, - filterDeletes = false - }: { - offset: number - limit: number - idsArray: ID[] - withUsers?: boolean - filterDeletes?: boolean - }) { - try { - const tracks = await withEagerOption( - { - normal: (libs) => libs.Track.getTracks, - eager: DiscoveryAPI.getTracks - }, - limit, - offset, - idsArray, - null, // targetUserId - null, // sort - null, // minBlockNumber - filterDeletes, // filterDeleted - withUsers // withUsers - ) - return tracks || [] - } catch (e) { - console.error(e) - return [] - } - } - - /** - * @typedef {Object} getTracksIdentifier - * @property {string} handle - * @property {number} id - * @property {string} url_title - */ - - /** - * gets all tracks matching identifiers, including unlisted. - * - * @param {getTracksIdentifier[]} identifiers - * @returns {(Array)} track - */ - async function getTracksIncludingUnlisted( - identifiers: { id: ID }[], - withUsers = true - ) { - try { - const tracks = await withEagerOption( - { - normal: (libs) => libs.Track.getTracksIncludingUnlisted, - eager: DiscoveryAPI.getTracksIncludingUnlisted - }, - identifiers, - withUsers - ) - - return tracks - } catch (e) { - console.error(e) - return [] - } - } - - async function getArtistTracks({ - offset, - limit, - userId, - sort = null, - filterDeleted = null, - withUsers = true - }: Omit< - DiscoveryAPIParams, - 'sort' | 'filterDeleted' - > & { - sort: Nullable - filterDeleted: Nullable - }) { - try { - const tracks = await withEagerOption( - { - normal: (libs) => libs.Track.getTracks, - eager: DiscoveryAPI.getTracks - }, - limit, - offset, - null, - userId, - sort, - null, - filterDeleted, - withUsers - ) - return tracks || [] - } catch (e) { - console.error(e) - return [] - } - } - - async function getSocialFeed({ - filter, - offset, - limit, - withUsers = true, - tracksOnly = false - }: DiscoveryAPIParams) { - const filterMap = { - [FeedFilter.ALL]: 'all', - [FeedFilter.ORIGINAL]: 'original', - [FeedFilter.REPOST]: 'repost' - } - - let feedItems: Array = [] - try { - feedItems = await withEagerOption( - { - normal: (libs) => libs.User.getSocialFeed, - eager: DiscoveryAPI.getSocialFeed, - requiresUser: true - }, - filterMap[filter as FeedFilter], - limit, - offset, - withUsers, - tracksOnly - ) - // It's possible all the requests timed out, - // we need to not return a null object here. - if (!feedItems) return [] - } catch (err) { - console.error(err) - } - return feedItems.map((item) => { - if ('playlist_id' in item) { - return getCollectionImages(item) - } - return item - }) - } - - async function getUserFeed({ - offset, - limit, - userId, - withUsers = true - }: DiscoveryAPIParams & { - userId: string - }) { - try { - const tracks = await withEagerOption( - { - normal: (libs) => libs.User.getUserRepostFeed, - eager: DiscoveryAPI.getUserRepostFeed - }, - userId, - limit, - offset, - withUsers - ) - return tracks - } catch (e) { - console.error(e) - return [] - } - } - + // TODO(C-2719) async function searchTags({ query, userTagCount, @@ -1137,7 +955,7 @@ export const audiusBackend = ({ } } - // userId, start, end + // TODO(C-2719) async function getUserListenCountsMonthly( currentUserId: number, startTime: string, @@ -1375,6 +1193,7 @@ export const audiusBackend = ({ } } + // TODO(C-2719) async function getCreators(ids: ID[]) { try { if (ids.length === 0) return [] @@ -1400,7 +1219,7 @@ export const audiusBackend = ({ } } - async function getCreatorSocialHandle(handle: string) { + async function getSocialHandles(handle: string) { try { const res = await fetch( `${identityServiceUrl}/social_handles?handle=${handle}` @@ -1418,6 +1237,7 @@ export const audiusBackend = ({ * @param user The user metadata which contains the CID for the metadata multihash * @returns Object The associated wallets mapping of address to nested signature */ + // TODO(C-2719) async function fetchUserAssociatedEthWallets(user: User) { const cid = user?.metadata_multihash ?? null if (cid) { @@ -1434,6 +1254,7 @@ export const audiusBackend = ({ * @param user The user metadata which contains the CID for the metadata multihash * @returns Object The associated wallets mapping of address to nested signature */ + // TODO(C-2719) async function fetchUserAssociatedSolWallets(user: User) { const cid = user?.metadata_multihash ?? null if (cid) { @@ -1450,6 +1271,7 @@ export const audiusBackend = ({ * @param user The user metadata which contains the CID for the metadata multihash * @returns Object The associated wallets mapping of address to nested signature */ + // TODO(C-2719) async function fetchUserAssociatedWallets(user: User) { const cid = user?.metadata_multihash ?? null if (cid) { @@ -1577,6 +1399,7 @@ export const audiusBackend = ({ } } + // TODO(C-2719) async function getFolloweeFollows(userId: ID, limit = 100, offset = 0) { let followers = [] try { @@ -1599,6 +1422,7 @@ export const audiusBackend = ({ return followers } + // TODO(C-2719) async function getPlaylists( userId: Nullable, playlistIds: Nullable, @@ -1755,6 +1579,7 @@ export const audiusBackend = ({ } } + // TODO(C-2719) async function validateTracksInPlaylist(playlistId: ID) { try { const { isValid, invalidTrackIds } = @@ -1828,40 +1653,7 @@ export const audiusBackend = ({ } } - async function getSavedPlaylists(limit = 100, offset = 0) { - try { - const saves = await withEagerOption( - { - normal: (libs) => libs.Playlist.getSavedPlaylists, - eager: DiscoveryAPI.getSavedPlaylists - }, - limit, - offset - ) - return saves.map((save: { save_item_id: ID }) => save.save_item_id) - } catch (err) { - console.log(getErrorMessage(err)) - return [] - } - } - - async function getSavedAlbums(limit = 100, offset = 0) { - try { - const saves = await withEagerOption( - { - normal: (libs) => libs.Playlist.getSavedAlbums, - eager: DiscoveryAPI.getSavedAlbums - }, - limit, - offset - ) - return saves.map((save: { save_item_id: ID }) => save.save_item_id) - } catch (err) { - console.log(getErrorMessage(err)) - return [] - } - } - + // TODO(C-2719) async function getSavedTracks(limit = 100, offset = 0) { try { return withEagerOption( @@ -2592,6 +2384,7 @@ export const audiusBackend = ({ return notification } + // TODO(C-2719) async function getDiscoveryNotifications({ timestamp, groupIdOffset, @@ -3074,6 +2867,7 @@ export const audiusBackend = ({ /** * Returns whether the current user is subscribed to userId. */ + // TODO(C-2719) async function getUserSubscribed(userId: ID) { await waitForLibsInit() const account = audiusLibs.Account.getCurrentUser() @@ -3252,38 +3046,6 @@ export const audiusBackend = ({ } } - /** - * Make the claim for the distribution - * NOTE: if the claim was already made, the response will 500 and error - * @returns {Promise} didMakeClaim - */ - async function makeDistributionClaim() { - await waitForLibsInit() - const wallet = audiusLibs.web3Manager.getWalletAddress() - if (!wallet) return null - - await audiusLibs.Account.makeDistributionClaim() - return true - } - - /** - * Make a request to check if the user has already claimed - * @returns {Promise} doesHaveClaim - */ - async function getHasClaimed() { - await waitForLibsInit() - const wallet = audiusLibs.web3Manager.getWalletAddress() - if (!wallet) return - - try { - const hasClaimed = await audiusLibs.Account.getHasClaimed() - return hasClaimed - } catch (e) { - console.error(e) - return null - } - } - /** * Make a request to fetch the eth AUDIO balance of the the user * @params {bool} bustCache @@ -3666,8 +3428,6 @@ export const audiusBackend = ({ getAudioTransactionsCount, getAddressSolBalance, getAssociatedTokenAccountInfo, - getAllTracks, - getArtistTracks, getAudiusLibs, getAudiusLibsTyped, getBalance, @@ -3677,10 +3437,9 @@ export const audiusBackend = ({ getCollectionImages, getCreatorNodeIPFSGateways, getCreators, - getCreatorSocialHandle, + getSocialHandles, getEmailNotificationSettings, getFolloweeFollows, - getHasClaimed, getImageUrl, getLatestTxReceipt, getNotifications, @@ -3689,16 +3448,11 @@ export const audiusBackend = ({ getPushNotificationSettings, getRandomFeePayer, getSafariBrowserPushEnabled, - getSavedAlbums, - getSavedPlaylists, getSavedTracks, getSelectableCreatorNodes, getSignature, - getSocialFeed, getTrackImages, - getTracksIncludingUnlisted, getUserEmail, - getUserFeed, getUserImages, getUserListenCountsMonthly, getUserSubscribed, @@ -3706,10 +3460,8 @@ export const audiusBackend = ({ getWeb3, handleInUse, identityServiceUrl, - isCreatorNodeSyncing, legacyUserNodeUrl, listCreatorNodes, - makeDistributionClaim, markAllNotificationAsViewed, orderPlaylist, publishPlaylist, diff --git a/packages/common/src/services/explore/Explore.ts b/packages/common/src/services/explore/Explore.ts index ae647f40398..82c14df7012 100644 --- a/packages/common/src/services/explore/Explore.ts +++ b/packages/common/src/services/explore/Explore.ts @@ -3,7 +3,8 @@ import { FeedFilter, ID, UserCollectionMetadata, - UserTrack + UserTrack, + UserTrackMetadata } from '../../models' import { encodeHashId, removeNullable } from '../../utils' import { @@ -24,10 +25,6 @@ type TopUserListen = { trackId: number } -type UserListens = { - [key: number]: number -} - type ExploreConfig = { audiusBackendInstance: AudiusBackend apiClient: AudiusAPIClient @@ -63,27 +60,7 @@ export class Explore { } } - async getUserListens(trackIds: ID[]): Promise { - try { - const { data, signature } = await this.audiusBackendInstance.signData() - const idQuery = trackIds.map((id) => `&trackIdList=${id}`).join('') - return fetch( - `${this.audiusBackendInstance.identityServiceUrl}/users/listens?${idQuery}`, - { - headers: { - [AuthHeaders.Message]: data, - [AuthHeaders.Signature]: signature - } - } - ) - .then((res) => res.json()) - .then((res) => res.listenMap) - } catch (e) { - console.error(e) - return {} - } - } - + // TODO(C-2719) async getTopFolloweeTracksFromWindow( userId: ID, window: string, @@ -105,22 +82,30 @@ export class Explore { } } - async getFeedNotListenedTo(limit = 25) { + async getFeedNotListenedTo(currentUserId: ID, limit = 25) { try { - const lineupItems = await this.audiusBackendInstance.getSocialFeed({ - filter: FeedFilter.ORIGINAL, + const lineupItems = (await this.apiClient.getSocialFeed({ offset: 0, - limit: 100, - withUsers: true, - tracksOnly: true - }) + limit, + with_users: true, + filter: FeedFilter.ORIGINAL, + tracks_only: true, + current_user_id: currentUserId + })) as UserTrackMetadata[] | null + if (!lineupItems) return [] const tracks = lineupItems.filter( (lineupItem): lineupItem is UserTrack => 'track_id' in lineupItem ) - const trackIds = tracks.map((track) => track.track_id) - const listens: any = await this.getUserListens(trackIds) + // Imperfect solution. Ideally we use an endpoint that gives us true/false + // if a user has listened to a passed in array of tracks. + const history = await this.apiClient.getUserTrackHistory({ + currentUserId, + userId: currentUserId, + limit: 50 + }) + const listens = history.map((item) => item.track?.track_id) const notListenedToTracks = tracks.filter( (track) => !listens[track.track_id] @@ -146,6 +131,7 @@ export class Explore { } } + // TODO(C-2719) async getTopFolloweeSaves(limit = 25) { try { const libs = await this.audiusBackendInstance.getAudiusLibs() @@ -158,6 +144,7 @@ export class Explore { } } + // TODO(C-2719) async getMostLovedTracks(userId: ID, limit = 25) { try { const encodedUserId = encodeHashId(userId) @@ -175,6 +162,7 @@ export class Explore { } } + // TODO(C-2719) async getFeelingLuckyTracks(userId: ID | null, limit = 25) { try { let tracks: APITrack[] @@ -200,18 +188,8 @@ export class Explore { } } - async getLatestTrackID(): Promise { - try { - const libs = await this.audiusBackendInstance.getAudiusLibs() - const latestTrackID = await libs.discoveryProvider.getLatest('track') - return latestTrackID - } catch (e) { - console.error(e) - return 0 - } - } - /** PLAYLIST ENDPOINTS */ + // TODO(C-2719) async getTopCollections( type?: 'playlist' | 'album', followeesOnly?: boolean, diff --git a/packages/common/src/services/wallet-client/WalletClient.ts b/packages/common/src/services/wallet-client/WalletClient.ts index b6d620f8648..80570f5a1d7 100644 --- a/packages/common/src/services/wallet-client/WalletClient.ts +++ b/packages/common/src/services/wallet-client/WalletClient.ts @@ -155,15 +155,6 @@ export class WalletClient { } } - async claim(): Promise { - try { - await this.audiusBackendInstance.makeDistributionClaim() - } catch (err) { - console.error(err) - throw err - } - } - async sendTokens(address: WalletAddress, amount: BNWei): Promise { if (amount.lt(MIN_TRANSFERRABLE_WEI)) { throw new Error('Insufficient Audio to transfer') diff --git a/packages/web/src/common/store/cache/tracks/sagas.js b/packages/web/src/common/store/cache/tracks/sagas.js index b7e159f00df..9989b3d214e 100644 --- a/packages/web/src/common/store/cache/tracks/sagas.js +++ b/packages/web/src/common/store/cache/tracks/sagas.js @@ -249,10 +249,7 @@ function* deleteTrackAsync(action) { const handle = yield select(getUserHandle) // Before deleting, check if the track is set as the artist pick & delete if so - const socials = yield call( - audiusBackendInstance.getCreatorSocialHandle, - handle - ) + const socials = yield call(audiusBackendInstance.getSocialHandles, handle) if (socials.pinnedTrackId === action.trackId) { yield put( cacheActions.update(Kind.USERS, [ diff --git a/packages/web/src/common/store/cache/users/sagas.js b/packages/web/src/common/store/cache/users/sagas.js index c90fe8ada4f..2336078e745 100644 --- a/packages/web/src/common/store/cache/users/sagas.js +++ b/packages/web/src/common/store/cache/users/sagas.js @@ -331,7 +331,7 @@ export function* fetchUserSocials({ handle }) { } user = yield call(waitForValue, getUser, { handle }) const socials = yield call( - audiusBackendInstance.getCreatorSocialHandle, + audiusBackendInstance.getSocialHandles, user.handle ) diff --git a/packages/web/src/common/store/pages/token-dashboard/getAccountMetadataCID.ts b/packages/web/src/common/store/pages/token-dashboard/getAccountMetadataCID.ts index d7be672f886..71d05f4fa25 100644 --- a/packages/web/src/common/store/pages/token-dashboard/getAccountMetadataCID.ts +++ b/packages/web/src/common/store/pages/token-dashboard/getAccountMetadataCID.ts @@ -7,11 +7,14 @@ const { getUserId } = accountSelectors export function* getAccountMetadataCID() { yield* waitForRead() - const audiusBackendInstance = yield* getContext('audiusBackendInstance') + const apiClient = yield* getContext('apiClient') const accountUserId = yield* select(getUserId) if (!accountUserId) return null - const users = yield* call(audiusBackendInstance.getCreators, [accountUserId]) + const users = yield* call([apiClient, apiClient.getUser], { + userId: accountUserId, + currentUserId: accountUserId + }) if (users.length !== 1) return null return users[0].metadata_multihash } diff --git a/packages/web/src/common/store/smart-collection/sagas.ts b/packages/web/src/common/store/smart-collection/sagas.ts index 9d7c6bf06a7..05835da4e6d 100644 --- a/packages/web/src/common/store/smart-collection/sagas.ts +++ b/packages/web/src/common/store/smart-collection/sagas.ts @@ -108,7 +108,11 @@ function* fetchBestNewReleases() { function* fetchUnderTheRadar() { const explore = yield* getContext('explore') - const tracks = yield* call([explore, 'getFeedNotListenedTo']) + const currentUserId = yield* select(getUserId) + if (currentUserId == null) { + return + } + const tracks = yield* call([explore, 'getFeedNotListenedTo'], currentUserId) const trackIds = tracks .filter((track: UserTrack) => !track.user.is_deactivated) diff --git a/packages/web/src/components/notification/Notification/utils.ts b/packages/web/src/components/notification/Notification/utils.ts index a548fd2338d..7c67e551d7b 100644 --- a/packages/web/src/components/notification/Notification/utils.ts +++ b/packages/web/src/components/notification/Notification/utils.ts @@ -41,7 +41,7 @@ export const getRankSuffix = (rank: number) => { } export const getTwitterHandleByUserHandle = async (userHandle: string) => { - const { twitterHandle } = await audiusBackendInstance.getCreatorSocialHandle( + const { twitterHandle } = await audiusBackendInstance.getSocialHandles( userHandle ) return twitterHandle || '' diff --git a/packages/web/src/pages/upload-page/components/ShareBanner.tsx b/packages/web/src/pages/upload-page/components/ShareBanner.tsx index ddbd8cdd9cf..c8cccc1c613 100644 --- a/packages/web/src/pages/upload-page/components/ShareBanner.tsx +++ b/packages/web/src/pages/upload-page/components/ShareBanner.tsx @@ -61,7 +61,7 @@ const getContinuePage = (uploadType: UploadType) => { } const getTwitterHandleByUserHandle = async (userHandle: string) => { - const { twitterHandle } = await audiusBackendInstance.getCreatorSocialHandle( + const { twitterHandle } = await audiusBackendInstance.getSocialHandles( userHandle ) return twitterHandle || '' diff --git a/packages/web/src/store/errors/reportToSentry.ts b/packages/web/src/store/errors/reportToSentry.ts index 56d5b484b76..eeded03ae91 100644 --- a/packages/web/src/store/errors/reportToSentry.ts +++ b/packages/web/src/store/errors/reportToSentry.ts @@ -17,6 +17,7 @@ export const reportToSentry = async ({ error, name }: ReportToSentryArgs) => { + console.debug(error, level) try { Sentry.withScope((scope) => { if (level) {