import PropTypes from 'prop-types'; import React, { useState } from 'react'; import { SubjectType } from '@metamask/permission-controller'; import { useI18nContext } from '../../../hooks/useI18nContext'; import PermissionsConnectHeader from '../../../components/app/permissions-connect-header'; import PermissionsConnectFooter from '../../../components/app/permissions-connect-footer'; import AccountList from '../../../components/ui/account-list'; import { PageContainerFooter } from '../../../components/ui/page-container'; const ChooseAccount = ({ selectedAccountAddresses, addressLastConnectedMap = {}, accounts, selectAccounts, selectNewAccountViaModal, cancelPermissionsRequest, permissionsRequestId, targetSubjectMetadata, nativeCurrency, }) => { const [selectedAccounts, setSelectedAccounts] = useState( selectedAccountAddresses, ); const t = useI18nContext(); const handleAccountClick = (address) => { const newSelectedAccounts = new Set(selectedAccounts); if (newSelectedAccounts.has(address)) { newSelectedAccounts.delete(address); } else { newSelectedAccounts.add(address); } setSelectedAccounts(newSelectedAccounts); }; const selectAll = () => { const newSelectedAccounts = new Set( accounts.map((account) => account.address), ); setSelectedAccounts(newSelectedAccounts); }; const deselectAll = () => { setSelectedAccounts(new Set()); }; const allAreSelected = () => { return accounts.length === selectedAccounts.size; }; const getHeaderText = () => { if (accounts.length === 0) { return t('connectAccountOrCreate'); } ///: BEGIN:ONLY_INCLUDE_IN(snaps) if (targetSubjectMetadata?.subjectType === SubjectType.Snap) { return t('selectAccountsForSnap'); } ///: END:ONLY_INCLUDE_IN return t('selectAccounts'); }; const headerText = getHeaderText(); return ( <>