mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-29 21:55:58 +00:00
reduce size of Pair class
This commit is contained in:
parent
10605d96a2
commit
3d01ec8598
5 changed files with 19 additions and 64 deletions
|
@ -1,10 +1,19 @@
|
|||
import 'package:isar/isar.dart';
|
||||
import 'package:stackwallet/utilities/logger.dart';
|
||||
|
||||
part 'pair.g.dart';
|
||||
|
||||
// embedded enum // no not modify
|
||||
enum SupportedRateType { fixed, estimated, both }
|
||||
|
||||
@collection
|
||||
class Pair {
|
||||
Pair({
|
||||
required this.exchangeName,
|
||||
required this.from,
|
||||
required this.to,
|
||||
required this.rateType,
|
||||
});
|
||||
|
||||
Id? id;
|
||||
|
||||
@Index()
|
||||
|
@ -15,54 +24,19 @@ class Pair {
|
|||
CompositeIndex("to"),
|
||||
])
|
||||
final String from;
|
||||
final String fromNetwork;
|
||||
|
||||
final String to;
|
||||
final String toNetwork;
|
||||
|
||||
final bool fixedRate;
|
||||
final bool floatingRate;
|
||||
|
||||
Pair({
|
||||
required this.exchangeName,
|
||||
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,
|
||||
}) {
|
||||
try {
|
||||
return Pair(
|
||||
exchangeName: exchangeName,
|
||||
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?;
|
||||
} catch (e, s) {
|
||||
Logging.instance.log("Pair.fromMap(): $e\n$s", level: LogLevel.Error);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
@enumerated
|
||||
final SupportedRateType rateType;
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
"id": id,
|
||||
"exchangeName": exchangeName,
|
||||
"from": from,
|
||||
"fromNetwork": fromNetwork,
|
||||
"to": to,
|
||||
"toNetwork": toNetwork,
|
||||
"fixedRate": fixedRate,
|
||||
"floatingRate": floatingRate,
|
||||
"rateType": rateType,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -71,22 +45,15 @@ class Pair {
|
|||
other is Pair &&
|
||||
exchangeName == other.exchangeName &&
|
||||
from == other.from &&
|
||||
fromNetwork == other.fromNetwork &&
|
||||
to == other.to &&
|
||||
toNetwork == other.toNetwork &&
|
||||
fixedRate == other.fixedRate &&
|
||||
floatingRate == other.floatingRate;
|
||||
rateType == other.rateType;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
id,
|
||||
exchangeName,
|
||||
from,
|
||||
fromNetwork,
|
||||
to,
|
||||
toNetwork,
|
||||
fixedRate,
|
||||
floatingRate,
|
||||
rateType,
|
||||
);
|
||||
|
||||
@override
|
||||
|
|
|
@ -843,10 +843,7 @@ class ChangeNowAPI {
|
|||
exchangeName: ChangeNowExchange.exchangeName,
|
||||
from: stringPair[0],
|
||||
to: stringPair[1],
|
||||
fromNetwork: "",
|
||||
toNetwork: "",
|
||||
fixedRate: false,
|
||||
floatingRate: true,
|
||||
rateType: SupportedRateType.estimated,
|
||||
),
|
||||
);
|
||||
} catch (_) {
|
||||
|
|
|
@ -104,11 +104,8 @@ class ChangeNowExchange extends Exchange {
|
|||
Pair(
|
||||
exchangeName: ChangeNowExchange.exchangeName,
|
||||
from: market.from,
|
||||
fromNetwork: "",
|
||||
to: market.to,
|
||||
toNetwork: "",
|
||||
fixedRate: true,
|
||||
floatingRate: false,
|
||||
rateType: SupportedRateType.fixed,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -139,11 +139,8 @@ class MajesticBankExchange extends Exchange {
|
|||
final pair = Pair(
|
||||
exchangeName: MajesticBankExchange.exchangeName,
|
||||
from: rate.fromCurrency,
|
||||
fromNetwork: "",
|
||||
to: rate.toCurrency,
|
||||
toNetwork: "",
|
||||
fixedRate: true,
|
||||
floatingRate: true,
|
||||
rateType: SupportedRateType.both,
|
||||
);
|
||||
pairs.add(pair);
|
||||
}
|
||||
|
|
|
@ -274,11 +274,8 @@ class SimpleSwapAPI {
|
|||
Pair(
|
||||
exchangeName: SimpleSwapExchange.exchangeName,
|
||||
from: from,
|
||||
fromNetwork: "",
|
||||
to: to as String,
|
||||
toNetwork: "",
|
||||
fixedRate: args.item2,
|
||||
floatingRate: !args.item2,
|
||||
rateType: SupportedRateType.estimated,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue