diff --git a/lib/app_config.dart b/lib/app_config.dart index 846af4811..2b83a7868 100644 --- a/lib/app_config.dart +++ b/lib/app_config.dart @@ -1,3 +1,5 @@ +import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; + abstract class AppConfig { static const appName = prefix + _separator + suffix; @@ -6,4 +8,27 @@ abstract class AppConfig { static const _separator = " "; static const suffix = "Wallet"; + + // comment out coins to disable them + static const supportedCoins = [ + Bitcoin, + BitcoinFrost, + Litecoin, + Bitcoincash, + Dogecoin, + Epiccash, + Ecash, + Ethereum, + Firo, + Monero, + Particl, + Peercoin, + Solana, + Stellar, + Tezos, + Wownero, + Namecoin, + Nano, + Banano, + ]; } diff --git a/lib/models/isar/models/contact_entry.dart b/lib/models/isar/models/contact_entry.dart index 16925ce24..67eac36df 100644 --- a/lib/models/isar/models/contact_entry.dart +++ b/lib/models/isar/models/contact_entry.dart @@ -37,7 +37,7 @@ class ContactEntry { @ignore List get addressesSorted { final List sorted = []; - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { final slice = addresses.where((e) => e.coin == coin).toList(); if (slice.isNotEmpty) { slice.sort( diff --git a/lib/models/isar/stack_theme.dart b/lib/models/isar/stack_theme.dart index 3ff54c3b7..b891c288e 100644 --- a/lib/models/isar/stack_theme.dart +++ b/lib/models/isar/stack_theme.dart @@ -1548,7 +1548,8 @@ class StackTheme { json["colors"]["box_shadows"]["home_view_button_bar"] == null ? null : jsonEncode( - json["colors"]["box_shadows"]["home_view_button_bar"] as Map) + json["colors"]["box_shadows"]["home_view_button_bar"] as Map, + ) ..coinColorsJsonString = jsonEncode(json["colors"]['coin'] as Map) ..overlayInt = parseColor(json["colors"]["overlay"] as String) ..accentColorBlueInt = @@ -1587,7 +1588,8 @@ class StackTheme { ..buttonBackBorderSecondaryInt = parseColor(json["colors"]["button_back_border_secondary"] as String) ..buttonBackBorderSecondaryDisabledInt = parseColor( - json["colors"]["button_back_border_secondary_disabled"] as String) + json["colors"]["button_back_border_secondary_disabled"] as String, + ) ..numberBackDefaultInt = parseColor(json["colors"]["number_back_default"] as String) ..numpadBackDefaultInt = @@ -1621,7 +1623,8 @@ class StackTheme { ..buttonTextBorderlessInt = parseColor(json["colors"]["button_text_borderless"] as String) ..buttonTextBorderlessDisabledInt = parseColor( - json["colors"]["button_text_borderless_disabled"] as String) + json["colors"]["button_text_borderless_disabled"] as String, + ) ..numberTextDefaultInt = parseColor(json["colors"]["number_text_default"] as String) ..numpadTextDefaultInt = @@ -1629,9 +1632,11 @@ class StackTheme { ..bottomNavTextInt = parseColor(json["colors"]["bottom_nav_text"] as String) ..customTextButtonEnabledTextInt = parseColor( - json["colors"]["custom_text_button_enabled_text"] as String) + json["colors"]["custom_text_button_enabled_text"] as String, + ) ..customTextButtonDisabledTextInt = parseColor( - json["colors"]["custom_text_button_disabled_text"] as String) + json["colors"]["custom_text_button_disabled_text"] as String, + ) ..switchBGOnInt = parseColor(json["colors"]["switch_bg_on"] as String) ..switchBGOffInt = parseColor(json["colors"]["switch_bg_off"] as String) ..switchBGDisabledInt = @@ -1651,7 +1656,8 @@ class StackTheme { ..stepIndicatorBGLinesInt = parseColor(json["colors"]["step_indicator_bg_lines"] as String) ..stepIndicatorBGLinesInactiveInt = parseColor( - json["colors"]["step_indicator_bg_lines_inactive"] as String) + json["colors"]["step_indicator_bg_lines_inactive"] as String, + ) ..stepIndicatorIconTextInt = parseColor(json["colors"]["step_indicator_icon_text"] as String) ..stepIndicatorIconNumberInt = @@ -1687,7 +1693,8 @@ class StackTheme { ..bottomNavIconIconInt = parseColor(json["colors"]["bottom_nav_icon_icon"] as String) ..bottomNavIconIconHighlightedInt = parseColor( - json["colors"]["bottom_nav_icon_icon_highlighted"] as String) + json["colors"]["bottom_nav_icon_icon_highlighted"] as String, + ) ..topNavIconPrimaryInt = parseColor(json["colors"]["top_nav_icon_primary"] as String) ..topNavIconGreenInt = @@ -1717,13 +1724,17 @@ class StackTheme { ..textFieldSuccessBorderInt = parseColor(json["colors"]["text_field_success_border"] as String) ..textFieldActiveSearchIconLeftInt = parseColor( - json["colors"]["text_field_active_search_icon_left"] as String) + json["colors"]["text_field_active_search_icon_left"] as String, + ) ..textFieldDefaultSearchIconLeftInt = parseColor( - json["colors"]["text_field_default_search_icon_left"] as String) + json["colors"]["text_field_default_search_icon_left"] as String, + ) ..textFieldErrorSearchIconLeftInt = parseColor( - json["colors"]["text_field_error_search_icon_left"] as String) + json["colors"]["text_field_error_search_icon_left"] as String, + ) ..textFieldSuccessSearchIconLeftInt = parseColor( - json["colors"]["text_field_success_search_icon_left"] as String) + json["colors"]["text_field_success_search_icon_left"] as String, + ) ..textFieldActiveTextInt = parseColor(json["colors"]["text_field_active_text"] as String) ..textFieldDefaultTextInt = @@ -1739,23 +1750,31 @@ class StackTheme { ..textFieldSuccessLabelInt = parseColor(json["colors"]["text_field_success_label"] as String) ..textFieldActiveSearchIconRightInt = parseColor( - json["colors"]["text_field_active_search_icon_right"] as String) + json["colors"]["text_field_active_search_icon_right"] as String, + ) ..textFieldDefaultSearchIconRightInt = parseColor( - json["colors"]["text_field_default_search_icon_right"] as String) + json["colors"]["text_field_default_search_icon_right"] as String, + ) ..textFieldErrorSearchIconRightInt = parseColor( - json["colors"]["text_field_error_search_icon_right"] as String) + json["colors"]["text_field_error_search_icon_right"] as String, + ) ..textFieldSuccessSearchIconRightInt = parseColor( - json["colors"]["text_field_success_search_icon_right"] as String) + json["colors"]["text_field_success_search_icon_right"] as String, + ) ..settingsItem2ActiveBGInt = parseColor( - json["colors"]["settings_item_level_two_active_bg"] as String) + json["colors"]["settings_item_level_two_active_bg"] as String, + ) ..settingsItem2ActiveTextInt = parseColor( - json["colors"]["settings_item_level_two_active_text"] as String) + json["colors"]["settings_item_level_two_active_text"] as String, + ) ..settingsItem2ActiveSubInt = parseColor( - json["colors"]["settings_item_level_two_active_sub"] as String) + json["colors"]["settings_item_level_two_active_sub"] as String, + ) ..radioButtonIconBorderInt = parseColor(json["colors"]["radio_button_icon_border"] as String) ..radioButtonIconBorderDisabledInt = parseColor( - json["colors"]["radio_button_icon_border_disabled"] as String) + json["colors"]["radio_button_icon_border_disabled"] as String, + ) ..radioButtonBorderEnabledInt = parseColor(json["colors"]["radio_button_border_enabled"] as String) ..radioButtonBorderDisabledInt = @@ -1809,9 +1828,11 @@ class StackTheme { ..rateTypeToggleColorOffInt = parseColor(json["colors"]["rate_type_toggle_color_off"] as String) ..rateTypeToggleDesktopColorOnInt = parseColor( - json["colors"]["rate_type_toggle_desktop_color_on"] as String) + json["colors"]["rate_type_toggle_desktop_color_on"] as String, + ) ..rateTypeToggleDesktopColorOffInt = parseColor( - json["colors"]["rate_type_toggle_desktop_color_off"] as String) + json["colors"]["rate_type_toggle_desktop_color_off"] as String, + ) ..ethTagTextInt = parseColor(json["colors"]["eth_tag_text"] as String) ..ethTagBGInt = parseColor(json["colors"]["eth_tag_bg"] as String) ..ethWalletTagTextInt = @@ -1857,8 +1878,7 @@ class StackTheme { final Map result = {}; - for (final mainNetId - in Coins.cryptocurrencies.map((e) => e.mainNetId)) { + for (final mainNetId in Coins.enabled.map((e) => e.mainNetId)) { if (map[mainNetId] is String) { result[mainNetId] = Color( (map[mainNetId] as String).toBigIntFromHex.toInt(), @@ -2176,7 +2196,7 @@ class ThemeAssetsV2 implements IThemeAssets { final Map result = {}; - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { result[coin.mainNetId] = map[coin.mainNetId] as String? ?? placeHolder; } @@ -2511,7 +2531,7 @@ class ThemeAssetsV3 implements IThemeAssets { final Map result = {}; - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { result[coin.mainNetId] = map[coin.mainNetId] as String? ?? placeHolder; result[coin.mainNetId] = prependIfNeeded(result[coin.mainNetId]!); } diff --git a/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart b/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart index c0f73cee4..2179542e3 100644 --- a/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart +++ b/lib/pages/add_wallet_views/add_wallet_view/add_wallet_view.dart @@ -35,9 +35,6 @@ import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/default_eth_tokens.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin_frost.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/monero.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/wownero.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -66,12 +63,10 @@ class _AddWalletViewState extends ConsumerState { String _searchTerm = ""; final _coinsTestnet = [ - ...Coins.cryptocurrencies - .where((e) => e.network == CryptoCurrencyNetwork.test), + ...Coins.enabled.where((e) => e.network == CryptoCurrencyNetwork.test), ]; final _coins = [ - ...Coins.cryptocurrencies - .where((e) => e.network == CryptoCurrencyNetwork.main), + ...Coins.enabled.where((e) => e.network == CryptoCurrencyNetwork.main), ]; final List coinEntities = []; final List tokenEntities = []; @@ -152,17 +147,19 @@ class _AddWalletViewState extends ConsumerState { coinEntities.addAll(_coinsTestnet.map((e) => CoinEntity(e))); } - final contracts = - MainDB.instance.getEthContracts().sortByName().findAllSync(); + if (Coins.enabled.whereType().isNotEmpty) { + final contracts = + MainDB.instance.getEthContracts().sortByName().findAllSync(); - if (contracts.isEmpty) { - contracts.addAll(DefaultTokens.list); - MainDB.instance.putEthContracts(contracts).then( - (value) => ref.read(priceAnd24hChangeNotifierProvider).updatePrice()); + if (contracts.isEmpty) { + contracts.addAll(DefaultTokens.list); + MainDB.instance.putEthContracts(contracts).then((value) => + ref.read(priceAnd24hChangeNotifierProvider).updatePrice()); + } + + tokenEntities.addAll(contracts.map((e) => EthTokenEntity(e))); } - tokenEntities.addAll(contracts.map((e) => EthTokenEntity(e))); - WidgetsBinding.instance.addPostFrameCallback((_) { ref.refresh(addWalletSelectedEntityStateProvider); }); @@ -292,15 +289,16 @@ class _AddWalletViewState extends ConsumerState { initialState: ExpandableState.expanded, animationDurationMultiplier: 0.5, ), - ExpandingSubListItem( - title: "Tokens", - entities: filter(_searchTerm, tokenEntities), - initialState: ExpandableState.expanded, - animationDurationMultiplier: 0.5, - trailing: AddCustomTokenSelector( - addFunction: _addToken, + if (tokenEntities.isNotEmpty) + ExpandingSubListItem( + title: "Tokens", + entities: filter(_searchTerm, tokenEntities), + initialState: ExpandableState.expanded, + animationDurationMultiplier: 0.5, + trailing: AddCustomTokenSelector( + addFunction: _addToken, + ), ), - ), ], ), ), diff --git a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_text.dart b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_text.dart index 77c5bcefb..f1586b165 100644 --- a/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_text.dart +++ b/lib/pages/add_wallet_views/add_wallet_view/sub_widgets/add_wallet_text.dart @@ -12,7 +12,7 @@ import 'package:flutter/material.dart'; import 'package:stackwallet/utilities/text_styles.dart'; class AddWalletText extends StatelessWidget { - const AddWalletText({Key? key, required this.isDesktop}) : super(key: key); + const AddWalletText({super.key, required this.isDesktop}); final bool isDesktop; diff --git a/lib/pages/address_book_views/address_book_view.dart b/lib/pages/address_book_views/address_book_view.dart index a57ed3622..6cbc86a7f 100644 --- a/lib/pages/address_book_views/address_book_view.dart +++ b/lib/pages/address_book_views/address_book_view.dart @@ -26,7 +26,6 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'; import 'package:stackwallet/widgets/address_book_card.dart'; @@ -67,7 +66,7 @@ class _AddressBookViewState extends ConsumerState { ref.refresh(addressBookFilterProvider); if (widget.coin == null) { - final coins = [...Coins.cryptocurrencies]; + final coins = [...Coins.enabled]; coins.removeWhere( (e) => e is Firo && e.network == CryptoCurrencyNetwork.test, ); diff --git a/lib/pages/address_book_views/subviews/address_book_filter_view.dart b/lib/pages/address_book_views/subviews/address_book_filter_view.dart index 7253d02d1..2f863f379 100644 --- a/lib/pages/address_book_views/subviews/address_book_filter_view.dart +++ b/lib/pages/address_book_views/subviews/address_book_filter_view.dart @@ -16,7 +16,6 @@ import 'package:stackwallet/supported_coins.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; @@ -41,7 +40,7 @@ class _AddressBookFilterViewState extends ConsumerState { @override void initState() { - final coins = [...Coins.cryptocurrencies]; + final coins = [...Coins.enabled]; coins.removeWhere( (e) => e is Firo && e.network == CryptoCurrencyNetwork.test, ); 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 409cb2e7e..f1d474170 100644 --- a/lib/pages/address_book_views/subviews/coin_select_sheet.dart +++ b/lib/pages/address_book_views/subviews/coin_select_sheet.dart @@ -19,7 +19,6 @@ import 'package:stackwallet/themes/coin_image_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; class CoinSelectSheet extends StatelessWidget { @@ -28,7 +27,7 @@ class CoinSelectSheet extends StatelessWidget { @override Widget build(BuildContext context) { final maxHeight = MediaQuery.of(context).size.height * 0.60; - final coins_ = [...Coins.cryptocurrencies]; + final coins_ = [...Coins.enabled]; coins_.removeWhere( (e) => e is Firo && e.network == CryptoCurrencyNetwork.test, ); 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 22433f8dd..33c901527 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 @@ -30,7 +30,6 @@ import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/icon_widgets/clipboard_icon.dart'; import 'package:stackwallet/widgets/icon_widgets/qrcode_icon.dart'; @@ -40,11 +39,11 @@ import 'package:stackwallet/widgets/textfield_icon_button.dart'; class NewContactAddressEntryForm extends ConsumerStatefulWidget { const NewContactAddressEntryForm({ - Key? key, + super.key, required this.id, required this.barcodeScanner, required this.clipboard, - }) : super(key: key); + }); final int id; @@ -74,7 +73,7 @@ class _NewContactAddressEntryFormState ..text = ref.read(addressEntryDataProvider(widget.id)).address ?? ""; addressLabelFocusNode = FocusNode(); addressFocusNode = FocusNode(); - coins = [...Coins.cryptocurrencies]; + coins = [...Coins.enabled]; super.initState(); } @@ -91,7 +90,7 @@ class _NewContactAddressEntryFormState Widget build(BuildContext context) { final isDesktop = Util.isDesktop; if (isDesktop) { - coins = [...Coins.cryptocurrencies]; + coins = [...Coins.enabled]; coins.removeWhere( (e) => e is Firo && e.network == CryptoCurrencyNetwork.test, ); diff --git a/lib/pages/buy_view/buy_form.dart b/lib/pages/buy_view/buy_form.dart index d45f7ea76..53dcd01f3 100644 --- a/lib/pages/buy_view/buy_form.dart +++ b/lib/pages/buy_view/buy_form.dart @@ -1331,9 +1331,7 @@ class _BuyFormState extends ConsumerState { ), Expanded( child: AddressBookAddressChooser( - coin: Coins - .cryptocurrencies - .firstWhere( + coin: Coins.enabled.firstWhere( (e) => e.ticker.toLowerCase() == selectedCrypto!.ticker diff --git a/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart b/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart index beffa27c7..3cff7b1b1 100644 --- a/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart +++ b/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart @@ -32,9 +32,9 @@ import 'package:stackwallet/widgets/textfield_icon_button.dart'; class CryptoSelectionView extends ConsumerStatefulWidget { const CryptoSelectionView({ - Key? key, + super.key, required this.coins, - }) : super(key: key); + }); final List coins; @@ -70,7 +70,7 @@ class _CryptoSelectionViewState extends ConsumerState { coins.sort( (a, b) => a.ticker.toLowerCase().compareTo(b.ticker.toLowerCase()), ); - for (final coin in Coins.cryptocurrencies.reversed) { + for (final coin in Coins.enabled.reversed) { final index = coins.indexWhere( (element) => element.ticker.toLowerCase() == coin.ticker.toLowerCase(), ); diff --git a/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart b/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart index 0ea602e18..b19057387 100644 --- a/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart +++ b/lib/pages/exchange_view/exchange_coin_selection/exchange_currency_selection_view.dart @@ -44,12 +44,12 @@ import 'package:stackwallet/widgets/textfield_icon_button.dart'; class ExchangeCurrencySelectionView extends StatefulWidget { const ExchangeCurrencySelectionView({ - Key? key, + super.key, required this.willChangeTicker, required this.pairedTicker, required this.isFixedRate, required this.willChangeIsSend, - }) : super(key: key); + }); final String? willChangeTicker; final String? pairedTicker; @@ -365,7 +365,7 @@ class _ExchangeCurrencySelectionViewState Flexible( child: Builder( builder: (context) { - final coins = Coins.cryptocurrencies.where( + final coins = Coins.enabled.where( (e) => e.ticker.toLowerCase() != widget.pairedTicker?.toLowerCase(), diff --git a/lib/pages/exchange_view/exchange_step_views/step_2_view.dart b/lib/pages/exchange_view/exchange_step_views/step_2_view.dart index 7b81b0799..ac5795d27 100644 --- a/lib/pages/exchange_view/exchange_step_views/step_2_view.dart +++ b/lib/pages/exchange_view/exchange_step_views/step_2_view.dart @@ -207,11 +207,11 @@ class _Step2ViewState extends ConsumerState { text: "Choose from Stack", onTap: () { try { - final coin = Coins.cryptocurrencies - .firstWhere((e) => - e.ticker.toLowerCase() == - model.receiveTicker - .toLowerCase()); + final coin = Coins.enabled.firstWhere( + (e) => + e.ticker.toLowerCase() == + model.receiveTicker.toLowerCase(), + ); Navigator.of(context) .pushNamed( @@ -258,7 +258,8 @@ class _Step2ViewState extends ConsumerState { child: TextField( onTap: () {}, key: const Key( - "recipientExchangeStep2ViewAddressFieldKey"), + "recipientExchangeStep2ViewAddressFieldKey", + ), controller: _toController, readOnly: false, autocorrect: false, @@ -305,7 +306,8 @@ class _Step2ViewState extends ConsumerState { _toController.text.isNotEmpty ? TextFieldIconButton( key: const Key( - "sendViewClearAddressFieldButtonKey"), + "sendViewClearAddressFieldButtonKey", + ), onTap: () { _toController.text = ""; model.recipientAddress = @@ -323,11 +325,13 @@ class _Step2ViewState extends ConsumerState { ) : TextFieldIconButton( key: const Key( - "sendViewPasteAddressFieldButtonKey"), + "sendViewPasteAddressFieldButtonKey", + ), onTap: () async { final ClipboardData? data = await clipboard.getData( - Clipboard.kTextPlain); + Clipboard.kTextPlain, + ); if (data?.text != null && data!.text!.isNotEmpty) { final content = @@ -357,12 +361,14 @@ class _Step2ViewState extends ConsumerState { if (_toController.text.isEmpty) TextFieldIconButton( key: const Key( - "sendViewAddressBookButtonKey"), + "sendViewAddressBookButtonKey", + ), onTap: () { ref .read( - exchangeFlowIsActiveStateProvider - .state) + exchangeFlowIsActiveStateProvider + .state, + ) .state = true; Navigator.of(context) .pushNamed( @@ -371,14 +377,16 @@ class _Step2ViewState extends ConsumerState { .then((_) { ref .read( - exchangeFlowIsActiveStateProvider - .state) + exchangeFlowIsActiveStateProvider + .state, + ) .state = false; final address = ref .read( - exchangeFromAddressBookAddressStateProvider - .state) + exchangeFromAddressBookAddressStateProvider + .state, + ) .state; if (address.isNotEmpty) { _toController.text = address; @@ -386,8 +394,9 @@ class _Step2ViewState extends ConsumerState { _toController.text; ref .read( - exchangeFromAddressBookAddressStateProvider - .state) + exchangeFromAddressBookAddressStateProvider + .state, + ) .state = ""; } setState(() { @@ -404,7 +413,8 @@ class _Step2ViewState extends ConsumerState { if (_toController.text.isEmpty) TextFieldIconButton( key: const Key( - "sendViewScanQrButtonKey"), + "sendViewScanQrButtonKey", + ), onTap: () async { try { final qrResult = @@ -412,7 +422,8 @@ class _Step2ViewState extends ConsumerState { final results = AddressUtils.parseUri( - qrResult.rawContent); + qrResult.rawContent, + ); if (results.isNotEmpty) { // auto fill address _toController.text = @@ -482,10 +493,11 @@ class _Step2ViewState extends ConsumerState { text: "Choose from Stack", onTap: () { try { - final coin = Coins.cryptocurrencies - .firstWhere((e) => - e.ticker.toLowerCase() == - model.sendTicker.toLowerCase()); + final coin = Coins.enabled.firstWhere( + (e) => + e.ticker.toLowerCase() == + model.sendTicker.toLowerCase(), + ); Navigator.of(context) .pushNamed( @@ -512,8 +524,10 @@ class _Step2ViewState extends ConsumerState { }); }); } catch (e, s) { - Logging.instance.log("$e\n$s", - level: LogLevel.Info); + Logging.instance.log( + "$e\n$s", + level: LogLevel.Info, + ); } }, ), @@ -530,7 +544,8 @@ class _Step2ViewState extends ConsumerState { ), child: TextField( key: const Key( - "refundExchangeStep2ViewAddressFieldKey"), + "refundExchangeStep2ViewAddressFieldKey", + ), controller: _refundController, readOnly: false, autocorrect: false, @@ -577,7 +592,8 @@ class _Step2ViewState extends ConsumerState { _refundController.text.isNotEmpty ? TextFieldIconButton( key: const Key( - "sendViewClearAddressFieldButtonKey"), + "sendViewClearAddressFieldButtonKey", + ), onTap: () { _refundController.text = ""; model.refundAddress = @@ -595,12 +611,13 @@ class _Step2ViewState extends ConsumerState { ) : TextFieldIconButton( key: const Key( - "sendViewPasteAddressFieldButtonKey"), + "sendViewPasteAddressFieldButtonKey", + ), onTap: () async { final ClipboardData? data = await clipboard.getData( - Clipboard - .kTextPlain); + Clipboard.kTextPlain, + ); if (data?.text != null && data! .text!.isNotEmpty) { @@ -631,12 +648,14 @@ class _Step2ViewState extends ConsumerState { if (_refundController.text.isEmpty) TextFieldIconButton( key: const Key( - "sendViewAddressBookButtonKey"), + "sendViewAddressBookButtonKey", + ), onTap: () { ref .read( - exchangeFlowIsActiveStateProvider - .state) + exchangeFlowIsActiveStateProvider + .state, + ) .state = true; Navigator.of(context) .pushNamed( @@ -645,13 +664,15 @@ class _Step2ViewState extends ConsumerState { .then((_) { ref .read( - exchangeFlowIsActiveStateProvider - .state) + exchangeFlowIsActiveStateProvider + .state, + ) .state = false; final address = ref .read( - exchangeFromAddressBookAddressStateProvider - .state) + exchangeFromAddressBookAddressStateProvider + .state, + ) .state; if (address.isNotEmpty) { _refundController.text = @@ -672,7 +693,8 @@ class _Step2ViewState extends ConsumerState { if (_refundController.text.isEmpty) TextFieldIconButton( key: const Key( - "sendViewScanQrButtonKey"), + "sendViewScanQrButtonKey", + ), onTap: () async { try { final qrResult = @@ -680,7 +702,8 @@ class _Step2ViewState extends ConsumerState { final results = AddressUtils.parseUri( - qrResult.rawContent); + qrResult.rawContent, + ); if (results.isNotEmpty) { // auto fill address _refundController.text = diff --git a/lib/pages/exchange_view/exchange_step_views/step_4_view.dart b/lib/pages/exchange_view/exchange_step_views/step_4_view.dart index 58f1a0c6c..d7438668e 100644 --- a/lib/pages/exchange_view/exchange_step_views/step_4_view.dart +++ b/lib/pages/exchange_view/exchange_step_views/step_4_view.dart @@ -35,8 +35,6 @@ import 'package:stackwallet/utilities/clipboard_interface.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/stellar.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/isar/providers/wallet_info_provider.dart'; import 'package:stackwallet/wallets/models/tx_data.dart'; @@ -853,9 +851,8 @@ class _Step4ViewState extends ConsumerState { .useMaterialPageRoute, builder: (BuildContext context) { - final coin = Coins - .cryptocurrencies - .firstWhere( + final coin = + Coins.enabled.firstWhere( (e) => e.ticker .toLowerCase() == diff --git a/lib/pages/settings_views/global_settings_view/advanced_views/manage_coin_units/manage_coin_units_view.dart b/lib/pages/settings_views/global_settings_view/advanced_views/manage_coin_units/manage_coin_units_view.dart index 0e9444e79..929175498 100644 --- a/lib/pages/settings_views/global_settings_view/advanced_views/manage_coin_units/manage_coin_units_view.dart +++ b/lib/pages/settings_views/global_settings_view/advanced_views/manage_coin_units/manage_coin_units_view.dart @@ -11,7 +11,6 @@ import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/conditional_parent.dart'; @@ -45,7 +44,7 @@ class ManageCoinUnitsView extends ConsumerWidget { prefsChangeNotifierProvider.select((value) => value.showTestNetCoins), ); - final _coins = Coins.cryptocurrencies + final _coins = Coins.enabled .where((e) => e is! Firo && e.network != CryptoCurrencyNetwork.test) .toList(); diff --git a/lib/pages/settings_views/global_settings_view/manage_nodes_views/manage_nodes_view.dart b/lib/pages/settings_views/global_settings_view/manage_nodes_views/manage_nodes_view.dart index 74c0eaabd..02a8a6799 100644 --- a/lib/pages/settings_views/global_settings_view/manage_nodes_views/manage_nodes_view.dart +++ b/lib/pages/settings_views/global_settings_view/manage_nodes_views/manage_nodes_view.dart @@ -20,7 +20,6 @@ import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -38,7 +37,7 @@ class ManageNodesView extends ConsumerStatefulWidget { } class _ManageNodesViewState extends ConsumerState { - List _coins = [...Coins.cryptocurrencies]; + List _coins = [...Coins.enabled]; @override void initState() { diff --git a/lib/pages_desktop_specific/address_book_view/desktop_address_book.dart b/lib/pages_desktop_specific/address_book_view/desktop_address_book.dart index 808b3429f..f94e52187 100644 --- a/lib/pages_desktop_specific/address_book_view/desktop_address_book.dart +++ b/lib/pages_desktop_specific/address_book_view/desktop_address_book.dart @@ -28,7 +28,6 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/wallet/wallet_mixin_interfaces/spark_interface.dart'; import 'package:stackwallet/widgets/address_book_card.dart'; @@ -99,7 +98,7 @@ class _DesktopAddressBook extends ConsumerState { ref.refresh(addressBookFilterProvider); // if (widget.coin == null) { - final coins = Coins.cryptocurrencies.toList(); + final coins = Coins.enabled.toList(); coins.removeWhere( (e) => e is Firo && e.network == CryptoCurrencyNetwork.test, ); diff --git a/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/desktop_manage_block_explorers_dialog.dart b/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/desktop_manage_block_explorers_dialog.dart index 6a5e32248..623aacdc4 100644 --- a/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/desktop_manage_block_explorers_dialog.dart +++ b/lib/pages_desktop_specific/settings/settings_menu/advanced_settings/desktop_manage_block_explorers_dialog.dart @@ -39,13 +39,11 @@ class DesktopManageBlockExplorersDialog extends ConsumerWidget { prefsChangeNotifierProvider.select((value) => value.showTestNetCoins), ); - final coins = showTestNet - ? Coins.cryptocurrencies - : Coins.cryptocurrencies - .where( - (e) => e.network == CryptoCurrencyNetwork.main, - ) - .toList(); + final coins = Coins.enabled + .where( + (e) => showTestNet || e.network == CryptoCurrencyNetwork.main, + ) + .toList(); return DesktopDialog( maxHeight: 850, diff --git a/lib/pages_desktop_specific/settings/settings_menu/nodes_settings.dart b/lib/pages_desktop_specific/settings/settings_menu/nodes_settings.dart index 01392b088..6c0537618 100644 --- a/lib/pages_desktop_specific/settings/settings_menu/nodes_settings.dart +++ b/lib/pages_desktop_specific/settings/settings_menu/nodes_settings.dart @@ -23,9 +23,6 @@ import 'package:stackwallet/utilities/assets.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; import 'package:stackwallet/utilities/util.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/monero.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/wownero.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/icon_widgets/x_icon.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; @@ -33,7 +30,7 @@ import 'package:stackwallet/widgets/stack_text_field.dart'; import 'package:stackwallet/widgets/textfield_icon_button.dart'; class NodesSettings extends ConsumerStatefulWidget { - const NodesSettings({Key? key}) : super(key: key); + const NodesSettings({super.key}); static const String routeName = "/settingsMenuNodes"; @@ -42,7 +39,7 @@ class NodesSettings extends ConsumerStatefulWidget { } class _NodesSettings extends ConsumerState { - List _coins = [...Coins.cryptocurrencies]; + List _coins = [...Coins.enabled]; late final TextEditingController searchNodeController; late final FocusNode searchNodeFocusNode; @@ -56,10 +53,12 @@ class _NodesSettings extends ConsumerState { return coins; } return coins - .where((coin) => - coin.prettyName.contains(filter) || - coin.identifier.contains(filter) || - coin.ticker.toLowerCase().contains(filter.toLowerCase())) + .where( + (coin) => + coin.prettyName.contains(filter) || + coin.identifier.contains(filter) || + coin.ticker.toLowerCase().contains(filter.toLowerCase()), + ) .toList(); } @@ -227,8 +226,10 @@ class _NodesSettings extends ConsumerState { itemBuilder: (context, index) { final coin = coins[index]; final count = ref - .watch(nodeServiceChangeNotifierProvider - .select((value) => value.getNodesFor(coin))) + .watch( + nodeServiceChangeNotifierProvider + .select((value) => value.getNodesFor(coin)), + ) .length; return Padding( @@ -290,7 +291,8 @@ class _NodesSettings extends ConsumerState { Text( "${coin.prettyName} nodes", style: STextStyles.titleBold12( - context), + context, + ), ), Text( count > 1 diff --git a/lib/services/node_service.dart b/lib/services/node_service.dart index 2e0d692ea..8940964c9 100644 --- a/lib/services/node_service.dart +++ b/lib/services/node_service.dart @@ -31,7 +31,7 @@ class NodeService extends ChangeNotifier { }); Future updateDefaults() async { - for (final defaultNode in Coins.cryptocurrencies.map( + for (final defaultNode in Coins.enabled.map( (e) => e.defaultNode, )) { final savedNode = DB.instance @@ -238,7 +238,7 @@ class NodeService extends ChangeNotifier { final map = jsonDecode(result as String); Logging.instance.log(map, level: LogLevel.Info); - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { final nodeList = List>.from( map["nodes"][coin.identifier] as List? ?? [], ); diff --git a/lib/services/price.dart b/lib/services/price.dart index e2ff7384b..4bc02113a 100644 --- a/lib/services/price.dart +++ b/lib/services/price.dart @@ -48,7 +48,7 @@ class PriceAPI { ) async { final Map map = {}; - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { final entry = data[coin]; if (entry == null) { map[coin.prettyName] = ["0", 0.0]; @@ -68,8 +68,7 @@ class PriceAPI { {}; // init with 0 final result = { - for (final coin in Coins.cryptocurrencies) - coin: Tuple2(Decimal.zero, 0.0), + for (final coin in Coins.enabled) coin: Tuple2(Decimal.zero, 0.0), }; for (final entry in map.entries) { diff --git a/lib/services/price_service.dart b/lib/services/price_service.dart index 930099d74..b8d652ff0 100644 --- a/lib/services/price_service.dart +++ b/lib/services/price_service.dart @@ -30,7 +30,7 @@ class PriceService extends ChangeNotifier { Timer? _timer; final Map> _cachedPrices = { - for (final coin in Coins.cryptocurrencies) coin: Tuple2(Decimal.zero, 0.0) + for (final coin in Coins.enabled) coin: Tuple2(Decimal.zero, 0.0), }; final Map> _cachedTokenPrices = {}; diff --git a/lib/services/wallets.dart b/lib/services/wallets.dart index 22daf7716..b7f799fcb 100644 --- a/lib/services/wallets.dart +++ b/lib/services/wallets.dart @@ -10,19 +10,20 @@ import 'dart:async'; -import 'package:flutter_libmonero/monero/monero.dart'; -import 'package:flutter_libmonero/wownero/wownero.dart'; +import 'package:flutter_libmonero/monero/monero.dart' as monero; +import 'package:flutter_libmonero/wownero/wownero.dart' as wownero; import 'package:isar/isar.dart'; import 'package:stackwallet/db/hive/db.dart'; import 'package:stackwallet/db/isar/main_db.dart'; import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/services/notifications_service.dart'; import 'package:stackwallet/services/trade_sent_from_stack_service.dart'; +import 'package:stackwallet/supported_coins.dart'; import 'package:stackwallet/utilities/enums/sync_type_enum.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/prefs.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/epiccash.dart'; +import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/isar/models/wallet_info.dart'; import 'package:stackwallet/wallets/wallet/impl/epiccash_wallet.dart'; import 'package:stackwallet/wallets/wallet/wallet.dart'; @@ -76,27 +77,31 @@ class Wallets { await secureStorage.delete(key: Wallet.mnemonicKey(walletId: walletId)); await secureStorage.delete( - key: Wallet.mnemonicPassphraseKey(walletId: walletId)); + key: Wallet.mnemonicPassphraseKey(walletId: walletId), + ); await secureStorage.delete(key: Wallet.privateKeyKey(walletId: walletId)); if (info.coin is Wownero) { - final wowService = - wownero.createWowneroWalletService(DB.instance.moneroWalletInfoBox); + final wowService = wownero.wownero + .createWowneroWalletService(DB.instance.moneroWalletInfoBox); await wowService.remove(walletId); Logging.instance .log("monero wallet: $walletId deleted", level: LogLevel.Info); } else if (info.coin is Monero) { - final xmrService = - monero.createMoneroWalletService(DB.instance.moneroWalletInfoBox); + final xmrService = monero.monero + .createMoneroWalletService(DB.instance.moneroWalletInfoBox); await xmrService.remove(walletId); Logging.instance .log("monero wallet: $walletId deleted", level: LogLevel.Info); } else if (info.coin is Epiccash) { final deleteResult = await deleteEpicWallet( - walletId: walletId, secureStore: secureStorage); + walletId: walletId, + secureStore: secureStorage, + ); Logging.instance.log( - "epic wallet: $walletId deleted with result: $deleteResult", - level: LogLevel.Info); + "epic wallet: $walletId deleted with result: $deleteResult", + level: LogLevel.Info, + ); } // delete wallet data in main db @@ -108,7 +113,9 @@ class Wallets { // when delete was requested so instead of deleting now we mark the wallet // as needs delete by adding it's id to a list which gets checked on app start await DB.instance.add( - boxName: DB.boxNameWalletsToDeleteOnStart, value: walletId); + boxName: DB.boxNameWalletsToDeleteOnStart, + value: walletId, + ); final lookupService = TradeSentFromStackService(); for (final lookup in lookupService.all) { @@ -149,10 +156,12 @@ class Wallets { // clear out any wallet hive boxes where the wallet was deleted in previous app run for (final walletId in DB.instance .values(boxName: DB.boxNameWalletsToDeleteOnStart)) { - await mainDB.isar.writeTxn(() async => await mainDB.isar.walletInfo - .where() - .walletIdEqualTo(walletId) - .deleteAll()); + await mainDB.isar.writeTxn( + () async => await mainDB.isar.walletInfo + .where() + .walletIdEqualTo(walletId) + .deleteAll(), + ); } // clear list await DB.instance @@ -210,11 +219,13 @@ class Wallets { if (wallet is CwBasedInterface) { // walletsToInitLinearly.add(Tuple2(manager, shouldSetAutoSync)); } else { - walletInitFutures.add(wallet.init().then((_) { - if (shouldSetAutoSync) { - wallet.shouldAutoSync = true; - } - })); + walletInitFutures.add( + wallet.init().then((_) { + if (shouldSetAutoSync) { + wallet.shouldAutoSync = true; + } + }), + ); } _wallets[wallet.walletId] = wallet; @@ -251,10 +262,12 @@ class Wallets { // clear out any wallet hive boxes where the wallet was deleted in previous app run for (final walletId in DB.instance .values(boxName: DB.boxNameWalletsToDeleteOnStart)) { - await mainDB.isar.writeTxn(() async => await mainDB.isar.walletInfo - .where() - .walletIdEqualTo(walletId) - .deleteAll()); + await mainDB.isar.writeTxn( + () async => await mainDB.isar.walletInfo + .where() + .walletIdEqualTo(walletId) + .deleteAll(), + ); } // clear list await DB.instance @@ -346,10 +359,12 @@ class Wallets { .toList(); if (walletInitFutures.isNotEmpty && walletsToInitLinearly.isNotEmpty) { - unawaited(Future.wait([ - _initLinearly(walletsToInitLinearly), - ...walletInitFutures, - ])); + unawaited( + Future.wait([ + _initLinearly(walletsToInitLinearly), + ...walletInitFutures, + ]), + ); } else if (walletInitFutures.isNotEmpty) { unawaited(Future.wait(walletInitFutures)); } else if (walletsToInitLinearly.isNotEmpty) { @@ -370,16 +385,25 @@ class Wallets { // clear out any wallet hive boxes where the wallet was deleted in previous app run for (final walletId in DB.instance .values(boxName: DB.boxNameWalletsToDeleteOnStart)) { - await mainDB.isar.writeTxn(() async => await mainDB.isar.walletInfo - .where() - .walletIdEqualTo(walletId) - .deleteAll()); + await mainDB.isar.writeTxn( + () async => await mainDB.isar.walletInfo + .where() + .walletIdEqualTo(walletId) + .deleteAll(), + ); } // clear list await DB.instance .deleteAll(boxName: DB.boxNameWalletsToDeleteOnStart); - final walletInfoList = await mainDB.isar.walletInfo.where().findAll(); + final walletInfoList = await mainDB.isar.walletInfo + .where() + .filter() + .anyOf( + Coins.enabled.map((e) => e.identifier), + (q, element) => q.coinNameMatches(element), + ) + .findAll(); if (walletInfoList.isEmpty) { return; } @@ -552,11 +576,13 @@ class Wallets { if (wallet is CwBasedInterface) { // walletsToInitLinearly.add(Tuple2(manager, shouldSetAutoSync)); } else { - walletInitFutures.add(wallet.init().then((_) { - // if (shouldSetAutoSync) { - // wallet.shouldAutoSync = true; - // } - })); + walletInitFutures.add( + wallet.init().then((_) { + // if (shouldSetAutoSync) { + // wallet.shouldAutoSync = true; + // } + }), + ); } } @@ -596,6 +622,7 @@ class Wallets { Future _deleteWallet(String walletId) async { // TODO proper clean up of other wallet data in addition to the following await mainDB.isar.writeTxn( - () async => await mainDB.isar.walletInfo.deleteByWalletId(walletId)); + () async => await mainDB.isar.walletInfo.deleteByWalletId(walletId), + ); } } diff --git a/lib/supported_coins.dart b/lib/supported_coins.dart index aea128b9c..133ded94a 100644 --- a/lib/supported_coins.dart +++ b/lib/supported_coins.dart @@ -1,29 +1,17 @@ -import 'package:stackwallet/wallets/crypto_currency/coins/banano.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin_frost.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoincash.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/dogecoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/ecash.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/epiccash.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/ethereum.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/litecoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/monero.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/namecoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/nano.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/particl.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/peercoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/solana.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/stellar.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/tezos.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/wownero.dart'; +import 'package:stackwallet/app_config.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/crypto_currency/intermediate/frost_currency.dart'; /// The supported coins. Eventually move away from the Coin enum class Coins { - /// A List of our supported coins. - static final List cryptocurrencies = [ + /// A List of enabled coins. + static List get enabled => all + .where( + (element) => AppConfig.supportedCoins.contains(element.runtimeType)) + .toList(); + + /// A List of all implemented coins. + static final List all = [ Bitcoin(CryptoCurrencyNetwork.main), BitcoinFrost(CryptoCurrencyNetwork.main), Litecoin(CryptoCurrencyNetwork.main), @@ -54,7 +42,7 @@ class Coins { ]; static CryptoCurrency getCryptoCurrencyFor(String coinIdentifier) => - cryptocurrencies.firstWhere( + all.firstWhere( (e) => e.identifier == coinIdentifier, ); @@ -63,7 +51,7 @@ class Coins { bool caseInsensitive = true, }) { final _ticker = caseInsensitive ? ticker.toLowerCase() : ticker; - return cryptocurrencies.firstWhere( + return all.firstWhere( caseInsensitive ? (e) => e.ticker.toLowerCase() == _ticker && e is! FrostCurrency : (e) => e.ticker == _ticker && e is! FrostCurrency, @@ -75,7 +63,7 @@ class Coins { static CryptoCurrency getCryptoCurrencyByPrettyName(final String prettyName) { final name = prettyName.replaceAll(" ", "").toLowerCase(); try { - return cryptocurrencies.firstWhere( + return all.firstWhere( (e) => e.identifier.toLowerCase() == name || e.prettyName == prettyName, ); } catch (_) { diff --git a/lib/utilities/prefs.dart b/lib/utilities/prefs.dart index e14e10dc7..a83cd802d 100644 --- a/lib/utilities/prefs.dart +++ b/lib/utilities/prefs.dart @@ -85,7 +85,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "lastUnlockedTimeout", - value: lastUnlockedTimeout); + value: lastUnlockedTimeout,); _lastUnlockedTimeout = lastUnlockedTimeout; notifyListeners(); } @@ -93,7 +93,7 @@ class Prefs extends ChangeNotifier { Future _getLastUnlockedTimeout() async { return (DB.instance.get( - boxName: DB.boxNamePrefs, key: "lastUnlockedTimeout")) as int? ?? + boxName: DB.boxNamePrefs, key: "lastUnlockedTimeout",)) as int? ?? 60; } @@ -106,7 +106,7 @@ class Prefs extends ChangeNotifier { set lastUnlocked(int lastUnlocked) { if (_lastUnlocked != lastUnlocked) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "lastUnlocked", value: lastUnlocked); + boxName: DB.boxNamePrefs, key: "lastUnlocked", value: lastUnlocked,); _lastUnlocked = lastUnlocked; notifyListeners(); } @@ -114,7 +114,7 @@ class Prefs extends ChangeNotifier { Future _getLastUnlocked() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "lastUnlocked") as int? ?? + boxName: DB.boxNamePrefs, key: "lastUnlocked",) as int? ?? 0; } @@ -133,13 +133,13 @@ class Prefs extends ChangeNotifier { await DB.instance.put( boxName: DB.boxNamePrefs, key: "currentNotificationId", - value: _currentNotificationId); + value: _currentNotificationId,); notifyListeners(); } Future _getCurrentNotificationIndex() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "currentNotificationId") as int? ?? + boxName: DB.boxNamePrefs, key: "currentNotificationId",) as int? ?? 0; } @@ -154,7 +154,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "walletIdsSyncOnStartup", - value: walletIdsSyncOnStartup); + value: walletIdsSyncOnStartup,); _walletIdsSyncOnStartup = walletIdsSyncOnStartup; notifyListeners(); } @@ -162,7 +162,7 @@ class Prefs extends ChangeNotifier { Future> _getWalletIdsSyncOnStartup() async { final list = await DB.instance.get( - boxName: DB.boxNamePrefs, key: "walletIdsSyncOnStartup") as List? ?? + boxName: DB.boxNamePrefs, key: "walletIdsSyncOnStartup",) as List? ?? []; return List.from(list); } @@ -178,7 +178,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "syncTypeIndex", - value: syncType.index); + value: syncType.index,); _syncType = syncType; notifyListeners(); } @@ -186,7 +186,7 @@ class Prefs extends ChangeNotifier { Future _getSyncType() async { final int index = await DB.instance.get( - boxName: DB.boxNamePrefs, key: "syncTypeIndex") as int? ?? + boxName: DB.boxNamePrefs, key: "syncTypeIndex",) as int? ?? SyncingType.allWalletsOnStartup.index; return SyncingType.values[index]; } @@ -200,7 +200,7 @@ class Prefs extends ChangeNotifier { set wifiOnly(bool wifiOnly) { if (_wifiOnly != wifiOnly) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "wifiOnly", value: wifiOnly); + boxName: DB.boxNamePrefs, key: "wifiOnly", value: wifiOnly,); _wifiOnly = wifiOnly; notifyListeners(); } @@ -223,7 +223,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "showFavoriteWallets", - value: showFavoriteWallets); + value: showFavoriteWallets,); _showFavoriteWallets = showFavoriteWallets; notifyListeners(); } @@ -231,7 +231,7 @@ class Prefs extends ChangeNotifier { Future _getShowFavoriteWallets() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "showFavoriteWallets") as bool? ?? + boxName: DB.boxNamePrefs, key: "showFavoriteWallets",) as bool? ?? true; } @@ -244,7 +244,7 @@ class Prefs extends ChangeNotifier { set language(String newLanguage) { if (_language != newLanguage) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "language", value: newLanguage); + boxName: DB.boxNamePrefs, key: "language", value: newLanguage,); _language = newLanguage; notifyListeners(); } @@ -252,7 +252,7 @@ class Prefs extends ChangeNotifier { Future _getPreferredLanguage() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "language") as String? ?? + boxName: DB.boxNamePrefs, key: "language",) as String? ?? Language.englishUS.description; } @@ -265,7 +265,7 @@ class Prefs extends ChangeNotifier { set currency(String newCurrency) { if (currency != newCurrency) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "currency", value: newCurrency); + boxName: DB.boxNamePrefs, key: "currency", value: newCurrency,); _currency = newCurrency; notifyListeners(); } @@ -273,7 +273,7 @@ class Prefs extends ChangeNotifier { Future _getPreferredCurrency() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "currency") as String? ?? + boxName: DB.boxNamePrefs, key: "currency",) as String? ?? "USD"; } @@ -327,7 +327,7 @@ class Prefs extends ChangeNotifier { set randomizePIN(bool randomizePIN) { if (_randomizePIN != randomizePIN) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "randomizePIN", value: randomizePIN); + boxName: DB.boxNamePrefs, key: "randomizePIN", value: randomizePIN,); _randomizePIN = randomizePIN; notifyListeners(); } @@ -335,7 +335,7 @@ class Prefs extends ChangeNotifier { Future _getRandomizePIN() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "randomizePIN") as bool? ?? + boxName: DB.boxNamePrefs, key: "randomizePIN",) as bool? ?? false; } @@ -348,7 +348,7 @@ class Prefs extends ChangeNotifier { set useBiometrics(bool useBiometrics) { if (_useBiometrics != useBiometrics) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "useBiometrics", value: useBiometrics); + boxName: DB.boxNamePrefs, key: "useBiometrics", value: useBiometrics,); _useBiometrics = useBiometrics; notifyListeners(); } @@ -356,7 +356,7 @@ class Prefs extends ChangeNotifier { Future _getUseBiometrics() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "useBiometrics") as bool? ?? + boxName: DB.boxNamePrefs, key: "useBiometrics",) as bool? ?? false; } @@ -390,7 +390,7 @@ class Prefs extends ChangeNotifier { set familiarity(int familiarity) { if (_familiarity != familiarity) { DB.instance.put( - boxName: DB.boxNamePrefs, key: "familiarity", value: familiarity); + boxName: DB.boxNamePrefs, key: "familiarity", value: familiarity,); _familiarity = familiarity; notifyListeners(); } @@ -398,7 +398,7 @@ class Prefs extends ChangeNotifier { Future _getHasFamiliarity() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "familiarity") as int? ?? + boxName: DB.boxNamePrefs, key: "familiarity",) as int? ?? 0; } @@ -439,7 +439,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "showTestNetCoins", - value: showTestNetCoins); + value: showTestNetCoins,); _showTestNetCoins = showTestNetCoins; notifyListeners(); } @@ -447,7 +447,7 @@ class Prefs extends ChangeNotifier { Future _getShowTestNetCoins() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "showTestNetCoins") as bool? ?? + boxName: DB.boxNamePrefs, key: "showTestNetCoins",) as bool? ?? false; } @@ -463,7 +463,7 @@ class Prefs extends ChangeNotifier { .put( boxName: DB.boxNamePrefs, key: "isAutoBackupEnabled", - value: isAutoBackupEnabled) + value: isAutoBackupEnabled,) .then((_) { _isAutoBackupEnabled = isAutoBackupEnabled; notifyListeners(); @@ -473,7 +473,7 @@ class Prefs extends ChangeNotifier { Future _getIsAutoBackupEnabled() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "isAutoBackupEnabled") as bool? ?? + boxName: DB.boxNamePrefs, key: "isAutoBackupEnabled",) as bool? ?? false; } @@ -488,7 +488,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "autoBackupLocation", - value: autoBackupLocation); + value: autoBackupLocation,); _autoBackupLocation = autoBackupLocation; notifyListeners(); } @@ -496,7 +496,7 @@ class Prefs extends ChangeNotifier { Future _getAutoBackupLocation() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "autoBackupLocation") as String?; + boxName: DB.boxNamePrefs, key: "autoBackupLocation",) as String?; } // auto backup frequency type @@ -513,19 +513,19 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "backupFrequencyType", - value: "10Min"); + value: "10Min",); break; case BackupFrequencyType.everyAppStart: DB.instance.put( boxName: DB.boxNamePrefs, key: "backupFrequencyType", - value: "onStart"); + value: "onStart",); break; case BackupFrequencyType.afterClosingAWallet: DB.instance.put( boxName: DB.boxNamePrefs, key: "backupFrequencyType", - value: "onWalletClose"); + value: "onWalletClose",); break; } _backupFrequencyType = backupFrequencyType; @@ -535,7 +535,7 @@ class Prefs extends ChangeNotifier { Future _getBackupFrequencyType() async { String? rate = await DB.instance.get( - boxName: DB.boxNamePrefs, key: "backupFrequencyType") as String?; + boxName: DB.boxNamePrefs, key: "backupFrequencyType",) as String?; rate ??= "10Min"; switch (rate) { case "10Min": @@ -560,7 +560,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "lastAutoBackup", - value: lastAutoBackup); + value: lastAutoBackup,); _lastAutoBackup = lastAutoBackup; notifyListeners(); } @@ -568,7 +568,7 @@ class Prefs extends ChangeNotifier { Future _getLastAutoBackup() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "autoBackupFileUri") as DateTime?; + boxName: DB.boxNamePrefs, key: "autoBackupFileUri",) as DateTime?; } // auto backup @@ -583,7 +583,7 @@ class Prefs extends ChangeNotifier { .put( boxName: DB.boxNamePrefs, key: "hideBlockExplorerWarning", - value: hideBlockExplorerWarning) + value: hideBlockExplorerWarning,) .then((_) { _hideBlockExplorerWarning = hideBlockExplorerWarning; notifyListeners(); @@ -594,7 +594,7 @@ class Prefs extends ChangeNotifier { Future _getHideBlockExplorerWarning() async { return await DB.instance.get( boxName: DB.boxNamePrefs, - key: "hideBlockExplorerWarning") as bool? ?? + key: "hideBlockExplorerWarning",) as bool? ?? false; } @@ -610,7 +610,7 @@ class Prefs extends ChangeNotifier { .put( boxName: DB.boxNamePrefs, key: "gotoWalletOnStartup", - value: gotoWalletOnStartup) + value: gotoWalletOnStartup,) .then((_) { _gotoWalletOnStartup = gotoWalletOnStartup; notifyListeners(); @@ -620,7 +620,7 @@ class Prefs extends ChangeNotifier { Future _getGotoWalletOnStartup() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "gotoWalletOnStartup") as bool? ?? + boxName: DB.boxNamePrefs, key: "gotoWalletOnStartup",) as bool? ?? false; } @@ -635,7 +635,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "startupWalletId", - value: startupWalletId); + value: startupWalletId,); _startupWalletId = startupWalletId; notifyListeners(); } @@ -643,7 +643,7 @@ class Prefs extends ChangeNotifier { Future _getStartupWalletId() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "startupWalletId") as String?; + boxName: DB.boxNamePrefs, key: "startupWalletId",) as String?; } // incognito mode off by default @@ -658,7 +658,7 @@ class Prefs extends ChangeNotifier { .put( boxName: DB.boxNamePrefs, key: "externalCalls", - value: externalCalls) + value: externalCalls,) .then((_) { _externalCalls = externalCalls; notifyListeners(); @@ -668,7 +668,7 @@ class Prefs extends ChangeNotifier { Future _getHasExternalCalls() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "externalCalls") as bool? ?? + boxName: DB.boxNamePrefs, key: "externalCalls",) as bool? ?? true; } @@ -718,7 +718,7 @@ class Prefs extends ChangeNotifier { Future saveSignupEpoch(int signupEpoch) async { _signupEpoch = signupEpoch; await DB.instance.put( - boxName: DB.boxNamePrefs, key: "signupEpoch", value: _signupEpoch); + boxName: DB.boxNamePrefs, key: "signupEpoch", value: _signupEpoch,); // notifyListeners(); } @@ -733,7 +733,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "enableCoinControl", - value: enableCoinControl); + value: enableCoinControl,); _enableCoinControl = enableCoinControl; notifyListeners(); } @@ -741,7 +741,7 @@ class Prefs extends ChangeNotifier { Future _getEnableCoinControl() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "enableCoinControl") as bool? ?? + boxName: DB.boxNamePrefs, key: "enableCoinControl",) as bool? ?? false; } @@ -756,7 +756,7 @@ class Prefs extends ChangeNotifier { DB.instance.put( boxName: DB.boxNamePrefs, key: "enableSystemBrightness", - value: enableSystemBrightness); + value: enableSystemBrightness,); _enableSystemBrightness = enableSystemBrightness; notifyListeners(); } @@ -764,7 +764,7 @@ class Prefs extends ChangeNotifier { Future _getEnableSystemBrightness() async { return await DB.instance.get( - boxName: DB.boxNamePrefs, key: "enableSystemBrightness") as bool? ?? + boxName: DB.boxNamePrefs, key: "enableSystemBrightness",) as bool? ?? false; } @@ -854,7 +854,7 @@ class Prefs extends ChangeNotifier { _amountUnits[coin] ?? AmountUnit.normal; void updateAmountUnit( - {required CryptoCurrency coin, required AmountUnit amountUnit}) { + {required CryptoCurrency coin, required AmountUnit amountUnit,}) { if (this.amountUnit(coin) != amountUnit) { DB.instance.put( boxName: DB.boxNamePrefs, @@ -867,7 +867,7 @@ class Prefs extends ChangeNotifier { } Future _setAmountUnits() async { - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { final unitIndex = await DB.instance.get( boxName: DB.boxNamePrefs, key: "amountUnitFor${coin.identifier}", @@ -900,7 +900,7 @@ class Prefs extends ChangeNotifier { } Future _setMaxDecimals() async { - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { final decimals = await DB.instance.get( boxName: DB.boxNamePrefs, key: "maxDecimalsFor${coin.identifier}", diff --git a/lib/wallets/crypto_currency/crypto_currency.dart b/lib/wallets/crypto_currency/crypto_currency.dart index 5a8e3e723..d4e484fa6 100644 --- a/lib/wallets/crypto_currency/crypto_currency.dart +++ b/lib/wallets/crypto_currency/crypto_currency.dart @@ -2,6 +2,27 @@ import 'package:stackwallet/models/isar/models/blockchain_data/address.dart'; import 'package:stackwallet/models/node_model.dart'; import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/banano.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/bitcoin_frost.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/bitcoincash.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/dogecoin.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/ecash.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/epiccash.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/ethereum.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/litecoin.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/monero.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/namecoin.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/nano.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/particl.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/peercoin.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/solana.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/stellar.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/tezos.dart'; +export 'package:stackwallet/wallets/crypto_currency/coins/wownero.dart'; +export 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; + enum CryptoCurrencyNetwork { main, test, diff --git a/lib/wallets/isar/models/wallet_info.dart b/lib/wallets/isar/models/wallet_info.dart index b165649ff..ed61ddede 100644 --- a/lib/wallets/isar/models/wallet_info.dart +++ b/lib/wallets/isar/models/wallet_info.dart @@ -407,9 +407,7 @@ class WalletInfo implements IsarId { this.cachedBalanceTertiaryString, this.otherDataJsonString, }) : assert( - Coins.cryptocurrencies - .map((e) => e.identifier) - .contains(coinName), + Coins.enabled.map((e) => e.identifier).contains(coinName), ); WalletInfo copyWith({ diff --git a/lib/wallets/isar/providers/all_wallets_info_provider.dart b/lib/wallets/isar/providers/all_wallets_info_provider.dart index a91a735c5..15ffaeb38 100644 --- a/lib/wallets/isar/providers/all_wallets_info_provider.dart +++ b/lib/wallets/isar/providers/all_wallets_info_provider.dart @@ -27,7 +27,7 @@ final pAllWalletsInfoByCoin = Provider((ref) { } final List<({CryptoCurrency coin, List wallets})> results = []; - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { if (map[coin] != null) { results.add(map[coin]!); } @@ -42,7 +42,14 @@ final _pAllWalletsInfo = ChangeNotifierProvider((ref) { if (_globalInstance == null) { final isar = ref.watch(mainDBProvider).isar; _globalInstance = _WalletInfoWatcher( - isar.walletInfo.where().findAllSync(), + isar.walletInfo + .where() + .filter() + .anyOf( + Coins.enabled.map((e) => e.identifier), + (q, element) => q.coinNameMatches(element), + ) + .findAllSync(), isar, ); } @@ -60,7 +67,15 @@ class _WalletInfoWatcher extends ChangeNotifier { _WalletInfoWatcher(this._value, Isar isar) { _streamSubscription = isar.walletInfo.watchLazy(fireImmediately: true).listen((event) { - isar.walletInfo.where().findAll().then((value) { + isar.walletInfo + .where() + .filter() + .anyOf( + Coins.enabled.map((e) => e.identifier), + (q, element) => q.coinNameMatches(element), + ) + .findAll() + .then((value) { _value = value; notifyListeners(); }); diff --git a/lib/wallets/isar/providers/favourite_wallets_provider.dart b/lib/wallets/isar/providers/favourite_wallets_provider.dart index 650b57d64..b09e94c95 100644 --- a/lib/wallets/isar/providers/favourite_wallets_provider.dart +++ b/lib/wallets/isar/providers/favourite_wallets_provider.dart @@ -4,6 +4,8 @@ import 'package:flutter/foundation.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:isar/isar.dart'; import 'package:stackwallet/providers/db/main_db_provider.dart'; +import 'package:stackwallet/supported_coins.dart'; +import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/wallets/isar/models/wallet_info.dart'; class _Watcher extends ChangeNotifier { @@ -17,6 +19,10 @@ class _Watcher extends ChangeNotifier { _Watcher(this._value, this.isFavourite, Isar isar) { _streamSubscription = isar.walletInfo .filter() + .anyOf( + Coins.enabled.map((e) => e.identifier), + (q, element) => q.coinNameMatches(element), + ) .isFavouriteEqualTo(isFavourite) .sortByFavouriteOrderIndex() .watch(fireImmediately: true) @@ -40,6 +46,10 @@ final _wiProvider = ChangeNotifierProvider.family<_Watcher, bool>( final watcher = _Watcher( isar.walletInfo .filter() + .anyOf( + Coins.enabled.map((e) => e.identifier), + (q, element) => q.coinNameMatches(element), + ) .isFavouriteEqualTo(isFavourite) .sortByFavouriteOrderIndex() .findAllSync(), diff --git a/lib/widgets/address_book_card.dart b/lib/widgets/address_book_card.dart index f8f23da8d..e1411a2fe 100644 --- a/lib/widgets/address_book_card.dart +++ b/lib/widgets/address_book_card.dart @@ -72,7 +72,7 @@ class _AddressBookCardState extends ConsumerState { final List coins = []; - for (final coin in Coins.cryptocurrencies) { + for (final coin in Coins.enabled) { if (contact.addresses.where((e) => e.coin == coin).isNotEmpty) { coins.add(coin); } diff --git a/lib/widgets/choose_coin_view.dart b/lib/widgets/choose_coin_view.dart index abd63b517..3a0f2e1a6 100644 --- a/lib/widgets/choose_coin_view.dart +++ b/lib/widgets/choose_coin_view.dart @@ -19,7 +19,6 @@ import 'package:stackwallet/themes/coin_icon_provider.dart'; import 'package:stackwallet/themes/stack_colors.dart'; import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/background.dart'; import 'package:stackwallet/widgets/custom_buttons/app_bar_icon_button.dart'; @@ -52,7 +51,7 @@ class ChooseCoinView extends ConsumerStatefulWidget { } class _ChooseCoinViewState extends ConsumerState { - List _coins = [...Coins.cryptocurrencies]; + List _coins = [...Coins.enabled]; @override void initState() { diff --git a/lib/widgets/node_options_sheet.dart b/lib/widgets/node_options_sheet.dart index 7002f7fa5..85ba3ddac 100644 --- a/lib/widgets/node_options_sheet.dart +++ b/lib/widgets/node_options_sheet.dart @@ -11,7 +11,6 @@ import 'dart:async'; import 'package:flutter/material.dart'; -import 'package:flutter_libmonero/wownero/wownero.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_svg/svg.dart'; import 'package:solana/solana.dart'; @@ -33,35 +32,17 @@ import 'package:stackwallet/utilities/test_epic_box_connection.dart'; import 'package:stackwallet/utilities/test_eth_node_connection.dart'; import 'package:stackwallet/utilities/test_monero_node_connection.dart'; import 'package:stackwallet/utilities/text_styles.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/banano.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin_frost.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoincash.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/dogecoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/ecash.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/epiccash.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/ethereum.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/firo.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/litecoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/monero.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/namecoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/nano.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/particl.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/peercoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/solana.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/stellar.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/tezos.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:tuple/tuple.dart'; class NodeOptionsSheet extends ConsumerWidget { const NodeOptionsSheet({ - Key? key, + super.key, required this.nodeId, required this.coin, required this.popBackToRoute, - }) : super(key: key); + }); final String nodeId; final CryptoCurrency coin; @@ -101,7 +82,10 @@ class NodeOptionsSheet extends ConsumerWidget { } Future _testConnection( - NodeModel node, BuildContext context, WidgetRef ref) async { + NodeModel node, + BuildContext context, + WidgetRef ref, + ) async { bool testPassed = false; switch (coin.runtimeType) { @@ -183,7 +167,7 @@ class NodeOptionsSheet extends ConsumerWidget { break; - case (Ethereum): + case const (Ethereum): try { testPassed = await testEthNodeConnection(node.host); } catch (_) { @@ -220,12 +204,14 @@ class NodeOptionsSheet extends ConsumerWidget { // context: context, // ); } else { - unawaited(showFloatingFlushBar( - type: FlushBarType.warning, - iconAsset: Assets.svg.circleAlert, - message: "Could not connect to node", - context: context, - )); + unawaited( + showFloatingFlushBar( + type: FlushBarType.warning, + iconAsset: Assets.svg.circleAlert, + message: "Could not connect to node", + context: context, + ), + ); } return testPassed; @@ -234,12 +220,16 @@ class NodeOptionsSheet extends ConsumerWidget { @override Widget build(BuildContext context, WidgetRef ref) { final maxHeight = MediaQuery.of(context).size.height * 0.60; - final node = ref.watch(nodeServiceChangeNotifierProvider - .select((value) => value.getNodeById(id: nodeId)))!; + final node = ref.watch( + nodeServiceChangeNotifierProvider + .select((value) => value.getNodeById(id: nodeId)), + )!; final status = ref - .watch(nodeServiceChangeNotifierProvider - .select((value) => value.getPrimaryNodeFor(currency: coin))) + .watch( + nodeServiceChangeNotifierProvider.select( + (value) => value.getPrimaryNodeFor(currency: coin)), + ) ?.id != nodeId ? "Disconnected" @@ -313,7 +303,8 @@ class NodeOptionsSheet extends ConsumerWidget { height: 15, width: 19, color: node.id.startsWith( - DefaultNodes.defaultNodeIdPrefix) + DefaultNodes.defaultNodeIdPrefix, + ) ? Theme.of(context) .extension()! .accentColorDark @@ -379,9 +370,10 @@ class NodeOptionsSheet extends ConsumerWidget { child: Text( "Details", style: STextStyles.button(context).copyWith( - color: Theme.of(context) - .extension()! - .accentColorDark), + color: Theme.of(context) + .extension()! + .accentColorDark, + ), ), ), ), diff --git a/test/services/node_service_test.dart b/test/services/node_service_test.dart index 85ee80dbd..a33d3c982 100644 --- a/test/services/node_service_test.dart +++ b/test/services/node_service_test.dart @@ -6,8 +6,6 @@ import 'package:stackwallet/models/node_model.dart'; import 'package:stackwallet/services/node_service.dart'; import 'package:stackwallet/supported_coins.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/bitcoin.dart'; -import 'package:stackwallet/wallets/crypto_currency/coins/monero.dart'; import 'package:stackwallet/wallets/crypto_currency/crypto_currency.dart'; void main() { @@ -114,7 +112,7 @@ void main() { await service.updateDefaults(); expect( service.nodes.length, - Coins.cryptocurrencies.map((e) => e.defaultNode).length, + Coins.enabled.map((e) => e.defaultNode).length, ); expect(fakeStore.interactions, 0); }); @@ -207,11 +205,10 @@ void main() { final fakeStore = FakeSecureStorage(); final service = NodeService(secureStorageInterface: fakeStore); final nodes = service.nodes; - final defaults = - Coins.cryptocurrencies.map((e) => e.defaultNode).toList(); + final defaults = Coins.enabled.map((e) => e.defaultNode).toList(); - nodes.sort((a, b) => a.host.compareTo(b.host)); - defaults.sort((a, b) => a.host.compareTo(b.host)); + nodes.sort((a, b) => a.id.compareTo(b.id)); + defaults.sort((a, b) => a.id.compareTo(b.id)); expect(nodes.length, defaults.length); expect(nodes.toString(), defaults.toString()); @@ -224,7 +221,7 @@ void main() { await service.add(nodeA, null, true); expect( service.nodes.length, - Coins.cryptocurrencies.map((e) => e.defaultNode).length + 1, + Coins.enabled.map((e) => e.defaultNode).length + 1, ); expect(fakeStore.interactions, 0); }); @@ -235,7 +232,7 @@ void main() { await service.add(nodeA, "some password", true); expect( service.nodes.length, - Coins.cryptocurrencies.map((e) => e.defaultNode).length + 1, + Coins.enabled.map((e) => e.defaultNode).length + 1, ); expect(fakeStore.interactions, 1); expect(fakeStore.writes, 1); @@ -293,7 +290,7 @@ void main() { expect( service.nodes.length, - Coins.cryptocurrencies.map((e) => e.defaultNode).length + 2, + Coins.enabled.map((e) => e.defaultNode).length + 2, ); expect( service.nodes.where((element) => element.id == nodeB.id).length,