Delegate returning rate to each provider to handle its logic internally

This commit is contained in:
OmarHatem 2022-12-07 21:09:15 +02:00
parent 8ff8cf38b8
commit 0da48f66fe
4 changed files with 11 additions and 13 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {