Skip to content

Commit

Permalink
fix(11215): add tests and adjust margin
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaryatrh committed Nov 6, 2024
1 parent 468105a commit d57c7bb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
4 changes: 4 additions & 0 deletions app/components/Views/LedgerConnect/index.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ const createStyles = (colors: Colors) =>
flex: 1,
marginTop: Device.getDeviceHeight() * 0.025,
},
bodyContainerWhithErrorMessage: {
flex: 1,
marginTop: Device.getDeviceHeight() * 0.01,
},
textContainer: {
marginTop: Device.getDeviceHeight() * 0.05,
},
Expand Down
29 changes: 25 additions & 4 deletions app/components/Views/LedgerConnect/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import useBluetooth from '../../hooks/Ledger/useBluetooth';
import useBluetoothDevices, {
BluetoothDevice,
} from '../../hooks/Ledger/useBluetoothDevices';
import { fireEvent } from '@testing-library/react-native';
import { fireEvent, waitFor } from '@testing-library/react-native';
import {
useNavigation,
NavigationProp,
Expand Down Expand Up @@ -35,9 +35,6 @@ interface UseBluetoothDevicesHook {
deviceScanError: boolean;
}

jest.mock('../../hooks/useBluetoothPermissions');
jest.mock('../../hooks/Ledger/useBluetooth');
jest.mock('../../hooks/Ledger/useBluetoothDevices');
jest.mock('../../hooks/Ledger/useLedgerBluetooth');
jest.mock('@react-navigation/native', () => ({
...jest.requireActual('@react-navigation/native'),
Expand All @@ -62,6 +59,11 @@ jest.mock('../../../util/device', () => ({
getDeviceHeight: jest.fn(),
}));

jest.mock('../../../core/Ledger/Ledger', () => ({
...jest.requireActual('../../../core/Ledger/Ledger'),
getDeviceId: jest.fn().mockResolvedValue('device-id'),
}));

jest.mock('../../../core/Engine', () => ({
context: {
KeyringController: {
Expand Down Expand Up @@ -366,4 +368,23 @@ describe('LedgerConnect', () => {

expect(ledgerLogicToRun).toHaveBeenCalled();
});

it('shows error message about multiple devices support', async () => {
isSendingLedgerCommands = true;
isAppLaunchConfirmationNeeded = false;
const { findByTestId } = renderWithProvider(
<LedgerConnect
onConnectLedger={onConfirmationComplete}
isSendingLedgerCommands={isSendingLedgerCommands}
isAppLaunchConfirmationNeeded={isAppLaunchConfirmationNeeded}
ledgerLogicToRun={ledgerLogicToRun}
ledgerError={undefined}
selectedDevice={selectedDevice}
setSelectedDevice={setSelectedDevice}
/>,
);
await waitFor(() => {
expect(findByTestId('multiple-devices-error-message')).toBeDefined();
});
});
});
15 changes: 10 additions & 5 deletions app/components/Views/LedgerConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ const LedgerConnect = ({
const onDeviceSelected = (currentDevice: BluetoothDevice | undefined) => {
const getStoredDeviceId = async () => {
const storedDeviceId = await getDeviceId();
const isMatchingDeviceId = currentDevice?.id === storedDeviceId;
const isMatchingDeviceId =
!storedDeviceId || currentDevice?.id === storedDeviceId;
setHasMatchingDeviceId(isMatchingDeviceId);

if (isMatchingDeviceId) {
Expand Down Expand Up @@ -128,6 +129,11 @@ const LedgerConnect = ({
});
};

const getStylesWithMultipleDevicesErrorMessage = () =>
hasMatchingDeviceId
? styles.bodyContainer
: styles.bodyContainerWhithErrorMessage;

useEffect(() => {
if (ledgerError) {
setLoading(false);
Expand Down Expand Up @@ -272,13 +278,12 @@ const LedgerConnect = ({
</Text>
)}
{!hasMatchingDeviceId && (
<Text red small>
Mutiple devices not supported yet, please forget your previous
device first before adding a new one
<Text red small testID={'multiple-devices-error-message'}>
{strings('ledger.multiple_devices_error_message')}
</Text>
)}
</View>
<View style={styles.bodyContainer}>
<View style={getStylesWithMultipleDevicesErrorMessage()}>
{!isAppLaunchConfirmationNeeded ? (
<Scan
onDeviceSelected={onDeviceSelected}
Expand Down
3 changes: 2 additions & 1 deletion locales/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -3318,7 +3318,8 @@
"blind_sign_error": "Blind signing error",
"blind_sign_error_message": "Blind signing is not enabled on your Ledger device. Please enable it in the settings.",
"user_reject_transaction": "User rejected the transaction",
"user_reject_transaction_message": "The user has rejected the transaction on the Ledger device."
"user_reject_transaction_message": "The user has rejected the transaction on the Ledger device.",
"multiple_devices_error_message": "Mutiple devices not supported yet, please forget your previous device first before adding a new one"
},
"account_actions": {
"edit_name": "Edit account name",
Expand Down

0 comments on commit d57c7bb

Please sign in to comment.