2023-02-05 20:32:39 +00:00
|
|
|
import 'package:isar/isar.dart';
|
2022-10-03 15:41:53 +00:00
|
|
|
import 'package:stackwallet/utilities/logger.dart';
|
|
|
|
|
2023-02-05 20:32:39 +00:00
|
|
|
part 'pair.g.dart';
|
|
|
|
|
|
|
|
@collection
|
2022-10-02 19:37:11 +00:00
|
|
|
class Pair {
|
2023-02-05 20:32:39 +00:00
|
|
|
Id? id;
|
|
|
|
|
|
|
|
@Index()
|
|
|
|
final String exchangeName;
|
|
|
|
|
|
|
|
@Index(composite: [
|
|
|
|
CompositeIndex("exchangeName"),
|
|
|
|
CompositeIndex("to"),
|
|
|
|
])
|
2022-10-02 19:37:11 +00:00
|
|
|
final String from;
|
|
|
|
final String fromNetwork;
|
|
|
|
|
|
|
|
final String to;
|
|
|
|
final String toNetwork;
|
|
|
|
|
|
|
|
final bool fixedRate;
|
|
|
|
final bool floatingRate;
|
|
|
|
|
|
|
|
Pair({
|
2023-02-05 20:32:39 +00:00
|
|
|
required this.exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
required this.from,
|
|
|
|
required this.fromNetwork,
|
|
|
|
required this.to,
|
|
|
|
required this.toNetwork,
|
|
|
|
required this.fixedRate,
|
|
|
|
required this.floatingRate,
|
|
|
|
});
|
|
|
|
|
2023-02-05 20:32:39 +00:00
|
|
|
factory Pair.fromMap(
|
|
|
|
Map<String, dynamic> map, {
|
|
|
|
required String exchangeName,
|
|
|
|
}) {
|
2022-10-03 15:41:53 +00:00
|
|
|
try {
|
|
|
|
return Pair(
|
2023-02-05 20:32:39 +00:00
|
|
|
exchangeName: exchangeName,
|
2022-10-03 15:41:53 +00:00
|
|
|
from: map["from"] as String,
|
|
|
|
fromNetwork: map["fromNetwork"] as String,
|
|
|
|
to: map["to"] as String,
|
|
|
|
toNetwork: map["toNetwork"] as String,
|
|
|
|
fixedRate: map["fixedRate"] as bool,
|
|
|
|
floatingRate: map["floatingRate"] as bool,
|
2023-02-05 20:32:39 +00:00
|
|
|
)..id = map["id"] as int?;
|
2022-10-03 15:41:53 +00:00
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance.log("Pair.fromMap(): $e\n$s", level: LogLevel.Error);
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toMap() {
|
2022-10-02 19:37:11 +00:00
|
|
|
return {
|
2023-02-05 20:32:39 +00:00
|
|
|
"id": id,
|
|
|
|
"exchangeName": exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
"from": from,
|
|
|
|
"fromNetwork": fromNetwork,
|
|
|
|
"to": to,
|
|
|
|
"toNetwork": toNetwork,
|
|
|
|
"fixedRate": fixedRate,
|
|
|
|
"floatingRate": floatingRate,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2022-10-03 15:41:53 +00:00
|
|
|
bool operator ==(other) =>
|
|
|
|
other is Pair &&
|
2023-02-05 20:32:39 +00:00
|
|
|
exchangeName == other.exchangeName &&
|
2022-10-03 15:41:53 +00:00
|
|
|
from == other.from &&
|
|
|
|
fromNetwork == other.fromNetwork &&
|
|
|
|
to == other.to &&
|
|
|
|
toNetwork == other.toNetwork &&
|
|
|
|
fixedRate == other.fixedRate &&
|
|
|
|
floatingRate == other.floatingRate;
|
|
|
|
|
|
|
|
@override
|
2023-02-05 20:32:39 +00:00
|
|
|
int get hashCode => Object.hash(
|
|
|
|
id,
|
|
|
|
exchangeName,
|
2022-10-03 15:41:53 +00:00
|
|
|
from,
|
|
|
|
fromNetwork,
|
|
|
|
to,
|
|
|
|
toNetwork,
|
|
|
|
fixedRate,
|
|
|
|
floatingRate,
|
|
|
|
);
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() => "Pair: ${toMap()}";
|
2022-10-02 19:37:11 +00:00
|
|
|
}
|