Skip to content

Commit

Permalink
feat: update the profile sagas deployEntityWithoutNewFiles to use the…
Browse files Browse the repository at this point in the history
… identity
  • Loading branch information
juanmahidalgo committed Dec 18, 2023
1 parent 67df674 commit 888a37f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 22 deletions.
36 changes: 26 additions & 10 deletions src/lib/entities.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ethers } from 'ethers'
import { Authenticator, AuthChain } from '@dcl/crypto'
import { Authenticator, AuthChain, AuthIdentity } from '@dcl/crypto'
import { Entity, EntityType } from '@dcl/schemas/dist/platform/entity'
import { ContentClient, createContentClient } from 'dcl-catalyst-client/dist/client/ContentClient'
import {
ContentClient,
createContentClient
} from 'dcl-catalyst-client/dist/client/ContentClient'
import { BuildEntityWithoutFilesOptions } from 'dcl-catalyst-client/dist/client/types'
import { buildEntityWithoutNewFiles } from 'dcl-catalyst-client/dist/client/utils/DeploymentBuilder'
import { getConnectedProvider } from './eth'
Expand All @@ -15,10 +18,19 @@ export class EntitiesOperator {
private catalystContentClientWithoutGbCollector: ContentClient | null // Undefined until initialization
private readonly peerAPI: PeerAPI

constructor(private peerUrl: string, private peerWithNoGbCollectorUrl?: string) {
this.catalystContentClient = createContentClient({ url: `${peerUrl}/content`, fetcher: createFetchComponent() })
constructor(
private peerUrl: string,
private peerWithNoGbCollectorUrl?: string
) {
this.catalystContentClient = createContentClient({
url: `${peerUrl}/content`,
fetcher: createFetchComponent()
})
this.catalystContentClientWithoutGbCollector = peerWithNoGbCollectorUrl
? createContentClient({ url: `${peerUrl}/content`, fetcher: createFetchComponent() })
? createContentClient({
url: `${peerUrl}/content`,
fetcher: createFetchComponent()
})
: null
this.peerAPI = new PeerAPI(peerUrl)
}
Expand Down Expand Up @@ -80,7 +92,7 @@ export class EntitiesOperator {
hashesByKey: Map<string, string>,
entityType: EntityType,
pointer: string,
address: string
identity: AuthIdentity
): Promise<any> {
const options: BuildEntityWithoutFilesOptions = {
type: entityType,
Expand All @@ -90,13 +102,17 @@ export class EntitiesOperator {
timestamp: Date.now()
}

const catalystContentClient = this.catalystContentClientWithoutGbCollector ?? this.catalystContentClient
const catalystContentClient =
this.catalystContentClientWithoutGbCollector ?? this.catalystContentClient
const contentUrl = this.peerWithNoGbCollectorUrl ?? this.peerUrl

const entityToDeploy = await buildEntityWithoutNewFiles(createFetchComponent(), { contentUrl: `${contentUrl}/content`, ...options })
const entityToDeploy = await buildEntityWithoutNewFiles(
createFetchComponent(),
{ contentUrl: `${contentUrl}/content`, ...options }
)

const authChain: AuthChain = await this.authenticateEntityDeployment(
address,
const authChain = Authenticator.signPayload(
identity,
entityToDeploy.entityId
)

Expand Down
12 changes: 9 additions & 3 deletions src/modules/profile/sagas.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AuthIdentity } from '@dcl/crypto'
import { Avatar } from '@dcl/schemas/dist/platform/profile'
import { EntityType } from '@dcl/schemas/dist/platform/entity'
import { expectSaga } from 'redux-saga-test-plan'
Expand All @@ -18,7 +19,12 @@ import {
setProfileAvatarDescriptionSuccess
} from './actions'

const profileSagas = createProfileSaga({ peerUrl: 'aURL' });
const mockAuthIdentity: AuthIdentity = {} as AuthIdentity

const profileSagas = createProfileSaga({
getIdentity: () => mockAuthIdentity,
peerUrl: 'aURL'
})
const address = 'anAddress'
const description = 'aDescription'
const errorMessage = 'anError'
Expand Down Expand Up @@ -94,7 +100,7 @@ describe('when handling the action to set the profile avatar description', () =>
getHashesByKeyMap(newAvatar),
EntityType.PROFILE,
address,
address
mockAuthIdentity
],
Promise.resolve(undefined)
)
Expand Down Expand Up @@ -186,7 +192,7 @@ describe('when handling the action to set the profile avatar alias', () => {
getHashesByKeyMap(newAvatar),
EntityType.PROFILE,
address,
address
mockAuthIdentity
],
Promise.resolve(undefined)
)
Expand Down
24 changes: 15 additions & 9 deletions src/modules/profile/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { takeLatest, put, call, takeEvery } from 'redux-saga/effects'
import { AuthIdentity } from '@dcl/crypto'
import { Avatar } from '@dcl/schemas/dist/platform/profile'
import { EntityType } from '@dcl/schemas/dist/platform/entity'
import { PeerAPI } from '../../lib/peer'
Expand Down Expand Up @@ -28,11 +29,13 @@ import { getHashesByKeyMap, lambdaProfileToContentProfile } from './utils'
import { Profile } from './types'

type CreateProfileSagaOptions = {
getIdentity: () => AuthIdentity | undefined
peerUrl: string
peerWithNoGbCollectorUrl?: string
}

export function createProfileSaga({
getIdentity,
peerUrl,
peerWithNoGbCollectorUrl
}: CreateProfileSagaOptions) {
Expand Down Expand Up @@ -134,15 +137,18 @@ export function createProfileSaga({
const profileMetadata: Profile = {
avatars: [newAvatar, ...profileWithContentHashes.avatars.slice(1)]
}

yield call(
[entities, 'deployEntityWithoutNewFiles'],
profileMetadata,
getHashesByKeyMap(newAvatar),
EntityType.PROFILE,
address,
address
)
const identity = getIdentity()

if (identity) {
yield call(
[entities, 'deployEntityWithoutNewFiles'],
profileMetadata,
getHashesByKeyMap(newAvatar),
EntityType.PROFILE,
address,
identity
)
}

return newAvatar
}
Expand Down

0 comments on commit 888a37f

Please sign in to comment.