2023-04-25 15:39:16 +02:00
|
|
|
import React, { useContext } from 'react';
|
2023-07-17 19:34:32 +02:00
|
|
|
import PropTypes from 'prop-types';
|
2023-04-25 15:39:16 +02:00
|
|
|
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';
|
2023-07-17 19:34:32 +02:00
|
|
|
import { setSelectedAddress } from '../../../store/actions';
|
2023-04-25 15:39:16 +02:00
|
|
|
import { getMetaMaskAccountsRaw } from '../../../selectors';
|
|
|
|
import {
|
|
|
|
getMMIAddressFromModalOrAddress,
|
|
|
|
getCustodyAccountDetails,
|
|
|
|
getMMIConfiguration,
|
|
|
|
} from '../../../selectors/institutional/selectors';
|
|
|
|
import {
|
|
|
|
AlignItems,
|
2023-07-17 19:34:32 +02:00
|
|
|
Display,
|
|
|
|
FlexDirection,
|
2023-04-25 15:39:16 +02:00
|
|
|
JustifyContent,
|
|
|
|
TextAlign,
|
|
|
|
TextColor,
|
|
|
|
TextVariant,
|
|
|
|
} from '../../../helpers/constants/design-system';
|
2023-07-17 19:34:32 +02:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
BUTTON_VARIANT,
|
|
|
|
Modal,
|
|
|
|
ModalHeader,
|
|
|
|
ModalContent,
|
|
|
|
ModalOverlay,
|
|
|
|
Text,
|
|
|
|
Box,
|
|
|
|
} from '../../component-library';
|
2023-04-25 15:39:16 +02:00
|
|
|
|
2023-07-17 19:34:32 +02:00
|
|
|
const CustodyConfirmLink = ({ hideModal }) => {
|
2023-04-25 15:39:16 +02:00
|
|
|
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,
|
2023-07-18 15:55:37 +02:00
|
|
|
event: MetaMetricsEventName.DeeplinkClicked,
|
2023-04-25 15:39:16 +02:00
|
|
|
});
|
|
|
|
dispatch(mmiActions.setWaitForConfirmDeepLinkDialog(false));
|
|
|
|
dispatch(hideModal());
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2023-07-17 19:34:32 +02:00
|
|
|
<Modal isOpen onClose={hideModal}>
|
|
|
|
<ModalOverlay />
|
|
|
|
<ModalContent>
|
|
|
|
<ModalHeader onClose={hideModal}>{t('awaitingApproval')}</ModalHeader>
|
|
|
|
<Box display={Display.Flex} flexDirection={FlexDirection.Column}>
|
|
|
|
{iconUrl ? (
|
|
|
|
<Box
|
|
|
|
display={Display.Flex}
|
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
paddingTop={5}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
className="custody-confirm-link__img"
|
|
|
|
src="/images/logo/mmi-logo.svg"
|
|
|
|
alt="MMI logo"
|
|
|
|
/>
|
|
|
|
{'>'}
|
|
|
|
<img
|
|
|
|
className="custody-confirm-link__img"
|
|
|
|
src={iconUrl}
|
|
|
|
alt={custodianName}
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
) : (
|
|
|
|
<Box
|
|
|
|
display={Display.Flex}
|
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.center}
|
|
|
|
paddingTop={5}
|
|
|
|
>
|
|
|
|
<span>{custodianName}</span>
|
|
|
|
</Box>
|
|
|
|
)}
|
|
|
|
<Text
|
|
|
|
as="p"
|
|
|
|
paddingTop={4}
|
|
|
|
paddingRight={5}
|
|
|
|
paddingLeft={5}
|
|
|
|
paddingBottom={10}
|
|
|
|
textAlign={TextAlign.Center}
|
|
|
|
color={TextColor.textDefault}
|
|
|
|
variant={TextVariant.bodySm}
|
|
|
|
className="custody-confirm-link__description"
|
|
|
|
>
|
|
|
|
{text || t('custodyDeeplinkDescription', [displayName])}
|
|
|
|
</Text>
|
|
|
|
<Button
|
|
|
|
data-testid="custody-confirm-link__btn"
|
|
|
|
variant={BUTTON_VARIANT.PRIMARY}
|
|
|
|
className="custody-confirm-link__btn"
|
|
|
|
onClick={onClick}
|
|
|
|
>
|
|
|
|
{action ||
|
|
|
|
(action ? t('openCustodianApp', [displayName]) : t('close'))}
|
|
|
|
</Button>
|
2023-04-25 15:39:16 +02:00
|
|
|
</Box>
|
2023-07-17 19:34:32 +02:00
|
|
|
</ModalContent>
|
|
|
|
</Modal>
|
2023-04-25 15:39:16 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2023-07-17 19:34:32 +02:00
|
|
|
CustodyConfirmLink.propTypes = {
|
|
|
|
hideModal: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
2023-04-25 15:39:16 +02:00
|
|
|
export default withModalProps(CustodyConfirmLink);
|