Skip to content

Commit

Permalink
Revert "Revert single tx signup in libs (#5471)"
Browse files Browse the repository at this point in the history
This reverts commit 0adb382.
  • Loading branch information
isaacsolo committed Jul 7, 2023
1 parent 366c6c5 commit 823f1af
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
11 changes: 3 additions & 8 deletions libs/src/api/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
64 changes: 44 additions & 20 deletions libs/src/api/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -591,25 +591,20 @@ export class Users extends Base {
}
}

async createEntityManagerUserV2({ metadata }: { metadata: UserMetadata }) {
async createEntityManagerUserV2({
metadata,
profilePictureFile,
coverPhotoFile
}: {
metadata: UserMetadata
profilePictureFile: Nullable<File>
coverPhotoFile: Nullable<File>
}) {
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)
Expand All @@ -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) {
Expand Down

0 comments on commit 823f1af

Please sign in to comment.