CAKE-185 | added validation of amount for xmr.to provider in the exchange_page.dart; added isValidAmount() to exchange_view_model.dart

This commit is contained in:
OleksandrSobol 2020-11-26 21:04:05 +02:00
parent dd71edd8c8
commit 4cb4ede2d3
2 changed files with 33 additions and 1 deletions

View file

@ -411,7 +411,18 @@ class ExchangePage extends BasePage {
buttonAction: () => Navigator.of(context).pop());
});
} else {
exchangeViewModel.createTrade();
exchangeViewModel.isValidAmount()
? exchangeViewModel.createTrade()
: showPopUp<void>(
context: context,
builder: (BuildContext context) {
return AlertWithOneAction(
alertTitle: 'XMR.TO error',
alertContent: 'Invalid amount. Maximum limit 8 digits after the decimal point ',
buttonText: S.of(context).ok,
buttonAction: () =>
Navigator.of(context).pop());
});
}
}
},

View file

@ -306,6 +306,27 @@ abstract class ExchangeViewModelBase with Store {
void removeTemplate({ExchangeTemplate template}) =>
_exchangeTemplateStore.remove(template: template);
bool isValidAmount() {
bool isValid = true;
if (provider is XMRTOExchangeProvider) {
final amount = isReceiveAmountEntered
? receiveAmount
: depositAmount;
final amountParts = amount.replaceAll(',', '.')
.split('.');
final numberOfFractionDigits =
amountParts.length > 1
? amountParts[1].length : 0;
isValid = !(numberOfFractionDigits > 8);
}
return isValid;
}
List<ExchangeProvider> providersForCurrentPair() {
return _providersForPair(from: depositCurrency, to: receiveCurrency);
}