mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
Validate swap amounts before creating trade (#3296)
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user