diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
index ed76bea3..44ca2d9b 100644
--- a/.idea/inspectionProfiles/Project_Default.xml
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -5,6 +5,10 @@
+
+
+
+
diff --git a/metamask-android-sdk/build.gradle b/metamask-android-sdk/build.gradle
index 58699898..3a2492b1 100644
--- a/metamask-android-sdk/build.gradle
+++ b/metamask-android-sdk/build.gradle
@@ -15,7 +15,7 @@ android {
targetSdk 33
ext.versionCode = 1
- ext.versionName = "0.6.0"
+ ext.versionName = "0.6.1"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
consumerProguardFiles 'consumer-rules.pro'
@@ -65,7 +65,7 @@ dependencies {
ext {
PUBLISH_GROUP_ID = 'io.metamask.androidsdk'
- PUBLISH_VERSION = '0.6.0'
+ PUBLISH_VERSION = '0.6.1'
PUBLISH_ARTIFACT_ID = 'metamask-android-sdk'
}
diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt
index f177fb33..0f6c626e 100644
--- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt
+++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/Ethereum.kt
@@ -9,6 +9,8 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
+import kotlinx.coroutines.runBlocking
+import kotlinx.coroutines.withContext
import java.lang.ref.WeakReference
private const val METAMASK_DEEPLINK = "https://metamask.app.link"
@@ -46,9 +48,12 @@ class Ethereum (
// Expose plain variables for developers who prefer not using observing live data via ethereumState
val chainId: String
- get() = currentEthereumState.chainId
+ get() = if (currentEthereumState.chainId.isEmpty()) { currentEthereumState.chainId } else { cachedChainId }
val selectedAddress: String
- get() = currentEthereumState.selectedAddress
+ get() = if (currentEthereumState.selectedAddress.isEmpty()) { currentEthereumState.selectedAddress } else { cachedAccount }
+
+ private var cachedChainId = ""
+ private var cachedAccount = ""
// Toggle SDK tracking
var enableDebug: Boolean = true
@@ -58,23 +63,30 @@ class Ethereum (
}
init {
- updateSessionDuration()
- initializeEthereumState()
+ runBlocking { fetchCachedSession() }
}
- private fun initializeEthereumState() {
- coroutineScope.launch(Dispatchers.IO) {
+ private suspend fun fetchCachedSession() {
+ withContext(Dispatchers.IO) {
try {
val account = storage.getValue(key = SessionManager.SESSION_ACCOUNT_KEY, file = SessionManager.SESSION_CONFIG_FILE)
val chainId = storage.getValue(key = SessionManager.SESSION_CHAIN_ID_KEY, file = SessionManager.SESSION_CONFIG_FILE)
- _ethereumState.postValue(
- currentEthereumState.copy(
- selectedAddress = account ?: "",
- chainId = chainId ?: ""
+ if (account != null && chainId != null) {
+ cachedChainId = chainId
+ cachedAccount = account
+
+ _ethereumState.postValue(
+ currentEthereumState.copy(
+ selectedAddress = account,
+ chainId = chainId,
+ sessionId = communicationClient?.sessionId ?: ""
+ )
)
- )
+ } else {
+
+ }
} catch (e: Exception) {
- logger.error(e.localizedMessage)
+ e.localizedMessage?.let { logger.error(it) }
}
}
}
@@ -125,6 +137,7 @@ class Ethereum (
fun connect(callback: ((Result) -> Unit)? = null) {
connectRequestSent = true
+
val error = dappMetadata.validationError
if (error != null) {
callback?.invoke((Result.Error(error)))
@@ -207,11 +220,19 @@ class Ethereum (
}
fun getChainId(callback: ((Result) -> Unit)?) {
- ethereumRequest(method = EthereumMethod.ETH_CHAIN_ID, params = null, callback)
+ if(connectRequestSent) {
+ ethereumRequest(method = EthereumMethod.ETH_CHAIN_ID, params = null, callback)
+ } else {
+ callback?.invoke((Result.Success.Item(cachedChainId)))
+ }
}
fun getEthAccounts(callback: ((Result) -> Unit)?) {
- ethereumRequest(method = EthereumMethod.ETH_ACCOUNTS, params = null, callback)
+ if (connectRequestSent) {
+ ethereumRequest(method = EthereumMethod.ETH_ACCOUNTS, params = null, callback)
+ } else {
+ callback?.invoke((Result.Success.Item(cachedAccount)))
+ }
}
fun getEthBalance(address: String, block: String, callback: ((Result) -> Unit)? = null) {
diff --git a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt
index 5977b680..3946081a 100644
--- a/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt
+++ b/metamask-android-sdk/src/main/java/io/metamask/androidsdk/SDKInfo.kt
@@ -1,6 +1,6 @@
package io.metamask.androidsdk
object SDKInfo {
- const val VERSION = "0.6.0"
+ const val VERSION = "0.6.1"
const val PLATFORM = "android"
}
\ No newline at end of file