From eb55b85633757b58984e65a4dfa003d984146b06 Mon Sep 17 00:00:00 2001 From: Kacper Date: Wed, 15 Nov 2023 17:18:54 +0100 Subject: [PATCH] Disconnect improvements and fixes --- .../com/walletconnect/web3/modal/client/Web3Modal.kt | 4 ++-- .../ui/components/internal/Web3ModalComponent.kt | 11 ++++++++--- .../ui/components/internal/snackbar/ModalSnackBar.kt | 4 ++++ .../components/internal/snackbar/ModalSnackbarHost.kt | 1 + .../web3/modal/ui/routes/account/AccountState.kt | 2 +- 5 files changed, 16 insertions(+), 6 deletions(-) diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt index 8ceaa0cd99..8a7fff87ef 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/client/Web3Modal.kt @@ -144,6 +144,7 @@ object Web3Modal { } override fun onSessionDelete(deletedSession: Sign.Model.DeletedSession) { + scope.launch { deleteSessionDataUseCase() } delegate.onSessionDelete(deletedSession.toModal()) } @@ -210,11 +211,10 @@ object Web3Modal { onError(InvalidSessionException.toModalError()) return } - + scope.launch { deleteSessionDataUseCase() } SignClient.disconnect( Sign.Params.Disconnect(sessionTopic), { - scope.launch { deleteSessionDataUseCase() } onSuccess(it.toModal()) }, { onError(it.toModal()) } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt index 2136128542..47da117742 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/Web3ModalComponent.kt @@ -42,10 +42,15 @@ fun Web3ModalComponent( LaunchedEffect(Unit) { Web3ModalDelegate .wcEventModels - .filterIsInstance() .onEach { event -> - web3ModalViewModel.saveSession(event) - closeModal() + when(event) { + is Modal.Model.ApprovedSession -> { + web3ModalViewModel.saveSession(event) + closeModal() + } + is Modal.Model.DeletedSession.Success -> { closeModal() } + else -> Unit + } } .collect() } diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt index ce00b5f248..ef62b91da0 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackBar.kt @@ -34,6 +34,10 @@ internal fun ModalSnackBar( Row( modifier = Modifier .height(40.dp) + .background( + color = Web3ModalTheme.colors.background.color125, + shape = shape + ) .background( color = Web3ModalTheme.colors.grayGlass05, shape = shape diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt index 0ef7024636..297017f32d 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/components/internal/snackbar/ModalSnackbarHost.kt @@ -39,6 +39,7 @@ internal fun ModalSnackBarHost( visible = isVisibleSnackBar, modifier = Modifier .padding(top = 10.dp) + .padding(horizontal = 60.dp) .align(Alignment.TopCenter), enter = fadeIn() + scaleIn(), exit = fadeOut() + scaleOut() diff --git a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt index 61e9f7f16c..b924154de5 100644 --- a/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt +++ b/product/web3modal/src/main/kotlin/com/walletconnect/web3/modal/ui/routes/account/AccountState.kt @@ -113,12 +113,12 @@ internal class AccountState( fun disconnect() { Web3Modal.disconnect( onSuccess = { - coroutineScope.launch { deleteSessionDataUseCase() } coroutineScope.launch(Dispatchers.Main) { closeModal() } }, onError = { showError(it.throwable.localizedMessage) logger.error(it.throwable) + coroutineScope.launch(Dispatchers.Main) { closeModal() } } ) }