Updated on 2026-08-14
This commit is contained in:
parent
e3a7ba0a77
commit
a1b5761bf3
4 changed files with 23 additions and 10 deletions
|
|
@ -6,9 +6,11 @@ import arrow.core.left
|
|||
import arrow.core.right
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.tangem.blockchain.common.Blockchain
|
||||
import com.tangem.blockchain.extensions.hexToInt
|
||||
import com.tangem.blockchainsdk.utils.ExcludedBlockchains
|
||||
import com.tangem.data.walletconnect.model.CAIP2
|
||||
import com.tangem.data.walletconnect.model.NamespaceKey
|
||||
import com.tangem.data.walletconnect.network.ethereum.WcEthNetwork.NamespaceConverter.Companion.ETH_NAMESPACE_KEY
|
||||
import com.tangem.data.walletconnect.request.WcRequestToUseCaseConverter
|
||||
import com.tangem.data.walletconnect.request.WcRequestToUseCaseConverter.Companion.fromJson
|
||||
import com.tangem.data.walletconnect.sign.WcMethodUseCaseContext
|
||||
|
|
@ -113,8 +115,10 @@ internal class WcEthNetwork(
|
|||
.getOrElse { return it.left() }
|
||||
?.firstOrNull()
|
||||
?.let {
|
||||
val caip2 = CAIP2.fromRaw("$ETH_NAMESPACE_KEY:${it.chainId.hexToInt()}")
|
||||
?: return null.right()
|
||||
val newNetwork = networksConverter
|
||||
.mainOrAnyWalletNetworkForRequest(it.chainId, wallet)
|
||||
.mainOrAnyWalletNetworkForRequest(caip2.raw, wallet)
|
||||
?: return null.right()
|
||||
WcEthMethod.AddEthereumChain(rawChain = it, network = newNetwork).right()
|
||||
}
|
||||
|
|
@ -147,13 +151,17 @@ internal class WcEthNetwork(
|
|||
override val excludedBlockchains: ExcludedBlockchains,
|
||||
) : WcNamespaceConverter {
|
||||
|
||||
override val namespaceKey: NamespaceKey = NamespaceKey("eip155")
|
||||
override val namespaceKey: NamespaceKey = NamespaceKey(ETH_NAMESPACE_KEY)
|
||||
|
||||
override fun toBlockchain(chainId: CAIP2): Blockchain? {
|
||||
if (chainId.namespace != namespaceKey.key) return null
|
||||
val ethChainId = chainId.reference.toIntOrNull() ?: return null
|
||||
return Blockchain.fromChainId(ethChainId)
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ETH_NAMESPACE_KEY = "eip155"
|
||||
}
|
||||
}
|
||||
|
||||
internal class Factories @Inject constructor(
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import com.squareup.moshi.JsonClass
|
|||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class WcEthAddChain(
|
||||
/**
|
||||
* chainId are identified by EIP-155 integers expressed in hexadecimal notation,
|
||||
* with 0x prefix and no leading zeroes for the chainId value.
|
||||
* For more information https://eips.ethereum.org/EIPS/eip-5792#atomicbatch-capability
|
||||
*/
|
||||
@Json(name = "chainId")
|
||||
val chainId: String,
|
||||
)
|
||||
|
|
@ -15,7 +15,7 @@ sealed interface WcEthMethod : WcMethod {
|
|||
val account: String,
|
||||
val dataForSign: String,
|
||||
) : WcEthMethod {
|
||||
val humanMsg: String = params.message.contents.orEmpty()
|
||||
val humanMsg: String = params.message?.contents.orEmpty()
|
||||
}
|
||||
|
||||
data class SendTransaction(
|
||||
|
|
|
|||
|
|
@ -6,24 +6,24 @@ import com.squareup.moshi.JsonClass
|
|||
@JsonClass(generateAdapter = true)
|
||||
data class WcEthSignTypedDataParams(
|
||||
@Json(name = "domain")
|
||||
val domain: Domain,
|
||||
val domain: Domain?,
|
||||
@Json(name = "message")
|
||||
val message: Message,
|
||||
val message: Message?,
|
||||
@Json(name = "primaryType")
|
||||
val primaryType: String,
|
||||
val primaryType: String?,
|
||||
@Json(name = "types")
|
||||
val types: Map<String, List<Types.Type>>,
|
||||
) {
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class Domain(
|
||||
@Json(name = "chainId")
|
||||
val chainId: Int,
|
||||
val chainId: Int?,
|
||||
@Json(name = "name")
|
||||
val name: String,
|
||||
val name: String?,
|
||||
@Json(name = "verifyingContract")
|
||||
val verifyingContract: String,
|
||||
val verifyingContract: String?,
|
||||
@Json(name = "version")
|
||||
val version: String,
|
||||
val version: String?,
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue