Skip to content

Commit

Permalink
fix: setting custom hd path for ledger
Browse files Browse the repository at this point in the history
  • Loading branch information
marcinbodnar committed May 9, 2022
1 parent fc36027 commit 1745f75
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
19 changes: 14 additions & 5 deletions packages/frontend/src/components/accounts/ledger/LedgerHdPaths.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';
import { Translate } from 'react-localize-redux';
import styled from 'styled-components';

Expand Down Expand Up @@ -109,7 +109,12 @@ const Container = styled.div`
}
`;

export default function LedgerHdPaths({ onSetPath, path, onConfirmHdPath }) {
export default function LedgerHdPaths({
confirmedPath,
setConfirmedPath
}) {
const [path, setPath] = useState(confirmedPath);

onKeyDown((e) => {
const dropdownOpen = document.getElementById('hd-paths-dropdown').classList.contains('open');
if (dropdownOpen) {
Expand All @@ -123,15 +128,19 @@ export default function LedgerHdPaths({ onSetPath, path, onConfirmHdPath }) {
});

const increment = () => {
onSetPath(path + 1);
setPath(path + 1);
};

const decrement = () => {
if (path > 0) {
onSetPath(path - 1);
setPath(path - 1);
}
};

const handleConfirmHdPath = () => {
setConfirmedPath(path);
};

const dropDownContent = () => {
return (
<div className='ledger-dropdown-content'>
Expand All @@ -152,7 +161,7 @@ export default function LedgerHdPaths({ onSetPath, path, onConfirmHdPath }) {
</div>
</div>
</div>
<FormButton className='hd-paths-dropdown-toggle' onClick={onConfirmHdPath}>
<FormButton className='hd-paths-dropdown-toggle' onClick={handleConfirmHdPath}>
<Translate id='signInLedger.advanced.setPath'/>
</FormButton>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import React from 'react';
import { Translate } from 'react-localize-redux';

import { Mixpanel } from '../../../../mixpanel/index';
import FormButton from '../../../common/FormButton';
import LocalAlertBox from '../../../common/LocalAlertBox';
import LedgerImageCircle from '../../../svg/LedgerImageCircle';
import LedgerHdPaths from '../LedgerHdPaths';

const Authorize = ({
status,
path,
setPath,
confirmedPath,
setConfirmedPath,
handleSignIn,
signingIn,
Expand All @@ -24,12 +22,8 @@ const Authorize = ({
<br /><br />
<LocalAlertBox localAlert={status.localAlert} />
<LedgerHdPaths
path={path}
onSetPath={(path) => setPath(path)}
onConfirmHdPath={() => {
setConfirmedPath(path);
Mixpanel.track('IE-Ledger Sign in set custom HD path');
}}
confirmedPath={confirmedPath}
setConfirmedPath={setConfirmedPath}
/>
<div className='buttons-bottom-buttons'>
<FormButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ export function SignInLedgerWrapper(props) {

const [accountId, setAccountId] = useState('');
const [loader, setLoader] = useState(false);
const [path, setPath] = useState(1);
const [confirmedPath, setConfirmedPath] = useState(null);
const ledgerHdPath = confirmedPath ? `44'/397'/0'/0'/${confirmedPath}'` : null;
const [confirmedPath, setConfirmedPath] = useState(1);
const ledgerHdPath = `44'/397'/0'/0'/${confirmedPath}'`;

const account = useSelector(selectAccountSlice);
const status = useSelector(selectStatusSlice);
Expand Down Expand Up @@ -127,8 +126,7 @@ export function SignInLedgerWrapper(props) {
if (!signInWithLedgerStatus) {
return <Authorize
status={status}
path={path}
setPath={setPath}
confirmedPath={confirmedPath}
setConfirmedPath={setConfirmedPath}
handleSignIn={handleSignIn}
signingIn={!!signInWithLedgerStatus}
Expand Down
4 changes: 1 addition & 3 deletions packages/frontend/src/redux/slices/ledger/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ const signInWithLedgerAddAndSaveAccounts = createAsyncThunk(
async ({ path, accountIds }, { dispatch, getState }) => {
for (let accountId of accountIds) {
try {
if (path) {
setLedgerHdPath({ accountId, path });
}
setLedgerHdPath({ accountId, path });
await dispatch(addLedgerAccountId({ accountId })).unwrap();
dispatch(ledgerSlice.actions.setLedgerTxSigned({ status: false, accountId }));
} catch (e) {
Expand Down

0 comments on commit 1745f75

Please sign in to comment.