Skip to content

Commit

Permalink
[C-2719] Clean up and document non v1 usage (#3520)
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondjacobson authored Jun 7, 2023
1 parent 2cf5bb7 commit e2896fe
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 330 deletions.
282 changes: 17 additions & 265 deletions packages/common/src/services/audius-backend/AudiusBackend.ts

Large diffs are not rendered by default.

70 changes: 24 additions & 46 deletions packages/common/src/services/explore/Explore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
FeedFilter,
ID,
UserCollectionMetadata,
UserTrack
UserTrack,
UserTrackMetadata
} from '../../models'
import { encodeHashId, removeNullable } from '../../utils'
import {
Expand All @@ -24,10 +25,6 @@ type TopUserListen = {
trackId: number
}

type UserListens = {
[key: number]: number
}

type ExploreConfig = {
audiusBackendInstance: AudiusBackend
apiClient: AudiusAPIClient
Expand Down Expand Up @@ -63,27 +60,7 @@ export class Explore {
}
}

async getUserListens(trackIds: ID[]): Promise<UserListens> {
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,
Expand All @@ -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]
Expand All @@ -146,6 +131,7 @@ export class Explore {
}
}

// TODO(C-2719)
async getTopFolloweeSaves(limit = 25) {
try {
const libs = await this.audiusBackendInstance.getAudiusLibs()
Expand All @@ -158,6 +144,7 @@ export class Explore {
}
}

// TODO(C-2719)
async getMostLovedTracks(userId: ID, limit = 25) {
try {
const encodedUserId = encodeHashId(userId)
Expand All @@ -175,6 +162,7 @@ export class Explore {
}
}

// TODO(C-2719)
async getFeelingLuckyTracks(userId: ID | null, limit = 25) {
try {
let tracks: APITrack[]
Expand All @@ -200,18 +188,8 @@ export class Explore {
}
}

async getLatestTrackID(): Promise<number> {
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,
Expand Down
9 changes: 0 additions & 9 deletions packages/common/src/services/wallet-client/WalletClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,6 @@ export class WalletClient {
}
}

async claim(): Promise<void> {
try {
await this.audiusBackendInstance.makeDistributionClaim()
} catch (err) {
console.error(err)
throw err
}
}

async sendTokens(address: WalletAddress, amount: BNWei): Promise<void> {
if (amount.lt(MIN_TRANSFERRABLE_WEI)) {
throw new Error('Insufficient Audio to transfer')
Expand Down
5 changes: 1 addition & 4 deletions packages/web/src/common/store/cache/tracks/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, [
Expand Down
2 changes: 1 addition & 1 deletion packages/web/src/common/store/cache/users/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export function* fetchUserSocials({ handle }) {
}
user = yield call(waitForValue, getUser, { handle })
const socials = yield call(
audiusBackendInstance.getCreatorSocialHandle,
audiusBackendInstance.getSocialHandles,
user.handle
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion packages/web/src/common/store/smart-collection/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ''
Expand Down
1 change: 1 addition & 0 deletions packages/web/src/store/errors/reportToSentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const reportToSentry = async ({
error,
name
}: ReportToSentryArgs) => {
console.debug(error, level)
try {
Sentry.withScope((scope) => {
if (level) {
Expand Down

0 comments on commit e2896fe

Please sign in to comment.