import { useModalSearchParams } from '@/hooks/useModalSearchParams' import { Modal } from '@/shared/Modal/Modal' import { MODAL_PARAMS_KEYS } from '@/types/modal' import { call, getShortenNpub } from '@/utils/helpers' import { Avatar, Box, Stack, Typography } from '@mui/material' import { useParams, useSearchParams } from 'react-router-dom' import { useAppSelector } from '@/store/hooks/redux' import { selectAppsByNpub } from '@/store' import { StyledButton, StyledToggleButtonsGroup } from './styled' import { ActionToggleButton } from './сomponents/ActionToggleButton' import { useState } from 'react' import { swicCall } from '@/modules/swic' enum ACTION_TYPE { BASIC = 'Basic', ADVANCED = 'Advanced', CUSTOM = 'Custom', } export const ModalConfirmConnect = () => { const { getModalOpened, handleClose } = useModalSearchParams() const isModalOpened = getModalOpened(MODAL_PARAMS_KEYS.CONFIRM_CONNECT) const { npub = '' } = useParams<{ npub: string }>() const apps = useAppSelector((state) => selectAppsByNpub(state, npub)) const [selectedActionType, setSelectedActionType] = useState( ACTION_TYPE.BASIC, ) const [searchParams] = useSearchParams() const appNpub = searchParams.get('appNpub') || '' const pendingReqId = searchParams.get('reqId') || '' const triggerApp = apps.find((app) => app.appNpub === appNpub) const { name, icon = '' } = triggerApp || {} const appName = name || getShortenNpub(appNpub) const handleActionTypeChange = (_: any, value: ACTION_TYPE) => { setSelectedActionType(value) } const handleCloseModal = handleClose( MODAL_PARAMS_KEYS.CONFIRM_CONNECT, async (sp) => { sp.delete('appNpub') sp.delete('reqId') await swicCall('confirm', pendingReqId, false, false) }, ) async function confirmPending( id: string, allow: boolean, remember: boolean, ) { call(async () => { await swicCall('confirm', id, allow, remember) console.log('confirmed', id, allow, remember) }) handleClose(MODAL_PARAMS_KEYS.CONFIRM_CONNECT, async (sp) => { sp.delete('appNpub') sp.delete('reqId') }) } return ( {appName} Would like to connect to your account Cancel confirmPending(pendingReqId, true, false) } > Allow {selectedActionType} actions ) }