use simplex_api supported_fiats and update fiat model

This commit is contained in:
sneurlax 2023-01-20 15:45:37 -06:00
parent adf83aa3a6
commit c3dd04b830
2 changed files with 31 additions and 10 deletions

View file

@ -1,3 +1,5 @@
import 'package:decimal/decimal.dart';
class Fiat {
/// Fiat ticker
final String ticker;
@ -5,17 +7,30 @@ class Fiat {
/// Fiat name
final String name;
/// Fiat name
final Decimal min_amount;
/// Fiat name
final Decimal max_amount;
/// Fiat logo url
final String image;
Fiat({required this.ticker, required this.name, required this.image});
Fiat(
{required this.ticker,
required this.name,
required this.min_amount,
required this.max_amount,
required this.image});
factory Fiat.fromJson(Map<String, dynamic> json) {
try {
return Fiat(
ticker: json["ticker"] as String,
name: json["name"] as String,
image: json["image"] as String,
ticker: "${json['ticker']}",
name: "${json['name']}", // TODO nameFromTicker
min_amount: Decimal.parse("${json['min_amount'] ?? 0}"),
max_amount: Decimal.parse("${json['max_amount'] ?? 0}"),
image: "${json['image']}",
);
} catch (e) {
rethrow;
@ -26,6 +41,8 @@ class Fiat {
final map = {
"ticker": ticker,
"name": name,
"min_amount": min_amount,
"max_amount": max_amount,
"image": image,
};
@ -35,11 +52,15 @@ class Fiat {
Fiat copyWith({
String? ticker,
String? name,
Decimal? min_amount,
Decimal? max_amount,
String? image,
}) {
return Fiat(
ticker: ticker ?? this.ticker,
name: name ?? this.name,
min_amount: min_amount ?? this.min_amount,
max_amount: max_amount ?? this.max_amount,
image: image ?? this.image,
);
}

View file

@ -66,7 +66,6 @@ class SimplexAPI {
List<Crypto> cryptos = [];
List<Fiat> fiats = [];
// TODO map List<String> supportedCryptos to List<Crypto>
for (final crypto in jsonArray as List) {
cryptos.add(Crypto.fromJson({
'ticker': "${crypto['ticker_symbol']}",
@ -126,12 +125,13 @@ class SimplexAPI {
print(jsonArray);
var supportedFiats = jsonArray['result']['supported_fiat_currencies'];
// TODO map List<String> supportedFiats to List<Fiat>
for (final ticker in supportedFiats as List) {
for (final fiat in jsonArray as List) {
print(fiat);
fiats.add(Fiat.fromJson({
'ticker': ticker as String,
'name': ticker,
'ticker': "${fiat['ticker_symbol']}",
'name': "${fiat['ticker_symbol']}",
'min_amount': "${fiat['min_amount']}",
'max_amount': "${fiat['max_amount']}",
'image': "",
}));
}