globalesim: tabs are sibling routes (#nav)
- Commit
13bdb25bde91e549b66c0c7b33870018ba76b209- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-16 19:56 UTC (19 days ago)
- Parents
e9edbfe
Retire Route.Tabs and make Route.Purchase and Route.Pricing real sibling destinations. Navigation starts on Purchase and uses the route-backed TabbedPagerScaffold (RouteTab, same labels, icons and order) with MainNavigation hosted in its content slot; both tab entries are registered with SiblingPage(), so switching resets the stack instead of scrolling a pager. The one-shot ViewModel message effect moves from the old tab host to the Navigation host level, so messages are still shown exactly once no matter which tab produced them or is on top. The Stripe payment launchers keep flowing into the Purchase (HomeScreen) entry unchanged. AGENTS entry-point reading order now names the two new routes. Tests: the route serialization check now encodes Route.Purchase, the stale Tabs self-assertion is dropped, and navigationRendersTabsOffline clicks the Pricing tab and asserts the pricing search field appears. Verified on devvm21958 (no push): - ./gradlew :globalesim:compileDevKotlin :globalesim:testDevUnitTest — green
Diff
globalesim/AGENTS.md
diff --git a/globalesim/AGENTS.md b/globalesim/AGENTS.mdindex 788edc02fe..55d0ef9ba0 100644--- a/globalesim/AGENTS.md+++ b/globalesim/AGENTS.md@@ -19,7 +19,7 @@ _Install: ./install globalesim (dev by default)._ - Rate catalog (server-scaled to the wallet's face value), Stripe card and NOWPayments crypto (+5%) top-ups, $5–$20 per payment - One-tap install via the standard `https://esimsetup.android.com/esim_qrcode_provisioning?carddata=LPA:1$<smdp>$<code>` link (unpinned ACTION_VIEW, raw carddata) **Architecture / data-flow:** `ui/` screens → `platform/EsimViewModel` (single `EsimUiState`) → `data/api/EsimApi` (own `/esim/v1/*` on api.maproj.org, FIRST_PARTY) with pure `domain/QuoteMath` and `data/AnonymousIdStore` (DataStore UUID). The reseller vendor is server-only (`location_share_server/src/handlers/esim*.rs`) and never named here.-**Entry points + reading order:** `Route.Tabs` (Purchase + Pricing tabs, no other routes) → `MainActivity.kt` → `Navigation.kt` → `platform/EsimViewModel.kt` → `data/api/EsimApi.kt`.+**Entry points + reading order:** `Route.Purchase` / `Route.Pricing` (sibling tab routes, no other routes) → `MainActivity.kt` → `Navigation.kt` → `platform/EsimViewModel.kt` → `data/api/EsimApi.kt`. **Gotchas:** - After any payment the ViewModel polls `/status` until the wallet rises (server-owned pending checkout + `pending_credit_cents` keep it going); pull-to-refresh on Purchase reloads status - One open crypto checkout per account, owned by the server and restored from `/status`
globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.ktindex a3faecbb00..ffe8b6302b 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt@@ -1,7 +1,6 @@ package com.vayunmathur.globalesim import android.content.Intent-import androidx.compose.foundation.pager.rememberPagerState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.platform.LocalContext@@ -12,31 +11,22 @@ import com.vayunmathur.globalesim.ui.HomeScreen import com.vayunmathur.globalesim.ui.PricingScreen import com.vayunmathur.library.ui.IconGlobe import com.vayunmathur.library.ui.IconSim-import com.vayunmathur.library.ui.PagerTab-import com.vayunmathur.library.ui.TabStyle+import com.vayunmathur.library.ui.RouteTab import com.vayunmathur.library.ui.TabbedPagerScaffold import com.vayunmathur.library.ui.rememberMessenger import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.SiblingPage import com.vayunmathur.library.util.rememberNavBackStack -@Composable-fun Navigation(viewModel: EsimViewModel, launchers: CardPaymentLaunchers? = null) {- val backStack = rememberNavBackStack<Route>(Route.Tabs)-- MainNavigation(backStack) {- entry<Route.Tabs> {- EsimTabs(viewModel = viewModel, launchers = launchers)- }- }-}- /**- * The two bottom-nav tabs: Purchase (your eSIM + top-ups) and Pricing- * (searchable per-country rates). ViewModel messages are shown here, once,- * rather than by each tab (both tabs stay composed in the pager).+ * The two bottom-nav tabs as sibling routes: Purchase (your eSIM + top-ups)+ * and Pricing (searchable per-country rates), switched by resetting the+ * back stack. ViewModel messages are shown here at the host, once, rather+ * than by each tab screen. */ @Composable-private fun EsimTabs(viewModel: EsimViewModel, launchers: CardPaymentLaunchers?) {+fun Navigation(viewModel: EsimViewModel, launchers: CardPaymentLaunchers? = null) {+ val backStack = rememberNavBackStack<Route>(Route.Purchase) val context = LocalContext.current val messenger = rememberMessenger() val message = viewModel.state.message@@ -46,26 +36,32 @@ private fun EsimTabs(viewModel: EsimViewModel, launchers: CardPaymentLaunchers?) viewModel.dismissMessage() } }- val pagerState = rememberPagerState(pageCount = { 2 })- val tabs = listOf(- PagerTab("Purchase", { IconSim() }) {- HomeScreen(- state = viewModel.state,- launchers = launchers,- onStartCardPurchase = viewModel::startCardPurchase,- onStartCryptoPurchase = { cents ->- viewModel.startCryptoPurchase(cents) { url ->- context.startActivity(Intent(Intent.ACTION_VIEW, url.toUri()))- }- },- onClearCryptoInvoice = viewModel::clearPendingInvoice,- onClaim = viewModel::claim,- onRefresh = viewModel::refresh,- )- },- PagerTab("Pricing", { IconGlobe() }) {- PricingScreen(state = viewModel.state, onRefresh = viewModel::refreshRates)- },- )- TabbedPagerScaffold(tabs = tabs, pagerState = pagerState, tabStyle = TabStyle.BottomNav)+ TabbedPagerScaffold(+ backStack = backStack,+ tabs = listOf<RouteTab<Route>>(+ RouteTab(Route.Purchase, "Purchase") { IconSim() },+ RouteTab(Route.Pricing, "Pricing") { IconGlobe() },+ ),+ ) {+ MainNavigation(backStack) {+ entry<Route.Purchase>(metadata = SiblingPage()) {+ HomeScreen(+ state = viewModel.state,+ launchers = launchers,+ onStartCardPurchase = viewModel::startCardPurchase,+ onStartCryptoPurchase = { cents ->+ viewModel.startCryptoPurchase(cents) { url ->+ context.startActivity(Intent(Intent.ACTION_VIEW, url.toUri()))+ }+ },+ onClearCryptoInvoice = viewModel::clearPendingInvoice,+ onClaim = viewModel::claim,+ onRefresh = viewModel::refresh,+ )+ }+ entry<Route.Pricing>(metadata = SiblingPage()) {+ PricingScreen(state = viewModel.state, onRefresh = viewModel::refreshRates)+ }+ }+ } }
globalesim/src/main/java/com/vayunmathur/globalesim/Route.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/Route.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/Route.ktindex 9286e276e1..dfb8d3f325 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/Route.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/Route.kt@@ -6,7 +6,11 @@ import kotlinx.serialization.Serializable /** Contract for route. */ @Serializable sealed interface Route : NavKey {- /** Tab host: Purchase + Pricing. */+ /** Purchase tab (sibling route): your eSIM, balance and top-ups. */ @Serializable- data object Tabs : Route+ data object Purchase : Route++ /** Pricing tab (sibling route): searchable per-country rates. */+ @Serializable+ data object Pricing : Route }
globalesim/src/test/java/com/vayunmathur/globalesim/platform/EsimViewModelTest.kt
diff --git a/globalesim/src/test/java/com/vayunmathur/globalesim/platform/EsimViewModelTest.kt b/globalesim/src/test/java/com/vayunmathur/globalesim/platform/EsimViewModelTest.ktindex e18c9cfac1..164d3f60f6 100644--- a/globalesim/src/test/java/com/vayunmathur/globalesim/platform/EsimViewModelTest.kt+++ b/globalesim/src/test/java/com/vayunmathur/globalesim/platform/EsimViewModelTest.kt@@ -143,8 +143,8 @@ class EsimViewModelTest { @Test fun routeAndStateValueSemantics() { val encoded = kotlinx.serialization.json.Json.encodeToString( com.vayunmathur.globalesim.Route.serializer(),- com.vayunmathur.globalesim.Route.Tabs)- assertTrue(encoded.contains("Tabs"), encoded)+ com.vayunmathur.globalesim.Route.Purchase)+ assertTrue(encoded.contains("Purchase"), encoded) val s = EsimUiState(loading = true, simId = "x") assertEquals(s, s.copy()) assertEquals(s.hashCode(), s.copy().hashCode())
globalesim/src/test/java/com/vayunmathur/globalesim/ui/PricingSheetComposeTest.kt
diff --git a/globalesim/src/test/java/com/vayunmathur/globalesim/ui/PricingSheetComposeTest.kt b/globalesim/src/test/java/com/vayunmathur/globalesim/ui/PricingSheetComposeTest.ktindex 8d1eddf395..cc399242a6 100644--- a/globalesim/src/test/java/com/vayunmathur/globalesim/ui/PricingSheetComposeTest.kt+++ b/globalesim/src/test/java/com/vayunmathur/globalesim/ui/PricingSheetComposeTest.kt@@ -110,6 +110,8 @@ class PricingSheetComposeTest { val vm = EsimViewModel(app) composeRule.setContent { DynamicTheme { Navigation(viewModel = vm) } } composeRule.onAllNodesWithText("Purchase")[0].assertIsDisplayed()- assertEquals(Route.Tabs, Route.Tabs)+ composeRule.onAllNodesWithText("Pricing")[0].performClick()+ composeRule.waitForIdle()+ composeRule.onNodeWithText("Search countries", substring = true).assertExists() } }