Skip to content

Commit

Permalink
Add support for array format in account import and export (project-se…
Browse files Browse the repository at this point in the history
  • Loading branch information
moshthepitt authored Jan 29, 2021
1 parent efcc69a commit f0386ce
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/AddAccountDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/components/ExportAccountDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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={
Expand Down

0 comments on commit f0386ce

Please sign in to comment.