2023-02-15 19:07:33 +01:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-03 18:26:45 +02:00
|
|
|
import React, { useContext } from 'react';
|
2023-02-15 19:07:33 +01:00
|
|
|
import withModalProps from '../../../../helpers/higher-order-components/with-modal-props';
|
|
|
|
import Box from '../../../ui/box';
|
2023-04-19 23:16:49 +02:00
|
|
|
import {
|
|
|
|
Text,
|
|
|
|
Button,
|
2023-05-06 23:04:20 +02:00
|
|
|
BUTTON_SIZES,
|
2023-04-26 18:17:25 +02:00
|
|
|
BUTTON_VARIANT,
|
2023-04-19 23:16:49 +02:00
|
|
|
ButtonIcon,
|
|
|
|
IconName,
|
|
|
|
} from '../../../component-library';
|
2023-02-15 19:07:33 +01:00
|
|
|
import {
|
|
|
|
AlignItems,
|
2023-06-08 13:05:16 +02:00
|
|
|
Display,
|
|
|
|
FlexDirection,
|
2023-02-15 19:07:33 +01:00
|
|
|
JustifyContent,
|
|
|
|
Size,
|
|
|
|
TextVariant,
|
|
|
|
} from '../../../../helpers/constants/design-system';
|
|
|
|
import HoldToRevealButton from '../../hold-to-reveal-button';
|
|
|
|
import { useI18nContext } from '../../../../hooks/useI18nContext';
|
|
|
|
import ZENDESK_URLS from '../../../../helpers/constants/zendesk-url';
|
2023-05-03 18:26:45 +02:00
|
|
|
import { MetaMetricsContext } from '../../../../contexts/metametrics';
|
|
|
|
import {
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventKeyType,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
} from '../../../../../shared/constants/metametrics';
|
2023-02-15 19:07:33 +01:00
|
|
|
|
2023-05-06 23:04:20 +02:00
|
|
|
const HoldToRevealModal = ({
|
|
|
|
onLongPressed,
|
|
|
|
hideModal,
|
|
|
|
willHide = true,
|
|
|
|
holdToRevealType = 'SRP',
|
|
|
|
}) => {
|
2023-02-15 19:07:33 +01:00
|
|
|
const t = useI18nContext();
|
2023-05-06 23:04:20 +02:00
|
|
|
const holdToRevealTitle =
|
|
|
|
holdToRevealType === 'SRP'
|
|
|
|
? 'holdToRevealSRPTitle'
|
|
|
|
: 'holdToRevealPrivateKeyTitle';
|
|
|
|
|
|
|
|
const holdToRevealButton =
|
|
|
|
holdToRevealType === 'SRP' ? 'holdToRevealSRP' : 'holdToRevealPrivateKey';
|
2023-05-03 18:26:45 +02:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2023-02-15 19:07:33 +01:00
|
|
|
|
|
|
|
const unlock = () => {
|
|
|
|
onLongPressed();
|
2023-05-06 23:04:20 +02:00
|
|
|
if (willHide) {
|
|
|
|
hideModal();
|
|
|
|
}
|
2023-02-15 19:07:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleCancel = () => {
|
|
|
|
hideModal();
|
|
|
|
};
|
|
|
|
|
2023-05-06 23:04:20 +02:00
|
|
|
const renderHoldToRevealPrivateKeyContent = () => {
|
|
|
|
return (
|
2023-02-15 19:07:33 +01:00
|
|
|
<Box
|
2023-06-08 13:05:16 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-05-06 23:04:20 +02:00
|
|
|
gap={4}
|
2023-02-15 19:07:33 +01:00
|
|
|
marginBottom={6}
|
|
|
|
>
|
2023-05-06 23:04:20 +02:00
|
|
|
<Text variant={TextVariant.bodyMd}>
|
|
|
|
{t('holdToRevealContentPrivateKey1', [
|
|
|
|
<Text
|
|
|
|
key="hold-to-reveal-2"
|
|
|
|
variant={TextVariant.bodyMdBold}
|
|
|
|
as="span"
|
|
|
|
>
|
|
|
|
{t('holdToRevealContentPrivateKey2')}
|
|
|
|
</Text>,
|
|
|
|
])}
|
|
|
|
</Text>
|
|
|
|
<Text variant={TextVariant.bodyMdBold}>
|
|
|
|
{t('holdToRevealContent3', [
|
|
|
|
<Text
|
|
|
|
key="hold-to-reveal-4"
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
as="span"
|
2023-06-08 13:05:16 +02:00
|
|
|
display={Display.Inline}
|
2023-05-06 23:04:20 +02:00
|
|
|
>
|
|
|
|
{t('holdToRevealContent4')}
|
|
|
|
</Text>,
|
|
|
|
<Button
|
|
|
|
key="hold-to-reveal-5"
|
|
|
|
variant={BUTTON_VARIANT.LINK}
|
|
|
|
size={BUTTON_SIZES.INHERIT}
|
|
|
|
href={ZENDESK_URLS.NON_CUSTODIAL_WALLET}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('holdToRevealContent5')}
|
|
|
|
</Button>,
|
|
|
|
])}
|
|
|
|
</Text>
|
2023-02-15 19:07:33 +01:00
|
|
|
</Box>
|
2023-05-06 23:04:20 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const renderHoldToRevealSRPContent = () => {
|
|
|
|
return (
|
2023-02-15 19:07:33 +01:00
|
|
|
<Box
|
2023-06-08 13:05:16 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-02-15 19:07:33 +01:00
|
|
|
gap={4}
|
|
|
|
marginBottom={6}
|
|
|
|
>
|
|
|
|
<Text variant={TextVariant.bodyMd}>
|
|
|
|
{t('holdToRevealContent1', [
|
|
|
|
<Text
|
|
|
|
key="hold-to-reveal-2"
|
|
|
|
variant={TextVariant.bodyMdBold}
|
|
|
|
as="span"
|
|
|
|
>
|
|
|
|
{t('holdToRevealContent2')}
|
|
|
|
</Text>,
|
|
|
|
])}
|
|
|
|
</Text>
|
|
|
|
<Text variant={TextVariant.bodyMdBold}>
|
|
|
|
{t('holdToRevealContent3', [
|
|
|
|
<Text
|
|
|
|
key="hold-to-reveal-4"
|
|
|
|
variant={TextVariant.bodyMd}
|
|
|
|
as="span"
|
2023-06-08 13:05:16 +02:00
|
|
|
display={Display.Inline}
|
2023-02-15 19:07:33 +01:00
|
|
|
>
|
|
|
|
{t('holdToRevealContent4')}
|
|
|
|
</Text>,
|
|
|
|
<Button
|
|
|
|
key="hold-to-reveal-5"
|
2023-04-26 18:17:25 +02:00
|
|
|
variant={BUTTON_VARIANT.LINK}
|
2023-02-15 19:07:33 +01:00
|
|
|
size={Size.auto}
|
|
|
|
href={ZENDESK_URLS.NON_CUSTODIAL_WALLET}
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('holdToRevealContent5')}
|
|
|
|
</Button>,
|
|
|
|
])}
|
|
|
|
</Text>
|
|
|
|
</Box>
|
2023-05-06 23:04:20 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Box
|
|
|
|
className="hold-to-reveal-modal"
|
2023-06-08 13:05:16 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Column}
|
2023-05-06 23:04:20 +02:00
|
|
|
justifyContent={JustifyContent.flexStart}
|
|
|
|
padding={6}
|
|
|
|
>
|
|
|
|
<Box
|
2023-06-08 13:05:16 +02:00
|
|
|
display={Display.Flex}
|
|
|
|
flexDirection={FlexDirection.Row}
|
2023-05-06 23:04:20 +02:00
|
|
|
alignItems={AlignItems.center}
|
|
|
|
justifyContent={JustifyContent.spaceBetween}
|
|
|
|
marginBottom={6}
|
|
|
|
>
|
|
|
|
<Text variant={TextVariant.headingSm}>{t(holdToRevealTitle)}</Text>
|
|
|
|
{willHide && (
|
|
|
|
<ButtonIcon
|
|
|
|
className="hold-to-reveal-modal__close"
|
|
|
|
iconName={IconName.Close}
|
|
|
|
size={Size.SM}
|
|
|
|
onClick={() => {
|
|
|
|
trackEvent({
|
|
|
|
category: MetaMetricsEventCategory.Keys,
|
|
|
|
event: MetaMetricsEventName.SrpHoldToRevealCloseClicked,
|
|
|
|
properties: {
|
|
|
|
key_type: MetaMetricsEventKeyType.Srp,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
handleCancel();
|
|
|
|
}}
|
|
|
|
ariaLabel={t('close')}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</Box>
|
|
|
|
{holdToRevealType === 'SRP'
|
|
|
|
? renderHoldToRevealSRPContent()
|
|
|
|
: renderHoldToRevealPrivateKeyContent()}
|
2023-02-15 19:07:33 +01:00
|
|
|
<HoldToRevealButton
|
2023-05-06 23:04:20 +02:00
|
|
|
buttonText={t(holdToRevealButton)}
|
2023-02-15 19:07:33 +01:00
|
|
|
onLongPressed={unlock}
|
|
|
|
marginLeft="auto"
|
|
|
|
marginRight="auto"
|
|
|
|
/>
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
HoldToRevealModal.propTypes = {
|
|
|
|
// The function to be executed after the hold to reveal long press has been completed
|
|
|
|
onLongPressed: PropTypes.func.isRequired,
|
|
|
|
hideModal: PropTypes.func,
|
2023-05-06 23:04:20 +02:00
|
|
|
willHide: PropTypes.bool,
|
|
|
|
holdToRevealType: PropTypes.oneOf(['SRP', 'PrivateKey']).isRequired,
|
2023-02-15 19:07:33 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default withModalProps(HoldToRevealModal);
|