Skip to content

Commit

Permalink
Merge pull request #1282 from WalletConnect/hotfix/1.21.1
Browse files Browse the repository at this point in the history
Release 1.21.1
  • Loading branch information
kacperoak authored Jan 24, 2024
2 parents 70a8ef3 + b56c0bf commit ffd7af3
Show file tree
Hide file tree
Showing 31 changed files with 268 additions and 141 deletions.
1 change: 1 addition & 0 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ WalletConnect v2 protocols for Android applications.

| BOM | [Core SDK](core/android) | [Sign SDK](protocol/sign) | [Auth SDK](protocol/auth) | [Chat SDK](protocol/chat) | [Notify SDK](protocol/notify) | [web3wallet](product/web3wallet) | [web3modal](product/web3modal) | [WalletConnectModal](product/walletconnectmodal) |
|-----------------------------------------------------------------------------------------|--------------------------|---------------------------|---------------------------|---------------------------|:------------------------------|----------------------------------|--------------------------------|--------------------------------------------------|
| 1.21.1 | 1.26.0 | 2.24.0 | 1.24.0 | 1.0.0.beta23 | 1.0.0-beta04 | 1.19.0 | 1.1.1 | 1.1.1 |
| 1.21.0 | 1.26.0 | 2.24.0 | 1.24.0 | 1.0.0.beta23 | 1.0.0-beta04 | 1.19.0 | 1.1.0 | 1.1.0 |
| 1.20.0 | 1.25.0 | 2.23.0 | 1.23.0 | 1.0.0.beta22 | 1.0.0-beta03 | 1.18.0 | 1.0.0 | 1.0.0-beta02 |
| 1.19.1 | 1.24.0 | 2.22.0 | 1.22.0 | 1.0.0.beta21 | 1.0.0-beta02 | 1.17.0 | 1.0.0-beta02 | 1.0.0-beta01 |
Expand Down
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ allprojects {
jvmTarget = jvmVersion.toString()
}
}

configurations.configureEach {
resolutionStrategy.eachDependency {
if (requested.group == "androidx.navigation" && requested.name == "navigation-compose") {
useVersion(composeNavigationVersion)
}
}
}
}

subprojects {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ fun DependencyHandlerScope.compose() {
}

fun DependencyHandlerScope.accompanist() {
"api"("com.google.accompanist:accompanist-navigation-material:$accompanistVersion")
"implementation"("com.google.accompanist:accompanist-navigation-material:$accompanistVersion")
"implementation"("com.google.accompanist:accompanist-drawablepainter:$accompanistVersion")
"implementation"("com.google.accompanist:accompanist-navigation-animation:$accompanistVersion")
"implementation"("com.google.accompanist:accompanist-systemuicontroller:$accompanistVersion")
Expand Down
10 changes: 5 additions & 5 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID"
const val KEY_SDK_NAME = "SDK_NAME"

//Latest versions
const val BOM_VERSION = "1.21.0"
const val BOM_VERSION = "1.21.1"
const val FOUNDATION_VERSION = "1.13.0"
const val CORE_VERSION = "1.26.0"
const val SIGN_VERSION = "2.24.0"
const val AUTH_VERSION = "1.24.0"
const val CHAT_VERSION = "1.0.0-beta23"
const val NOTIFY_VERSION = "1.0.0-beta04"
const val WEB_3_WALLET = "1.19.0"
const val WEB_3_MODAL = "1.1.0"
const val WC_MODAL_VERSION = "1.1.0"
const val MODAL_CORE_VERSION = "1.1.0"
const val WEB_3_MODAL = "1.1.1"
const val WC_MODAL_VERSION = "1.1.1"
const val MODAL_CORE_VERSION = "1.1.1"

val jvmVersion = JavaVersion.VERSION_11
const val MIN_SDK: Int = 23
Expand Down Expand Up @@ -61,7 +61,7 @@ const val kethereumVersion = "0.85.7"
const val wsRestJavaVersion = "3.1.0"
const val fcmVersion = "23.1.1"
const val relinkerVersion = "1.4.5"
const val accompanistVersion = "0.31.5-beta"
const val accompanistVersion = "0.31.3-beta"
const val coreKtxVersion = "1.10.1"
const val appCompatVersion = "1.6.1"
const val materialVersion = "1.9.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.walletconnect.modal.ui.components.common.VerticalSpacer
import com.walletconnect.wcmodal.client.Modal
import com.walletconnect.wcmodal.domain.WalletConnectModalDelegate
Expand All @@ -54,12 +52,10 @@ internal fun WalletConnectModal(

@ExperimentalAnimationApi
@Composable
internal fun WalletConnectModalComponent(
navController: NavHostController = rememberNavController(),
closeModal: () -> Unit
) {
internal fun WalletConnectModalComponent(closeModal: () -> Unit) {
val context = LocalContext.current
val viewModel: WalletConnectModalViewModel = viewModel()
val navController = rememberAnimatedNavController()
val state by viewModel.modalState.collectAsState()

LaunchedEffect(Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ class WalletConnectModalSheet : BottomSheetDialogFragment() {
this@WalletConnectModalSheet,
onBackPressedCallback(navController)
)

WalletConnectModalComponent(
navController = navController,
closeModal = { this@WalletConnectModalSheet.dismiss() }
)
WalletConnectModalComponent(closeModal = { this@WalletConnectModalSheet.dismiss() })
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.walletconnect.wcmodal.ui.navigation

import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navArgument
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.walletconnect.util.Empty
import com.walletconnect.wcmodal.ui.WalletConnectModalState
import com.walletconnect.wcmodal.ui.routes.all_wallets.AllWalletsRoute
Expand All @@ -19,6 +17,7 @@ import com.walletconnect.wcmodal.ui.routes.help.HelpRoute
import com.walletconnect.wcmodal.ui.routes.on_hold.RedirectOnHoldScreen
import com.walletconnect.wcmodal.ui.routes.scan_code.ScanQRCodeRoute

@ExperimentalAnimationApi
@Composable
internal fun ModalNavGraph(
navController: NavHostController,
Expand All @@ -27,14 +26,10 @@ internal fun ModalNavGraph(
updateRecentWalletId: (String) -> Unit,
retry: (() -> Unit) -> Unit
) {
NavHost(
AnimatedNavHost(
navController = navController,
startDestination = Route.ConnectYourWallet.path,
modifier = modifier,
enterTransition = { fadeIn(tween()) },
popExitTransition = { fadeOut(tween()) },
exitTransition = { fadeOut(tween()) },
popEnterTransition = { fadeIn(tween()) }
) {
composable(route = Route.ConnectYourWallet.path) {
ConnectYourWalletRoute(navController = navController, wallets = state.wallets)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,15 @@ object Web3Modal {
runCatching {
wcKoinApp.modules(web3ModalModule())
setInternalDelegate(Web3ModalDelegate)
}.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) }
onSuccess()
}
.onFailure { error -> return@onInitializedClient onError(Modal.Model.Error(error)) }
.onSuccess { onSuccess() }
}

fun setChains(chains: List<Modal.Model.Chain>) {
this.chains = chains
}

fun getSelectedChain() = getSelectedChainUseCase()?.toChain()

internal fun getSelectedChainOrFirst() = getSelectedChain() ?: chains.first()

fun setSessionProperties(properties: Map<String, String>) {
Expand All @@ -105,7 +104,7 @@ object Web3Modal {
@Throws(IllegalStateException::class)
fun setDelegate(delegate: ModalDelegate) {
Web3ModalDelegate.wcEventModels.onEach { event ->
when(event) {
when (event) {
is Modal.Model.ApprovedSession -> delegate.onSessionApproved(event)
is Modal.Model.ConnectionState -> delegate.onConnectionStateChange(event)
is Modal.Model.DeletedSession.Success -> delegate.onSessionDelete(event)
Expand All @@ -122,6 +121,7 @@ object Web3Modal {

@Throws(IllegalStateException::class)
private fun setInternalDelegate(delegate: ModalDelegate) {
Web3ModalDelegate.sessionTopic = getSessionTopicUseCase()
val signDelegate = object : SignClient.DappDelegate {
override fun onSessionApproved(approvedSession: Sign.Model.ApprovedSession) {
delegate.onSessionApproved(approvedSession.toModal())
Expand All @@ -144,7 +144,6 @@ object Web3Modal {
}

override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) {
scope.launch { deleteSessionDataUseCase() }
delegate.onSessionDelete(deletedSession.toModal())
}

Expand Down Expand Up @@ -221,6 +220,12 @@ object Web3Modal {
)
}

/**
* Caution: This function is blocking and runs on the current thread.
* It is advised that this function be called from background operation
*/
fun getSelectedChain() = getSelectedChainUseCase()?.toChain()

/**
* Caution: This function is blocking and runs on the current thread.
* It is advised that this function be called from background operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,9 @@ import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import com.walletconnect.android.internal.common.scope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.runBlocking

private val SESSION_TOPIC = stringPreferencesKey("session_topic_key")
private val SELECTED_CHAIN = stringPreferencesKey("selected_chain_key")
Expand All @@ -23,19 +18,13 @@ internal class SessionRepository(
private val context: Context
) {

val sessionTopic: StateFlow<String?> = context.sessionStore.data
.map { preferences ->
preferences[SESSION_TOPIC]
}.stateIn(scope, started = SharingStarted.Lazily, null)
val sessionTopic: Flow<String?> = context.sessionStore.data.map { preferences -> preferences[SESSION_TOPIC] }

val selectedChain: StateFlow<String?> = context.sessionStore.data
.map { preferences ->
preferences[SELECTED_CHAIN]
}.stateIn(scope, started = SharingStarted.Lazily, null)
val selectedChain: Flow<String?> = context.sessionStore.data.map { preferences -> preferences[SELECTED_CHAIN] }

fun getSelectedChain(): String? = selectedChain.value
suspend fun getSelectedChain(): String? = selectedChain.first()

fun getSessionTopic(): String? = sessionTopic.value
suspend fun getSessionTopic(): String? = sessionTopic.first()

suspend fun saveSessionTopic(topic: String) {
context.sessionStore.edit { store ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package com.walletconnect.web3.modal.domain.delegate

import com.walletconnect.android.internal.common.wcKoinApp
import com.walletconnect.web3.modal.client.Modal
import com.walletconnect.web3.modal.client.Web3Modal
import com.walletconnect.web3.modal.domain.usecase.DeleteSessionDataUseCase
import com.walletconnect.web3.modal.domain.usecase.GetSelectedChainUseCase
import com.walletconnect.web3.modal.domain.usecase.SaveChainSelectionUseCase
import com.walletconnect.web3.modal.domain.usecase.SaveSessionTopicUseCase
import com.walletconnect.web3.modal.utils.EthUtils
import com.walletconnect.web3.modal.utils.getSelectedChain
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
Expand All @@ -13,10 +20,19 @@ import kotlinx.coroutines.launch
internal object Web3ModalDelegate : Web3Modal.ModalDelegate {
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
private val _wcEventModels: MutableSharedFlow<Modal.Model?> = MutableSharedFlow()
val wcEventModels: SharedFlow<Modal.Model?> = _wcEventModels.asSharedFlow()
val wcEventModels: SharedFlow<Modal.Model?> = _wcEventModels.asSharedFlow()
var sessionTopic: String? = null

private val saveSessionTopicUseCase: SaveSessionTopicUseCase by lazy { wcKoinApp.koin.get() }
private val saveChainSelectionUseCase: SaveChainSelectionUseCase by lazy { wcKoinApp.koin.get() }
private val getSelectedChainUseCase: GetSelectedChainUseCase by lazy { wcKoinApp.koin.get() }
private val deleteSessionDataUseCase: DeleteSessionDataUseCase by lazy { wcKoinApp.koin.get() }

override fun onSessionApproved(approvedSession: Modal.Model.ApprovedSession) {
//TODO That will be removed after coinbase integration to Web3ModalEngine
scope.launch {
saveSessionTopicUseCase(approvedSession.topic)
saveChainSelectionUseCase(Web3Modal.chains.getSelectedChain(getSelectedChainUseCase()).id)
_wcEventModels.emit(approvedSession)
}
}
Expand All @@ -29,18 +45,38 @@ internal object Web3ModalDelegate : Web3Modal.ModalDelegate {

override fun onSessionUpdate(updatedSession: Modal.Model.UpdatedSession) {
scope.launch {
saveSessionTopicUseCase(updatedSession.topic)
_wcEventModels.emit(updatedSession)
}
}

override fun onSessionEvent(sessionEvent: Modal.Model.SessionEvent) {
scope.launch {
consumeSessionEvent(sessionEvent)
_wcEventModels.emit(sessionEvent)
}
}

private suspend fun consumeSessionEvent(sessionEvent: Modal.Model.SessionEvent) {
try {
when (sessionEvent.name) {
EthUtils.accountsChanged -> {
val (_, chainReference, _) = sessionEvent.data.split(":")
Web3Modal.chains.find { it.chainReference == chainReference }?.let { chain -> saveChainSelectionUseCase(chain.id) }
}
EthUtils.chainChanged -> {
val (chainReference, _) = sessionEvent.data.split(".")
Web3Modal.chains.find { it.chainReference == chainReference }?.let { chain -> saveChainSelectionUseCase(chain.id) }
}
}
} catch (throwable: Throwable) {
onError(Modal.Model.Error(throwable))
}
}

override fun onSessionDelete(deletedSession: Modal.Model.DeletedSession) {
scope.launch {
deleteSessionDataUseCase()
_wcEventModels.emit(deletedSession)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.walletconnect.web3.modal.domain.usecase

import com.walletconnect.web3.modal.domain.SessionRepository
import kotlinx.coroutines.runBlocking

internal class GetSelectedChainUseCase(
private val repository: SessionRepository
) {
operator fun invoke() = repository.getSelectedChain()
operator fun invoke() = runBlocking { repository.getSelectedChain() }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.walletconnect.web3.modal.domain.usecase

import com.walletconnect.web3.modal.domain.SessionRepository
import kotlinx.coroutines.runBlocking

internal class GetSessionTopicUseCase(
private val repository: SessionRepository
) {
operator fun invoke() = repository.getSessionTopic()
operator fun invoke() = runBlocking { repository.getSessionTopic() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ private const val CHOOSE_NETWORK_ARG = "{chooseNetwork}"
private val web3ModalPath = Route.WEB3MODAL.path + "/" + CHOOSE_NETWORK_ARG

fun NavGraphBuilder.web3Modal() {
dialog<Web3ModalSheet>(web3ModalPath)
dialog<Web3ModalSheet>(web3ModalPath) { argument(CHOOSE_NETWORK_KEY) { type = NavType.BoolType } }
}

fun NavController.openWeb3Modal(
Expand Down
Loading

0 comments on commit ffd7af3

Please sign in to comment.