diff --git a/lib/view_model/exchange/exchange_view_model.dart b/lib/view_model/exchange/exchange_view_model.dart index 3b35aa7ab..03d0ef4db 100644 --- a/lib/view_model/exchange/exchange_view_model.dart +++ b/lib/view_model/exchange/exchange_view_model.dart @@ -1025,6 +1025,39 @@ abstract class ExchangeViewModelBase extends WalletChangeListenerViewModel with @action Future 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) { await calculateDepositAllAmount(); final amount = double.tryParse(_depositAmount);