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-3093] Update clients to use socials from DN #8742

Merged
merged 13 commits into from
Jun 7, 2024
5 changes: 5 additions & 0 deletions packages/common/src/adapters/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ export const userMetadataFromSDK = (

// Required Nullable fields
bio: user.bio ?? null,
twitter_handle: user.twitter_handle ?? null,
sddioulde marked this conversation as resolved.
Show resolved Hide resolved
instagram_handle: user.instagram_handle ?? null,
tiktok_handle: user.tiktok_handle ?? null,
website: user.website ?? null,
donation: user.donation ?? null,
cover_photo_sizes: user.cover_photo_sizes ?? null,
creator_node_endpoint: user.creator_node_endpoint ?? null,
location: user.location ?? null,
Expand Down
6 changes: 2 additions & 4 deletions packages/common/src/hooks/useTwitterButtonStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ export const useTwitterButtonStatus = (
useState<ShareStatus>('idle')

const userName = user?.name
const twitterHandle = user ? user.twitter_handle : null
const twitterHandle = user?.twitter_handle

const additionalUserName = additionalUser?.name
const additionalTwitterHandle = additionalUser
? additionalUser.twitter_handle
: null
const additionalTwitterHandle = additionalUser?.twitter_handle

// Initially twitter handle is undefined; after fetch it's
// set to either null or a value in `fetchUserSocials` sagas
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/messages/sign-on/socialMediaMessages.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { SocialPlatform } from '~/models'

export const socialMediaMessages = {
verificationError:
'Something went wrong. Please try again or verify with another account.',
socialMediaLoginSucess: (platform: 'twitter' | 'instagram' | 'tiktok') => {
socialMediaLoginSucess: (platform: SocialPlatform) => {
const platformName = {
twitter: 'Twitter',
instagram: 'Instagram',
Expand Down
18 changes: 10 additions & 8 deletions packages/common/src/models/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { Grant } from './Grant'
import { Timestamped } from './Timestamped'
import { UserEvent } from './UserEvent'

export type SocialPlatform = 'twitter' | 'instagram' | 'tiktok'

export type UserMetadata = {
album_count: number
allow_ai_attribution?: boolean
Expand All @@ -39,6 +41,14 @@ export type UserMetadata = {
has_collectibles: boolean
is_deactivated: boolean
is_verified: boolean
twitter_handle: Nullable<string>
instagram_handle: Nullable<string>
tiktok_handle: Nullable<string>
verified_with_twitter: boolean
verified_with_instagram: boolean
verified_with_tiktok: boolean
website: Nullable<string>
donation: Nullable<string>
location: Nullable<string>
metadata_multihash: Nullable<CID>
name: string
Expand All @@ -57,15 +67,7 @@ export type UserMetadata = {
// Only present on the "current" account
track_save_count?: number
user_id: number
twitter_handle?: string
instagram_handle?: string
tiktok_handle?: string
website?: string
wallet?: string
donation?: string
twitterVerified?: boolean
instagramVerified?: boolean
tikTokVerified?: boolean
balance?: Nullable<StringWei>
total_balance?: Nullable<StringWei>
associated_wallets?: Nullable<string[]>
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/schemas/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ const userMetadataSchema = {
bio: null,
location: null,
is_verified: false,
twitter_handle: null,
instagram_handle: null,
tiktok_handle: null,
website: null,
donation: null,
creator_node_endpoint: null,
updated_at: null,
associated_wallets: null,
Expand Down
8 changes: 8 additions & 0 deletions packages/common/src/services/audius-api-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ export type APIUser = {
handle: string
id: OpaqueID
is_verified: boolean
twitter_handle: Nullable<string>
instagram_handle: Nullable<string>
tiktok_handle: Nullable<string>
verified_with_twitter: boolean
verified_with_instagram: boolean
verified_with_tiktok: boolean
website: Nullable<string>
donation: Nullable<string>
is_deactivated: boolean
location: Nullable<string>
name: string
Expand Down
92 changes: 58 additions & 34 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -742,19 +742,35 @@ export const audiusBackend = ({
const account = audiusLibs.Account.getCurrentUser()
if (!account) return null

try {
const body = await getSocialHandles(account.handle)
account.twitter_handle = body.twitterHandle || null
account.instagram_handle = body.instagramHandle || null
account.tiktok_handle = body.tikTokHandle || null
account.website = body.website || null
account.donation = body.donation || null
account.twitterVerified = body.twitterVerified || false
account.instagramVerified = body.instagramVerified || false
account.tikTokVerified = body.tikTokVerified || false
} catch (e) {
console.error(e)
// This is saying that if there is any social info coming back from DN,
// then we should not attempt to fetch socials from identity.
// It is possible that identity has more up-to-date socials than DN,
// but we can live with that until we do the final social backfill from identity to DN.
const hasSocialsFromDn =
account.twitter_handle ||
account.instagram_handle ||
account.tiktok_handle ||
account.website ||
account.donation ||
account.verified_with_twitter ||
sddioulde marked this conversation as resolved.
Show resolved Hide resolved
account.verified_with_instagram ||
account.verified_with_tiktok
if (!hasSocialsFromDn) {
sddioulde marked this conversation as resolved.
Show resolved Hide resolved
try {
const body = await getSocialHandles(account.handle)
account.twitter_handle = body.twitterHandle || null
account.instagram_handle = body.instagramHandle || null
account.tiktok_handle = body.tikTokHandle || null
account.website = body.website || null
account.donation = body.donation || null
account.verified_with_twitter = body.twitterVerified || false
account.verified_with_instagram = body.instagramVerified || false
account.verified_with_tiktok = body.tikTokVerified || false
} catch (e) {
console.error(e)
}
}

try {
const userBank = await audiusLibs.solanaWeb3Manager.deriveUserBank()
account.userBank = userBank.toString()
Expand Down Expand Up @@ -1055,29 +1071,37 @@ export const audiusBackend = ({
newMetadata.cover_photo_sizes = resp.id
}

if (
typeof newMetadata.twitter_handle === 'string' ||
typeof newMetadata.instagram_handle === 'string' ||
typeof newMetadata.tiktok_handle === 'string' ||
typeof newMetadata.website === 'string' ||
typeof newMetadata.donation === 'string'
) {
const { data, signature } = await signData()
await fetch(`${identityServiceUrl}/social_handles`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
[AuthHeaders.Message]: data,
[AuthHeaders.Signature]: signature
},
body: JSON.stringify({
twitterHandle: newMetadata.twitter_handle,
instagramHandle: newMetadata.instagram_handle,
tikTokHandle: newMetadata.tiktok_handle,
website: newMetadata.website,
donation: newMetadata.donation
// Leave this here for now, but this should be removed once we believe
// that old clients have caught up and are updating socials via entity manager to DN.
try {
if (
typeof newMetadata.twitter_handle === 'string' ||
typeof newMetadata.instagram_handle === 'string' ||
typeof newMetadata.tiktok_handle === 'string' ||
typeof newMetadata.website === 'string' ||
typeof newMetadata.donation === 'string'
) {
const { data, signature } = await signData()
await fetch(`${identityServiceUrl}/social_handles`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
[AuthHeaders.Message]: data,
[AuthHeaders.Signature]: signature
},
body: JSON.stringify({
twitterHandle: newMetadata.twitter_handle,
instagramHandle: newMetadata.instagram_handle,
tikTokHandle: newMetadata.tiktok_handle,
website: newMetadata.website,
donation: newMetadata.donation
})
})
})
}
} catch (e) {
console.error(
`Could not update socials in identity, but they should still be updated in DN with code below. Error: ${e}`
)
}

newMetadata = schemas.newUserMetadata(newMetadata, true)
Expand Down
5 changes: 5 additions & 0 deletions packages/libs/src/api/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { Base, BaseConstructorArgs, Services } from './base'
// null or non-null values
const USER_PROPS = [
'is_verified',
'twitter_handle',
'instagram_handle',
'tiktok_handle',
'website',
'donation',
'is_deactivated',
'name',
'handle',
Expand Down
32 changes: 32 additions & 0 deletions packages/libs/src/services/schemaValidator/schemas/userSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,38 @@
"type": ["string", "null"],
"default": null
},
"twitter_handle": {
"type": ["string", "null"],
"default": null
},
"instagram_handle": {
"type": ["string", "null"],
"default": null
},
"tiktok_handle": {
"type": ["string", "null"],
"default": null
},
"verified_with_twitter": {
"type": "boolean",
"default": false
},
"verified_with_instagram": {
"type": "boolean",
"default": false
},
"verified_with_tiktok": {
"type": "boolean",
"default": false
},
"website": {
"type": ["string", "null"],
"default": null
},
"donation": {
"type": ["string", "null"],
"default": null
},
"bio": {
"type": ["string", "null"],
"default": null
Expand Down
16 changes: 8 additions & 8 deletions packages/libs/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ export type UserMetadata = {
handle_lc: string
is_deactivated: boolean
is_verified: boolean
twitter_handle: Nullable<string>
instagram_handle: Nullable<string>
tiktok_handle: Nullable<string>
verified_with_twitter: boolean
verified_with_instagram: boolean
verified_with_tiktok: boolean
website: Nullable<string>
donation: Nullable<string>
is_storage_v2: boolean
location: Nullable<string>
// this should be removed
Expand All @@ -64,15 +72,7 @@ export type UserMetadata = {

// Only present on the "current" account
track_save_count?: number
twitter_handle?: string
instagram_handle?: string
tiktok_handle?: string
website?: string
wallet?: string
donation?: string
twitterVerified?: boolean
instagramVerified?: boolean
tikTokVerified?: boolean
}

export type User = UserMetadata
Expand Down
10 changes: 5 additions & 5 deletions packages/mobile/src/components/share-drawer/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const getContentUrl = (content: ShareContent) => {
}
}

const getShareHandle = async (handle: string) => {
const getTwitterShareHandle = async (handle: string) => {
const { twitterHandle } = await audiusBackendInstance.getSocialHandles(handle)
return twitterHandle ? `@${twitterHandle}` : handle
}
Expand All @@ -47,13 +47,13 @@ export const getTwitterShareText = async (content: ShareContent) => {
track: { title },
artist: { handle }
} = content
return messages.trackShareText(title, await getShareHandle(handle))
return messages.trackShareText(title, await getTwitterShareHandle(handle))
}
case 'profile': {
const {
profile: { handle }
} = content
return messages.profileShareText(await getShareHandle(handle))
return messages.profileShareText(await getTwitterShareHandle(handle))
}
case 'album': {
const {
Expand All @@ -62,7 +62,7 @@ export const getTwitterShareText = async (content: ShareContent) => {
} = content
return messages.albumShareText(
playlist_name,
await getShareHandle(handle)
await getTwitterShareHandle(handle)
)
}
case 'playlist': {
Expand All @@ -72,7 +72,7 @@ export const getTwitterShareText = async (content: ShareContent) => {
} = content
return messages.playlistShareText(
playlist_name,
await getShareHandle(handle)
await getTwitterShareHandle(handle)
)
}
case 'audioNftPlaylist': {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ const useStyles = makeStyles(({ palette, spacing }) => ({
}))

type EditProfileFormProps = FormikProps<ProfileValues> & {
isTwitterVerified?: boolean
isInstagramVerified?: boolean
isTikTokVerified?: boolean
isTwitterVerified: boolean
isInstagramVerified: boolean
isTikTokVerified: boolean
}

const EditProfileForm = (props: EditProfileFormProps) => {
Expand Down Expand Up @@ -134,8 +134,12 @@ const EditProfileForm = (props: EditProfileFormProps) => {

export const EditProfileScreen = () => {
const profile = useSelector(getAccountUser)!
const { user_id, twitterVerified, instagramVerified, tikTokVerified } =
profile
const {
user_id,
verified_with_twitter: verifiedWithTwitter,
verified_with_instagram: verifiedWithInstagram,
verified_with_tiktok: verifiedWithTiktok
} = profile

const dispatch = useDispatch()

Expand Down Expand Up @@ -208,9 +212,9 @@ export const EditProfileScreen = () => {
return (
<EditProfileForm
{...formikProps}
isTwitterVerified={twitterVerified}
isInstagramVerified={instagramVerified}
isTikTokVerified={tikTokVerified}
isTwitterVerified={verifiedWithTwitter}
isInstagramVerified={verifiedWithInstagram}
isTikTokVerified={verifiedWithTiktok}
/>
)
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,8 @@ export const ProfileSocials = () => {
const dispatch = useDispatch()

useEffect(() => {
if (twitter_handle === undefined) {
dispatch(fetchUserSocials(handle))
}
}, [twitter_handle, dispatch, handle])
dispatch(fetchUserSocials(handle))
}, [dispatch, handle])

const socialLinks = useMemo(() => {
const links = [
Expand Down
Loading