Updated on 2026-08-14

This commit is contained in:
Tangem 2023-11-21 12:47:53 +04:00
parent 275e07cb9d
commit 9fd43ad7fb
15 changed files with 56 additions and 502 deletions

View file

@ -14,7 +14,6 @@ import com.tangem.tap.common.extensions.dispatchOnMain
import com.tangem.tap.common.extensions.onUserWalletSelected
import com.tangem.tap.common.redux.AppState
import com.tangem.tap.domain.TangemSdkManager
import com.tangem.tap.domain.tokens.UserTokensRepository
import com.tangem.tap.network.exchangeServices.ExchangeService
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
@ -41,7 +40,6 @@ class AppStateHolder @Inject constructor() : WalletsStateHolder, ReduxNavControl
@Deprecated("Use scan response from selected user wallet")
var scanResponse: ScanResponse? = null
var userTokensRepository: UserTokensRepository? = null
var mainStore: Store<AppState>? = null
var tangemSdkManager: TangemSdkManager? = null
var appFiatCurrency: FiatCurrency = FiatCurrency.Default

View file

@ -4,9 +4,12 @@ import com.tangem.blockchain.common.AmountType
import com.tangem.blockchain.common.Blockchain
import com.tangem.blockchain.common.Token
import com.tangem.blockchain.common.WalletManager
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.common.extensions.fromNetworkId
import com.tangem.domain.common.extensions.toCoinId
import com.tangem.domain.common.extensions.toNetworkId
import com.tangem.domain.tokens.model.CryptoCurrency
import com.tangem.domain.tokens.repository.CurrenciesRepository
import com.tangem.domain.walletmanager.WalletManagersFacade
import com.tangem.lib.crypto.UserWalletManager
import com.tangem.lib.crypto.models.Currency
@ -21,6 +24,8 @@ import java.math.BigDecimal
class UserWalletManagerImpl(
private val appStateHolder: AppStateHolder,
private val walletManagersFacade: WalletManagersFacade,
private val currenciesRepository: CurrenciesRepository,
private val userWalletsStore: UserWalletsStore,
) : UserWalletManager {
override suspend fun getUserTokens(
@ -28,43 +33,44 @@ class UserWalletManagerImpl(
derivationPath: String?,
isExcludeCustom: Boolean,
): List<Currency> {
val card = appStateHolder.getActualCard()
val userTokensRepository =
requireNotNull(appStateHolder.userTokensRepository) { "userTokensRepository is null" }
return if (card != null) {
userTokensRepository.getUserTokens(card, null) // refactor in [REDACTED_JIRA]
.filter {
val checkCustom = if (isExcludeCustom) {
!it.isCustomCurrency(null)
} else {
true
}
it.blockchain.toNetworkId() == networkId &&
checkCustom &&
it.derivationPath == derivationPath
}
.map {
if (it is com.tangem.tap.features.wallet.models.Currency.Token) {
NonNativeToken(
id = it.coinId ?: "",
name = it.currencyName,
symbol = it.currencySymbol,
networkId = it.blockchain.toNetworkId(),
contractAddress = it.token.contractAddress,
decimalCount = it.token.decimals,
)
} else {
NativeToken(
id = it.coinId ?: "",
name = it.currencyName,
symbol = it.currencySymbol,
networkId = it.blockchain.toNetworkId(),
)
}
}
} else {
emptyList()
// FIXME: Find user wallet by ID
val userWallet = requireNotNull(userWalletsStore.selectedUserWalletOrNull) {
"No user wallet selected"
}
return currenciesRepository.getMultiCurrencyWalletCurrenciesSync(userWallet.walletId)
.filter {
val checkCustom = if (isExcludeCustom) {
!it.isCustom
} else {
true
}
val blockchain = Blockchain.fromId(it.network.id.value)
blockchain.toNetworkId() == networkId &&
checkCustom &&
it.network.derivationPath.value == derivationPath
}
.map {
val blockchain = Blockchain.fromId(it.network.id.value)
if (it is CryptoCurrency.Token) {
NonNativeToken(
id = it.id.rawCurrencyId ?: "",
name = it.name,
symbol = it.symbol,
networkId = blockchain.toNetworkId(),
contractAddress = it.contractAddress,
decimalCount = it.decimals,
)
} else {
NativeToken(
id = it.id.rawCurrencyId ?: "",
name = it.name,
symbol = it.symbol,
networkId = blockchain.toNetworkId(),
)
}
}
}
override fun getNativeTokenForNetwork(networkId: String): Currency {

View file

@ -2,6 +2,7 @@ package com.tangem.tap.proxy.di
import com.tangem.common.Provider
import com.tangem.core.analytics.api.AnalyticsEventHandler
import com.tangem.datasource.local.userwallet.UserWalletsStore
import com.tangem.domain.card.repository.CardSdkConfigRepository
import com.tangem.domain.common.CardTypesResolver
import com.tangem.domain.common.util.cardTypesResolver
@ -23,7 +24,7 @@ import javax.inject.Singleton
@Module
@InstallIn(SingletonComponent::class)
class ProxyModule {
internal object ProxyModule {
@Provides
@Singleton
@ -36,10 +37,14 @@ class ProxyModule {
fun provideUserWalletManager(
appStateHolder: AppStateHolder,
walletManagersFacade: WalletManagersFacade,
currenciesRepository: CurrenciesRepository,
userWalletsStore: UserWalletsStore,
): UserWalletManager {
return UserWalletManagerImpl(
appStateHolder = appStateHolder,
walletManagersFacade = walletManagersFacade,
currenciesRepository = currenciesRepository,
userWalletsStore = userWalletsStore,
)
}