Cw 262 better handle user exchange amount below minimum or maximum trade size (#868)

* CW-262-Better-handle-user-exchange-amount-below-minimum-or-maximum-trade-size

* fix: App should compute conversion even if it's not within the limits
This commit is contained in:
Adegoke David
2023-04-20 03:13:37 +02:00
committed by GitHub
parent efef30f8eb
commit 7b91b0e938
26 changed files with 185 additions and 12 deletions
@@ -198,6 +198,9 @@ abstract class ExchangeViewModelBase with Store {
@observable
bool isFixedRateMode;
@observable
Limits limits;
@computed
SyncStatus get status => wallet.syncStatus;
@@ -241,8 +244,6 @@ abstract class ExchangeViewModelBase with Store {
List<CryptoCurrency> depositCurrencies;
Limits limits;
NumberFormat _cryptoNumberFormat;
final SettingsStore _settingsStore;
@@ -320,6 +321,22 @@ abstract class ExchangeViewModelBase with Store {
.replaceAll(RegExp('\\,'), '');
}
bool checkIfInputMeetsMinOrMaxCondition(String input) {
final _enteredAmount = double.tryParse(input.replaceAll(',', '.')) ?? 0;
double minLimit = limits.min ?? 0;
double? maxLimit = limits.max;
if (_enteredAmount < minLimit) {
return false;
}
if (maxLimit != null && _enteredAmount > maxLimit) {
return false;
}
return true;
}
Future<void> _calculateBestRate() async {
final amount = double.tryParse(isFixedRateMode ? receiveAmount : depositAmount) ?? 1;