Skip to content

Commit

Permalink
Make identity details required, add blockchain propert
Browse files Browse the repository at this point in the history
  • Loading branch information
creativedrewy committed Oct 17, 2023
1 parent 62b3d0d commit 3ca4ecb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@ package com.solana.mobilewalletadapter.clientlib
import android.net.Uri
import com.solana.mobilewalletadapter.clientlib.protocol.MobileWalletAdapterClient.AuthorizationResult

internal sealed class IdentityState {
data class Provided(
val appIdentity: ConnectionIdentity
): IdentityState()

object NotProvided: IdentityState()
}

data class ConnectionIdentity(
val identityUri: Uri,
val iconUri: Uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@ import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException

class MobileWalletAdapter(
private val connectionIdentity: ConnectionIdentity,
private val timeout: Int = Scenario.DEFAULT_CLIENT_TIMEOUT_MS,
private val ioDispatcher: CoroutineDispatcher = Dispatchers.IO,
private val scenarioProvider: AssociationScenarioProvider = AssociationScenarioProvider(),
connectionIdentity: ConnectionIdentity? = null,
) {

private var identityState: IdentityState = IdentityState.NotProvided

private val adapterOperations = LocalAdapterOperations(ioDispatcher)

var authToken: String? = null
Expand Down Expand Up @@ -64,18 +62,8 @@ class MobileWalletAdapter(
field = value
}

init {
connectionIdentity?.let {
identityState = IdentityState.Provided(it)
}
}

suspend fun connect(sender: ActivityResultSender): TransactionResult<Unit> {
return transact(sender) {
if (identityState is IdentityState.NotProvided) {
throw IllegalStateException("App identity credentials must be provided via the constructor to use the connect method.")
}
}
return transact(sender) { }
}

suspend fun <T> transact(
Expand Down Expand Up @@ -120,24 +108,21 @@ class MobileWalletAdapter(
val client = scenario.start().get(ASSOCIATION_CONNECT_DISCONNECT_TIMEOUT_MS, TimeUnit.MILLISECONDS)
adapterOperations.client = client

val authResult = identityState.let { id ->
if (id is IdentityState.Provided) {
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, blockchain.fullName, authToken, null, null)
} else {
authToken?.let { token ->
adapterOperations.reauthorize(identityUri, iconUri, identityName, token)
} ?: run {
adapterOperations.authorize(identityUri, iconUri, identityName, RpcCluster.Custom(blockchain.cluster))
}.also {
authToken = it.authToken
}
}
}
val authResult = with (connectionIdentity) {
if (protocolVersion == SessionProperties.ProtocolVersion.V1) {
/**
* TODO: Full MWA 2.0 support has feature & multi-address params. Will be implemented in a future minor release.
* Both the features & addresses params are set to null for now.
*/
adapterOperations.authorize(identityUri, iconUri, identityName, blockchain.fullName, authToken, null, null)
} else {
null
authToken?.let { token ->
adapterOperations.reauthorize(identityUri, iconUri, identityName, token)
} ?: run {
adapterOperations.authorize(identityUri, iconUri, identityName, RpcCluster.Custom(blockchain.cluster))
}.also {
authToken = it.authToken
}
}
}

Expand Down

0 comments on commit 3ca4ecb

Please sign in to comment.