Delegate returning rate to each provider to handle its logic internally
OmarHatem committed
Dec 7, 2022 at 21:09 UTC
0da48f66fef74b94270ef77767c64182dbb4f08e
4 files changed
+11
-13
lib/exchange/changenow/changenow_exchange_provider.dart
+7
-7
@@ -113,8 +113,8 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
113
// since we schedule to calculate the rate every 5 seconds we need to ensure that
114
// we have the latest rate id with the given inputs before creating the trade
115
await calculateAmount(
116
- from: _request.to,
117
- to: _request.from,
116
+ from: _request.from,
117
+ to: _request.to,
118
amount: double.tryParse(_request.toAmount) ?? 0,
119
isFixedRateMode: true,
120
isReceiveAmount: true,
@@ -222,10 +222,10 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
222
final type = isReverse ? 'reverse' : 'direct';
223
final flow = getFlow(isFixedRateMode);
224
final params = <String, String>{
225
- 'fromCurrency': isReverse ? normalizeCryptoCurrency(to) : normalizeCryptoCurrency(from),
226
- 'toCurrency': isReverse ? normalizeCryptoCurrency(from) : normalizeCryptoCurrency(to),
227
- 'fromNetwork': isReverse ? networkFor(to) : networkFor(from),
228
- 'toNetwork': isReverse ? networkFor(from) : networkFor(to),
225
+ 'fromCurrency': normalizeCryptoCurrency(from),
226
+ 'toCurrency': normalizeCryptoCurrency(to),
227
+ 'fromNetwork': networkFor(from),
228
+ 'toNetwork': networkFor(to),
229
'type': type,
230
'flow': flow};
231
@@ -246,7 +246,7 @@ class ChangeNowExchangeProvider extends ExchangeProvider {
246
_lastUsedRateId = rateId;
247
}
248
249
- return isReverse ? fromAmount : toAmount;
249
+ return isReverse ? (amount / fromAmount) : (toAmount / amount);
250
} catch(e) {
251
print(e.toString());
252
return 0.0;
lib/exchange/sideshift/sideshift_exchange_provider.dart
+1
-3
@@ -79,9 +79,7 @@ class SideShiftExchangeProvider extends ExchangeProvider {
79
80
if (amount > max) return 0.00;
81
82
- final estimatedAmount = rate * amount;
83
-
84
- return estimatedAmount;
82
+ return rate;
83
} catch (_) {
84
return 0.00;
85
}
lib/exchange/simpleswap/simpleswap_exchange_provider.dart
+1
-1
@@ -60,7 +60,7 @@ class SimpleSwapExchangeProvider extends ExchangeProvider {
60
61
if (response.body == "null") return 0.00;
62
final data = json.decode(response.body) as String;
63
- return double.parse(data);
63
+ return double.parse(data) / amount;
64
} catch (_) {
65
return 0.00;
66
}
lib/view_model/exchange/exchange_view_model.dart
+2
-2
@@ -316,7 +316,7 @@ abstract class ExchangeViewModelBase with Store {
316
to: receiveCurrency,
317
amount: amount,
318
isFixedRateMode: isFixedRateMode,
319
- isReceiveAmount: false))
319
+ isReceiveAmount: isFixedRateMode))
320
);
321
322
_sortedAvailableProviders.clear();
@@ -324,7 +324,7 @@ abstract class ExchangeViewModelBase with Store {
324
for (int i=0;i<result.length;i++) {
325
if (result[i] != 0) {
326
/// add this provider as its valid for this trade
327
- _sortedAvailableProviders[result[i] / amount] = _tradeAvailableProviders[i];
327
+ _sortedAvailableProviders[result[i]] = _tradeAvailableProviders[i];
328
}
329
}
330
if (_sortedAvailableProviders.isNotEmpty) {