Skip to content

Commit

Permalink
Navigation hotfix for new root navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Milan-Cerovsky committed Jan 10, 2025
1 parent 3f02a56 commit 915d8d4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 69 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this application adheres to [Semantic Versioning](https://semver.org/spec/v2

## [Unreleased]

### Fixed
- Fixed an issue when the application did not clean navigation stack after clicking View Transactions after
successful transaction

## [1.3.2 (828)] - 2025-01-09

### Changed
Expand Down
4 changes: 4 additions & 0 deletions docs/whatsNew/WHATS_NEW_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ directly impact users rather than highlighting other key architectural updates.*

## [Unreleased]

### Fixed
- Fixed an issue when the application did not clean navigation stack after clicking View Transactions after
successful transaction

## [1.3.2 (828)] - 2025-01-09

### Changed
Expand Down
4 changes: 4 additions & 0 deletions docs/whatsNew/WHATS_NEW_ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ directly impact users rather than highlighting other key architectural updates.*

## [Unreleased]

### Fixed
- Fixed an issue when the application did not clean navigation stack after clicking View Transactions after
successful transaction

## [1.3.2 (828)] - 2025-01-09

### Cambiado
Expand Down
67 changes: 31 additions & 36 deletions ui-lib/src/main/java/co/electriccoin/zcash/ui/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,47 +123,36 @@ internal fun MainActivity.Navigation() {
LaunchedEffect(Unit) {
navigationRouter.observe().collect {
when (it) {
is NavigationCommand.Forward.ByRoute -> {
navController.navigate(it.route)
}
is NavigationCommand.Forward.ByTypeSafetyRoute<*> -> {
is NavigationCommand.Forward ->
if (it.route is ExternalUrl) {
WebBrowserUtil.startActivity(this@Navigation, it.route.url)
return@collect
} else {
navController.navigate(it.route)
}
}
is NavigationCommand.Replace.ByRoute -> {
navController.navigate(it.route) {
popUpTo(navController.currentBackStackEntry?.destination?.id ?: 0) {
inclusive = true
}
navController.executeNavigation(route = it.route)
}
}
is NavigationCommand.Replace.ByTypeSafetyRoute<*> -> {
is NavigationCommand.Replace ->
if (it.route is ExternalUrl) {
navController.popBackStack()
WebBrowserUtil.startActivity(this@Navigation, it.route.url)
return@collect
} else {
navController.navigate(it.route) {
navController.executeNavigation(route = it.route) {
popUpTo(navController.currentBackStackEntry?.destination?.id ?: 0) {
inclusive = true
}
}
}
}
NavigationCommand.Back -> {
navController.popBackStack()
}
is NavigationCommand.NewRoot ->
navController.executeNavigation(route = it.route) {
popUpTo(HOME) {
inclusive = true
}
}
NavigationCommand.Back -> navController.popBackStack()

NavigationCommand.BackToRoot -> {
NavigationCommand.BackToRoot ->
navController.popBackStack(
destinationId = navController.graph.startDestinationId,
inclusive = false
)
}
}
}
}
Expand Down Expand Up @@ -512,6 +501,25 @@ fun NavHostController.navigateJustOnce(
}
}

private fun NavHostController.executeNavigation(
route: Any,
builder: (NavOptionsBuilder.() -> Unit)? = null
) {
if (route is String) {
if (builder == null) {
navigate(route)
} else {
navigate(route, builder)
}
} else {
if (builder == null) {
navigate(route)
} else {
navigate(route, builder)
}
}
}

/**
* Pops up the current screen from the back stack. Parameter currentRouteToBePopped is meant to be
* set only to the current screen so we can easily debounce multiple screen popping from the back stack.
Expand All @@ -528,20 +536,7 @@ fun NavHostController.popBackStackJustOnce(currentRouteToBePopped: String) {
object NavigationArguments {
const val SEND_SCAN_RECIPIENT_ADDRESS = "send_scan_recipient_address"
const val SEND_SCAN_ZIP_321_URI = "send_scan_zip_321_uri"

const val SEND_CONFIRM_RECIPIENT_ADDRESS = "send_confirm_recipient_address"
const val SEND_CONFIRM_AMOUNT = "send_confirm_amount"
const val SEND_CONFIRM_MEMO = "send_confirm_memo"
const val SEND_CONFIRM_PROPOSAL = "send_confirm_proposal"
const val SEND_CONFIRM_INITIAL_STAGE = "send_confirm_initial_stage"

const val MULTIPLE_SUBMISSION_CLEAR_FORM = "multiple_submission_clear_form"

const val PAYMENT_REQUEST_ADDRESS = "payment_request_address"
const val PAYMENT_REQUEST_AMOUNT = "payment_request_amount"
const val PAYMENT_REQUEST_MEMO = "payment_request_memo"
const val PAYMENT_REQUEST_PROPOSAL = "payment_request_proposal"
const val PAYMENT_REQUEST_URI = "payment_request_uri"
}

object NavigationTargets {
Expand Down
38 changes: 12 additions & 26 deletions ui-lib/src/main/java/co/electriccoin/zcash/ui/NavigationRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

interface NavigationRouter {
fun forward(route: String)
fun forward(route: Any)

fun <T : Any> forward(route: T)
fun replace(route: Any)

fun replace(route: String)

fun <T : Any> replace(route: T)
fun newRoot(route: Any)

fun back()

Expand All @@ -29,27 +27,21 @@ class NavigationRouterImpl : NavigationRouter {

private val channel = Channel<NavigationCommand>()

override fun forward(route: String) {
scope.launch {
channel.send(NavigationCommand.Forward.ByRoute(route))
}
}

override fun <T : Any> forward(route: T) {
override fun forward(route: Any) {
scope.launch {
channel.send(NavigationCommand.Forward.ByTypeSafetyRoute(route))
channel.send(NavigationCommand.Forward(route))
}
}

override fun replace(route: String) {
override fun replace(route: Any) {
scope.launch {
channel.send(NavigationCommand.Replace.ByRoute(route))
channel.send(NavigationCommand.Replace(route))
}
}

override fun <T : Any> replace(route: T) {
override fun newRoot(route: Any) {
scope.launch {
channel.send(NavigationCommand.Replace.ByTypeSafetyRoute(route))
channel.send(NavigationCommand.NewRoot(route))
}
}

Expand All @@ -69,17 +61,11 @@ class NavigationRouterImpl : NavigationRouter {
}

sealed interface NavigationCommand {
sealed interface Forward : NavigationCommand {
data class ByRoute(val route: String) : Forward

data class ByTypeSafetyRoute<T : Any>(val route: T) : Forward
}
data class Forward(val route: Any) : NavigationCommand

sealed interface Replace : NavigationCommand {
data class ByRoute(val route: String) : Replace
data class Replace(val route: Any) : NavigationCommand

data class ByTypeSafetyRoute<T : Any>(val route: T) : Replace
}
data class NewRoot(val route: Any) : NavigationCommand

data object Back : NavigationCommand

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package co.electriccoin.zcash.ui.common.usecase
import co.electriccoin.zcash.ui.NavigationRouter
import co.electriccoin.zcash.ui.screen.selectkeystoneaccount.SelectKeystoneAccount
import com.sparrowwallet.hummingbird.UR
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class ParseKeystoneSignInRequestUseCase(
private val navigationRouter: NavigationRouter
Expand All @@ -14,13 +16,14 @@ class ParseKeystoneSignInRequestUseCase(

@Suppress("TooGenericExceptionCaught")
@Throws(InvalidKeystoneSignInQRException::class)
private fun parseOrThrow(ur: UR) {
try {
keystoneSDK.parseZcashAccounts(ur)
} catch (e: Exception) {
throw InvalidKeystoneSignInQRException(e)
private suspend fun parseOrThrow(ur: UR) =
withContext(Dispatchers.Default) {
try {
keystoneSDK.parseZcashAccounts(ur)
} catch (e: Exception) {
throw InvalidKeystoneSignInQRException(e)
}
}
}
}

class InvalidKeystoneSignInQRException(cause: Throwable) : Exception(cause)
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class ViewTransactionsAfterSuccessfulProposalUseCase(
zashiProposalRepository.clear()
keystoneProposalRepository.clear()
observeClearSend.requestClear()
navigationRouter.forward(HOME)
navigationRouter.newRoot(HOME)
}
}

0 comments on commit 915d8d4

Please sign in to comment.