mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-03 22:54:29 +01:00
ab4843f06b
* UX: Multichain: Implement Account Details Popover * Styling account details popover * using ButtonSecondary with variant, removing Text * adding account-details jest test * Close popover when outside area clicked * Move all export functionality into the popover * Improve jest tests * Implement new design for export key screens * Hide warning when popover is closed * Vertically align the copy button * Move AccountDetailsDisplay to its own file * Move authentication to its own file * Move private key to its own component * Fix misalignment of avatar on display screen * Move private key to its own component * Update ui/components/multichain/account-details/account-details-authenticate.js Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net> * Update ui/components/multichain/account-details/account-details.test.js Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net> * Prevent account name overflow, update text size * Use FormTextField * Add analytics * Move location of accountDetailsAddress * Ensure passsword input is used --------- Co-authored-by: Victor Thomas <10986371+vthomas13@users.noreply.github.com> Co-authored-by: Nidhi Kumari <nidhi.kumari@consensys.net>
91 lines
2.4 KiB
JavaScript
91 lines
2.4 KiB
JavaScript
import React, { useCallback, useState } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import PropTypes from 'prop-types';
|
|
import {
|
|
DISPLAY,
|
|
SEVERITIES,
|
|
TextColor,
|
|
TextVariant,
|
|
} from '../../../helpers/constants/design-system';
|
|
import {
|
|
BannerAlert,
|
|
ButtonPrimary,
|
|
ButtonSecondary,
|
|
FormTextField,
|
|
Text,
|
|
} from '../../component-library';
|
|
import Box from '../../ui/box/box';
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
import { exportAccount, hideWarning } from '../../../store/actions';
|
|
|
|
export const AccountDetailsAuthenticate = ({ address, onCancel }) => {
|
|
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)).then((res) => {
|
|
dispatch(hideWarning());
|
|
return res;
|
|
});
|
|
}, [dispatch, password, address]);
|
|
|
|
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,
|
|
}}
|
|
/>
|
|
{warning ? (
|
|
<Text
|
|
marginTop={1}
|
|
color={TextColor.errorDefault}
|
|
variant={TextVariant.bodySm}
|
|
>
|
|
{warning}
|
|
</Text>
|
|
) : null}
|
|
<BannerAlert marginTop={6} severity={SEVERITIES.DANGER}>
|
|
<Text variant={TextVariant.bodySm}>{t('privateKeyWarning')}</Text>
|
|
</BannerAlert>
|
|
<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,
|
|
};
|