From a92287361240edc1ddd5ed8e5e6f98a1a947b69d Mon Sep 17 00:00:00 2001 From: zubiden <19638254+zubiden@users.noreply.github.com> Date: Wed, 14 May 2025 19:01:56 +0300 Subject: [PATCH] Multi-Account: Fix test server handling (#5889) --- src/components/auth/AuthPhoneNumber.tsx | 7 ++++++- src/components/left/main/AccountMenuItems.tsx | 1 + src/components/left/main/LeftMainHeader.scss | 10 ++++++++++ .../modals/gift/withdraw/GiftWithdrawModal.tsx | 2 +- src/global/actions/api/initial.ts | 6 +++++- 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/auth/AuthPhoneNumber.tsx b/src/components/auth/AuthPhoneNumber.tsx index afb126aa8..3beaf8266 100644 --- a/src/components/auth/AuthPhoneNumber.tsx +++ b/src/components/auth/AuthPhoneNumber.tsx @@ -42,6 +42,7 @@ type StateProps = Pick & { language?: string; phoneCodeList: ApiCountryCode[]; + isTestServer?: boolean; }; const MIN_NUMBER_LENGTH = 7; @@ -59,6 +60,7 @@ const AuthPhoneNumber: FC = ({ authNearestCountry, phoneCodeList, language, + isTestServer, }) => { const { setAuthPhoneNumber, @@ -87,11 +89,12 @@ const AuthPhoneNumber: FC = ({ const hasActiveAccount = Object.values(accountsInfo).length > 0; const phoneNumberSlots = useMemo(() => ( Object.entries(accountsInfo) + .filter(([, info]) => info.isTest === isTestServer) .reduce((acc, [key, { phone }]) => { if (phone) acc[phone] = Number(key); return acc; }, {} as Record) - ), [accountsInfo]); + ), [accountsInfo, isTestServer]); const fullNumber = country ? `+${country.countryCode} ${phoneNumber || ''}` : phoneNumber; const canSubmit = fullNumber && fullNumber.replace(/[^\d]+/g, '').length >= MIN_NUMBER_LENGTH; @@ -295,6 +298,7 @@ export default memo(withGlobal( const { sharedState: { settings: { language } }, countryList: { phoneCodes: phoneCodeList }, + config, } = global; return { @@ -310,6 +314,7 @@ export default memo(withGlobal( ]), language, phoneCodeList, + isTestServer: config?.isTestServer, }; }, )(AuthPhoneNumber)); diff --git a/src/components/left/main/AccountMenuItems.tsx b/src/components/left/main/AccountMenuItems.tsx index 96b352803..9e46b141a 100644 --- a/src/components/left/main/AccountMenuItems.tsx +++ b/src/components/left/main/AccountMenuItems.tsx @@ -94,6 +94,7 @@ const AccountMenuItems = ({ onClick={account.userId === currentUser.id ? onSelectCurrent : undefined} href={account.userId !== currentUser.id ? getAccountSlotUrl(Number(slot)) : undefined} > + {account.isTest && T} {hasSeparator && } diff --git a/src/components/left/main/LeftMainHeader.scss b/src/components/left/main/LeftMainHeader.scss index b29f839c2..9c30b6bc7 100644 --- a/src/components/left/main/LeftMainHeader.scss +++ b/src/components/left/main/LeftMainHeader.scss @@ -159,6 +159,16 @@ .account-menu-item { --custom-emoji-size: 1rem; + &-test { + position: absolute; + left: 2.875rem; + bottom: 0.0625rem; + color: var(--color-text-secondary); + font-size: 0.5rem; + font-weight: var(--font-weight-medium); + z-index: 1; + } + .account-avatar { margin-inline: 0.375rem 1.125rem; } diff --git a/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx b/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx index 6d4d5ee11..8a4e0ea8d 100644 --- a/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx +++ b/src/components/modals/gift/withdraw/GiftWithdrawModal.tsx @@ -133,7 +133,7 @@ const GiftWithdrawModal = ({ modal, hasPassword, passwordHint }: OwnProps & Stat {!hasPassword && ( <> {lang('ErrorPasswordMissing')} - + )} {hasPassword && !exportDelay && ( diff --git a/src/global/actions/api/initial.ts b/src/global/actions/api/initial.ts index 5f7dafbd1..ac546423f 100644 --- a/src/global/actions/api/initial.ts +++ b/src/global/actions/api/initial.ts @@ -52,8 +52,12 @@ addActionHandler('initApi', (global, actions): ActionReturnType => { const hasTestParam = window.location.search.includes('test') || initialLocationHash?.tgWebAuthTest === '1'; + const isTestServer = global.config?.isTestServer; const accountsInfo = getAccountsInfo(); - const accountIds = Object.values(accountsInfo).map(({ userId }) => userId)?.filter(Boolean); + const accountIds = Object.values(accountsInfo) + .filter((info) => info.isTest === isTestServer) + .map(({ userId }) => userId) + .filter(Boolean); void initApi(actions.apiUpdate, { userAgent: navigator.userAgent,