use Julian's isStackCoin helper func

very nice.  didn't realize I could catch an error.  learning every day round here
This commit is contained in:
sneurlax 2023-01-20 18:26:13 -06:00
parent b376b00d7c
commit 49f024b656
2 changed files with 15 additions and 31 deletions

View file

@ -250,13 +250,23 @@ class _CryptoSelectionViewState extends State<CryptoSelectionView> {
}
}
bool isStackCoin(String? ticker) {
if (ticker == null) return false;
try {
coinFromTickerCaseInsensitive(ticker);
return true;
} on ArgumentError catch (_) {
return false;
}
}
Widget? getIconForTicker(String ticker) {
print(ticker);
String? iconAsset = isCoinSupportedByTicker(ticker)
String? iconAsset = isStackCoin(ticker)
? Assets.svg.iconFor(coin: coinFromTickerCaseInsensitive(ticker))
: Assets.svg.buyIconFor(ticker);
if (iconAsset != null) {
return SvgPicture.asset(iconAsset, height: 20, width: 20);
}
return null;
return (iconAsset != null)
? SvgPicture.asset(iconAsset, height: 20, width: 20)
: null;
}

View file

@ -328,29 +328,3 @@ Coin coinFromTickerCaseInsensitive(String ticker) {
ticker, "name", "No Coin enum value with that ticker");
}
}
// This was added for the Buy view.I would use coinFromTickerCaseInsensitive
// however I need it to return null or something else to indicate failure
// instead of throwing an exception
bool isCoinSupportedByTicker(String ticker) {
switch (ticker.toLowerCase()) {
case "btc":
case "ltc":
case "bch":
case "doge":
case "epic":
case "firo":
case "xmr":
case "nmc":
case "part":
case "tltc":
case "tbtc":
case "tbch":
case "tfiro":
case "tdoge":
case "wow":
return true;
default:
return false;
}
}