Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 6 commits into from
Jan 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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