From 50a3815946de412aa395dade025982fd694c853b Mon Sep 17 00:00:00 2001 From: sneurlax Date: Fri, 20 Jan 2023 17:58:18 -0600 Subject: [PATCH] get coin images for coins we support --- .../sub_widgets/crypto_selection_view.dart | 36 ++++++++++++------- lib/utilities/enums/coin_enum.dart | 26 ++++++++++++++ 2 files changed, 50 insertions(+), 12 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 917f8d560..fc7455180 100644 --- a/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart +++ b/lib/pages/buy_view/sub_widgets/crypto_selection_view.dart @@ -198,18 +198,17 @@ class _CryptoSelectionViewState extends State { child: Row( children: [ SizedBox( - width: 24, - height: 24, - child: _coins[index].image.isNotEmpty - ? SvgPicture.network( - _coins[index].image, - width: 24, - height: 24, - placeholderBuilder: (_) => - const LoadingIndicator(), - ) - : null, - ), + width: 24, + height: 24, + child: _coins[index].image.isNotEmpty + ? SvgPicture.network( + _coins[index].image, + width: 24, + height: 24, + placeholderBuilder: (_) => + const LoadingIndicator(), + ) + : getIconForTicker(_coins[index].ticker)), const SizedBox( width: 10, ), @@ -250,3 +249,16 @@ class _CryptoSelectionViewState extends State { ); } } + +Widget? getIconForTicker(String ticker) { + print(ticker); + if (!isCoinSupportedByTicker(ticker)) { + return null; + } + Coin? coin = coinFromTickerCaseInsensitive(ticker); + String iconAsset = Assets.svg.iconFor(coin: coin); + if (iconAsset != null) { + return SvgPicture.asset(iconAsset, height: 20, width: 20); + } + return null; +} diff --git a/lib/utilities/enums/coin_enum.dart b/lib/utilities/enums/coin_enum.dart index df586ebf5..922e76c4b 100644 --- a/lib/utilities/enums/coin_enum.dart +++ b/lib/utilities/enums/coin_enum.dart @@ -330,3 +330,29 @@ 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; + } +}