diff --git a/lib/exchange/xmrto/xmrto_exchange_provider.dart b/lib/exchange/xmrto/xmrto_exchange_provider.dart index c57529823..26adaedef 100644 --- a/lib/exchange/xmrto/xmrto_exchange_provider.dart +++ b/lib/exchange/xmrto/xmrto_exchange_provider.dart @@ -12,6 +12,7 @@ import 'package:cake_wallet/exchange/xmrto/xmrto_trade_request.dart'; import 'package:cake_wallet/exchange/trade_not_created_exeption.dart'; import 'package:cake_wallet/exchange/exchange_provider_description.dart'; import 'package:cake_wallet/exchange/trade_not_found_exeption.dart'; +import 'package:cake_wallet/generated/i18n.dart'; class XMRTOExchangeProvider extends ExchangeProvider { XMRTOExchangeProvider() @@ -90,12 +91,25 @@ class XMRTOExchangeProvider extends ExchangeProvider { Future createTrade({TradeRequest request}) async { final _request = request as XMRTOTradeRequest; final url = originalApiUri + _orderCreateUriSuffix; + final _amount = _request.isBTCRequest + ? _request.receiveAmount + : _request.amount; + + final _amountCurrency = _request.isBTCRequest + ? _request.to.toString() + : _request.from.toString(); + + final pattern = '^([0-9]+([.\,][0-9]{0,8})?|[.\,][0-9]{1,8})\$'; + final isValid = RegExp(pattern).hasMatch(_amount); + + if (!isValid) { + throw TradeNotCreatedException(description, + description: S.current.xmr_to_error_description); + } + final body = { - 'amount': - _request.isBTCRequest ? _request.receiveAmount : _request.amount, - 'amount_currency': _request.isBTCRequest - ? _request.to.toString() - : _request.from.toString(), + 'amount': _amount, + 'amount_currency': _amountCurrency, 'btc_dest_address': _request.address }; final response = await post(url, diff --git a/lib/src/screens/exchange/exchange_page.dart b/lib/src/screens/exchange/exchange_page.dart index 84581be08..12b8926b5 100644 --- a/lib/src/screens/exchange/exchange_page.dart +++ b/lib/src/screens/exchange/exchange_page.dart @@ -411,18 +411,7 @@ class ExchangePage extends BasePage { buttonAction: () => Navigator.of(context).pop()); }); } else { - exchangeViewModel.isValidAmount() - ? exchangeViewModel.createTrade() - : showPopUp( - context: context, - builder: (BuildContext context) { - return AlertWithOneAction( - alertTitle: S.of(context).xmr_to_error, - alertContent: S.of(context).xmr_to_error_description, - buttonText: S.of(context).ok, - buttonAction: () => - Navigator.of(context).pop()); - }); + exchangeViewModel.createTrade(); } } }, diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 1ea299600..e533e1e93 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -311,20 +311,6 @@ 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 pattern = '^([0-9]+([.\,][0-9]{0,8})?|[.\,][0-9]{1,8})\$'; - isValid = RegExp(pattern).hasMatch(amount); - } - - return isValid; - } - List providersForCurrentPair() { return _providersForPair(from: depositCurrency, to: receiveCurrency); }