mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 19:16:09 +00:00
Delegate returning rate to each provider to handle its logic internally
This commit is contained in:
parent
8ff8cf38b8
commit
0da48f66fe
4 changed files with 11 additions and 13 deletions
|
@ -113,8 +113,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
|||
// since we schedule to calculate the rate every 5 seconds we need to ensure that
|
||||
// we have the latest rate id with the given inputs before creating the trade
|
||||
await calculateAmount(
|
||||
from: _request.to,
|
||||
to: _request.from,
|
||||
from: _request.from,
|
||||
to: _request.to,
|
||||
amount: double.tryParse(_request.toAmount) ?? 0,
|
||||
isFixedRateMode: true,
|
||||
isReceiveAmount: true,
|
||||
|
@ -222,10 +222,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
|||
final type = isReverse ? 'reverse' : 'direct';
|
||||
final flow = getFlow(isFixedRateMode);
|
||||
final params = <String, String>{
|
||||
'fromCurrency': isReverse ? normalizeCryptoCurrency(to) : normalizeCryptoCurrency(from),
|
||||
'toCurrency': isReverse ? normalizeCryptoCurrency(from) : normalizeCryptoCurrency(to),
|
||||
'fromNetwork': isReverse ? networkFor(to) : networkFor(from),
|
||||
'toNetwork': isReverse ? networkFor(from) : networkFor(to),
|
||||
'fromCurrency': normalizeCryptoCurrency(from),
|
||||
'toCurrency': normalizeCryptoCurrency(to),
|
||||
'fromNetwork': networkFor(from),
|
||||
'toNetwork': networkFor(to),
|
||||
'type': type,
|
||||
'flow': flow};
|
||||
|
||||
|
@ -246,7 +246,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
|
|||
_lastUsedRateId = rateId;
|
||||
}
|
||||
|
||||
return isReverse ? fromAmount : toAmount;
|
||||
return isReverse ? (amount / fromAmount) : (toAmount / amount);
|
||||
} catch(e) {
|
||||
print(e.toString());
|
||||
return 0.0;
|
||||
|
|
|
@ -79,9 +79,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
|
|||
|
||||
if (amount > max) return 0.00;
|
||||
|
||||
final estimatedAmount = rate * amount;
|
||||
|
||||
return estimatedAmount;
|
||||
return rate;
|
||||
} catch (_) {
|
||||
return 0.00;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
|
|||
|
||||
if (response.body == "null") return 0.00;
|
||||
final data = json.decode(response.body) as String;
|
||||
return double.parse(data);
|
||||
return double.parse(data) / amount;
|
||||
} catch (_) {
|
||||
return 0.00;
|
||||
}
|
||||
|
|
|
@ -316,7 +316,7 @@ abstract class ExchangeViewModelBase with Store {
|
|||
to: receiveCurrency,
|
||||
amount: amount,
|
||||
isFixedRateMode: isFixedRateMode,
|
||||
isReceiveAmount: false))
|
||||
isReceiveAmount: isFixedRateMode))
|
||||
);
|
||||
|
||||
_sortedAvailableProviders.clear();
|
||||
|
@ -324,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] / amount] = _tradeAvailableProviders[i];
|
||||
_sortedAvailableProviders[result[i]] = _tradeAvailableProviders[i];
|
||||
}
|
||||
}
|
||||
if (_sortedAvailableProviders.isNotEmpty) {
|
||||
|
|
Loading…
Reference in a new issue