diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt index fa37c4a60..c4b644229 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/Web3WalletActivity.kt @@ -43,7 +43,7 @@ class Web3WalletActivity : AppCompatActivity() { private val connectionsViewModel = ConnectionsViewModel() private val requestPermissionLauncher = registerForActivityResult( - ActivityResultContracts.RequestPermission() + ActivityResultContracts.RequestPermission() ) { isGranted: Boolean -> if (isGranted) { // FCM SDK (and your app) can post notifications. @@ -93,7 +93,10 @@ class Web3WalletActivity : AppCompatActivity() { when (event) { is CoreEvent.Disconnect -> { connectionsViewModel.refreshConnections() - navController.navigate(Route.Connections.path) + + if (navController.currentDestination?.route != Route.Connections.path) { + navController.navigate(Route.Connections.path) + } } else -> Unit @@ -115,13 +118,13 @@ class Web3WalletActivity : AppCompatActivity() { connectionsViewModel: ConnectionsViewModel, ) { web3walletViewModel.sessionRequestStateFlow - .onEach { - if (it.arrayOfArgs.isNotEmpty()) { - web3walletViewModel.showRequestLoader(false) - navController.navigate(Route.SessionRequest.path) - } + .onEach { + if (it.arrayOfArgs.isNotEmpty()) { + web3walletViewModel.showRequestLoader(false) + navController.navigate(Route.SessionRequest.path) } - .launchIn(lifecycleScope) + } + .launchIn(lifecycleScope) web3walletViewModel.walletEvents .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED) @@ -129,25 +132,27 @@ class Web3WalletActivity : AppCompatActivity() { when (event) { is SignEvent.SessionProposal -> navController.navigate(Route.SessionProposal.path) is SignEvent.ExpiredRequest -> { - navController.popBackStack( - route = Route.Connections.path, - inclusive = false - ) + if (navController.currentDestination?.route != Route.Connections.path) { + navController.popBackStack(route = Route.Connections.path, inclusive = false) + } Toast.makeText(baseContext, "Request expired", Toast.LENGTH_SHORT).show() } - is SignEvent.Disconnect -> { - connectionsViewModel.refreshConnections() + is SignEvent.Disconnect -> { + connectionsViewModel.refreshConnections() + + if (navController.currentDestination?.route != Route.Connections.path) { navController.navigate(Route.Connections.path) } + } - is AuthEvent.OnRequest -> navController.navigate(Route.AuthRequest.path) - is SignEvent.SessionAuthenticate -> navController.navigate(Route.SessionAuthenticate.path) + is AuthEvent.OnRequest -> navController.navigate(Route.AuthRequest.path) + is SignEvent.SessionAuthenticate -> navController.navigate(Route.SessionAuthenticate.path) - else -> Unit - } + else -> Unit } - .launchIn(lifecycleScope) + } + .launchIn(lifecycleScope) } override fun onNewIntent(intent: Intent?) { @@ -170,7 +175,7 @@ class Web3WalletActivity : AppCompatActivity() { } if (intent?.dataString?.startsWith("kotlin-web3wallet://request") == false - && intent.dataString?.contains("requestId") == false + && intent.dataString?.contains("requestId") == false ) { navController.handleDeepLink(intent) } @@ -180,9 +185,9 @@ class Web3WalletActivity : AppCompatActivity() { // This is only necessary for API level >= 33 (TIRAMISU) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { if (ContextCompat.checkSelfPermission( - this, - android.Manifest.permission.POST_NOTIFICATIONS - ) == PackageManager.PERMISSION_GRANTED + this, + android.Manifest.permission.POST_NOTIFICATIONS + ) == PackageManager.PERMISSION_GRANTED ) { // FCM SDK (and your app) can post notifications. } else { diff --git a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/host/WalletSampleHost.kt b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/host/WalletSampleHost.kt index ec1f0691e..dae42b214 100644 --- a/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/host/WalletSampleHost.kt +++ b/sample/wallet/src/main/kotlin/com/walletconnect/sample/wallet/ui/routes/host/WalletSampleHost.kt @@ -79,7 +79,9 @@ fun WalletSampleHost( web3walletViewModel.eventsSharedFlow.collect { when (it) { is PairingEvent.Error -> { - navController.popBackStack(route = Route.Connections.path, inclusive = false) + if (navController.currentDestination?.route != Route.Connections.path) { + navController.popBackStack(route = Route.Connections.path, inclusive = false) + } Toast.makeText(navController.context, it.message, Toast.LENGTH_SHORT).show() }