@@ -12,17 +12,23 @@ class BitBoxDeviceDatasource {
1212 Future <List <BitBoxDeviceModel >> scanDevices () async {
1313 try {
1414 if (! Platform .isAndroid) {
15- throw const BitBoxError .operationFailed (message: 'BitBox is only supported on Android' );
15+ throw const BitBoxError .operationFailed (
16+ message: 'BitBox is only supported on Android' ,
17+ );
1618 }
17-
19+
1820 final devices = await BitBoxApi .scanDevices ();
19-
20- return devices.map ((device) => BitBoxDeviceModel .fromBitBoxDevice (
21- deviceName: device.deviceName,
22- serialNumber: device.serialNumber,
23- product: device.product,
24- connectionType: BitBoxConnectionType .usb,
25- )).toList ();
21+
22+ return devices
23+ .map (
24+ (device) => BitBoxDeviceModel .fromBitBoxDevice (
25+ deviceName: device.deviceName,
26+ serialNumber: device.serialNumber,
27+ product: device.product,
28+ connectionType: BitBoxConnectionType .usb,
29+ ),
30+ )
31+ .toList ();
2632 } catch (e) {
2733 if (e is BitBoxError ) rethrow ;
2834 throw BitBoxError .operationFailed (message: e.toString ());
@@ -32,22 +38,28 @@ class BitBoxDeviceDatasource {
3238 Future <BitBoxDeviceModel > connectDevice (BitBoxDeviceModel device) async {
3339 try {
3440 if (! Platform .isAndroid) {
35- throw const BitBoxError .operationFailed (message: 'BitBox is only supported on Android' );
41+ throw const BitBoxError .operationFailed (
42+ message: 'BitBox is only supported on Android' ,
43+ );
3644 }
37-
38- final hasPermission = await BitBoxApi .requestPermission (device.deviceName);
45+
46+ final hasPermission = await BitBoxApi .requestPermission (
47+ device.deviceName,
48+ );
3949 if (! hasPermission) {
4050 throw const BitBoxError .permissionDenied ();
4151 }
42-
52+
4353 final opened = await BitBoxApi .openDevice (
44- device.deviceName,
54+ device.deviceName,
4555 device.serialNumber,
4656 );
4757 if (! opened) {
48- throw const BitBoxError .operationFailed (message: 'Failed to open device' );
58+ throw const BitBoxError .operationFailed (
59+ message: 'Failed to open device' ,
60+ );
4961 }
50-
62+
5163 _connectedDevices.add (device.serialNumber);
5264 _cachedDevice = device;
5365 return device;
@@ -60,7 +72,7 @@ class BitBoxDeviceDatasource {
6072 Future <String > unlockDevice (BitBoxDeviceModel device) async {
6173 try {
6274 final pairingCode = await BitBoxApi .startPairing (device.serialNumber);
63-
75+
6476 if (pairingCode != null && pairingCode.isNotEmpty) {
6577 return pairingCode;
6678 } else {
@@ -74,11 +86,13 @@ class BitBoxDeviceDatasource {
7486 Future <String > pairDevice (BitBoxDeviceModel device) async {
7587 try {
7688 final confirmed = await BitBoxApi .confirmPairing (device.serialNumber);
77-
89+
7890 if (! confirmed) {
79- throw const BitBoxError .operationFailed (message: 'Pairing confirmation failed' );
91+ throw const BitBoxError .operationFailed (
92+ message: 'Pairing confirmation failed' ,
93+ );
8094 }
81-
95+
8296 return await BitBoxApi .getRootFingerprint (device.serialNumber);
8397 } catch (e) {
8498 throw BitBoxError .operationFailed (message: e.toString ());
@@ -93,7 +107,7 @@ class BitBoxDeviceDatasource {
93107 }) async {
94108 try {
95109 final xpubType = isTestnet ? 'tpub' : 'xpub' ;
96-
110+
97111 final xpub = await BitBoxApi .getBtcXpub (
98112 serialNumber: device.serialNumber,
99113 keypath: derivationPath,
@@ -140,8 +154,10 @@ class BitBoxDeviceDatasource {
140154 required bool isTestnet,
141155 }) async {
142156 try {
143- final String bitboxScriptType = scriptType == ScriptType .bip49 ? 'p2wpkhp2sh' : 'p2wpkh' ;
144-
157+ final String bitboxScriptType = scriptType == ScriptType .bip49
158+ ? 'p2wpkhp2sh'
159+ : 'p2wpkh' ;
160+
145161 final verifiedAddress = await BitBoxApi .verifyAddress (
146162 serialNumber: device.serialNumber,
147163 keypath: derivationPath,
@@ -157,7 +173,7 @@ class BitBoxDeviceDatasource {
157173 Future <void > disconnectConnection (BitBoxDeviceModel device) async {
158174 try {
159175 await BitBoxApi .closeDevice (device.serialNumber);
160-
176+
161177 _connectedDevices.remove (device.serialNumber);
162178 if (_cachedDevice? .serialNumber == device.serialNumber) {
163179 _cachedDevice = null ;
@@ -180,7 +196,7 @@ class BitBoxDeviceDatasource {
180196 // Ignore individual device close errors during disposal
181197 }
182198 }
183-
199+
184200 _connectedDevices.clear ();
185201 _cachedDevice = null ;
186202 } catch (e) {
0 commit comments