+
+
+ Derivable Accounts
+
+
+ {
+ setDPathMenuItem(e.target.value);
+ }}
+ >
+ {showRoot && (
+
+ {`m/44'/501'`}
+
+ )}
+
+ {`m/44'/501'/0'`}
+
+
+ {`m/44'/501'/0'/0'`}
+
+ {showDeprecated && (
+
+ {`m/501'/0'/0/0 (deprecated)`}
+
+ )}
+
+
+
+ {accounts.map((acc) => {
+ return (
+ onClick(acc) : {}}>
+
+
+ );
+ })}
+
+ );
+}
+
// Material UI's Select doesn't render properly when using an `undefined` value,
// so we define this type and the subsequent `toDerivationPath` translator as a
// workaround.
//
// DERIVATION_PATH.deprecated is always undefined.
-const DerivationPathMenuItem = {
+export const DerivationPathMenuItem = {
Deprecated: 0,
Bip44: 1,
Bip44Change: 2,
+ Bip44Root: 3, // Ledger only.
};
-function toDerivationPath(dPathMenuItem) {
+export function toDerivationPath(dPathMenuItem) {
switch (dPathMenuItem) {
case DerivationPathMenuItem.Deprecated:
return DERIVATION_PATH.deprecated;
@@ -431,6 +455,8 @@ function toDerivationPath(dPathMenuItem) {
return DERIVATION_PATH.bip44;
case DerivationPathMenuItem.Bip44Change:
return DERIVATION_PATH.bip44Change;
+ case DerivationPathMenuItem.Bip44Root:
+ return DERIVATION_PATH.bip44Root;
default:
throw new Error(`invalid derivation path: ${dPathMenuItem}`);
}
diff --git a/src/utils/wallet.js b/src/utils/wallet.js
index bddbdeda..ffd8a0e2 100644
--- a/src/utils/wallet.js
+++ b/src/utils/wallet.js
@@ -176,9 +176,7 @@ export function WalletProvider({ children }) {
'walletSelector',
DEFAULT_WALLET_SELECTOR,
);
- const [ledgerPubKey, setLedgerPubKey] = useState(
- walletSelector.ledger ? walletSelector.importedPubkey : undefined,
- );
+ const [_hardwareWalletAccount, setHardwareWalletAccount] = useState(null);
// `walletCount` is the number of HD wallets.
const [walletCount, setWalletCount] = useLocalStorageState('walletCount', 1);
@@ -193,9 +191,15 @@ export function WalletProvider({ children }) {
try {
const onDisconnect = () => {
setWalletSelector(DEFAULT_WALLET_SELECTOR);
- setLedgerPubKey(undefined);
+ setHardwareWalletAccount(undefined);
+ };
+ const args = {
+ onDisconnect,
+ derivationPath: walletSelector.derivationPath,
+ account: walletSelector.account,
+ change: walletSelector.change,
};
- wallet = await Wallet.create(connection, 'ledger', { onDisconnect });
+ wallet = await Wallet.create(connection, 'ledger', args);
} catch (e) {
console.log(`received error using ledger wallet: ${e}`);
let message = 'Received error unlocking ledger';
@@ -204,7 +208,7 @@ export function WalletProvider({ children }) {
}
enqueueSnackbar(message, { variant: 'error' });
setWalletSelector(DEFAULT_WALLET_SELECTOR);
- setLedgerPubKey(undefined);
+ setHardwareWalletAccount(undefined);
return;
}
}
@@ -244,9 +248,7 @@ export function WalletProvider({ children }) {
]);
function addAccount({ name, importedAccount, ledger }) {
- if (ledger) {
- setLedgerPubKey(importedAccount);
- } else if (importedAccount === undefined) {
+ if (importedAccount === undefined) {
name && localStorage.setItem(`name${walletCount}`, name);
setWalletCount(walletCount + 1);
} else {
@@ -319,29 +321,26 @@ export function WalletProvider({ children }) {
};
});
- if (ledgerPubKey) {
- derivedAccounts.push({
- selector: {
- walletIndex: undefined,
- importedPubkey: ledgerPubKey,
- ledger: true,
- },
- address: new PublicKey(ledgerPubKey), // todo: get the ledger address
- name: 'Hardware wallet',
- isSelected: walletSelector.ledger,
- });
- }
-
return derivedAccounts.concat(importedAccounts);
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [
- seed,
- walletCount,
- walletSelector,
- privateKeyImports,
- walletNames,
- ledgerPubKey,
- ]);
+ }, [seed, walletCount, walletSelector, privateKeyImports, walletNames]);
+
+ let hardwareWalletAccount;
+ if (_hardwareWalletAccount) {
+ hardwareWalletAccount = {
+ ..._hardwareWalletAccount,
+ selector: {
+ walletIndex: undefined,
+ ledger: true,
+ importedPubkey: _hardwareWalletAccount.publicKey,
+ derivationPath: _hardwareWalletAccount.derivationPath,
+ account: _hardwareWalletAccount.account,
+ change: _hardwareWalletAccount.change,
+ },
+ address: _hardwareWalletAccount.publicKey,
+ isSelected: walletSelector.ledger,
+ };
+ }
return (