import type { GlobalState, TabArgs } from '../types'; import { DEFAULT_GIFT_PROFILE_FILTER_OPTIONS } from '../../config'; import arePropsShallowEqual from '../../util/arePropsShallowEqual'; import { getCurrentTabId } from '../../util/establishMultitabRole'; import { getHasAdminRight, isChatAdmin, isChatChannel, } from '../helpers'; import { selectChat } from './chats'; import { selectTabState } from './tabs'; import { selectUser } from './users'; export function selectPaymentInputInvoice( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.inputInvoice; } export function selectPaymentForm( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.form; } export function selectStarsPayment( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).starsPayment; } export function selectPaymentRequestId( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.requestId; } export function selectProviderPublishableKey( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.form?.nativeParams.publishableKey; } export function selectProviderPublicToken( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.form?.nativeParams.publicToken; } export function selectStripeCredentials( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.stripeCredentials; } export function selectSmartGlocalCredentials( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectTabState(global, tabId).payment.smartGlocalCredentials; } export function selectCanUseGiftProfileAdminFilter( global: T, peerId: string, ) { const chat = selectChat(global, peerId); return chat && isChatChannel(chat) && isChatAdmin(chat) && getHasAdminRight(chat, 'postMessages'); } export function selectCanUseGiftProfileFilter( global: T, peerId: string, ) { const chat = selectChat(global, peerId); const user = selectUser(global, peerId); return Boolean(user) || (chat && isChatChannel(chat)); } export function selectGiftProfileFilter( global: T, peerId: string, ...[tabId = getCurrentTabId()]: TabArgs ) { return selectCanUseGiftProfileFilter(global, peerId) ? selectTabState(global, tabId).savedGifts.filter : undefined; } export function selectIsGiftProfileFilterDefault( global: T, ...[tabId = getCurrentTabId()]: TabArgs ) { return arePropsShallowEqual(selectTabState(global, tabId).savedGifts.filter, DEFAULT_GIFT_PROFILE_FILTER_OPTIONS); }