Skip to content

Commit

Permalink
fix: No unsafe assignment (first PR) (#2207)
Browse files Browse the repository at this point in the history
* feat: No unsafe assigment

* fix: Lint order sagas

* fix: Lint more files

* fix: Lint more files

* fix: Unecessary typing
  • Loading branch information
LautaroPetaccio authored Apr 8, 2024
1 parent 1935854 commit b20d17b
Show file tree
Hide file tree
Showing 45 changed files with 428 additions and 402 deletions.

This file was deleted.

29 changes: 0 additions & 29 deletions webapp/src/components/AssetBrowse/RadioBox/RadioBox.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions webapp/src/components/AssetBrowse/RadioBox/RadioBox.types.ts

This file was deleted.

2 changes: 0 additions & 2 deletions webapp/src/components/AssetBrowse/RadioBox/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const StatusFilter = ({ status, onChange, defaultCollapsed = false }: Sta

const handleChange = useCallback(
(_evt, { value }) => {
let options: BrowseOptions = { status: value }
let options: BrowseOptions = { status: value as AssetStatusFilter }
if (value === AssetStatusFilter.NOT_FOR_SALE) {
options = { ...options, minPrice: undefined, maxPrice: undefined }
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/AssetList/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const AssetList = (props: Props) => {
}, [])

const handleLoadMore = useCallback(
newPage => {
(newPage: number) => {
onBrowse({ page: newPage })
getAnalytics().track(events.LOAD_MORE, { page: newPage })
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createRef, RefObject } from 'react'
import { Bid, ChainId, Item, ListingStatus, Network, NFTCategory, Order, Rarity } from '@dcl/schemas'
import * as containersModule from 'decentraland-dapps/dist/containers'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { formatWeiMANA } from '../../../lib/mana'
import * as bidAPI from '../../../modules/vendor/decentraland/bid/api'
Expand All @@ -11,7 +12,7 @@ jest.mock('../../../modules/vendor/decentraland/nft/api')
jest.mock('../../../modules/vendor/decentraland/order/api')
jest.mock('../../../modules/vendor/decentraland/bid/api')
jest.mock('decentraland-dapps/dist/containers', () => {
const module = jest.requireActual('decentraland-dapps/dist/containers')
const module = jest.requireActual<typeof containersModule>('decentraland-dapps/dist/containers')
return {
...module,
Profile: () => <div></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { waitFor } from '@testing-library/react'
import { ChainId, Item, ListingStatus, Network, NFTCategory, Order, Rarity } from '@dcl/schemas'
import * as containersModule from 'decentraland-dapps/dist/containers'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { formatDistanceToNow, getDateAndMonthName } from '../../../lib/date'
import { formatWeiMANA } from '../../../lib/mana'
Expand All @@ -12,7 +13,7 @@ import ListingsTable from './ListingsTable'
jest.mock('../../../modules/vendor/decentraland/nft/api')
jest.mock('../../../modules/vendor/decentraland/order/api')
jest.mock('decentraland-dapps/dist/containers', () => {
const module = jest.requireActual('decentraland-dapps/dist/containers')
const module = jest.requireActual<typeof containersModule>('decentraland-dapps/dist/containers')
return {
...module,
Profile: () => <div></div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { waitFor } from '@testing-library/react'
import { ChainId, Item, Network, NFTCategory, Rarity } from '@dcl/schemas'
import * as containersModule from 'decentraland-dapps/dist/containers'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { OwnersResponse } from '../../../modules/vendor/decentraland'
import * as nftAPI from '../../../modules/vendor/decentraland/nft/api'
Expand All @@ -10,7 +11,7 @@ const ownerIdMock = '0x92712b730b9a474f99a47bb8b1750190d5959a2b'

jest.mock('../../../modules/vendor/decentraland/nft/api')
jest.mock('decentraland-dapps/dist/containers', () => {
const module = jest.requireActual('decentraland-dapps/dist/containers')
const module = jest.requireActual<typeof containersModule>('decentraland-dapps/dist/containers')
return {
...module,
Profile: () => <div>{ownerIdMock}</div>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Modals/BuyWithCryptoModal/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const useTokenBalance = (selectedToken: Token, selectedChain: ChainId, ad
['function balanceOf(address owner) view returns (uint256)'],
provider
)
const balance: BigNumber = await tokenContract.balanceOf(address)
const balance = (await tokenContract.balanceOf(address)) as BigNumber

if (!cancel) {
setSelectedTokenBalance(balance)
Expand Down
8 changes: 5 additions & 3 deletions webapp/src/modules/asset/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function* handleSetAssetPurchaseWithCard(action: SetPurchaseAction) {
const { purchase } = action.payload
if (isNFTPurchase(purchase)) {
const { nft, status } = purchase
const { pathname }: ReturnType<typeof getLocation> = yield select(getLocation)
const { pathname } = (yield select(getLocation)) as ReturnType<typeof getLocation>

const { tradeType, contractAddress, tokenId, itemId } = nft
const assetType: AssetType = tradeType === TradeType.PRIMARY ? AssetType.ITEM : AssetType.NFT
Expand Down Expand Up @@ -69,7 +69,9 @@ function* handleFetchSmartWearableRequiredPermissionsRequest(action: FetchSmartW
} = asset

if (wearable?.isSmart && urn) {
requiredPermissions = yield call(getSmartWearableRequiredPermissions, urn)
requiredPermissions = (yield call(getSmartWearableRequiredPermissions, urn)) as Awaited<
ReturnType<typeof getSmartWearableRequiredPermissions>
>
}

yield put(fetchSmartWearableRequiredPermissionsSuccess(asset, requiredPermissions))
Expand All @@ -89,7 +91,7 @@ function* handleFetchSmartWearableVideoHashRequest(action: FetchSmartWearableVid
} = asset

if (wearable?.isSmart && urn) {
videoHash = yield call(getSmartWearableVideoShowcase, asset)
videoHash = (yield call(getSmartWearableVideoShowcase, asset)) as Awaited<ReturnType<typeof getSmartWearableVideoShowcase>>
}

yield put(fetchSmartWearableVideoHashSuccess(asset, videoHash))
Expand Down
9 changes: 6 additions & 3 deletions webapp/src/modules/asset/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ export function isWearableOrEmote(asset: Asset): boolean {
}

export function* buyAssetWithCard(asset: Asset) {
const buyNftsWithCardExplanationPopupKey: string | null = yield call([localStorage, 'getItem'], BUY_NFTS_WITH_CARD_EXPLANATION_POPUP_KEY)
const buyNftsWithCardExplanationPopupKey = (yield call(
[localStorage, 'getItem'],
BUY_NFTS_WITH_CARD_EXPLANATION_POPUP_KEY
)) as ReturnType<typeof localStorage.getItem>

if (buyNftsWithCardExplanationPopupKey === 'true') {
yield put(openTransak(asset))
Expand All @@ -109,10 +112,10 @@ export function* buyAssetWithCard(asset: Asset) {

yield put(openModal('BuyWithCardExplanationModal', { asset }))

const { close }: { close: CloseModalAction } = yield race({
const { close } = (yield race({
continue: take(SET_PURCHASE),
close: take(CLOSE_MODAL)
})
})) as { close: CloseModalAction }

if (close) {
return
Expand Down
61 changes: 41 additions & 20 deletions webapp/src/modules/bid/sagas.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { takeEvery, put, select, call } from 'redux-saga/effects'
import { Bid, RentalListing, RentalStatus } from '@dcl/schemas'
import { takeEvery, put, select, call, all } from 'redux-saga/effects'
import { Bid, RentalStatus } from '@dcl/schemas'
import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { isErrorWithMessage } from '../../lib/error'
import { getContract } from '../contract/selectors'
import { getCurrentNFT } from '../nft/selectors'
import { NFT } from '../nft/types'
import { getRentalById } from '../rental/selectors'
import { isRentalListingOpen, waitUntilRentalChangesStatus } from '../rental/utils'
import { VendorName } from '../vendor/types'
import { Vendor, VendorFactory } from '../vendor/VendorFactory'
import { VendorFactory } from '../vendor/VendorFactory'
import { getWallet } from '../wallet/selectors'
import {
PLACE_BID_REQUEST,
Expand Down Expand Up @@ -47,10 +46,19 @@ function* handlePlaceBidRequest(action: PlaceBidRequestAction) {
const { nft, price, expiresAt, fingerprint } = action.payload
try {
const { bidService } = VendorFactory.build(nft.vendor)
const wallet = (yield select(getWallet)) as ReturnType<typeof getWallet>

const wallet: ReturnType<typeof getWallet> = yield select(getWallet)
const txHash: string = yield call(() => bidService!.place(wallet, nft, price, expiresAt, fingerprint))
yield put(placeBidSuccess(nft, price, expiresAt, nft.chainId, txHash, wallet!.address, fingerprint))
if (!wallet) {
throw new Error("Can't place a bid without a wallet")
}
if (!bidService) {
throw new Error("Couldn't find a valid bid service for vendor")
}

const txHash = (yield call([bidService, 'place'], wallet, nft, price, expiresAt, fingerprint)) as Awaited<
ReturnType<typeof bidService.place>
>
yield put(placeBidSuccess(nft, price, expiresAt, nft.chainId, txHash, wallet.address, fingerprint))
} catch (error) {
yield put(placeBidFailure(nft, price, expiresAt, isErrorWithMessage(error) ? error.message : t('global.unknown_error'), fingerprint))
}
Expand All @@ -59,25 +67,28 @@ function* handlePlaceBidRequest(action: PlaceBidRequestAction) {
function* handleAcceptBidRequest(action: AcceptBidRequestAction) {
const { bid } = action.payload
try {
const contract: ReturnType<typeof getContract> = yield select(getContract, {
const contract = (yield select(getContract, {
address: bid.contractAddress
})
})) as ReturnType<typeof getContract>
if (!contract || !contract.vendor) {
throw new Error(
contract
? `Couldn't find a valid vendor for contract ${contract?.address}`
: `Couldn't find a valid vendor for contract ${bid.contractAddress}`
)
}
const vendor: Vendor<VendorName> = yield call([VendorFactory, 'build'], contract.vendor)
const vendor = (yield call([VendorFactory, 'build'], contract.vendor)) as ReturnType<typeof VendorFactory.build>
if (!vendor.bidService) {
throw new Error("Couldn't find a valid bid service for vendor")
}

const wallet: ReturnType<typeof getWallet> = yield select(getWallet)
const txHash: string = yield call([vendor.bidService!, 'accept'], wallet, bid)
const wallet = (yield select(getWallet)) as ReturnType<typeof getWallet>
const txHash = (yield call([vendor.bidService, 'accept'], wallet, bid)) as Awaited<ReturnType<typeof vendor.bidService.accept>>
yield put(acceptBidtransactionSubmitted(bid, txHash))
const nft: NFT | null = yield select(getCurrentNFT)
const nft = (yield select(getCurrentNFT)) as ReturnType<typeof getCurrentNFT>
if (nft?.openRentalId) {
yield call(waitForTx, txHash)
const rental: RentalListing | null = yield select(getRentalById, nft.openRentalId)
const rental = (yield select(getRentalById, nft.openRentalId)) as ReturnType<typeof getRentalById>
if (isRentalListingOpen(rental)) {
yield call(waitUntilRentalChangesStatus, nft, RentalStatus.CANCELLED)
}
Expand All @@ -92,16 +103,20 @@ function* handleAcceptBidRequest(action: AcceptBidRequestAction) {
function* handleCancelBidRequest(action: CancelBidRequestAction) {
const { bid } = action.payload
try {
const contract: ReturnType<typeof getContract> = yield select(getContract, {
const contract = (yield select(getContract, {
address: bid.contractAddress
})
})) as ReturnType<typeof getContract>

if (!contract || !contract.vendor) {
throw new Error(`Couldn't find a valid vendor for contract ${contract?.address}`)
}
const { bidService } = VendorFactory.build(contract.vendor)
if (!bidService) {
throw new Error("Couldn't find a valid bid service for vendor")
}

const wallet: ReturnType<typeof getWallet> = yield select(getWallet)
const txHash: string = yield call(() => bidService!.cancel(wallet, bid))
const wallet = (yield select(getWallet)) as ReturnType<typeof getWallet>
const txHash = (yield call([bidService, 'cancel'], wallet, bid)) as Awaited<ReturnType<typeof bidService.cancel>>

yield put(cancelBidSuccess(bid, txHash))
} catch (error) {
Expand All @@ -121,7 +136,10 @@ function* handleFetchBidsByAddressRequest(action: FetchBidsByAddressRequestActio
continue
}

const bids: [Bid[], Bid[]] = yield call(() => Promise.all([bidService.fetchBySeller(address), bidService.fetchByBidder(address)]))
const bids = (yield all([call([bidService, 'fetchBySeller'], address), call([bidService, 'fetchByBidder'], address)])) as [
Awaited<ReturnType<typeof bidService.fetchBySeller>>,
Awaited<ReturnType<typeof bidService.fetchByBidder>>
]
sellerBids = sellerBids.concat(bids[0])
bidderBids = bidderBids.concat(bids[1])
}
Expand All @@ -136,8 +154,11 @@ function* handleFetchBidsByNFTRequest(action: FetchBidsByNFTRequestAction) {
const { nft } = action.payload
try {
const { bidService } = VendorFactory.build(nft.vendor)
if (!bidService) {
throw new Error("Couldn't find a valid bid service for vendor")
}

const bids: Bid[] = yield call(() => bidService!.fetchByNFT(nft))
const bids = (yield call([bidService, 'fetchByNFT'], nft)) as Awaited<ReturnType<typeof bidService.fetchByNFT>>

yield put(fetchBidsByNFTSuccess(nft, bids))
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/modules/bid/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function isInsufficientMANA(bid: Bid) {
const provider = await getNetworkProvider(bid.chainId)
const contract = getContract(ContractName.MANAToken, bid.chainId)
const mana = new ethers.Contract(contract.address, contract.abi, new ethers.providers.Web3Provider(provider))
const balanceRaw: BigNumber = await mana.balanceOf(bid.bidder)
const balanceRaw = (await mana.balanceOf(bid.bidder)) as BigNumber
const balance = parseFloat(ethers.utils.formatEther(balanceRaw))
const price = parseFloat(ethers.utils.formatEther(bid.price))

Expand Down
12 changes: 8 additions & 4 deletions webapp/src/modules/collection/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ export function* handleFetchCollectionsRequest(action: FetchCollectionsRequestAc
const { filters, shouldFetchItems } = action.payload

try {
const { data: collections, total }: CollectionResponse = yield call([collectionAPI, collectionAPI.fetch], filters)
const { data: collections, total }: CollectionResponse = (yield call([collectionAPI, collectionAPI.fetch], filters)) as Awaited<
ReturnType<typeof collectionAPI.fetch>
>

yield put(fetchCollectionsSuccess(collections, total))

if (shouldFetchItems) {
const itemsByContractAddress: ReturnType<typeof getItemsByContractAddress> = yield select(getItemsByContractAddress)
const itemsByContractAddress = (yield select(getItemsByContractAddress)) as ReturnType<typeof getItemsByContractAddress>

for (const collection of collections) {
const items = itemsByContractAddress[collection.contractAddress]
Expand All @@ -54,7 +56,9 @@ export function* handleFetchSingleCollectionRequest(action: FetchSingleCollectio
const { contractAddress, shouldFetchItems } = action.payload

try {
const { data: collections }: CollectionResponse = yield call([collectionAPI, collectionAPI.fetch], { contractAddress })
const { data: collections } = (yield call([collectionAPI, collectionAPI.fetch], { contractAddress })) as Awaited<
ReturnType<typeof collectionAPI.fetch>
>

if (collections.length === 0) {
yield put(fetchSingleCollectionFailure(`Could not get Collection "${contractAddress}"`))
Expand All @@ -64,7 +68,7 @@ export function* handleFetchSingleCollectionRequest(action: FetchSingleCollectio
const [collection] = collections

if (shouldFetchItems) {
const itemsByContractAddress: ReturnType<typeof getItemsByContractAddress> = yield select(getItemsByContractAddress)
const itemsByContractAddress = (yield select(getItemsByContractAddress)) as ReturnType<typeof getItemsByContractAddress>

const items = itemsByContractAddress[collection.contractAddress]

Expand Down
Loading

0 comments on commit b20d17b

Please sign in to comment.