Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PAY-3632] Migrate socials code off of libs #10657

Merged
merged 5 commits into from
Dec 10, 2024
Merged
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
6 changes: 3 additions & 3 deletions packages/common/src/api/signUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const signUpApi = createApi({
getHandleReservedStatus: {
fetch: async (
{ handle }: { handle: string },
{ audiusBackend, remoteConfigInstance, env }
{ audiusBackend, identityService, remoteConfigInstance, env }
) => {
const handleCheckTimeout =
remoteConfigInstance.getRemoteVar(
Expand All @@ -47,7 +47,7 @@ const signUpApi = createApi({
FeatureFlags.VERIFY_HANDLE_WITH_TWITTER
)
? promiseWithTimeout(
audiusBackend.twitterHandle(handle),
identityService.lookupTwitterHandle(handle),
handleCheckTimeout
)
: null
Expand Down Expand Up @@ -77,7 +77,7 @@ const signUpApi = createApi({

const reservedStatus = parseHandleReservedStatusFromSocial({
isOauthVerified: false,
lookedUpTwitterUser: twitterUser?.user ?? null,
lookedUpTwitterUser: twitterUser,
lookedUpInstagramUser: instagramUser,
lookedUpTikTokUser: tiktokUser
})
Expand Down
6 changes: 5 additions & 1 deletion packages/common/src/audius-query/AudiusQueryContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { Dispatch } from 'redux'
import { getContext } from 'typed-redux-saga'

import type { AudiusAPIClient } from '~/services/audius-api-client'
import type { AuthService } from '~/services/auth'
import type { AuthService, IdentityService } from '~/services/auth'
import {
AudiusBackend,
Env,
Expand All @@ -24,6 +24,7 @@ export type AudiusQueryContextType = {
audiusSdk: () => Promise<AudiusSdk>
audiusBackend: AudiusBackend
authService: AuthService
identityService: IdentityService
dispatch: Dispatch
reportToSentry: (args: ReportToSentryArgs) => void
env: Env
Expand Down Expand Up @@ -83,6 +84,9 @@ export function* getAudiusQueryContext(): Generator<
authService: yield* getContext<AudiusQueryContextType['authService']>(
'authService'
),
identityService: yield* getContext<
AudiusQueryContextType['identityService']
>('identityService'),
audiusSdk: yield* getContext<AudiusQueryContextType['audiusSdk']>(
'audiusSdk'
),
Expand Down
80 changes: 0 additions & 80 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {
Name,
TikTokUser,
Track,
TwitterUser,
User,
UserMetadata,
UserCollection,
Expand Down Expand Up @@ -1020,18 +1019,6 @@ export const audiusBackend = ({
}
}

async function twitterHandle(handle: string) {
await waitForLibsInit()
try {
const user: TwitterUser = await audiusLibs.Account.lookupTwitterHandle(
handle
)
return { success: true, user }
} catch (error) {
return { success: false, error }
}
}

async function instagramHandle(handle: string) {
try {
const res = await fetch(
Expand All @@ -1056,69 +1043,6 @@ export const audiusBackend = ({
}
}

async function associateTwitterAccount(
twitterId: string,
userId: ID,
handle: string,
blockNumber: number
) {
await waitForLibsInit()
try {
await audiusLibs.Account.associateTwitterUser(
twitterId,
userId,
handle,
blockNumber
)
return { success: true }
} catch (error) {
console.error(getErrorMessage(error))
return { success: false, error }
}
}

async function associateInstagramAccount(
instagramId: string,
userId: ID,
handle: string,
blockNumber: number
) {
await waitForLibsInit()
try {
await audiusLibs.Account.associateInstagramUser(
instagramId,
userId,
handle,
blockNumber
)
return { success: true }
} catch (error) {
console.error(getErrorMessage(error))
return { success: false, error }
}
}

async function associateTikTokAccount(
tikTokId: string,
userId: ID,
handle: string,
blockNumber: number
) {
await waitForLibsInit()
try {
await audiusLibs.Account.associateTikTokUser(
tikTokId,
userId,
handle,
blockNumber
)
return { success: true }
} catch (error) {
console.error(getErrorMessage(error))
return { success: false, error }
}
}

async function clearNotificationBadges({ sdk }: { sdk: AudiusSdk }) {
try {
const { data, signature } = await signIdentityServiceRequest({ sdk })
Expand Down Expand Up @@ -1832,9 +1756,6 @@ export const audiusBackend = ({
addDiscoveryProviderSelectionListener,
addPlaylistTrack,
audiusLibs: audiusLibs as AudiusLibsType,
associateInstagramAccount,
associateTwitterAccount,
associateTikTokAccount,
clearNotificationBadges,
createPlaylist,
currentDiscoveryProvider,
Expand Down Expand Up @@ -1881,7 +1802,6 @@ export const audiusBackend = ({
signIdentityServiceRequest,
signUp,
transferAudioToWAudio,
twitterHandle,
instagramHandle,
tiktokHandle,
undoRepostCollection,
Expand Down
67 changes: 67 additions & 0 deletions packages/common/src/services/auth/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EthWallet, SetAuthFn } from '@audius/hedgehog'
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'
import sigUtil from 'eth-sig-util'

import { TwitterUser } from '~/models'
import { Nullable } from '~/utils/typeUtils'
import { uuid } from '~/utils/uid'

Expand Down Expand Up @@ -89,6 +90,72 @@ export class IdentityService {
})
}

async lookupTwitterHandle(handle: string): Promise<TwitterUser> {
if (handle) {
return await this._makeRequest({
url: '/twitter/handle_lookup',
method: 'get',
params: { handle }
})
} else {
throw new Error('No handle passed into function lookupTwitterHandle')
}
}

async associateTwitterUser(
uuid: string,
userId: number,
handle: string,
blockNumber?: number
) {
return await this._makeRequest({
url: '/twitter/associate',
method: 'post',
data: {
uuid,
userId,
handle,
blockNumber
}
})
}

async associateInstagramUser(
uuid: string,
userId: number,
handle: string,
blockNumber?: number
) {
return await this._makeRequest({
url: '/instagram/associate',
method: 'post',
data: {
uuid,
userId,
handle,
blockNumber
}
})
}

async associateTikTokUser(
uuid: string,
userId: number,
handle: string,
blockNumber?: number
) {
return await this._makeRequest({
url: '/tiktok/associate',
method: 'post',
data: {
uuid,
userId,
handle,
blockNumber
}
})
}

/**
* Get the user's email used for notifications and display.
*/
Expand Down
Loading