diff --git a/src/components/main/Main.tsx b/src/components/main/Main.tsx index a818eb6a2..041d379a2 100644 --- a/src/components/main/Main.tsx +++ b/src/components/main/Main.tsx @@ -217,7 +217,7 @@ const Main = ({ loadPremiumGifts, loadTonGifts, loadStarGifts, - loadMyCollectibleGifts, + loadMyUniqueGifts, loadDefaultTopicIcons, loadAddedStickers, loadFavoriteStickers, @@ -333,7 +333,7 @@ const Main = ({ loadPremiumGifts(); loadTonGifts(); loadStarGifts(); - loadMyCollectibleGifts(); + loadMyUniqueGifts(); loadAvailableEffects(); loadBirthdayNumbersStickers(); loadRestrictedEmojiStickers(); diff --git a/src/components/modals/gift/GiftModal.tsx b/src/components/modals/gift/GiftModal.tsx index 672f8e76c..80f16c52b 100644 --- a/src/components/modals/gift/GiftModal.tsx +++ b/src/components/modals/gift/GiftModal.tsx @@ -58,8 +58,8 @@ type StateProps = { boostPerSentGift?: number; starGiftsById?: Record; starGiftIdsByCategory?: Record; - myCollectibleGiftsById?: Record; - myCollectibleGiftIds?: string[]; + myUniqueGiftsById?: Record; + myUniqueGiftIds?: string[]; starBalance?: ApiStarsAmount; peer?: ApiPeer; isSelf?: boolean; @@ -81,8 +81,8 @@ const GiftModal: FC = ({ modal, starGiftsById, starGiftIdsByCategory, - myCollectibleGiftsById, - myCollectibleGiftIds, + myUniqueGiftsById, + myUniqueGiftIds, starBalance, peer, isSelf, @@ -99,7 +99,7 @@ const GiftModal: FC = ({ loadResaleGifts, openGiftInMarket, closeResaleGiftsMarket, - loadMyCollectibleGifts, + loadMyUniqueGifts, openGiftTransferConfirmModal, } = getActions(); const dialogRef = useRef(); @@ -235,7 +235,7 @@ const GiftModal: FC = ({ }); } - if (selectedCategory === 'resale') { + if (selectedCategory === 'collectible') { return lang('StarGiftDescriptionCollectibles'); } @@ -293,8 +293,8 @@ const GiftModal: FC = ({ }); const handleMyGiftClick = useLastCallback((gift: ApiStarGift) => { - if (gift.type === 'starGift' || !myCollectibleGiftsById || !peer?.id) return; - const savedGift = myCollectibleGiftsById[gift.id]; + if (gift.type === 'starGift' || !myUniqueGiftsById || !peer?.id) return; + const savedGift = myUniqueGiftsById[gift.id]; openGiftTransferConfirmModal({ gift: savedGift, @@ -303,23 +303,23 @@ const GiftModal: FC = ({ }); const handleLoadMore = useLastCallback(() => { - if (selectedCategory === 'myCollectibles') { - loadMyCollectibleGifts(); + if (selectedCategory === 'myUnique') { + loadMyUniqueGifts(); } }); function renderStarGifts() { - if (selectedCategory === 'myCollectibles') { + if (selectedCategory === 'myUnique') { return ( - {myCollectibleGiftsById && myCollectibleGiftIds?.map((giftId) => { - const savedGift = myCollectibleGiftsById[giftId]; + {myUniqueGiftsById && myUniqueGiftIds?.map((giftId) => { + const savedGift = myUniqueGiftsById[giftId]; if (!savedGift) return undefined; return ( @@ -356,8 +356,7 @@ const GiftModal: FC = ({ {starGiftsById && filteredGiftIds?.flatMap((giftId) => { const gift = starGiftsById[giftId]; const shouldShowResale = Boolean(gift.availabilityResale) && !areUniqueStarGiftsDisallowed; - const shouldDuplicateAsResale = selectedCategory !== 'resale' - && shouldShowResale && !gift.isSoldOut && !areLimitedStarGiftsDisallowed; + const shouldDuplicateAsResale = shouldShowResale && !gift.isSoldOut && !areLimitedStarGiftsDisallowed; const elements = [ = ({ {renderStarGiftsHeader()} {renderStarGiftsDescription()} ((global, { modal }): Complete((global, { modal }): Complete void; }; @@ -26,15 +27,16 @@ type StateProps = { const StarGiftCategoryList = ({ idsByCategory, onCategoryChanged, - areCollectibleStarGiftsDisallowed, + areUniqueStarGiftsDisallowed, + areLimitedStarGiftsDisallowed, isSelf, - hasCollectible, + hasMyUnique, }: StateProps & OwnProps) => { const ref = useRef(); const lang = useLang(); - const hasResale = idsByCategory && idsByCategory['resale'].length > 0; + const hasCollectible = Boolean(idsByCategory?.collectible?.length); const [selectedCategory, setSelectedCategory] = useState('all'); @@ -47,8 +49,8 @@ const StarGiftCategoryList = ({ function renderCategoryName(category: StarGiftCategory) { if (category === 'all') return lang('AllGiftsCategory'); - if (category === 'myCollectibles') return lang('GiftCategoryMyGifts'); - if (category === 'resale') return lang('GiftCategoryCollectibles'); + if (category === 'myUnique') return lang('GiftCategoryMyGifts'); + if (category === 'collectible') return lang('GiftCategoryCollectibles'); return category; } @@ -71,13 +73,14 @@ const StarGiftCategoryList = ({ return (
{renderCategoryItem('all')} - {!areCollectibleStarGiftsDisallowed && !isSelf && hasCollectible && renderCategoryItem('myCollectibles')} - {!areCollectibleStarGiftsDisallowed && hasResale && renderCategoryItem('resale')} + {!areUniqueStarGiftsDisallowed && !isSelf && hasMyUnique && renderCategoryItem('myUnique')} + {(!areUniqueStarGiftsDisallowed || !areLimitedStarGiftsDisallowed) + && hasCollectible && renderCategoryItem('collectible')}
); }; -export default memo(withGlobal( +export default memo(withGlobal( (global): Complete => { const { starGifts } = global; diff --git a/src/global/actions/api/stars.ts b/src/global/actions/api/stars.ts index 45ce914a0..dbdf136e1 100644 --- a/src/global/actions/api/stars.ts +++ b/src/global/actions/api/stars.ts @@ -138,7 +138,8 @@ addActionHandler('loadStarGifts', async (global): Promise => { const allStarGiftIds = Object.keys(byId); const allStarGifts = Object.values(byId); - const resaleStarGiftIds = allStarGifts.map((gift) => (gift.availabilityResale ? gift.id : undefined)) + const collectibleStarGiftIds = allStarGifts.map((gift) => ( + (gift.availabilityResale || (gift.isLimited && !gift.isSoldOut)) ? gift.id : undefined)) .filter(Boolean); global = { @@ -147,23 +148,23 @@ addActionHandler('loadStarGifts', async (global): Promise => { byId, idsByCategory: { all: allStarGiftIds, - resale: resaleStarGiftIds, - myCollectibles: [], + collectible: collectibleStarGiftIds, + myUnique: [], }, }, }; setGlobal(global); }); -addActionHandler('loadMyCollectibleGifts', async (global, actions, payload): Promise => { +addActionHandler('loadMyUniqueGifts', async (global, actions, payload): Promise => { const { shouldRefresh } = payload || {}; const currentUserId = global.currentUserId; if (!currentUserId) return; - const currentMyCollectibleGifts = global.myCollectibleGifts; - const localNextOffset = currentMyCollectibleGifts?.nextOffset; + const currentMyUniqueGifts = global.myUniqueGifts; + const localNextOffset = currentMyUniqueGifts?.nextOffset; - if (currentMyCollectibleGifts && !localNextOffset && !shouldRefresh) return; + if (currentMyUniqueGifts && !localNextOffset && !shouldRefresh) return; const peer = selectPeer(global, currentUserId); if (!peer) return; @@ -196,13 +197,13 @@ addActionHandler('loadMyCollectibleGifts', async (global, actions, payload): Pro global = { ...global, - myCollectibleGifts: { + myUniqueGifts: { byId: { - ...!shouldRefresh && (global.myCollectibleGifts?.byId || {}), + ...!shouldRefresh && (global.myUniqueGifts?.byId || {}), ...byId, }, ids: [ - ...!shouldRefresh ? (global.myCollectibleGifts?.ids || []) : [], + ...!shouldRefresh ? (global.myUniqueGifts?.ids || []) : [], ...ids, ], nextOffset: result.nextOffset, @@ -372,7 +373,7 @@ addActionHandler('reloadPeerSavedGifts', (global, actions, payload): ActionRetur } }); if (peerId === global.currentUserId) { - actions.loadMyCollectibleGifts({ shouldRefresh: true }); + actions.loadMyUniqueGifts({ shouldRefresh: true }); } }); diff --git a/src/global/types/actions.ts b/src/global/types/actions.ts index a5387fa1d..2142385ef 100644 --- a/src/global/types/actions.ts +++ b/src/global/types/actions.ts @@ -2556,7 +2556,7 @@ export interface ActionPayloads { loadPremiumGifts: undefined; loadTonGifts: undefined; loadStarGifts: undefined; - loadMyCollectibleGifts: { + loadMyUniqueGifts: { shouldRefresh?: true; } | undefined; updateResaleGiftsFilter: { diff --git a/src/global/types/globalState.ts b/src/global/types/globalState.ts index de244de49..bb6739f6e 100644 --- a/src/global/types/globalState.ts +++ b/src/global/types/globalState.ts @@ -312,7 +312,7 @@ export type GlobalState = { byId: Record; idsByCategory: Record; }; - myCollectibleGifts?: { + myUniqueGifts?: { byId: Record; ids: string[]; nextOffset?: string; diff --git a/src/types/index.ts b/src/types/index.ts index 89d08eda8..aad6383e1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -670,7 +670,7 @@ export type WebPageMediaSize = 'large' | 'small'; export type AttachmentCompression = 'compress' | 'original'; -export type StarGiftCategory = 'all' | 'myCollectibles' | 'resale'; +export type StarGiftCategory = 'all' | 'myUnique' | 'collectible'; export type CallSound = ( 'join' | 'allowTalk' | 'leave' | 'connecting' | 'incoming' | 'end' | 'connect' | 'busy' | 'ringing'