From 5000d826fb8bd38e729489ece2c36240a6a69091 Mon Sep 17 00:00:00 2001 From: Gabriel Restori Soares Date: Wed, 30 Nov 2022 09:47:49 +0100 Subject: [PATCH] FAT-659 Automatically select last seen device if compatible for CLS (#1911) * FAT-659 Automatically select last seen device if compatible for CLS * FAT-659 Add changelog --- .changeset/warm-fishes-talk.md | 5 +++++ .../src/screens/CustomImage/Step3Transfer.tsx | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .changeset/warm-fishes-talk.md diff --git a/.changeset/warm-fishes-talk.md b/.changeset/warm-fishes-talk.md new file mode 100644 index 000000000000..be20f09b65f1 --- /dev/null +++ b/.changeset/warm-fishes-talk.md @@ -0,0 +1,5 @@ +--- +"live-mobile": minor +--- + +Auto-select the last connected device for CLS if it is a Nano FTS diff --git a/apps/ledger-live-mobile/src/screens/CustomImage/Step3Transfer.tsx b/apps/ledger-live-mobile/src/screens/CustomImage/Step3Transfer.tsx index 78dabd7d0a2a..cad61f2e759c 100644 --- a/apps/ledger-live-mobile/src/screens/CustomImage/Step3Transfer.tsx +++ b/apps/ledger-live-mobile/src/screens/CustomImage/Step3Transfer.tsx @@ -1,6 +1,6 @@ -import React, { useCallback, useState } from "react"; +import React, { useCallback, useEffect, useState } from "react"; import { ScrollView } from "react-native"; -import { useDispatch } from "react-redux"; +import { useDispatch, useSelector } from "react-redux"; import { Flex } from "@ledgerhq/native-ui"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import { Device } from "@ledgerhq/live-common/hw/actions/types"; @@ -17,6 +17,7 @@ import { StackNavigatorProps, } from "../../components/RootNavigator/types/helpers"; import { CustomImageNavigatorParamList } from "../../components/RootNavigator/types/CustomImageNavigator"; +import { lastConnectedDeviceSelector } from "../../reducers/settings"; const deviceModelIds = [DeviceModelId.nanoFTS]; @@ -43,7 +44,15 @@ type NavigationProps = BaseComposite< const Step3Transfer = ({ route, navigation }: NavigationProps) => { const dispatch = useDispatch(); const { rawData, device: deviceFromRoute, previewData } = route.params; + const [device, setDevice] = useState(deviceFromRoute); + const lastConnectedDevice = useSelector(lastConnectedDeviceSelector); + + useEffect(() => { + if (!device && lastConnectedDevice?.modelId === DeviceModelId.nanoFTS) { + setDevice(lastConnectedDevice); + } + }, [lastConnectedDevice, device]); const handleError = useCallback( (error: Error) => {