Validate swap amounts before creating trade (#3296)

This commit is contained in:
Serhii
2026-06-04 17:45:07 +02:00
committed by GitHub
parent 5099fa3b9c
commit ea4bdc709b
@@ -1025,6 +1025,39 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with
@action @action
Future<void> createTrade() async { Future<void> createTrade() async {
final depositAmountValue =
double.tryParse(_depositAmount.replaceAll(',', '.')) ?? 0.0;
final receiveAmountValue =
double.tryParse(_receiveAmount.replaceAll(',', '.')) ?? 0.0;
if (depositAmountValue <= 0 || receiveAmountValue <= 0) {
ExchangeProviderLogger.logError(
provider: forcedProvider?.description ?? bestRateProvider?.description,
function: 'createTrade',
error: 'Invalid swap amount: deposit=$_depositAmount receive=$_receiveAmount',
requestData: {
'from': depositCurrency.title,
'to': receiveCurrency.title,
'fromAmount': _depositAmount,
'toAmount': _receiveAmount,
'isFixedRateMode': isFixedRateMode,
'forcedProvider': forcedProvider?.title,
'bestRateProvider': bestRateProvider?.title,
},
);
final invalidAmountError = depositAmountValue <= 0
? '$depositAmountValue is not a valid amount for depositAmount'
: '$receiveAmountValue is not a valid amount for receiveAmount';
tradeState = TradeIsCreatedFailure(
title: S.current.trade_not_created,
error: invalidAmountError,
);
return;
}
if (isSendAllEnabled) { if (isSendAllEnabled) {
await calculateDepositAllAmount(); await calculateDepositAllAmount();
final amount = double.tryParse(_depositAmount); final amount = double.tryParse(_depositAmount);