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

feat: add logic to use catalog v2 endpoint if FF is on #2306

Merged
merged 4 commits into from
Oct 28, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { connect } from 'react-redux'
import { isLoadingType } from 'decentraland-dapps/dist/modules/loading/selectors'
import { fetchCreatorsAccountRequest, FETCH_CREATORS_ACCOUNT_REQUEST } from '../../../modules/account/actions'
import { getCreators, getLoading } from '../../../modules/account/selectors'
import { getIsOffchainPublicNFTOrdersEnabled } from '../../../modules/features/selectors'
import { RootState } from '../../../modules/reducer'
import { SearchBarDropdown } from './SearchBarDropdown'
import { MapDispatch, MapDispatchProps, MapStateProps } from './SearchBarDropdown.types'

const mapState = (state: RootState): MapStateProps => ({
fetchedCreators: getCreators(state),
isLoadingCreators: isLoadingType(getLoading(state), FETCH_CREATORS_ACCOUNT_REQUEST)
isLoadingCreators: isLoadingType(getLoading(state), FETCH_CREATORS_ACCOUNT_REQUEST),
isOffchainEnabled: getIsOffchainPublicNFTOrdersEnabled(state)
})

const mapDispatch = (dispatch: MapDispatch): MapDispatchProps => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ function renderSearchDropBarDropdown(props: Partial<SearchBarDropdownProps> = {}
fetchedCreators: [],
isLoadingCreators: false,
onFetchCreators: jest.fn(),
onClickOutside: jest.fn()
onClickOutside: jest.fn(),
isOffchainEnabled: false
}
return renderWithProviders(
<ResponsiveContext.Provider value={{ width: 900 }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const SearchBarDropdown = ({
fetchedCreators,
isLoadingCreators,
onFetchCreators,
onClickOutside
onClickOutside,
isOffchainEnabled
}: SearchBarDropdownProps) => {
const isSearchingWearables = category === NFTCategory.WEARABLE
const isSearchingEmotes = category === NFTCategory.EMOTE
Expand Down Expand Up @@ -139,8 +140,11 @@ export const SearchBarDropdown = ({
first: MAX_AMOUNT_OF_RESULTS
},
{
'x-search-uuid': searchUUID,
'x-anonymous-id': anonId
v2: isOffchainEnabled,
headers: {
'x-search-uuid': searchUUID,
'x-anonymous-id': anonId
}
}
)
.then(response => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type SearchBarDropdownProps = {
fetchedCreators: CreatorAccount[]
onFetchCreators: typeof fetchCreatorsAccountRequest
isLoadingCreators: boolean
isOffchainEnabled: boolean
onClickOutside: (event: MouseEvent) => void
}

Expand All @@ -20,7 +21,7 @@ export enum SearchTab {
COLLECTIONS = 'collections'
}

export type MapStateProps = Pick<SearchBarDropdownProps, 'fetchedCreators' | 'isLoadingCreators'>
export type MapStateProps = Pick<SearchBarDropdownProps, 'fetchedCreators' | 'isLoadingCreators' | 'isOffchainEnabled'>

export type MapDispatchProps = Pick<SearchBarDropdownProps, 'onFetchCreators'>
export type MapDispatch = Dispatch<FetchCreatorsAccountRequestAction>
18 changes: 16 additions & 2 deletions webapp/src/modules/favorites/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { throwError } from 'redux-saga-test-plan/providers'
import { Item } from '@dcl/schemas'
import { CLOSE_MODAL, closeModal, openModal } from 'decentraland-dapps/dist/modules/modal/actions'
import { CONNECT_WALLET_SUCCESS } from 'decentraland-dapps/dist/modules/wallet/actions'
import { getIsMarketplaceServerEnabled } from '../features/selectors'
import { getIsMarketplaceServerEnabled, getIsOffchainPublicNFTOrdersEnabled } from '../features/selectors'
import { getIdentity as getAccountIdentity } from '../identity/utils'
import { getData as getItemsData } from '../item/selectors'
import { ItemBrowseOptions } from '../item/types'
Expand Down Expand Up @@ -153,6 +153,7 @@ describe('when handling the request for fetching favorited items', () => {
.provide([
[select(getListId), listId],
[select(getIsMarketplaceServerEnabled), isMarketplaceFFOn],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getAddress), address],
[call(getAccountIdentity), Promise.resolve()],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total })],
Expand Down Expand Up @@ -186,6 +187,7 @@ describe('when handling the request for fetching favorited items', () => {
[select(getListId), listId],
[select(getIsMarketplaceServerEnabled), isMarketplaceFFOn],
[select(getAddress), address],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[call(getAccountIdentity), Promise.resolve()],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total })],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.reject(error)]
Expand Down Expand Up @@ -221,6 +223,7 @@ describe('when handling the request for fetching favorited items', () => {
[select(getListId), listId],
[select(getAddress), address],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[call(getAccountIdentity), Promise.resolve()],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total })],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: [item] })]
Expand Down Expand Up @@ -270,6 +273,7 @@ describe('when handling the request for fetching favorited items', () => {
[select(getListId), listId],
[select(getAddress), address],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[call(getAccountIdentity), Promise.resolve()],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), { results: favoritedItemIds, total }]
])
Expand Down Expand Up @@ -338,6 +342,7 @@ describe('when handling the request for fetching favorited items', () => {
.provide([
[select(getListId), listId],
[select(getAddress), null],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getIsMarketplaceServerEnabled), true],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total })],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.reject(error)]
Expand All @@ -349,7 +354,8 @@ describe('when handling the request for fetching favorited items', () => {
...options.filters,
first: 1,
ids: [favoritedItemIds[0].itemId]
}
},
{ v2: false }
]
})
.put(fetchFavoritedItemsFailure(error.message))
Expand All @@ -372,6 +378,7 @@ describe('when handling the request for fetching favorited items', () => {
[select(getListId), listId],
[select(getAddress), null],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), Promise.resolve({ results: favoritedItemIds, total })],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: [item] })]
])
Expand Down Expand Up @@ -420,6 +427,7 @@ describe('when handling the request for fetching favorited items', () => {
[select(getListId), listId],
[select(getAddress), null],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(FavoritesAPI.prototype.getPicksByList), { results: favoritedItemIds, total }]
])
.call.like({
Expand Down Expand Up @@ -596,6 +604,7 @@ describe('when handling the request for fetching lists', () => {
.provide([
[call(getAccountIdentity), Promise.resolve()],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.resolve({ results: lists, total })],
[select(getItemsData), {}],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: items })]
Expand Down Expand Up @@ -632,6 +641,7 @@ describe('when handling the request for fetching lists', () => {
.provide([
[call(getAccountIdentity), Promise.resolve()],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.resolve({ results: lists, total })],
[select(getItemsData), { anItemId: items[0] }],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: [items[1]] })]
Expand Down Expand Up @@ -715,6 +725,7 @@ describe('when handling the request for fetching lists', () => {
.provide([
[call(getAccountIdentity), Promise.resolve()],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.resolve({ results: lists, total })],
[select(getItemsData), {}],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: items })]
Expand Down Expand Up @@ -752,6 +763,7 @@ describe('when handling the request for fetching lists', () => {
.provide([
[call(getAccountIdentity), Promise.resolve()],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(FavoritesAPI.prototype.getLists), Promise.resolve({ results: lists, total })],
[select(getItemsData), {}],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.reject(error)]
Expand Down Expand Up @@ -967,6 +979,7 @@ describe('when handling the request for getting a list', () => {
.provide([
[matchers.call.fn(FavoritesAPI.prototype.getList), Promise.resolve(list)],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getItemsData), {}],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: items })]
])
Expand Down Expand Up @@ -1006,6 +1019,7 @@ describe('when handling the request for getting a list', () => {
.provide([
[matchers.call.fn(FavoritesAPI.prototype.getList), Promise.resolve(list)],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getItemsData), { anotherItemId: {} }],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.resolve({ data: items })]
])
Expand Down
8 changes: 5 additions & 3 deletions webapp/src/modules/favorites/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { closeModal, CloseModalAction, CLOSE_MODAL, openModal } from 'decentrala
import { ConnectWalletSuccessAction, CONNECT_WALLET_FAILURE, CONNECT_WALLET_SUCCESS } from 'decentraland-dapps/dist/modules/wallet/actions'
import { AuthIdentity } from 'decentraland-crypto-fetch'
import { isErrorWithMessage } from '../../lib/error'
import { getIsMarketplaceServerEnabled } from '../features/selectors'
import { getIsMarketplaceServerEnabled, getIsOffchainPublicNFTOrdersEnabled } from '../features/selectors'
import { getIdentity as getAccountIdentity } from '../identity/utils'
import { getData as getItemsData } from '../item/selectors'
import { ItemBrowseOptions } from '../item/types'
Expand Down Expand Up @@ -109,7 +109,8 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) {
}

const api = (yield call(getCatalogAPI)) as CatalogAPI
const result = (yield call([api, 'get'], itemFilters)) as Awaited<ReturnType<typeof api.get>>
const isOffchainEnabled: boolean = yield select(getIsOffchainPublicNFTOrdersEnabled)
const result = (yield call([api, 'get'], itemFilters, { v2: isOffchainEnabled })) as Awaited<ReturnType<typeof api.get>>
previewItems = result.data
}
}
Expand Down Expand Up @@ -145,9 +146,10 @@ export function* favoritesSaga(getIdentity: () => AuthIdentity | undefined) {
}

const api = (yield call(getCatalogAPI)) as CatalogAPI
const isOffchainEnabled: boolean = yield select(getIsOffchainPublicNFTOrdersEnabled)

if (results.length > 0) {
const result = (yield call([api, 'get'], optionsFilters)) as Awaited<ReturnType<typeof api.get>>
const result = (yield call([api, 'get'], optionsFilters, { v2: isOffchainEnabled })) as Awaited<ReturnType<typeof api.get>>
items = result.data
}

Expand Down
11 changes: 10 additions & 1 deletion webapp/src/modules/item/sagas.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ import { sendTransaction } from 'decentraland-dapps/dist/modules/wallet/utils'
import { NetworkGatewayType } from 'decentraland-ui'
import { fetchSmartWearableRequiredPermissionsRequest } from '../asset/actions'
import { buyAssetWithCard, BUY_NFTS_WITH_CARD_EXPLANATION_POPUP_KEY } from '../asset/utils'
import { getIsMarketplaceServerEnabled, getIsOffchainPublicItemOrdersEnabled } from '../features/selectors'
import {
getIsMarketplaceServerEnabled,
getIsOffchainPublicItemOrdersEnabled,
getIsOffchainPublicNFTOrdersEnabled
} from '../features/selectors'
import { waitForFeatureFlagsToBeLoaded } from '../features/utils'
import { locations } from '../routing/locations'
import { View } from '../ui/types'
Expand Down Expand Up @@ -474,6 +478,7 @@ describe('when handling the fetch items request action', () => {
[matchers.call.fn(waitForFeatureFlagsToBeLoaded), undefined],
[select(getWallet), wallet],
[select(getIsOffchainPublicItemOrdersEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getIsMarketplaceServerEnabled), true],
[getContext('history'), { location: { pathname } }],
{
Expand Down Expand Up @@ -511,6 +516,7 @@ describe('when handling the fetch items request action', () => {
[matchers.call.fn(waitForFeatureFlagsToBeLoaded), undefined],
[select(getWallet), wallet],
[select(getIsOffchainPublicItemOrdersEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getIsMarketplaceServerEnabled), true],
[getContext('history'), { location: { pathname } }],
{
Expand Down Expand Up @@ -553,6 +559,7 @@ describe('when handling the fetch items request action', () => {
[matchers.call.fn(waitForWalletConnectionAndIdentityIfConnecting), undefined],
[matchers.call.fn(waitForFeatureFlagsToBeLoaded), undefined],
[select(getIsOffchainPublicItemOrdersEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getWallet), undefined],
[getContext('history'), { location: { pathname } }],
[select(getIsMarketplaceServerEnabled), false]
Expand All @@ -571,6 +578,7 @@ describe('when handling the fetch items request action', () => {
[getContext('history'), { location: { pathname: '' } }],
[select(getWallet), undefined],
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[select(getIsOffchainPublicItemOrdersEnabled), true],
[select(getWallet), undefined],
[matchers.call.fn(CatalogAPI.prototype.get), Promise.reject(anError)],
Expand Down Expand Up @@ -666,6 +674,7 @@ describe('when handling the fetch trending items request action', () => {
return expectSaga(itemSaga, getIdentity)
.provide([
[select(getIsMarketplaceServerEnabled), true],
[select(getIsOffchainPublicNFTOrdersEnabled), false],
[matchers.call.fn(ItemAPI.prototype.getTrendings), fetchResult],
[matchers.call.fn(CatalogAPI.prototype.get), fetchResult],
[matchers.call.fn(waitForWalletConnectionAndIdentityIfConnecting), undefined]
Expand Down
38 changes: 30 additions & 8 deletions webapp/src/modules/item/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ethers } from 'ethers'
import { History } from 'history'
import { SagaIterator, Task } from 'redux-saga'
import { call, cancel, cancelled, fork, race, select, take, getContext } from 'redux-saga/effects'
import { Entity, Trade } from '@dcl/schemas'
import { CatalogFilters, Entity, Trade } from '@dcl/schemas'
import { getConnectedProvider } from 'decentraland-dapps/dist/lib/eth'
import { SetPurchaseAction, SET_PURCHASE } from 'decentraland-dapps/dist/modules/gateway/actions'
import { PurchaseStatus } from 'decentraland-dapps/dist/modules/gateway/types'
Expand All @@ -20,7 +20,11 @@ import { API_SIGNER } from '../../lib/api'
import { isErrorWithMessage } from '../../lib/error'
import { fetchSmartWearableRequiredPermissionsRequest } from '../asset/actions'
import { buyAssetWithCard } from '../asset/utils'
import { getIsMarketplaceServerEnabled, getIsOffchainPublicItemOrdersEnabled } from '../features/selectors'
import {
getIsMarketplaceServerEnabled,
getIsOffchainPublicItemOrdersEnabled,
getIsOffchainPublicNFTOrdersEnabled
} from '../features/selectors'
import { waitForFeatureFlagsToBeLoaded } from '../features/utils'
import { locations } from '../routing/locations'
import { isCatalogView } from '../routing/utils'
Expand Down Expand Up @@ -130,9 +134,14 @@ export function* itemSaga(getIdentity: () => AuthIdentity | undefined) {
const ids = data.map(item => item.id)
const isMarketplaceServerEnabled: boolean = yield select(getIsMarketplaceServerEnabled)
const api = isMarketplaceServerEnabled ? marketplaceServerCatalogAPI : catalogAPI
const { data: itemData }: { data: Item[]; total: number } = yield call([api, 'get'], {
ids
})
const isOffchainEnabled: boolean = yield select(getIsOffchainPublicNFTOrdersEnabled)
const { data: itemData }: { data: Item[]; total: number } = yield call(
[api, 'get'],
{
ids
},
{ v2: isOffchainEnabled }
)
yield put(fetchTrendingItemsSuccess(itemData))
} catch (error) {
yield put(fetchTrendingItemsFailure(isErrorWithMessage(error) ? error.message : t('global.unknown_error')))
Expand Down Expand Up @@ -161,9 +170,22 @@ export function* itemSaga(getIdentity: () => AuthIdentity | undefined) {
const isMarketplaceServerEnabled: boolean = yield select(getIsMarketplaceServerEnabled)
const isOffchainPublicItemOrdersEnabled: boolean = yield select(getIsOffchainPublicItemOrdersEnabled)
const catalogViewAPI = isMarketplaceServerEnabled ? marketplaceServerCatalogAPI : catalogAPI
const itemViewAPI = isOffchainPublicItemOrdersEnabled ? marketplaceItemAPI : itemAPI
const api = isCatalogView(view) ? catalogViewAPI : itemViewAPI
const { data, total }: { data: Item[]; total: number } = yield call([api, 'get'], filters)
const isOffchainEnabled: boolean = yield select(getIsOffchainPublicNFTOrdersEnabled)
let data: Item[] = []
let total: number = 0

if (isCatalogView(view)) {
const result: { data: Item[]; total: number } = yield call([catalogViewAPI, 'get'], filters as CatalogFilters, {
v2: isOffchainEnabled
})
;({ data, total } = result)
} else {
const result: { data: Item[]; total: number } = yield call(
[isOffchainPublicItemOrdersEnabled ? marketplaceItemAPI : itemAPI, 'get'],
filters
)
;({ data, total } = result)
}
yield put(fetchItemsSuccess(data, total, action.payload, Date.now()))
} catch (error) {
yield put(fetchItemsFailure(isErrorWithMessage(error) ? error.message : t('global.unknown_error'), action.payload))
Expand Down
Loading
Loading