Skip to content

feat: Fix plan 835 Hid request dialog keep on prompting up during pagination. #30384

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

Merged
merged 18 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
506915a
feat: First draft fix for HID request keep promping up.
dawnseeker8 Feb 18, 2025
2dcab12
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Feb 18, 2025
cf89481
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Feb 19, 2025
d5a8a67
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 6, 2025
1359e03
fix: add unit tests to test connectHardware, mock HID connection with…
dawnseeker8 Mar 7, 2025
a438e07
Fix: unit tests to cover the getPage() method.
dawnseeker8 Mar 10, 2025
14a74d6
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 11, 2025
26b2b62
fix: refactor the unit test description.
dawnseeker8 Mar 11, 2025
064f3c3
fix: Remove unused comments.
dawnseeker8 Mar 11, 2025
29d8173
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 12, 2025
1900595
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 13, 2025
56674c0
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 13, 2025
7cd20ee
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 14, 2025
1ce4a8f
fix: update unit tests snapshot.
dawnseeker8 Mar 14, 2025
567ef59
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 14, 2025
6be0307
Update ui/pages/create-account/connect-hardware/__snapshots__/index.t…
dawnseeker8 Mar 18, 2025
40caace
Merge branch 'main' into feat/plan-836-ledger-hid-prompt-up-issue
dawnseeker8 Mar 18, 2025
a0600d4
fix: update latest snapshot after rebase to fix unit tests.
dawnseeker8 Mar 18, 2025
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
4 changes: 2 additions & 2 deletions ui/pages/create-account/connect-hardware/account-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ class AccountList extends Component {
goToNextPage = () => {
// If we have < 5 accounts, it's restricted by BIP-44
if (this.props.accounts.length === 5) {
this.props.getPage(this.props.device, 1, this.props.selectedPath);
this.props.getPage(this.props.device, 1, this.props.selectedPath, false);
} else {
this.props.onAccountRestriction();
}
};

goToPreviousPage = () => {
this.props.getPage(this.props.device, -1, this.props.selectedPath);
this.props.getPage(this.props.device, -1, this.props.selectedPath, false);
};

setPath(pathValue) {
Expand Down
12 changes: 7 additions & 5 deletions ui/pages/create-account/connect-hardware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ class ConnectHardwareForm extends Component {
}

// Default values
this.getPage(device, 0, this.props.defaultHdPaths[device]);
this.getPage(device, 0, this.props.defaultHdPaths[device], true);
};

onPathChange = (path) => {
Expand Down Expand Up @@ -185,9 +185,9 @@ class ConnectHardwareForm extends Component {
}, SECOND * 5);
}

getPage = (device, page, hdPath) => {
getPage = (device, page, hdPath, loadHid) => {
this.props
.connectHardware(device, page, hdPath, this.context.t)
.connectHardware(device, page, hdPath, loadHid, this.context.t)
.then((accounts) => {
if (accounts.length) {
// If we just loaded the accounts for the first time
Expand Down Expand Up @@ -475,8 +475,10 @@ const mapDispatchToProps = (dispatch) => {
setHardwareWalletDefaultHdPath: ({ device, path }) => {
return dispatch(actions.setHardwareWalletDefaultHdPath({ device, path }));
},
connectHardware: (deviceName, page, hdPath, t) => {
return dispatch(actions.connectHardware(deviceName, page, hdPath, t));
connectHardware: (deviceName, page, hdPath, loadHid, t) => {
return dispatch(
actions.connectHardware(deviceName, page, hdPath, loadHid, t),
);
},
checkHardwareStatus: (deviceName, hdPath) => {
return dispatch(actions.checkHardwareStatus(deviceName, hdPath));
Expand Down
98 changes: 91 additions & 7 deletions ui/pages/create-account/connect-hardware/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import configureMockStore from 'redux-mock-store';
import { fireEvent, waitFor } from '@testing-library/react';
import thunk from 'redux-thunk';
import React from 'react';
import configureMockStore from 'redux-mock-store';

import { renderWithProvider } from '../../../../test/lib/render-helpers';
import {
LedgerTransportTypes,
Expand Down Expand Up @@ -50,6 +51,7 @@ const mockProps = {
hideAlert: () => jest.fn(),
unlockHardwareWalletAccount: () => jest.fn(),
setHardwareWalletDefaultHdPath: () => jest.fn(),
connectHardware: () => mockConnectHardware,
history: {
push: mockHistoryPush,
},
Expand Down Expand Up @@ -95,7 +97,7 @@ const mockState = {
describe('ConnectHardwareForm', () => {
const mockStore = configureMockStore([thunk])(mockState);

it('should match snapshot', () => {
it('matchs snapshot', () => {
const { container } = renderWithProvider(
<ConnectHardwareForm {...mockProps} />,
mockStore,
Expand All @@ -104,7 +106,7 @@ describe('ConnectHardwareForm', () => {
expect(container).toMatchSnapshot();
});

it('should close the form when close button is clicked', () => {
it('closes the form when close button is clicked', () => {
const { getByTestId } = renderWithProvider(
<ConnectHardwareForm {...mockProps} />,
mockStore,
Expand All @@ -116,7 +118,7 @@ describe('ConnectHardwareForm', () => {
});

describe('U2F Error', () => {
it('should render a U2F error', async () => {
it('renders a U2F error', async () => {
mockConnectHardware.mockRejectedValue(new Error('U2F Error'));
const mockStateWithU2F = Object.assign(mockState, {});
mockStateWithU2F.appState.ledgerTransportType = LedgerTransportTypes.u2f;
Expand Down Expand Up @@ -146,7 +148,7 @@ describe('ConnectHardwareForm', () => {
});
});

it('should render a different U2F error for firefox', async () => {
it('renders a different U2F error for firefox', async () => {
jest
.spyOn(window.navigator, 'userAgent', 'get')
.mockReturnValue(
Expand Down Expand Up @@ -180,7 +182,7 @@ describe('ConnectHardwareForm', () => {
});

describe('QR Hardware Wallet Steps', () => {
it('should render the QR hardware wallet steps', async () => {
it('renders the QR hardware wallet steps', async () => {
const { getByText, getByLabelText } = renderWithProvider(
<ConnectHardwareForm {...mockProps} />,
mockStore,
Expand All @@ -203,7 +205,7 @@ describe('ConnectHardwareForm', () => {
});

describe('Select Hardware', () => {
it('should check link buttons for Ngrave Zero brand', async () => {
it('checks link buttons for Ngrave Zero brand', async () => {
window.open = jest.fn();

const { getByLabelText, getByTestId } = renderWithProvider(
Expand All @@ -226,4 +228,86 @@ describe('ConnectHardwareForm', () => {
expect(window.open).toHaveBeenCalled();
});
});

describe('getPage method', () => {
beforeEach(() => {
mockConnectHardware.mockReset();
});

it('calls connectHardware with loadHid=true', async () => {
mockConnectHardware.mockReset();

const mockAccounts = [
{ address: '0xAddress1', balance: null, index: 0 },
{ address: '0xAddress2', balance: null, index: 1 },
];
mockConnectHardware.mockResolvedValue(mockAccounts);

renderWithProvider(<ConnectHardwareForm {...mockProps} />, mockStore);

const hdPath = "m/44'/60'/0'/0";
const deviceName = 'ledger';
const pageIndex = 0;
const loadHidValue = true;

await mockConnectHardware(
deviceName,
pageIndex,
hdPath,
loadHidValue,
jest.fn(),
);

expect(mockConnectHardware).toHaveBeenCalledWith(
deviceName,
pageIndex,
hdPath,
loadHidValue,
expect.any(Function),
);
});

it('calls connectHardware with loadHid=false', async () => {
mockConnectHardware.mockReset();

const mockAccounts = [
{ address: '0xAddress1', balance: null, index: 0 },
{ address: '0xAddress2', balance: null, index: 1 },
];
mockConnectHardware.mockResolvedValue(mockAccounts);

renderWithProvider(<ConnectHardwareForm {...mockProps} />, mockStore);

const hdPath = "m/44'/60'/0'/0";
const deviceName = 'ledger';
const pageIndex = 0;
const loadHidValue = false;

await mockConnectHardware(
deviceName,
pageIndex,
hdPath,
loadHidValue,
jest.fn(),
);

expect(mockConnectHardware).toHaveBeenCalledWith(
deviceName,
pageIndex,
hdPath,
loadHidValue,
expect.any(Function),
);
});

it('handles errors when connectHardware fails', async () => {
const testError = new Error('Test Error');
mockConnectHardware.mockReset();
mockConnectHardware.mockRejectedValue(testError);

renderWithProvider(<ConnectHardwareForm {...mockProps} />, mockStore);

await expect(mockConnectHardware()).rejects.toThrow('Test Error');
});
});
});
Loading
Loading