From 7f9ef2aa0ff6486f0d71d11a7b9b0dc0210cadef Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:30:41 +0200 Subject: [PATCH] Telegram Stars: Follow-up (#4691) --- src/components/middle/MessageList.tsx | 2 +- .../modals/stars/StarsBalanceModal.tsx | 30 ++++++++++++------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/components/middle/MessageList.tsx b/src/components/middle/MessageList.tsx index 78e0a85bc..68398a6cf 100644 --- a/src/components/middle/MessageList.tsx +++ b/src/components/middle/MessageList.tsx @@ -325,7 +325,7 @@ const MessageList: FC = ({ if (!messageIds || !messagesById || threadId !== MAIN_THREAD_ID || type === 'scheduled') { return; } - const ids = messageIds.filter((id) => messagesById[id].factCheck?.shouldFetch); + const ids = messageIds.filter((id) => messagesById[id]?.factCheck?.shouldFetch); if (!ids.length) return; diff --git a/src/components/modals/stars/StarsBalanceModal.tsx b/src/components/modals/stars/StarsBalanceModal.tsx index 916a746a6..9e5ab72aa 100644 --- a/src/components/modals/stars/StarsBalanceModal.tsx +++ b/src/components/modals/stars/StarsBalanceModal.tsx @@ -77,24 +77,34 @@ const StarsBalanceModal = ({ } }, [isOpen]); - const renderingOptions = useMemo(() => { + const [renderingOptions, canExtend] = useMemo(() => { if (!topupOptions) { - return undefined; + return [undefined, false]; } + const maxOption = topupOptions.reduce((max, option) => ( + max.stars > option.stars ? max : option + )); + const forceShowAll = starsNeeded && maxOption.stars < starsNeeded; + const result: { option: ApiStarTopupOption; starsCount: number }[] = []; - let currentStarsCount = 0; + let currentStackedStarsCount = 0; + let canExtendOptions = false; topupOptions.forEach((option) => { - if (!option.isExtended) currentStarsCount++; - if (!areOptionsExtended && option.isExtended) return; - if (starsNeeded && option.stars < starsNeeded) return; + if (!option.isExtended) currentStackedStarsCount++; + + if (starsNeeded && !forceShowAll && option.stars < starsNeeded) return; + if (!areOptionsExtended && option.isExtended) { + canExtendOptions = true; + return; + } result.push({ option, - starsCount: currentStarsCount, + starsCount: currentStackedStarsCount, }); }); - return result; + return [result, canExtendOptions]; }, [areOptionsExtended, topupOptions, starsNeeded]); const tosText = useMemo(() => { @@ -164,8 +174,8 @@ const StarsBalanceModal = ({ {renderingOptions?.map(({ option, starsCount }) => ( ))} - {!areOptionsExtended && ( -