Updated on 2026-08-14
This commit is contained in:
commit
08a8537fa7
4 changed files with 28 additions and 15 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package com.tangem.tap.domain.walletconnect2.data
|
||||
|
||||
import android.app.Application
|
||||
import arrow.core.flatten
|
||||
import com.tangem.tap.domain.walletconnect2.domain.WalletConnectRepository
|
||||
import com.tangem.tap.domain.walletconnect2.domain.WcJrpcRequestsDeserializer
|
||||
import com.tangem.tap.domain.walletconnect2.domain.models.*
|
||||
|
|
@ -97,6 +98,7 @@ class WalletConnectRepositoryImpl @Inject constructor(
|
|||
sessionProposal.url,
|
||||
sessionProposal.icons,
|
||||
sessionProposal.requiredNamespaces.values.flatMap { it.chains ?: emptyList() },
|
||||
sessionProposal.optionalNamespaces.values.flatMap { it.chains ?: emptyList() },
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -187,6 +189,7 @@ class WalletConnectRepositoryImpl @Inject constructor(
|
|||
namespaces = sessionProposal.requiredNamespaces,
|
||||
userNamespaces = userNamespaces,
|
||||
)
|
||||
|
||||
if (missingNetworks.isNotEmpty()) {
|
||||
Timber.e("Not added blockchains: $missingNetworks")
|
||||
scope.launch {
|
||||
|
|
@ -204,17 +207,26 @@ class WalletConnectRepositoryImpl @Inject constructor(
|
|||
}.groupBy { pair -> pair.first }
|
||||
.mapValues { entry -> entry.value.map { pair -> pair.second }.toSet() }
|
||||
|
||||
val preparedNamespaces = sessionProposal.requiredNamespaces.map { requiredNamespace ->
|
||||
val accounts = requiredNamespace.value.chains?.mapNotNull { userChains[it] }?.flatten() ?: emptyList()
|
||||
val preparedNamespaces = sessionProposal.requiredNamespaces
|
||||
.map { requiredNamespace ->
|
||||
val accountsRequired = requiredNamespace.value.chains
|
||||
?.mapNotNull { chain -> userChains[chain] }
|
||||
?.flatten() ?: emptyList()
|
||||
val accountsOptional = sessionProposal.optionalNamespaces[requiredNamespace.key]?.chains
|
||||
?.mapNotNull { chain -> userChains[chain] }
|
||||
?.flatten() ?: emptyList()
|
||||
|
||||
requiredNamespace.key to Wallet.Model.Namespace.Session(
|
||||
accounts = accounts,
|
||||
methods = requiredNamespace.value.methods,
|
||||
events = requiredNamespace.value.events,
|
||||
)
|
||||
}.toMap()
|
||||
requiredNamespace.key to Wallet.Model.Namespace.Session(
|
||||
accounts = accountsRequired + accountsOptional,
|
||||
methods = requiredNamespace.value.methods,
|
||||
events = requiredNamespace.value.events,
|
||||
)
|
||||
}.toMap()
|
||||
|
||||
val sessionApproval = Wallet.Params.SessionApprove(sessionProposal.proposerPublicKey, preparedNamespaces)
|
||||
val sessionApproval = Wallet.Params.SessionApprove(
|
||||
proposerPublicKey = sessionProposal.proposerPublicKey,
|
||||
namespaces = preparedNamespaces,
|
||||
)
|
||||
|
||||
Timber.d("Session approval is prepared for sending: $sessionApproval")
|
||||
|
||||
|
|
|
|||
|
|
@ -50,15 +50,15 @@ class WalletConnectInteractor(
|
|||
when (wcEvent) {
|
||||
is WalletConnectEvents.SessionProposal -> {
|
||||
Timber.d("WC session proposal event received")
|
||||
val unsupportedNetworks = wcEvent.chainIds
|
||||
val unsupportedNetworks = wcEvent.requiredChainIds
|
||||
.filter { blockchainHelper.chainIdToNetworkIdOrNull(it) == null }
|
||||
if (unsupportedNetworks.isNotEmpty()) {
|
||||
val error = WalletConnectError.ApprovalErrorUnsupportedNetwork(unsupportedNetworks)
|
||||
handler.onSessionRejected(error)
|
||||
return@onEach
|
||||
}
|
||||
|
||||
val networksFormatted = wcEvent.chainIds
|
||||
val networksFormatted = (wcEvent.requiredChainIds + wcEvent.optionalChainIds)
|
||||
.distinct()
|
||||
.mapNotNull { blockchainHelper.chainIdToFullNameOrNull(it) }
|
||||
.toString()
|
||||
handler.onProposalReceived(proposal = wcEvent, networksFormatted = networksFormatted)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ sealed interface WalletConnectEvents {
|
|||
val description: String,
|
||||
val url: String,
|
||||
val icons: List<URI>,
|
||||
val chainIds: List<String>,
|
||||
val requiredChainIds: List<String>,
|
||||
val optionalChainIds: List<String>,
|
||||
) : WalletConnectEvents
|
||||
|
||||
data class SessionApprovalError(val error: WalletConnectError) : WalletConnectEvents
|
||||
|
|
|
|||
|
|
@ -72,8 +72,8 @@ mviCore = "1.3.1"
|
|||
kotlinSerialization = "1.4.1"
|
||||
arrow = "1.2.0-RC"
|
||||
reactiveNetwork = "3.0.8"
|
||||
walletConnectCore = "1.15.0"
|
||||
walletConnectWeb3 = "1.8.0"
|
||||
walletConnectCore = "1.17.0"
|
||||
walletConnectWeb3 = "1.10.0"
|
||||
# endregion Other libraries
|
||||
|
||||
# region Tangem
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue