diff --git a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart index fada0b998..a708267a9 100644 --- a/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart +++ b/lib/pages/wallets_view/sub_widgets/wallet_list_item.dart @@ -63,8 +63,8 @@ class WalletListItem extends ConsumerWidget { // Check if Tor is enabled... if (ref.read(prefsChangeNotifierProvider).useTor) { // ... and if the coin supports Tor. - final cryptocurrency = SupportedCoins.coins[coin]; - if (cryptocurrency != null && !cryptocurrency!.torSupport) { + final cryptocurrency = SupportedCoins.getCryptoCurrencyFor(coin); + if (!cryptocurrency.torSupport) { // If not, show a Tor warning dialog. final shouldContinue = await showDialog( context: context, 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 8785c7ac6..3b3c6f32f 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 @@ -29,7 +29,7 @@ import 'package:stackwallet/widgets/dialogs/tor_warning_dialog.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart'; class WalletSummaryTable extends ConsumerStatefulWidget { - const WalletSummaryTable({Key? key}) : super(key: key); + const WalletSummaryTable({super.key}); @override ConsumerState createState() => _WalletTableState(); @@ -70,10 +70,10 @@ class _WalletTableState extends ConsumerState { class DesktopWalletSummaryRow extends ConsumerStatefulWidget { const DesktopWalletSummaryRow({ - Key? key, + super.key, required this.coin, required this.walletCount, - }) : super(key: key); + }); final Coin coin; final int walletCount; @@ -91,8 +91,8 @@ class _DesktopWalletSummaryRowState // Check if Tor is enabled... if (ref.read(prefsChangeNotifierProvider).useTor) { // ... and if the coin supports Tor. - final cryptocurrency = SupportedCoins.coins[widget.coin]; - if (cryptocurrency != null && !cryptocurrency!.torSupport) { + final cryptocurrency = SupportedCoins.getCryptoCurrencyFor(widget.coin); + if (!cryptocurrency.torSupport) { // If not, show a Tor warning dialog. final shouldContinue = await showDialog( context: context, diff --git a/lib/supported_coins.dart b/lib/supported_coins.dart index ef28d8916..48960c03e 100644 --- a/lib/supported_coins.dart +++ b/lib/supported_coins.dart @@ -13,66 +13,73 @@ 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/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/wallets/crypto_currency/crypto_currency.dart'; -/// The supported coins. +/// The supported coins. Eventually move away from the Coin enum class SupportedCoins { - /// A List of our supported coins. - static final List cryptocurrencies = [ - // Mainnet coins. - Bitcoin(CryptoCurrencyNetwork.main), - Monero(CryptoCurrencyNetwork.main), - Banano(CryptoCurrencyNetwork.main), - Bitcoincash(CryptoCurrencyNetwork.main), - BitcoinFrost(CryptoCurrencyNetwork.main), - Dogecoin(CryptoCurrencyNetwork.main), - Ecash(CryptoCurrencyNetwork.main), - Epiccash(CryptoCurrencyNetwork.main), - Ethereum(CryptoCurrencyNetwork.main), - Firo(CryptoCurrencyNetwork.main), - Litecoin(CryptoCurrencyNetwork.main), - Namecoin(CryptoCurrencyNetwork.main), - Nano(CryptoCurrencyNetwork.main), - Particl(CryptoCurrencyNetwork.main), - Stellar(CryptoCurrencyNetwork.main), - Tezos(CryptoCurrencyNetwork.main), - Wownero(CryptoCurrencyNetwork.main), + /// A List of our supported coins. Piggy back on [Coin] for now + static final List cryptocurrencies = + Coin.values.map((e) => getCryptoCurrencyFor(e)).toList(growable: false); - /// Testnet coins. - Bitcoin(CryptoCurrencyNetwork.test), - Banano(CryptoCurrencyNetwork.test), - Bitcoincash(CryptoCurrencyNetwork.test), - BitcoinFrost(CryptoCurrencyNetwork.test), - Dogecoin(CryptoCurrencyNetwork.test), - Stellar(CryptoCurrencyNetwork.test), - Firo(CryptoCurrencyNetwork.test), - Litecoin(CryptoCurrencyNetwork.test), - Stellar(CryptoCurrencyNetwork.test), - ]; - - /// A Map linking a CryptoCurrency with its associated Coin. + /// A getter function linking a [CryptoCurrency] with its associated [Coin]. /// /// Temporary: Remove when the Coin enum is removed. - static final Map coins = { - Coin.bitcoin: Bitcoin(CryptoCurrencyNetwork.main), - Coin.monero: Monero(CryptoCurrencyNetwork.main), - Coin.banano: Banano(CryptoCurrencyNetwork.main), - Coin.bitcoincash: Bitcoincash(CryptoCurrencyNetwork.main), - Coin.bitcoinFrost: BitcoinFrost(CryptoCurrencyNetwork.main), - Coin.dogecoin: Dogecoin(CryptoCurrencyNetwork.main), - Coin.eCash: Ecash(CryptoCurrencyNetwork.main), - Coin.epicCash: Epiccash(CryptoCurrencyNetwork.main), - Coin.ethereum: Ethereum(CryptoCurrencyNetwork.main), - Coin.firo: Firo(CryptoCurrencyNetwork.main), - Coin.litecoin: Litecoin(CryptoCurrencyNetwork.main), - Coin.namecoin: Namecoin(CryptoCurrencyNetwork.main), - Coin.nano: Nano(CryptoCurrencyNetwork.main), - Coin.particl: Particl(CryptoCurrencyNetwork.main), - Coin.stellar: Stellar(CryptoCurrencyNetwork.main), - Coin.tezos: Tezos(CryptoCurrencyNetwork.main), - Coin.wownero: Wownero(CryptoCurrencyNetwork.main), - }; + static CryptoCurrency getCryptoCurrencyFor(Coin coin) { + switch (coin) { + case Coin.bitcoin: + return Bitcoin(CryptoCurrencyNetwork.main); + case Coin.bitcoinFrost: + return BitcoinFrost(CryptoCurrencyNetwork.main); + case Coin.litecoin: + return Litecoin(CryptoCurrencyNetwork.main); + case Coin.bitcoincash: + return Bitcoincash(CryptoCurrencyNetwork.main); + case Coin.dogecoin: + return Dogecoin(CryptoCurrencyNetwork.main); + case Coin.epicCash: + return Epiccash(CryptoCurrencyNetwork.main); + case Coin.eCash: + return Ecash(CryptoCurrencyNetwork.main); + case Coin.ethereum: + return Ethereum(CryptoCurrencyNetwork.main); + case Coin.firo: + return Firo(CryptoCurrencyNetwork.main); + case Coin.monero: + return Monero(CryptoCurrencyNetwork.main); + case Coin.particl: + return Particl(CryptoCurrencyNetwork.main); + case Coin.solana: + return Solana(CryptoCurrencyNetwork.main); + case Coin.stellar: + return Stellar(CryptoCurrencyNetwork.main); + case Coin.tezos: + return Tezos(CryptoCurrencyNetwork.main); + case Coin.wownero: + return Wownero(CryptoCurrencyNetwork.main); + case Coin.namecoin: + return Namecoin(CryptoCurrencyNetwork.main); + case Coin.nano: + return Nano(CryptoCurrencyNetwork.main); + case Coin.banano: + return Banano(CryptoCurrencyNetwork.main); + case Coin.bitcoinTestNet: + return Bitcoin(CryptoCurrencyNetwork.test); + case Coin.bitcoinFrostTestNet: + return BitcoinFrost(CryptoCurrencyNetwork.test); + case Coin.litecoinTestNet: + return Litecoin(CryptoCurrencyNetwork.test); + case Coin.bitcoincashTestnet: + return Bitcoincash(CryptoCurrencyNetwork.test); + case Coin.firoTestNet: + return Firo(CryptoCurrencyNetwork.test); + case Coin.dogecoinTestNet: + return Dogecoin(CryptoCurrencyNetwork.test); + case Coin.stellarTestnet: + return Stellar(CryptoCurrencyNetwork.test); + } + } }