From eb1ea592fcf73ed4bfc705afe83376c541da2130 Mon Sep 17 00:00:00 2001 From: Joshua Wellbrock Date: Sun, 23 Feb 2025 10:50:22 +0100 Subject: [PATCH 1/2] feat: adjustable modal size, dismiss button displayed only if canDismiss true --- lib/src/ui/sec_modal.dart | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/src/ui/sec_modal.dart b/lib/src/ui/sec_modal.dart index 0f6ba28..e058db8 100644 --- a/lib/src/ui/sec_modal.dart +++ b/lib/src/ui/sec_modal.dart @@ -13,7 +13,7 @@ import 'package:mtrust_sec_kit/src/ui/sec_result.dart'; /// Provide a [builder] that renders some UI with a callback to open the sheet. class SecModalBuilder extends StatelessWidget { /// Creates a new instance of [SecModalBuilder] - const SecModalBuilder({ + const SecModalBuilder({ required this.strategy, required this.payload, required this.onVerificationDone, @@ -23,6 +23,7 @@ class SecModalBuilder extends StatelessWidget { this.disconnectOnClose = true, this.turnOffOnClose = true, this.canDismiss = true, + this.fixedDialogSize = const Size(400, 400), super.key, }); @@ -53,6 +54,9 @@ class SecModalBuilder extends StatelessWidget { /// Whether the modal can be dissmissed by the user final bool canDismiss; + /// Size of the modal + final Size fixedDialogSize; + @override Widget build(BuildContext context) { var topRadius = LdTheme.of(context).sizingConfig.radiusM; @@ -101,6 +105,7 @@ class SecModalBuilder extends StatelessWidget { useSafeArea: useSafeArea, strategy: strategy, payload: payload, + fixedDialogSize: fixedDialogSize, ), ); } @@ -146,15 +151,18 @@ LdModal secModal({ /// Whether to use safe area inside the modal required bool useSafeArea, + + /// Size of the modal + Size fixedDialogSize = const Size(400, 400), }) { return LdModal( disableScrolling: true, padding: EdgeInsets.zero, noHeader: true, - showDismissButton: false, + showDismissButton: canDismiss, userCanDismiss: canDismiss, topRadius: topRadius, - fixedDialogSize: const Size(400, 400), + fixedDialogSize: fixedDialogSize, bottomRadius: bottomRadius, useSafeArea: useSafeArea, insets: insets, From a04b89bfdfd439566ac72e1eef38cd5283179e29 Mon Sep 17 00:00:00 2001 From: Joshua Wellbrock Date: Sun, 23 Feb 2025 11:20:37 +0100 Subject: [PATCH 2/2] fix: set token amount in default workflow --- lib/src/ui/sec_modal.dart | 13 +++++++++++-- lib/src/ui/sec_widget.dart | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/src/ui/sec_modal.dart b/lib/src/ui/sec_modal.dart index e058db8..50717f0 100644 --- a/lib/src/ui/sec_modal.dart +++ b/lib/src/ui/sec_modal.dart @@ -24,6 +24,7 @@ class SecModalBuilder extends StatelessWidget { this.turnOffOnClose = true, this.canDismiss = true, this.fixedDialogSize = const Size(400, 400), + this.tokenAmount, super.key, }); @@ -51,12 +52,15 @@ class SecModalBuilder extends StatelessWidget { /// The builder that opens the sheet. final Widget Function(BuildContext context, Function openSheet) builder; - /// Whether the modal can be dissmissed by the user + /// Whether the modal can be dissmissed by the user. final bool canDismiss; - /// Size of the modal + /// Size of the modal. final Size fixedDialogSize; + /// Amount of tokens to be requested on token refresh. + final int? tokenAmount; + @override Widget build(BuildContext context) { var topRadius = LdTheme.of(context).sizingConfig.radiusM; @@ -106,6 +110,7 @@ class SecModalBuilder extends StatelessWidget { strategy: strategy, payload: payload, fixedDialogSize: fixedDialogSize, + tokenAmount: tokenAmount, ), ); } @@ -154,6 +159,9 @@ LdModal secModal({ /// Size of the modal Size fixedDialogSize = const Size(400, 400), + + /// Amount of token to be requested on token refresh + int? tokenAmount, }) { return LdModal( disableScrolling: true, @@ -178,6 +186,7 @@ LdModal secModal({ onVerificationFailed: () async { Navigator.of(context).pop(SecResultFailed()); }, + tokenAmount: tokenAmount, ), ).padL(), ); diff --git a/lib/src/ui/sec_widget.dart b/lib/src/ui/sec_widget.dart index 2c47f58..ff93360 100644 --- a/lib/src/ui/sec_widget.dart +++ b/lib/src/ui/sec_widget.dart @@ -16,6 +16,7 @@ class SecWidget extends StatelessWidget { required this.onVerificationDone, required this.onVerificationFailed, this.storageAdapter, + this.tokenAmount, super.key, }); @@ -35,6 +36,9 @@ class SecWidget extends StatelessWidget { /// Will be called if a verification failed. final Future Function() onVerificationFailed; + /// Amount of token to be requested on token refresh. + final int? tokenAmount; + @override Widget build(BuildContext context) { return DeviceConnector( @@ -49,6 +53,9 @@ class SecWidget extends StatelessWidget { final reader = SECReader( connectionStrategy: strategy, ); + if(tokenAmount != null) { + reader.setTokenAmount(tokenAmount!); + } return reader.prime(payload); }, ),