Skip to content

Commit

Permalink
fix: update refund action text (#324)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
erdemyerebasmaz authored Jan 23, 2025
1 parent 95fc5d8 commit d75cfed
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 109 deletions.
5 changes: 3 additions & 2 deletions lib/cubit/refund/refund_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ class RefundCubit extends Cubit<RefundState> {
_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();
}
},
Expand Down
2 changes: 2 additions & 0 deletions lib/cubit/refund/refund_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ class RefundState {
error: error ?? this.error,
);
}

bool get hasRefundables => refundables?.isNotEmpty ?? false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Widget> warnings = <Widget>[];

final RefundState refundState = context.watch<RefundCubit>().state;
if (refundState.hasRefundables) {
_logger.info('Adding refundables warning.');
warnings.add(const RefundablesWarningAction());
}

// final AccountState accountState = context.watch<AccountCubit>().state;
// if (!accountState.didCompleteInitialSync) {
// _logger.info('Adding sync warning.');
// warnings.add(const InitialSyncWarningAction());
// }

final SecurityState securityState = context.watch<SecurityCubit>().state;
if (securityState.verificationStatus == VerificationStatus.unverified) {
_logger.info('Adding mnemonic verification warning.');
warnings.add(const VerifyMnemonicWarningAction());
}

final BackupState? backupState = context.watch<BackupCubit>().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<AccountCubit, AccountState>(
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<SecurityCubit, SecurityState>(
builder: (BuildContext context, SecurityState securityState) {
return BlocBuilder<BackupCubit, BackupState?>(
builder: (BuildContext context, BackupState? backupState) {
_logger.fine(
'Building with: securityState: $securityState backupState: $backupState accountState: $accountState',
);

final List<Widget> warnings = <Widget>[];

/*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(),
);
},
);
Expand Down
4 changes: 1 addition & 3 deletions lib/routes/home/widgets/home_drawer/home_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ class HomeDrawer extends StatelessWidget {

return BlocBuilder<RefundCubit, RefundState>(
builder: (BuildContext context, RefundState refundState) {
final bool hasRefundables = refundState.refundables?.isNotEmpty ?? false;

return BreezNavigationDrawer(
<DrawerItemConfigGroup>[
if (hasRefundables) ...<DrawerItemConfigGroup>[
if (refundState.hasRefundables) ...<DrawerItemConfigGroup>[
DrawerItemConfigGroup(
<DrawerItemConfig>[
DrawerItemConfig(
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/refund/widgets/refund_item_action.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _RefundItemActionState extends State<RefundItemAction> {
height: 36.0,
width: 145.0,
child: SubmitButton(
texts.get_refund_action_broadcasted,
texts.get_refund_action_continue,
() {
Navigator.of(context).pushNamed(
RefundPage.routeName,
Expand Down

0 comments on commit d75cfed

Please sign in to comment.