Skip to content

Commit

Permalink
[CON-678] v2 user profile edit (#3431)
Browse files Browse the repository at this point in the history
  • Loading branch information
theoilie authored May 25, 2023
1 parent abf827f commit fb25e74
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 101 deletions.
129 changes: 45 additions & 84 deletions packages/common/src/services/audius-backend/AudiusBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ export const audiusBackend = ({
metadata: updatedMetadata,

// We don't need these properties, but the confirmer expects them.
// TODO: Remove after v2 is fully rolled out and v1 is removed
// TODO (theo): Remove after v2 is fully rolled out and v1 is removed
transcodedTrackCID: updatedMetadata.track_cid,
metadataMultihash: '',
metadataFileUUID: '',
Expand Down Expand Up @@ -1558,7 +1558,6 @@ export const audiusBackend = ({
return null
}

// TODO (theo): don't call uploadImage if storage v2 signup is enabled
async function updateCreator(metadata: User, _id: ID) {
let newMetadata = { ...metadata }
const associatedWallets = await fetchUserAssociatedWallets(metadata)
Expand All @@ -1571,25 +1570,42 @@ export const audiusBackend = ({
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
const storageV2UploadEnabled = await getFeatureEnabled(
FeatureFlags.STORAGE_V2_TRACK_UPLOAD
)
try {
if (newMetadata.updatedProfilePicture) {
const resp = await audiusLibs.File.uploadImage(
newMetadata.updatedProfilePicture.file,
undefined,
null,
writeMetadataThroughChainEnabled
)
newMetadata.profile_picture_sizes = resp.dirCID
if (storageV2UploadEnabled) {
const resp = await audiusLibs.creatorNode.uploadProfilePictureV2(
newMetadata.updatedProfilePicture.file
)
newMetadata.profile_picture_sizes = resp.id
} else {
const resp = await audiusLibs.File.uploadImage(
newMetadata.updatedProfilePicture.file,
undefined,
null,
writeMetadataThroughChainEnabled
)
newMetadata.profile_picture_sizes = resp.dirCID
}
}

if (newMetadata.updatedCoverPhoto) {
const resp = await audiusLibs.File.uploadImage(
newMetadata.updatedCoverPhoto.file,
false,
null,
writeMetadataThroughChainEnabled
)
newMetadata.cover_photo_sizes = resp.dirCID
if (storageV2UploadEnabled) {
const resp = await audiusLibs.creatorNode.uploadCoverPhotoV2(
newMetadata.updatedCoverPhoto.file
)
newMetadata.cover_photo_sizes = resp.id
} else {
const resp = await audiusLibs.File.uploadImage(
newMetadata.updatedCoverPhoto.file,
false,
null,
writeMetadataThroughChainEnabled
)
newMetadata.cover_photo_sizes = resp.dirCID
}
}

if (
Expand Down Expand Up @@ -1618,74 +1634,20 @@ export const audiusBackend = ({
}

newMetadata = schemas.newUserMetadata(newMetadata, true)
const { blockHash, blockNumber, userId } =
await audiusLibs.User.updateCreator(
newMetadata.user_id,
newMetadata,
writeMetadataThroughChainEnabled
)
return { blockHash, blockNumber, userId }
} catch (err) {
console.error(getErrorMessage(err))
return false
}
}

// TODO (theo): don't call uploadImage if storage v2 signup is enabled
async function updateUser(metadata: User, id: ID) {
let newMetadata = { ...metadata }
const writeMetadataThroughChainEnabled =
(await getFeatureEnabled(FeatureFlags.WRITE_METADATA_THROUGH_CHAIN)) ??
false
try {
if (newMetadata.updatedProfilePicture) {
const resp = await audiusLibs.File.uploadImage(
newMetadata.updatedProfilePicture.file,
undefined,
null,
writeMetadataThroughChainEnabled
)
newMetadata.profile_picture_sizes = resp.dirCID
}

if (newMetadata.updatedCoverPhoto) {
const resp = await audiusLibs.File.uploadImage(
newMetadata.updatedCoverPhoto.file,
false,
null,
writeMetadataThroughChainEnabled
)
newMetadata.cover_photo_sizes = resp.dirCID
}
if (
typeof newMetadata.twitter_handle === 'string' ||
typeof newMetadata.instagram_handle === 'string' ||
typeof newMetadata.tiktok_handle === 'string' ||
typeof newMetadata.website === 'string' ||
typeof newMetadata.donation === 'string'
) {
await fetch(`${identityServiceUrl}/social_handles`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
handle: newMetadata.handle,
twitterHandle: newMetadata.twitter_handle,
instagramHandle: newMetadata.instagram_handle,
website: newMetadata.website,
donation: newMetadata.donation
})
})
if (storageV2UploadEnabled) {
const userId = newMetadata.user_id
const { blockHash, blockNumber } =
await audiusLibs.User.updateMetadataV2({ newMetadata, userId })
return { blockHash, blockNumber, userId }
} else {
const { blockHash, blockNumber, userId } =
await audiusLibs.User.updateCreator(
newMetadata.user_id,
newMetadata,
writeMetadataThroughChainEnabled
)
return { blockHash, blockNumber, userId }
}

newMetadata = schemas.newUserMetadata(newMetadata, true)

const { blockHash, blockNumber } = await audiusLibs.User.updateUser(
id,
newMetadata
)
return { blockHash, blockNumber }
} catch (err) {
console.error(getErrorMessage(err))
throw err
Expand Down Expand Up @@ -3901,7 +3863,6 @@ export const audiusBackend = ({
updatePlaylistLastViewedAt,
updatePushNotificationSettings,
updateTrack,
updateUser,
updateUserEvent,
updateUserLocationTimezone,
subscribeToUser,
Expand Down
27 changes: 10 additions & 17 deletions packages/web/src/common/store/profile/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ export function* updateProfileAsync(action) {
)

// Get existing metadata and combine with it
const gateways = audiusBackendInstance.getCreatorNodeIPFSGateways(
metadata.creator_node_endpoint
)
const gateways = metadata.is_storage_v2
? []
: audiusBackendInstance.getCreatorNodeIPFSGateways(
metadata.creator_node_endpoint
)
const cid = metadata.metadata_multihash ?? null
if (cid) {
try {
Expand Down Expand Up @@ -508,20 +510,11 @@ function* confirmUpdateProfile(userId, metadata) {
confirmerActions.requestConfirmation(
makeKindId(Kind.USERS, userId),
function* () {
let response
if (metadata.creator_node_endpoint) {
response = yield call(
audiusBackendInstance.updateCreator,
metadata,
userId
)
} else {
response = yield call(
audiusBackendInstance.updateUser,
metadata,
userId
)
}
const response = yield call(
audiusBackendInstance.updateCreator,
metadata,
userId
)
const { blockHash, blockNumber } = response

const confirmed = yield call(confirmTransaction, blockHash, blockNumber)
Expand Down

0 comments on commit fb25e74

Please sign in to comment.