Skip to content

Commit

Permalink
Add Blockchain object support
Browse files Browse the repository at this point in the history
  • Loading branch information
creativedrewy committed Oct 17, 2023
1 parent 75e5b41 commit 62b3d0d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MobileWalletAdapter(
* Specify the RPC cluster used for all operations. Note: changing at runtime will invalidate
* the auth token and reauthorization will be required
*/
var rpcCluster: RpcCluster = RpcCluster.Devnet
var blockchain: Blockchain = Solana.Devnet
set(value) {
if (value != field) {
authToken = null
Expand All @@ -41,6 +41,29 @@ class MobileWalletAdapter(
field = value
}

@Deprecated(
"RpcCluster provides only Solana clusters; use the Blockchain object for full multi-chain support.",
replaceWith = ReplaceWith("Set `blockchain` property moving forward."),
DeprecationLevel.WARNING
)
var rpcCluster: RpcCluster = RpcCluster.Devnet
set(value) {
when (value) {
RpcCluster.MainnetBeta -> {
blockchain = Solana.Mainnet
}
RpcCluster.Devnet -> {
blockchain = Solana.Devnet
}
RpcCluster.Testnet -> {
blockchain = Solana.Testnet
}
else -> { }
}

field = value
}

init {
connectionIdentity?.let {
identityState = IdentityState.Provided(it)
Expand Down Expand Up @@ -102,12 +125,12 @@ class MobileWalletAdapter(
with (id.appIdentity) {
if (protocolVersion == SessionProperties.ProtocolVersion.V1) {
//TODO: Full MWA 2.0 support has feature & multi-address params. Will be implemented in a future minor release.
adapterOperations.authorize(identityUri, iconUri, identityName, "SOMECHAIN", authToken, null, null)
adapterOperations.authorize(identityUri, iconUri, identityName, blockchain.fullName, authToken, null, null)
} else {
authToken?.let { token ->
adapterOperations.reauthorize(identityUri, iconUri, identityName, token)
} ?: run {
adapterOperations.authorize(identityUri, iconUri, identityName, rpcCluster)
adapterOperations.authorize(identityUri, iconUri, identityName, RpcCluster.Custom(blockchain.cluster))
}.also {
authToken = it.authToken
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ package com.solana.mobilewalletadapter.clientlib

import com.solana.mobilewalletadapter.common.ProtocolContract

@Deprecated(
"RpcCluster is deprecated as of MWA 2.0",
replaceWith = ReplaceWith("Use the Blockchain object for multi-chain support"),
DeprecationLevel.WARNING
)
sealed class RpcCluster(val name: String) {
object MainnetBeta : RpcCluster(ProtocolContract.CLUSTER_MAINNET_BETA)
object Testnet : RpcCluster(ProtocolContract.CLUSTER_TESTNET)
object Devnet : RpcCluster(ProtocolContract.CLUSTER_DEVNET)
class Custom(name: String) : RpcCluster(name)
}

sealed class Blockchain(
val name: String,
val cluster: String
) {
val fullName
get() = "$name:$cluster"
}

sealed class Solana {
object Mainnet: Blockchain("solana", ProtocolContract.CLUSTER_MAINNET_BETA)
object Testnet: Blockchain("solana", ProtocolContract.CLUSTER_TESTNET)
object Devnet: Blockchain("solana", ProtocolContract.CLUSTER_DEVNET)
}

open class TransactionParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.solana.core.SerializeConfig
import com.solana.core.Transaction
import com.solana.mobilewalletadapter.clientlib.ActivityResultSender
import com.solana.mobilewalletadapter.clientlib.MobileWalletAdapter
import com.solana.mobilewalletadapter.clientlib.RpcCluster
import com.solana.mobilewalletadapter.clientlib.TransactionResult
import com.solana.programs.MemoProgram
import com.solanamobile.ktxclientsample.usecase.Connected
Expand Down

0 comments on commit 62b3d0d

Please sign in to comment.