Fix static amount value for determining best rate and replace it with the input the user types

This commit is contained in:
OmarHatem 2022-12-01 22:11:51 +02:00
parent cbe31aa5aa
commit dd99508d3e

View file

@ -296,12 +296,14 @@ abstract class ExchangeViewModelBase with Store {
} }
Future<void> _calculateBestRate() async { Future<void> _calculateBestRate() async {
final amount = double.tryParse(depositAmount) ?? double.tryParse(receiveAmount) ?? 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))
); );
@ -311,7 +313,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) {