Skip to content

Commit 58df0c4

Browse files
committed
feat: enrich verification failure callback with exception details
1 parent 253968b commit 58df0c4

7 files changed

Lines changed: 56 additions & 41 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ To display the SEC Modal, utilize the `SecModalBuilder` widget. It requires a co
9595
strategy: _connectionStrategy,
9696
payload: // Payload,
9797
onVerificationDone: (mesurement) {},
98-
onVerificationFailed: () {},
98+
onVerificationFailed: (exception) {
99+
// Handle verification failure. The exception provides details about the cause.
100+
},
99101
onDismiss: (){ } // Optionally
100102
canDismiss: true, // Define whether the user can dismiss the modal
101103
builder: (context, openModal) {

example/lib/main.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import 'package:example/virtual_strategy.dart';
22
import 'package:flutter/foundation.dart';
33
import 'package:flutter/material.dart';
4-
import 'package:mtrust_sec_kit/mtrust_sec_kit.dart';
5-
64
import 'package:liquid_flutter/liquid_flutter.dart';
5+
import 'package:mtrust_sec_kit/mtrust_sec_kit.dart';
76
import 'package:mtrust_urp_ble_strategy/mtrust_urp_ble_strategy.dart';
87

98
void main() {
@@ -102,8 +101,8 @@ class _MainAppState extends State<MainApp> {
102101
onVerificationDone: (measurement) {
103102
debugPrint("Verification done ${measurement.measurement}");
104103
},
105-
onVerificationFailed: () {
106-
debugPrint("Verification failed");
104+
onVerificationFailed: (exception) {
105+
debugPrint("Verification failed: $exception");
107106
},
108107
builder: (context, openModal) {
109108
return LdButton(

example/pubspec.lock

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -297,26 +297,26 @@ packages:
297297
dependency: transitive
298298
description:
299299
name: leak_tracker
300-
sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0"
300+
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
301301
url: "https://pub.dev"
302302
source: hosted
303-
version: "10.0.9"
303+
version: "11.0.2"
304304
leak_tracker_flutter_testing:
305305
dependency: transitive
306306
description:
307307
name: leak_tracker_flutter_testing
308-
sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573
308+
sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1"
309309
url: "https://pub.dev"
310310
source: hosted
311-
version: "3.0.9"
311+
version: "3.0.10"
312312
leak_tracker_testing:
313313
dependency: transitive
314314
description:
315315
name: leak_tracker_testing
316-
sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3"
316+
sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1"
317317
url: "https://pub.dev"
318318
source: hosted
319-
version: "3.0.1"
319+
version: "3.0.2"
320320
lints:
321321
dependency: transitive
322322
description:
@@ -392,18 +392,18 @@ packages:
392392
dependency: "direct main"
393393
description:
394394
name: mtrust_urp_ble_strategy
395-
sha256: "5100452a073f9af8597ceaf76424038de60077b3e268da996338f6d63b7f2d5a"
395+
sha256: e2c71e86d7b181b2aa14b1dfc7cfc5e59e1fe98c74188f2e5f961388de47b1ec
396396
url: "https://pub.dev"
397397
source: hosted
398-
version: "9.1.0-7"
398+
version: "9.1.0-12"
399399
mtrust_urp_core:
400400
dependency: transitive
401401
description:
402402
name: mtrust_urp_core
403-
sha256: "225745795a036ded39ec83eb1d88c53ff3f3d37afd6446a9bdf495f90637b7d3"
403+
sha256: f2d499a6774b0f23431a5e5e1b3713a00eca7d284505b2a956921ff0c86ce8d8
404404
url: "https://pub.dev"
405405
source: hosted
406-
version: "9.1.0-9"
406+
version: "9.1.0-12"
407407
mtrust_urp_types:
408408
dependency: "direct main"
409409
description:
@@ -416,18 +416,18 @@ packages:
416416
dependency: "direct main"
417417
description:
418418
name: mtrust_urp_ui
419-
sha256: ae8e8826dfd84a71662dcb560c3865609893e9ec237430f5c12e9f17ea097f93
419+
sha256: "066ff4ab77e04687de547dd771fffa56458f37a39c4cb6e18dc039bce01092cd"
420420
url: "https://pub.dev"
421421
source: hosted
422-
version: "9.1.0-9"
422+
version: "9.1.0-12"
423423
mtrust_urp_virtual_strategy:
424424
dependency: "direct main"
425425
description:
426426
name: mtrust_urp_virtual_strategy
427-
sha256: "3686e02ad12854f9a10d189c6499a21734cd347c81170561beca97ef7ad80006"
427+
sha256: eed4b781fdac4a8d7b797cd8793fadd8f13d6d28a2a9854c9cf8b6a4ed9738d8
428428
url: "https://pub.dev"
429429
source: hosted
430-
version: "9.1.0-7"
430+
version: "9.1.0-12"
431431
multi_split_view:
432432
dependency: transitive
433433
description:
@@ -669,10 +669,10 @@ packages:
669669
dependency: transitive
670670
description:
671671
name: test_api
672-
sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd
672+
sha256: "522f00f556e73044315fa4585ec3270f1808a4b186c936e612cab0b565ff1e00"
673673
url: "https://pub.dev"
674674
source: hosted
675-
version: "0.7.4"
675+
version: "0.7.6"
676676
typed_data:
677677
dependency: transitive
678678
description:
@@ -717,10 +717,10 @@ packages:
717717
dependency: transitive
718718
description:
719719
name: vector_math
720-
sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803"
720+
sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b
721721
url: "https://pub.dev"
722722
source: hosted
723-
version: "2.1.4"
723+
version: "2.2.0"
724724
vm_service:
725725
dependency: transitive
726726
description:
@@ -786,5 +786,5 @@ packages:
786786
source: hosted
787787
version: "3.1.3"
788788
sdks:
789-
dart: ">=3.7.0-0 <4.0.0"
789+
dart: ">=3.8.0-0 <4.0.0"
790790
flutter: ">=3.32.0"

lib/src/ui/scanning_view.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ class ScanningView extends StatelessWidget {
3131
) onVerificationDone;
3232

3333
/// Function to call when the verification fails.
34-
final Future<void> Function() onVerificationFailed;
34+
final Future<void> Function(
35+
SecReaderException? exception,
36+
) onVerificationFailed;
3537

3638
@override
3739
Widget build(BuildContext context) {
@@ -193,7 +195,10 @@ class ScanningView extends StatelessWidget {
193195
width: double.infinity,
194196
borderRadius: LdTheme.of(context).radius(LdSize.l),
195197
size: LdSize.l,
196-
onPressed: onVerificationFailed,
198+
onPressed: () => onVerificationFailed(
199+
measurementController.state.error?.exception
200+
as SecReaderException?,
201+
),
197202
loadingText: SecLocalizations.of(context).disconnecting,
198203
context: context,
199204
child: Text(

lib/src/ui/sec_modal.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class SecModalBuilder extends StatelessWidget {
4343
final void Function(UrpSecSecureMeasurement measurement) onVerificationDone;
4444

4545
/// Will be called if a verification failed.
46-
final void Function() onVerificationFailed;
46+
final void Function(SecReaderException?) onVerificationFailed;
4747

4848
/// Called when the user dismisses the sheet.
4949
final void Function()? onDismiss;
@@ -89,7 +89,7 @@ class SecModalBuilder extends StatelessWidget {
8989
return builder(context, () async {
9090
final result = await openModal();
9191
if (result is SecResultFailed) {
92-
onVerificationFailed();
92+
onVerificationFailed(result.exception);
9393
} else if (result is SecResultSuccess) {
9494
onVerificationDone(result.measurement);
9595
} else {
@@ -125,7 +125,13 @@ class SecResultSuccess extends SecResult {
125125
class SecResultDismissed extends SecResult {}
126126

127127
/// Returned in case of a failed SEC verification (e.g. a timeout)
128-
class SecResultFailed extends SecResult {}
128+
class SecResultFailed extends SecResult {
129+
/// Creates a new instance of [SecResultFailed]
130+
SecResultFailed(this.exception);
131+
132+
/// The exception that caused the failure.
133+
final SecReaderException? exception;
134+
}
129135

130136
/// Build a modal using [SecWidget], pops the result of the SEC verification.
131137
/// The result is either [SecResultSuccess], [SecResultFailed]
@@ -178,8 +184,8 @@ LdModal secModal({
178184
onVerificationDone: (UrpSecSecureMeasurement measurement) async {
179185
Navigator.of(context).pop(SecResultSuccess(measurement));
180186
},
181-
onVerificationFailed: () async {
182-
Navigator.of(context).pop(SecResultFailed());
187+
onVerificationFailed: (exception) async {
188+
Navigator.of(context).pop(SecResultFailed(exception));
183189
},
184190
tokenAmount: tokenAmount,
185191
),

lib/src/ui/sec_widget.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class SecWidget extends StatelessWidget {
3535
) onVerificationDone;
3636

3737
/// Will be called if a verification failed.
38-
final Future<void> Function() onVerificationFailed;
38+
final Future<void> Function(SecReaderException?) onVerificationFailed;
3939

4040
/// Amount of token to be requested on token refresh.
4141
final int? tokenAmount;
@@ -104,7 +104,10 @@ class SecWidget extends StatelessWidget {
104104
)
105105
else
106106
LdButtonWarning(
107-
onPressed: onVerificationFailed,
107+
onPressed: () => onVerificationFailed(
108+
controller.state.error?.exception
109+
as SecReaderException?,
110+
),
108111
context: context,
109112
child: Text(
110113
locale.done,
@@ -138,9 +141,9 @@ class SecWidget extends StatelessWidget {
138141
controller.reset();
139142
await onVerificationDone(measurement);
140143
},
141-
onVerificationFailed: () async {
144+
onVerificationFailed: (e) async {
142145
controller.reset();
143-
await onVerificationFailed();
146+
await onVerificationFailed(e);
144147
},
145148
remainingScans: controller.state.result?.gsa,
146149
);

test/sec_widget_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void main() {
2727
storageAdapter: storageAdapter,
2828
payload: '',
2929
onVerificationDone: (_) async {},
30-
onVerificationFailed: () async {},
30+
onVerificationFailed: (_) async {},
3131
),
3232
),
3333
);
@@ -48,7 +48,7 @@ void main() {
4848
storageAdapter: storageAdapter,
4949
payload: '',
5050
onVerificationDone: (_) async {},
51-
onVerificationFailed: () async {},
51+
onVerificationFailed: (_) async {},
5252
),
5353
),
5454
);
@@ -74,7 +74,7 @@ void main() {
7474
storageAdapter: storageAdapter,
7575
payload: '',
7676
onVerificationDone: (_) async {},
77-
onVerificationFailed: () async {},
77+
onVerificationFailed: (_) async {},
7878
),
7979
),
8080
);
@@ -106,7 +106,7 @@ void main() {
106106
storageAdapter: storageAdapter,
107107
payload: '',
108108
onVerificationDone: (_) async {},
109-
onVerificationFailed: () async {},
109+
onVerificationFailed: (_) async {},
110110
),
111111
),
112112
);
@@ -142,7 +142,7 @@ void main() {
142142
storageAdapter: storageAdapter,
143143
payload: '',
144144
onVerificationDone: (_) async {},
145-
onVerificationFailed: () async {},
145+
onVerificationFailed: (_) async {},
146146
),
147147
),
148148
);
@@ -179,7 +179,7 @@ void main() {
179179
storageAdapter: storageAdapter,
180180
payload: '',
181181
onVerificationDone: (_) async {},
182-
onVerificationFailed: () async {},
182+
onVerificationFailed: (_) async {},
183183
),
184184
),
185185
);

0 commit comments

Comments
 (0)