Updated on 2026-08-14
This commit is contained in:
parent
56733bbf0b
commit
b2616969b4
5 changed files with 113 additions and 9 deletions
|
|
@ -10,6 +10,7 @@ import com.reown.walletkit.client.WalletKit
|
|||
import com.tangem.core.analytics.api.AnalyticsEventHandler
|
||||
import com.tangem.data.walletconnect.pair.unsupportedDApps
|
||||
import com.tangem.domain.walletconnect.model.legacy.Account
|
||||
import com.tangem.features.walletconnect.components.WalletConnectFeatureToggles
|
||||
import com.tangem.tap.common.analytics.events.WalletConnect
|
||||
import com.tangem.tap.domain.walletconnect2.app.TangemWcBlockchainHelper
|
||||
import com.tangem.tap.domain.walletconnect2.domain.LegacyWalletConnectRepository
|
||||
|
|
@ -21,8 +22,94 @@ import com.tangem.tap.features.details.redux.walletconnect.WalletConnectAction.O
|
|||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import timber.log.Timber
|
||||
|
||||
internal class DefaultLegacyWalletConnectRepositoryFacade constructor(
|
||||
private val stub: LegacyWalletConnectRepositoryStub,
|
||||
private val legacy: DefaultLegacyWalletConnectRepository,
|
||||
private val walletConnectFeatureToggles: WalletConnectFeatureToggles,
|
||||
) : LegacyWalletConnectRepository {
|
||||
private val isNewWc by lazy {
|
||||
walletConnectFeatureToggles.isRedesignedWalletConnectEnabled
|
||||
}
|
||||
override val events: Flow<WalletConnectEvents> by lazy {
|
||||
if (isNewWc) stub.events else legacy.events
|
||||
}
|
||||
override val activeSessions: Flow<List<WalletConnectSession>> by lazy {
|
||||
if (isNewWc) stub.activeSessions else legacy.activeSessions
|
||||
}
|
||||
override val currentSessions: List<WalletConnectSession> by lazy {
|
||||
if (isNewWc) stub.currentSessions else legacy.currentSessions
|
||||
}
|
||||
|
||||
override fun init(projectId: String) {
|
||||
if (isNewWc) stub.init(projectId) else legacy.init(projectId)
|
||||
}
|
||||
|
||||
override fun setUserNamespaces(userNamespaces: Map<NetworkNamespace, List<Account>>) {
|
||||
if (isNewWc) stub.setUserNamespaces(userNamespaces) else legacy.setUserNamespaces(userNamespaces)
|
||||
}
|
||||
|
||||
override fun updateSessions() {
|
||||
if (isNewWc) stub.updateSessions() else legacy.updateSessions()
|
||||
}
|
||||
|
||||
override fun pair(uri: String, source: SourceType) {
|
||||
if (isNewWc) stub.pair(uri, source) else legacy.pair(uri, source)
|
||||
}
|
||||
|
||||
override fun disconnect(topic: String) {
|
||||
if (isNewWc) stub.disconnect(topic) else legacy.disconnect(topic)
|
||||
}
|
||||
|
||||
override fun approve(userNamespaces: Map<NetworkNamespace, List<Account>>, blockchainNames: List<String>) {
|
||||
if (isNewWc) stub.approve(userNamespaces, blockchainNames) else legacy.approve(userNamespaces, blockchainNames)
|
||||
}
|
||||
|
||||
override fun reject() {
|
||||
if (isNewWc) stub.reject() else legacy.reject()
|
||||
}
|
||||
|
||||
override fun sendRequest(requestData: RequestData, result: String) {
|
||||
if (isNewWc) stub.sendRequest(requestData, result) else legacy.sendRequest(requestData, result)
|
||||
}
|
||||
|
||||
override fun rejectRequest(requestData: RequestData, error: WalletConnectError) {
|
||||
if (isNewWc) stub.rejectRequest(requestData, error) else legacy.rejectRequest(requestData, error)
|
||||
}
|
||||
|
||||
override fun cancelRequest(topic: String, id: Long, message: String) {
|
||||
if (isNewWc) stub.cancelRequest(topic, id, message) else legacy.cancelRequest(topic, id, message)
|
||||
}
|
||||
}
|
||||
|
||||
internal class LegacyWalletConnectRepositoryStub : LegacyWalletConnectRepository {
|
||||
override val events: Flow<WalletConnectEvents> = emptyFlow()
|
||||
override val activeSessions: Flow<List<WalletConnectSession>> = emptyFlow()
|
||||
override val currentSessions: List<WalletConnectSession> = listOf()
|
||||
|
||||
override fun init(projectId: String) = Unit
|
||||
|
||||
override fun setUserNamespaces(userNamespaces: Map<NetworkNamespace, List<Account>>) = Unit
|
||||
|
||||
override fun updateSessions() = Unit
|
||||
|
||||
override fun pair(uri: String, source: SourceType) = Unit
|
||||
|
||||
override fun disconnect(topic: String) = Unit
|
||||
|
||||
override fun approve(userNamespaces: Map<NetworkNamespace, List<Account>>, blockchainNames: List<String>) = Unit
|
||||
|
||||
override fun reject() = Unit
|
||||
|
||||
override fun sendRequest(requestData: RequestData, result: String) = Unit
|
||||
|
||||
override fun rejectRequest(requestData: RequestData, error: WalletConnectError) = Unit
|
||||
|
||||
override fun cancelRequest(topic: String, id: Long, message: String) = Unit
|
||||
}
|
||||
|
||||
@Suppress("LargeClass")
|
||||
internal class DefaultLegacyWalletConnectRepository(
|
||||
private val application: Application,
|
||||
|
|
|
|||
|
|
@ -10,14 +10,18 @@ import com.tangem.domain.tokens.repository.CurrenciesRepository
|
|||
import com.tangem.domain.walletconnect.model.legacy.WalletConnectSessionsRepository
|
||||
import com.tangem.domain.walletmanager.WalletManagersFacade
|
||||
import com.tangem.domain.wallets.legacy.UserWalletsListManager
|
||||
import com.tangem.features.walletconnect.components.WalletConnectFeatureToggles
|
||||
import com.tangem.tap.domain.walletconnect.WalletConnectSdkHelper
|
||||
import com.tangem.tap.domain.walletconnect2.app.TangemWcBlockchainHelper
|
||||
import com.tangem.tap.domain.walletconnect2.app.WalletConnectEventsHandlerImpl
|
||||
import com.tangem.tap.domain.walletconnect2.data.DefaultLegacyWalletConnectRepository
|
||||
import com.tangem.tap.domain.walletconnect2.data.DefaultLegacyWalletConnectRepositoryFacade
|
||||
import com.tangem.tap.domain.walletconnect2.data.DefaultWalletConnectSessionsRepository
|
||||
import com.tangem.tap.domain.walletconnect2.domain.*
|
||||
import com.tangem.tap.domain.walletconnect2.data.LegacyWalletConnectRepositoryStub
|
||||
import com.tangem.tap.domain.walletconnect2.domain.LegacyWalletConnectRepository
|
||||
import com.tangem.tap.domain.walletconnect2.domain.WalletConnectInteractor
|
||||
import com.tangem.tap.domain.walletconnect2.domain.WcJrpcRequestsDeserializer
|
||||
import com.tangem.tap.domain.walletconnect2.toggles.WalletConnectFeatureToggles
|
||||
import com.tangem.tap.domain.walletconnect2.toggles.DefaultWalletConnectFeatureToggles
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
|
|
@ -60,7 +64,7 @@ internal object WalletConnectModule {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun provideWalletConnectFeatureToggles(featureTogglesManager: FeatureTogglesManager): WalletConnectFeatureToggles {
|
||||
return WalletConnectFeatureToggles(featureTogglesManager)
|
||||
return DefaultWalletConnectFeatureToggles(featureTogglesManager)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
@ -69,12 +73,19 @@ internal object WalletConnectModule {
|
|||
application: Application,
|
||||
wcRequestDeserializer: WcJrpcRequestsDeserializer,
|
||||
analyticsHandler: AnalyticsEventHandler,
|
||||
walletConnectFeatureToggles: WalletConnectFeatureToggles,
|
||||
): LegacyWalletConnectRepository {
|
||||
return DefaultLegacyWalletConnectRepository(
|
||||
val legacy = DefaultLegacyWalletConnectRepository(
|
||||
application = application,
|
||||
wcRequestDeserializer = wcRequestDeserializer,
|
||||
analyticsHandler = analyticsHandler,
|
||||
)
|
||||
val stub = LegacyWalletConnectRepositoryStub()
|
||||
return DefaultLegacyWalletConnectRepositoryFacade(
|
||||
stub,
|
||||
legacy,
|
||||
walletConnectFeatureToggles,
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
package com.tangem.tap.domain.walletconnect2.toggles
|
||||
|
||||
import com.tangem.core.configtoggle.feature.FeatureTogglesManager
|
||||
import com.tangem.features.walletconnect.components.WalletConnectFeatureToggles
|
||||
|
||||
internal class WalletConnectFeatureToggles(
|
||||
internal class DefaultWalletConnectFeatureToggles(
|
||||
private val featureTogglesManager: FeatureTogglesManager,
|
||||
) {
|
||||
) : WalletConnectFeatureToggles {
|
||||
|
||||
val isRedesignedWalletConnectEnabled: Boolean
|
||||
override val isRedesignedWalletConnectEnabled: Boolean
|
||||
get() = featureTogglesManager.isFeatureEnabled("WALLET_CONNECT_REDESIGN_ENABLED")
|
||||
}
|
||||
|
|
@ -12,7 +12,7 @@ import com.tangem.features.disclaimer.api.components.DisclaimerComponent
|
|||
import com.tangem.features.managetokens.component.ManageTokensComponent
|
||||
import com.tangem.features.managetokens.component.ManageTokensSource
|
||||
import com.tangem.features.markets.details.MarketsTokenDetailsComponent
|
||||
import com.tangem.features.nft.component.*
|
||||
import com.tangem.features.nft.component.NFTComponent
|
||||
import com.tangem.features.onboarding.v2.entry.OnboardingEntryComponent
|
||||
import com.tangem.features.onramp.component.*
|
||||
import com.tangem.features.pushnotifications.api.PushNotificationsComponent
|
||||
|
|
@ -24,7 +24,7 @@ import com.tangem.features.swap.SwapComponent
|
|||
import com.tangem.features.tester.api.TesterRouter
|
||||
import com.tangem.features.tokendetails.TokenDetailsComponent
|
||||
import com.tangem.features.wallet.WalletEntryComponent
|
||||
import com.tangem.tap.domain.walletconnect2.toggles.WalletConnectFeatureToggles
|
||||
import com.tangem.features.walletconnect.components.WalletConnectFeatureToggles
|
||||
import com.tangem.tap.features.details.ui.appcurrency.api.AppCurrencySelectorComponent
|
||||
import com.tangem.tap.features.details.ui.appsettings.api.AppSettingsComponent
|
||||
import com.tangem.tap.features.details.ui.cardsettings.api.CardSettingsComponent
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
package com.tangem.features.walletconnect.components
|
||||
|
||||
interface WalletConnectFeatureToggles {
|
||||
val isRedesignedWalletConnectEnabled: Boolean
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue