| 1 | import 'package:cake_wallet/core/auth_service.dart'; |
| 2 | import 'package:cake_wallet/di.dart'; |
| 3 | import 'package:cake_wallet/generated/i18n.dart'; |
| 4 | import 'package:cake_wallet/new-ui/modal_navigator.dart'; |
| 5 | import 'package:cake_wallet/new-ui/pages/account_customizer.dart'; |
| 6 | import 'package:cake_wallet/new-ui/pages/card_customizer.dart'; |
| 7 | import 'package:cake_wallet/new-ui/pages/settings_page.dart'; |
| 8 | import 'package:cake_wallet/new-ui/viewmodels/card_customizer/card_customizer_bloc.dart'; |
| 9 | import 'package:cake_wallet/new-ui/widgets/coins_page/action_row/coin_action_row.dart'; |
| 10 | import 'package:cake_wallet/new-ui/widgets/coins_page/assets_history/assets_history_section.dart'; |
| 11 | import 'package:cake_wallet/new-ui/widgets/coins_page/cards/cards_view.dart'; |
| 12 | import 'package:cake_wallet/new-ui/widgets/coins_page/mweb_ad.dart'; |
| 13 | import 'package:cake_wallet/new-ui/widgets/coins_page/top_bar_widget/top_bar.dart'; |
| 14 | import 'package:cake_wallet/new-ui/widgets/coins_page/unconfirmed_balance_widget.dart'; |
| 15 | import 'package:cake_wallet/new-ui/widgets/coins_page/wallet_info.dart'; |
| 16 | import "package:cake_wallet/new-ui/widgets/coins_page/zcash_migration_modal.dart"; |
| 17 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 18 | import 'package:cake_wallet/view_model/dashboard/nft_view_model.dart'; |
| 19 | import 'package:cake_wallet/view_model/monero_account_list/monero_account_edit_or_create_view_model.dart'; |
| 20 | import 'package:cake_wallet/view_model/monero_account_list/monero_account_list_view_model.dart'; |
| 21 | import "package:cw_core/amount/money.dart"; |
| 22 | import "package:cw_core/crypto_currency.dart"; |
| 23 | import "package:cw_core/transaction_direction.dart"; |
| 24 | import 'package:flutter/cupertino.dart'; |
| 25 | import 'package:flutter/material.dart'; |
| 26 | import 'package:flutter_bloc/flutter_bloc.dart'; |
| 27 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 28 | import 'package:mobx/mobx.dart'; |
| 29 | import 'package:modal_bottom_sheet/modal_bottom_sheet.dart'; |
| 30 | |
| 31 | class NewHomePage extends StatefulWidget { |
| 32 | NewHomePage({super.key, required this.dashboardViewModel, required this.nftViewModel}); |
| 33 | |
| 34 | final DashboardViewModel dashboardViewModel; |
| 35 | final NFTViewModel nftViewModel; |
| 36 | |
| 37 | @override |
| 38 | State<NewHomePage> createState() => _NewHomePageState(); |
| 39 | } |
| 40 | |
| 41 | class _NewHomePageState extends State<NewHomePage> { |
| 42 | MoneroAccountListViewModel? accountListViewModel; |
| 43 | bool _lightningMode = false; |
| 44 | |
| 45 | @override |
| 46 | void initState() { |
| 47 | super.initState(); |
| 48 | _setAccountViewModel(); |
| 49 | reaction((_) => widget.dashboardViewModel.wallet, (_) { |
| 50 | _setAccountViewModel(); |
| 51 | setState(() { |
| 52 | _lightningMode = false; |
| 53 | }); |
| 54 | }); |
| 55 | |
| 56 | reaction((_) => widget.dashboardViewModel.isMigratingToIronwood, (val) { |
| 57 | if (val && !widget.dashboardViewModel.settingsStore.zcashMigrationModalViewed) { |
| 58 | if(!context.mounted) { |
| 59 | return; |
| 60 | } |
| 61 | widget.dashboardViewModel.settingsStore.zcashMigrationModalViewed = true; |
| 62 | showMaterialModalBottomSheet( |
| 63 | context: context, |
| 64 | backgroundColor: Colors.transparent, |
| 65 | builder: (context) => ZcashMigrationModal( |
| 66 | hasContinue: true, |
| 67 | balance: widget.dashboardViewModel.wallet.balance.values.first.unavailable |
| 68 | .toStringWithSymbol(), |
| 69 | ), |
| 70 | ); |
| 71 | } |
| 72 | }); |
| 73 | } |
| 74 | |
| 75 | void _setAccountViewModel() { |
| 76 | accountListViewModel = widget.dashboardViewModel.balanceViewModel.hasAccounts |
| 77 | ? getIt.get<MoneroAccountListViewModel>() |
| 78 | : null; |
| 79 | } |
| 80 | |
| 81 | @override |
| 82 | Widget build(BuildContext context) { |
| 83 | return Container( |
| 84 | height: MediaQuery.of(context).size.height, |
| 85 | decoration: BoxDecoration( |
| 86 | gradient: LinearGradient( |
| 87 | colors: [ |
| 88 | Theme.of(context).colorScheme.surface, |
| 89 | Theme.of(context).colorScheme.surfaceDim, |
| 90 | ], |
| 91 | begin: Alignment.topCenter, |
| 92 | end: Alignment.bottomCenter, |
| 93 | ), |
| 94 | ), |
| 95 | child: Stack( |
| 96 | children: [ |
| 97 | CustomScrollView( |
| 98 | physics: BouncingScrollPhysics(parent: AlwaysScrollableScrollPhysics()), |
| 99 | slivers: [ |
| 100 | SliverPadding( |
| 101 | padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top), |
| 102 | sliver: CupertinoSliverRefreshControl( |
| 103 | refreshTriggerPullDistance: 160, |
| 104 | refreshIndicatorExtent: 90, |
| 105 | onRefresh: () => widget.dashboardViewModel.refreshDashboard(), |
| 106 | ), |
| 107 | ), |
| 108 | SliverToBoxAdapter( |
| 109 | child: Column( |
| 110 | mainAxisSize: MainAxisSize.max, |
| 111 | mainAxisAlignment: MainAxisAlignment.start, |
| 112 | spacing: 24.0, |
| 113 | children: [ |
| 114 | TopBar( |
| 115 | dashboardViewModel: widget.dashboardViewModel, |
| 116 | lightningMode: _lightningMode, |
| 117 | onLightningSwitchPress: () { |
| 118 | setState(() { |
| 119 | _lightningMode = !_lightningMode; |
| 120 | }); |
| 121 | }, |
| 122 | onSettingsButtonPress: () { |
| 123 | CupertinoScaffold.showCupertinoModalBottomSheet( |
| 124 | context: context, |
| 125 | barrierColor: Colors.black.withAlpha(85), |
| 126 | builder: (context) => FractionallySizedBox( |
| 127 | child: Material( |
| 128 | child: NewSettingsPage( |
| 129 | dashboardViewModel: widget.dashboardViewModel, |
| 130 | authService: getIt.get<AuthService>(), |
| 131 | ))), |
| 132 | ); |
| 133 | }, |
| 134 | ), |
| 135 | Observer( |
| 136 | builder: (_) => WalletInfoBar( |
| 137 | lightningMode: _lightningMode, |
| 138 | hardwareWalletType: widget.dashboardViewModel.wallet.hardwareWalletType, |
| 139 | name: widget.dashboardViewModel.wallet.name, |
| 140 | hasCustomize: accountListViewModel != null, |
| 141 | onCustomizeButtonTap: openAccountCustomizer), |
| 142 | ), |
| 143 | Column( |
| 144 | children: [ |
| 145 | Observer( |
| 146 | builder: (_) => CardsView( |
| 147 | key: ValueKey(widget.dashboardViewModel.wallet.name), |
| 148 | onCustomizeTapped: openCardCustomizer, |
| 149 | dashboardViewModel: widget.dashboardViewModel, |
| 150 | accountListViewModel: accountListViewModel, |
| 151 | onCompactModeBackgroundCardsTapped: openAccountCustomizer, |
| 152 | lightningMode: _lightningMode, |
| 153 | ), |
| 154 | ), |
| 155 | Observer(builder: (_) { |
| 156 | return AnimatedSize( |
| 157 | duration: Duration(milliseconds: 150), |
| 158 | curve: Curves.easeInOutCubic, |
| 159 | child: (widget.dashboardViewModel.shouldShowBalanceHiddenMessage) |
| 160 | ? Column( |
| 161 | children: [ |
| 162 | SizedBox( |
| 163 | height: 12, |
| 164 | width: double.infinity, |
| 165 | ), |
| 166 | Text( |
| 167 | S.of(context).long_press_show_balance, |
| 168 | style: TextStyle( |
| 169 | color: |
| 170 | Theme.of(context).colorScheme.onSurfaceVariant), |
| 171 | ) |
| 172 | ], |
| 173 | ) |
| 174 | : SizedBox(width: double.infinity), |
| 175 | ); |
| 176 | }), |
| 177 | UnconfirmedBalanceWidget( |
| 178 | dashboardViewModel: widget.dashboardViewModel, |
| 179 | ), |
| 180 | ], |
| 181 | ), |
| 182 | Observer( |
| 183 | builder: (_) { |
| 184 | return Column( |
| 185 | children: [ |
| 186 | CoinActionRow( |
| 187 | lightningMode: _lightningMode, |
| 188 | showSwap: widget.dashboardViewModel.isEnabledSwapAction, |
| 189 | walletType: widget.dashboardViewModel.wallet.type, |
| 190 | ), |
| 191 | MwebAd( |
| 192 | dashboardViewModel: widget.dashboardViewModel, |
| 193 | ), |
| 194 | ], |
| 195 | ); |
| 196 | }, |
| 197 | ), |
| 198 | ], |
| 199 | ), |
| 200 | ), |
| 201 | Observer( |
| 202 | builder: (_) => AssetsHistorySection( |
| 203 | nftViewModel: widget.nftViewModel, |
| 204 | dashboardViewModel: widget.dashboardViewModel, |
| 205 | ), |
| 206 | ), |
| 207 | SliverToBoxAdapter( |
| 208 | child: SizedBox(height: 80.0), |
| 209 | ) |
| 210 | ]), |
| 211 | Container( |
| 212 | height: (MediaQuery.of(context).padding.top), |
| 213 | decoration: BoxDecoration( |
| 214 | gradient: LinearGradient( |
| 215 | begin: Alignment.bottomCenter, |
| 216 | end: Alignment.topCenter, |
| 217 | colors: <Color>[ |
| 218 | Theme.of(context).colorScheme.surface.withAlpha(5), |
| 219 | Theme.of(context).colorScheme.surface.withAlpha(25), |
| 220 | Theme.of(context).colorScheme.surface.withAlpha(50), |
| 221 | Theme.of(context).colorScheme.surface.withAlpha(100), |
| 222 | Theme.of(context).colorScheme.surface.withAlpha(150), |
| 223 | Theme.of(context).colorScheme.surface.withAlpha(175), |
| 224 | Theme.of(context).colorScheme.surface.withAlpha(200), |
| 225 | ], |
| 226 | ), |
| 227 | ), |
| 228 | ), |
| 229 | ], |
| 230 | ), |
| 231 | ); |
| 232 | } |
| 233 | |
| 234 | void openAccountCustomizer() async { |
| 235 | await CupertinoScaffold.showCupertinoModalBottomSheet( |
| 236 | barrierColor: Colors.black.withAlpha(60), |
| 237 | context: context, |
| 238 | builder: (context) { |
| 239 | return ModalNavigator( |
| 240 | parentContext: context, |
| 241 | heightMode: ModalHeightModes.fullScreen, |
| 242 | rootPage: Material( |
| 243 | child: AccountCustomizer( |
| 244 | accountListViewModel: accountListViewModel!, |
| 245 | accountEditOrCreateViewModel: getIt.get<MoneroAccountEditOrCreateViewModel>(), |
| 246 | dashboardViewModel: widget.dashboardViewModel, |
| 247 | )), |
| 248 | ); |
| 249 | }, |
| 250 | ); |
| 251 | widget.dashboardViewModel.loadCardDesigns(); |
| 252 | } |
| 253 | |
| 254 | void openCardCustomizer() async { |
| 255 | final bloc = getIt.get<CardCustomizerBloc>( |
| 256 | param1: _lightningMode, |
| 257 | param2: widget.dashboardViewModel.settingsStore.displayAmountsInSatoshi); |
| 258 | await CupertinoScaffold.showCupertinoModalBottomSheet( |
| 259 | barrierColor: Colors.black.withAlpha(60), |
| 260 | context: context, |
| 261 | builder: (context) { |
| 262 | return ModalNavigator( |
| 263 | parentContext: context, |
| 264 | heightMode: ModalHeightModes.fullScreen, |
| 265 | rootPage: BlocProvider( |
| 266 | create: (context) => bloc, |
| 267 | child: Material( |
| 268 | child: CardCustomizer( |
| 269 | cryptoTitle: widget.dashboardViewModel.wallet.currency.fullName ?? |
| 270 | widget.dashboardViewModel.wallet.currency.name, |
| 271 | cryptoName: widget.dashboardViewModel.wallet.currency.name, |
| 272 | )), |
| 273 | )); |
| 274 | }, |
| 275 | ); |
| 276 | bloc.add(DesignSaved()); |
| 277 | await bloc.stream.firstWhere((s) => s is CardCustomizerSaved); |
| 278 | widget.dashboardViewModel.loadCardDesigns(); |
| 279 | } |
| 280 | } |