From 605f17c8737f528d4d5479eedcd095f743321643 Mon Sep 17 00:00:00 2001 From: Tangem Date: Fri, 9 Aug 2024 19:29:13 +0400 Subject: [PATCH] Updated on 2026-08-14 --- .../tap/common/redux/legacy/LegacyMiddleware.kt | 10 +++++----- .../com/tangem/domain}/utils/BigDecimalUtils.kt | 8 ++++---- domain/tokens/models/build.gradle.kts | 13 +------------ .../tangem/domain/tokens/model/NetworkAddress.kt | 8 -------- .../usecase/CreateApprovalTransactionUseCase.kt | 2 +- .../state/confirm/SendNotificationFactory.kt | 4 ++-- .../impl/presentation/viewmodel/SendViewModel.kt | 4 ++-- .../feature/swap/domain/SwapInteractorImpl.kt | 8 ++++---- 8 files changed, 19 insertions(+), 38 deletions(-) rename domain/{tokens/models/src/main/java/com/tangem/domain/tokens => legacy/src/main/java/com/tangem/domain}/utils/BigDecimalUtils.kt (72%) diff --git a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt index 80d9f694c8..e4bf1086bd 100644 --- a/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt +++ b/app/src/main/java/com/tangem/tap/common/redux/legacy/LegacyMiddleware.kt @@ -3,7 +3,7 @@ package com.tangem.tap.common.redux.legacy import com.tangem.blockchain.common.AmountType import com.tangem.domain.feedback.models.BlockchainErrorInfo import com.tangem.domain.redux.LegacyAction -import com.tangem.domain.tokens.utils.convertToAmount +import com.tangem.domain.utils.convertToSdkAmount import com.tangem.tap.common.extensions.inject import com.tangem.tap.common.extensions.stripZeroPlainString import com.tangem.tap.common.feedback.FeedbackEmail @@ -42,7 +42,7 @@ internal object LegacyMiddleware { is LegacyAction.SendEmailTransactionFailed -> { if (store.inject(DaggerGraphState::feedbackManagerFeatureToggles).isLocalLogsEnabled) { - val amount = action.amount?.convertToAmount(action.cryptoCurrency) + val amount = action.amount?.convertToSdkAmount(action.cryptoCurrency) store.inject(DaggerGraphState::saveBlockchainErrorUseCase).invoke( error = BlockchainErrorInfo( errorMessage = action.errorMessage, @@ -55,7 +55,7 @@ internal object LegacyMiddleware { "" }, amount = amount?.value?.stripZeroPlainString() ?: "unknown", - fee = action.fee?.convertToAmount(action.cryptoCurrency) + fee = action.fee?.convertToSdkAmount(action.cryptoCurrency) ?.value?.stripZeroPlainString() ?: "unknown", ), ) @@ -73,8 +73,8 @@ internal object LegacyMiddleware { )?.let { walletManager -> store.state.globalState.feedbackManager?.infoHolder?.updateOnSendError( walletManager = walletManager, - amountToSend = action.amount?.convertToAmount(action.cryptoCurrency), - feeAmount = action.fee?.convertToAmount(action.cryptoCurrency), + amountToSend = action.amount?.convertToSdkAmount(action.cryptoCurrency), + feeAmount = action.fee?.convertToSdkAmount(action.cryptoCurrency), destinationAddress = action.destinationAddress, ) } diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/utils/BigDecimalUtils.kt b/domain/legacy/src/main/java/com/tangem/domain/utils/BigDecimalUtils.kt similarity index 72% rename from domain/tokens/models/src/main/java/com/tangem/domain/tokens/utils/BigDecimalUtils.kt rename to domain/legacy/src/main/java/com/tangem/domain/utils/BigDecimalUtils.kt index fe93d1d8ec..ad26bc198e 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/utils/BigDecimalUtils.kt +++ b/domain/legacy/src/main/java/com/tangem/domain/utils/BigDecimalUtils.kt @@ -1,13 +1,13 @@ -package com.tangem.domain.tokens.utils +package com.tangem.domain.utils -import com.tangem.blockchain.common.Amount import com.tangem.blockchain.common.AmountType import com.tangem.blockchain.common.Token import com.tangem.domain.tokens.model.CryptoCurrency import java.math.BigDecimal +import com.tangem.blockchain.common.Amount as SdkAmount -/** Converts `BigDecimal` [cryptoCurrency] to [Amount] */ -fun BigDecimal.convertToAmount(cryptoCurrency: CryptoCurrency) = Amount( +/** Converts `BigDecimal` [cryptoCurrency] to [SdkAmount] */ +fun BigDecimal.convertToSdkAmount(cryptoCurrency: CryptoCurrency): SdkAmount = SdkAmount( currencySymbol = cryptoCurrency.symbol, value = this, decimals = cryptoCurrency.decimals, diff --git a/domain/tokens/models/build.gradle.kts b/domain/tokens/models/build.gradle.kts index c51f155acf..92950e7beb 100644 --- a/domain/tokens/models/build.gradle.kts +++ b/domain/tokens/models/build.gradle.kts @@ -1,14 +1,9 @@ plugins { - alias(deps.plugins.android.library) - alias(deps.plugins.kotlin.android) + alias(deps.plugins.kotlin.jvm) alias(deps.plugins.kotlin.serialization) id("configuration") } -android { - namespace = "com.tangem.domain.tokens.model" -} - dependencies { /** Project - Core */ implementation(projects.core.analytics.models) @@ -17,13 +12,7 @@ dependencies { implementation(projects.domain.txhistory.models) implementation(projects.domain.staking.models) - /** SDK dependencies */ - implementation(deps.tangem.blockchain) { - exclude(module = "joda-time") - } - /** Other dependencies */ implementation(deps.kotlin.serialization) implementation(deps.jodatime) - implementation(deps.timber) } \ No newline at end of file diff --git a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/NetworkAddress.kt b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/NetworkAddress.kt index 9b57fcfe15..2e21ba5001 100644 --- a/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/NetworkAddress.kt +++ b/domain/tokens/models/src/main/java/com/tangem/domain/tokens/model/NetworkAddress.kt @@ -1,7 +1,5 @@ package com.tangem.domain.tokens.model -import timber.log.Timber - /** * Represents a network address configuration. */ @@ -47,11 +45,5 @@ sealed class NetworkAddress { enum class Type { Primary, Secondary, } - - init { - if (value.isEmpty()) { - Timber.w("Address value is blank") - } - } } } \ No newline at end of file diff --git a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateApprovalTransactionUseCase.kt b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateApprovalTransactionUseCase.kt index 01cf52d680..c884ee6124 100644 --- a/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateApprovalTransactionUseCase.kt +++ b/domain/transaction/src/main/java/com/tangem/domain/transaction/usecase/CreateApprovalTransactionUseCase.kt @@ -3,8 +3,8 @@ package com.tangem.domain.transaction.usecase import arrow.core.Either import com.tangem.blockchain.common.transaction.Fee import com.tangem.domain.tokens.model.CryptoCurrency -import com.tangem.domain.tokens.utils.convertToAmount import com.tangem.domain.transaction.TransactionRepository +import com.tangem.domain.utils.convertToAmount import com.tangem.domain.wallets.models.UserWalletId import java.math.BigDecimal diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt index 54dd992fa4..ae185f4c0c 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/state/confirm/SendNotificationFactory.kt @@ -20,8 +20,8 @@ import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.model.warnings.CryptoCurrencyWarning import com.tangem.domain.tokens.repository.CurrencyChecksRepository -import com.tangem.domain.tokens.utils.convertToAmount import com.tangem.domain.transaction.usecase.ValidateTransactionUseCase +import com.tangem.domain.utils.convertToSdkAmount import com.tangem.domain.wallets.models.UserWallet import com.tangem.features.send.impl.R import com.tangem.features.send.impl.presentation.analytics.SendAnalyticEvents @@ -447,7 +447,7 @@ internal class SendNotificationFactory( val sendingCurrency = cryptoCurrencyStatusProvider().currency validateTransactionUseCase( - amount = sendingAmount.convertToAmount(sendingCurrency), + amount = sendingAmount.convertToSdkAmount(sendingCurrency), fee = fee ?: return, memo = state.recipientState?.memoTextField?.value, destination = requireNotNull(state.recipientState?.addressTextField?.value), diff --git a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt index 764197090e..4c9d9bfe6a 100644 --- a/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt +++ b/features/send/impl/src/main/java/com/tangem/features/send/impl/presentation/viewmodel/SendViewModel.kt @@ -29,12 +29,12 @@ import com.tangem.domain.tokens.error.CurrencyStatusError import com.tangem.domain.tokens.model.CryptoCurrency import com.tangem.domain.tokens.model.CryptoCurrencyStatus import com.tangem.domain.tokens.repository.CurrencyChecksRepository -import com.tangem.domain.tokens.utils.convertToAmount import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.ValidateAddressError import com.tangem.domain.transaction.usecase.* import com.tangem.domain.txhistory.usecase.GetExplorerTransactionUrlUseCase import com.tangem.domain.txhistory.usecase.GetFixedTxHistoryItemsUseCase +import com.tangem.domain.utils.convertToSdkAmount import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetUserWalletUseCase @@ -855,7 +855,7 @@ internal class SendViewModel @Inject constructor( viewModelScope.launch { createTransactionUseCase( - amount = receivingAmount.convertToAmount(cryptoCurrency), + amount = receivingAmount.convertToSdkAmount(cryptoCurrency), fee = fee, memo = memo, destination = recipient, diff --git a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt index c0d6a4c835..de0468d9ff 100644 --- a/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt +++ b/features/swap/domain/src/main/java/com/tangem/feature/swap/domain/SwapInteractorImpl.kt @@ -22,11 +22,11 @@ import com.tangem.domain.tokens.model.FeePaidCurrency import com.tangem.domain.tokens.repository.CurrenciesRepository import com.tangem.domain.tokens.repository.CurrencyChecksRepository import com.tangem.domain.tokens.repository.QuotesRepository -import com.tangem.domain.tokens.utils.convertToAmount import com.tangem.domain.transaction.error.GetFeeError import com.tangem.domain.transaction.error.SendTransactionError import com.tangem.domain.transaction.models.TransactionType import com.tangem.domain.transaction.usecase.* +import com.tangem.domain.utils.convertToSdkAmount import com.tangem.domain.wallets.models.UserWallet import com.tangem.domain.wallets.models.UserWalletId import com.tangem.domain.wallets.usecase.GetSelectedWalletSyncUseCase @@ -216,7 +216,7 @@ internal class SwapInteractorImpl @Inject constructor( permissionOptions.approveData.approveData } val approveTransaction = createTransactionUseCase( - amount = BigDecimal.ZERO.convertToAmount(permissionOptions.fromToken), + amount = BigDecimal.ZERO.convertToSdkAmount(permissionOptions.fromToken), fee = getFeeForTransaction( fee = permissionOptions.txFee, blockchain = Blockchain.fromId(permissionOptions.fromToken.network.id.value), @@ -518,7 +518,7 @@ internal class SwapInteractorImpl @Inject constructor( ) validateTransactionUseCase( - amount = amount.value.convertToAmount(fromToken), + amount = amount.value.convertToSdkAmount(fromToken), fee = fee, memo = null, destination = getTokenAddress(fromToken), @@ -791,7 +791,7 @@ internal class SwapInteractorImpl @Inject constructor( if (demoConfig.isDemoCardId(cardId)) return SwapTransactionState.UnknownError val txData = createTransactionUseCase( - amount = amount.value.convertToAmount(currencyToSend.currency), + amount = amount.value.convertToSdkAmount(currencyToSend.currency), fee = getFeeForTransaction( fee = txFee, blockchain = Blockchain.fromId(currencyToSend.currency.network.id.value),