get coin images for coins we support

This commit is contained in:
sneurlax 2023-01-20 17:58:18 -06:00
parent 39f5df3158
commit 50a3815946
2 changed files with 50 additions and 12 deletions

View file

@ -208,8 +208,7 @@ class _CryptoSelectionViewState extends State<CryptoSelectionView> {
placeholderBuilder: (_) => placeholderBuilder: (_) =>
const LoadingIndicator(), const LoadingIndicator(),
) )
: null, : getIconForTicker(_coins[index].ticker)),
),
const SizedBox( const SizedBox(
width: 10, width: 10,
), ),
@ -250,3 +249,16 @@ class _CryptoSelectionViewState extends State<CryptoSelectionView> {
); );
} }
} }
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;
}

View file

@ -330,3 +330,29 @@ Coin coinFromTickerCaseInsensitive(String ticker) {
ticker, "name", "No Coin enum value with that 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;
}
}