Skip to content

Commit

Permalink
feat: Filter exotic rarity (#3079)
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio committed Apr 15, 2024
1 parent a6ed197 commit f45c7d4
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import {
getUnsyncedCollectionError,
getError as getCollectionError
} from 'modules/collection/selectors'
import { getLoading as getItemLoading, getCollectionItems, getError as getItemError } from 'modules/item/selectors'
import { getLoading as getItemLoading, getCollectionItems, getError as getItemError, getFilteredRarities } from 'modules/item/selectors'
import { publishCollectionRequest, PUBLISH_COLLECTION_REQUEST } from 'modules/collection/actions'
import { CREATE_COLLECTION_FORUM_POST_REQUEST } from 'modules/forum/actions'
import { fetchRaritiesRequest, FETCH_RARITIES_REQUEST, FETCH_ITEMS_REQUEST } from 'modules/item/actions'
import { getRarities } from 'modules/item/selectors'
import { getIsPublishCollectionsWertEnabled } from 'modules/features/selectors'
import { OwnProps, MapStateProps, MapDispatchProps, MapDispatch } from './PublishWizardCollectionModal.types'
import PublishWizardCollectionModal from './PublishWizardCollectionModal'
Expand All @@ -30,7 +29,7 @@ const mapState = (state: RootState, ownProps: OwnProps): MapStateProps => {
wallet: getWallet(state)!,
collection,
items: getCollectionItems(state, collectionId),
rarities: getRarities(state),
rarities: getFilteredRarities(state),
unsyncedCollectionError: getUnsyncedCollectionError(state),
itemError: getItemError(state),
collectionError: getCollectionError(state),
Expand Down
64 changes: 61 additions & 3 deletions src/modules/item/selectors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { mockedItem } from 'specs/item'
import { ItemState } from './reducer'
import {
getAuthorizedItems,
getFilteredRarities,
getItem,
getItems,
getPaginatedCollectionItems,
Expand Down Expand Up @@ -64,9 +65,12 @@ describe('Item selectors', () => {
pages: 1,
page: 1
}
}
},
rarities: [{ id: Rarity.COMMON, name: Rarity.COMMON, price: '100', maxSupply: 100 }]
},
rarities: [
{ id: Rarity.COMMON, name: Rarity.COMMON, price: '100', maxSupply: 100 },
{ id: Rarity.EXOTIC, name: Rarity.EXOTIC, price: '100', maxSupply: 50 }
]
}
} as any
})

Expand Down Expand Up @@ -180,6 +184,60 @@ describe('Item selectors', () => {
})
})

describe('when getting the filtered rarities', () => {
describe('and the feature flag is enabled', () => {
beforeEach(() => {
state = {
...state,
features: {
data: {
dapps: {
name: 'dapps',
flags: {
'dapps-exotic-rarity': true
},
variants: {}
}
},
error: null,
loading: [],
hasLoadedInitialFlags: true
}
} as RootState
})

it('should return the rarities with the exotic rarity', () => {
expect(getFilteredRarities(state)).toEqual(state.item.rarities)
})
})

describe('and the feature flag is not enabled', () => {
beforeEach(() => {
state = {
...state,
features: {
data: {
dapps: {
name: 'dapps',
flags: {
'dapps-exotic-rarity': false
},
variants: {}
}
},
error: null,
loading: [],
hasLoadedInitialFlags: true
}
} as RootState
})

it('should return the rarities without the exotic rarity', () => {
expect(getFilteredRarities(state)).toEqual(state.item.rarities.filter(rarity => rarity.name !== Rarity.EXOTIC))
})
})
})

describe('when getting the rarities', () => {
it('should return the rarities', () => {
expect(getRarities(state)).toEqual(state.item.rarities)
Expand Down
10 changes: 9 additions & 1 deletion src/modules/item/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Entity } from '@dcl/schemas'
import { Entity, Rarity } from '@dcl/schemas'
import { createSelector } from 'reselect'
import { isLoadingType } from 'decentraland-dapps/dist/modules/loading/selectors'
import { getAddress } from 'decentraland-dapps/dist/modules/wallet/selectors'
Expand All @@ -13,6 +13,7 @@ import { ItemCuration } from 'modules/curations/itemCuration/types'
import { getItemCurationsByItemId } from 'modules/curations/itemCuration/selectors'
import { CurationStatus } from 'modules/curations/types'
import { getItemThirdParty } from 'modules/thirdParty/selectors'
import { getIsExoticRarityEnabled } from 'modules/features/selectors'
import { isUserManagerOfThirdParty } from 'modules/thirdParty/utils'
import { isEqual } from 'lib/address'
import { buildCatalystItemURN, isThirdParty } from '../../lib/urn'
Expand Down Expand Up @@ -84,6 +85,13 @@ export const getRarities = (state: RootState): BlockchainRarity[] => {
return getState(state).rarities
}

// Temporal rarity selector to filter out the exotic rarity in accordance to the feature flag
export const getFilteredRarities = createSelector<RootState, boolean, BlockchainRarity[], BlockchainRarity[]>(
getIsExoticRarityEnabled,
getRarities,
(isExoticRarityEnabled, rarities) => rarities.filter(rarity => isExoticRarityEnabled || rarity.name !== Rarity.EXOTIC)
)

export const getWearables = createSelector<RootState, Item[], Item[]>(getItems, items =>
items.filter(item => item.type === ItemType.WEARABLE)
)
Expand Down

0 comments on commit f45c7d4

Please sign in to comment.