Skip to content

Commit

Permalink
breaking change
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Dec 3, 2024
1 parent 2d03022 commit 8b73a56
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
32 changes: 15 additions & 17 deletions packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -30,39 +30,37 @@ export const BluetoothConnect = ({ onClose }: BluetoothConnectProps) => {
type: 'found',
uuid: 'TODO',
});
const [deviceList, setDeviceList] = useState<ElectronBluetoothDevice[]>([]);
const [selectedDevice, setSelectedDevice] = useState<ElectronBluetoothDevice | undefined>(
undefined,
);
const [deviceList, setDeviceList] = useState<BluetoothDevice[]>([]);
const [selectedDevice, setSelectedDevice] = useState<BluetoothDevice | undefined>(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();
};
}, []);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions packages/suite/src/components/suite/bluetooth/types.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down

0 comments on commit 8b73a56

Please sign in to comment.