diff --git a/packages/suite/src/actions/bluetooth/bluetoothConnectDeviceThunk.ts b/packages/suite/src/actions/bluetooth/bluetoothConnectDeviceThunk.ts index 6ca9a7b847c..79457ffae86 100644 --- a/packages/suite/src/actions/bluetooth/bluetoothConnectDeviceThunk.ts +++ b/packages/suite/src/actions/bluetooth/bluetoothConnectDeviceThunk.ts @@ -1,14 +1,43 @@ -import { BLUETOOTH_PREFIX } from '@suite-common/bluetooth'; +import { BLUETOOTH_PREFIX, bluetoothActions } from '@suite-common/bluetooth'; import { createThunk } from '@suite-common/redux-utils'; +import { notificationsActions } from '@suite-common/toast-notifications'; import { bluetoothIpc } from '@trezor/transport-bluetooth'; -type ThunkResponse = ReturnType; +type BluetoothConnectDeviceThunkResult = { + success: boolean; +}; -export const bluetoothConnectDeviceThunk = createThunk( +export const bluetoothConnectDeviceThunk = createThunk< + BluetoothConnectDeviceThunkResult, + { id: string }, + void +>( `${BLUETOOTH_PREFIX}/bluetoothConnectDeviceThunk`, - async ({ id }, { fulfillWithValue }) => { + async ({ id }, { fulfillWithValue, dispatch }) => { const result = await bluetoothIpc.connectDevice(id); - return fulfillWithValue(result); + if (!result.success) { + dispatch( + bluetoothActions.connectDeviceEventAction({ + id, + connectionStatus: { type: 'error', error: result.error }, + }), + ); + dispatch( + notificationsActions.addToast({ + type: 'error', + error: result.error, + }), + ); + } else { + dispatch( + bluetoothActions.connectDeviceEventAction({ + id, + connectionStatus: { type: 'connected' }, + }), + ); + } + + return fulfillWithValue({ success: result.success }); }, ); diff --git a/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx b/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx index ced55cd7035..48c746ed853 100644 --- a/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx +++ b/packages/suite/src/components/suite/bluetooth/BluetoothConnect.tsx @@ -7,7 +7,6 @@ import { selectKnownDevices, selectScanStatus, } from '@suite-common/bluetooth'; -import { notificationsActions } from '@suite-common/toast-notifications'; import { Card, Column, ElevationUp } from '@trezor/components'; import { spacings } from '@trezor/theme'; import { BluetoothDevice } from '@trezor/transport-bluetooth'; @@ -24,6 +23,7 @@ import { BluetoothVersionNotCompatible } from './errors/BluetoothVersionNotCompa import { bluetoothConnectDeviceThunk } from '../../../actions/bluetooth/bluetoothConnectDeviceThunk'; import { bluetoothStartScanningThunk } from '../../../actions/bluetooth/bluetoothStartScanningThunk'; import { bluetoothStopScanningThunk } from '../../../actions/bluetooth/bluetoothStopScanningThunk'; +import { closeModalApp } from '../../../actions/suite/routerActions'; import { useDispatch, useSelector } from '../../../hooks/suite'; const SCAN_TIMEOUT = 30_000; @@ -100,26 +100,8 @@ export const BluetoothConnect = ({ onClose, uiMode }: BluetoothConnectProps) => setSelectedDeviceId(id); const result = await dispatch(bluetoothConnectDeviceThunk({ id })).unwrap(); - if (!result.success) { - dispatch( - bluetoothActions.connectDeviceEventAction({ - id, - connectionStatus: { type: 'error', error: result.error }, - }), - ); - dispatch( - notificationsActions.addToast({ - type: 'error', - error: result.error, - }), - ); - } else { - dispatch( - bluetoothActions.connectDeviceEventAction({ - id, - connectionStatus: { type: 'connected' }, - }), - ); + if (uiMode === 'card' && result.success) { + dispatch(closeModalApp()); } };