From 6062a629d700261c4580e8b1989fcd0710bc730f Mon Sep 17 00:00:00 2001 From: ERussel Date: Tue, 2 Apr 2024 16:25:29 +0200 Subject: [PATCH] don't allow going below ed for crosschain transfers --- .../CrossChain/CrossChainTransferPresenter.swift | 2 +- .../Validation/TransferDataValidatorFactory.swift | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/novawallet/Modules/Transfer/BaseTransfer/CrossChain/CrossChainTransferPresenter.swift b/novawallet/Modules/Transfer/BaseTransfer/CrossChain/CrossChainTransferPresenter.swift index 3a6eeae04c..24e378ca24 100644 --- a/novawallet/Modules/Transfer/BaseTransfer/CrossChain/CrossChainTransferPresenter.swift +++ b/novawallet/Modules/Transfer/BaseTransfer/CrossChain/CrossChainTransferPresenter.swift @@ -183,7 +183,7 @@ class CrossChainTransferPresenter { locale: selectedLocale ), - dataValidatingFactory.notViolatingMinBalanceBeforePayingDeliveryFee( + dataValidatingFactory.notViolatingMinBalanceWhenDeliveryFeeEnabled( for: .init( amount: isOriginUtilityTransfer ? sendingAmount : 0, originNetworkFee: networkFee?.amountForCurrentAccount, diff --git a/novawallet/Modules/Transfer/Validation/TransferDataValidatorFactory.swift b/novawallet/Modules/Transfer/Validation/TransferDataValidatorFactory.swift index e934f17c1e..b4c0536934 100644 --- a/novawallet/Modules/Transfer/Validation/TransferDataValidatorFactory.swift +++ b/novawallet/Modules/Transfer/Validation/TransferDataValidatorFactory.swift @@ -67,7 +67,7 @@ protocol TransferDataValidatorFactoryProtocol: BaseDataValidatingFactoryProtocol locale: Locale ) -> DataValidating - func notViolatingMinBalanceBeforePayingDeliveryFee( + func notViolatingMinBalanceWhenDeliveryFeeEnabled( for params: CrossChainValidationAtLeastEdForDeliveryFee, locale: Locale ) -> DataValidating @@ -289,13 +289,15 @@ final class TransferDataValidatorFactory: TransferDataValidatorFactoryProtocol { }) } - func notViolatingMinBalanceBeforePayingDeliveryFee( + func notViolatingMinBalanceWhenDeliveryFeeEnabled( for params: CrossChainValidationAtLeastEdForDeliveryFee, locale: Locale ) -> DataValidating { let assetInfo = utilityAssetInfo let networkFeeAmountInPlank = params.originNetworkFee ?? 0 let networkFeeDecimal = networkFeeAmountInPlank.decimal(assetInfo: assetInfo) + let deliveryFeeInPlank = params.originDeliveryFee ?? 0 + let deliveryFeeDecimal = deliveryFeeInPlank.decimal(assetInfo: assetInfo) let balanceDecimal = params.totalBalance?.decimal(assetInfo: assetInfo) ?? 0 let minBalanceDecimal = params.minBalance?.decimal(assetInfo: assetInfo) ?? 0 let crosschainHoldingDecimal = params.crosschainHolding?.decimal(assetInfo: assetInfo) ?? 0 @@ -308,7 +310,7 @@ final class TransferDataValidatorFactory: TransferDataValidatorFactoryProtocol { let tokenFormatter = AssetBalanceFormatterFactory().createTokenFormatter(for: assetInfo) - let feeAndEd = networkFeeDecimal + minBalanceDecimal + crosschainHoldingDecimal + let feeAndEd = networkFeeDecimal + deliveryFeeDecimal + minBalanceDecimal + crosschainHoldingDecimal let availableDecimal = balanceDecimal >= feeAndEd ? balanceDecimal - feeAndEd : 0 let availableString = tokenFormatter.value(for: locale).stringFromDecimal(availableDecimal) ?? "" @@ -324,7 +326,7 @@ final class TransferDataValidatorFactory: TransferDataValidatorFactoryProtocol { return true } - return networkFeeDecimal + sendingDecimal + minBalanceDecimal <= balanceDecimal + return networkFeeDecimal + deliveryFeeDecimal + sendingDecimal + minBalanceDecimal <= balanceDecimal }) }