diff --git a/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx b/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx index fc6c2f37ff5e..cb97343a9e75 100644 --- a/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx +++ b/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx @@ -1,10 +1,10 @@ import { useEffect, useState } from 'react'; -import { desktopApi, ElectronBluetoothDevice } from '@trezor/suite-desktop-api'; import TrezorConnect from '@trezor/connect'; import { Card, ElevationUp, Column } from '@trezor/components'; import { spacings } from '@trezor/theme'; import { notificationsActions } from '@suite-common/toast-notifications'; +import { bluetoothManager, BluetoothDevice } from '@trezor/transport-bluetooth'; import { BluetoothNotEnabled } from './errors/BluetoothNotEnabled'; import { BluetoothDeviceList } from './BluetoothDeviceList'; @@ -30,39 +30,37 @@ export const BluetoothConnect = ({ onClose }: BluetoothConnectProps) => { type: 'found', uuid: 'TODO', }); - const [deviceList, setDeviceList] = useState([]); - const [selectedDevice, setSelectedDevice] = useState( - undefined, - ); + const [deviceList, setDeviceList] = useState([]); + const [selectedDevice, setSelectedDevice] = useState(undefined); const dispatch = useDispatch(); useEffect(() => { - desktopApi.on('bluetooth/adapter-event', isPowered => { - console.warn('bluetooth/adapter-event', isPowered); + bluetoothManager.on('adapter-event', isPowered => { + console.warn('adapter-event', isPowered); setBluetoothEnabled(isPowered); if (!isPowered) { setDeviceList([]); } }); - desktopApi.on('bluetooth/device-list-update', list => { - console.warn('bluetooth/device-list-update', list); + bluetoothManager.on('device-list-update', list => { + console.warn('device-list-update', list); setDeviceList(list); }); - desktopApi.on('bluetooth/device-connection-status', event => { - console.warn('bluetooth/device-connection-status', event); + bluetoothManager.on('device-connection-status', event => { + console.warn('device-connection-status', event); setSelectedDeviceStatus(event); }); - desktopApi.bluetoothRequestDevice(); + bluetoothManager.startScan(); return () => { - desktopApi.removeAllListeners('bluetooth/adapter-event'); - desktopApi.removeAllListeners('bluetooth/device-list-update'); - desktopApi.removeAllListeners('bluetooth/device-connection-status'); - desktopApi.bluetoothStopScan(); + bluetoothManager.removeAllListeners('adapter-event'); + bluetoothManager.removeAllListeners('device-list-update'); + bluetoothManager.removeAllListeners('device-connection-status'); + bluetoothManager.stopScan(); }; }, []); @@ -86,7 +84,7 @@ export const BluetoothConnect = ({ onClose }: BluetoothConnectProps) => { setSelectedDevice(deviceList.find(d => d.uuid === uuid)); setSelectedDeviceStatus({ type: 'pairing', uuid }); - const result = await desktopApi.bluetoothConnectDevice(uuid); + const result = await bluetoothManager.connectDevice(uuid); console.log('result', result); diff --git a/packages/suite/src/components/suite/bluetooth/types.ts b/packages/suite/src/components/suite/bluetooth/types.ts index 0582e037f34f..9c853e80dfb3 100644 --- a/packages/suite/src/components/suite/bluetooth/types.ts +++ b/packages/suite/src/components/suite/bluetooth/types.ts @@ -1,9 +1,9 @@ -import { BluetoothDeviceConnectionStatus } from '@trezor/suite-desktop-api'; +import type { DeviceConnectionStatus } from '@trezor/transport-bluetooth'; export type FakeScanStatus = 'running' | 'done'; export type DeviceBluetoothStatus = - | BluetoothDeviceConnectionStatus + | DeviceConnectionStatus | { uuid: string; type: 'found' | 'error';