use a switch to exhaustively ensure we didn't forget to include a newly added Coin value

This commit is contained in:
julian 2024-05-09 10:51:28 -06:00
parent 370cb3f4a6
commit 9bfac51926
3 changed files with 67 additions and 60 deletions

View file

@ -63,8 +63,8 @@ class WalletListItem extends ConsumerWidget {
// Check if Tor is enabled... // Check if Tor is enabled...
if (ref.read(prefsChangeNotifierProvider).useTor) { if (ref.read(prefsChangeNotifierProvider).useTor) {
// ... and if the coin supports Tor. // ... and if the coin supports Tor.
final cryptocurrency = SupportedCoins.coins[coin]; final cryptocurrency = SupportedCoins.getCryptoCurrencyFor(coin);
if (cryptocurrency != null && !cryptocurrency!.torSupport) { if (!cryptocurrency.torSupport) {
// If not, show a Tor warning dialog. // If not, show a Tor warning dialog.
final shouldContinue = await showDialog<bool>( final shouldContinue = await showDialog<bool>(
context: context, context: context,

View file

@ -29,7 +29,7 @@ import 'package:stackwallet/widgets/dialogs/tor_warning_dialog.dart';
import 'package:stackwallet/widgets/rounded_white_container.dart'; import 'package:stackwallet/widgets/rounded_white_container.dart';
class WalletSummaryTable extends ConsumerStatefulWidget { class WalletSummaryTable extends ConsumerStatefulWidget {
const WalletSummaryTable({Key? key}) : super(key: key); const WalletSummaryTable({super.key});
@override @override
ConsumerState<WalletSummaryTable> createState() => _WalletTableState(); ConsumerState<WalletSummaryTable> createState() => _WalletTableState();
@ -70,10 +70,10 @@ class _WalletTableState extends ConsumerState<WalletSummaryTable> {
class DesktopWalletSummaryRow extends ConsumerStatefulWidget { class DesktopWalletSummaryRow extends ConsumerStatefulWidget {
const DesktopWalletSummaryRow({ const DesktopWalletSummaryRow({
Key? key, super.key,
required this.coin, required this.coin,
required this.walletCount, required this.walletCount,
}) : super(key: key); });
final Coin coin; final Coin coin;
final int walletCount; final int walletCount;
@ -91,8 +91,8 @@ class _DesktopWalletSummaryRowState
// Check if Tor is enabled... // Check if Tor is enabled...
if (ref.read(prefsChangeNotifierProvider).useTor) { if (ref.read(prefsChangeNotifierProvider).useTor) {
// ... and if the coin supports Tor. // ... and if the coin supports Tor.
final cryptocurrency = SupportedCoins.coins[widget.coin]; final cryptocurrency = SupportedCoins.getCryptoCurrencyFor(widget.coin);
if (cryptocurrency != null && !cryptocurrency!.torSupport) { if (!cryptocurrency.torSupport) {
// If not, show a Tor warning dialog. // If not, show a Tor warning dialog.
final shouldContinue = await showDialog<bool>( final shouldContinue = await showDialog<bool>(
context: context, context: context,

View file

@ -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/namecoin.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/nano.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/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/stellar.dart';
import 'package:stackwallet/wallets/crypto_currency/coins/tezos.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/coins/wownero.dart';
import 'package:stackwallet/wallets/crypto_currency/crypto_currency.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 { class SupportedCoins {
/// A List of our supported coins. /// A List of our supported coins. Piggy back on [Coin] for now
static final List<CryptoCurrency> cryptocurrencies = [ static final List<CryptoCurrency> cryptocurrencies =
// Mainnet coins. Coin.values.map((e) => getCryptoCurrencyFor(e)).toList(growable: false);
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),
/// Testnet coins. /// A getter function linking a [CryptoCurrency] with its associated [Coin].
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.
/// ///
/// Temporary: Remove when the Coin enum is removed. /// Temporary: Remove when the Coin enum is removed.
static final Map<Coin, CryptoCurrency> coins = { static CryptoCurrency getCryptoCurrencyFor(Coin coin) {
Coin.bitcoin: Bitcoin(CryptoCurrencyNetwork.main), switch (coin) {
Coin.monero: Monero(CryptoCurrencyNetwork.main), case Coin.bitcoin:
Coin.banano: Banano(CryptoCurrencyNetwork.main), return Bitcoin(CryptoCurrencyNetwork.main);
Coin.bitcoincash: Bitcoincash(CryptoCurrencyNetwork.main), case Coin.bitcoinFrost:
Coin.bitcoinFrost: BitcoinFrost(CryptoCurrencyNetwork.main), return BitcoinFrost(CryptoCurrencyNetwork.main);
Coin.dogecoin: Dogecoin(CryptoCurrencyNetwork.main), case Coin.litecoin:
Coin.eCash: Ecash(CryptoCurrencyNetwork.main), return Litecoin(CryptoCurrencyNetwork.main);
Coin.epicCash: Epiccash(CryptoCurrencyNetwork.main), case Coin.bitcoincash:
Coin.ethereum: Ethereum(CryptoCurrencyNetwork.main), return Bitcoincash(CryptoCurrencyNetwork.main);
Coin.firo: Firo(CryptoCurrencyNetwork.main), case Coin.dogecoin:
Coin.litecoin: Litecoin(CryptoCurrencyNetwork.main), return Dogecoin(CryptoCurrencyNetwork.main);
Coin.namecoin: Namecoin(CryptoCurrencyNetwork.main), case Coin.epicCash:
Coin.nano: Nano(CryptoCurrencyNetwork.main), return Epiccash(CryptoCurrencyNetwork.main);
Coin.particl: Particl(CryptoCurrencyNetwork.main), case Coin.eCash:
Coin.stellar: Stellar(CryptoCurrencyNetwork.main), return Ecash(CryptoCurrencyNetwork.main);
Coin.tezos: Tezos(CryptoCurrencyNetwork.main), case Coin.ethereum:
Coin.wownero: Wownero(CryptoCurrencyNetwork.main), 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);
}
}
} }