CAKE-185 | added validation of amount for xmr.to provider in the exchange_page.dart; added isValidAmount() to exchange_view_model.dart
OleksandrSobol committed
Nov 26, 2020 at 21:04 UTC
4cb4ede2d30f09207a7bda3fef9f350cfedff024
2 files changed
+33
-1
lib/src/screens/exchange/exchange_page.dart
+12
-1
@@ -411,7 +411,18 @@ class ExchangePage extends BasePage {
411
buttonAction: () => Navigator.of(context).pop());
412
});
413
} else {
414
- exchangeViewModel.createTrade();
414
+ exchangeViewModel.isValidAmount()
415
+ ? exchangeViewModel.createTrade()
416
+ : showPopUp<void>(
417
+ context: context,
418
+ builder: (BuildContext context) {
419
+ return AlertWithOneAction(
420
+ alertTitle: 'XMR.TO error',
421
+ alertContent: 'Invalid amount. Maximum limit 8 digits after the decimal point ',
422
+ buttonText: S.of(context).ok,
423
+ buttonAction: () =>
424
+ Navigator.of(context).pop());
425
+ });
426
}
427
}
428
},
lib/view_model/exchange/exchange_view_model.dart
+21
@@ -306,6 +306,27 @@ abstract class ExchangeViewModelBase with Store {
306
void removeTemplate({ExchangeTemplate template}) =>
307
_exchangeTemplateStore.remove(template: template);
308
309
+ bool isValidAmount() {
310
+ bool isValid = true;
311
+
312
+ if (provider is XMRTOExchangeProvider) {
313
+ final amount = isReceiveAmountEntered
314
+ ? receiveAmount
315
+ : depositAmount;
316
+
317
+ final amountParts = amount.replaceAll(',', '.')
318
+ .split('.');
319
+
320
+ final numberOfFractionDigits =
321
+ amountParts.length > 1
322
+ ? amountParts[1].length : 0;
323
+
324
+ isValid = !(numberOfFractionDigits > 8);
325
+ }
326
+
327
+ return isValid;
328
+ }
329
+
330
List<ExchangeProvider> providersForCurrentPair() {
331
return _providersForPair(from: depositCurrency, to: receiveCurrency);
332
}