mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-03 09:29:48 +00:00
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:
commit
707df3717d
2 changed files with 10 additions and 8 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue