Skip to content

Commit

Permalink
fix: Look for a owned placement point before undeploying an scene (#3217
Browse files Browse the repository at this point in the history
)

* fix: Look for a owned placement point before undeploying an scene

* fix: Tests
  • Loading branch information
LautaroPetaccio authored Nov 5, 2024
1 parent 8b7055b commit 03051be
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/config/env/dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"MARKETPLACE_API": "https://marketplace-api.decentraland.zone/v1",
"DOCS_URL": "https://docs.decentraland.org",
"MARKETPLACE_WEB_URL": "https://decentraland.zone/marketplace",
"LAND_MANAGER_GRAPH_URL": "https://api.studio.thegraph.com/query/49472/land-manager-sepolia/version/latest",
"MARKETPLACE_GRAPH_URL": "https://api.studio.thegraph.com/query/49472/marketplace-sepolia/version/latest",
"RENTALS_GRAPH_URL": "https://api.studio.thegraph.com/query/49472/rentals-ethereum-sepolia/version/latest",
"LAND_MANAGER_GRAPH_URL": "https://subgraph.decentraland.zone/land-manager-sepolia",
"MARKETPLACE_GRAPH_URL": "https://subgraph.decentraland.org/marketplace-sepolia",
"RENTALS_GRAPH_URL": "https://subgraph.decentraland.zone/rentals-ethereum-sepolia",
"SHARE_SCENE_URL": "https://share.decentraland.zone/b",
"INTERCOM_APP_ID": "z0h94kay",
"SEGMENT_API_KEY": "H21EgRI4eYwICDZf5uW6ek2BiykIR6wA",
Expand Down
9 changes: 8 additions & 1 deletion src/modules/deployment/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { getData } from 'modules/project/selectors'
import { getData as getDeployments } from 'modules/deployment/selectors'
import { createFiles } from 'modules/project/export'
import { getSceneByProjectId } from 'modules/scene/utils'
import { getLandTiles } from 'modules/land/selectors'
import {
clearDeploymentFailure,
clearDeploymentRequest,
Expand Down Expand Up @@ -184,7 +185,10 @@ describe('when handling the clear deployment request action', () => {
describe('when the stored deployments does not contain a deployment for the provided id', () => {
it('should put a clear deployment failure action signaling that the deployment id is invalid', async () => {
await expectSaga(deploymentSaga, builderAPI, catalystClient)
.provide([[select(getDeployments), deployments]])
.provide([
[select(getDeployments), deployments],
[select(getLandTiles), []]
])
.put(clearDeploymentFailure(deploymentId, 'Unable to clear deployment: Invalid deployment'))
.dispatch(clearDeploymentRequest(deploymentId))
.silentRun()
Expand All @@ -201,6 +205,7 @@ describe('when handling the clear deployment request action', () => {
await expectSaga(deploymentSaga, builderAPI, catalystClient)
.provide([
[select(getDeployments), deployments],
[select(getLandTiles), []],
[call(getIdentity), identity]
])
.put(clearDeploymentFailure(deploymentId, 'Unable to clear deployment: Invalid identity'))
Expand Down Expand Up @@ -228,6 +233,7 @@ describe('when handling the clear deployment request action', () => {
await expectSaga(deploymentSaga, builderAPI, catalystClient)
.provide([
[select(getDeployments), deployments],
[select(getLandTiles), []],
[call(getIdentity), identity],
[
call(cryptoFetch, `${worldsContentServerUrl}/entities/world`, {
Expand All @@ -252,6 +258,7 @@ describe('when handling the clear deployment request action', () => {
await expectSaga(deploymentSaga, builderAPI, catalystClient)
.provide([
[select(getDeployments), deployments],
[select(getLandTiles), []],
[call(getIdentity), identity],
[
call(cryptoFetch, `${worldsContentServerUrl}/entities/world`, {
Expand Down
20 changes: 17 additions & 3 deletions src/modules/deployment/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { isErrorWithMessage } from 'decentraland-dapps/dist/lib/error'
import { takeLatest, takeEvery, put, select, call, take, all } from 'redux-saga/effects'
import { config } from 'config'
import { BuilderAPI, getEmptySceneUrl, getPreviewUrl } from 'lib/api/builder'
import { Deployment, SceneDefinition, Placement } from 'modules/deployment/types'
import { Deployment, SceneDefinition, Placement, Coordinate } from 'modules/deployment/types'
import { takeScreenshot } from 'modules/editor/actions'
import { fetchENSWorldStatusRequest } from 'modules/ens/actions'
import { isLoggedIn } from 'modules/identity/selectors'
import { getIdentity } from 'modules/identity/utils'
import { FETCH_LANDS_SUCCESS, FetchLandsSuccessAction } from 'modules/land/actions'
import { getCoordsByEstateId } from 'modules/land/selectors'
import { getCoordsByEstateId, getLandTiles } from 'modules/land/selectors'
import { coordsToId, idToCoords } from 'modules/land/utils'
import { LandType } from 'modules/land/types'
import { recordMediaRequest, RECORD_MEDIA_SUCCESS, RecordMediaSuccessAction } from 'modules/media/actions'
Expand Down Expand Up @@ -400,6 +400,7 @@ export function* deploymentSaga(builder: BuilderAPI, catalystClient: CatalystCli
try {
const deployments: ReturnType<typeof getDeployments> = yield select(getDeployments)
const deployment = deployments[deploymentId]
const lands = (yield select(getLandTiles)) as ReturnType<typeof getLandTiles>

if (!deployment) {
throw new Error('Unable to clear deployment: Invalid deployment')
Expand All @@ -423,11 +424,24 @@ export function* deploymentSaga(builder: BuilderAPI, catalystClient: CatalystCli
} else {
const contentClient: ContentClient = yield call([catalystClient, 'getContentClient'])
const { placement } = deployment
// If deployment was done with a placement point not owned by the user, we need to find a point that is currently own by them.
// This could happen if a estate has a deployment, the estate gets dissolved and the lands sent to different users.
const landsBelongingToTheDeployment = deployments[deploymentId].parcels
.filter(parcel => lands[parcel])
.map(parcel => lands[parcel].land)
let placementPoint: Coordinate = placement.point
const isPlacementPointOwnedByUser = landsBelongingToTheDeployment.some(
land => land.id === placement.point.x + ',' + placement.point.y
)
if (!isPlacementPointOwnedByUser && landsBelongingToTheDeployment[0]) {
placementPoint = { x: landsBelongingToTheDeployment[0].x ?? 0, y: landsBelongingToTheDeployment[0].y ?? 0 }
}

const [emptyProject, emptyScene] = getEmptyDeployment(deployment.projectId || UNPUBLISHED_PROJECT_ID)
const files: UnwrapPromise<ReturnType<typeof createFiles>> = yield call(createFiles, {
project: emptyProject,
scene: emptyScene,
point: placement.point,
point: placementPoint,
rotation: placement.rotation,
thumbnail: getEmptySceneUrl(),
author: null,
Expand Down

0 comments on commit 03051be

Please sign in to comment.