stack_wallet/lib/models/exchange/simpleswap/sp_currency.dart

112 lines
2.6 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
import '../../../utilities/logger.dart';
2022-10-02 19:37:11 +00:00
class SPCurrency {
/// currency name
final String name;
/// currency symbol
final String symbol;
/// currency network
final String network;
/// has this currency extra id parameter
final bool hasExtraId;
/// name of extra id (if exists)
final String? extraId;
/// relative url for currency icon svg
final String image;
/// informational messages about the currency they are changing
final List<dynamic> warningsFrom;
/// informational messages about the currency for which they are exchanged
final List<dynamic> warningsTo;
SPCurrency({
required this.name,
required this.symbol,
required this.network,
required this.hasExtraId,
required this.extraId,
required this.image,
required this.warningsFrom,
required this.warningsTo,
});
factory SPCurrency.fromJson(Map<String, dynamic> json) {
try {
return SPCurrency(
name: json["name"] as String,
symbol: json["symbol"] as String,
network: json["network"] as String? ?? "",
hasExtraId: json["has_extra_id"] as bool,
extraId: json["extra_id"] as String?,
image: json["image"] as String,
warningsFrom: json["warnings_from"] as List<dynamic>,
warningsTo: json["warnings_to"] as List<dynamic>,
);
} catch (e, s) {
2024-05-27 23:56:22 +00:00
Logging.instance.log(
"SPCurrency.fromJson failed to parse: $e\n$s",
level: LogLevel.Error,
);
2022-10-02 19:37:11 +00:00
rethrow;
}
}
Map<String, dynamic> toJson() {
final map = {
"name": name,
"symbol": symbol,
"network": network,
"has_extra_id": hasExtraId,
"extra_id": extraId,
"image": image,
"warnings_from": warningsFrom,
"warnings_to": warningsTo,
};
return map;
}
SPCurrency copyWith({
String? name,
String? symbol,
String? network,
bool? hasExtraId,
String? extraId,
String? image,
List<dynamic>? warningsFrom,
List<dynamic>? warningsTo,
}) {
return SPCurrency(
name: name ?? this.name,
symbol: symbol ?? this.symbol,
network: network ?? this.network,
hasExtraId: hasExtraId ?? this.hasExtraId,
extraId: extraId ?? this.extraId,
image: image ?? this.image,
warningsFrom: warningsFrom ?? this.warningsFrom,
warningsTo: warningsTo ?? this.warningsTo,
);
}
@override
String toString() {
return "SPCurrency: ${toJson()}";
}
}