| 1 | import 'package:cake_wallet/new-ui/widgets/coins_page/assets_history/asset_details_modal.dart'; |
| 2 | import 'package:cake_wallet/view_model/dashboard/dashboard_view_model.dart'; |
| 3 | import 'package:cw_core/crypto_currency.dart'; |
| 4 | import 'package:flutter/material.dart'; |
| 5 | import 'package:flutter_mobx/flutter_mobx.dart'; |
| 6 | |
| 7 | import 'asset_tile.dart'; |
| 8 | |
| 9 | class AssetsSection extends StatelessWidget { |
| 10 | const AssetsSection({super.key, required this.dashboardViewModel}); |
| 11 | |
| 12 | final DashboardViewModel dashboardViewModel; |
| 13 | |
| 14 | @override |
| 15 | Widget build(BuildContext context) { |
| 16 | return SliverToBoxAdapter( |
| 17 | child: Padding( |
| 18 | padding: const EdgeInsets.only(bottom: 64.0), |
| 19 | child: Observer(builder: (context) { |
| 20 | final hasMweb = dashboardViewModel.hasMweb && dashboardViewModel.mwebEnabled; |
| 21 | return ListView.separated( |
| 22 | shrinkWrap: true, |
| 23 | padding: EdgeInsets.symmetric(vertical: 18), |
| 24 | physics: NeverScrollableScrollPhysics(), |
| 25 | itemCount: |
| 26 | dashboardViewModel.balanceViewModel.formattedBalances.length + (hasMweb ? 1 : 0), |
| 27 | separatorBuilder: (context, index) => Padding( |
| 28 | padding: const EdgeInsets.symmetric(horizontal: 18.0), |
| 29 | child: Container( |
| 30 | color: Theme.of(context).colorScheme.surfaceContainer, |
| 31 | height: 1, |
| 32 | child: Padding( |
| 33 | padding: const EdgeInsets.symmetric(horizontal: 8.0), |
| 34 | child: Container( |
| 35 | color: Theme.of(context).colorScheme.surfaceContainerHigh, |
| 36 | ), |
| 37 | ), |
| 38 | ), |
| 39 | ), |
| 40 | itemBuilder: (context, index) { |
| 41 | return Observer(builder: (context) { |
| 42 | if (hasMweb) { |
| 43 | return AssetTile( |
| 44 | showSwap: dashboardViewModel.isEnabledSwapAction, |
| 45 | balance: dashboardViewModel.balanceViewModel.formattedBalances.first, |
| 46 | showSecondary: index > 0 ? true : false, |
| 47 | wallet: dashboardViewModel.wallet, |
| 48 | chainIconPath: |
| 49 | index > 0 ? dashboardViewModel.wallet.currency.chainIconPath! : "", |
| 50 | trailingText: index > 0 ? "MWEB" : null, |
| 51 | modalMode: index > 0 |
| 52 | ? AssetDetailsModalModes.ltcPrivate |
| 53 | : AssetDetailsModalModes.ltcTransparent, |
| 54 | isFirst: index == 0, |
| 55 | isLast: index != 0, |
| 56 | title: index > 0 ? "Litecoin Private" : null, |
| 57 | ); |
| 58 | } |
| 59 | |
| 60 | final balance = |
| 61 | dashboardViewModel.balanceViewModel.formattedBalances.elementAt(index); |
| 62 | return AssetTile( |
| 63 | showSwap: dashboardViewModel.isEnabledSwapAction, |
| 64 | showBridgeButton: dashboardViewModel.showBridge(balance.asset), |
| 65 | balance: balance, |
| 66 | wallet: dashboardViewModel.wallet, |
| 67 | isFirst: index == 0, |
| 68 | isLast: index == dashboardViewModel.balanceViewModel.formattedBalances.length - 1, |
| 69 | chainIconPath: _getChainIconPath(), |
| 70 | ); |
| 71 | }); |
| 72 | }, |
| 73 | ); |
| 74 | }), |
| 75 | ), |
| 76 | ); |
| 77 | } |
| 78 | |
| 79 | // TODO refactor chainIconPath to get rid of this ugly thing. it's needed because arbitrum's wallet currency isn't arb |
| 80 | String _getChainIconPath() { |
| 81 | try { |
| 82 | return CryptoCurrency.fromString( |
| 83 | dashboardViewModel.wallet.currency.tag ?? dashboardViewModel.wallet.currency.title) |
| 84 | .chainIconPath!; |
| 85 | } catch (e) { |
| 86 | return dashboardViewModel.wallet.currency.chainIconPath ?? ""; |
| 87 | } |
| 88 | } |
| 89 | } |