| 1 | import 'package:cake_wallet/generated/i18n.dart'; |
| 2 | import 'package:cw_core/currency_for_wallet_type.dart'; |
| 3 | import 'package:flutter/material.dart'; |
| 4 | import 'package:cake_wallet/src/widgets/bottom_sheet/base_bottom_sheet_widget.dart'; |
| 5 | import 'package:cake_wallet/src/widgets/standard_list.dart'; |
| 6 | import 'package:cw_core/wallet_info.dart'; |
| 7 | import 'package:cw_core/wallet_type.dart'; |
| 8 | import 'package:cake_wallet/view_model/wallet_switcher_view_model.dart'; |
| 9 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 10 | |
| 11 | class WalletSwitcherBottomSheet extends BaseBottomSheet { |
| 12 | WalletSwitcherBottomSheet({ |
| 13 | Key? key, |
| 14 | required this.viewModel, |
| 15 | this.filterWalletType, |
| 16 | this.subtitle, |
| 17 | this.onWalletSelected, |
| 18 | }) : super( |
| 19 | titleText: S.current.select_a_wallet, |
| 20 | footerType: FooterType.none, |
| 21 | maxHeight: 900, |
| 22 | ); |
| 23 | |
| 24 | final WalletSwitcherViewModel viewModel; |
| 25 | final WalletType? filterWalletType; |
| 26 | final String? subtitle; |
| 27 | final Function(WalletInfo)? onWalletSelected; |
| 28 | |
| 29 | @override |
| 30 | Widget contentWidget(BuildContext context) { |
| 31 | return _WalletSwitcherContent( |
| 32 | viewModel: viewModel, |
| 33 | filterWalletType: filterWalletType, |
| 34 | subtitle: subtitle, |
| 35 | onWalletSelected: onWalletSelected, |
| 36 | ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | class _WalletSwitcherContent extends StatelessWidget { |
| 41 | const _WalletSwitcherContent({ |
| 42 | required this.viewModel, |
| 43 | this.filterWalletType, |
| 44 | this.subtitle, |
| 45 | this.onWalletSelected, |
| 46 | }); |
| 47 | |
| 48 | final WalletSwitcherViewModel viewModel; |
| 49 | final WalletType? filterWalletType; |
| 50 | final String? subtitle; |
| 51 | final Function(WalletInfo)? onWalletSelected; |
| 52 | |
| 53 | @override |
| 54 | Widget build(BuildContext context) { |
| 55 | return FutureBuilder( |
| 56 | future: viewModel.getWallets(filterWalletType), |
| 57 | builder: (context, snapshot) => Observer( |
| 58 | builder: (_) { |
| 59 | final List<WalletInfo> wallets = (snapshot.data ?? []); |
| 60 | |
| 61 | if (viewModel.isProcessing) { |
| 62 | return Container( |
| 63 | height: 200, |
| 64 | child: Center( |
| 65 | child: CircularProgressIndicator( |
| 66 | color: Theme.of(context).colorScheme.primary, |
| 67 | ), |
| 68 | ), |
| 69 | ); |
| 70 | } |
| 71 | |
| 72 | return Container( |
| 73 | height: 400, |
| 74 | child: Column( |
| 75 | crossAxisAlignment: CrossAxisAlignment.start, |
| 76 | children: [ |
| 77 | Expanded( |
| 78 | child: StandardList( |
| 79 | itemCount: wallets.length, |
| 80 | itemBuilder: (context, index) { |
| 81 | final wallet = wallets[index]; |
| 82 | |
| 83 | return InkWell( |
| 84 | onTap: () { |
| 85 | viewModel.selectWallet(wallet); |
| 86 | Navigator.of(context).pop(); |
| 87 | }, |
| 88 | borderRadius: BorderRadius.circular(12), |
| 89 | child: Container( |
| 90 | margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), |
| 91 | decoration: BoxDecoration( |
| 92 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 93 | borderRadius: BorderRadius.circular(16), |
| 94 | ), |
| 95 | height: 60, |
| 96 | padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12), |
| 97 | child: Row( |
| 98 | children: [ |
| 99 | Image.asset( |
| 100 | getCryptoCurrencyIconForWalletListItem( |
| 101 | wallet.type, |
| 102 | ), |
| 103 | width: 32, |
| 104 | height: 32, |
| 105 | ), |
| 106 | const SizedBox(width: 16), |
| 107 | Text( |
| 108 | wallet.name, |
| 109 | style: Theme.of(context).textTheme.bodyMedium!.copyWith( |
| 110 | fontSize: 18, |
| 111 | fontWeight: FontWeight.w700, |
| 112 | color: Theme.of(context).colorScheme.onSurface, |
| 113 | letterSpacing: 0.0, |
| 114 | ), |
| 115 | maxLines: 1, |
| 116 | overflow: TextOverflow.ellipsis, |
| 117 | ), |
| 118 | ], |
| 119 | ), |
| 120 | ), |
| 121 | ); |
| 122 | }, |
| 123 | ), |
| 124 | ), |
| 125 | ], |
| 126 | ), |
| 127 | ); |
| 128 | }, |
| 129 | ), |
| 130 | ); |
| 131 | } |
| 132 | } |