Updated on 2026-08-14
This commit is contained in:
parent
43c8cb47a4
commit
48747e746f
7 changed files with 99 additions and 14 deletions
|
|
@ -16,7 +16,6 @@ import com.tangem.domain.models.scan.ScanResponse
|
|||
import com.tangem.domain.tokens.AddCryptoCurrenciesUseCase
|
||||
import com.tangem.domain.tokens.TokensAction
|
||||
import com.tangem.domain.tokens.model.CryptoCurrency
|
||||
import com.tangem.domain.walletconnect.WalletConnectActions
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
import com.tangem.operations.derivation.ExtendedPublicKeysMap
|
||||
|
|
@ -202,9 +201,7 @@ object TokensMiddleware {
|
|||
userWalletId = userWallet.walletId,
|
||||
update = { it.copy(scanResponse = updatedScanResponse) },
|
||||
).doOnSuccess {
|
||||
addCryptoCurrenciesUseCase(userWallet.walletId, currencyList).onRight {
|
||||
store.dispatch(action = WalletConnectActions.New.SetupUserChains(userWallet = userWallet))
|
||||
}
|
||||
addCryptoCurrenciesUseCase(userWallet.walletId, currencyList)
|
||||
}
|
||||
}
|
||||
store.dispatchOnMain(NavigationAction.PopBackTo())
|
||||
|
|
|
|||
|
|
@ -52,10 +52,7 @@ internal class GetMultiWalletWarningsFactory @Inject constructor(
|
|||
flow = getTokenListUseCase(userWallet.walletId).conflate(),
|
||||
flow2 = isReadyToShowRateAppUseCase().conflate(),
|
||||
flow3 = isNeedToBackupUseCase(userWallet.walletId).conflate(),
|
||||
// flow4 = getMissedAddressCryptoCurrenciesUseCase(userWallet.walletId).conflate(),
|
||||
) { maybeTokenList, isReadyToShowRating, isNeedToBackup ->
|
||||
// maybeTokenList.onRight { Timber.e(it.toString()) }
|
||||
// maybeMissedAddressCurrencies.onRight { Timber.e(it.toString()) }
|
||||
readyForRateAppNotification = true
|
||||
buildList {
|
||||
addCriticalNotifications(cardTypesResolver)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.loaders.implementors
|
||||
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.redux.ReduxStateHolder
|
||||
import com.tangem.domain.tokens.GetTokenListUseCase
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender
|
||||
|
|
@ -9,6 +10,7 @@ import com.tangem.feature.wallet.presentation.wallet.domain.WalletWithFundsCheck
|
|||
import com.tangem.feature.wallet.presentation.wallet.state2.WalletStateController
|
||||
import com.tangem.feature.wallet.presentation.wallet.subscribers.MultiWalletWarningsSubscriber
|
||||
import com.tangem.feature.wallet.presentation.wallet.subscribers.TokenListSubscriber
|
||||
import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletConnectNetworksSubscriber
|
||||
import com.tangem.feature.wallet.presentation.wallet.subscribers.WalletSubscriber
|
||||
import com.tangem.feature.wallet.presentation.wallet.viewmodels.intents.WalletClickIntentsV2
|
||||
|
||||
|
|
@ -22,6 +24,7 @@ internal class MultiWalletContentLoader(
|
|||
private val walletWithFundsChecker: WalletWithFundsChecker,
|
||||
private val getTokenListUseCase: GetTokenListUseCase,
|
||||
private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory,
|
||||
private val reduxStateHolder: ReduxStateHolder,
|
||||
) : WalletContentLoader(id = userWallet.walletId) {
|
||||
|
||||
override fun create(): List<WalletSubscriber> {
|
||||
|
|
@ -41,6 +44,11 @@ internal class MultiWalletContentLoader(
|
|||
clickIntents = clickIntents,
|
||||
getMultiWalletWarningsFactory = getMultiWalletWarningsFactory,
|
||||
),
|
||||
WalletConnectNetworksSubscriber(
|
||||
userWallet = userWallet,
|
||||
getTokenListUseCase = getTokenListUseCase,
|
||||
reduxStateHolder = reduxStateHolder,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.loaders.implementors
|
||||
|
||||
import com.tangem.domain.appcurrency.model.AppCurrency
|
||||
import com.tangem.domain.redux.ReduxStateHolder
|
||||
import com.tangem.domain.tokens.GetTokenListUseCase
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.feature.wallet.presentation.wallet.analytics.utils.TokenListAnalyticsSender
|
||||
|
|
@ -18,6 +19,7 @@ internal class MultiWalletContentLoaderFactory @Inject constructor(
|
|||
private val tokenListAnalyticsSender: TokenListAnalyticsSender,
|
||||
private val walletWithFundsChecker: WalletWithFundsChecker,
|
||||
private val getMultiWalletWarningsFactory: GetMultiWalletWarningsFactory,
|
||||
private val reduxStateHolder: ReduxStateHolder,
|
||||
) {
|
||||
|
||||
fun create(
|
||||
|
|
@ -34,6 +36,7 @@ internal class MultiWalletContentLoaderFactory @Inject constructor(
|
|||
walletWithFundsChecker = walletWithFundsChecker,
|
||||
getTokenListUseCase = getTokenListUseCase,
|
||||
getMultiWalletWarningsFactory = getMultiWalletWarningsFactory,
|
||||
reduxStateHolder = reduxStateHolder,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
package com.tangem.feature.wallet.presentation.wallet.subscribers
|
||||
|
||||
import arrow.core.Either
|
||||
import com.tangem.domain.redux.ReduxStateHolder
|
||||
import com.tangem.domain.tokens.GetTokenListUseCase
|
||||
import com.tangem.domain.tokens.error.TokenListError
|
||||
import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
||||
import com.tangem.domain.tokens.model.NetworkGroup
|
||||
import com.tangem.domain.tokens.model.TokenList
|
||||
import com.tangem.domain.walletconnect.WalletConnectActions
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* WalletConnect networks subscriber. Update WalletConnect networks for a specified [userWallet].
|
||||
*
|
||||
* @property userWallet user wallet
|
||||
* @property getTokenListUseCase use case for subscribing on token list changes
|
||||
* @property reduxStateHolder redux state holder
|
||||
*
|
||||
[REDACTED_AUTHOR]
|
||||
*/
|
||||
internal class WalletConnectNetworksSubscriber(
|
||||
private val userWallet: UserWallet,
|
||||
private val getTokenListUseCase: GetTokenListUseCase,
|
||||
private val reduxStateHolder: ReduxStateHolder,
|
||||
) : WalletSubscriber() {
|
||||
|
||||
private val mutex = Mutex()
|
||||
|
||||
override fun create(coroutineScope: CoroutineScope): Flow<Either<TokenListError, TokenList>> {
|
||||
return getTokenListUseCase(userWalletId = userWallet.walletId)
|
||||
.conflate()
|
||||
.distinctUntilCurrenciesChanged()
|
||||
.filterLoadedTokens()
|
||||
.onEach {
|
||||
mutex.withLock {
|
||||
Timber.d("WalletConnect: ${userWallet.walletId} networks is updated")
|
||||
|
||||
reduxStateHolder.dispatch(
|
||||
action = WalletConnectActions.New.SetupUserChains(userWallet = userWallet),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun MaybeTokenListFlow.distinctUntilCurrenciesChanged(): MaybeTokenListFlow {
|
||||
return distinctUntilChanged { old, new ->
|
||||
val oldCurrencies = old.fold(ifLeft = { null }, ifRight = { it.getCryptoCurrencies() })
|
||||
val newCurrencies = new.fold(ifLeft = { null }, ifRight = { it.getCryptoCurrencies() })
|
||||
|
||||
oldCurrencies == newCurrencies
|
||||
}
|
||||
}
|
||||
|
||||
private fun MaybeTokenListFlow.filterLoadedTokens(): MaybeTokenListFlow {
|
||||
return filter { either ->
|
||||
either.fold(
|
||||
ifLeft = { false },
|
||||
ifRight = { it.getCryptoCurrencies().isAllCurrenciesLoaded() },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun TokenList.getCryptoCurrencies(): List<CryptoCurrencyStatus> {
|
||||
return when (this) {
|
||||
is TokenList.Ungrouped -> currencies
|
||||
is TokenList.GroupedByNetwork -> groups.flatMap(NetworkGroup::currencies)
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<CryptoCurrencyStatus>.isAllCurrenciesLoaded(): Boolean {
|
||||
return none { it.value is CryptoCurrencyStatus.Loading }
|
||||
}
|
||||
}
|
||||
|
|
@ -34,6 +34,7 @@ import kotlinx.coroutines.delay
|
|||
import kotlinx.coroutines.flow.*
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
|
|
@ -142,9 +143,15 @@ internal class WalletViewModelV2 @Inject constructor(
|
|||
.distinctUntilChanged()
|
||||
.onEach { selectedWallet ->
|
||||
if (selectedWallet.isMultiCurrency) {
|
||||
Timber.d("WalletConnect: initialize and setup networks for ${selectedWallet.walletId}")
|
||||
|
||||
reduxStateHolder.dispatch(
|
||||
action = WalletConnectActions.New.Initialize(userWallet = selectedWallet),
|
||||
)
|
||||
|
||||
reduxStateHolder.dispatch(
|
||||
action = WalletConnectActions.New.SetupUserChains(userWallet = selectedWallet),
|
||||
)
|
||||
}
|
||||
}
|
||||
.flowOn(dispatchers.main)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ import com.tangem.domain.tokens.model.CryptoCurrencyStatus
|
|||
import com.tangem.domain.tokens.model.NetworkAddress
|
||||
import com.tangem.domain.tokens.models.analytics.TokenReceiveAnalyticsEvent
|
||||
import com.tangem.domain.tokens.models.analytics.TokenScreenAnalyticsEvent
|
||||
import com.tangem.domain.walletconnect.WalletConnectActions
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.models.UserWallet
|
||||
import com.tangem.domain.wallets.models.UserWalletId
|
||||
|
|
@ -252,12 +251,6 @@ internal class WalletCurrencyActionsClickIntentsImplementor @Inject constructor(
|
|||
)
|
||||
},
|
||||
ifRight = {
|
||||
getSelectedWalletSyncUseCase.unwrap()?.let { userWallet ->
|
||||
reduxStateHolder.dispatch(
|
||||
action = WalletConnectActions.New.SetupUserChains(userWallet = userWallet),
|
||||
)
|
||||
}
|
||||
|
||||
stateHolder.update(CloseBottomSheetTransformer(userWalletId = userWalletId))
|
||||
},
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue