Skip to content

Commit 4494dee

Browse files
authored
feat: Filter collections by category (#840)
* feat: Filter items using contracts that contains wearables or emotes * feat: Add emotes contracts to wallet authorizations * refactor: Reduce two ifs to one * feat: Avoid add twice the contracts for categories: wearables and emotes * fix: Clear filters when selecting emote play mode * refactor: Nested conditional
1 parent 21ece1c commit 4494dee

File tree

5 files changed

+42
-18
lines changed

5 files changed

+42
-18
lines changed

webapp/src/components/Vendor/NFTFilters/FiltersMenu/FiltersMenu.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,24 @@ const FiltersMenu = (props: Props) => {
5353
onOnlySmartChange
5454
} = props
5555

56+
// Emote category sends this param undefined
57+
const category =
58+
isOnlySmart !== undefined ? NFTCategory.WEARABLE : NFTCategory.EMOTE
59+
5660
const collectionOptions = useMemo(() => {
5761
return [
5862
{
5963
value: ALL_FILTER_OPTION,
6064
text: t('nft_filters.all_collections')
6165
},
6266
...getContracts(availableContracts)
63-
.filter(contract => contract.category === NFTCategory.WEARABLE)
67+
.filter(contract => contract.category === category)
6468
.map(contract => ({
6569
value: contract.address,
6670
text: contract.name
6771
}))
6872
]
69-
}, [availableContracts])
73+
}, [availableContracts, category])
7074

7175
const rarityOptions = useMemo(() => {
7276
const options = Object.values(Rarity)

webapp/src/modules/routing/sagas.spec.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { ItemSortBy, Network, NFTCategory, Rarity } from '@dcl/schemas'
1+
import {
2+
EmotePlayMode,
3+
ItemSortBy,
4+
Network,
5+
NFTCategory,
6+
Rarity
7+
} from '@dcl/schemas'
28
import { getLocation, push } from 'connected-react-router'
39
import { expectSaga } from 'redux-saga-test-plan'
410
import { call, select } from 'redux-saga/effects'
@@ -45,7 +51,8 @@ describe('when handling the clear filters request action', () => {
4551
rarities: [Rarity.EPIC],
4652
wearableGenders: [WearableGender.FEMALE],
4753
contracts: ['aContract'],
48-
network: Network.ETHEREUM
54+
network: Network.ETHEREUM,
55+
emotePlayMode: EmotePlayMode.SIMPLE
4956
}
5057

5158
const browseOptionsWithoutFilters: BrowseOptions = { ...browseOptions }
@@ -54,6 +61,7 @@ describe('when handling the clear filters request action', () => {
5461
delete browseOptionsWithoutFilters.network
5562
delete browseOptionsWithoutFilters.contracts
5663
delete browseOptionsWithoutFilters.page
64+
delete browseOptionsWithoutFilters.emotePlayMode
5765

5866
const pathname = 'aPath'
5967

webapp/src/modules/routing/sagas.ts

+1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ function* handleClearFilters() {
137137
'wearableGenders',
138138
'network',
139139
'contracts',
140+
'emotePlayMode',
140141
'page'
141142
])
142143

webapp/src/modules/routing/selectors.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,26 @@ export const hasFiltersEnabled = createSelector<
252252
WearableGender[],
253253
Rarity[],
254254
string[],
255+
string | undefined,
255256
boolean
256257
>(
257258
getNetwork,
258259
getWearableGenders,
259260
getRarities,
260261
getContracts,
261-
(network, genders, rarities, contracts) => {
262+
getEmotePlayMode,
263+
(network, genders, rarities, contracts, playMode) => {
262264
const hasNetworkFilter = network !== undefined
263265
const hasGenderFilter = genders.length > 0
264266
const hasRarityFilter = rarities.length > 0
265267
const hasContractsFilter = contracts.length > 0
268+
const hasEmotePlayModeFilter = playMode !== undefined
266269
return (
267270
hasNetworkFilter ||
268271
hasGenderFilter ||
269272
hasRarityFilter ||
270-
hasContractsFilter
273+
hasContractsFilter ||
274+
hasEmotePlayModeFilter
271275
)
272276
}
273277
)

webapp/src/modules/wallet/sagas.ts

+19-12
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,25 @@ function* handleWallet(
156156
network: contract.network
157157
})
158158

159-
authorizations.push({
160-
address,
161-
authorizedAddress: marketplace.address,
162-
contractAddress: contract.address,
163-
contractName:
164-
contract.category === NFTCategory.WEARABLE &&
165-
contract.network === Network.MATIC
166-
? ContractName.ERC721CollectionV2
167-
: ContractName.ERC721,
168-
chainId: contract.chainId,
169-
type: AuthorizationType.APPROVAL
170-
})
159+
if (
160+
(contract.category === NFTCategory.WEARABLE ||
161+
contract.category === NFTCategory.EMOTE) &&
162+
!authorizations.some(
163+
authorization => authorization.contractAddress === contract.address
164+
)
165+
) {
166+
authorizations.push({
167+
address,
168+
authorizedAddress: marketplace.address,
169+
contractAddress: contract.address,
170+
contractName:
171+
contract.network === Network.MATIC
172+
? ContractName.ERC721CollectionV2
173+
: ContractName.ERC721,
174+
chainId: contract.chainId,
175+
type: AuthorizationType.APPROVAL
176+
})
177+
}
171178

172179
// add authorizations for the rentals contract for the land and estate registries
173180
if (

0 commit comments

Comments
 (0)