diff --git a/libs/src/api/Account.ts b/libs/src/api/Account.ts index 64959e7c436..4c2de2af6b3 100644 --- a/libs/src/api/Account.ts +++ b/libs/src/api/Account.ts @@ -249,16 +249,11 @@ export class Account extends Base { phase = phases.ADD_USER const { newMetadata, blockHash, blockNumber } = await this.User.createEntityManagerUserV2({ - metadata + metadata, + profilePictureFile, + coverPhotoFile }) - // Upload user's profile images, if any - phase = phases.UPLOAD_PROFILE_IMAGES - await this.User.uploadProfileImagesV2( - profilePictureFile!, - coverPhotoFile!, - newMetadata - ) return { blockHash, blockNumber, userId: newMetadata.user_id } } catch (e: any) { return { diff --git a/libs/src/api/Users.ts b/libs/src/api/Users.ts index a132e7d4f8d..8ef55175cf8 100644 --- a/libs/src/api/Users.ts +++ b/libs/src/api/Users.ts @@ -591,25 +591,20 @@ export class Users extends Base { } } - async createEntityManagerUserV2({ metadata }: { metadata: UserMetadata }) { + async createEntityManagerUserV2({ + metadata, + profilePictureFile, + coverPhotoFile + }: { + metadata: UserMetadata + profilePictureFile: Nullable + coverPhotoFile: Nullable + }) { this.REQUIRES(Services.DISCOVERY_PROVIDER) try { // Create the user with EntityMananer const userId = await this._generateUserId() - const manageEntityResponse = - await this.contracts.EntityManagerClient!.manageEntity( - userId, - EntityManagerClient.EntityType.USER, - userId, - EntityManagerClient.Action.CREATE, - 'v2' - ) - await this._waitForDiscoveryToIndexUser( - userId, - manageEntityResponse.txReceipt.blockNumber - ) - // Ensure metadata has expected properties const newMetadata = this.cleanUserMetadata({ ...metadata }) this._validateUserMetadata(newMetadata) @@ -627,13 +622,42 @@ export class Users extends Base { repost_count: 0 }) - // Update metadata on chain to include wallet - const { blockHash, blockNumber } = await this.updateMetadataV2({ - newMetadata, - userId - }) + // Upload images + if (profilePictureFile) { + const resp = await this.creatorNode.uploadProfilePictureV2( + profilePictureFile + ) + newMetadata.profile_picture_sizes = resp.id + } + if (coverPhotoFile) { + const resp = await this.creatorNode.uploadCoverPhotoV2(coverPhotoFile) + newMetadata.cover_photo_sizes = resp.id + } - return { newMetadata, blockHash, blockNumber } + const cid = await Utils.fileHasher.generateMetadataCidV1(newMetadata) + const manageEntityResponse = + await this.contracts.EntityManagerClient!.manageEntity( + userId, + EntityManagerClient.EntityType.USER, + userId, + EntityManagerClient.Action.CREATE, + JSON.stringify({ + cid: cid.toString(), + data: newMetadata + }) + ) + await this._waitForDiscoveryToIndexUser( + userId, + manageEntityResponse.txReceipt.blockNumber + ) + // Update libs instance with new user metadata object + this.userStateManager.setCurrentUser({ ...newMetadata }) + + return { + newMetadata, + blockHash: manageEntityResponse.txReceipt.blockHash, + blockNumber: manageEntityResponse.txReceipt.blockNumber + } } catch (e) { const errorMsg = `createEntityManagerUserV2() error: ${e}` if (e instanceof Error) {