diff --git a/lib/models/buy/response_objects/crypto.dart b/lib/models/buy/response_objects/crypto.dart index ae8a25695..31693eb3c 100644 --- a/lib/models/buy/response_objects/crypto.dart +++ b/lib/models/buy/response_objects/crypto.dart @@ -5,46 +5,13 @@ class Crypto { /// Crypto name final String name; - /// Crypto network - final String network; - /// Crypto logo url final String image; - /// Indicates if a currency has an Extra ID - final bool hasExternalId; - - /// external id if it exists - final String? externalId; - - /// Indicates if a currency is a fiat currency (EUR, USD) - final bool isFiat; - - /// Indicates if a currency is popular - final bool featured; - - /// Indicates if a currency is stable - final bool isStable; - - /// Indicates if a currency is available on a fixed-rate flow - final bool supportsFixedRate; - - /// (Optional - based on api call) Indicates whether the pair is - /// currently supported by change now - final bool? isAvailable; - Crypto({ required this.ticker, required this.name, - required this.network, required this.image, - required this.hasExternalId, - this.externalId, - required this.isFiat, - required this.featured, - required this.isStable, - required this.supportsFixedRate, - this.isAvailable, }); factory Crypto.fromJson(Map<String, dynamic> json) { @@ -52,15 +19,7 @@ class Crypto { return Crypto( ticker: json["ticker"] as String, name: json["name"] as String, - network: json["network"] as String? ?? "", image: json["image"] as String, - hasExternalId: json["hasExternalId"] as bool, - externalId: json["externalId"] as String?, - isFiat: json["isFiat"] as bool, - featured: json["featured"] as bool, - isStable: json["isStable"] as bool, - supportsFixedRate: json["supportsFixedRate"] as bool, - isAvailable: json["isAvailable"] as bool?, ); } catch (e) { rethrow; @@ -71,48 +30,21 @@ class Crypto { final map = { "ticker": ticker, "name": name, - "network": network, "image": image, - "hasExternalId": hasExternalId, - "externalId": externalId, - "isFiat": isFiat, - "featured": featured, - "isStable": isStable, - "supportsFixedRate": supportsFixedRate, }; - if (isAvailable != null) { - map["isAvailable"] = isAvailable!; - } - return map; } Crypto copyWith({ String? ticker, String? name, - String? network, String? image, - bool? hasExternalId, - String? externalId, - bool? isFiat, - bool? featured, - bool? isStable, - bool? supportsFixedRate, - bool? isAvailable, }) { return Crypto( ticker: ticker ?? this.ticker, name: name ?? this.name, - network: network ?? this.network, image: image ?? this.image, - hasExternalId: hasExternalId ?? this.hasExternalId, - externalId: externalId ?? this.externalId, - isFiat: isFiat ?? this.isFiat, - featured: featured ?? this.featured, - isStable: isStable ?? this.isStable, - supportsFixedRate: supportsFixedRate ?? this.supportsFixedRate, - isAvailable: isAvailable ?? this.isAvailable, ); } diff --git a/lib/models/buy/response_objects/fiat.dart b/lib/models/buy/response_objects/fiat.dart index 99433a6be..c1d565493 100644 --- a/lib/models/buy/response_objects/fiat.dart +++ b/lib/models/buy/response_objects/fiat.dart @@ -5,62 +5,17 @@ class Fiat { /// Fiat name final String name; - /// Fiat network - final String network; - /// Fiat logo url final String image; - /// Indicates if a currency has an Extra ID - final bool hasExternalId; - - /// external id if it exists - final String? externalId; - - /// Indicates if a currency is a fiat currency (EUR, USD) - final bool isFiat; - - /// Indicates if a currency is popular - final bool featured; - - /// Indicates if a currency is stable - final bool isStable; - - /// Indicates if a currency is available on a fixed-rate flow - final bool supportsFixedRate; - - /// (Optional - based on api call) Indicates whether the pair is - /// currently supported by change now - final bool? isAvailable; - - Fiat({ - required this.ticker, - required this.name, - required this.network, - required this.image, - required this.hasExternalId, - this.externalId, - required this.isFiat, - required this.featured, - required this.isStable, - required this.supportsFixedRate, - this.isAvailable, - }); + Fiat({required this.ticker, required this.name, required this.image}); factory Fiat.fromJson(Map<String, dynamic> json) { try { return Fiat( ticker: json["ticker"] as String, name: json["name"] as String, - network: json["network"] as String? ?? "", image: json["image"] as String, - hasExternalId: json["hasExternalId"] as bool, - externalId: json["externalId"] as String?, - isFiat: json["isFiat"] as bool, - featured: json["featured"] as bool, - isStable: json["isStable"] as bool, - supportsFixedRate: json["supportsFixedRate"] as bool, - isAvailable: json["isAvailable"] as bool?, ); } catch (e) { rethrow; @@ -71,48 +26,21 @@ class Fiat { final map = { "ticker": ticker, "name": name, - "network": network, "image": image, - "hasExternalId": hasExternalId, - "externalId": externalId, - "isFiat": isFiat, - "featured": featured, - "isStable": isStable, - "supportsFixedRate": supportsFixedRate, }; - if (isAvailable != null) { - map["isAvailable"] = isAvailable!; - } - return map; } Fiat copyWith({ String? ticker, String? name, - String? network, String? image, - bool? hasExternalId, - String? externalId, - bool? isFiat, - bool? featured, - bool? isStable, - bool? supportsFixedRate, - bool? isAvailable, }) { return Fiat( ticker: ticker ?? this.ticker, name: name ?? this.name, - network: network ?? this.network, image: image ?? this.image, - hasExternalId: hasExternalId ?? this.hasExternalId, - externalId: externalId ?? this.externalId, - isFiat: isFiat ?? this.isFiat, - featured: featured ?? this.featured, - isStable: isStable ?? this.isStable, - supportsFixedRate: supportsFixedRate ?? this.supportsFixedRate, - isAvailable: isAvailable ?? this.isAvailable, ); } diff --git a/lib/services/buy/simplex/simplex_api.dart b/lib/services/buy/simplex/simplex_api.dart index 6a6dc677e..22c7c9db2 100644 --- a/lib/services/buy/simplex/simplex_api.dart +++ b/lib/services/buy/simplex/simplex_api.dart @@ -1,5 +1,6 @@ import 'dart:convert'; +import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; // import 'package:stackwallet/models/exchange/response_objects/fixed_rate_market.dart'; // import 'package:stackwallet/models/exchange/response_objects/pair.dart'; @@ -163,9 +164,11 @@ class SimplexAPI { } print(res.body); - return null; + dynamic jsonArray = jsonDecode(res.body); - // return await compute(_parseAvailableCurrenciesJson, jsonArray as List); + print(jsonArray); + + return await compute(_parseSupported, jsonArray); } catch (e, s) { Logging.instance.log("getAvailableCurrencies exception: $e\n$s", level: LogLevel.Error); @@ -178,22 +181,22 @@ class SimplexAPI { } } - BuyResponse<List<Fiat>> _parseAvailableCurrenciesJson( - List<dynamic> jsonArray) { + BuyResponse<List<Fiat>> _parseSupported(dynamic jsonArray) { try { - List<Fiat> currencies = []; + List<Fiat> cryptos = []; + List<Fiat> fiats = []; for (final json in jsonArray) { - try { - currencies.add(Fiat.fromJson(Map<String, dynamic>.from(json as Map))); - } catch (_) { + dynamic supportedCryptos = + jsonArray['result']['supported_digital_currencies']; + print(supportedCryptos); return BuyResponse( exception: BuyException("Failed to serialize $json", BuyExceptionType.serializeResponseError)); - } - } + dynamic supportedFiats = jsonArray['result']['supported_fiat_currencies']; + print(supportedFiats); - return BuyResponse(value: currencies); + return BuyResponse(value: cryptos); } catch (e, s) { Logging.instance.log("_parseAvailableCurrenciesJson exception: $e\n$s", level: LogLevel.Error);