Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Linting rules (no-floating-promises) #2187

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions webapp/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ module.exports = {
files: ['*.ts', '*.tsx', '*.cjs'],
extends: ['plugin:@typescript-eslint/recommended', 'plugin:@typescript-eslint/recommended-requiring-type-checking', 'prettier'],
rules: {
'@typescript-eslint/no-floating-promises': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-floating-promises
'@typescript-eslint/no-unsafe-return': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-return
'@typescript-eslint/naming-convention': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/naming-convention/
'@typescript-eslint/explicit-module-boundary-types': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/explicit-module-boundary-types
'@typescript-eslint/ban-ts-comment': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/ban-ts-comment
'@typescript-eslint/no-unsafe-assignment': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-assignment/
'@typescript-eslint/no-unsafe-call': 'off', // TODO: migrate code progressively to remove this line. https://typescript-eslint.io/rules/no-unsafe-call/
Expand Down
14 changes: 4 additions & 10 deletions webapp/src/components/AccountPage/AccountBanner/AccountBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react'
import React, { useState, useEffect, useCallback } from 'react'
import { Back, Container, Loader } from 'decentraland-ui'
import { Icon } from 'semantic-ui-react'
import classNames from 'classnames'
Expand All @@ -20,8 +20,8 @@

const AccountBanner = ({ address, store, isLoading, onBack, onFetchStore }: Props) => {
const [hasCopiedAddress, setHasCopied] = useTimer(1200)

const [openExternalLinkModal, setOpenExternalLinkModal] = useState<string>()
const handleCopy = useCallback(() => copyText(address, setHasCopied), [address, setHasCopied])

useEffect(() => {
onFetchStore(address)
Expand Down Expand Up @@ -59,20 +59,14 @@
<div className="profile-address-hash">{shortenAddress(address)}</div>
{!isMobile() && (
<div>
<Icon
onClick={() => copyText(address, setHasCopied)}
aria-label="Copy address"
aria-hidden="false"
className="copy"
name="copy outline"
/>
<Icon onClick={handleCopy} aria-label="Copy address" aria-hidden="false" className="copy" name="copy outline" />
{hasCopiedAddress && <span className="profile-copied-text-desktop copied">{t('account_page.copied')}</span>}
</div>
)}
</div>
{isMobile() && (
<div className="profile-copy-text-mobile">
<div role="button" aria-label="copy" onClick={() => copyText(address, setHasCopied)}>
<div role="button" aria-label="copy" onClick={handleCopy}>
{hasCopiedAddress ? (
<span className="copied">{t('account_page.copied_capitalized')}</span>
) : (
Expand All @@ -91,4 +85,4 @@
)
}

export default React.memo(AccountBanner)

Check warning on line 88 in webapp/src/components/AccountPage/AccountBanner/AccountBanner.tsx

View workflow job for this annotation

GitHub Actions / lint

Caution: `React` also has a named export `memo`. Check if you meant to write `import {memo} from 'react'` instead

Check warning on line 88 in webapp/src/components/AccountPage/AccountBanner/AccountBanner.tsx

View workflow job for this annotation

GitHub Actions / lint

Caution: `React` also has a named export `memo`. Check if you meant to write `import {memo} from 'react'` instead
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ export const CollectionFilter = ({ collection, onlyOnSale, onChange, defaultColl
)

useEffect(() => {
if (collection && collection !== savedCollectionInfo?.value) {
handleFetchOptionsFromValue(collection)
}

if (!collection) {
setSavedCollectionInfo(null)
const setCollectionInfo = async () => {
if (collection && collection !== savedCollectionInfo?.value) {
await handleFetchOptionsFromValue(collection)
} else if (!collection) {
setSavedCollectionInfo(null)
}
}
void setCollectionInfo()
}, [collection, savedCollectionInfo, handleFetchOptionsFromValue])

const header = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,17 @@ export const CreatorsFilter = ({
)

useEffect(() => {
if (creators?.length) {
setIsFetchingNames(true)
ProfilesCache.fetchProfile(creators).then(profiles => {
const fetchCreators = async () => {
if (creators?.length) {
setIsFetchingNames(true)
const profiles = await ProfilesCache.fetchProfile(creators)
setSelectedCreators(profileToCreatorAccount(profiles))
setIsFetchingNames(false)
})
} else if (!creators?.length) {
setSelectedCreators([])
} else if (!creators?.length) {
setSelectedCreators([])
}
}
void fetchCreators()
}, [creators])

const handleCreatorsChange = useCallback(
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/AssetFilters/Inventory/Inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const Inventory = ({

useEffect(() => {
let cancel = false
;(async () => {
void (async () => {
try {
setIsLoading(true)
const data = await fetcher()
Expand Down
12 changes: 7 additions & 5 deletions webapp/src/components/AssetImage/AssetImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ const AssetImage = (props: Props) => {
)

useEffect(() => {
if (asset.category === NFTCategory.EMOTE && wearableController && isDraggable && !isLoadingWearablePreview) {
wearableController.emote?.hasSound().then(sound => {
const getHasSound = async () => {
if (asset.category === NFTCategory.EMOTE && wearableController && isDraggable && !isLoadingWearablePreview) {
const sound = await wearableController.emote?.hasSound()
setHasSound(sound)
})
}
}
void getHasSound
}, [wearableController, asset.category, isDraggable, hasSound, isLoadingWearablePreview])

const estateSelection = useMemo(() => (estate ? getSelection(estate) : []), [estate])
Expand Down Expand Up @@ -422,8 +424,8 @@ const AssetImage = (props: Props) => {
})}
size="small"
aria-label="enable sound"
onClick={() => {
handleControlActionChange(isSoundEnabled ? ControlOptionAction.DISABLE_SOUND : ControlOptionAction.ENABLE_SOUND)
onClick={async () => {
await handleControlActionChange(isSoundEnabled ? ControlOptionAction.DISABLE_SOUND : ControlOptionAction.ENABLE_SOUND)
setIsSoundEnabled(!isSoundEnabled)
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,34 @@ export const SelectedFilters = ({ browseOptions, isLandSection, category, onBrow
const [selectedCreators, setSelectedCreators] = useState<Pick<CreatorAccount, 'address' | 'name'>[]>()

useEffect(() => {
const fetchData = async (contract: string) => {
const collection = await getCollectionByAddress(contract)
return collection
}
const getCollections = async () => {
if (contracts?.length) {
const collections = await Promise.all(contracts.map(contract => getCollectionByAddress(contract)))

if (contracts?.length) {
const promises = contracts.map(contract => fetchData(contract))
Promise.all(promises).then(collections => {
setCollections(
collections.map(collection => ({
address: collection.contractAddress,
name: collection.name
}))
)
})
} else if (!contracts?.length) {
setCollections([])
} else if (!contracts?.length) {
setCollections([])
}
}

void getCollections()
}, [contracts, onlyOnSale])

useEffect(() => {
if (creators?.length) {
ProfilesCache.fetchProfile(creators).then(profiles => {
const getCreators = async () => {
if (creators?.length) {
const profiles = await ProfilesCache.fetchProfile(creators)
setSelectedCreators(profileToCreatorAccount(profiles))
})
} else if (!creators?.length) {
setSelectedCreators([])
} else if (!creators?.length) {
setSelectedCreators([])
}
}
void getCreators()
}, [creators])

const priceLabel = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const CampaignBadge = ({ contract, isCampaignBrowserEnabled }: Props) => {
}, [contracts])

useEffect(() => {
;(async () => {
void (async () => {
try {
if (isCampaignBrowserEnabled) {
const addresses = await builderAPI.fetchAddressesByTag([CAMPAIGN_TAG])
Expand Down
45 changes: 22 additions & 23 deletions webapp/src/components/ManaToFiat/ManaToFiat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@ const ManaToFiat = (props: Props) => {

useEffect(() => {
let cancel = false
try {
const value = parseFloat(utils.formatEther(mana))
new TokenConverter()
.marketMANAToUSD(value)
.then(usd => {
const divider =
usd > ONE_TRILLION.value
? ONE_TRILLION
: usd > ONE_BILLION.value
? ONE_BILLION
: usd > ONE_MILLION.value
? ONE_MILLION
: { value: 1, displayValue: '' }
if (cancel) return
setFiatValue(
`$${(+(+usd / divider.value).toFixed(digits)).toLocaleString(undefined, {
maximumFractionDigits: digits
})}${divider.displayValue}`
)
})
.catch()
} catch (error) {
// do nothing
const computeFiatValue = async () => {
try {
const value = parseFloat(utils.formatEther(mana))
const usd = await new TokenConverter().marketMANAToUSD(value)
const divider =
usd > ONE_TRILLION.value
? ONE_TRILLION
: usd > ONE_BILLION.value
? ONE_BILLION
: usd > ONE_MILLION.value
? ONE_MILLION
: { value: 1, displayValue: '' }
if (cancel) return
setFiatValue(
`$${(+(+usd / divider.value).toFixed(digits)).toLocaleString(undefined, {
maximumFractionDigits: digits
})}${divider.displayValue}`
)
} catch (error) {
// do nothing
}
}
void computeFiatValue()
return () => {
cancel = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const BuyWithCryptoModal = (props: Props) => {
setCrossChainProvider(provider)
}

initializeCrossChainProvider()
void initializeCrossChainProvider()
}, [])

const { isFetchingBalance, tokenBalance: selectedTokenBalance } = useTokenBalance(selectedToken, selectedChain, wallet?.address)
Expand All @@ -135,7 +135,7 @@ export const BuyWithCryptoModal = (props: Props) => {

// init lib if necessary and fetch chains & supported tokens
useEffect(() => {
;(async () => {
void (async () => {
try {
if (crossChainProvider) {
if (!crossChainProvider.isLibInitialized()) {
Expand Down Expand Up @@ -179,7 +179,7 @@ export const BuyWithCryptoModal = (props: Props) => {

// computes if the user can buy the item with the selected token
useEffect(() => {
;(async () => {
void (async () => {
if (
selectedToken &&
((selectedToken.symbol === 'MANA' && !!wallet) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const ChainAndTokenSelector = (props: Props) => {
setIsFetchingBalances(false)
}
}
fetchBalances()
void fetchBalances()
}, [currentChain, wallet.address])

const filteredTokens = useMemo(() => {
Expand Down
8 changes: 4 additions & 4 deletions webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const useTokenBalance = (selectedToken: Token, selectedChain: ChainId, ad
// fetch selected token balance & price
useEffect(() => {
let cancel = false
;(async () => {
void (async () => {
try {
setIsFetchingBalance(true)
if (
Expand Down Expand Up @@ -137,7 +137,7 @@ const useGasCost = (
}

if (!shouldUseCrossChainProvider && wallet && nativeChainToken && getNetwork(wallet.chainId) === assetNetwork) {
calculateGas()
void calculateGas()
} else {
setGasCost(undefined)
}
Expand Down Expand Up @@ -403,7 +403,7 @@ const useCrossChainRoute = (
}

interval = setInterval(() => {
calculateRoute()
return calculateRoute()
}, ROUTE_FETCH_INTERVAL)
}
return () => {
Expand All @@ -429,7 +429,7 @@ const useCrossChainRoute = (
const isPayingWithMANAButFromOtherChain = selectedToken.symbol === 'MANA' && selectedToken.chainId !== assetChainId.toString()

if (isBuyingL1WithOtherTokenThanEthereumMANA || isPayingWithOtherTokenThanMANA || isPayingWithMANAButFromOtherChain) {
calculateRoute()
void calculateRoute()
}
}
setRouteFailed(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const FavoritesModal = ({ metadata: { itemId }, identity, onClose }: Props) => {
)

useEffect(() => {
fetchNextPage(0, 100)
void fetchNextPage(0, 100)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ const SaveToListModal = (props: Props) => {
)

useEffect(() => {
fetchNextPage(0, 24)
void fetchNextPage(0, 24)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const ShareListModal = (props: Props) => {
onClose()
}, [onClose])

const handleCopyLink = useCallback(() => {
const handleCopyLink = useCallback(async () => {
const url = `${MARKETPLACE_URL}${listLink}`
getAnalytics().track(events.SHARE_LIST, {
list,
url,
type: events.SHARE_LIST_TYPE.COPY_LINK
})
copyText(url, setHasCopied)
await copyText(url, setHasCopied)
}, [list, listLink, setHasCopied])

const handleShareOnTwitter = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const ClaimNamePage = (props: Props) => {
const isMobileOrTable = useTabletAndBelowMediaQuery()

useEffect(() => {
;(async () => {
void (async () => {
try {
const bannedNames = await lists.fetchBannedNames()
setBannedNames(bannedNames)
Expand Down Expand Up @@ -87,7 +87,7 @@ const ClaimNamePage = (props: Props) => {
setName(text)
const timeoutId = setTimeout(() => {
if (debounceRef.current === timeoutId) {
handleNameChange(text)
return handleNameChange(text)
}
}, 1000)
if (debounceRef.current) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/SellPage/SellModal/SellModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const SellModal = (props: Props) => {
}
}

fetchContractName()
void fetchContractName()
}
}, [nftContract])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SelectFilter = (props: Props) => {
}
}

tryFetchOptionFromValue()
void tryFetchOptionFromValue()
}, [fetchOptionFromValue, providedOptions, value, onChange])

// The component will fetch the options from the backend depending on the search input.
Expand Down
Loading
Loading