decentraland / decentraland/builder

[BUG] Import Scenes functionality breaks if not logged in due to incorrect if statement

Open
#2,340 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
156
Forks
91
Avg merge
2d 7h
Merged PRs (30d)
31

Description

## 🎉 Description
If the user is not logged in with an Ethereum account the Import Scene functionality of the builder breaks.

* [x] 🐛 This is a bug report.
* [ ] 📈 This is a feature request.

## 📝 Details

If the user is not logged in with an Ethereum account the Import Scene functionality of the builder breaks. The project is correctly stored to LocalStorage but it is not displayed on the UI, as there is a borken if statement that is validating the projects strictly comparing the ethAddress property to null, however the decentraland-dapp returns undefined if the address is not present.

## 🔢 Steps To Reproduce Issue

```
- Run the Builder (or access the production Builder)
- Try to import a Scene created with the Builder without being logged in
- The Scene will be added to LocalStorage, but not be showed in the UI
```

## 👍 Other Information

The way the code is written today should allow importing of Scenes without login, however this breaks the functionality. I already have a branch created locally to create a PR, could I contribute with this fix?

The fix should be strictly comparing with undefined or comparing it to a falsy value, as shown below:
```
export const getUserProjects = createSelector(getAddress, getData, (address, projects) => {
return Object.keys(projects).reduce((record, projectId) => {
const project = projects[projectId]
const isOwnedByUser = !!project.ethAddress && !!address && isEqual(project.ethAddress, address)
if (isOwnedByUser || project.ethAddress === undefined) {
record[projectId] = project
}
return record
}, {} as ProjectState['data'])
})
```

Or

```
export const getUserProjects = createSelector(getAddress, getData, (address, projects) => {
return Object.keys(projects).reduce((record, projectId) => {
const project = projects[projectId]
const isOwnedByUser = !!project.ethAddress && !!address && isEqual(project.ethAddress, address)
if (isOwnedByUser || !project.ethAddress) {
record[projectId] = project
}
return record
}, {} as ProjectState['data'])
})
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.