From 6c48caff486a0a88839afb3fb72514095c446b71 Mon Sep 17 00:00:00 2001 From: sneurlax Date: Thu, 26 Jan 2023 17:08:57 -0600 Subject: [PATCH] only add stack coins to list TODO refactor isStackCoin into a reusable form instead of copying it around 3 times :P --- lib/services/buy/simplex/simplex_api.dart | 28 +++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 95b99c07e..f51f53c4f 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -8,6 +8,7 @@ import 'package:stackwallet/models/buy/response_objects/fiat.dart'; import 'package:stackwallet/models/buy/response_objects/order.dart'; import 'package:stackwallet/models/buy/response_objects/quote.dart'; import 'package:stackwallet/services/buy/buy_response.dart'; +import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/fiat_enum.dart'; import 'package:stackwallet/utilities/logger.dart'; import 'package:stackwallet/utilities/prefs.dart'; @@ -71,13 +72,15 @@ class SimplexAPI { for (final crypto in jsonArray as List) { // TODO validate jsonArray - cryptos.add(Crypto.fromJson({ - 'ticker': "${crypto['ticker_symbol']}", - 'name': crypto['name'], - 'network': "${crypto['network']}", - 'contractAddress': "${crypto['contractAddress']}", - 'image': "", - })); + if (isStackCoin("${crypto['ticker_symbol']}")) { + cryptos.add(Crypto.fromJson({ + 'ticker': "${crypto['ticker_symbol']}", + 'name': crypto['name'], + 'network': "${crypto['network']}", + 'contractAddress': "${crypto['contractAddress']}", + 'image': "", + })); + } } return BuyResponse(value: cryptos); @@ -331,3 +334,14 @@ class SimplexAPI { String timeZoneFormatter(Duration offset) => "${offset.isNegative ? "-" : "+"}${offset.inHours.abs().toString().padLeft(2, "0")}:${(offset.inMinutes - offset.inHours * 60).abs().toString().padLeft(2, "0")}"; } + +bool isStackCoin(String? ticker) { + if (ticker == null) return false; + + try { + coinFromTickerCaseInsensitive(ticker); + return true; + } on ArgumentError catch (_) { + return false; + } +}