-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! feat: implement suite-common bluetooth code into Suite
- Loading branch information
1 parent
ef80901
commit 1a79397
Showing
2 changed files
with
37 additions
and
26 deletions.
There are no files selected for viewing
39 changes: 34 additions & 5 deletions
39
packages/suite/src/actions/bluetooth/bluetoothConnectDeviceThunk.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<typeof bluetoothIpc.connectDevice>; | ||
type BluetoothConnectDeviceThunkResult = { | ||
success: boolean; | ||
}; | ||
|
||
export const bluetoothConnectDeviceThunk = createThunk<ThunkResponse, { id: string }, void>( | ||
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 }); | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters