globalesim: explicit create button, no auto-provision
- Commit
f4456162fe0f5d9bac7386c4a4db64cd0136e609- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-24 18:26 UTC (1 month ago)
- Parents
9b103e6
Diff
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 84ba0d8f4c..e78510ad34 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt@@ -23,6 +23,7 @@ fun Navigation(viewModel: EsimViewModel) { HomeScreen( state = viewModel.state, onTopUp = viewModel::topUp,+ onCreateEsim = viewModel::createEsim, onStartCardPurchase = viewModel::startCardPurchase, onCardPurchaseDone = { viewModel.clearPendingPurchase()
globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.ktindex eaaf8dd575..c5902cef50 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt@@ -38,14 +38,31 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { init { viewModelScope.launch {- val id = idStore.getOrCreate()- runCatching { EsimApi.register(id) }+ // Mint the anonymous id only. Provisioning happens on explicit+ // user action (createEsim) — never on launch, since each+ // provision is a real $1.75 vendor charge.+ idStore.getOrCreate() refreshAll() } } private suspend fun accountId(): String = idStore.getOrCreate() + /**+ * Explicit user action: provision the account's one eSIM. Each call is+ * a real vendor charge, so the UI gates this behind a confirmation+ * button — it is NEVER called on launch. Idempotent server-side:+ * re-tapping an existing account returns its profile.+ */+ fun createEsim() {+ viewModelScope.launch {+ state = state.copy(loading = true, error = null)+ runCatching { EsimApi.register(accountId()) }+ .onSuccess { refreshAll() }+ .onFailure { state = state.copy(loading = false, error = it.message) }+ }+ }+ fun dismissError() { state = state.copy(error = null) }
globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.ktindex bf29ce58b5..4f3ba5dcba 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt@@ -42,6 +42,7 @@ import com.vayunmathur.library.ui.rememberMessenger fun HomeScreen( state: EsimUiState, onTopUp: (Long) -> Unit,+ onCreateEsim: () -> Unit, onStartCardPurchase: (amountCents: Long, publishableKey: String?, onKey: (String) -> Unit, onSheetReady: () -> Unit) -> Unit, onCardPurchaseDone: () -> Unit, onStartCryptoPurchase: (Long) -> Unit,@@ -108,11 +109,20 @@ fun HomeScreen( if (state.loading && profile == null) { LoadingIndicator() } else if (profile == null) {- Text("Setting up your eSIM…")+ Text("One global eSIM for 200+ countries.") Text(- "Your global eSIM is being created. Pull to refresh.",- modifier = Modifier.padding(top = 8.dp),+ "Pay as you go (~$1/GB), credit never expires, " ++ "no email needed. Creating your eSIM reserves " ++ "it on the network.",+ modifier = Modifier.padding(top = 4.dp), )+ Button(+ onClick = onCreateEsim,+ enabled = !state.loading,+ modifier = Modifier.fillMaxWidth().padding(top = 12.dp),+ ) {+ Text("Create my eSIM")+ } } else { Text("Status: ${profile.status}") Text(
globalesim/src/screenshotTest/kotlin/com/vayunmathur/globalesim/ui/MetadataPreviews.kt
diff --git a/globalesim/src/screenshotTest/kotlin/com/vayunmathur/globalesim/ui/MetadataPreviews.kt b/globalesim/src/screenshotTest/kotlin/com/vayunmathur/globalesim/ui/MetadataPreviews.ktindex f4f677510a..9a6516cbfd 100644--- a/globalesim/src/screenshotTest/kotlin/com/vayunmathur/globalesim/ui/MetadataPreviews.kt+++ b/globalesim/src/screenshotTest/kotlin/com/vayunmathur/globalesim/ui/MetadataPreviews.kt@@ -40,6 +40,7 @@ class MetadataPreviews { HomeScreen( state = EsimUiState(profile = demoProfile, budgetCents = 2000), onTopUp = {},+ onCreateEsim = {}, onStartCardPurchase = { _, _, _, _ -> }, onCardPurchaseDone = {}, onStartCryptoPurchase = {},