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...
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<bool>(
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';
class WalletSummaryTable extends ConsumerStatefulWidget {
const WalletSummaryTable({Key? key}) : super(key: key);
const WalletSummaryTable({super.key});
@override
ConsumerState<WalletSummaryTable> createState() => _WalletTableState();
@ -70,10 +70,10 @@ class _WalletTableState extends ConsumerState<WalletSummaryTable> {
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<bool>(
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/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<CryptoCurrency> 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<CryptoCurrency> 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<Coin, CryptoCurrency> 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);
}
}
}