| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import "package:cake_wallet/new-ui/widgets/coins_page/zcash_migration_modal.dart"; |
| 3 | import 'package:cake_wallet/new-ui/widgets/new_primary_button.dart'; |
| 4 | import 'package:cake_wallet/new-ui/widgets/receive_page/receive_top_bar.dart'; |
| 5 | import 'package:cake_wallet/src/widgets/cake_image_widget.dart'; |
| 6 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 7 | import "package:flutter/cupertino.dart"; |
| 8 | import 'package:flutter/material.dart'; |
| 9 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 10 | import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; |
| 11 | |
| 12 | class UnconfirmedBalanceWidget extends StatelessWidget { |
| 13 | const UnconfirmedBalanceWidget({ |
| 14 | super.key, |
| 15 | required this.dashboardViewModel, |
| 16 | }); |
| 17 | |
| 18 | final DashboardViewModel dashboardViewModel; |
| 19 | |
| 20 | @override |
| 21 | Widget build(BuildContext context) { |
| 22 | final currency = dashboardViewModel.wallet.currency; |
| 23 | return Observer(builder: (_) { |
| 24 | final show = dashboardViewModel.balanceViewModel |
| 25 | .hasAdditionalBalance(dashboardViewModel.wallet.currency); |
| 26 | final isIronwoodMigration = dashboardViewModel.isMigratingToIronwood; |
| 27 | |
| 28 | return AnimatedSize( |
| 29 | duration: const Duration(milliseconds: 300), |
| 30 | curve: Curves.easeOutCubic, |
| 31 | alignment: Alignment.topCenter, |
| 32 | child: show |
| 33 | ? Column( |
| 34 | children: [ |
| 35 | const SizedBox(height: 12, width: double.infinity), |
| 36 | Observer(builder: (context) { |
| 37 | final balance = dashboardViewModel.balanceViewModel.additionalBalance(currency); |
| 38 | |
| 39 | return Container( |
| 40 | width: MediaQuery.of(context).size.width * 0.87, |
| 41 | height: 48, |
| 42 | decoration: BoxDecoration( |
| 43 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 44 | borderRadius: BorderRadius.circular(16.0), |
| 45 | ), |
| 46 | child: Material( |
| 47 | color: Colors.transparent, |
| 48 | child: InkWell( |
| 49 | onTap: () { |
| 50 | final modal = isIronwoodMigration |
| 51 | ? ZcashMigrationModal( |
| 52 | hasContinue: false, balance: "${balance} ${currency.symbol}") |
| 53 | : UnconfirmedBalanceModal( |
| 54 | balance: balance.toStringWithSymbol(), |
| 55 | currencyIconPath: currency.iconPath ?? "", |
| 56 | ); |
| 57 | showMaterialModalBottomSheet( |
| 58 | backgroundColor: Colors.transparent, |
| 59 | context: context, |
| 60 | builder: (context) => modal); |
| 61 | }, |
| 62 | child: Padding( |
| 63 | padding: const EdgeInsets.symmetric(horizontal: 12.0), |
| 64 | child: Row( |
| 65 | mainAxisAlignment: MainAxisAlignment.spaceBetween, |
| 66 | children: [ |
| 67 | Row( |
| 68 | spacing: 12, |
| 69 | children: [ |
| 70 | SizedBox( |
| 71 | height: 20, |
| 72 | width: 20, |
| 73 | child: isIronwoodMigration |
| 74 | ? CupertinoActivityIndicator( |
| 75 | color: Theme.of(context).colorScheme.primary, |
| 76 | ) |
| 77 | : CircularProgressIndicator( |
| 78 | strokeWidth: 2, |
| 79 | backgroundColor: |
| 80 | Theme.of(context).colorScheme.primary.withAlpha(50), |
| 81 | color: Theme.of(context).colorScheme.primary, |
| 82 | value: dashboardViewModel.confirmationProgress, |
| 83 | ), |
| 84 | ), |
| 85 | Row( |
| 86 | spacing: 4, |
| 87 | children: [ |
| 88 | Text( |
| 89 | "$balance ${currency.title}", |
| 90 | style: TextStyle( |
| 91 | color: Theme.of(context).colorScheme.primary, |
| 92 | ), |
| 93 | ), |
| 94 | Text(isIronwoodMigration ? S.of(context).migrating_to_ironwood : S.of(context).confirming), |
| 95 | ], |
| 96 | ) |
| 97 | ], |
| 98 | ), |
| 99 | Icon( |
| 100 | Icons.chevron_right, |
| 101 | color: Theme.of(context).colorScheme.onSurfaceVariant, |
| 102 | ) |
| 103 | ], |
| 104 | ), |
| 105 | ), |
| 106 | ), |
| 107 | ), |
| 108 | ); |
| 109 | }), |
| 110 | ], |
| 111 | ) |
| 112 | : const SizedBox(width: double.infinity), |
| 113 | ); |
| 114 | }); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | class UnconfirmedBalanceModal extends StatelessWidget { |
| 119 | const UnconfirmedBalanceModal({super.key, required this.balance, required this.currencyIconPath}); |
| 120 | |
| 121 | final String balance; |
| 122 | final String currencyIconPath; |
| 123 | |
| 124 | @override |
| 125 | Widget build(BuildContext context) { |
| 126 | return Container( |
| 127 | decoration: BoxDecoration( |
| 128 | color: Theme.of(context).colorScheme.surface, |
| 129 | borderRadius: BorderRadius.vertical(top: Radius.circular(16))), |
| 130 | child: SafeArea( |
| 131 | top: false, |
| 132 | child: Column( |
| 133 | mainAxisSize: MainAxisSize.min, |
| 134 | spacing: 20, |
| 135 | children: [ |
| 136 | ModalTopBar( |
| 137 | title: S.of(context).balance_confirmation, |
| 138 | leadingIcon: Icon(Icons.close), |
| 139 | leadingSemanticLabel: S.of(context).close, |
| 140 | onLeadingPressed: Navigator.of(context).pop), |
| 141 | Padding( |
| 142 | padding: const EdgeInsets.symmetric(horizontal: 16.0), |
| 143 | child: Column( |
| 144 | spacing: 20, |
| 145 | children: [ |
| 146 | Stack( |
| 147 | alignment: Alignment.bottomRight, |
| 148 | children: [ |
| 149 | CakeImageWidget(imageUrl: currencyIconPath, height: 100, width: 100), |
| 150 | Container( |
| 151 | width: 36, |
| 152 | height: 36, |
| 153 | decoration: BoxDecoration( |
| 154 | border: |
| 155 | Border.all(color: Theme.of(context).colorScheme.surface, width: 3), |
| 156 | borderRadius: BorderRadius.circular(12), |
| 157 | color: Colors.white), |
| 158 | child: Icon( |
| 159 | Icons.lock_outlined, |
| 160 | size: 24, |
| 161 | color: Colors.black, |
| 162 | ), |
| 163 | ), |
| 164 | ], |
| 165 | ), |
| 166 | Text( |
| 167 | "${balance} ${S.of(context).balance_confirmation_desc_1}\n\n${S.of(context).balance_confirmation_desc_2}\n\n${S.of(context).balance_confirmation_desc_3}", |
| 168 | style: TextStyle(fontSize: 16), |
| 169 | textAlign: TextAlign.center, |
| 170 | ), |
| 171 | NewPrimaryButton( |
| 172 | onPressed: Navigator.of(context).pop, |
| 173 | text: S.of(context).close, |
| 174 | color: Theme.of(context).colorScheme.primary, |
| 175 | textColor: Theme.of(context).colorScheme.onPrimary), |
| 176 | SizedBox(), |
| 177 | ], |
| 178 | ), |
| 179 | ) |
| 180 | ], |
| 181 | ), |
| 182 | ), |
| 183 | ); |
| 184 | } |
| 185 | } |
| 186 |