mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-23 19:16:09 +00:00
CAKE-185 | removed isValidAmount() from exchange_view_model.dart and exchange_page.dart; throw exception in the createTrade() (xmrto_exchange_provider.dart) if number of fractional digits of amount more than 8
This commit is contained in:
parent
27cfad5d95
commit
df01fa0314
3 changed files with 20 additions and 31 deletions
|
@ -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/trade_not_created_exeption.dart';
|
||||||
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
import 'package:cake_wallet/exchange/exchange_provider_description.dart';
|
||||||
import 'package:cake_wallet/exchange/trade_not_found_exeption.dart';
|
import 'package:cake_wallet/exchange/trade_not_found_exeption.dart';
|
||||||
|
import 'package:cake_wallet/generated/i18n.dart';
|
||||||
|
|
||||||
class XMRTOExchangeProvider extends ExchangeProvider {
|
class XMRTOExchangeProvider extends ExchangeProvider {
|
||||||
XMRTOExchangeProvider()
|
XMRTOExchangeProvider()
|
||||||
|
@ -90,12 +91,25 @@ class XMRTOExchangeProvider extends ExchangeProvider {
|
||||||
Future<Trade> createTrade({TradeRequest request}) async {
|
Future<Trade> createTrade({TradeRequest request}) async {
|
||||||
final _request = request as XMRTOTradeRequest;
|
final _request = request as XMRTOTradeRequest;
|
||||||
final url = originalApiUri + _orderCreateUriSuffix;
|
final url = originalApiUri + _orderCreateUriSuffix;
|
||||||
final body = {
|
final _amount = _request.isBTCRequest
|
||||||
'amount':
|
? _request.receiveAmount
|
||||||
_request.isBTCRequest ? _request.receiveAmount : _request.amount,
|
: _request.amount;
|
||||||
'amount_currency': _request.isBTCRequest
|
|
||||||
|
final _amountCurrency = _request.isBTCRequest
|
||||||
? _request.to.toString()
|
? _request.to.toString()
|
||||||
: _request.from.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': _amount,
|
||||||
|
'amount_currency': _amountCurrency,
|
||||||
'btc_dest_address': _request.address
|
'btc_dest_address': _request.address
|
||||||
};
|
};
|
||||||
final response = await post(url,
|
final response = await post(url,
|
||||||
|
|
|
@ -411,18 +411,7 @@ class ExchangePage extends BasePage {
|
||||||
buttonAction: () => Navigator.of(context).pop());
|
buttonAction: () => Navigator.of(context).pop());
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
exchangeViewModel.isValidAmount()
|
exchangeViewModel.createTrade();
|
||||||
? exchangeViewModel.createTrade()
|
|
||||||
: showPopUp<void>(
|
|
||||||
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());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -311,20 +311,6 @@ abstract class ExchangeViewModelBase with Store {
|
||||||
void removeTemplate({ExchangeTemplate template}) =>
|
void removeTemplate({ExchangeTemplate template}) =>
|
||||||
_exchangeTemplateStore.remove(template: 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<ExchangeProvider> providersForCurrentPair() {
|
List<ExchangeProvider> providersForCurrentPair() {
|
||||||
return _providersForPair(from: depositCurrency, to: receiveCurrency);
|
return _providersForPair(from: depositCurrency, to: receiveCurrency);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue