import React, { useContext } from 'react'; import { useSelector, useDispatch } from 'react-redux'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { MetaMetricsEventName, MetaMetricsEventCategory, } from '../../../../shared/constants/metametrics'; import { useI18nContext } from '../../../hooks/useI18nContext'; import withModalProps from '../../../helpers/higher-order-components/with-modal-props'; import { toChecksumHexAddress } from '../../../../shared/modules/hexstring-utils'; import { mmiActionsFactory } from '../../../store/institutional/institution-background'; import { hideModal, setSelectedAddress } from '../../../store/actions'; import { getMetaMaskAccountsRaw } from '../../../selectors'; import { getMMIAddressFromModalOrAddress, getCustodyAccountDetails, getMMIConfiguration, } from '../../../selectors/institutional/selectors'; import Box from '../../ui/box/box'; import { AlignItems, DISPLAY, FLEX_DIRECTION, FontWeight, JustifyContent, TextAlign, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import { Button, BUTTON_VARIANT } from '../../component-library'; import { Text } from '../../component-library/text/deprecated'; const CustodyConfirmLink = () => { const t = useI18nContext(); const dispatch = useDispatch(); const mmiActions = mmiActionsFactory(); const trackEvent = useContext(MetaMetricsContext); const mmiAccounts = useSelector(getMetaMaskAccountsRaw); const address = useSelector(getMMIAddressFromModalOrAddress); const custodyAccountDetails = useSelector(getCustodyAccountDetails); const { custodians } = useSelector(getMMIConfiguration); const { custodianName } = custodyAccountDetails[toChecksumHexAddress(address)] || {}; const { displayName, iconUrl } = custodians.find( (item) => item.name === custodianName || {}, ); const { url, ethereum, text, action } = useSelector( (state) => state.appState.modal.modalState.props.link || {}, ); const onClick = () => { if (url) { global.platform.openTab({ url }); } if (ethereum) { const ethAccount = Object.keys(mmiAccounts).find((account) => ethereum.accounts.includes(account.toLowerCase()), ); ethAccount && dispatch(setSelectedAddress(ethAccount.toLowerCase())); } trackEvent({ category: MetaMetricsEventCategory.MMI, event: MetaMetricsEventName.UserClickedDeepLink, }); dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(false)); dispatch(hideModal()); }; return ( {iconUrl ? ( MMI logo {'>'} {custodianName} ) : ( {custodianName} )} {t('awaitingApproval')} {text || t('custodyDeeplinkDescription', [displayName])} ); }; export default withModalProps(CustodyConfirmLink);