2022-10-02 19:37:11 +00:00
|
|
|
import 'package:hive/hive.dart';
|
2022-10-03 00:54:35 +00:00
|
|
|
import 'package:stackwallet/models/exchange/change_now/exchange_transaction.dart';
|
|
|
|
import 'package:stackwallet/services/exchange/change_now/change_now_exchange.dart';
|
|
|
|
|
|
|
|
part 'trade.g.dart';
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveType(typeId: Trade.typeId)
|
|
|
|
class Trade {
|
|
|
|
static const typeId = 22;
|
|
|
|
|
|
|
|
@HiveField(0)
|
|
|
|
final String uuid;
|
|
|
|
|
|
|
|
@HiveField(1)
|
|
|
|
final String tradeId;
|
|
|
|
|
|
|
|
@HiveField(2)
|
|
|
|
final String rateType;
|
|
|
|
|
|
|
|
@HiveField(3)
|
|
|
|
final String direction;
|
|
|
|
|
|
|
|
@HiveField(4)
|
|
|
|
final DateTime timestamp;
|
|
|
|
|
|
|
|
@HiveField(5)
|
|
|
|
final DateTime updatedAt;
|
|
|
|
|
|
|
|
@HiveField(6)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payInCurrency;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(7)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payInAmount;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(8)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payInAddress;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(9)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payInNetwork;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(10)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payInExtraId;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(11)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payInTxid;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(12)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payOutCurrency;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(13)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payOutAmount;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(14)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payOutAddress;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(15)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payOutNetwork;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(16)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payOutExtraId;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(17)
|
2022-10-02 20:46:50 +00:00
|
|
|
final String payOutTxid;
|
2022-10-02 19:37:11 +00:00
|
|
|
|
|
|
|
@HiveField(18)
|
|
|
|
final String refundAddress;
|
|
|
|
|
|
|
|
@HiveField(19)
|
|
|
|
final String refundExtraId;
|
|
|
|
|
|
|
|
@HiveField(20)
|
|
|
|
final String status;
|
|
|
|
|
2022-10-03 00:54:35 +00:00
|
|
|
@HiveField(21)
|
|
|
|
final String exchangeName;
|
|
|
|
|
2022-10-02 19:37:11 +00:00
|
|
|
const Trade({
|
|
|
|
required this.uuid,
|
|
|
|
required this.tradeId,
|
|
|
|
required this.rateType,
|
|
|
|
required this.direction,
|
|
|
|
required this.timestamp,
|
|
|
|
required this.updatedAt,
|
2022-10-02 20:46:50 +00:00
|
|
|
required this.payInCurrency,
|
|
|
|
required this.payInAmount,
|
|
|
|
required this.payInAddress,
|
|
|
|
required this.payInNetwork,
|
|
|
|
required this.payInExtraId,
|
|
|
|
required this.payInTxid,
|
|
|
|
required this.payOutCurrency,
|
|
|
|
required this.payOutAmount,
|
|
|
|
required this.payOutAddress,
|
|
|
|
required this.payOutNetwork,
|
|
|
|
required this.payOutExtraId,
|
|
|
|
required this.payOutTxid,
|
2022-10-02 19:37:11 +00:00
|
|
|
required this.refundAddress,
|
|
|
|
required this.refundExtraId,
|
|
|
|
required this.status,
|
2022-10-03 00:54:35 +00:00
|
|
|
required this.exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
Trade copyWith({
|
|
|
|
String? tradeId,
|
|
|
|
String? rateType,
|
|
|
|
String? direction,
|
|
|
|
DateTime? timestamp,
|
|
|
|
DateTime? updatedAt,
|
2022-10-02 20:46:50 +00:00
|
|
|
String? payInCurrency,
|
|
|
|
String? payInAmount,
|
|
|
|
String? payInAddress,
|
|
|
|
String? payInNetwork,
|
|
|
|
String? payInExtraId,
|
|
|
|
String? payInTxid,
|
|
|
|
String? payOutCurrency,
|
|
|
|
String? payOutAmount,
|
|
|
|
String? payOutAddress,
|
|
|
|
String? payOutNetwork,
|
|
|
|
String? payOutExtraId,
|
|
|
|
String? payOutTxid,
|
2022-10-02 19:37:11 +00:00
|
|
|
String? refundAddress,
|
|
|
|
String? refundExtraId,
|
|
|
|
String? status,
|
2022-10-03 00:54:35 +00:00
|
|
|
String? exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
}) {
|
|
|
|
return Trade(
|
2022-10-02 20:46:50 +00:00
|
|
|
uuid: uuid,
|
2022-10-02 19:37:11 +00:00
|
|
|
tradeId: tradeId ?? this.tradeId,
|
|
|
|
rateType: rateType ?? this.rateType,
|
|
|
|
direction: direction ?? this.direction,
|
|
|
|
timestamp: timestamp ?? this.timestamp,
|
|
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
2022-10-02 20:46:50 +00:00
|
|
|
payInCurrency: payInCurrency ?? this.payInCurrency,
|
|
|
|
payInAmount: payInAmount ?? this.payInAmount,
|
|
|
|
payInAddress: payInAddress ?? this.payInAddress,
|
|
|
|
payInNetwork: payInNetwork ?? this.payInNetwork,
|
|
|
|
payInExtraId: payInExtraId ?? this.payInExtraId,
|
|
|
|
payInTxid: payInTxid ?? this.payInTxid,
|
|
|
|
payOutCurrency: payOutCurrency ?? this.payOutCurrency,
|
|
|
|
payOutAmount: payOutAmount ?? this.payOutAmount,
|
|
|
|
payOutAddress: payOutAddress ?? this.payOutAddress,
|
|
|
|
payOutNetwork: payOutNetwork ?? this.payOutNetwork,
|
|
|
|
payOutExtraId: payOutExtraId ?? this.payOutExtraId,
|
|
|
|
payOutTxid: payOutTxid ?? this.payOutTxid,
|
2022-10-02 19:37:11 +00:00
|
|
|
refundAddress: refundAddress ?? this.refundAddress,
|
|
|
|
refundExtraId: refundExtraId ?? this.refundExtraId,
|
|
|
|
status: status ?? this.status,
|
2022-10-03 00:54:35 +00:00
|
|
|
exchangeName: exchangeName ?? this.exchangeName,
|
2022-10-02 19:37:11 +00:00
|
|
|
);
|
|
|
|
}
|
2022-10-02 20:02:10 +00:00
|
|
|
|
2022-10-03 00:54:35 +00:00
|
|
|
Map<String, String> toMap() {
|
2022-10-02 20:02:10 +00:00
|
|
|
return {
|
2022-10-02 20:46:50 +00:00
|
|
|
"uuid": uuid,
|
|
|
|
"tradeId": tradeId,
|
|
|
|
"rateType": rateType,
|
|
|
|
"direction": direction,
|
2022-10-03 00:54:35 +00:00
|
|
|
"timestamp": timestamp.toIso8601String(),
|
|
|
|
"updatedAt": updatedAt.toIso8601String(),
|
2022-10-02 20:46:50 +00:00
|
|
|
"payInCurrency": payInCurrency,
|
|
|
|
"payInAmount": payInAmount,
|
|
|
|
"payInAddress": payInAddress,
|
|
|
|
"payInNetwork": payInNetwork,
|
|
|
|
"payInExtraId": payInExtraId,
|
|
|
|
"payInTxid": payInTxid,
|
|
|
|
"payOutCurrency": payOutCurrency,
|
|
|
|
"payOutAmount": payOutAmount,
|
|
|
|
"payOutAddress": payOutAddress,
|
|
|
|
"payOutNetwork": payOutNetwork,
|
|
|
|
"payOutExtraId": payOutExtraId,
|
|
|
|
"payOutTxid": payOutTxid,
|
|
|
|
"refundAddress": refundAddress,
|
|
|
|
"refundExtraId": refundExtraId,
|
|
|
|
"status": status,
|
2022-10-03 00:54:35 +00:00
|
|
|
"exchangeName": exchangeName,
|
2022-10-02 20:02:10 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-03 00:54:35 +00:00
|
|
|
factory Trade.fromMap(Map<String, dynamic> map) {
|
|
|
|
return Trade(
|
|
|
|
uuid: map["uuid"] as String,
|
|
|
|
tradeId: map["tradeId"] as String,
|
|
|
|
rateType: map["rateType"] as String,
|
|
|
|
direction: map["direction"] as String,
|
|
|
|
timestamp: DateTime.parse(map["timestamp"] as String),
|
|
|
|
updatedAt: DateTime.parse(map["updatedAt"] as String),
|
|
|
|
payInCurrency: map["payInCurrency"] as String,
|
|
|
|
payInAmount: map["payInAmount"] as String,
|
|
|
|
payInAddress: map["payInAddress"] as String,
|
|
|
|
payInNetwork: map["payInNetwork"] as String,
|
|
|
|
payInExtraId: map["payInExtraId"] as String,
|
|
|
|
payInTxid: map["payInTxid"] as String,
|
|
|
|
payOutCurrency: map["payOutCurrency"] as String,
|
|
|
|
payOutAmount: map["payOutAmount"] as String,
|
|
|
|
payOutAddress: map["payOutAddress"] as String,
|
|
|
|
payOutNetwork: map["payOutNetwork"] as String,
|
|
|
|
payOutExtraId: map["payOutExtraId"] as String,
|
|
|
|
payOutTxid: map["payOutTxid"] as String,
|
|
|
|
refundAddress: map["refundAddress"] as String,
|
|
|
|
refundExtraId: map["refundExtraId"] as String,
|
|
|
|
status: map["status"] as String,
|
|
|
|
exchangeName: map["exchangeName"] as String,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-04 00:55:12 +00:00
|
|
|
factory Trade.fromExchangeTransaction(
|
|
|
|
ExchangeTransaction exTx, bool reversed) {
|
2022-10-03 00:54:35 +00:00
|
|
|
return Trade(
|
|
|
|
uuid: exTx.uuid,
|
|
|
|
tradeId: exTx.id,
|
|
|
|
rateType: "",
|
2022-10-04 00:55:12 +00:00
|
|
|
direction: reversed ? "reverse" : "direct",
|
2022-10-03 00:54:35 +00:00
|
|
|
timestamp: exTx.date,
|
|
|
|
updatedAt: DateTime.tryParse(exTx.statusObject!.updatedAt) ?? exTx.date,
|
|
|
|
payInCurrency: exTx.fromCurrency,
|
|
|
|
payInAmount: exTx.statusObject!.amountSendDecimal.isEmpty
|
|
|
|
? exTx.statusObject!.expectedSendAmountDecimal
|
|
|
|
: exTx.statusObject!.amountSendDecimal,
|
|
|
|
payInAddress: exTx.payinAddress,
|
|
|
|
payInNetwork: "",
|
|
|
|
payInExtraId: exTx.payinExtraId,
|
|
|
|
payInTxid: exTx.statusObject!.payinHash,
|
|
|
|
payOutCurrency: exTx.toCurrency,
|
|
|
|
payOutAmount: exTx.amount,
|
|
|
|
payOutAddress: exTx.payoutAddress,
|
|
|
|
payOutNetwork: "",
|
|
|
|
payOutExtraId: exTx.payoutExtraId,
|
|
|
|
payOutTxid: exTx.statusObject!.payoutHash,
|
|
|
|
refundAddress: exTx.refundAddress,
|
|
|
|
refundExtraId: exTx.refundExtraId,
|
|
|
|
status: exTx.statusObject!.status.name,
|
|
|
|
exchangeName: ChangeNowExchange.exchangeName,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-02 20:02:10 +00:00
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return toMap().toString();
|
|
|
|
}
|
2022-10-02 19:37:11 +00:00
|
|
|
}
|