From 301f4b5cf5b9bfd4b037aae18367e0894f4b8df5 Mon Sep 17 00:00:00 2001 From: ryleedavis Date: Tue, 2 May 2023 15:05:04 -0600 Subject: [PATCH] WIP: rename coin image provider + add coin icon provider --- .../sub_widgets/coin_select_item.dart | 3 +- .../sub_widgets/coin_image.dart | 2 +- .../subviews/coin_select_sheet.dart | 2 +- .../new_contact_address_entry_form.dart | 3 +- .../sub_widgets/restoring_wallet_card.dart | 5 ++- .../my_stack_view/wallet_summary_table.dart | 11 +++--- .../wallet_view/desktop_wallet_view.dart | 5 +-- lib/themes/coin_icon_provider.dart | 36 +++++++++++++++++++ ...provider.dart => coin_image_provider.dart} | 0 .../wallet_info_row_coin_icon.dart | 9 ++--- 10 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 lib/themes/coin_icon_provider.dart rename lib/themes/{theme_coin_provider.dart => coin_image_provider.dart} (100%) diff --git a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/coin_select_item.dart b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/coin_select_item.dart index 4f2a84a9a..0d5613437 100644 --- a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/coin_select_item.dart +++ b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/coin_select_item.dart @@ -8,6 +8,7 @@ import 'package:stackwallet/models/isar/exchange_cache/currency.dart'; import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart'; import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; @@ -76,7 +77,7 @@ class CoinSelectItem extends ConsumerWidget { height: 26, ) : SvgPicture.asset( - Assets.svg.iconFor(coin: entity.coin), + ref.watch(coinIconProvider(entity.coin)), width: 26, height: 26, ), diff --git a/lib/pages/add_wallet_views/create_or_restore_wallet_view/sub_widgets/coin_image.dart b/lib/pages/add_wallet_views/create_or_restore_wallet_view/sub_widgets/coin_image.dart index f99036c96..9d7cff5a3 100644 --- a/lib/pages/add_wallet_views/create_or_restore_wallet_view/sub_widgets/coin_image.dart +++ b/lib/pages/add_wallet_views/create_or_restore_wallet_view/sub_widgets/coin_image.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; -import 'package:stackwallet/themes/theme_coin_provider.dart'; +import 'package:stackwallet/themes/coin_image_provider.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/theme/color_theme.dart'; diff --git a/lib/pages/address_book_views/subviews/coin_select_sheet.dart b/lib/pages/address_book_views/subviews/coin_select_sheet.dart index 6167406e0..0cbe34d0b 100644 --- a/lib/pages/address_book_views/subviews/coin_select_sheet.dart +++ b/lib/pages/address_book_views/subviews/coin_select_sheet.dart @@ -2,7 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/providers/global/prefs_provider.dart'; -import 'package:stackwallet/themes/theme_coin_provider.dart'; +import 'package:stackwallet/themes/coin_image_provider.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; diff --git a/lib/pages/address_book_views/subviews/new_contact_address_entry_form.dart b/lib/pages/address_book_views/subviews/new_contact_address_entry_form.dart index 25cff073b..91cb6fe67 100644 --- a/lib/pages/address_book_views/subviews/new_contact_address_entry_form.dart +++ b/lib/pages/address_book_views/subviews/new_contact_address_entry_form.dart @@ -7,6 +7,7 @@ import 'package:stackwallet/pages/address_book_views/subviews/coin_select_sheet. import 'package:stackwallet/providers/providers.dart'; // import 'package:stackwallet/providers/global/should_show_lockscreen_on_resume_state_provider.dart'; import 'package:stackwallet/providers/ui/address_book_providers/address_entry_data_provider.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/address_utils.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/barcode_scanner_interface.dart'; @@ -141,7 +142,7 @@ class _NewContactAddressEntryFormState child: Row( children: [ SvgPicture.asset( - Assets.svg.iconFor(coin: coin), + ref.watch(coinIconProvider(coin)), height: 24, width: 24, ), diff --git a/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_widgets/restoring_wallet_card.dart b/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_widgets/restoring_wallet_card.dart index fc1b92d6c..ae8ca2f5e 100644 --- a/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_widgets/restoring_wallet_card.dart +++ b/lib/pages/settings_views/global_settings_view/stack_backup_views/sub_widgets/restoring_wallet_card.dart @@ -6,6 +6,7 @@ import 'package:stackwallet/pages/settings_views/global_settings_view/stack_back import 'package:stackwallet/pages/settings_views/global_settings_view/stack_backup_views/sub_widgets/restoring_item_card.dart'; import 'package:stackwallet/providers/stack_restore/stack_restoring_ui_state_provider.dart'; import 'package:stackwallet/route_generator.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/stack_restoring_status.dart'; @@ -81,9 +82,7 @@ class _RestoringWalletCardState extends ConsumerState { .colorForCoin(coin), child: Center( child: SvgPicture.asset( - Assets.svg.iconFor( - coin: coin, - ), + ref.watch(coinIconProvider(coin)), height: 20, width: 20, ), diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart index 70189b383..9d5b9021e 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_summary_table.dart @@ -3,8 +3,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:stackwallet/pages/wallets_view/wallets_overview.dart'; import 'package:stackwallet/providers/providers.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/amount/amount.dart'; -import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; @@ -58,7 +58,7 @@ class _WalletTableState extends ConsumerState { } } -class DesktopWalletSummaryRow extends StatefulWidget { +class DesktopWalletSummaryRow extends ConsumerStatefulWidget { const DesktopWalletSummaryRow({ Key? key, required this.coin, @@ -69,11 +69,12 @@ class DesktopWalletSummaryRow extends StatefulWidget { final int walletCount; @override - State createState() => + ConsumerState createState() => _DesktopWalletSummaryRowState(); } -class _DesktopWalletSummaryRowState extends State { +class _DesktopWalletSummaryRowState + extends ConsumerState { bool _hovering = false; void _onPressed() { @@ -141,7 +142,7 @@ class _DesktopWalletSummaryRowState extends State { child: Row( children: [ SvgPicture.asset( - Assets.svg.iconFor(coin: widget.coin), + ref.watch(coinIconProvider(widget.coin)), width: 28, height: 28, ), diff --git a/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart b/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart index 512774df8..ca186d4c8 100644 --- a/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart +++ b/lib/pages_desktop_specific/my_stack_view/wallet_view/desktop_wallet_view.dart @@ -19,6 +19,7 @@ import 'package:stackwallet/providers/providers.dart'; import 'package:stackwallet/providers/ui/transaction_filter_provider.dart'; import 'package:stackwallet/services/event_bus/events/global/wallet_sync_status_changed_event.dart'; import 'package:stackwallet/services/event_bus/global_event_bus.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/backup_frequency_type.dart'; @@ -184,7 +185,7 @@ class _DesktopWalletViewState extends ConsumerState { width: 15, ), SvgPicture.asset( - Assets.svg.iconFor(coin: coin), + ref.watch(coinIconProvider(coin)), width: 32, height: 32, ), @@ -240,7 +241,7 @@ class _DesktopWalletViewState extends ConsumerState { child: Row( children: [ SvgPicture.asset( - Assets.svg.iconFor(coin: coin), + ref.watch(coinIconProvider(coin)), width: 40, height: 40, ), diff --git a/lib/themes/coin_icon_provider.dart b/lib/themes/coin_icon_provider.dart new file mode 100644 index 000000000..75b8a3e11 --- /dev/null +++ b/lib/themes/coin_icon_provider.dart @@ -0,0 +1,36 @@ +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:stackwallet/themes/theme_providers.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; + +final coinIconProvider = Provider.family((ref, coin) { + final assets = ref.watch(themeProvider).assets; + switch (coin) { + case Coin.bitcoin: + case Coin.bitcoinTestNet: + return assets.bitcoin; + case Coin.litecoin: + case Coin.litecoinTestNet: + return assets.litecoin; + case Coin.bitcoincash: + case Coin.bitcoincashTestnet: + return assets.bitcoincash; + case Coin.dogecoin: + case Coin.dogecoinTestNet: + return assets.dogecoin; + case Coin.epicCash: + return assets.epicCash; + case Coin.firo: + case Coin.firoTestNet: + return assets.firo; + case Coin.monero: + return assets.monero; + case Coin.wownero: + return assets.wownero; + case Coin.namecoin: + return assets.namecoin; + case Coin.particl: + return assets.particl; + case Coin.ethereum: + return assets.ethereum; + } +}); diff --git a/lib/themes/theme_coin_provider.dart b/lib/themes/coin_image_provider.dart similarity index 100% rename from lib/themes/theme_coin_provider.dart rename to lib/themes/coin_image_provider.dart diff --git a/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart b/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart index afe47e250..e2ff61dba 100644 --- a/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart +++ b/lib/widgets/wallet_info_row/sub_widgets/wallet_info_row_coin_icon.dart @@ -1,15 +1,16 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:isar/isar.dart'; import 'package:stackwallet/models/isar/exchange_cache/currency.dart'; import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart'; import 'package:stackwallet/services/exchange/exchange_data_loading_service.dart'; -import 'package:stackwallet/utilities/assets.dart'; +import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/theme/stack_colors.dart'; -class WalletInfoCoinIcon extends StatelessWidget { +class WalletInfoCoinIcon extends ConsumerWidget { const WalletInfoCoinIcon({ Key? key, required this.coin, @@ -22,7 +23,7 @@ class WalletInfoCoinIcon extends StatelessWidget { final double size; @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { Currency? currency; if (contractAddress != null) { currency = ExchangeDataLoadingService.instance.isar.currencies @@ -59,7 +60,7 @@ class WalletInfoCoinIcon extends StatelessWidget { height: 20, ) : SvgPicture.asset( - Assets.svg.iconFor(coin: coin), + ref.watch(coinIconProvider(coin)), width: 20, height: 20, ),