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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-08-26 08:11:35 +00:00
|
|
|
import 'package:decimal/decimal.dart';
|
2024-05-27 23:56:22 +00:00
|
|
|
|
2024-05-23 00:37:06 +00:00
|
|
|
import '../../../utilities/logger.dart';
|
2022-08-26 08:11:35 +00:00
|
|
|
|
|
|
|
class EstimatedExchangeAmount {
|
|
|
|
/// Estimated exchange amount
|
|
|
|
final Decimal estimatedAmount;
|
|
|
|
|
|
|
|
/// Dash-separated min and max estimated time in minutes
|
|
|
|
final String transactionSpeedForecast;
|
|
|
|
|
|
|
|
/// Some warnings like warnings that transactions on this network
|
|
|
|
/// take longer or that the currency has moved to another network
|
|
|
|
final String? warningMessage;
|
|
|
|
|
|
|
|
/// (Optional) Use rateId for fixed-rate flow. If this field is true, you
|
|
|
|
/// could use returned field "rateId" in next method for creating transaction
|
|
|
|
/// to freeze estimated amount that you got in this method. Current estimated
|
|
|
|
/// amount would be valid until time in field "validUntil"
|
|
|
|
final String? rateId;
|
|
|
|
|
|
|
|
/// ONLY for fixed rate.
|
|
|
|
/// Network fee for transferring funds between wallets, it should be deducted
|
|
|
|
/// from the result. Formula for calculating the estimated amount is given below
|
|
|
|
/// estimatedAmount = (rate * amount) - networkFee
|
|
|
|
final Decimal? networkFee;
|
|
|
|
|
|
|
|
EstimatedExchangeAmount({
|
|
|
|
required this.estimatedAmount,
|
|
|
|
required this.transactionSpeedForecast,
|
|
|
|
required this.warningMessage,
|
|
|
|
required this.rateId,
|
|
|
|
this.networkFee,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory EstimatedExchangeAmount.fromJson(Map<String, dynamic> json) {
|
|
|
|
try {
|
|
|
|
return EstimatedExchangeAmount(
|
2024-05-27 23:56:22 +00:00
|
|
|
estimatedAmount: Decimal.parse(
|
|
|
|
json["estimatedAmount"]?.toString() ??
|
|
|
|
json["estimatedDeposit"].toString(),
|
|
|
|
),
|
2022-10-04 00:01:04 +00:00
|
|
|
transactionSpeedForecast:
|
|
|
|
json["transactionSpeedForecast"] as String? ?? "",
|
2022-08-26 08:11:35 +00:00
|
|
|
warningMessage: json["warningMessage"] as String?,
|
|
|
|
rateId: json["rateId"] as String?,
|
|
|
|
networkFee: Decimal.tryParse(json["networkFee"].toString()),
|
|
|
|
);
|
|
|
|
} catch (e, s) {
|
|
|
|
Logging.instance
|
|
|
|
.log("Failed to parse: $json \n$e\n$s", level: LogLevel.Fatal);
|
|
|
|
rethrow;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Map<String, dynamic> toJson() {
|
|
|
|
return {
|
|
|
|
"estimatedAmount": estimatedAmount,
|
|
|
|
"transactionSpeedForecast": transactionSpeedForecast,
|
|
|
|
"warningMessage": warningMessage,
|
|
|
|
"rateId": rateId,
|
|
|
|
"networkFee": networkFee,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
EstimatedExchangeAmount copyWith({
|
|
|
|
Decimal? estimatedAmount,
|
|
|
|
String? transactionSpeedForecast,
|
|
|
|
String? warningMessage,
|
|
|
|
String? rateId,
|
|
|
|
Decimal? networkFee,
|
|
|
|
}) {
|
|
|
|
return EstimatedExchangeAmount(
|
|
|
|
estimatedAmount: estimatedAmount ?? this.estimatedAmount,
|
|
|
|
transactionSpeedForecast:
|
|
|
|
transactionSpeedForecast ?? this.transactionSpeedForecast,
|
|
|
|
warningMessage: warningMessage ?? this.warningMessage,
|
|
|
|
rateId: rateId ?? this.rateId,
|
|
|
|
networkFee: networkFee ?? this.networkFee,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String toString() {
|
|
|
|
return "EstimatedExchangeAmount: ${toJson()}";
|
|
|
|
}
|
|
|
|
}
|