Updated on 2026-08-14
This commit is contained in:
parent
8e433e111e
commit
17c591db4e
19 changed files with 180 additions and 81 deletions
|
|
@ -9,6 +9,8 @@ import com.tangem.datasource.api.tangemTech.models.account.WalletAccountDTO
|
|||
import com.tangem.domain.account.models.AccountList
|
||||
import com.tangem.domain.common.wallets.UserWalletsListRepository
|
||||
import com.tangem.domain.models.account.Account
|
||||
import com.tangem.domain.models.account.AccountId
|
||||
import com.tangem.domain.models.account.DerivationIndex
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import javax.inject.Inject
|
||||
|
|
@ -63,6 +65,9 @@ internal class DefaultWalletAccountsResponseFactory @Inject constructor(
|
|||
currencies = userWallet?.let(cardCryptoCurrencyFactory::createDefaultCoinsForMultiCurrencyWallet).orEmpty(),
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
accountId = userWallet?.let {
|
||||
AccountId.forCryptoPortfolio(userWalletId = it.walletId, derivationIndex = DerivationIndex.Main)
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +104,9 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
every { walletId } returns userWalletId
|
||||
}
|
||||
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
|
||||
val defaultCoins = listOf(mockk<CryptoCurrency.Coin>())
|
||||
coEvery { userWalletsListRepository.userWalletsSync() } returns listOf(userWallet)
|
||||
every { cardCryptoCurrencyFactory.createDefaultCoinsForMultiCurrencyWallet(userWallet) } returns defaultCoins
|
||||
|
|
@ -119,12 +122,10 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
currencies = defaultCoins,
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
accountId = accounts.first().accountId,
|
||||
)
|
||||
} returns defaultResponse
|
||||
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
|
||||
val accountsDTO = createWalletAccountDTO(userWalletId)
|
||||
every { cryptoPortfolioConverter.convertListBack(accounts) } returns listOf(accountsDTO)
|
||||
|
||||
|
|
@ -152,6 +153,7 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
currencies = defaultCoins,
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
accountId = accounts.first().accountId,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -162,6 +164,10 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
val userWallet = mockk<UserWallet>(relaxed = true) {
|
||||
every { walletId } returns userWalletId
|
||||
}
|
||||
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
|
||||
coEvery { userWalletsListRepository.userWalletsSync() } returns listOf(userWallet)
|
||||
every { cardCryptoCurrencyFactory.createDefaultCoinsForMultiCurrencyWallet(userWallet) } returns emptyList()
|
||||
val defaultResponse = UserTokensResponse(
|
||||
|
|
@ -174,10 +180,10 @@ class DefaultWalletAccountsResponseFactoryTest {
|
|||
currencies = emptyList(),
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
accountId = accounts.first().accountId,
|
||||
)
|
||||
} returns defaultResponse
|
||||
val accounts = AccountList.empty(userWallet.walletId).accounts
|
||||
.filterIsInstance<Account.CryptoPortfolio>()
|
||||
|
||||
every { cryptoPortfolioConverter.convertListBack(accounts) } returns emptyList()
|
||||
|
||||
// Act
|
||||
|
|
|
|||
|
|
@ -238,7 +238,7 @@ internal class DefaultCustomTokensRepository(
|
|||
"User tokens not found for user wallet [$userWalletId] while removing currency"
|
||||
}
|
||||
|
||||
val token = userTokensResponseFactory.createResponseToken(cryptoCurrency)
|
||||
val token = userTokensResponseFactory.createResponseToken(currency = cryptoCurrency, accountId = null)
|
||||
userTokensSaver.storeAndPush(
|
||||
userWalletId = userWalletId,
|
||||
response = storedCurrencies.copy(tokens = storedCurrencies.tokens.filterNot { it == token }),
|
||||
|
|
@ -249,6 +249,27 @@ internal class DefaultCustomTokensRepository(
|
|||
}
|
||||
}
|
||||
|
||||
override suspend fun convertToCryptoCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
currency: ManagedCryptoCurrency.Custom,
|
||||
): CryptoCurrency {
|
||||
return when (currency) {
|
||||
is ManagedCryptoCurrency.Custom.Coin -> createCoin(
|
||||
userWalletId = userWalletId,
|
||||
networkId = currency.network.id,
|
||||
derivationPath = currency.network.derivationPath,
|
||||
)
|
||||
is ManagedCryptoCurrency.Custom.Token -> cryptoCurrencyFactory.createToken(
|
||||
network = currency.network,
|
||||
rawId = currency.currencyId.rawCurrencyId,
|
||||
name = currency.name,
|
||||
symbol = currency.symbol,
|
||||
decimals = currency.decimals,
|
||||
contractAddress = currency.contractAddress,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getSupportedNetworks(userWalletId: UserWalletId): List<Network> = withContext(dispatchers.io) {
|
||||
val userWallet = requireNotNull(userWalletsStore.getSyncOrNull(userWalletId)) {
|
||||
"User wallet [$userWalletId] not found while getting supported networks"
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ internal class DefaultMultiWalletCryptoCurrenciesFetcher(
|
|||
currencies = cardCryptoCurrencyFactory.createDefaultCoinsForMultiCurrencyWallet(userWallet),
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
accountId = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -74,26 +74,6 @@ internal class DefaultCurrenciesRepository(
|
|||
userTokensSaver.storeAndPush(userWalletId, response)
|
||||
}
|
||||
|
||||
override suspend fun saveCurrenciesLocal(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) {
|
||||
withContext(dispatchers.io) {
|
||||
val savedResponse = requireNotNull(
|
||||
value = getSavedUserTokensResponseSync(key = userWalletId),
|
||||
lazyMessage = { "Saved tokens empty. Can not perform add currencies action." },
|
||||
)
|
||||
|
||||
val updatedResponse = savedResponse.copy(
|
||||
tokens = currencies.map(userTokensResponseFactory::createResponseToken),
|
||||
)
|
||||
|
||||
userTokensSaver.store(userWalletId = userWalletId, response = updatedResponse)
|
||||
|
||||
fetchExpressAssetsByNetworkIds(
|
||||
userWallet = userWalletsStore.getSyncStrict(key = userWalletId),
|
||||
userTokens = updatedResponse,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun addCurrenciesCache(
|
||||
userWalletId: UserWalletId,
|
||||
currencies: List<CryptoCurrency>,
|
||||
|
|
@ -667,6 +647,7 @@ internal class DefaultCurrenciesRepository(
|
|||
return demoConfig.isDemoCardId(userWallet.cardId) && response == null
|
||||
}
|
||||
|
||||
// TODO [REDACTED_JIRA]
|
||||
private suspend fun fetchExpressAssetsByNetworkIds(userWallet: UserWallet, userTokens: UserTokensResponse) {
|
||||
val tokens = userTokens.tokens.map { token ->
|
||||
LeastTokenInfo(
|
||||
|
|
@ -731,6 +712,7 @@ internal class DefaultCurrenciesRepository(
|
|||
),
|
||||
isGroupedByNetwork = false,
|
||||
isSortedByBalance = false,
|
||||
accountId = null,
|
||||
)
|
||||
|
||||
private fun ensureIsCorrectUserWallet(userWalletId: UserWalletId, isMultiCurrencyWalletExpected: Boolean) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
|
|||
import com.tangem.domain.managetokens.repository.CustomTokensRepository
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
class RemoveCustomManagedCryptoCurrencyUseCase(private val repository: CustomTokensRepository) {
|
||||
|
||||
suspend operator fun invoke(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
|
|||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.derivations.DerivationsRepository
|
||||
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
@Suppress("LongParameterList")
|
||||
class SaveManagedTokensUseCase(
|
||||
private val customTokensRepository: CustomTokensRepository,
|
||||
|
|
|
|||
|
|
@ -43,8 +43,14 @@ interface CustomTokensRepository {
|
|||
formValues: AddCustomTokenForm.Validated.All,
|
||||
): CryptoCurrency.Token
|
||||
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
suspend fun removeCurrency(userWalletId: UserWalletId, currency: ManagedCryptoCurrency.Custom)
|
||||
|
||||
suspend fun convertToCryptoCurrency(
|
||||
userWalletId: UserWalletId,
|
||||
currency: ManagedCryptoCurrency.Custom,
|
||||
): CryptoCurrency
|
||||
|
||||
suspend fun getSupportedNetworks(userWalletId: UserWalletId): List<Network>
|
||||
|
||||
fun createDerivationPath(rawPath: String): Network.DerivationPath
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.tangem.domain.markets
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.wallets.derivations.DerivationsRepository
|
||||
import com.tangem.domain.markets.repositories.MarketsTokenRepository
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
|
|
@ -11,6 +10,7 @@ import com.tangem.domain.quotes.multi.MultiQuoteStatusFetcher
|
|||
import com.tangem.domain.staking.StakingIdFactory
|
||||
import com.tangem.domain.staking.multi.MultiYieldBalanceFetcher
|
||||
import com.tangem.domain.tokens.repository.CurrenciesRepository
|
||||
import com.tangem.domain.wallets.derivations.DerivationsRepository
|
||||
|
||||
/**
|
||||
* Use case for saving tokens from Markets
|
||||
|
|
@ -21,6 +21,7 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
|
|||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
@Suppress("LongParameterList")
|
||||
class SaveMarketTokensUseCase(
|
||||
private val derivationsRepository: DerivationsRepository,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import kotlinx.coroutines.coroutineScope
|
|||
* This use case interacts with the underlying repositories to both add currencies and refresh
|
||||
* network statuses, particularly after the addition of new tokens.
|
||||
*/
|
||||
// TODO: Add tests
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
@Suppress("LongParameterList")
|
||||
class AddCryptoCurrenciesUseCase(
|
||||
private val currenciesRepository: CurrenciesRepository,
|
||||
|
|
|
|||
|
|
@ -34,14 +34,6 @@ interface CurrenciesRepository {
|
|||
isSortedByBalance: Boolean,
|
||||
)
|
||||
|
||||
/**
|
||||
* Saves the given list of cryptocurrencies for a specific multi-currency user wallet.
|
||||
*
|
||||
* @param userWalletId The unique identifier of the user wallet.
|
||||
* @param currencies The list of cryptocurrencies to be saved.
|
||||
*/
|
||||
suspend fun saveCurrenciesLocal(userWalletId: UserWalletId, currencies: List<CryptoCurrency>)
|
||||
|
||||
/**
|
||||
* Add currencies to a specific user wallet.
|
||||
*
|
||||
|
|
@ -50,7 +42,7 @@ interface CurrenciesRepository {
|
|||
* @throws DataError.UserWalletError.WrongUserWallet If single-currency user wallet
|
||||
* ID provided.
|
||||
*/
|
||||
@Deprecated("Tech debt")
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
suspend fun addCurrenciesCache(userWalletId: UserWalletId, currencies: List<CryptoCurrency>): List<CryptoCurrency>
|
||||
|
||||
/**
|
||||
|
|
@ -61,6 +53,7 @@ interface CurrenciesRepository {
|
|||
* @throws DataError.UserWalletError.WrongUserWallet If multi-currency user wallet
|
||||
* ID provided.
|
||||
*/
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
suspend fun removeCurrency(userWalletId: UserWalletId, currency: CryptoCurrency)
|
||||
|
||||
/**
|
||||
|
|
@ -71,6 +64,7 @@ interface CurrenciesRepository {
|
|||
* @throws DataError.UserWalletError.WrongUserWallet If single-currency user wallet
|
||||
* ID provided.
|
||||
*/
|
||||
@Deprecated("Use SaveCryptoCurrenciesUseCase")
|
||||
suspend fun removeCurrencies(userWalletId: UserWalletId, currencies: List<CryptoCurrency>)
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -46,8 +46,6 @@ internal class MockCurrenciesRepository(
|
|||
isTokensSortedByBalanceAfterSortingApply = isSortedByBalance
|
||||
}
|
||||
|
||||
override suspend fun saveCurrenciesLocal(userWalletId: UserWalletId, currencies: List<CryptoCurrency>) = Unit
|
||||
|
||||
override suspend fun addCurrenciesCache(
|
||||
userWalletId: UserWalletId,
|
||||
currencies: List<CryptoCurrency>,
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package com.tangem.features.managetokens.utils.list
|
|||
|
||||
import arrow.core.Either
|
||||
import arrow.core.NonEmptyList
|
||||
import arrow.core.right
|
||||
import com.tangem.domain.account.status.usecase.SaveCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.managetokens.CheckIsCurrencyNotAddedUseCase
|
||||
import com.tangem.domain.managetokens.CreateCryptoCurrencyUseCase
|
||||
import com.tangem.domain.managetokens.FindTokenUseCase
|
||||
|
|
@ -28,6 +30,7 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
|
|||
private val findTokenUseCase: FindTokenUseCase,
|
||||
private val checkIsCurrencyNotAddedUseCase: CheckIsCurrencyNotAddedUseCase,
|
||||
private val coldWalletAndHasMissedDerivationsUseCase: ColdWalletAndHasMissedDerivationsUseCase,
|
||||
private val saveCryptoCurrenciesUseCase: SaveCryptoCurrenciesUseCase,
|
||||
@Assisted private val mode: AddCustomTokenMode,
|
||||
) {
|
||||
|
||||
|
|
@ -40,15 +43,19 @@ internal class CustomTokenFormUseCasesFacade @AssistedInject constructor(
|
|||
}
|
||||
|
||||
suspend fun addCryptoCurrenciesUseCase(currency: CryptoCurrency): Either<Throwable, Unit> = when (mode) {
|
||||
is AddCustomTokenMode.Account -> TODO("Account")
|
||||
is AddCustomTokenMode.Wallet -> addCryptoCurrenciesUseCase.invoke(
|
||||
userWalletId = mode.userWalletId,
|
||||
currency = currency,
|
||||
)
|
||||
is AddCustomTokenMode.Account -> {
|
||||
saveCryptoCurrenciesUseCase(accountId = mode.accountId, add = currency)
|
||||
}
|
||||
is AddCustomTokenMode.Wallet -> {
|
||||
addCryptoCurrenciesUseCase.invoke(
|
||||
userWalletId = mode.userWalletId,
|
||||
currency = currency,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun derivePublicKeysUseCase(currencies: List<CryptoCurrency>): Either<Throwable, Unit> = when (mode) {
|
||||
is AddCustomTokenMode.Account -> TODO("Account")
|
||||
is AddCustomTokenMode.Account -> Unit.right()
|
||||
is AddCustomTokenMode.Wallet -> derivePublicKeysUseCase.invoke(
|
||||
userWalletId = mode.userWalletId,
|
||||
currencies = currencies,
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ package com.tangem.features.managetokens.utils.list
|
|||
|
||||
import arrow.core.Either
|
||||
import arrow.core.left
|
||||
import com.tangem.domain.account.status.usecase.SaveCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.managetokens.*
|
||||
import com.tangem.domain.managetokens.model.CurrencyUnsupportedState
|
||||
import com.tangem.domain.managetokens.model.ManageTokensListConfig
|
||||
import com.tangem.domain.managetokens.model.ManagedCryptoCurrency
|
||||
import com.tangem.domain.managetokens.repository.CustomTokensRepository
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.network.Network
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
import com.tangem.domain.wallets.usecase.ColdWalletAndHasMissedDerivationsUseCase
|
||||
|
|
@ -23,6 +26,8 @@ internal class ManageTokensUseCasesFacade @AssistedInject constructor(
|
|||
private val checkCurrencyUnsupportedUseCase: CheckCurrencyUnsupportedUseCase,
|
||||
private val coldWalletAndHasMissedDerivationsUseCase: ColdWalletAndHasMissedDerivationsUseCase,
|
||||
private val saveManagedTokensUseCase: SaveManagedTokensUseCase,
|
||||
private val saveCryptoCurrenciesUseCase: SaveCryptoCurrenciesUseCase,
|
||||
private val customTokensRepository: CustomTokensRepository,
|
||||
@Assisted private val mode: ManageTokensMode,
|
||||
) {
|
||||
|
||||
|
|
@ -40,7 +45,14 @@ internal class ManageTokensUseCasesFacade @AssistedInject constructor(
|
|||
|
||||
suspend fun removeCustomCurrencyUseCase(customCurrency: ManagedCryptoCurrency.Custom): Either<Throwable, Unit> {
|
||||
return when (mode) {
|
||||
is ManageTokensMode.Account -> TODO("Account")
|
||||
is ManageTokensMode.Account -> {
|
||||
val currency = customTokensRepository.convertToCryptoCurrency(
|
||||
userWalletId = mode.accountId.userWalletId,
|
||||
currency = customCurrency,
|
||||
)
|
||||
|
||||
saveCryptoCurrenciesUseCase(accountId = mode.accountId, remove = currency)
|
||||
}
|
||||
is ManageTokensMode.Wallet -> removeCustomCurrencyUseCase.invoke(
|
||||
userWalletId = mode.userWalletId,
|
||||
customCurrency = customCurrency,
|
||||
|
|
@ -92,15 +104,46 @@ internal class ManageTokensUseCasesFacade @AssistedInject constructor(
|
|||
currenciesToAdd: Map<ManagedCryptoCurrency.Token, Set<Network>>,
|
||||
currenciesToRemove: Map<ManagedCryptoCurrency.Token, Set<Network>>,
|
||||
): Either<Throwable, Unit> = when (mode) {
|
||||
is ManageTokensMode.Account -> TODO("Account")
|
||||
is ManageTokensMode.Wallet -> saveManagedTokensUseCase.invoke(
|
||||
userWalletId = mode.userWalletId,
|
||||
currenciesToAdd = currenciesToAdd,
|
||||
currenciesToRemove = currenciesToRemove,
|
||||
)
|
||||
is ManageTokensMode.Account -> {
|
||||
saveCryptoCurrenciesUseCase(
|
||||
accountId = mode.accountId,
|
||||
add = currenciesToAdd.mapToCryptoCurrencies(userWalletId = mode.accountId.userWalletId),
|
||||
remove = currenciesToRemove.mapToCryptoCurrencies(userWalletId = mode.accountId.userWalletId),
|
||||
)
|
||||
}
|
||||
is ManageTokensMode.Wallet -> {
|
||||
saveManagedTokensUseCase.invoke(
|
||||
userWalletId = mode.userWalletId,
|
||||
currenciesToAdd = currenciesToAdd,
|
||||
currenciesToRemove = currenciesToRemove,
|
||||
)
|
||||
}
|
||||
ManageTokensMode.None -> nonePortfolioError.left()
|
||||
}
|
||||
|
||||
private suspend fun Map<ManagedCryptoCurrency.Token, Set<Network>>.mapToCryptoCurrencies(
|
||||
userWalletId: UserWalletId,
|
||||
): List<CryptoCurrency> {
|
||||
return flatMap { (token, networks) ->
|
||||
token.availableNetworks
|
||||
.filter { sourceNetwork -> networks.contains(sourceNetwork.network) }
|
||||
.map { sourceNetwork ->
|
||||
when (sourceNetwork) {
|
||||
is ManagedCryptoCurrency.SourceNetwork.Default -> customTokensRepository.createToken(
|
||||
managedCryptoCurrency = token,
|
||||
sourceNetwork = sourceNetwork,
|
||||
rawId = CryptoCurrency.RawID(token.id.value),
|
||||
)
|
||||
is ManagedCryptoCurrency.SourceNetwork.Main -> customTokensRepository.createCoin(
|
||||
userWalletId = userWalletId,
|
||||
networkId = sourceNetwork.id,
|
||||
derivationPath = sourceNetwork.network.derivationPath,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@AssistedFactory
|
||||
interface Factory {
|
||||
fun create(mode: ManageTokensMode): ManageTokensUseCasesFacade
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
package com.tangem.features.onramp.hottokens.portfolio.model
|
||||
|
||||
import arrow.core.getOrElse
|
||||
import arrow.core.left
|
||||
import com.tangem.core.decompose.di.ModelScoped
|
||||
import com.tangem.core.decompose.model.Model
|
||||
import com.tangem.core.decompose.model.ParamsContainer
|
||||
import com.tangem.domain.wallets.usecase.DerivePublicKeysUseCase
|
||||
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.models.wallet.UserWallet
|
||||
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.wallets.usecase.DerivePublicKeysUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.features.onramp.hottokens.portfolio.OnrampAddToPortfolioComponent
|
||||
import com.tangem.features.onramp.hottokens.portfolio.entity.OnrampAddToPortfolioUM
|
||||
|
|
@ -35,6 +37,7 @@ internal class OnrampAddToPortfolioModel @Inject constructor(
|
|||
override val dispatchers: CoroutineDispatcherProvider,
|
||||
private val derivePublicKeysUseCase: DerivePublicKeysUseCase,
|
||||
private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase,
|
||||
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||
private val getUserWalletUseCase: GetUserWalletUseCase,
|
||||
) : Model() {
|
||||
|
||||
|
|
@ -73,16 +76,25 @@ internal class OnrampAddToPortfolioModel @Inject constructor(
|
|||
modelScope.launch {
|
||||
changeAddButtonProgressStatus(isProgress = true)
|
||||
|
||||
derivePublicKeysUseCase(params.userWalletId, listOfNotNull(params.cryptoCurrency)).getOrElse {
|
||||
Timber.e("Failed to derive public keys: $it")
|
||||
if (accountsFeatureToggles.isFeatureEnabled) {
|
||||
// saveCryptoCurrenciesUseCase(
|
||||
// accountId = params.accountId,
|
||||
// add = params.cryptoCurrency,
|
||||
// )
|
||||
// TODO account
|
||||
IllegalStateException("Not implemented yet").left()
|
||||
} else {
|
||||
derivePublicKeysUseCase(params.userWalletId, listOfNotNull(params.cryptoCurrency)).getOrElse {
|
||||
Timber.e("Failed to derive public keys: $it")
|
||||
|
||||
changeAddButtonProgressStatus(isProgress = false)
|
||||
changeAddButtonProgressStatus(isProgress = false)
|
||||
}
|
||||
|
||||
addCryptoCurrenciesUseCase(
|
||||
userWalletId = params.userWalletId,
|
||||
currency = params.cryptoCurrency,
|
||||
)
|
||||
}
|
||||
|
||||
addCryptoCurrenciesUseCase(
|
||||
userWalletId = params.userWalletId,
|
||||
currency = params.cryptoCurrency,
|
||||
)
|
||||
.onRight { params.onSuccessAdding(params.cryptoCurrency.id) }
|
||||
.onLeft { changeAddButtonProgressStatus(isProgress = false) }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ dependencies {
|
|||
implementation(projects.libs.crypto)
|
||||
|
||||
/** Domain modules */
|
||||
implementation(projects.domain.account.status)
|
||||
implementation(projects.domain.card)
|
||||
implementation(projects.domain.models)
|
||||
implementation(projects.domain.tokens)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.tangem.feature.referral.domain
|
|||
|
||||
import arrow.core.getOrElse
|
||||
import com.tangem.common.core.TangemSdkError
|
||||
import com.tangem.domain.account.status.usecase.SaveCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.models.PortfolioId
|
||||
import com.tangem.domain.models.currency.CryptoCurrency
|
||||
import com.tangem.domain.models.wallet.UserWalletId
|
||||
|
|
@ -21,6 +22,7 @@ internal class ReferralInteractorImpl(
|
|||
private val derivePublicKeysUseCase: DerivePublicKeysUseCase,
|
||||
private val getUserWalletUseCase: GetUserWalletUseCase,
|
||||
private val addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase,
|
||||
private val saveCryptoCurrenciesUseCase: SaveCryptoCurrenciesUseCase,
|
||||
) : ReferralInteractor {
|
||||
|
||||
private val tokensForReferral = mutableListOf<TokenData>()
|
||||
|
|
@ -45,19 +47,23 @@ internal class ReferralInteractorImpl(
|
|||
val cryptoCurrency = repository.getCryptoCurrency(userWalletId = userWallet.walletId, tokenData = tokenData)
|
||||
?: error("Failed to create crypto currency")
|
||||
|
||||
// todo account different for account?
|
||||
derivePublicKeysUseCase(userWallet.walletId, listOfNotNull(cryptoCurrency)).getOrElse {
|
||||
Timber.e("Failed to derive public keys: $it")
|
||||
throw it.mapToDomainError()
|
||||
}
|
||||
|
||||
when (portfolioId) {
|
||||
is PortfolioId.Account -> TODO("account")
|
||||
is PortfolioId.Wallet -> addCryptoCurrenciesUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
currency = cryptoCurrency,
|
||||
)
|
||||
is PortfolioId.Account -> {
|
||||
saveCryptoCurrenciesUseCase(accountId = portfolioId.accountId, add = cryptoCurrency)
|
||||
}
|
||||
is PortfolioId.Wallet -> {
|
||||
derivePublicKeysUseCase(userWallet.walletId, listOfNotNull(cryptoCurrency)).getOrElse {
|
||||
Timber.e("Failed to derive public keys: $it")
|
||||
throw it.mapToDomainError()
|
||||
}
|
||||
|
||||
addCryptoCurrenciesUseCase(
|
||||
userWalletId = userWallet.walletId,
|
||||
currency = cryptoCurrency,
|
||||
)
|
||||
}
|
||||
}
|
||||
.onLeft(Timber::e)
|
||||
|
||||
val publicAddress = when (portfolioId) {
|
||||
is PortfolioId.Account -> TODO("account")
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
package com.tangem.feature.referral.domain.di
|
||||
|
||||
import com.tangem.core.decompose.di.ModelScoped
|
||||
import com.tangem.core.decompose.di.ModelComponent
|
||||
import com.tangem.domain.wallets.usecase.DerivePublicKeysUseCase
|
||||
import com.tangem.core.decompose.di.ModelScoped
|
||||
import com.tangem.domain.account.status.usecase.SaveCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.wallets.usecase.DerivePublicKeysUseCase
|
||||
import com.tangem.domain.wallets.usecase.GetUserWalletUseCase
|
||||
import com.tangem.feature.referral.domain.ReferralInteractor
|
||||
import com.tangem.feature.referral.domain.ReferralInteractorImpl
|
||||
|
|
@ -25,6 +26,7 @@ class ReferralDomainModule {
|
|||
derivePublicKeysUseCase: DerivePublicKeysUseCase,
|
||||
getUserWalletUseCase: GetUserWalletUseCase,
|
||||
addCryptoCurrenciesUseCase: AddCryptoCurrenciesUseCase,
|
||||
saveCryptoCurrenciesUseCase: SaveCryptoCurrenciesUseCase,
|
||||
): ReferralInteractor {
|
||||
return ReferralInteractorImpl(
|
||||
repository = referralRepository,
|
||||
|
|
@ -32,6 +34,7 @@ class ReferralDomainModule {
|
|||
derivePublicKeysUseCase = derivePublicKeysUseCase,
|
||||
getUserWalletUseCase = getUserWalletUseCase,
|
||||
addCryptoCurrenciesUseCase = addCryptoCurrenciesUseCase,
|
||||
saveCryptoCurrenciesUseCase = saveCryptoCurrenciesUseCase,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,7 @@ package com.tangem.features.send.v2.send.confirm.model
|
|||
import android.os.SystemClock
|
||||
import androidx.compose.runtime.Stable
|
||||
import arrow.core.getOrElse
|
||||
import arrow.core.left
|
||||
import com.tangem.blockchain.common.AmountType
|
||||
import com.tangem.blockchain.common.TransactionData
|
||||
import com.tangem.common.routing.AppRouter
|
||||
|
|
@ -20,6 +21,7 @@ import com.tangem.core.navigation.share.ShareManager
|
|||
import com.tangem.core.navigation.url.UrlOpener
|
||||
import com.tangem.core.ui.extensions.resourceReference
|
||||
import com.tangem.core.ui.extensions.stringReference
|
||||
import com.tangem.domain.account.featuretoggle.AccountsFeatureToggles
|
||||
import com.tangem.domain.balancehiding.GetBalanceHidingSettingsUseCase
|
||||
import com.tangem.domain.feedback.GetWalletMetaInfoUseCase
|
||||
import com.tangem.domain.feedback.SaveBlockchainErrorUseCase
|
||||
|
|
@ -105,6 +107,7 @@ internal class SendConfirmModel @Inject constructor(
|
|||
private val feeSelectorReloadTrigger: FeeSelectorReloadTrigger,
|
||||
private val sendAmountReduceTrigger: SendAmountReduceTrigger,
|
||||
private val getBalanceHidingSettingsUseCase: GetBalanceHidingSettingsUseCase,
|
||||
private val accountsFeatureToggles: AccountsFeatureToggles,
|
||||
sendBalanceUpdaterFactory: SendBalanceUpdater.Factory,
|
||||
) : Model(), SendConfirmClickIntents, FeeSelectorModelCallback, SendNotificationsComponent.ModelCallback {
|
||||
|
||||
|
|
@ -429,13 +432,21 @@ internal class SendConfirmModel @Inject constructor(
|
|||
val network = receivingUserWallet.network ?: return
|
||||
|
||||
modelScope.launch(dispatchers.default) {
|
||||
withContext(NonCancellable) {
|
||||
addCryptoCurrenciesUseCase(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
network = network,
|
||||
)
|
||||
if (accountsFeatureToggles.isFeatureEnabled) {
|
||||
// val tokenToAdd = currenciesRepository.createTokenCurrency(cryptoCurrency, network)
|
||||
// saveCryptoCurrenciesUseCase(accountId = accountId, add = tokenToAdd)
|
||||
// TODO account
|
||||
IllegalStateException("Not implemented yet").left()
|
||||
} else {
|
||||
withContext(NonCancellable) {
|
||||
addCryptoCurrenciesUseCase(
|
||||
userWalletId = userWalletId,
|
||||
cryptoCurrency = cryptoCurrency,
|
||||
network = network,
|
||||
)
|
||||
}
|
||||
}
|
||||
.onLeft(Timber::e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue