Updated on 2026-08-14

This commit is contained in:
Tangem 2024-10-31 15:21:06 +03:00
parent 58e6110121
commit 8b91930e18
5 changed files with 18 additions and 2 deletions

View file

@ -24,6 +24,12 @@ internal class TangemWcBlockchainHelper(
return blockchain?.toNetworkId()
}
override fun chainIdsToBlockchains(chainIds: List<String>): List<Blockchain> {
return chainIds.mapNotNull {
it.parseId()?.chainIdToBlockchain()
}.distinct()
}
override fun chainIdToMissingNetworkNameOrNull(chainId: String): String? {
val parsedId = chainId.parseId() ?: return null
val blockchain = parsedId.chainIdToBlockchain()
@ -103,6 +109,7 @@ internal class TangemWcBlockchainHelper(
second.toIntOrNull()
?.let(Blockchain::fromChainId)
}
SOLANA_NAMESPACE -> Blockchain.Solana
else -> {
Blockchain.fromNetworkId(networkId = first)
.takeIf(supportedNonEvmBlockchains::contains)
@ -112,6 +119,7 @@ internal class TangemWcBlockchainHelper(
private companion object {
const val EVM_NAMESPACE = "eip155"
const val SOLANA_NAMESPACE = "solana"
const val CHAIN_SEPARATOR = ":"
const val TESTNET_SEPARATOR = "/"
}

View file

@ -19,7 +19,7 @@ internal class WalletConnectEventsHandlerImpl : WalletConnectEventsHandler {
WalletConnectDialog.SessionProposalDialog(
sessionProposal = proposal,
networks = networksFormatted,
onApprove = { store.dispatchOnMain(WalletConnectAction.ApproveProposal) },
onApprove = { store.dispatchOnMain(WalletConnectAction.ApproveProposal(proposal)) },
onReject = { store.dispatchOnMain(WalletConnectAction.RejectProposal) },
),
),

View file

@ -1,5 +1,6 @@
package com.tangem.tap.domain.walletconnect2.domain
import com.tangem.blockchain.common.Blockchain
import com.tangem.tap.domain.walletconnect2.domain.models.Account
interface WcBlockchainHelper {
@ -14,4 +15,6 @@ interface WcBlockchainHelper {
fun chainIdToFullNameOrNull(chainId: String): String?
fun chainIdsToAccounts(walletAddress: String, chainIds: List<String>, derivationPath: String?): List<Account>
fun chainIdsToBlockchains(chainIds: List<String>): List<Blockchain>
}

View file

@ -2,6 +2,7 @@ package com.tangem.tap.features.details.redux.walletconnect
import com.tangem.tap.domain.walletconnect2.domain.WcPreparedRequest
import com.tangem.tap.domain.walletconnect2.domain.models.WalletConnectError
import com.tangem.tap.domain.walletconnect2.domain.models.WalletConnectEvents
import com.tangem.tap.features.details.ui.walletconnect.WcSessionForScreen
import org.rekotlin.Action
@ -22,7 +23,7 @@ sealed class WalletConnectAction : Action {
data class ShowClipboardOrScanQrDialog(val wcUri: String) : WalletConnectAction()
//region WalletConnect 2.0
data object ApproveProposal : WalletConnectAction()
data class ApproveProposal(val proposal: WalletConnectEvents.SessionProposal) : WalletConnectAction()
data object RejectProposal : WalletConnectAction()
data object SessionEstablished : WalletConnectAction()

View file

@ -85,7 +85,11 @@ class WalletConnectMiddleware {
}
is WalletConnectAction.ApproveProposal -> {
scope.launch {
val proposalChainIds = action.proposal.requiredChainIds + action.proposal.optionalChainIds
val proposalBlockchains =
walletConnectInteractor.blockchainHelper.chainIdsToBlockchains(proposalChainIds)
val accounts = getWalletManagers()
.filter { walletManager -> proposalBlockchains.contains(walletManager.wallet.blockchain) }
.flatMap {
val wallet = it.wallet
val chainIds = walletConnectInteractor.blockchainHelper.networkIdToChainIdOrNull(