Skip to content

Commit

Permalink
home - warning buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
mocodesmo committed Mar 27, 2024
1 parent 7d1856c commit 8e6cace
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 33 deletions.
40 changes: 39 additions & 1 deletion lib/_ui/warning.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:bb_mobile/_ui/components/text.dart';
import 'package:bb_mobile/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:gap/gap.dart';

Expand Down Expand Up @@ -39,3 +38,42 @@ class WarningContainer extends StatelessWidget {
);
}
}

class WarningBanner extends StatelessWidget {
const WarningBanner({super.key, required this.onTap, required this.info});

final Function() onTap;
final String info;

@override
Widget build(BuildContext context) {
return Row(
children: [
const Spacer(),
InkWell(
borderRadius: BorderRadius.circular(10),
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: context.colour.error.withOpacity(0.2),
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
FaIcon(
FontAwesomeIcons.triangleExclamation,
color: context.colour.error,
size: 16,
),
const Gap(8),
BBText.errorSmall(info),
],
),
),
),
const Spacer(),
],
);
}
}
19 changes: 19 additions & 0 deletions lib/home/bloc/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,25 @@ class HomeState with _$HomeState {
return null;
}

Set<({String info, WalletBloc walletBloc})> homeWarnings(BBNetwork network) {
bool instantBalWarning(WalletBloc wb) {
if (wb.state.wallet?.type != BBWalletType.instant) return false;
return wb.state.balanceSats() > 100000000;
}

bool backupWarning(WalletBloc wb) => !wb.state.wallet!.backupTested;

final warnings = <({String info, WalletBloc walletBloc})>{};
for (final walletBloc in walletBlocsFromNetwork(network)) {
if (instantBalWarning(walletBloc))
warnings.add((info: 'Instant wallet balance is high', walletBloc: walletBloc));
if (backupWarning(walletBloc))
warnings.add((info: 'Back up your wallet! Tap to test backup.', walletBloc: walletBloc));
}

return warnings;
}

// int? selectedWalletIdx(BBNetwork network) {
// final wallet = selectedWalletCubit?.state.wallet;
// if (wallet == null) return null;
Expand Down
22 changes: 22 additions & 0 deletions lib/home/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:bb_mobile/_pkg/wallet/utxo.dart';
import 'package:bb_mobile/_ui/components/button.dart';
import 'package:bb_mobile/_ui/components/indicators.dart';
import 'package:bb_mobile/_ui/components/text.dart';
import 'package:bb_mobile/_ui/warning.dart';
import 'package:bb_mobile/currency/bloc/currency_cubit.dart';
import 'package:bb_mobile/home/bloc/home_cubit.dart';
import 'package:bb_mobile/home/bloc/state.dart';
Expand Down Expand Up @@ -900,3 +901,24 @@ class HomeNoWallets extends StatelessWidget {
// );
}
}

class HomeWarnings extends StatelessWidget {
const HomeWarnings({super.key});

@override
Widget build(BuildContext context) {
final network = context.select((NetworkCubit x) => x.state.getBBNetwork());
final warnings = context.select((HomeCubit x) => x.state.homeWarnings(network));
return Column(
children: [
for (final w in warnings)
WarningBanner(
onTap: () {
final bloc = w.walletBloc;
},
info: w.info,
),
],
);
}
}
41 changes: 9 additions & 32 deletions lib/wallet/wallet_txs.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import 'package:bb_mobile/_model/transaction.dart';
import 'package:bb_mobile/_ui/components/indicators.dart';
import 'package:bb_mobile/_ui/components/text.dart';
import 'package:bb_mobile/_ui/warning.dart';
import 'package:bb_mobile/currency/bloc/currency_cubit.dart';
import 'package:bb_mobile/styles.dart';
import 'package:bb_mobile/wallet/bloc/wallet_bloc.dart';
import 'package:extra_alignments/extra_alignments.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -177,37 +177,14 @@ class BackupAlertBanner extends StatelessWidget {

if (backupTested) return const SizedBox.shrink();

return Row(
children: [
const Spacer(),
InkWell(
borderRadius: BorderRadius.circular(10),
onTap: () {
final walletBloc = context.read<WalletBloc>();

context.push('/wallet-settings/open-backup', extra: walletBloc);
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: context.colour.error.withOpacity(0.2),
borderRadius: BorderRadius.circular(10),
),
child: Row(
children: [
FaIcon(
FontAwesomeIcons.triangleExclamation,
color: context.colour.error,
size: 16,
),
const Gap(8),
const BBText.errorSmall('Back up your wallet! Tap to test backup.'),
],
),
),
),
const Spacer(),
],
return WarningBanner(
onTap: () {
context.push(
'/wallet-settings/open-backup',
extra: context.read<WalletBloc>(),
);
},
info: 'Back up your wallet! Tap to test backup.',
);
}
}

0 comments on commit 8e6cace

Please sign in to comment.