From 3ca4ecb57de71c094aac2125cb700df1560322b3 Mon Sep 17 00:00:00 2001 From: Andrew Watson Date: Tue, 17 Oct 2023 15:17:50 -0700 Subject: [PATCH] Make identity details required, add blockchain propert --- .../clientlib/DataModels.kt | 8 ---- .../clientlib/MobileWalletAdapter.kt | 47 +++++++------------ 2 files changed, 16 insertions(+), 39 deletions(-) diff --git a/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/DataModels.kt b/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/DataModels.kt index e210a4a38..34533a081 100644 --- a/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/DataModels.kt +++ b/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/DataModels.kt @@ -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, diff --git a/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/MobileWalletAdapter.kt b/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/MobileWalletAdapter.kt index 0baa77bae..fce697b17 100644 --- a/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/MobileWalletAdapter.kt +++ b/android/clientlib-ktx/src/main/java/com/solana/mobilewalletadapter/clientlib/MobileWalletAdapter.kt @@ -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 @@ -64,18 +62,8 @@ class MobileWalletAdapter( field = value } - init { - connectionIdentity?.let { - identityState = IdentityState.Provided(it) - } - } - suspend fun connect(sender: ActivityResultSender): TransactionResult { - 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 transact( @@ -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 + } } }