Updated on 2026-08-14
This commit is contained in:
commit
907e239a8a
32 changed files with 152 additions and 96 deletions
|
|
@ -19,6 +19,7 @@ dependencies {
|
|||
kapt(deps.hilt.kapt)
|
||||
|
||||
/** Domain */
|
||||
implementation(projects.domain.appCurrency)
|
||||
implementation(projects.domain.models)
|
||||
implementation(projects.domain.tokens)
|
||||
implementation(projects.domain.tokens.models)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ import com.tangem.blockchain.common.AmountType
|
|||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.common.transaction.Fee
|
||||
import com.tangem.blockchain.common.transaction.TransactionFee
|
||||
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
||||
import com.tangem.domain.appcurrency.extenstions.unwrap
|
||||
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
|
||||
import com.tangem.domain.tokens.GetCryptoCurrencyStatusesSyncUseCase
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
|
|
@ -55,6 +58,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
private val quotesRepository: QuotesRepository,
|
||||
private val dispatcher: CoroutineDispatcherProvider,
|
||||
private val swapTransactionRepository: SwapTransactionRepository,
|
||||
private val appCurrencyRepository: AppCurrencyRepository,
|
||||
private val initialToCurrencyResolver: InitialToCurrencyResolver,
|
||||
) : SwapInteractor {
|
||||
|
||||
|
|
@ -62,6 +66,10 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
EstimateFeeUseCase(walletManagersFacade, dispatcher)
|
||||
}
|
||||
|
||||
private val getSelectedAppCurrencyUseCase by lazy(LazyThreadSafetyMode.NONE) {
|
||||
GetSelectedAppCurrencyUseCase(appCurrencyRepository)
|
||||
}
|
||||
|
||||
private val swapCurrencyConverter = SwapCurrencyConverter()
|
||||
private val amountFormatter = AmountFormatter()
|
||||
private val hundredPercent = BigInteger("100")
|
||||
|
|
@ -638,8 +646,8 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
type = AmountType.Coin,
|
||||
)
|
||||
|
||||
return when (blockchain) {
|
||||
Blockchain.Ethereum -> {
|
||||
return when {
|
||||
blockchain.isEvm() -> {
|
||||
val feeAmountWithDecimals = feeAmountValue.movePointRight(fee.decimals)
|
||||
Fee.Ethereum(
|
||||
amount = feeAmount,
|
||||
|
|
@ -647,11 +655,12 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
gasPrice = (feeAmountWithDecimals / fee.gasLimit.toBigDecimal()).toBigInteger(),
|
||||
)
|
||||
}
|
||||
Blockchain.Vechain -> Fee.Vechain(
|
||||
blockchain == Blockchain.VeChain -> Fee.VeChain(
|
||||
amount = feeAmount,
|
||||
gasPriceCoef = fee.gasLimit,
|
||||
gasPriceCoef = Fee.VeChain.getGasPriceCoef(fee.gasLimit.toLong(), fee.feeValue),
|
||||
gasLimit = fee.gasLimit.toLong(),
|
||||
)
|
||||
Blockchain.Aptos -> {
|
||||
blockchain == Blockchain.Aptos -> {
|
||||
Fee.Aptos(
|
||||
amount = feeAmount,
|
||||
gasUnitPrice = fee.feeValue.toLong() / fee.gasLimit,
|
||||
|
|
@ -754,8 +763,8 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
)
|
||||
}
|
||||
|
||||
private fun createEmptyAmountState(): SwapState {
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
private suspend fun createEmptyAmountState(): SwapState {
|
||||
val appCurrency = getSelectedAppCurrencyUseCase.unwrap()
|
||||
return SwapState.EmptyAmountState(
|
||||
zeroAmountEquivalent = BigDecimal.ZERO.toFiatString(
|
||||
rateValue = BigDecimal.ONE,
|
||||
|
|
@ -947,7 +956,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
}
|
||||
|
||||
private suspend fun getFormattedFiatFees(networkId: String, vararg fees: BigDecimal): List<String> {
|
||||
val appCurrency = userWalletManager.getUserAppCurrency()
|
||||
val appCurrency = getSelectedAppCurrencyUseCase.unwrap()
|
||||
val nativeToken = repository.getNativeTokenForNetwork(networkId)
|
||||
val rates = getQuotes(nativeToken.id)
|
||||
return rates[nativeToken.id]?.fiatRate?.let { rate ->
|
||||
|
|
@ -1345,7 +1354,7 @@ internal class SwapInteractorImpl @Inject constructor(
|
|||
return when (this) {
|
||||
is Fee.Common -> 0
|
||||
is Fee.Ethereum -> gasLimit.toInt()
|
||||
is Fee.Vechain -> gasPriceCoef
|
||||
is Fee.VeChain -> gasLimit.toInt()
|
||||
is Fee.Aptos -> amount.longValue?.div(gasUnitPrice)?.toInt() ?: 0
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.tangem.feature.swap.domain.di
|
||||
|
||||
import com.tangem.domain.appcurrency.repository.AppCurrencyRepository
|
||||
import com.tangem.domain.card.repository.CardSdkConfigRepository
|
||||
import com.tangem.domain.demo.DemoConfig
|
||||
import com.tangem.domain.demo.IsDemoCardUseCase
|
||||
|
|
@ -40,6 +41,7 @@ class SwapDomainModule {
|
|||
@SwapScope sendTransactionUseCase: SendTransactionUseCase,
|
||||
quotesRepository: QuotesRepository,
|
||||
swapTransactionRepository: SwapTransactionRepository,
|
||||
appCurrencyRepository: AppCurrencyRepository,
|
||||
walletManagersFacade: WalletManagersFacade,
|
||||
coroutineDispatcherProvider: CoroutineDispatcherProvider,
|
||||
initialToCurrencyResolver: InitialToCurrencyResolver,
|
||||
|
|
@ -56,6 +58,7 @@ class SwapDomainModule {
|
|||
walletManagersFacade = walletManagersFacade,
|
||||
dispatcher = coroutineDispatcherProvider,
|
||||
swapTransactionRepository = swapTransactionRepository,
|
||||
appCurrencyRepository = appCurrencyRepository,
|
||||
initialToCurrencyResolver = initialToCurrencyResolver,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ internal class TokenDetailsSwapTransactionsStateConverter(
|
|||
val toAmount = transaction.toCryptoAmount
|
||||
val fromAmount = transaction.fromCryptoAmount
|
||||
val toFiatAmount = quotes.firstOrNull {
|
||||
it.rawCurrencyId == swapCurrency.fromCryptoCurrency.id.rawCurrencyId
|
||||
it.rawCurrencyId == swapCurrency.toCryptoCurrency.id.rawCurrencyId
|
||||
}?.fiatRate?.multiply(toAmount)
|
||||
val fromFiatAmount = quotes.firstOrNull {
|
||||
it.rawCurrencyId == swapCurrency.fromCryptoCurrency.id.rawCurrencyId
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ sealed class WalletScreenAnalyticsEvent {
|
|||
|
||||
object BackupYourWallet : MainScreen(event = "Notice - Backup Your Wallet")
|
||||
|
||||
object UnlockAllWithFaceID : MainScreen(event = "Button - Unlock All With Face ID")
|
||||
object UnlockAllWithBiometrics : MainScreen(event = "Button - Unlock All With Biometrics")
|
||||
|
||||
object UnlockWithCardScan : MainScreen(event = "Button - Unlock With Card Scan")
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.domain
|
||||
|
||||
import arrow.core.Either
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.tokens.GetPrimaryCurrencyStatusUpdatesUseCase
|
||||
import com.tangem.domain.tokens.error.CurrencyStatusError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
|
|
@ -38,15 +35,6 @@ internal suspend fun GetPrimaryCurrencyStatusUpdatesUseCase.unwrap(userWalletId:
|
|||
)
|
||||
}
|
||||
|
||||
internal suspend fun GetSelectedAppCurrencyUseCase.unwrap(): AppCurrency {
|
||||
return this()
|
||||
.map { maybeAppCurrency ->
|
||||
maybeAppCurrency.getOrElse { AppCurrency.Default }
|
||||
}
|
||||
.firstOrNull()
|
||||
?: AppCurrency.Default
|
||||
}
|
||||
|
||||
internal suspend fun GetPrimaryCurrencyStatusUpdatesUseCase.collectLatest(
|
||||
userWalletId: UserWalletId,
|
||||
onRight: suspend (CryptoCurrencyStatus) -> Unit,
|
||||
|
|
|
|||
|
|
@ -211,7 +211,7 @@ internal class WalletsUpdateActionResolverV2 @Inject constructor(
|
|||
|
||||
override fun toString(): String {
|
||||
return """
|
||||
Initialize(
|
||||
InitializeWallets(
|
||||
selectedWalletIndex = $selectedWalletIndex,
|
||||
selectedWallet = ${selectedWallet.walletId},
|
||||
wallets = ${wallets.joinToString { it.walletId.toString() }}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import com.tangem.core.ui.components.bottomsheets.tokenreceive.mapToAddressModel
|
|||
import com.tangem.core.ui.extensions.WrappedList
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.domain.appcurrency.GetSelectedAppCurrencyUseCase
|
||||
import com.tangem.domain.appcurrency.extenstions.unwrap
|
||||
import com.tangem.domain.common.util.cardTypesResolver
|
||||
import com.tangem.domain.demo.IsDemoCardUseCase
|
||||
import com.tangem.domain.redux.ReduxStateHolder
|
||||
|
|
|
|||
|
|
@ -231,7 +231,7 @@ internal class WalletWarningsClickIntentsImplementer @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onUnlockWalletClick() {
|
||||
analyticsEventHandler.send(MainScreen.UnlockAllWithFaceID)
|
||||
analyticsEventHandler.send(MainScreen.UnlockAllWithBiometrics)
|
||||
|
||||
viewModelScope.launch(dispatchers.main) {
|
||||
unlockWalletsUseCase(throwIfNotAllWalletsUnlocked = true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue