1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00
metamask-extension/ui/components/multichain/account-details/account-details-authenticate.js
Howard Braham d76b458235
fix(privateKey): Restore hold-to-reveal button for private key export (#20109)
* fix(privateKey): Restore hold-to-reveal button for private key export

* lint and unit test fixes

* adding e2e tests to reveal private key

* fixing lint issues

* fixed: Private key is able to be presented without tapping and holding the "Hold to reveal" CTA

* Incorrect password test and support hold to reveal

* improving unit tests

---------

Co-authored-by: Plasma Corral <32695229+plasmacorral@users.noreply.github.com>
Co-authored-by: Gustavo Antunes <17601467+gantunesr@users.noreply.github.com>
2023-08-24 17:35:26 -04:00

93 lines
2.4 KiB
JavaScript

import PropTypes from 'prop-types';
import React, { useCallback, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
Display,
FontWeight,
Severity,
TextVariant,
} from '../../../helpers/constants/design-system';
import {
BannerAlert,
Box,
ButtonPrimary,
ButtonSecondary,
FormTextField,
} from '../../component-library';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { exportAccount, hideWarning } from '../../../store/actions';
export const AccountDetailsAuthenticate = ({
address,
onCancel,
setPrivateKey,
setShowHoldToReveal,
}) => {
const t = useI18nContext();
const dispatch = useDispatch();
const [password, setPassword] = useState('');
// Password error would result from appState
const warning = useSelector((state) => state.appState.warning);
const onSubmit = useCallback(() => {
dispatch(
exportAccount(password, address, setPrivateKey, setShowHoldToReveal),
).then((res) => {
dispatch(hideWarning());
return res;
});
}, [dispatch, password, address, setPrivateKey, setShowHoldToReveal]);
const handleKeyPress = useCallback(
(e) => {
if (e.key === 'Enter') {
onSubmit();
}
},
[onSubmit],
);
return (
<>
<FormTextField
marginTop={6}
id="account-details-authenticate"
label={t('enterYourPassword')}
placeholder={t('password')}
error={warning}
helpText={warning}
onChange={(e) => setPassword(e.target.value)}
value={password}
variant={TextVariant.bodySm}
type="password"
inputProps={{ onKeyPress: handleKeyPress }}
labelProps={{ fontWeight: FontWeight.Medium }}
autoFocus
/>
<BannerAlert
marginTop={6}
severity={Severity.Danger}
description={t('privateKeyWarning')}
/>
<Box display={Display.Flex} marginTop={6} gap={2}>
<ButtonSecondary onClick={onCancel} block>
{t('cancel')}
</ButtonSecondary>
<ButtonPrimary onClick={onSubmit} disabled={password === ''} block>
{t('confirm')}
</ButtonPrimary>
</Box>
</>
);
};
AccountDetailsAuthenticate.propTypes = {
address: PropTypes.string.isRequired,
onCancel: PropTypes.func.isRequired,
setPrivateKey: PropTypes.func.isRequired,
setShowHoldToReveal: PropTypes.func.isRequired,
};