Fix static amount value for determining best rate and replace it with the input the user types
OmarHatem committed
Dec 1, 2022 at 22:11 UTC
dd99508d3e3d894987dc2f5d1616f310c1586fb7
1 file changed
+4
-2
lib/view_model/exchange/exchange_view_model.dart
+4
-2
@@ -296,12 +296,14 @@ abstract class ExchangeViewModelBase with Store {
296
}
297
298
Future<void> _calculateBestRate() async {
299
+ final amount = double.tryParse(depositAmount) ?? double.tryParse(receiveAmount) ?? 1;
300
+
301
final result = await Future.wait<double>(
302
_tradeAvailableProviders
303
.map((element) => element.calculateAmount(
304
from: depositCurrency,
305
to: receiveCurrency,
304
- amount: 1,
306
+ amount: amount,
307
isFixedRateMode: isFixedRateMode,
308
isReceiveAmount: false))
309
);
@@ -311,7 +313,7 @@ abstract class ExchangeViewModelBase with Store {
313
for (int i=0;i<result.length;i++) {
314
if (result[i] != 0) {
315
/// add this provider as its valid for this trade
314
- _sortedAvailableProviders[result[i]] = _tradeAvailableProviders[i];
316
+ _sortedAvailableProviders[result[i] / amount] = _tradeAvailableProviders[i];
317
}
318
}
319
if (_sortedAvailableProviders.isNotEmpty) {