-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
ab6657a
commit 7275047
Showing
99 changed files
with
1,354 additions
and
2,425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { full } from '@audius/sdk' | ||
|
||
import { Grant } from '~/models/Grant' | ||
import { decodeHashId } from '~/utils/hashIds' | ||
|
||
export const grantFromSDK = (input: full.Grant): Grant => { | ||
return { | ||
grantee_address: input.granteeAddress, | ||
user_id: decodeHashId(input.userId) ?? null, | ||
is_revoked: input.isRevoked, | ||
is_approved: input.isApproved, | ||
created_at: input.createdAt, | ||
updated_at: input.updatedAt | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { full } from '@audius/sdk' | ||
|
||
import { | ||
CoverPhotoSizesCids, | ||
ProfilePictureSizesCids, | ||
SquareSizes, | ||
WidthSizes | ||
} from '~/models/ImageSizes' | ||
|
||
export const coverPhotoSizesCIDsFromSDK = ( | ||
input: full.CoverPhoto | ||
): CoverPhotoSizesCids => { | ||
return [WidthSizes.SIZE_640, WidthSizes.SIZE_2000].reduce((out, size) => { | ||
out[size] = input[size] ?? null | ||
return out | ||
}, {}) | ||
} | ||
|
||
export const profilePictureSizesCIDsFromSDK = ( | ||
input: full.ProfilePicture | ||
): ProfilePictureSizesCids => { | ||
return [ | ||
SquareSizes.SIZE_1000_BY_1000, | ||
SquareSizes.SIZE_150_BY_150, | ||
SquareSizes.SIZE_480_BY_480 | ||
].reduce((out, size) => { | ||
out[size] = input[size] ?? null | ||
return out | ||
}, {}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './grant' | ||
export * from './imageSize' | ||
export * from './playlistLibrary' | ||
export * from './user' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { full } from '@audius/sdk' | ||
|
||
import { PlaylistLibrary, PlaylistLibraryItem } from '~/models/PlaylistLibrary' | ||
|
||
export const playlistLibraryFromSDK = ( | ||
input?: full.PlaylistLibrary | ||
): PlaylistLibrary | undefined => { | ||
if (!input) return undefined | ||
return { | ||
contents: input.contents as PlaylistLibraryItem[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import type { full } from '@audius/sdk' | ||
import { omit } from 'lodash' | ||
import snakecaseKeys from 'snakecase-keys' | ||
|
||
import { | ||
ManagedUserMetadata, | ||
UserManagerMetadata, | ||
UserMetadata | ||
} from '~/models/User' | ||
import { SolanaWalletAddress, StringWei } from '~/models/Wallet' | ||
import { decodeHashId } from '~/utils/hashIds' | ||
import { removeNullable } from '~/utils/typeUtils' | ||
|
||
import { grantFromSDK } from './grant' | ||
import { | ||
coverPhotoSizesCIDsFromSDK, | ||
profilePictureSizesCIDsFromSDK | ||
} from './imageSize' | ||
import { playlistLibraryFromSDK } from './playlistLibrary' | ||
|
||
/** Converts a SDK `full.UserFull` response to a UserMetadata. Note: Will _not_ include the "current user" fields as those aren't returned by the Users API */ | ||
export const userMetadataFromSDK = ( | ||
input: full.UserFull | ||
): UserMetadata | undefined => { | ||
const user = snakecaseKeys(input) | ||
const decodedUserId = decodeHashId(user.id) | ||
if (!decodedUserId) { | ||
return undefined | ||
} | ||
|
||
const newUser: UserMetadata = { | ||
// Fields from API that are omitted in this model | ||
...omit(user, ['id', 'cover_photo_legacy', 'profile_picture_legacy']), | ||
|
||
// Conversions | ||
artist_pick_track_id: user.artist_pick_track_id | ||
? decodeHashId(user.artist_pick_track_id) | ||
: null, | ||
|
||
// Nested Types | ||
playlist_library: playlistLibraryFromSDK(user.playlist_library) ?? null, | ||
cover_photo_cids: user.cover_photo_cids | ||
? coverPhotoSizesCIDsFromSDK(user.cover_photo_cids) | ||
: null, | ||
profile_picture_cids: user.profile_picture_cids | ||
? profilePictureSizesCIDsFromSDK(user.profile_picture_cids) | ||
: null, | ||
|
||
// Re-types | ||
balance: user.balance as StringWei, | ||
associated_wallets_balance: user.associated_wallets_balance as StringWei, | ||
total_balance: user.total_balance as StringWei, | ||
user_id: decodedUserId, | ||
spl_wallet: user.spl_wallet as SolanaWalletAddress, | ||
|
||
// Legacy Overrides | ||
cover_photo: user.cover_photo_legacy ?? null, | ||
profile_picture: user.profile_picture_legacy ?? null, | ||
|
||
// Required Nullable fields | ||
bio: user.bio ?? null, | ||
cover_photo_sizes: user.cover_photo_sizes ?? null, | ||
creator_node_endpoint: user.creator_node_endpoint ?? null, | ||
location: user.location ?? null, | ||
metadata_multihash: user.metadata_multihash ?? null, | ||
profile_picture_sizes: user.profile_picture_sizes ?? null | ||
} | ||
|
||
return newUser | ||
} | ||
|
||
export const userMetadataListFromSDK = (input?: full.UserFull[]) => | ||
input ? input.map((d) => userMetadataFromSDK(d)).filter(removeNullable) : [] | ||
|
||
export const managedUserFromSDK = ( | ||
input: full.ManagedUser | ||
): ManagedUserMetadata | undefined => { | ||
const user = userMetadataFromSDK(input.user) | ||
if (!user) { | ||
return undefined | ||
} | ||
return { | ||
user, | ||
grant: grantFromSDK(input.grant) | ||
} | ||
} | ||
|
||
export const managedUserListFromSDK = (input?: full.ManagedUser[]) => | ||
input ? input.map((d) => managedUserFromSDK(d)).filter(removeNullable) : [] | ||
|
||
export const userManagerFromSDK = ( | ||
input: full.UserManager | ||
): UserManagerMetadata | undefined => { | ||
const manager = userMetadataFromSDK(input.manager) | ||
if (!manager) { | ||
return undefined | ||
} | ||
return { | ||
manager, | ||
grant: grantFromSDK(input.grant) | ||
} | ||
} | ||
|
||
export const userManagerListFromSDK = (input?: full.UserManager[]) => | ||
input ? input.map((d) => userManagerFromSDK(d)).filter(removeNullable) : [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.