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
|
@ -114,7 +114,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
||||||
|
|
||||||
final uri = Uri.https(apiAuthority, createTradePath);
|
final uri = Uri.https(apiAuthority, createTradePath);
|
||||||
final response = await post(uri, headers: headers, body: json.encode(body));
|
final response = await post(uri, headers: headers, body: json.encode(body));
|
||||||
|
|
||||||
if (response.statusCode == 400) {
|
if (response.statusCode == 400) {
|
||||||
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
final responseJSON = json.decode(response.body) as Map<String, dynamic>;
|
||||||
final error = responseJSON['error'] as String;
|
final error = responseJSON['error'] as String;
|
||||||
|
@ -130,7 +130,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
||||||
final id = responseJSON['id'] as String;
|
final id = responseJSON['id'] as String;
|
||||||
final inputAddress = responseJSON['payinAddress'] as String;
|
final inputAddress = responseJSON['payinAddress'] as String;
|
||||||
final refundAddress = responseJSON['refundAddress'] as String;
|
final refundAddress = responseJSON['refundAddress'] as String;
|
||||||
final extraId = responseJSON['payinExtraId'] as String;
|
final extraId = responseJSON['payinExtraId'] as String?;
|
||||||
|
|
||||||
return Trade(
|
return Trade(
|
||||||
id: id,
|
id: id,
|
||||||
|
|
|
@ -307,12 +307,14 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _calculateBestRate() async {
|
Future<void> _calculateBestRate() async {
|
||||||
|
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1;
|
||||||
|
|
||||||
final result = await Future.wait<double>(
|
final result = await Future.wait<double>(
|
||||||
_tradeAvailableProviders
|
_tradeAvailableProviders
|
||||||
.map((element) => element.calculateAmount(
|
.map((element) => element.calculateAmount(
|
||||||
from: depositCurrency,
|
from: depositCurrency,
|
||||||
to: receiveCurrency,
|
to: receiveCurrency,
|
||||||
amount: 1,
|
amount: amount,
|
||||||
isFixedRateMode: isFixedRateMode,
|
isFixedRateMode: isFixedRateMode,
|
||||||
isReceiveAmount: false))
|
isReceiveAmount: false))
|
||||||
);
|
);
|
||||||
|
@ -322,7 +324,7 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
for (int i=0;i<result.length;i++) {
|
for (int i=0;i<result.length;i++) {
|
||||||
if (result[i] != 0) {
|
if (result[i] != 0) {
|
||||||
/// add this provider as its valid for this trade
|
/// add this provider as its valid for this trade
|
||||||
_sortedAvailableProviders[result[i]] = _tradeAvailableProviders[i];
|
_sortedAvailableProviders[result[i] / amount] = _tradeAvailableProviders[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_sortedAvailableProviders.isNotEmpty) {
|
if (_sortedAvailableProviders.isNotEmpty) {
|
||||||
|
@ -345,7 +347,7 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
? depositCurrency
|
? depositCurrency
|
||||||
: receiveCurrency;
|
: receiveCurrency;
|
||||||
|
|
||||||
double lowestMin = double.maxFinite;
|
double? lowestMin = double.maxFinite;
|
||||||
double? highestMax = 0.0;
|
double? highestMax = 0.0;
|
||||||
|
|
||||||
for (var provider in selectedProviders) {
|
for (var provider in selectedProviders) {
|
||||||
|
@ -360,8 +362,8 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
to: to,
|
to: to,
|
||||||
isFixedRateMode: isFixedRateMode);
|
isFixedRateMode: isFixedRateMode);
|
||||||
|
|
||||||
if (tempLimits.min != null && tempLimits.min! < lowestMin) {
|
if (lowestMin != null && (tempLimits.min ?? -1) < lowestMin) {
|
||||||
lowestMin = tempLimits.min!;
|
lowestMin = tempLimits.min;
|
||||||
}
|
}
|
||||||
if (highestMax != null && (tempLimits.max ?? double.maxFinite) > highestMax) {
|
if (highestMax != null && (tempLimits.max ?? double.maxFinite) > highestMax) {
|
||||||
highestMax = tempLimits.max;
|
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);
|
limits = Limits(min: lowestMin, max: highestMax);
|
||||||
|
|
||||||
limitsState = LimitsLoadedSuccessfully(limits: limits);
|
limitsState = LimitsLoadedSuccessfully(limits: limits);
|
||||||
|
|
Loading…
Reference in a new issue