Skip to content

Commit b7cd72c

Browse files
committed
Validation of private key is added
1 parent aa78d7f commit b7cd72c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

examples/wallet/app/components/RestoreWalletFromPrivateKey.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Container from 'react-bootstrap/Container';
66
import Row from 'react-bootstrap/Row';
77
import typeof { setAccount as SetAccount } from '../actions/account';
88
import CreateUnlockWalletPassword from '../containers/CreateUnlockWalletPassword';
9+
import { getAccountFromPrivateKey } from '../utils/wasmWrapper';
910

1011
type Props = {
1112
setAccount: SetAccount,
@@ -30,6 +31,15 @@ export default ({
3031
}
3132
};
3233

34+
const checkValidPrivateKey = function checkValidPrivateKey() {
35+
getAccountFromPrivateKey(newPrivateKey)
36+
.then(() => setPrivateKeyErrorMessage(''))
37+
.catch(error => {
38+
console.error(error);
39+
setPrivateKeyErrorMessage('Invalid private key');
40+
});
41+
};
42+
3343
const [newPrivateKey, setNewPrivateKey] = useState('');
3444
const [privateKeyErrorMessage, setPrivateKeyErrorMessage] = useState('');
3545

@@ -45,6 +55,7 @@ export default ({
4555
value={newPrivateKey}
4656
isInvalid={privateKeyErrorMessage}
4757
onChange={event => setNewPrivateKey(event.target.value)}
58+
onBlur={() => checkValidPrivateKey()}
4859
/>
4960
<Form.Control.Feedback type="invalid">
5061
{privateKeyErrorMessage}

0 commit comments

Comments
 (0)