Skip to content

Commit

Permalink
[W3M/WCM] Handle on proposal expired event
Browse files Browse the repository at this point in the history
  • Loading branch information
kacperoak committed Jan 25, 2024
1 parent 029c4f7 commit 268bd2c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ internal fun RedirectOnHoldScreen(
.collect {
when (it) {
is Modal.Model.RejectedSession -> redirectState.value = RedirectState.Reject
else -> redirectState.value = RedirectState.Loading
is Modal.Model.ExpiredProposal -> redirectState.value = RedirectState.Expired
else -> Unit
}
}
}
Expand Down Expand Up @@ -159,6 +160,19 @@ private fun RedirectStateContent(state: RedirectState, wallet: Wallet) {
VerticalSpacer(height = 20.dp)
Text(text = "Connection declined", color = ModalTheme.colors.errorColor)
}

RedirectState.Expired -> {
WalletImage(
url = wallet.imageUrl,
modifier = Modifier
.border(1.dp, ModalTheme.colors.errorColor, shape = RoundedCornerShape(22.dp))
.size(90.dp)
.padding(4.dp)
.clip(RoundedCornerShape(20.dp))
)
VerticalSpacer(height = 20.dp)
Text(text = "Connection expired", color = ModalTheme.colors.errorColor)
}
}
}

Expand Down Expand Up @@ -287,5 +301,5 @@ private fun OnHoldScreenPreview(

private class RedirectStateProvider : PreviewParameterProvider<RedirectState> {
override val values: Sequence<RedirectState>
get() = sequenceOf(RedirectState.Loading, RedirectState.Reject)
get() = sequenceOf(RedirectState.Loading, RedirectState.Reject, RedirectState.Expired)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package com.walletconnect.wcmodal.ui.routes.on_hold
internal sealed class RedirectState {
object Loading : RedirectState()
object Reject : RedirectState()
object Expired: RedirectState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ package com.walletconnect.web3.modal.ui.routes.connect.redirect
sealed class RedirectState {
object Loading: RedirectState()
object Reject: RedirectState()
object Expired: RedirectState()
object NotDetected: RedirectState()
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ internal fun RedirectWalletRoute(

LaunchedEffect(Unit) {
Web3ModalDelegate.wcEventModels.collect {
redirectState = when (it) {
is Modal.Model.RejectedSession -> RedirectState.Reject
else -> RedirectState.Loading
when (it) {
is Modal.Model.RejectedSession -> { redirectState = RedirectState.Reject }
is Modal.Model.ExpiredProposal -> { redirectState = RedirectState.Expired }
else -> Unit
}
}
}
Expand Down Expand Up @@ -242,7 +243,7 @@ private fun LandscapeRedirectContent(
horizontalAlignment = Alignment.CenterHorizontally
) {
RedirectLabel(state = redirectState, wallet = wallet)
if (redirectState == RedirectState.NotDetected || redirectState == RedirectState.Reject) {
if (redirectState != RedirectState.Loading) {
VerticalSpacer(height = 20.dp)
TryAgainButton(onClick = onMobileRetry)
}
Expand Down Expand Up @@ -273,7 +274,7 @@ private fun WalletImageBox(
when {
redirectState == RedirectState.NotDetected || platformTab == PlatformTab.WEB -> RoundedWalletImage(url = wallet.imageUrl)
redirectState == RedirectState.Loading -> WalletImageWithLoader(url = wallet.imageUrl)
redirectState == RedirectState.Reject -> RejectWalletImage(wallet.imageUrl)
redirectState == RedirectState.Reject || redirectState == RedirectState.Expired -> RejectWalletImage(wallet.imageUrl)
}
}
}
Expand All @@ -291,14 +292,18 @@ private fun RedirectLabel(state: RedirectState, wallet: Wallet) {
description = "Accept connection request in your wallet app"
descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200)
}

RedirectState.Reject -> {
header = "Connection declined"
description = "Connection can be declined if a previous request is still active"
headerStyle = Web3ModalTheme.typo.paragraph400.copy(Web3ModalTheme.colors.error)
descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200)
}

RedirectState.Expired -> {
header = "Connection expired"
description = String.Empty
headerStyle = Web3ModalTheme.typo.paragraph400.copy(Web3ModalTheme.colors.error)
descriptionStyle = Web3ModalTheme.typo.small400.copy(color = Web3ModalTheme.colors.foreground.color200)
}
RedirectState.NotDetected -> {
header = "App not installed"
description = String.Empty
Expand Down Expand Up @@ -354,7 +359,7 @@ private fun RedirectMobileWalletScreen(
) {
when (redirectState) {
RedirectState.Loading -> LoadingState(state, wallet, onRetry, onCopyLinkClick)
RedirectState.Reject -> RejectedState(state, wallet, onRetry)
RedirectState.Reject, RedirectState.Expired -> RejectedOrExpiredState(state, wallet, onRetry)
RedirectState.NotDetected -> NotDetectedWalletState(state, wallet, onOpenPlayStore)
}
}
Expand Down Expand Up @@ -432,7 +437,7 @@ private fun RoundedWalletImage(url: String) {
}

@Composable
private fun RejectedState(
private fun RejectedOrExpiredState(
state: RedirectState,
wallet: Wallet,
onRetry: () -> Unit
Expand Down Expand Up @@ -488,6 +493,16 @@ private fun PreviewRedirectWalletScreenWithRejectedState() {
}
}

@UiModePreview
@Landscape
@Composable
private fun PreviewRedirectWalletScreenWithExpiredState() {
val wallet = testWallets.first()
Web3ModalPreview(wallet.name) {
RedirectWalletScreen(redirectState = RedirectState.Expired, platformTab = PlatformTab.MOBILE, {}, wallet, {}, {}, {}, {})
}
}

@UiModePreview
@Landscape
@Composable
Expand Down

0 comments on commit 268bd2c

Please sign in to comment.