Skip to content

Commit

Permalink
fix: no-unsafe-enum-comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
LautaroPetaccio committed Mar 13, 2024
1 parent f68580c commit 447b56c
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 44 deletions.
3 changes: 1 addition & 2 deletions webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ module.exports = {
'@typescript-eslint/no-unsafe-member-access': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-member-access/
'@typescript-eslint/no-unsafe-argument': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-argument/
'@typescript-eslint/no-explicit-any': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-explicit-any
'import/order': 'off', // TODO: migrate code progressively to remove this line.
'@typescript-eslint/no-unsafe-enum-comparison': 'off'
'import/order': 'off' // TODO: migrate code progressively to remove this line.
},
parserOptions: {
project: ['./tsconfig.json']
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/AccountSidebar/AccountSidebar.types.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Dispatch } from 'redux'
import { browse, BrowseAction } from '../../modules/routing/actions'
import { Section } from '../../modules/vendor/decentraland'

export type Props = {
section: string
section: Section
address: string
isCurrentAccount?: boolean
onBrowse: typeof browse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { AssetType } from '../../../modules/asset/types'
import { BrowseOptions } from '../../../modules/routing/types'
import { Section } from '../../../modules/vendor/decentraland'

export type Props = {
section: string
section: Section
address: string
assetType: AssetType
onBrowse: (options: BrowseOptions) => void
Expand Down
29 changes: 15 additions & 14 deletions webapp/src/components/AssetFilters/PriceFilter/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { NFTCategory } from '@dcl/schemas'
import { ethers } from 'ethers'
import { getCategoryFromSection, getSearchEmoteCategory, getSearchWearableCategory } from '../../../modules/routing/search'
import { PriceFilterExtraOption, PriceFilters, Section } from '../../../modules/vendor/decentraland'
import { isOfEnumType } from '../../../utils/enums'

const LAND_MAX_PRICE_ALLOWED = ethers.BigNumber.from('1000000000000000000000000000') // 1B

Expand All @@ -11,21 +12,21 @@ const WEARABLES_MAX_PRICE_ALLOWED = ethers.BigNumber.from('100000000000000000000

export const getChartUpperBound = (section: string) => {
let upperBound = WEARABLES_MAX_PRICE_ALLOWED
switch (section) {
case Section.LAND:
case Section.ESTATES:
case Section.PARCELS:
upperBound = LAND_MAX_PRICE_ALLOWED
break
case Section.ENS:
upperBound = ENS_MAX_PRICE_ALLOWED
break

default:
upperBound = WEARABLES_MAX_PRICE_ALLOWED
break
if (isOfEnumType(section, Section)) {
switch (section) {
case Section.LAND:
case Section.ESTATES:
case Section.PARCELS:
upperBound = LAND_MAX_PRICE_ALLOWED
break
case Section.ENS:
upperBound = ENS_MAX_PRICE_ALLOWED
break
default:
upperBound = WEARABLES_MAX_PRICE_ALLOWED
break
}
}

return upperBound
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export const StatusFilter = ({ status, onChange, defaultCollapsed = false }: Sta
const isMobileOrTablet = useTabletAndBelowMediaQuery()
const statusOptions = useMemo(
() =>
Object.keys(AssetStatusFilter).map(opt => ({
value: opt.toLocaleLowerCase(),
Object.values(AssetStatusFilter).map(opt => ({
value: opt,
text: t(`nft_filters.status.${opt.toLocaleLowerCase()}`)
})),
[]
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/AssetImage/AssetImage.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { Dispatch } from 'redux'
import { Avatar, IPreviewController, Item, Order, Rarity } from '@dcl/schemas'
import { Avatar, IPreviewController, Item, Order, Rarity, Network } from '@dcl/schemas'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import {
setIsTryingOn,
Expand Down Expand Up @@ -89,5 +89,5 @@ export type AvailableForMintPopupType = {
rarity: Rarity
contractAddress: string
itemId: string
network: string
network: Network
}
2 changes: 1 addition & 1 deletion webapp/src/components/AssetImage/AvailableForMintPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const AvailableForMintPopup = ({ price, stock, rarity, contractAddress, itemId,
</span>
<div className="containerRow">
<div className="informationBold">
<Mana withTooltip size="large" network={network as Network} className="informationBold">
<Mana withTooltip size="large" network={network} className="informationBold">
{formatWeiToAssetCard(price)}
</Mana>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const SelectedFilters = ({ browseOptions, isLandSection, category, onBrow

const handleDeleteRarity = useCallback(
(rarity: string) => {
onBrowse({ rarities: rarities?.filter((r: Rarity) => r !== rarity) })
onBrowse({ rarities: rarities?.filter((r: Rarity) => r !== (rarity as Rarity)) })
},
[onBrowse, rarities]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export const BuyWithCryptoModal = (props: Props) => {
}, [providerChains, selectedChain])

const chainNativeToken = useMemo(() => {
return providerTokens.find(t => +t.chainId === selectedChain && t.symbol === selectedProviderChain?.nativeCurrency.symbol)
return providerTokens.find(
t => +t.chainId.toString() === selectedChain.toString() && t.symbol === selectedProviderChain?.nativeCurrency.symbol
)
}, [selectedChain, selectedProviderChain, providerTokens])

const { gasCost, isFetchingGasCost } = onGetGasCost(selectedToken, chainNativeToken, wallet)
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/SuccessPage/SuccessPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { NFTCategory } from '@dcl/schemas'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { locations } from '../../modules/routing/locations'
import { config } from '../../config'
import { isOfEnumType } from '../../utils/enums'
import { Footer } from '../Footer'
import { Asset, AssetType } from '../../modules/asset/types'
import { AssetImage } from '../AssetImage'
Expand Down Expand Up @@ -38,7 +39,7 @@ export function SuccessPage(props: Props) {
const search = new URLSearchParams(useLocation().search)
const contractAddress = search.get('contractAddress')
const tokenId = search.get('tokenId')
const assetType = search.get('assetType')
const assetType = isOfEnumType(search.get('assetType'), AssetType) ? (search.get('assetType') as AssetType) : null
const subdomain = search.get('subdomain')

// this is a workaround to show the NAME while the transaction is being mined or the tokenId getting retrieved.
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/modules/nft/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ export function getNFT(contractAddress: string | null, tokenId: string | null, n

export const getBodyShapeUrn = (bodyShape: string) => `urn:decentraland:off-chain:base-avatars:${bodyShape}`

export function isGender(bodyShapes: BodyShape[], gender: BodyShape) {
export function isGender(bodyShapes: (BodyShape | string)[], gender: BodyShape): boolean {
if (bodyShapes.length !== 1) {
return false
}
return bodyShapes[0] === gender || getBodyShapeUrn(bodyShapes[0]) === gender
return bodyShapes[0] === gender.toString() || getBodyShapeUrn(bodyShapes[0]) === gender.toString()
}

export function isUnisex(bodyShapes: BodyShape[]) {
Expand Down
15 changes: 8 additions & 7 deletions webapp/src/modules/routing/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {
GO_BACK,
GoBackAction
} from './actions'
import { BrowseOptions, Sections } from './types'
import { BrowseOptions } from './types'
import { Section } from '../vendor/decentraland'
import { getClearedBrowseOptions, isCatalogView, rentalFilters, SALES_PER_PAGE, sellFilters, buildBrowseURL } from './utils'
import { FetchSalesFailureAction, fetchSalesRequest, FETCH_SALES_FAILURE, FETCH_SALES_SUCCESS } from '../sale/actions'
Expand All @@ -83,6 +83,7 @@ import {
ClaimNameSuccessAction,
ClaimNameTransactionSubmittedAction
} from '../ens/actions'
import { isOfEnumType } from '../../utils/enums'
import { DCLRegistrar__factory } from '../../contracts/factories/DCLRegistrar__factory'
import { REGISTRAR_ADDRESS } from '../ens/sagas'

Expand Down Expand Up @@ -168,7 +169,7 @@ export function* fetchAssetsFromRoute(options: BrowseOptions) {
const view = options.view!
const vendor = options.vendor!
const page = options.page!
const section = options.section!
const section = options.section && isOfEnumType(options.section, Section) ? options.section : undefined
const sortBy = options.sortBy!
const {
search,
Expand All @@ -193,7 +194,7 @@ export function* fetchAssetsFromRoute(options: BrowseOptions) {
yield put(setView(view))
}

const category = getCategoryFromSection(section)
const category = section ? getCategoryFromSection(section) : undefined

const currentPageInState: number = yield select(getPage)
const offset = currentPageInState && currentPageInState < page ? page - 1 : 0
Expand Down Expand Up @@ -240,12 +241,12 @@ export function* fetchAssetsFromRoute(options: BrowseOptions) {
)
break
default: {
const isWearableHead = section === Sections[VendorName.DECENTRALAND].WEARABLES_HEAD
const isWearableAccessory = section === Sections[VendorName.DECENTRALAND].WEARABLES_ACCESSORIES
const isWearableHead = section === Section.WEARABLES_HEAD
const isWearableAccessory = section === Section.WEARABLES_ACCESSORIES

const wearableCategory = !isWearableAccessory ? getSearchWearableCategory(section) : undefined
const wearableCategory = !isWearableAccessory && section ? getSearchWearableCategory(section) : undefined

const emoteCategory = category === NFTCategory.EMOTE ? getSearchEmoteCategory(section) : undefined
const emoteCategory = category === NFTCategory.EMOTE && section ? getSearchEmoteCategory(section) : undefined

const { rarities, wearableGenders, emotePlayMode } = options

Expand Down
19 changes: 16 additions & 3 deletions webapp/src/modules/routing/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Section } from '../vendor/decentraland'
import { NFTSortBy } from '../nft/types'
import { isAccountView, isLandSection } from '../ui/utils'
import { AssetStatusFilter } from '../../utils/filters'
import { isOfEnumType } from '../../utils/enums'
import { AssetType } from '../asset/types'
import { isCatalogView, isCatalogViewWithStatusFilter } from './utils'

Expand Down Expand Up @@ -161,7 +162,11 @@ export function getSearchParams(options?: BrowseOptions) {
return params
}

export function getCategoryFromSection(section: string) {
export function getCategoryFromSection(section: string): NFTCategory | undefined {
if (!isOfEnumType(section, Section)) {
return undefined
}

switch (section) {
case Section.PARCELS:
return NFTCategory.PARCEL
Expand Down Expand Up @@ -246,7 +251,11 @@ export function getSearchSection(category: WearableCategory | EmoteCategory) {
}
}

export function getSearchWearableCategory(section: string) {
export function getSearchWearableCategory(section: string): WearableCategory | undefined {
if (!isOfEnumType(section, Section)) {
return undefined
}

switch (section) {
case Section.WEARABLES_EYEBROWS:
return WearableCategory.EYEBROWS
Expand Down Expand Up @@ -285,7 +294,11 @@ export function getSearchWearableCategory(section: string) {
}
}

export function getSearchEmoteCategory(section: string) {
export function getSearchEmoteCategory(section: string): EmoteCategory | undefined {
if (!isOfEnumType(section, Section)) {
return undefined
}

switch (section) {
case Section.EMOTES_DANCE:
return EmoteCategory.DANCE
Expand Down
9 changes: 7 additions & 2 deletions webapp/src/modules/routing/selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { getSearch as getRouterSearch, getLocation } from 'connected-react-route
import { EmotePlayMode, GenderFilterOption, Network, Rarity } from '@dcl/schemas'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { AssetStatusFilter } from '../../utils/filters'
import { isOfEnumType } from '../../utils/enums'
import { getView } from '../ui/browse/selectors'
import { View } from '../ui/types'
import { VendorName } from '../vendor/types'
Expand Down Expand Up @@ -53,7 +54,11 @@ export const getSection = createSelector<RootState, string, ReturnType<typeof ge
return Sections.decentraland.LAND
}

if ((!section || section === Sections[vendor].ALL) && pathname === locations.browse() && vendor === VendorName.DECENTRALAND) {
if (
(!section || (isOfEnumType(section, Sections[vendor]) && section === Sections[vendor].ALL)) &&
pathname === locations.browse() &&
vendor === VendorName.DECENTRALAND
) {
return Sections.decentraland.WEARABLES
}

Expand Down Expand Up @@ -146,7 +151,7 @@ export const getSortByOptions = createSelector<RootState, boolean | undefined, b
(onlyOnRent, onlyOnSale, status) => {
const SORT_BY_MAP = getAllSortByOptions()
let orderByDropdownOptions: SortByOption[] = []
if (status) {
if (status && isOfEnumType(status, AssetStatusFilter)) {
const baseFilters = [
SORT_BY_MAP[SortBy.NEWEST],
SORT_BY_MAP[SortBy.RECENTLY_LISTED],
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/modules/store/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BuildEntityWithoutFilesOptions } from 'dcl-catalyst-client/dist/client/
import { EntityContentItemReference } from 'dcl-catalyst-commons'
import { peerUrl } from '../../lib/environment'
import { convertToOutputString } from '../../utils/output'
import { isOfEnumType } from '../../utils/enums'
import { LinkType, Store, StoreEntityMetadata } from './types'

export const getPeerCoverUrl = (hash: string) => `${peerUrl}/content/contents/${hash}`
Expand Down Expand Up @@ -48,7 +49,7 @@ export const getStoreFromEntity = (entity: Entity): Store => {
coverName = reference.file
}

const getLink = (type: LinkType) => metadata.links.find(link => link.name === type)?.url || ''
const getLink = (type: LinkType) => metadata.links.find(link => isOfEnumType(link.name, LinkType) && link.name === type)?.url || ''

return {
cover,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/modules/ui/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function* handleSetWearablePreviewController(action: SetWearablePreviewControlle
try {
while (true) {
try {
const event: string = yield take(emotesChannel)
const event: PreviewEmoteEventType = yield take(emotesChannel)
switch (event) {
case PreviewEmoteEventType.ANIMATION_PLAY:
yield put(setEmotePlaying(true))
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/modules/vendor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getFilters(vendor: VendorName, options: BrowseOptions): NFTsFetc
const isWearableHead = section === currentSection.WEARABLES_HEAD
const isWearableAccessory = section === currentSection.WEARABLES_ACCESSORIES

const category = getCategoryFromSection(section!)
const category = section ? getCategoryFromSection(section) : undefined
const wearableCategory = !isWearableAccessory && category === NFTCategory.WEARABLE ? getSearchWearableCategory(section!) : undefined

const emoteCategory = category === NFTCategory.EMOTE ? getSearchEmoteCategory(section!) : undefined
Expand Down Expand Up @@ -79,7 +79,7 @@ export function getOriginURL(vendor: VendorName) {
}
}

export function isVendor(vendor: string) {
export function isVendor(vendor: string): vendor is VendorName {
return Object.values(VendorName).includes(vendor as VendorName)
}

Expand Down

0 comments on commit 447b56c

Please sign in to comment.