stack_wallet/lib/models/isar/exchange_cache/pair.dart

95 lines
2 KiB
Dart
Raw Normal View History

import 'package:isar/isar.dart';
2022-10-03 15:41:53 +00:00
import 'package:stackwallet/utilities/logger.dart';
part 'pair.g.dart';
@collection
2022-10-02 19:37:11 +00:00
class Pair {
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({
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,
});
factory Pair.fromMap(
Map<String, dynamic> map, {
required String exchangeName,
}) {
2022-10-03 15:41:53 +00:00
try {
return Pair(
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,
)..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 {
"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 &&
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
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
}