Add support for array format in account import and export (#74)

This commit is contained in:
Kelvin Jayanoris 2021-01-29 11:44:05 +03:00 committed by GitHub
parent efcc69a1a0
commit f0386cee96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -8,7 +8,6 @@ import FormControlLabel from '@material-ui/core/FormControlLabel';
import FormGroup from '@material-ui/core/FormGroup';
import Switch from '@material-ui/core/Switch';
import { Account } from '@solana/web3.js';
import * as bs58 from 'bs58';
import DialogForm from './DialogForm';
export default function AddAccountDialog({ open, onAdd, onClose }) {
@ -83,9 +82,14 @@ export default function AddAccountDialog({ open, onAdd, onClose }) {
);
}
/**
* Returns an account object when given the private key
*
* @param {string} privateKey - the private key in array format
*/
function decodeAccount(privateKey) {
try {
const a = new Account(bs58.decode(privateKey));
const a = new Account(JSON.parse(privateKey));
return a;
} catch (_) {
return undefined;

View File

@ -6,13 +6,13 @@ import DialogContent from '@material-ui/core/DialogContent';
import TextField from '@material-ui/core/TextField';
import FormControlLabel from '@material-ui/core/FormControlLabel';
import Switch from '@material-ui/core/Switch';
import * as bs58 from 'bs58';
import DialogForm from './DialogForm';
import { useWallet } from '../utils/wallet';
export default function ExportAccountDialog({ open, onClose }) {
const wallet = useWallet();
const [isHidden, setIsHidden] = useState(true);
const keyOutput = `[${Array.from(wallet.provider.account.secretKey)}]`;
return (
<DialogForm open={open} onClose={onClose} fullWidth>
@ -24,7 +24,7 @@ export default function ExportAccountDialog({ open, onClose }) {
type={isHidden && 'password'}
variant="outlined"
margin="normal"
value={bs58.encode(wallet.provider.account.secretKey)}
value={keyOutput}
/>
<FormControlLabel
control={