pare down crypto and fiat types and WIP stash of progress

This commit is contained in:
sneurlax 2023-01-12 15:15:42 -06:00
parent 8e9150d7fe
commit b18ee6ba19
3 changed files with 15 additions and 152 deletions
lib
models/buy/response_objects
services/buy/simplex

View file

@ -5,46 +5,13 @@ class Crypto {
/// Crypto name /// Crypto name
final String name; final String name;
/// Crypto network
final String network;
/// Crypto logo url /// Crypto logo url
final String image; 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({ Crypto({
required this.ticker, required this.ticker,
required this.name, required this.name,
required this.network,
required this.image, 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) { factory Crypto.fromJson(Map<String, dynamic> json) {
@ -52,15 +19,7 @@ class Crypto {
return Crypto( return Crypto(
ticker: json["ticker"] as String, ticker: json["ticker"] as String,
name: json["name"] as String, name: json["name"] as String,
network: json["network"] as String? ?? "",
image: json["image"] 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) { } catch (e) {
rethrow; rethrow;
@ -71,48 +30,21 @@ class Crypto {
final map = { final map = {
"ticker": ticker, "ticker": ticker,
"name": name, "name": name,
"network": network,
"image": image, "image": image,
"hasExternalId": hasExternalId,
"externalId": externalId,
"isFiat": isFiat,
"featured": featured,
"isStable": isStable,
"supportsFixedRate": supportsFixedRate,
}; };
if (isAvailable != null) {
map["isAvailable"] = isAvailable!;
}
return map; return map;
} }
Crypto copyWith({ Crypto copyWith({
String? ticker, String? ticker,
String? name, String? name,
String? network,
String? image, String? image,
bool? hasExternalId,
String? externalId,
bool? isFiat,
bool? featured,
bool? isStable,
bool? supportsFixedRate,
bool? isAvailable,
}) { }) {
return Crypto( return Crypto(
ticker: ticker ?? this.ticker, ticker: ticker ?? this.ticker,
name: name ?? this.name, name: name ?? this.name,
network: network ?? this.network,
image: image ?? this.image, 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,
); );
} }

View file

@ -5,62 +5,17 @@ class Fiat {
/// Fiat name /// Fiat name
final String name; final String name;
/// Fiat network
final String network;
/// Fiat logo url /// Fiat logo url
final String image; final String image;
/// Indicates if a currency has an Extra ID Fiat({required this.ticker, required this.name, required this.image});
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,
});
factory Fiat.fromJson(Map<String, dynamic> json) { factory Fiat.fromJson(Map<String, dynamic> json) {
try { try {
return Fiat( return Fiat(
ticker: json["ticker"] as String, ticker: json["ticker"] as String,
name: json["name"] as String, name: json["name"] as String,
network: json["network"] as String? ?? "",
image: json["image"] 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) { } catch (e) {
rethrow; rethrow;
@ -71,48 +26,21 @@ class Fiat {
final map = { final map = {
"ticker": ticker, "ticker": ticker,
"name": name, "name": name,
"network": network,
"image": image, "image": image,
"hasExternalId": hasExternalId,
"externalId": externalId,
"isFiat": isFiat,
"featured": featured,
"isStable": isStable,
"supportsFixedRate": supportsFixedRate,
}; };
if (isAvailable != null) {
map["isAvailable"] = isAvailable!;
}
return map; return map;
} }
Fiat copyWith({ Fiat copyWith({
String? ticker, String? ticker,
String? name, String? name,
String? network,
String? image, String? image,
bool? hasExternalId,
String? externalId,
bool? isFiat,
bool? featured,
bool? isStable,
bool? supportsFixedRate,
bool? isAvailable,
}) { }) {
return Fiat( return Fiat(
ticker: ticker ?? this.ticker, ticker: ticker ?? this.ticker,
name: name ?? this.name, name: name ?? this.name,
network: network ?? this.network,
image: image ?? this.image, 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,
); );
} }

View file

@ -1,5 +1,6 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http; 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/fixed_rate_market.dart';
// import 'package:stackwallet/models/exchange/response_objects/pair.dart'; // import 'package:stackwallet/models/exchange/response_objects/pair.dart';
@ -163,9 +164,11 @@ class SimplexAPI {
} }
print(res.body); 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) { } catch (e, s) {
Logging.instance.log("getAvailableCurrencies exception: $e\n$s", Logging.instance.log("getAvailableCurrencies exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);
@ -178,22 +181,22 @@ class SimplexAPI {
} }
} }
BuyResponse<List<Fiat>> _parseAvailableCurrenciesJson( BuyResponse<List<Fiat>> _parseSupported(dynamic jsonArray) {
List<dynamic> jsonArray) {
try { try {
List<Fiat> currencies = []; List<Fiat> cryptos = [];
List<Fiat> fiats = [];
for (final json in jsonArray) { for (final json in jsonArray) {
try { dynamic supportedCryptos =
currencies.add(Fiat.fromJson(Map<String, dynamic>.from(json as Map))); jsonArray['result']['supported_digital_currencies'];
} catch (_) { print(supportedCryptos);
return BuyResponse( return BuyResponse(
exception: BuyException("Failed to serialize $json", exception: BuyException("Failed to serialize $json",
BuyExceptionType.serializeResponseError)); BuyExceptionType.serializeResponseError));
} dynamic supportedFiats = jsonArray['result']['supported_fiat_currencies'];
} print(supportedFiats);
return BuyResponse(value: currencies); return BuyResponse(value: cryptos);
} catch (e, s) { } catch (e, s) {
Logging.instance.log("_parseAvailableCurrenciesJson exception: $e\n$s", Logging.instance.log("_parseAvailableCurrenciesJson exception: $e\n$s",
level: LogLevel.Error); level: LogLevel.Error);