Add support for array format in account import and export (#74)
This commit is contained in:
parent
efcc69a1a0
commit
f0386cee96
|
@ -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;
|
||||
|
|
|
@ -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={
|
||||
|
|
Loading…
Reference in New Issue