From 49f024b65627d71b640485b996c55daa0bcad8d5 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 20 Jan 2023 18:26:13 -0600 Subject: [PATCH] use Julian's isStackCoin helper func very nice. didn't realize I could catch an error. learning every day round here --- .../sub_widgets/crypto_selection_view.dart | 20 ++++++++++---- lib/utilities/enums/coin_enum.dart | 26 ------------------- 2 files changed, 15 insertions(+), 31 deletions(-) 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 8d398d2d0..2ba50dda8 100644 --- a/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart +++ b/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart @@ -250,13 +250,23 @@ class _CryptoSelectionViewState extends State { } } +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; } diff --git a/lib/utilities/enums/coin_enum.dart b/lib/utilities/enums/coin_enum.dart index 7f130e00a..e50e51b44 100644 --- a/lib/utilities/enums/coin_enum.dart +++ b/lib/utilities/enums/coin_enum.dart @@ -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; - } -}