From d75cfed586a226c01f1db25a8bb6921e67472783 Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Thu, 23 Jan 2025 15:57:16 +0300 Subject: [PATCH] fix: update refund action text (#324) * fix: update refund action text fixes #322 * Refresh refundable list on PaymentRefundable SDK event (#327) fixes #325 * Add warning on home page if user has refundables (#328) fixes #326 --- lib/cubit/refund/refund_cubit.dart | 5 +- lib/cubit/refund/refund_state.dart | 2 + .../widgets/account_required_actions.dart | 238 ++++++++++-------- .../home/widgets/home_drawer/home_drawer.dart | 4 +- .../refund/widgets/refund_item_action.dart | 2 +- 5 files changed, 142 insertions(+), 109 deletions(-) diff --git a/lib/cubit/refund/refund_cubit.dart b/lib/cubit/refund/refund_cubit.dart index ab34dbcd..4885636f 100644 --- a/lib/cubit/refund/refund_cubit.dart +++ b/lib/cubit/refund/refund_cubit.dart @@ -42,8 +42,9 @@ class RefundCubit extends Cubit { _logger.info('Listening to Refund events'); _paymentEventSubscription = _breezSdkLiquid.paymentEventStream.listen( (PaymentEvent paymentEvent) { - if (paymentEvent.sdkEvent is SdkEvent_PaymentRefunded || - paymentEvent.sdkEvent is SdkEvent_PaymentRefundPending) { + if (paymentEvent.sdkEvent is SdkEvent_PaymentRefundable || + paymentEvent.sdkEvent is SdkEvent_PaymentRefundPending || + paymentEvent.sdkEvent is SdkEvent_PaymentRefunded) { listRefundables(); } }, diff --git a/lib/cubit/refund/refund_state.dart b/lib/cubit/refund/refund_state.dart index daef7273..4d33b2f9 100644 --- a/lib/cubit/refund/refund_state.dart +++ b/lib/cubit/refund/refund_state.dart @@ -24,4 +24,6 @@ class RefundState { error: error ?? this.error, ); } + + bool get hasRefundables => refundables?.isNotEmpty ?? false; } diff --git a/lib/routes/home/widgets/home_app_bar/widgets/account_required_actions.dart b/lib/routes/home/widgets/home_app_bar/widgets/account_required_actions.dart index 37e54cc7..0fdd6cde 100644 --- a/lib/routes/home/widgets/home_app_bar/widgets/account_required_actions.dart +++ b/lib/routes/home/widgets/home_app_bar/widgets/account_required_actions.dart @@ -11,117 +11,149 @@ final Logger _logger = Logger('AccountRequiredActionsIndicator'); class AccountRequiredActionsIndicator extends StatelessWidget { const AccountRequiredActionsIndicator({super.key}); + @override + Widget build(BuildContext context) { + return Builder( + builder: (BuildContext context) { + final List warnings = []; + + final RefundState refundState = context.watch().state; + if (refundState.hasRefundables) { + _logger.info('Adding refundables warning.'); + warnings.add(const RefundablesWarningAction()); + } + + // final AccountState accountState = context.watch().state; + // if (!accountState.didCompleteInitialSync) { + // _logger.info('Adding sync warning.'); + // warnings.add(const InitialSyncWarningAction()); + // } + + final SecurityState securityState = context.watch().state; + if (securityState.verificationStatus == VerificationStatus.unverified) { + _logger.info('Adding mnemonic verification warning.'); + warnings.add(const VerifyMnemonicWarningAction()); + } + + final BackupState? backupState = context.watch().state; + if (backupState != null && backupState.status == BackupStatus.inProgress) { + _logger.info('Adding backup in progress warning.'); + warnings.add(const BackupInProgressWarningAction()); + } + + if (backupState?.status == BackupStatus.failed) { + _logger.info('Adding backup error warning.'); + warnings.add(const BackupFailedWarningAction()); + } + + if (warnings.isEmpty) { + return const SizedBox.shrink(); + } + + _logger.info('Total # of warnings: ${warnings.length}'); + + return Row( + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.min, + children: warnings, + ); + }, + ); + } +} + +class RefundablesWarningAction extends StatelessWidget { + const RefundablesWarningAction({super.key}); + + @override + Widget build(BuildContext context) { + return WarningAction( + onTap: () { + if (context.mounted) { + Navigator.of(context).pushNamed( + GetRefundPage.routeName, + ); + } + }, + ); + } +} + +class InitialSyncWarningAction extends StatelessWidget { + const InitialSyncWarningAction({super.key}); + @override Widget build(BuildContext context) { final ThemeData themeData = Theme.of(context); + return WarningAction( + onTap: () async {}, + iconWidget: Rotator( + child: Image( + image: const AssetImage('assets/icons/sync.png'), + color: themeData.appBarTheme.actionsIconTheme?.color, + ), + ), + ); + } +} + +class VerifyMnemonicWarningAction extends StatelessWidget { + const VerifyMnemonicWarningAction({super.key}); + + @override + Widget build(BuildContext context) { + return WarningAction( + onTap: () async { + final String? accountMnemonic = await ServiceInjector().credentialsManager.restoreMnemonic(); + if (context.mounted && accountMnemonic != null) { + Navigator.pushNamed( + context, + MnemonicsConfirmationPage.routeName, + arguments: accountMnemonic, + ); + } + }, + ); + } +} + +class BackupInProgressWarningAction extends StatelessWidget { + const BackupInProgressWarningAction({super.key}); - return BlocBuilder( - builder: (BuildContext context, AccountState accountState) { - return _buildContentWithAccountState(themeData, accountState); + @override + Widget build(BuildContext context) { + final ThemeData themeData = Theme.of(context); + return WarningAction( + onTap: () { + showDialog( + useRootNavigator: false, + useSafeArea: false, + context: context, + builder: (_) => const BackupInProgressDialog(), + ); }, + iconWidget: Rotator( + child: Image( + image: const AssetImage('assets/icons/sync.png'), + color: themeData.appBarTheme.actionsIconTheme!.color!, + ), + ), ); } +} + +class BackupFailedWarningAction extends StatelessWidget { + const BackupFailedWarningAction({super.key}); - Widget _buildContentWithAccountState( - ThemeData themeData, - AccountState accountState, - ) { - return BlocBuilder( - builder: (BuildContext context, SecurityState securityState) { - return BlocBuilder( - builder: (BuildContext context, BackupState? backupState) { - _logger.fine( - 'Building with: securityState: $securityState backupState: $backupState accountState: $accountState', - ); - - final List warnings = []; - - /*if (!accountState.didCompleteInitialSync) { - _logger.info('Adding sync warning.'); - warnings.add( - WarningAction( - onTap: () async {}, - iconWidget: Rotator( - child: Image( - image: const AssetImage('assets/icons/sync.png'), - color: themeData.appBarTheme.actionsIconTheme?.color, - ), - ), - ), - ); - }*/ - - if (securityState.verificationStatus == VerificationStatus.unverified) { - _logger.info('Adding mnemonic verification warning.'); - warnings.add( - WarningAction( - onTap: () async { - // TODO(erdemyerebasmaz): Handle the case accountMnemonic is null as restoreMnemonic is now nullable - await ServiceInjector().credentialsManager.restoreMnemonic().then( - (String? accountMnemonic) { - if (context.mounted) { - return Navigator.pushNamed( - context, - MnemonicsConfirmationPage.routeName, - arguments: accountMnemonic, - ); - } - }, - ); - }, - ), - ); - } - - if (backupState != null && backupState.status == BackupStatus.inProgress) { - _logger.info('Adding backup in progress warning.'); - warnings.add( - WarningAction( - onTap: () { - showDialog( - useRootNavigator: false, - useSafeArea: false, - context: context, - builder: (_) => const BackupInProgressDialog(), - ); - }, - iconWidget: Rotator( - child: Image( - image: const AssetImage('assets/icons/sync.png'), - color: themeData.appBarTheme.actionsIconTheme!.color!, - ), - ), - ), - ); - } - - if (backupState?.status == BackupStatus.failed) { - _logger.info('Adding backup error warning.'); - warnings.add( - WarningAction( - onTap: () { - showDialog( - useRootNavigator: false, - useSafeArea: false, - context: context, - builder: (_) => const EnableBackupDialog(), - ); - }, - ), - ); - } - - _logger.info('Total # of warnings: ${warnings.length}'); - if (warnings.isEmpty) { - return const SizedBox.shrink(); - } - - return Row( - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.min, - children: warnings, - ); - }, + @override + Widget build(BuildContext context) { + return WarningAction( + onTap: () { + showDialog( + useRootNavigator: false, + useSafeArea: false, + context: context, + builder: (_) => const EnableBackupDialog(), ); }, ); diff --git a/lib/routes/home/widgets/home_drawer/home_drawer.dart b/lib/routes/home/widgets/home_drawer/home_drawer.dart index a2a8a4c4..ad3da384 100644 --- a/lib/routes/home/widgets/home_drawer/home_drawer.dart +++ b/lib/routes/home/widgets/home_drawer/home_drawer.dart @@ -22,11 +22,9 @@ class HomeDrawer extends StatelessWidget { return BlocBuilder( builder: (BuildContext context, RefundState refundState) { - final bool hasRefundables = refundState.refundables?.isNotEmpty ?? false; - return BreezNavigationDrawer( [ - if (hasRefundables) ...[ + if (refundState.hasRefundables) ...[ DrawerItemConfigGroup( [ DrawerItemConfig( diff --git a/lib/routes/refund/widgets/refund_item_action.dart b/lib/routes/refund/widgets/refund_item_action.dart index 4ab1eda2..7cfc4e0d 100644 --- a/lib/routes/refund/widgets/refund_item_action.dart +++ b/lib/routes/refund/widgets/refund_item_action.dart @@ -29,7 +29,7 @@ class _RefundItemActionState extends State { height: 36.0, width: 145.0, child: SubmitButton( - texts.get_refund_action_broadcasted, + texts.get_refund_action_continue, () { Navigator.of(context).pushNamed( RefundPage.routeName,