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: LANDs section race condition #2197

Merged
merged 5 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 8 additions & 3 deletions webapp/src/components/AssetList/AssetList.container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { isLoadingType } from 'decentraland-dapps/dist/modules/loading/selectors
import { RootState } from '../../modules/reducer'
import { FETCH_NFTS_REQUEST } from '../../modules/nft/actions'
import { browse, clearFilters } from '../../modules/routing/actions'
import { getBrowseAssets, getCount } from '../../modules/ui/browse/selectors'
import { getBrowseAssets, getCount, getView } from '../../modules/ui/browse/selectors'
import { View } from '../../modules/ui/types'
import {
getVendor,
getPageNumber,
Expand All @@ -25,18 +26,22 @@ const mapState = (state: RootState): MapStateProps => {
const section = getSection(state)
const page = getPageNumber(state)
const assetType = getAssetType(state)
const view = getView(state)
const loadingState = getLoadingNFTs(state).filter(loading => loading.payload.options.view === view)
const assets = getBrowseAssets(state, section, assetType)
const loadingStateFilteredByView = loadingState.filter(ls => ls.payload.options.view === View.MARKET)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the AssetList component is used in a lot of places, will this restriction affect other places that don't share the Market view?

return {
vendor: getVendor(state),
assetType,
section: getSection(state),
assets: getBrowseAssets(state, section, assetType),
assets,
page,
count: getCount(state),
search: getSearch(state),
isLoading:
assetType === AssetType.ITEM
? isLoadingType(getLoadingItems(state), FETCH_ITEMS_REQUEST) || isLoadingFavoritedItems(state)
: isLoadingType(getLoadingNFTs(state), FETCH_NFTS_REQUEST),
: isLoadingType(loadingStateFilteredByView, FETCH_NFTS_REQUEST),
hasFiltersEnabled: hasFiltersEnabled(state),
visitedLocations: getVisitedLocations(state)
}
Expand Down
3 changes: 2 additions & 1 deletion webapp/src/components/Navigation/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import * as decentraland from '../../modules/vendor/decentraland'
import { locations } from '../../modules/routing/locations'
import { VendorName } from '../../modules/vendor'
import { SortBy } from '../../modules/routing/types'
import { Section } from '../../modules/vendor/decentraland'
import { AssetType } from '../../modules/asset/types'
import * as events from '../../utils/events'
import { CAMPAING_TAB_ANIMATION_ENABLED } from '../Campaign/config'
Expand Down Expand Up @@ -65,7 +66,7 @@ const Navigation = (props: Props) => {
<Link to={locations.browse(browseDefaultOptions)} onClick={onClearFilters}>
<Tabs.Tab active={activeTab === NavigationTab.COLLECTIBLES}>{t('navigation.collectibles')}</Tabs.Tab>
</Link>
<Link to={locations.lands()}>
<Link to={locations.lands({ section: Section.LAND, assetType: AssetType.NFT })}>
<Tabs.Tab active={activeTab === NavigationTab.LANDS}>{t('navigation.land')}</Tabs.Tab>
</Link>
<Link to={locations.claimName()}>
Expand Down
36 changes: 36 additions & 0 deletions webapp/src/modules/nft/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as matchers from 'redux-saga-test-plan/matchers'
import { ChainId, NFTCategory, Order, RentalListing, RentalStatus } from '@dcl/schemas'
import { Wallet } from 'decentraland-dapps/dist/modules/wallet/types'
import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils'
import { connectWalletSuccess } from 'decentraland-dapps/dist/modules/wallet'
import { Vendor, VendorFactory, VendorName } from '../vendor'
import { getWallet } from '../wallet/selectors'
import {
Expand All @@ -31,6 +32,9 @@ import { waitUntilRentalChangesStatus } from '../rental/utils'
import { getRentalById } from '../rental/selectors'
import { retryParams } from '../vendor/decentraland/utils'
import { fetchSmartWearableRequiredPermissionsRequest } from '../asset/actions'
import { getView } from '../ui/browse/selectors'
import { EXPIRED_LISTINGS_MODAL_KEY } from '../ui/utils'
import { MAX_QUERY_SIZE } from '../vendor/api'

jest.mock('decentraland-dapps/dist/lib/eth')

Expand Down Expand Up @@ -449,3 +453,35 @@ describe('when handling the transfer NFT request action', () => {
})
})
})

describe('when handling the connect wallet success action', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind moving some of the other tests that were deleted here to cover most of the execution cases?

const address = '0x...'
let wallet: Wallet
describe('and the message has been shown before and stored in the LocalStorage', () => {
beforeEach(() => {
wallet = { address } as Wallet
})
it('it should not fetch the wallet nfts on sale', () => {
return expectSaga(nftSaga, getIdentity)
.provide([
[select(getWallet), wallet],
[select(getView), View.MARKET],
[call([localStorage, 'getItem'], EXPIRED_LISTINGS_MODAL_KEY), 'true']
])
.not.put(
fetchNFTsRequest({
view: View.MARKET,
vendor: VendorName.DECENTRALAND,
params: {
first: MAX_QUERY_SIZE,
skip: 0,
onlyOnSale: true,
address
}
})
)
.dispatch(connectWalletSuccess({ address } as Wallet))
.run({ silenceTimeout: true })
})
})
})
38 changes: 38 additions & 0 deletions webapp/src/modules/nft/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { ErrorCode } from 'decentraland-transactions'
import { waitForTx } from 'decentraland-dapps/dist/modules/transaction/utils'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { t } from 'decentraland-dapps/dist/modules/translation/utils'
import { openModal } from 'decentraland-dapps/dist/modules/modal'
import { CONNECT_WALLET_SUCCESS, ConnectWalletSuccessAction, Wallet } from 'decentraland-dapps/dist/modules/wallet'
import { isErrorWithMessage } from '../../lib/error'
import { getWallet } from '../wallet/selectors'
import { Vendor, VendorFactory } from '../vendor/VendorFactory'
import { getContract, getContracts } from '../contract/selectors'
import { isLegacyOrder } from '../../lib/orders'
import { VendorName } from '../vendor/types'
import { AwaitFn } from '../types'
import { getContractKey, getContractKeyFromNFT, getStubMaticCollectionContract } from '../contract/utils'
Expand All @@ -17,6 +20,10 @@ import { upsertContracts } from '../contract/actions'
import { Contract } from '../vendor/services'
import { retryParams } from '../vendor/decentraland/utils'
import { fetchSmartWearableRequiredPermissionsRequest } from '../asset/actions'
import { View } from '../ui/types'
import { getView } from '../ui/browse/selectors'
import { EXPIRED_LISTINGS_MODAL_KEY } from '../ui/utils'
import { MAX_QUERY_SIZE } from '../vendor/api'
import {
DEFAULT_BASE_NFT_PARAMS,
FETCH_NFTS_REQUEST,
Expand Down Expand Up @@ -45,6 +52,37 @@ export function* nftSaga(getIdentity: () => AuthIdentity | undefined) {
yield takeEvery(FETCH_NFTS_REQUEST, handleFetchNFTsRequest)
yield takeEvery(FETCH_NFT_REQUEST, handleFetchNFTRequest)
yield takeEvery(TRANSFER_NFT_REQUEST, handleTransferNFTRequest)
yield takeEvery(CONNECT_WALLET_SUCCESS, handleConnectWalletSuccess)

function* handleConnectWalletSuccess(action: ConnectWalletSuccessAction) {
const {
payload: {
wallet: { address }
}
} = action
const view: View = yield select(getView)
const wallet: Wallet = yield select(getWallet)
const hasShownTheExpiredListingsModalBefore: string | null = yield call([localStorage, 'getItem'], EXPIRED_LISTINGS_MODAL_KEY)

if (hasShownTheExpiredListingsModalBefore !== 'true') {
const vendor: Vendor<VendorName> = yield call([VendorFactory, 'build'], VendorName.DECENTRALAND, API_OPTS)
const [, , orders]: AwaitFn<typeof vendor.nftService.fetch> = yield call(
[vendor.nftService, 'fetch'],
{
first: MAX_QUERY_SIZE,
skip: 0,
onlyOnSale: true,
address
},
{}
)
if (wallet && view !== View.CURRENT_ACCOUNT) {
if (orders.some(order => isLegacyOrder(order) && order.owner === wallet.address)) {
yield put(openModal('ExpiredListingsModal'))
}
}
}
}

function* handleFetchNFTsRequest(action: FetchNFTsRequestAction) {
const { options, timestamp } = action.payload
Expand Down
Loading
Loading