Updated on 2026-08-14
This commit is contained in:
parent
ebcf2f40e5
commit
dca991651c
13 changed files with 173 additions and 15 deletions
|
|
@ -2,12 +2,23 @@ package com.tangem.tap.proxy
|
|||
|
||||
import com.tangem.common.card.Card
|
||||
import com.tangem.domain.common.ScanResponse
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
import com.tangem.tap.domain.tokens.UserTokensRepository
|
||||
import com.tangem.tap.features.tokens.redux.TokensMiddleware
|
||||
import com.tangem.tap.features.wallet.redux.WalletState
|
||||
import org.rekotlin.Store
|
||||
|
||||
/**
|
||||
* Holds objects from old modules, that missing in DI graph
|
||||
* Object sets manually to use in new modules and [AppStateHolder] proxies its to DI
|
||||
*/
|
||||
class AppStateHolder {
|
||||
|
||||
val scanResponse: ScanResponse? = null
|
||||
val walletState: WalletState? = null
|
||||
val userTokensRepository: UserTokensRepository? = null
|
||||
val mainStore: Store<AppState>? = null
|
||||
val tokesMiddleware: TokensMiddleware? = null
|
||||
|
||||
fun getActualCard(): Card? {
|
||||
return scanResponse?.card
|
||||
|
|
|
|||
|
|
@ -8,15 +8,14 @@ import com.tangem.lib.crypto.DerivationManager
|
|||
import com.tangem.lib.crypto.models.Currency
|
||||
import com.tangem.lib.crypto.models.NonNativeToken
|
||||
import com.tangem.tap.domain.tokens.models.BlockchainNetwork
|
||||
import com.tangem.tap.features.tokens.redux.TokensMiddleware
|
||||
import kotlin.coroutines.suspendCoroutine
|
||||
|
||||
class DerivationManagerImpl(
|
||||
private val tokesMiddleware: TokensMiddleware,
|
||||
private val appStateHolder: AppStateHolder,
|
||||
) : DerivationManager {
|
||||
|
||||
override suspend fun deriveMissingBlockchains(currency: Currency) = suspendCoroutine<Boolean> { continuation ->
|
||||
val tokesMiddleware = requireNotNull(appStateHolder.tokesMiddleware) { "tokesMiddleware is null" }
|
||||
val blockchain = Blockchain.fromNetworkId(currency.networkId)
|
||||
val card = appStateHolder.getActualCard()
|
||||
if (blockchain != null && card != null) {
|
||||
|
|
|
|||
|
|
@ -12,24 +12,21 @@ import com.tangem.lib.crypto.UserWalletManager
|
|||
import com.tangem.lib.crypto.models.Currency
|
||||
import com.tangem.lib.crypto.models.NativeToken
|
||||
import com.tangem.lib.crypto.models.NonNativeToken
|
||||
import com.tangem.tap.common.redux.AppState
|
||||
import com.tangem.tap.domain.extensions.getUserWalletId
|
||||
import com.tangem.tap.domain.extensions.makeWalletManagerForApp
|
||||
import com.tangem.tap.domain.tokens.UserTokensRepository
|
||||
import com.tangem.tap.domain.tokens.models.BlockchainNetwork
|
||||
import com.tangem.tap.features.wallet.redux.WalletAction
|
||||
import org.rekotlin.Action
|
||||
import org.rekotlin.Store
|
||||
|
||||
class UserWalletManagerImpl(
|
||||
private val userTokensRepository: UserTokensRepository,
|
||||
private val appStateHolder: AppStateHolder,
|
||||
private val mainStore: Store<AppState>,
|
||||
private val walletManagerFactory: WalletManagerFactory,
|
||||
) : UserWalletManager {
|
||||
|
||||
override suspend fun getUserTokens(): List<Currency> {
|
||||
val card = appStateHolder.getActualCard()
|
||||
val userTokensRepository =
|
||||
requireNotNull(appStateHolder.userTokensRepository) { "userTokensRepository is null" }
|
||||
if (card != null) {
|
||||
userTokensRepository.getUserTokens(card)
|
||||
.filter { it.isToken() }
|
||||
|
|
@ -62,6 +59,8 @@ class UserWalletManagerImpl(
|
|||
|
||||
override suspend fun isTokenAdded(currency: Currency): Boolean {
|
||||
val card = appStateHolder.getActualCard()
|
||||
val userTokensRepository =
|
||||
requireNotNull(appStateHolder.userTokensRepository) { "userTokensRepository is null" }
|
||||
if (card != null) {
|
||||
return userTokensRepository.getUserTokens(card)
|
||||
.any { it.coinId.equals(currency.id) } //todo ensure that its the same ids
|
||||
|
|
@ -81,7 +80,7 @@ class UserWalletManagerImpl(
|
|||
} else {
|
||||
addNonNativeTokenToWalletAction(currency as NonNativeToken)
|
||||
}
|
||||
|
||||
val mainStore = requireNotNull(appStateHolder.mainStore) { "mainStore is null" }
|
||||
mainStore.dispatch(action)
|
||||
}
|
||||
|
||||
|
|
|
|||
41
app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt
Normal file
41
app/src/main/java/com/tangem/tap/proxy/di/ProxyModule.kt
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package com.tangem.tap.proxy.di
|
||||
|
||||
import com.tangem.blockchain.common.WalletManagerFactory
|
||||
import com.tangem.lib.crypto.DerivationManager
|
||||
import com.tangem.lib.crypto.UserWalletManager
|
||||
import com.tangem.tap.proxy.AppStateHolder
|
||||
import com.tangem.tap.proxy.DerivationManagerImpl
|
||||
import com.tangem.tap.proxy.UserWalletManagerImpl
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class ProxyModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAppStateHolder(): AppStateHolder {
|
||||
return AppStateHolder()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideUserWalletManager(appStateHolder: AppStateHolder): UserWalletManager {
|
||||
return UserWalletManagerImpl(
|
||||
appStateHolder = appStateHolder,
|
||||
walletManagerFactory = WalletManagerFactory(),
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideDerivationManager(appStateHolder: AppStateHolder): DerivationManager {
|
||||
return DerivationManagerImpl(
|
||||
appStateHolder = appStateHolder,
|
||||
)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue