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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-02-05 20:32:39 +00:00
|
|
|
import 'package:isar/isar.dart';
|
2024-05-23 17:26:58 +00:00
|
|
|
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../../app_config.dart';
|
|
|
|
import 'pair.dart';
|
2023-02-05 20:32:39 +00:00
|
|
|
|
|
|
|
part 'currency.g.dart';
|
|
|
|
|
|
|
|
@Collection(accessor: "currencies")
|
2022-08-26 08:11:35 +00:00
|
|
|
class Currency {
|
2023-02-05 20:32:39 +00:00
|
|
|
Id? id;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
final String exchangeName;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
/// Currency ticker
|
2023-02-05 20:32:39 +00:00
|
|
|
@Index(composite: [
|
|
|
|
CompositeIndex("exchangeName"),
|
|
|
|
CompositeIndex("name"),
|
|
|
|
])
|
2022-08-26 08:11:35 +00:00
|
|
|
final String ticker;
|
|
|
|
|
|
|
|
/// Currency name
|
|
|
|
final String name;
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
/// Currency network
|
|
|
|
final String network;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
/// Currency logo url
|
|
|
|
final String image;
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
/// external id if it exists
|
|
|
|
final String? externalId;
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
/// Indicates if a currency is a fiat currency (EUR, USD)
|
|
|
|
final bool isFiat;
|
|
|
|
|
|
|
|
/// Indicates if a currency is available on a fixed-rate flow
|
2023-02-06 15:23:31 +00:00
|
|
|
@enumerated
|
|
|
|
final SupportedRateType rateType;
|
2023-02-05 20:32:39 +00:00
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
/// (Optional - based on api call) Indicates whether the pair is
|
|
|
|
/// currently supported by change now
|
|
|
|
final bool? isAvailable;
|
|
|
|
|
2023-02-05 20:32:39 +00:00
|
|
|
@Index()
|
|
|
|
final bool isStackCoin;
|
|
|
|
|
2023-02-28 20:27:42 +00:00
|
|
|
final String? tokenContract;
|
|
|
|
|
2023-02-08 20:06:58 +00:00
|
|
|
@ignore
|
2023-02-28 20:27:42 +00:00
|
|
|
bool get supportsFixedRate =>
|
|
|
|
rateType == SupportedRateType.fixed || rateType == SupportedRateType.both;
|
2023-02-08 20:06:58 +00:00
|
|
|
|
|
|
|
@ignore
|
2023-02-28 20:27:42 +00:00
|
|
|
bool get supportsEstimatedRate =>
|
|
|
|
rateType == SupportedRateType.estimated ||
|
|
|
|
rateType == SupportedRateType.both;
|
2023-02-08 20:06:58 +00:00
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
Currency({
|
2023-02-05 20:32:39 +00:00
|
|
|
required this.exchangeName,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.ticker,
|
|
|
|
required this.name,
|
2022-10-02 19:37:11 +00:00
|
|
|
required this.network,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.image,
|
2022-10-02 19:37:11 +00:00
|
|
|
this.externalId,
|
2022-08-26 08:11:35 +00:00
|
|
|
required this.isFiat,
|
2023-02-06 15:23:31 +00:00
|
|
|
required this.rateType,
|
2022-08-26 08:11:35 +00:00
|
|
|
this.isAvailable,
|
2023-02-05 20:32:39 +00:00
|
|
|
required this.isStackCoin,
|
2023-02-28 20:27:42 +00:00
|
|
|
required this.tokenContract,
|
2022-08-26 08:11:35 +00:00
|
|
|
});
|
|
|
|
|
2023-02-05 20:32:39 +00:00
|
|
|
factory Currency.fromJson(
|
|
|
|
Map<String, dynamic> json, {
|
|
|
|
required String exchangeName,
|
2023-02-06 15:23:31 +00:00
|
|
|
required SupportedRateType rateType,
|
2023-02-05 20:32:39 +00:00
|
|
|
}) {
|
2022-08-26 08:11:35 +00:00
|
|
|
try {
|
2023-02-05 20:32:39 +00:00
|
|
|
final ticker = (json["ticker"] as String).toUpperCase();
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
return Currency(
|
2023-02-05 20:32:39 +00:00
|
|
|
exchangeName: exchangeName,
|
|
|
|
ticker: ticker,
|
2022-08-26 08:11:35 +00:00
|
|
|
name: json["name"] as String,
|
2022-10-03 00:49:12 +00:00
|
|
|
network: json["network"] as String? ?? "",
|
2022-08-26 08:11:35 +00:00
|
|
|
image: json["image"] as String,
|
2022-10-02 19:37:11 +00:00
|
|
|
externalId: json["externalId"] as String?,
|
2022-08-26 08:11:35 +00:00
|
|
|
isFiat: json["isFiat"] as bool,
|
2023-02-06 15:23:31 +00:00
|
|
|
rateType: rateType,
|
2022-08-26 08:11:35 +00:00
|
|
|
isAvailable: json["isAvailable"] as bool?,
|
2023-02-05 20:32:39 +00:00
|
|
|
isStackCoin:
|
2024-05-23 17:26:58 +00:00
|
|
|
json["isStackCoin"] as bool? ?? AppConfig.isStackCoin(ticker),
|
2023-02-28 20:27:42 +00:00
|
|
|
tokenContract: json["tokenContract"] as String?,
|
2023-02-05 20:32:39 +00:00
|
|
|
)..id = json["id"] as int?;
|
2022-08-26 08:11:35 +00:00
|
|
|
} catch (e) {
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
final map = {
|
2023-02-05 20:32:39 +00:00
|
|
|
"id": id,
|
|
|
|
"exchangeName": exchangeName,
|
2022-08-26 08:11:35 +00:00
|
|
|
"ticker": ticker,
|
|
|
|
"name": name,
|
2022-10-02 19:37:11 +00:00
|
|
|
"network": network,
|
2022-08-26 08:11:35 +00:00
|
|
|
"image": image,
|
2022-10-02 19:37:11 +00:00
|
|
|
"externalId": externalId,
|
2022-08-26 08:11:35 +00:00
|
|
|
"isFiat": isFiat,
|
2023-02-06 15:23:31 +00:00
|
|
|
"rateType": rateType,
|
2023-02-05 20:32:39 +00:00
|
|
|
"isAvailable": isAvailable,
|
|
|
|
"isStackCoin": isStackCoin,
|
2023-02-28 20:27:42 +00:00
|
|
|
"tokenContract": tokenContract,
|
2022-08-26 08:11:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
|
|
|
Currency copyWith({
|
2023-02-05 20:32:39 +00:00
|
|
|
Id? id,
|
|
|
|
String? exchangeName,
|
2022-08-26 08:11:35 +00:00
|
|
|
String? ticker,
|
|
|
|
String? name,
|
2022-10-02 19:37:11 +00:00
|
|
|
String? network,
|
2022-08-26 08:11:35 +00:00
|
|
|
String? image,
|
2022-10-02 19:37:11 +00:00
|
|
|
String? externalId,
|
2022-08-26 08:11:35 +00:00
|
|
|
bool? isFiat,
|
2023-02-06 15:23:31 +00:00
|
|
|
SupportedRateType? rateType,
|
2022-08-26 08:11:35 +00:00
|
|
|
bool? isAvailable,
|
2023-02-05 20:32:39 +00:00
|
|
|
bool? isStackCoin,
|
2023-02-28 20:27:42 +00:00
|
|
|
String? tokenContract,
|
2022-08-26 08:11:35 +00:00
|
|
|
}) {
|
|
|
|
return Currency(
|
2023-02-05 20:32:39 +00:00
|
|
|
exchangeName: exchangeName ?? this.exchangeName,
|
2022-08-26 08:11:35 +00:00
|
|
|
ticker: ticker ?? this.ticker,
|
|
|
|
name: name ?? this.name,
|
2022-10-02 19:37:11 +00:00
|
|
|
network: network ?? this.network,
|
2022-08-26 08:11:35 +00:00
|
|
|
image: image ?? this.image,
|
2022-10-02 19:37:11 +00:00
|
|
|
externalId: externalId ?? this.externalId,
|
2022-08-26 08:11:35 +00:00
|
|
|
isFiat: isFiat ?? this.isFiat,
|
2023-02-06 15:23:31 +00:00
|
|
|
rateType: rateType ?? this.rateType,
|
2022-08-26 08:11:35 +00:00
|
|
|
isAvailable: isAvailable ?? this.isAvailable,
|
2023-02-05 20:32:39 +00:00
|
|
|
isStackCoin: isStackCoin ?? this.isStackCoin,
|
2023-02-28 20:27:42 +00:00
|
|
|
tokenContract: tokenContract ?? this.tokenContract,
|
2023-02-05 20:32:39 +00:00
|
|
|
)..id = id ?? this.id;
|
2022-08-26 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "Currency: ${toJson()}";
|
|
|
|
}
|
|
|
|
}
|