1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-29 23:58:06 +01:00
metamask-extension/ui/pages/create-account/import-account/private-key.js
HowardBraham 694773f17a
Upgrading the Import Account modal (#17763)
Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
Co-authored-by: NidhiKJha <nidhi.kumari@consensys.net>
Co-authored-by: montelaidev <monte.lai@consensys.net>
2023-03-06 09:48:28 -08:00

58 lines
1.4 KiB
JavaScript

import PropTypes from 'prop-types';
import React, { useState } from 'react';
import { useSelector } from 'react-redux';
import {
FormTextField,
TEXT_FIELD_SIZES,
TEXT_FIELD_TYPES,
} from '../../../components/component-library';
import { useI18nContext } from '../../../hooks/useI18nContext';
import BottomButtons from './bottom-buttons';
PrivateKeyImportView.propTypes = {
importAccountFunc: PropTypes.func.isRequired,
};
export default function PrivateKeyImportView({ importAccountFunc }) {
const t = useI18nContext();
const [privateKey, setPrivateKey] = useState('');
const warning = useSelector((state) => state.appState.warning);
function handleKeyPress(event) {
if (privateKey !== '' && event.key === 'Enter') {
event.preventDefault();
_importAccountFunc();
}
}
function _importAccountFunc() {
importAccountFunc('Private Key', [privateKey]);
}
return (
<>
<FormTextField
id="private-key-box"
size={TEXT_FIELD_SIZES.LARGE}
autoFocus
type={TEXT_FIELD_TYPES.PASSWORD}
helpText={warning}
error
label={t('pastePrivateKey')}
value={privateKey}
onChange={(event) => setPrivateKey(event.target.value)}
inputProps={{
onKeyPress: handleKeyPress,
}}
marginBottom={4}
/>
<BottomButtons
importAccountFunc={_importAccountFunc}
isPrimaryDisabled={privateKey === ''}
/>
</>
);
}