mirror of
https://github.com/trezor/trezor-suite.git
synced 2026-03-24 16:17:15 +01:00
fix(suite-native): do not show setup card for unauthorized devices
This commit is contained in:
@@ -7,6 +7,7 @@ import { useNavigation } from '@react-navigation/native';
|
||||
import { bluetoothActions } from '@suite-common/bluetooth';
|
||||
import {
|
||||
selectIsAnyPhysicalDeviceConnectedViaUsb,
|
||||
selectIsDeviceAuthorized,
|
||||
selectIsDeviceThpLocked,
|
||||
} from '@suite-common/device';
|
||||
import { acquireDevice } from '@suite-common/wallet-core';
|
||||
@@ -29,13 +30,14 @@ export const useConnectDeviceHandler = () => {
|
||||
const dispatch = useDispatch();
|
||||
const navigation = useNavigation<NavigationProps>();
|
||||
|
||||
const isDeviceAuthorized = useSelector(selectIsDeviceAuthorized);
|
||||
const isDeviceThpLocked = useSelector(selectIsDeviceThpLocked);
|
||||
const isAnyPhysicalDeviceConnectedViaUsb = useSelector(
|
||||
selectIsAnyPhysicalDeviceConnectedViaUsb,
|
||||
);
|
||||
|
||||
const onConnectDevicePress = useCallback(() => {
|
||||
if (isDeviceThpLocked) {
|
||||
if (!isDeviceAuthorized || isDeviceThpLocked) {
|
||||
dispatch(acquireDevice({}));
|
||||
} else if (isAnyPhysicalDeviceConnectedViaUsb || Platform.OS === 'ios') {
|
||||
// Make sure auto-connect is enabled in case some device was manually disconnected.
|
||||
@@ -48,7 +50,13 @@ export const useConnectDeviceHandler = () => {
|
||||
screen: AuthorizeDeviceStackRoutes.ConnectDeviceCrossroads,
|
||||
});
|
||||
}
|
||||
}, [dispatch, isDeviceThpLocked, isAnyPhysicalDeviceConnectedViaUsb, navigation]);
|
||||
}, [
|
||||
dispatch,
|
||||
isDeviceAuthorized,
|
||||
isDeviceThpLocked,
|
||||
isAnyPhysicalDeviceConnectedViaUsb,
|
||||
navigation,
|
||||
]);
|
||||
|
||||
return { onConnectDevicePress };
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useSelector } from 'react-redux';
|
||||
import {
|
||||
selectIsDeviceAuthorized,
|
||||
selectIsDeviceConnected,
|
||||
selectIsDeviceInBootloader,
|
||||
selectIsDeviceInitialized,
|
||||
selectIsDeviceThpLocked,
|
||||
selectIsPortfolioTrackerDevice,
|
||||
@@ -17,6 +18,7 @@ import { EmptyPortfolioTrackerState } from './EmptyPortfolioTrackerState';
|
||||
import { UninitializedConnectedDeviceState } from './UninitializedConnectedDeviceState';
|
||||
|
||||
export const EmptyHomeRenderer = () => {
|
||||
const isDeviceInBootloader = useSelector(selectIsDeviceInBootloader);
|
||||
const isDeviceAuthorized = useSelector(selectIsDeviceAuthorized);
|
||||
const isPortfolioTrackerDevice = useSelector(selectIsPortfolioTrackerDevice);
|
||||
const hasOnlyEmptyPortfolioTracker = useSelector(selectHasOnlyEmptyPortfolioTracker);
|
||||
@@ -35,7 +37,12 @@ export const EmptyHomeRenderer = () => {
|
||||
|
||||
let ScreenContent = EmptyPortfolioTrackerState;
|
||||
|
||||
if (isDeviceSetupSupported && isDeviceConnected && !isDeviceInitialized && !isDeviceThpLocked) {
|
||||
if (
|
||||
isDeviceSetupSupported &&
|
||||
isDeviceConnected &&
|
||||
!isDeviceInitialized &&
|
||||
(isDeviceInBootloader || (isDeviceAuthorized && !isDeviceThpLocked))
|
||||
) {
|
||||
ScreenContent = UninitializedConnectedDeviceState;
|
||||
}
|
||||
// Crossroads should be displayed if there is no real device connected and portfolio tracker has no accounts
|
||||
|
||||
@@ -27,7 +27,52 @@ describe('EmptyHomeRenderer', () => {
|
||||
).toBeTruthy();
|
||||
};
|
||||
|
||||
it('should display UninitializedConnectedDeviceState when device is connected but not initialized', () => {
|
||||
it('should display UninitializedConnectedDeviceState when device is connected in bootloader, not initialized', () => {
|
||||
renderEmptyHomeRenderer({
|
||||
device: {
|
||||
selectedDevice: {
|
||||
connected: true,
|
||||
mode: 'bootloader',
|
||||
features: { initialized: false, internal_model: DeviceModelInternal.T3B1 },
|
||||
},
|
||||
devices: [{ id: 'device_id' }],
|
||||
},
|
||||
});
|
||||
|
||||
expectUninitializedConnectedDeviceState();
|
||||
});
|
||||
|
||||
it('should display UninitializedConnectedDeviceState when device is connected, authorized, not initialized', () => {
|
||||
renderEmptyHomeRenderer({
|
||||
device: {
|
||||
selectedDevice: {
|
||||
connected: true,
|
||||
state: {},
|
||||
features: { initialized: false, internal_model: DeviceModelInternal.T3B1 },
|
||||
},
|
||||
devices: [{ id: 'device_id' }],
|
||||
},
|
||||
});
|
||||
|
||||
expectUninitializedConnectedDeviceState();
|
||||
});
|
||||
|
||||
it('should not display EmptyPortfolioCrossroadsState when device is connected, not initialized, but model does not support setup', () => {
|
||||
renderEmptyHomeRenderer({
|
||||
device: {
|
||||
selectedDevice: {
|
||||
connected: true,
|
||||
state: undefined,
|
||||
features: { initialized: false, internal_model: DeviceModelInternal.T1B1 },
|
||||
},
|
||||
devices: [{ id: 'device_id' }],
|
||||
},
|
||||
});
|
||||
|
||||
expectEmptyPortfolioCrossroadsState();
|
||||
});
|
||||
|
||||
it('should not display EmptyPortfolioCrossroadsState when device is connected, not initialized, but not authorized', () => {
|
||||
renderEmptyHomeRenderer({
|
||||
device: {
|
||||
selectedDevice: {
|
||||
@@ -38,15 +83,16 @@ describe('EmptyHomeRenderer', () => {
|
||||
},
|
||||
});
|
||||
|
||||
expectUninitializedConnectedDeviceState();
|
||||
expectEmptyPortfolioCrossroadsState();
|
||||
});
|
||||
|
||||
it('should not display UninitializedConnectedDeviceState when device is connected, not initialized, but model does not support setup', () => {
|
||||
it('should not display EmptyPortfolioCrossroadsState when device is connected, not initialized, but thp-locked', () => {
|
||||
renderEmptyHomeRenderer({
|
||||
device: {
|
||||
selectedDevice: {
|
||||
connected: true,
|
||||
features: { initialized: false, internal_model: DeviceModelInternal.T1B1 },
|
||||
status: 'thp-locked',
|
||||
features: { initialized: false, internal_model: DeviceModelInternal.T3B1 },
|
||||
},
|
||||
devices: [{ id: 'device_id' }],
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user