Skip to content

Commit 595dfbb

Browse files
committed
refactor: Introduce nav routes hierarchy
1 parent e3f963f commit 595dfbb

35 files changed

+766
-790
lines changed

app/src/main/java/to/bitkit/ui/ContentView.kt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ fun ContentView(
144144
LaunchedEffect(appViewModel, navigator) {
145145
appViewModel.sendEffect.collect { effect ->
146146
when (effect) {
147-
is SendEffect.NavigateToAddress -> navigator.navigate(Routes.SendAddress)
148-
is SendEffect.NavigateToAmount -> navigator.navigate(Routes.SendAmount())
149-
is SendEffect.NavigateToScan -> navigator.navigate(Routes.SendQrScanner)
150-
is SendEffect.NavigateToCoinSelection -> navigator.navigate(Routes.SendCoinSelection)
151-
is SendEffect.NavigateToConfirm -> navigator.navigate(Routes.SendConfirm)
152-
is SendEffect.NavigateToQuickPay -> navigator.navigate(Routes.SendQuickPay)
153-
is SendEffect.NavigateToWithdrawConfirm -> navigator.navigate(Routes.SendWithdrawConfirm)
154-
is SendEffect.NavigateToWithdrawError -> navigator.navigate(Routes.SendWithdrawError)
155-
is SendEffect.NavigateToFee -> navigator.navigate(Routes.SendFeeRate)
156-
is SendEffect.NavigateToFeeCustom -> navigator.navigate(Routes.SendFeeCustom)
147+
is SendEffect.NavigateToAddress -> navigator.navigate(Routes.Send.Address)
148+
is SendEffect.NavigateToAmount -> navigator.navigate(Routes.Send.Amount())
149+
is SendEffect.NavigateToScan -> navigator.navigate(Routes.Send.QrScanner)
150+
is SendEffect.NavigateToCoinSelection -> navigator.navigate(Routes.Send.CoinSelection)
151+
is SendEffect.NavigateToConfirm -> navigator.navigate(Routes.Send.Confirm)
152+
is SendEffect.NavigateToQuickPay -> navigator.navigate(Routes.Send.QuickPay)
153+
is SendEffect.NavigateToWithdrawConfirm -> navigator.navigate(Routes.Send.WithdrawConfirm)
154+
is SendEffect.NavigateToWithdrawError -> navigator.navigate(Routes.Send.WithdrawError)
155+
is SendEffect.NavigateToFee -> navigator.navigate(Routes.Send.FeeRate)
156+
is SendEffect.NavigateToFeeCustom -> navigator.navigate(Routes.Send.FeeCustom)
157157
is SendEffect.PaymentSuccess -> {
158158
appViewModel.clearClipboardForAutoRead()
159-
navigator.navigate(Routes.SendSuccess)
159+
navigator.navigate(Routes.Send.Success)
160160
}
161161

162162
is SendEffect.PopBack -> navigator.popBackTo(effect.route)
@@ -310,8 +310,8 @@ fun ContentView(
310310
modifier = Modifier.align(Alignment.BottomCenter),
311311
) {
312312
TabBar(
313-
onSendClick = { navigator.navigate(Routes.SendRecipient) },
314-
onReceiveClick = { navigator.navigate(Routes.ReceiveQr) },
313+
onSendClick = { navigator.navigate(Routes.Send.Recipient) },
314+
onReceiveClick = { navigator.navigate(Routes.Receive.Qr) },
315315
onScanClick = { navigator.navigate(Routes.QrScanner) },
316316
)
317317
}

app/src/main/java/to/bitkit/ui/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ private fun OnboardingContent(
217217
appViewModel: AppViewModel,
218218
walletViewModel: WalletViewModel,
219219
) {
220-
val backStack = rememberNavBackStack(Routes.Terms)
220+
val backStack = rememberNavBackStack(Routes.Onboarding.Terms)
221221
val navigator = remember(backStack) { Navigator(backStack) }
222222
val isGeoBlocked by appViewModel.isGeoBlocked.collectAsStateWithLifecycle()
223223

app/src/main/java/to/bitkit/ui/components/AuthCheckScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fun AuthCheckScreen(
5454
}
5555

5656
AuthCheckAction.NAV_TO_RESET -> {
57-
navigator.navigate(Routes.ResetAndRestoreSettings)
57+
navigator.navigate(Routes.Settings.ResetAndRestore)
5858
}
5959
}
6060
},

app/src/main/java/to/bitkit/ui/components/DrawerMenu.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,29 +96,29 @@ fun DrawerMenu(
9696
scope.launch { drawerState.close() }
9797
},
9898
onActivityClick = {
99-
navigator.navigate(Routes.AllActivity)
99+
navigator.navigate(Routes.Activity.All)
100100
scope.launch { drawerState.close() }
101101
},
102102
onContactsClick = null, // TODO IMPLEMENT CONTACTS
103103
onProfileClick = null, // TODO IMPLEMENT PROFILE
104104
onWidgetsClick = {
105105
if (!hasSeenWidgetsIntro) {
106-
navigator.navigate(Routes.WidgetsIntro)
106+
navigator.navigate(Routes.Widgets.Intro)
107107
} else {
108-
navigator.navigate(Routes.AddWidget)
108+
navigator.navigate(Routes.Widgets.Add)
109109
}
110110
scope.launch { drawerState.close() }
111111
},
112112
onShopClick = {
113113
if (!hasSeenShopIntro) {
114-
navigator.navigate(Routes.ShopIntro)
114+
navigator.navigate(Routes.Shop.Intro)
115115
} else {
116-
navigator.navigate(Routes.ShopDiscover)
116+
navigator.navigate(Routes.Shop.Discover)
117117
}
118118
scope.launch { drawerState.close() }
119119
},
120120
onSettingsClick = {
121-
navigator.navigate(Routes.Settings)
121+
navigator.navigate(Routes.Settings.Main)
122122
scope.launch { drawerState.close() }
123123
},
124124
onAppStatusClick = {

app/src/main/java/to/bitkit/ui/nav/DeepLinks.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,42 +108,42 @@ class DeepLinkMatcher<T : Routes>(
108108
object DeepLinkPatterns {
109109
// bitkit:// scheme patterns
110110
val RECOVERY_MODE = DeepLinkPattern(
111-
routeClass = Routes.RecoveryMode::class,
111+
routeClass = Routes.Recovery.Mode::class,
112112
uriPattern = "${UriScheme.BITKIT.withSlashes}recovery-mode".toUri()
113113
)
114114

115115
// bitcoin:// scheme patterns (BIP21)
116116
// Note: bitcoin: URIs use address as "host" not path
117117
val SEND_BITCOIN = DeepLinkPattern(
118-
routeClass = Routes.SendAddress::class,
118+
routeClass = Routes.Send.Address::class,
119119
uriPattern = "${UriScheme.BITCOIN.withSlashes}{address}".toUri()
120120
)
121121

122122
// lightning:// scheme patterns
123123
val SEND_LIGHTNING = DeepLinkPattern(
124-
routeClass = Routes.SendAddress::class,
124+
routeClass = Routes.Send.Address::class,
125125
uriPattern = "${UriScheme.LIGHTNING.withSlashes}{invoice}".toUri()
126126
)
127127

128128
// lnurl:// scheme patterns
129129
val LNURL_PAY = DeepLinkPattern(
130-
routeClass = Routes.SendAddress::class,
130+
routeClass = Routes.Send.Address::class,
131131
uriPattern = "${UriScheme.LNURL_PAY.withSlashes}{data}".toUri()
132132
)
133133

134134
val LNURL_WITHDRAW = DeepLinkPattern(
135-
routeClass = Routes.ReceiveQr::class,
135+
routeClass = Routes.Receive.Qr::class,
136136
uriPattern = "${UriScheme.LNURL_WITHDRAW.withSlashes}{data}".toUri()
137137
)
138138

139139
val LNURL_CHANNEL = DeepLinkPattern(
140-
routeClass = Routes.LnurlChannel::class,
140+
routeClass = Routes.Sheet.LnurlChannel::class,
141141
uriPattern = "${UriScheme.LNURL_CHANNEL.withSlashes}{data}".toUri()
142142
)
143143

144144
// https:// scheme patterns (App Links)
145145
val TREASURE_HUNT = DeepLinkPattern(
146-
routeClass = Routes.GiftLoading::class,
146+
routeClass = Routes.Gift.Loading::class,
147147
uriPattern = "${UriScheme.HTTPS.withSlashes}www.bitkit.to/treasure-hunt".toUri()
148148
)
149149

app/src/main/java/to/bitkit/ui/nav/Navigator.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ class Navigator(@PublishedApi internal val backStack: NavBackStack<NavKey>) {
5151
fun isAtHome(): Boolean = backStack.lastOrNull() is Routes.Home
5252

5353
fun shouldShowTabBar(): Boolean = when (backStack.lastOrNull()) {
54-
is Routes.Home, is Routes.Savings, is Routes.Spending, is Routes.AllActivity -> true
54+
is Routes.Home, is Routes.Savings, is Routes.Spending, is Routes.Activity.All -> true
5555
else -> false
5656
}
57-
5857
}
5958

6059
const val MS_NAV_DELAY = 100L

0 commit comments

Comments
 (0)