Merge pull request #662 from cake-tech/CW-259-fix-change-now-trade

[CW-259] Fix Change now trade issue
This commit is contained in:
Omar Hatem 2022-12-03 23:49:45 +02:00 committed by GitHub
commit 707df3717d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -130,7 +130,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
final id = responseJSON['id'] as String;
final inputAddress = responseJSON['payinAddress'] as String;
final refundAddress = responseJSON['refundAddress'] as String;
final extraId = responseJSON['payinExtraId'] as String;
final extraId = responseJSON['payinExtraId'] as String?;
return Trade(
id: id,

View file

@ -307,12 +307,14 @@ abstract class ExchangeViewModelBase with Store {
}
Future<void> _calculateBestRate() async {
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1;
final result = await Future.wait<double>(
_tradeAvailableProviders
.map((element) => element.calculateAmount(
from: depositCurrency,
to: receiveCurrency,
amount: 1,
amount: amount,
isFixedRateMode: isFixedRateMode,
isReceiveAmount: false))
);
@ -322,7 +324,7 @@ abstract class ExchangeViewModelBase with Store {
for (int i=0;i<result.length;i++) {
if (result[i] != 0) {
/// add this provider as its valid for this trade
_sortedAvailableProviders[result[i]] = _tradeAvailableProviders[i];
_sortedAvailableProviders[result[i] / amount] = _tradeAvailableProviders[i];
}
}
if (_sortedAvailableProviders.isNotEmpty) {
@ -345,7 +347,7 @@ abstract class ExchangeViewModelBase with Store {
? depositCurrency
: receiveCurrency;
double lowestMin = double.maxFinite;
double? lowestMin = double.maxFinite;
double? highestMax = 0.0;
for (var provider in selectedProviders) {
@ -360,8 +362,8 @@ abstract class ExchangeViewModelBase with Store {
to: to,
isFixedRateMode: isFixedRateMode);
if (tempLimits.min != null && tempLimits.min! < lowestMin) {
lowestMin = tempLimits.min!;
if (lowestMin != null && (tempLimits.min ?? -1) < lowestMin) {
lowestMin = tempLimits.min;
}
if (highestMax != null && (tempLimits.max ?? double.maxFinite) > highestMax) {
highestMax = tempLimits.max;
@ -371,7 +373,7 @@ abstract class ExchangeViewModelBase with Store {
}
}
if (lowestMin < double.maxFinite) {
if (lowestMin != double.maxFinite) {
limits = Limits(min: lowestMin, max: highestMax);
limitsState = LimitsLoadedSuccessfully(limits: limits);