Skip to content

Commit

Permalink
fix: Add FF to fetch collection items from marketplace server (#3214)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyaiox authored Oct 23, 2024
1 parent af316ad commit de3a8c4
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/modules/item/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ import { takeLatestCancellable } from 'modules/common/utils'
import { waitForTx } from 'modules/transaction/utils'
import { getMethodData } from 'modules/wallet/utils'
import { setItems } from 'modules/editor/actions'
import { getIsLinkedWearablesV2Enabled } from 'modules/features/selectors'
import { getIsLinkedWearablesV2Enabled, getIsOffchainPublicItemOrdersEnabled } from 'modules/features/selectors'
import { getCatalystContentUrl } from 'lib/api/peer'
import { downloadZip } from 'lib/zip'
import { isErrorWithCode } from 'lib/error'
Expand Down Expand Up @@ -284,31 +284,34 @@ export function* itemSaga(legacyBuilder: LegacyBuilderAPI, builder: BuilderClien
const isFetchingMultiplePages = Array.isArray(page)

try {
const isOffchainPublicItemOrdersEnabled: boolean = yield select(getIsOffchainPublicItemOrdersEnabled)
const { items, paginationStats }: { items: Item[]; paginationStats?: PaginationStats } = yield call(
fetchCollectionItemsWithBatch,
collectionId,
isFetchingMultiplePages ? page : [page],
restOfOptions
)
let itemsToSave = items
let collection: Collection | undefined = yield select(getCollection, collectionId)
if (isOffchainPublicItemOrdersEnabled) {
let collection: Collection | undefined = yield select(getCollection, collectionId)

if (!collection) {
collection = yield call([legacyBuilder, 'fetchCollection'], collectionId)
}
if (!collection) {
collection = yield call([legacyBuilder, 'fetchCollection'], collectionId)
}

if (collection && collection.isPublished) {
const result: { data: DCLItem[] } = yield call([marketplace, 'fetchCollectionItems'], collection.contractAddress!)
itemsToSave = items.map(item => {
const publishedItem = result.data.find(publishedItem => publishedItem.id === `${collection?.contractAddress}-${item.tokenId}`)
return {
...item,
tradeExpiresAt: publishedItem?.tradeExpiresAt,
tradeId: publishedItem?.tradeId,
beneficiary: publishedItem?.beneficiary || item.beneficiary,
price: publishedItem?.price || item.price
}
})
if (collection && collection.isPublished) {
const result: { data: DCLItem[] } = yield call([marketplace, 'fetchCollectionItems'], collection.contractAddress!)
itemsToSave = items.map(item => {
const publishedItem = result.data.find(publishedItem => publishedItem.id === `${collection?.contractAddress}-${item.tokenId}`)
return {
...item,
tradeExpiresAt: publishedItem?.tradeExpiresAt,
tradeId: publishedItem?.tradeId,
beneficiary: publishedItem?.beneficiary || item.beneficiary,
price: publishedItem?.price || item.price
}
})
}
}
yield put(fetchCollectionItemsSuccess(collectionId, itemsToSave, overridePaginationData ? paginationStats : undefined))
} catch (error) {
Expand Down

0 comments on commit de3a8c4

Please sign in to comment.