import React, { useContext } from 'react'; import PropTypes from 'prop-types'; 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 { setSelectedAddress } from '../../../store/actions'; import { getMetaMaskIdentities } from '../../../selectors'; import { getMMIAddressFromModalOrAddress, getCustodyAccountDetails, getMMIConfiguration, } from '../../../selectors/institutional/selectors'; import { AlignItems, Display, FlexDirection, JustifyContent, TextAlign, TextColor, TextVariant, } from '../../../helpers/constants/design-system'; import { Button, BUTTON_VARIANT, Modal, ModalHeader, ModalContent, ModalOverlay, Text, Box, } from '../../component-library'; const CustodyConfirmLink = ({ hideModal }) => { const t = useI18nContext(); const dispatch = useDispatch(); const mmiActions = mmiActionsFactory(); const trackEvent = useContext(MetaMetricsContext); const mmiAccounts = useSelector(getMetaMaskIdentities); 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.DeeplinkClicked, }); dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(false)); hideModal(); }; return ( {t('awaitingApproval')} {iconUrl ? ( MMI logo {'>'} {custodianName} ) : ( {custodianName} )} {text || t('custodyDeeplinkDescription', [displayName])} ); }; CustodyConfirmLink.propTypes = { hideModal: PropTypes.func.isRequired, }; export default withModalProps(CustodyConfirmLink);