2021-06-28 15:09:32 +10:00
|
|
|
import { Button, TextField } from '@material-ui/core';
|
|
|
|
|
import React, { ChangeEvent, useState } from 'react';
|
2021-06-29 11:52:48 +10:00
|
|
|
import { loadKeyPairFromStorage } from './key_storage';
|
|
|
|
|
import { KeyPair } from '../crypto';
|
2021-06-28 15:09:32 +10:00
|
|
|
|
|
|
|
|
export interface Props {
|
|
|
|
|
setEthDmKeyPair: (keyPair: KeyPair) => void;
|
|
|
|
|
disabled: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function LoadKeyFromStorage(props: Props) {
|
|
|
|
|
const [password, setPassword] = useState<string>();
|
|
|
|
|
|
|
|
|
|
const disabled = props.disabled;
|
|
|
|
|
|
|
|
|
|
const handlePasswordChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
setPassword(event.target.value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const loadKeyPair = () => {
|
|
|
|
|
if (disabled) return;
|
|
|
|
|
if (!password) return;
|
|
|
|
|
loadKeyPairFromStorage(password).then((keyPair: KeyPair | undefined) => {
|
|
|
|
|
if (!keyPair) return;
|
|
|
|
|
console.log('EthDm KeyPair loaded from storage');
|
|
|
|
|
props.setEthDmKeyPair(keyPair);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
flexWrap: 'wrap',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<TextField
|
|
|
|
|
id="password-input"
|
|
|
|
|
label="Password"
|
|
|
|
|
variant="filled"
|
|
|
|
|
type="password"
|
|
|
|
|
onChange={handlePasswordChange}
|
|
|
|
|
value={password}
|
|
|
|
|
/>
|
|
|
|
|
<Button
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="primary"
|
|
|
|
|
onClick={loadKeyPair}
|
|
|
|
|
disabled={!password || disabled}
|
|
|
|
|
>
|
|
|
|
|
Load Eth-DM Key Pair from storage
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|