Skip to content

Commit 5f15da1

Browse files
authored
Support: BLE pairing flow imports and names (#1143)
* fix: incorrect import * chore: rename BleDevicesScanning * chore: type for PathToDeviceParam * feat: choice of navigation type: replace or navigate * chore: changeset * fix: not coming back to a successful pairing
1 parent 6875f14 commit 5f15da1

File tree

3 files changed

+26
-6
lines changed

3 files changed

+26
-6
lines changed

.changeset/five-carpets-leave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"live-mobile": patch
3+
---
4+
5+
Fix new BLE pairing flow, with more flexible options

apps/ledger-live-mobile/src/screens/BleDevicePairingFlow/BleDeviceScanning.tsx renamed to apps/ledger-live-mobile/src/screens/BleDevicePairingFlow/BleDevicesScanning.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { useSelector } from "react-redux";
1010
import { ScannedDevice } from "@ledgerhq/live-common/ble/types";
1111
import { getDeviceModel } from "@ledgerhq/devices";
1212
import { DeviceModelId } from "@ledgerhq/types-devices";
13+
import TransportBLE from "@ledgerhq/react-native-hw-transport-ble";
1314

1415
import { knownDevicesSelector } from "../../reducers/ble";
15-
import TransportBLE from "../../react-native-hw-transport-ble";
1616
import LocationRequired from "../LocationRequired";
1717
import BleDeviceItem from "./BleDeviceItem";
1818
import type { BleDevicePairingFlowProps } from "./index";

apps/ledger-live-mobile/src/screens/BleDevicePairingFlow/index.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { SafeAreaView } from "react-native-safe-area-context";
1010
import { Flex } from "@ledgerhq/native-ui";
1111
import type { BaseNavigatorStackParamList } from "../../components/RootNavigator/BaseNavigator";
1212
import RequiresBLE from "../../components/RequiresBLE";
13-
import { BleDevicesScanning } from "./BleDeviceScanning";
13+
import { BleDevicesScanning } from "./BleDevicesScanning";
1414
import { BleDevicePairing } from "./BleDevicePairing";
1515
import { addKnownDevice } from "../../actions/ble";
1616

@@ -20,14 +20,16 @@ export type NavigateInput = {
2020
};
2121

2222
export type PathToDeviceParam = PropertyPath;
23+
export type NavigationType = "navigate" | "replace";
2324

2425
export type BleDevicePairingFlowParams = {
2526
filterByDeviceModelId?: DeviceModelId;
2627
areKnownDevicesDisplayed?: boolean;
2728
onSuccessAddToKnownDevices?: boolean;
29+
navigationType?: NavigationType;
2830
onSuccessNavigateToConfig: {
2931
navigateInput: NavigateInput;
30-
pathToDeviceParam: string;
32+
pathToDeviceParam: PathToDeviceParam;
3133
};
3234
};
3335

@@ -40,9 +42,11 @@ export type BleDevicePairingFlowProps = StackScreenProps<
4042
* Screen handling the BLE flow with a scanning step and a pairing step
4143
* @param navigation react-navigation navigation object
4244
* @param route react-navigation route object. The route params are:
43-
* - filterByDeviceModelId: a device model id to filter on
45+
* - filterByDeviceModelId: (optional, default to none) a device model id to filter on
4446
* - areKnownDevicesDisplayed: boolean, display the already known device if true,
4547
* filter out them if false (default to true)
48+
* - navigationType: (optional, default to "navigate") when navigating after a successful pairing,
49+
* choose between a "replace" or a "navigate"
4650
* - onSuccessNavigateToConfig: object containing navigation config parameters when successful pairing:
4751
* - navigateInput: navigation object given as input to navigation.navigate. 2 mandatory props:
4852
* - name: navigator name or screen name if no need to specify a navigator
@@ -74,6 +78,7 @@ export const BleDevicePairingFlow = ({
7478
filterByDeviceModelId,
7579
areKnownDevicesDisplayed = true,
7680
onSuccessAddToKnownDevices = false,
81+
navigationType = "navigate",
7782
onSuccessNavigateToConfig: { navigateInput, pathToDeviceParam },
7883
} = route.params;
7984
const [deviceToPair, setDeviceToPair] = useState<Device | null>(null);
@@ -106,16 +111,26 @@ export const BleDevicePairingFlow = ({
106111
setFromPath(navigateInput, pathToDeviceParam, device);
107112
} else {
108113
console.error(
109-
`BLE pairing flow: device path param ${pathToDeviceParam} not existing on navigation input`,
114+
`BLE pairing flow: device path param ${String(
115+
pathToDeviceParam,
116+
)} not existing on navigation input`,
110117
);
111118
}
112119

113-
navigation.navigate(navigateInput);
120+
// Before navigating, to never come back a the successful pairing but to the scanning part
121+
setDeviceToPair(null);
122+
123+
if (navigationType === "replace") {
124+
navigation.replace(navigateInput.name, { ...navigateInput.params });
125+
} else {
126+
navigation.navigate(navigateInput);
127+
}
114128
},
115129
[
116130
dispatchRedux,
117131
navigateInput,
118132
navigation,
133+
navigationType,
119134
onSuccessAddToKnownDevices,
120135
pathToDeviceParam,
121136
],

0 commit comments

Comments
 (0)