Convert AudiusBackend to typescript#1650
Conversation
|
Preview this change https://demo.audius.co/sk-audius-backend-port |
|
Preview this change https://demo.audius.co/sk-audius-backend-port |
|
Preview this change https://demo.audius.co/sk-audius-backend-port |
| const addTrackImages = <T extends TrackMetadata>( | ||
| track: T | ||
| ): T & { duration: number; _cover_art_sizes: CoverArtSizes } => { | ||
| const addTrackImages = ( |
| function* fetchDashboardListenDataAsync(action) { | ||
| const listenData = yield call( | ||
| AudiusBackend.getTrackListens, | ||
| action.period, |
| userId: currentUser.user_id, | ||
| handle: currentUser.handle, | ||
| recipientEthAddress: currentUser.wallet, | ||
| recipientEthAddress: currentUser.wallet as string, |
There was a problem hiding this comment.
just checking we dont want an if statement to check that case wallet, endpoints, and parallelization are not around?
There was a problem hiding this comment.
Yeah actually I think I can add it to the null check above
| try { | ||
| yield call(waitForBackendSetup) | ||
| const accountUserId: Nullable<ID> = yield select(getUserId) | ||
| const accountUserId: ID = yield select(getUserId) |
There was a problem hiding this comment.
can we yield* these or would that take too long? from what i remember this actually is a Nullable<ID>
There was a problem hiding this comment.
yeah just tried it and after changing 'redux-saga/effects' import to 'typed-redux-saga/macro', this logic works:
const accountUserId = yield* select(getUserId)
const userMetadata = yield* select(getAccountUser)
if (!accountUserId || !userMetadata) return
yield put(
requestConfirmation(
DEACTIVATE_CONFIRMATION_UID,
...There was a problem hiding this comment.
Sick ok will do that instead
| const { blockHash, blockNumber } = yield call( | ||
| AudiusBackend.updateCreator, | ||
| { ...userMetadata, is_deactivated: true }, | ||
| { ...userMetadata, is_deactivated: true } as User, |
There was a problem hiding this comment.
(and wont need to cast here)
| return feedItems.map((item) => { | ||
| if (item.playlist_id) return AudiusBackend.getCollectionImages(item) | ||
| return feedItems.map((item: Collection | Track) => { | ||
| if ((item as Collection).playlist_id) { |
There was a problem hiding this comment.
i think you can do if ('playlist_id' in item) which then tells the rest of the branch item is Collection, and then also do we need to type (item: Collection | Track) or can that come from feedItem's type?
There was a problem hiding this comment.
Good call, yeah that all makes sense
| static async searchTags({ | ||
| searchText, | ||
| minTagThreshold, | ||
| query, |
There was a problem hiding this comment.
ah looks like it was changed, nice
| return true | ||
| } catch (err) { | ||
| console.error(err.message) | ||
| console.log(getErrorMessage(err)) |
There was a problem hiding this comment.
getErrorMessage so clutch
| referrer = null, | ||
| feePayerOverride = null | ||
| }: { | ||
| email: string |
There was a problem hiding this comment.
might be nice to create standalone type for this
There was a problem hiding this comment.
I agree but I think I'm gonna leave this for now because the type would have to live all the way at the top of the file outside of the AudiusBackend class. The benefit of having it colocated with the function outweighs the separate type imo here. Can def fix once AudiusBackend is split up and potentially not a class anymore
| feePayerOverride, | ||
| isFinalAttempt | ||
| }: { | ||
| challenges: { challenge_id: ChallengeRewardID; specifier: string }[] |
There was a problem hiding this comment.
and here too potentially
|
Preview this change https://demo.audius.co/sk-audius-backend-port |
|
Preview this change https://demo.audius.co/sk-audius-backend-port |
|
Preview this change https://demo.audius.co/sk-audius-backend-port |
| .map((track: Track) => track.track_id) | ||
| .filter(Boolean) | ||
|
|
||
| const tracks = lineupItems.filter( |
| const accountUserId = yield* select(getUserId) | ||
| const userMetadata = yield* select(getAccountUser) | ||
| if (!accountUserId || !userMetadata) return | ||
| yield* put( |
[c3682b3] [C-780] Update AudiusBackend to work in native context (#1677) Dylan Jeffers [398093d] [C-781] Add minimum threshold to common password check (#1684) Kyle Shanks [5a66847] Ensure fetch calls are awaited so errors are caught (#1683) Sebastian Klingler [d597054] Make audiusBackend configurable for different environments (#1670) Sebastian Klingler [b5fa3fa] Fix native build with new metro-config dependencies (#1676) Dylan Jeffers [408a425] [C-771] Update native metro-config to enable @audius/sdk (#1671) Dylan Jeffers [afde38e] [PAY-416] Early access mode & feature flag refactor (#1654) Michael Piazza [3b28c7e] Fix typecheck for mobile after AudiusBackend ts migration (#1672) Sebastian Klingler [e5fbbb5] Revert "Revert "Update explore endpoints in libs to use v1 (#1539)" (#1609)" (#1669) Joseph Lee [237784b] Default endpoints to empty array instead of null (#1665) Marcus Pasell [175e5d6] Add ModalContentPages to stems (#1659) Marcus Pasell [fdadaac] fix mobile menu on narrow (#1664) nicoback2 [3e2b499] Convert AudiusBackend to typescript (#1650) Sebastian Klingler
Description
Converts
AudiusBackend.jsto TypeScriptUsed the typed DiscoveryApi to specify argument types on many of the functions. This is with the help of pretty crazy
SnakeKeysToCameltype helper.Most of this extra layer will probably be removed eventually in favor of using the sdk, but types will help in the refactoring process
Dragons
Is there anything the reviewer should be on the lookout for? Are there any dangerous changes?
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide repro instructions & any configuration.
How will this change be monitored?
For features that are critical or could fail silently please describe the monitoring/alerting being added.
Feature Flags
Are all new features properly feature flagged? Describe added feature flags.