diff --git a/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.ts b/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.ts index eb7de6552..fa0ddd399 100644 --- a/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.ts +++ b/packages/core/src/internal/transport/ble/transport/BleDeviceConnection.ts @@ -198,10 +198,10 @@ export class BleDeviceConnection implements DeviceConnection { }); }, ); - const frames = this._apduSender.caseOf({ - Just: (apduSender) => apduSender.getFrames(apdu), - Nothing: () => [], - }); + const frames = this._apduSender.mapOrDefault( + (apduSender) => apduSender.getFrames(apdu), + [], + ); for (const frame of frames) { try { this._logger.debug("Sending Frame", { diff --git a/packages/core/src/internal/transport/ble/transport/WebBleTransport.ts b/packages/core/src/internal/transport/ble/transport/WebBleTransport.ts index 7c08ed007..33611668c 100644 --- a/packages/core/src/internal/transport/ble/transport/WebBleTransport.ts +++ b/packages/core/src/internal/transport/ble/transport/WebBleTransport.ts @@ -224,47 +224,37 @@ export class WebBleTransport implements Transport { return from(this.promptDeviceAccess()).pipe( switchMap(async (errorOrBleDevice) => - errorOrBleDevice.caseOf({ - Right: async (bleDevice) => { - // ble connect here as gatt server needs to be opened to fetch gatt service - if (bleDevice.gatt) { - try { - await bleDevice.gatt.connect(); - } catch (error) { - throw new OpeningConnectionError(error); - } + EitherAsync(async ({ liftEither, fromPromise }) => { + const bleDevice = await liftEither(errorOrBleDevice); + if (bleDevice.gatt) { + try { + await bleDevice.gatt.connect(); + } catch (error) { + throw new OpeningConnectionError(error); } - const errorOrBleGattService = - await this.getBleGattService(bleDevice); - return errorOrBleGattService.caseOf({ - Right: (bleGattService) => { - const errorOrBleDeviceInfos = - this.getBleDeviceInfos(bleGattService); - return errorOrBleDeviceInfos.caseOf({ - Right: (bleDeviceInfos) => { - const discoveredDevice = - this.getDiscoveredDeviceFrom(bleDeviceInfos); - this.setInternalDeviceFrom( - discoveredDevice, - bleDevice, - bleDeviceInfos, - bleGattService, - ); - return discoveredDevice; - }, - - Left: (error) => { - bleDevice.forget(); - throw error; - }, - }); - }, - Left: (error) => { - bleDevice.forget(); - throw error; - }, - }); - }, + } + try { + const bleGattService = await fromPromise( + this.getBleGattService(bleDevice), + ); + const bleDeviceInfos = await liftEither( + this.getBleDeviceInfos(bleGattService), + ); + const discoveredDevice = + this.getDiscoveredDeviceFrom(bleDeviceInfos); + this.setInternalDeviceFrom( + discoveredDevice, + bleDevice, + bleDeviceInfos, + bleGattService, + ); + return discoveredDevice; + } catch (error) { + await bleDevice.forget(); + throw error; + } + }).caseOf({ + Right: (discoveredDevice) => discoveredDevice, Left: (error) => { this._logger.error("Error while getting accessible device", { data: { error },