diff --git a/src/components/barters-table/index.js b/src/components/barters-table/index.js index f4c3882aa..5e4b5783f 100644 --- a/src/components/barters-table/index.js +++ b/src/components/barters-table/index.js @@ -148,6 +148,9 @@ function BartersTable({ selectedTrader, nameFilter, itemFilter, showAll, useBart } if (!rewardItem.item.containsItems) continue; for (const contained of rewardItem.item.containsItems) { + if (!contained) { + continue; + } if (contained.item.id === itemFilter) { return true; } diff --git a/src/features/barters/index.js b/src/features/barters/index.js index 49958a330..67f91e537 100644 --- a/src/features/barters/index.js +++ b/src/features/barters/index.js @@ -121,26 +121,26 @@ export const selectAllBarters = createSelector([selectBarters, selectQuests, sel } return { ...barter, - requiredItems: barter.requiredItems.map(req => { + requiredItems: barter.requiredItems.reduce((requirements, req) => { let matchedItem = items.find(it => it.id === req.item.id); - if (!matchedItem) { - return false; + if (matchedItem) { + requirements.push({ + ...req, + item: matchedItem, + }); } - return { - ...req, - item: matchedItem, - }; - }).filter(Boolean), - rewardItems: barter.rewardItems.map(req => { + return requirements; + }, []), + rewardItems: barter.rewardItems.reduce((requirements, req) => { const matchedItem = items.find(it => it.id === req.item.id); - if (!matchedItem) { - return false; + if (matchedItem) { + requirements.push({ + ...req, + item: matchedItem, + }); } - return { - ...req, - item: matchedItem, - }; - }).filter(Boolean), + return requirements; + }, []), taskUnlock: taskUnlock, }; }).filter(barter => barter.rewardItems.length > 0 && barter.requiredItems.length > 0); diff --git a/src/pages/item/index.js b/src/pages/item/index.js index 07f338a28..c1cf9261e 100644 --- a/src/pages/item/index.js +++ b/src/pages/item/index.js @@ -214,9 +214,9 @@ function Item() { const containsItems = currentItemData?.containsItems?.length > 0; const hasBarters = barters.some(barter => { - let requiredItems = barter.requiredItems.some(contained => contained.item.id === currentItemData.id); - let rewardItems = barter.rewardItems.some(contained => contained.item.id === currentItemData.id || - contained.item.containsItems.some(ci => ci.item.id === currentItemData.id)); + let requiredItems = barter.requiredItems.some(contained => contained?.item.id === currentItemData.id); + let rewardItems = barter.rewardItems.some(contained => contained?.item.id === currentItemData.id || + contained?.item.containsItems.some(ci => ci?.item.id === currentItemData.id)); return requiredItems || rewardItems; });