globalesim: travel data eSIM storefront app
- Commit
ee85bcadafbd7f262963178dff0b494e8f359e84- Author
- vayun-mathur <[email protected]>
- When
- 2026-10-24 07:13 UTC (1 month ago)
- Parents
b24dc08
Diff
.github/ISSUE_TEMPLATE/bug_report.yml
diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.ymlindex 22ced00fbf..e21d9f4dec 100644--- a/.github/ISSUE_TEMPLATE/bug_report.yml+++ b/.github/ISSUE_TEMPLATE/bug_report.yml@@ -33,6 +33,7 @@ body: - findfamily - flashcards - fooddelivery+ - globalesim - health - hub - keyboard
.github/ISSUE_TEMPLATE/feature_request.yml
diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.ymlindex 799d591177..8257f36126 100644--- a/.github/ISSUE_TEMPLATE/feature_request.yml+++ b/.github/ISSUE_TEMPLATE/feature_request.yml@@ -33,6 +33,7 @@ body: - findfamily - flashcards - fooddelivery+ - globalesim - health - hub - keyboard
.github/workflows/issue_labeler.yml
diff --git a/.github/workflows/issue_labeler.yml b/.github/workflows/issue_labeler.ymlindex 0650bac276..eb847fa7d9 100644--- a/.github/workflows/issue_labeler.yml+++ b/.github/workflows/issue_labeler.yml@@ -21,7 +21,7 @@ jobs: if (match && match[1]) { const selectedApp = match[1].trim().toLowerCase();- const validApps = ['appstore', 'arrows', 'astronomy', 'auto', 'backup', 'calculator', 'calendar', 'camera', 'cast', 'chess', 'clock', 'code', 'communicate', 'contacts', 'education', 'email', 'emergency', 'euicc', 'everysync', 'files', 'findfamily', 'flashcards', 'fooddelivery', 'health', 'hub', 'kart', 'keyboard', 'launcher', 'logicgate', 'logviewer', 'maps', 'measure', 'minesweeper', 'music', 'networklocation', 'nonogram', 'notes', 'office', 'openassistant', 'passwords', 'pdf', 'photos', 'pipes', 'parentalcontrols', 'screentime', 'setupwizard', 'share', 'securemail', 'solitaire', 'speech', 'sudoku', 'taxi', 'things', 'todo', 'translate', 'travel', 'tuner', 'unblockjam', 'uniflix', 'updater', 'vpn', 'watch', 'voxels', 'weather', 'web', 'wordmaker', 'youpipe'];+ const validApps = ['appstore', 'arrows', 'astronomy', 'auto', 'backup', 'calculator', 'calendar', 'camera', 'cast', 'chess', 'clock', 'code', 'communicate', 'contacts', 'education', 'email', 'emergency', 'euicc', 'everysync', 'files', 'findfamily', 'flashcards', 'fooddelivery', 'globalesim', 'health', 'hub', 'kart', 'keyboard', 'launcher', 'logicgate', 'logviewer', 'maps', 'measure', 'minesweeper', 'music', 'networklocation', 'nonogram', 'notes', 'office', 'openassistant', 'passwords', 'pdf', 'photos', 'pipes', 'parentalcontrols', 'screentime', 'setupwizard', 'share', 'securemail', 'solitaire', 'speech', 'sudoku', 'taxi', 'things', 'todo', 'translate', 'travel', 'tuner', 'unblockjam', 'uniflix', 'updater', 'vpn', 'watch', 'voxels', 'weather', 'web', 'wordmaker', 'youpipe']; if (validApps.includes(selectedApp)) { await github.rest.issues.addLabels({
README.md
diff --git a/README.md b/README.mdindex b9fc57fd63..5d216c0fa2 100644--- a/README.md+++ b/README.md@@ -70,6 +70,7 @@ Though some apps may have exceptions, generally a 64-bit device running at least | **Find Family** | MA-1 | [Homepage](https://maproj.org/apps/findfamily) | [](https://f-droid.org/packages/com.vayunmathur.findfamily) | [](https://api.maproj.org/obtainium-link?name=Find%20Family&packageName=com.vayunmathur.findfamily&apk=findfamily-release.apk) | | **Flashcards** | MA-3 | [Homepage](https://maproj.org/apps/flashcards) | [](https://f-droid.org/packages/com.vayunmathur.flashcards/) | [](https://api.maproj.org/obtainium-link?name=Flashcards&packageName=com.vayunmathur.flashcards&apk=flashcards-release.apk) | | **Food Delivery (US only)** | MA-E | [Homepage](https://maproj.org/apps/fooddelivery) | [](https://f-droid.org/packages/com.vayunmathur.fooddelivery/) | [](https://api.maproj.org/obtainium-link?name=Food%20Delivery&packageName=com.vayunmathur.fooddelivery&apk=fooddelivery-release.apk) |+| **Global eSIM** | MA-E | [Homepage](https://maproj.org/apps/globalesim) | In Progress | In Progress | | **Health** | MA-2 | [Homepage](https://maproj.org/apps/health) | [](https://f-droid.org/packages/com.vayunmathur.health/) | [](https://api.maproj.org/obtainium-link?name=Health&packageName=com.vayunmathur.health&apk=health-release.apk) | | **Keyboard** | MA-2 | [Homepage](https://maproj.org/apps/keyboard) | [](https://f-droid.org/packages/com.vayunmathur.keyboard/) | [](https://api.maproj.org/obtainium-link?name=Keyboard&packageName=com.vayunmathur.keyboard&apk=keyboard-release.apk) | | **Launcher** | MA-C | [Homepage](https://maproj.org/apps/launcher) | [](https://f-droid.org/packages/com.vayunmathur.launcher/) | [](https://api.maproj.org/obtainium-link?name=Launcher&packageName=com.vayunmathur.launcher&apk=launcher-release.apk) |
globalesim/AGENTS.md
diff --git a/globalesim/AGENTS.md b/globalesim/AGENTS.mdnew file mode 100644index 0000000000..6d2f519e0b--- /dev/null+++ b/globalesim/AGENTS.md@@ -0,0 +1,53 @@+# AGENTS.md — globalesim/ (':globalesim')++> Scoped supplement. Global rules in root `AGENTS.md` apply. Stay inside `globalesim/` + allowed shared modules. Do not root-scan.++_Install: ./install globalesim (dev by default)._+<!-- last-reviewed: 2026-10-24 -->+- Gradle: :globalesim / dir: globalesim/+- Package roots present: ui, data, domain, platform+- Entry files: MainActivity.kt, Route.kt, Navigation.kt+- Deps: :library:network, :library:ui (via conventions), androidx.datastore.preferences, stripe-android+- Metadata: metadata_data/globalesim.md (present)+- Rust: no / screenshotTest: yes++## Overview+**Purpose:** Travel data eSIM storefront. One global eSIM per anonymous account — top up USD credit, data deducts at the local per-country rate. Credit never expires.+**Key features:**+- Anonymous account (client-minted UUIDv4, no email/PII) with transfer codes for new phones+- Rate catalog, wallet top-ups (budget pool → on-SIM wallet), Stripe card purchases+- One-tap install handoff to the euicc LPA (`EsimLink.provisioningUri` pinned to LPA package)+**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` (`Home` / `Rates` / `Install` / `Transfer` / `Budget`) → `MainActivity.kt` → `Navigation.kt` → `platform/EsimViewModel.kt` → `data/api/EsimApi.kt`.+**Gotchas:**+- Top-up buttons disable while loading; each attempt carries a fresh idempotency key, server dedupes replays+- PaymentSheet presents from `pendingClientSecret` via LaunchedEffect; cleared on done/cancel+- Install shows no QR/code — same-phone QR is unscannable; direct LPA handoff only+- `rememberPaymentSheet` is deprecated in stripe-android 23.x (same as fooddelivery); leave until repo migrates++## Key files+### Root — entry + navigation+- com/vayunmathur/globalesim/MainActivity.kt+- com/vayunmathur/globalesim/Navigation.kt+- com/vayunmathur/globalesim/Route.kt+### data/ — api + anonymous id+- com/vayunmathur/globalesim/data/api/EsimApi.kt — BASE_URL + url(path) + NetworkClient calls+- com/vayunmathur/globalesim/data/api/EsimDtos.kt — generic DTOs only, no vendor strings+- com/vayunmathur/globalesim/data/AnonymousIdStore.kt+### domain/ — pure math (no Android)+- com/vayunmathur/globalesim/domain/QuoteMath.kt+### platform/ — ViewModel+- com/vayunmathur/globalesim/platform/EsimViewModel.kt+### ui/ — one public @Composable per file+- com/vayunmathur/globalesim/ui/HomeScreen.kt+- com/vayunmathur/globalesim/ui/RatesScreen.kt+- com/vayunmathur/globalesim/ui/InstallScreen.kt+- com/vayunmathur/globalesim/ui/TransferScreen.kt+- com/vayunmathur/globalesim/ui/BudgetScreen.kt++## Verify (this module only)+```+./gradlew :globalesim:compileDevKotlin+./gradlew :globalesim:lint+./gradlew :globalesim:testDevUnitTest+```
globalesim/build.gradle.kts
diff --git a/globalesim/build.gradle.kts b/globalesim/build.gradle.ktsnew file mode 100644index 0000000000..751cda944d--- /dev/null+++ b/globalesim/build.gradle.kts@@ -0,0 +1,29 @@+plugins {+ id("common-conventions-app")+ // Listing screenshots come from Compose previews (src/screenshotTest), not from an+ // instrumented test on a device. Same `:globalesim:metadata` task name either way.+ id("common-conventions-preview-metadata")+}++launcherIcon {+ symbol = "travel_explore"+}++android {+ defaultConfig {+ applicationId = "com.vayunmathur.globalesim"+ }+}++dependencies {+ // First-party backend (api.maproj.org) over pinned TLS roots.+ implementation(project(":library:network"))+ // Anonymous account id persistence.+ implementation(libs.androidx.datastore.preferences)+ // Credit top-ups via Stripe PaymentSheet (server creates the+ // PaymentIntent; the secret key never leaves the server).+ implementation(libs.stripe.android)+ // stripe-android applies the kotlin-parcelize compiler plugin but never publishes+ // kotlin-parcelize-runtime in its POM (see fooddelivery/build.gradle.kts).+ implementation(libs.kotlin.parcelize.runtime)+}
globalesim/src/main/AndroidManifest.xml
diff --git a/globalesim/src/main/AndroidManifest.xml b/globalesim/src/main/AndroidManifest.xmlnew file mode 100644index 0000000000..e15375f2a6--- /dev/null+++ b/globalesim/src/main/AndroidManifest.xml@@ -0,0 +1,27 @@+<?xml version="1.0" encoding="utf-8"?>+<manifest xmlns:android="http://schemas.android.com/apk/res/android">++ <uses-permission android:name="android.permission.INTERNET" />+ <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />++ <application+ android:allowBackup="true"+ android:dataExtractionRules="@xml/data_extraction_rules"+ android:icon="@mipmap/ic_launcher"+ android:label="@string/app_name"+ android:roundIcon="@mipmap/ic_launcher"+ android:supportsRtl="true"+ android:theme="@style/Theme.General">+ <activity+ android:configChanges="mcc|mnc|colorMode|density|fontScale|fontWeightAdjustment|keyboard|keyboardHidden|layoutDirection|navigation|orientation|screenLayout|screenSize|smallestScreenSize|touchscreen|uiMode"+ android:name=".MainActivity"+ android:exported="true"+ android:theme="@style/Theme.General">+ <intent-filter>+ <action android:name="android.intent.action.MAIN" />+ <category android:name="android.intent.category.LAUNCHER" />+ </intent-filter>+ </activity>+ </application>++</manifest>
globalesim/src/main/java/com/vayunmathur/globalesim/MainActivity.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/MainActivity.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/MainActivity.ktnew file mode 100644index 0000000000..00e0001fa2--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/MainActivity.kt@@ -0,0 +1,24 @@+package com.vayunmathur.globalesim++import androidx.activity.viewModels+import androidx.compose.runtime.Composable+import com.vayunmathur.globalesim.platform.EsimViewModel+import com.vayunmathur.library.network.NetworkClient+import com.vayunmathur.library.network.TrustBundle+import com.vayunmathur.library.ui.MaActivity++class MainActivity : MaActivity() {+ private val viewModel: EsimViewModel by viewModels()++ override fun onCreateBeforeContent() {+ // First-party backend only (api.maproj.org): Cloudflare Universal SSL+ // roots in FIRST_PARTY. The reseller vendor is never contacted here —+ // all vendor calls stay server-side behind /esim/v1/*.+ NetworkClient.init(this, TrustBundle.FIRST_PARTY)+ }++ @Composable+ override fun Content() {+ Navigation(viewModel)+ }+}
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.ktnew file mode 100644index 0000000000..1054e86ea2--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/Navigation.kt@@ -0,0 +1,69 @@+package com.vayunmathur.globalesim++import androidx.compose.runtime.Composable+import com.vayunmathur.globalesim.platform.EsimViewModel+import com.vayunmathur.globalesim.ui.BudgetScreen+import com.vayunmathur.globalesim.ui.HomeScreen+import com.vayunmathur.globalesim.ui.InstallScreen+import com.vayunmathur.globalesim.ui.RatesScreen+import com.vayunmathur.globalesim.ui.TransferScreen+import com.vayunmathur.library.util.MainNavigation+import com.vayunmathur.library.util.rememberNavBackStack++@Composable+fun Navigation(viewModel: EsimViewModel) {+ val backStack = rememberNavBackStack<Route>(Route.Home)++ MainNavigation(backStack) {+ entry<Route.Home> {+ HomeScreen(+ state = viewModel.state,+ onTopUp = viewModel::topUp,+ onStartCardPurchase = viewModel::startCardPurchase,+ onCardPurchaseDone = {+ viewModel.clearPendingPurchase()+ viewModel.refreshAll()+ },+ onOpenInstall = { backStack.add(Route.Install) },+ onOpenRates = { backStack.add(Route.Rates) },+ onOpenBudget = { backStack.add(Route.Budget) },+ onOpenTransfer = { backStack.add(Route.Transfer) },+ onRefresh = viewModel::refreshAll,+ onDismissError = viewModel::dismissError,+ )+ }+ entry<Route.Rates> {+ RatesScreen(+ state = viewModel.state,+ onNavigateBack = { backStack.pop() },+ onRefresh = viewModel::refreshRates,+ onDismissError = viewModel::dismissError,+ )+ }+ entry<Route.Install> {+ InstallScreen(+ state = viewModel.state,+ onNavigateBack = { backStack.pop() },+ onDismissError = viewModel::dismissError,+ )+ }+ entry<Route.Transfer> {+ TransferScreen(+ state = viewModel.state,+ onTransferOut = viewModel::transferOut,+ onTransferIn = { oldId, code ->+ viewModel.transferIn(oldId, code) { backStack.reset(Route.Home) }+ },+ onNavigateBack = { backStack.pop() },+ )+ }+ entry<Route.Budget> {+ BudgetScreen(+ state = viewModel.state,+ onNavigateBack = { backStack.pop() },+ onRefresh = viewModel::refreshBudget,+ onDismissError = viewModel::dismissError,+ )+ }+ }+}
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.ktnew file mode 100644index 0000000000..ca59eede52--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/Route.kt@@ -0,0 +1,27 @@+package com.vayunmathur.globalesim++import com.vayunmathur.library.util.NavKey+import kotlinx.serialization.Serializable++@Serializable+sealed interface Route : NavKey {+ /** Home: your eSIM status + wallet + top-up. */+ @Serializable+ data object Home : Route++ /** Per-country rate list (what each GB deducts where you travel). */+ @Serializable+ data object Rates : Route++ /** Install detail: QR + handoff (reissues the same activation code). */+ @Serializable+ data object Install : Route++ /** Move the eSIM to a new phone. */+ @Serializable+ data object Transfer : Route++ /** Credit balance + top-up history. */+ @Serializable+ data object Budget : Route+}
globalesim/src/main/java/com/vayunmathur/globalesim/data/AnonymousIdStore.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/data/AnonymousIdStore.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/data/AnonymousIdStore.ktnew file mode 100644index 0000000000..ba56518133--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/data/AnonymousIdStore.kt@@ -0,0 +1,40 @@+package com.vayunmathur.globalesim.data++import android.content.Context+import androidx.datastore.preferences.core.edit+import androidx.datastore.preferences.core.stringPreferencesKey+import androidx.datastore.preferences.preferencesDataStore+import java.util.UUID+import kotlinx.coroutines.flow.Flow+import kotlinx.coroutines.flow.first+import kotlinx.coroutines.flow.map++private val Context.esimAccountStore by preferencesDataStore(name = "esim_account")++/**+ * Anonymous account id store. The id is a client-minted UUIDv4 — no email,+ * no PII. The same id (+ transfer code) reinstalls the user's eSIMs on a+ * new phone. Auto-registers with the backend on first use.+ */+class AnonymousIdStore(private val context: Context) {+ val accountId: Flow<String?> =+ context.esimAccountStore.data.map { it[KEY_ACCOUNT_ID] }++ /** Returns the existing id, or mints + persists a new UUIDv4. */+ suspend fun getOrCreate(): String {+ val existing = context.esimAccountStore.data.map { it[KEY_ACCOUNT_ID] }.first()+ if (existing != null) return existing+ val fresh = UUID.randomUUID().toString()+ context.esimAccountStore.edit { it[KEY_ACCOUNT_ID] = fresh }+ return fresh+ }++ /** Replaces the id (used after a transfer-in adopts the new device id). */+ suspend fun replace(newId: String) {+ context.esimAccountStore.edit { it[KEY_ACCOUNT_ID] = newId }+ }++ companion object {+ private val KEY_ACCOUNT_ID = stringPreferencesKey("account_id")+ }+}
globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimApi.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimApi.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimApi.ktnew file mode 100644index 0000000000..cbe9ad5670--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimApi.kt@@ -0,0 +1,62 @@+package com.vayunmathur.globalesim.data.api++import com.vayunmathur.library.network.NetworkClient+import kotlinx.serialization.json.Json+import kotlinx.serialization.serializer++/**+ * Thin client for our own eSIM storefront API (the esim-v1 routes on+ * api.maproj.org, FIRST_PARTY trust). Generic DTOs only — the reseller+ * vendor is contacted server-side and is never named here.+ */+object EsimApi {+ const val BASE_URL = "https://api.maproj.org"++ private val json = Json { ignoreUnknownKeys = true; isLenient = true }++ fun url(path: String): String = BASE_URL + path++ private suspend inline fun <reified Req, reified Res> post(path: String, body: Req): Res =+ NetworkClient.callJson(+ url = url(path),+ method = "POST",+ headers = mapOf("Content-Type" to "application/json"),+ body = json.encodeToString(serializer<Req>(), body),+ )++ private suspend inline fun <reified Res> get(path: String): Res =+ NetworkClient.getJson(url(path))++ suspend fun register(accountId: String): RegisterResponse =+ post("/esim/v1/register", RegisterRequest(accountId))++ suspend fun rates(): RatesResponse = get("/esim/v1/rates")++ suspend fun status(accountId: String): StatusResponse =+ post("/esim/v1/status", AccountRequest(accountId))++ suspend fun detail(accountId: String, iccid: String): ProfileDto =+ post("/esim/v1/detail", ManageRequest(accountId, iccid))++ suspend fun topUp(req: TopUpRequest): TopUpResponse = post("/esim/v1/topup", req)++ suspend fun enable(accountId: String, iccid: String): ManageResponse =+ post("/esim/v1/enable", ManageRequest(accountId, iccid))++ suspend fun disable(accountId: String, iccid: String): ManageResponse =+ post("/esim/v1/disable", ManageRequest(accountId, iccid))++ suspend fun transferOut(accountId: String): TransferOutResponse =+ post("/esim/v1/transfer-out", TransferOutRequest(accountId))++ suspend fun transferIn(oldAccountId: String, code: String, newAccountId: String): TransferInResponse =+ post("/esim/v1/transfer-in", TransferInRequest(oldAccountId, code, newAccountId))++ suspend fun budget(accountId: String): BudgetResponse =+ post("/esim/v1/budget", AccountRequest(accountId))++ suspend fun stripeKey(): StripeKeyResponse = get("/esim/v1/stripe-key")++ suspend fun stripeIntent(accountId: String, amountCents: Long): StripeIntentResponse =+ post("/esim/v1/stripe-intent", StripeIntentRequest(accountId, amountCents))+}
globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimDtos.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimDtos.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimDtos.ktnew file mode 100644index 0000000000..ccee6af97e--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimDtos.kt@@ -0,0 +1,98 @@+package com.vayunmathur.globalesim.data.api++import kotlinx.serialization.Serializable++/**+ * Generic eSIM storefront DTOs. These mirror our own esim-v1 API on+ * api.maproj.org — they contain no vendor names, URLs, or key material.+ * The reseller vendor is contacted server-side only and is never named here.+ *+ * Product model: one global eSIM per anonymous account. The user tops up+ * USD credit; data deducts from the on-SIM wallet at the local per-country+ * rate. Credit never expires.+ */++@Serializable+data class RegisterRequest(val accountId: String)++@Serializable+data class RegisterResponse(val ok: Boolean = false)++@Serializable+data class RateDto(+ val countryCode: String,+ val countryName: String,+ /** Integer USD cents per GB. Integer math only — no float money. */+ val pricePerGbUsdCents: Long,+)++@Serializable+data class RatesResponse(val rates: List<RateDto> = emptyList())++@Serializable+data class AccountRequest(val accountId: String)++/** The account's single global eSIM (null when not yet provisioned). */+@Serializable+data class ProfileDto(+ val iccid: String,+ val status: String,+ val activationCode: String = "",+ val smdpAddress: String = "",+ /** On-SIM wallet balance in USD cents. */+ val walletUsdCents: Long = 0,+)++@Serializable+data class StatusResponse(val profile: ProfileDto? = null)++@Serializable+data class TopUpRequest(+ val accountId: String,+ /** USD cents to move from budget to the on-SIM wallet. */+ val amountCents: Long,+ /** Client-minted UUIDv4 per tap; the server dedupes replays. */+ val idempotencyKey: String,+)++@Serializable+data class TopUpResponse(+ val walletUsdCents: Long = 0,+ val budgetUsdCents: Long = 0,+)++@Serializable+data class ManageRequest(val accountId: String, val iccid: String)++@Serializable+data class ManageResponse(val ok: Boolean = false)++@Serializable+data class TransferOutRequest(val accountId: String)++@Serializable+data class TransferOutResponse(val transferCode: String = "")++@Serializable+data class TransferInRequest(val oldAccountId: String, val code: String, val newAccountId: String)++@Serializable+data class TransferInResponse(val ok: Boolean = false)++@Serializable+data class BudgetResponse(+ /** User-paid credit pool in USD cents. */+ val budgetUsdCents: Long = 0,+)++@Serializable+data class StripeKeyResponse(val publishableKey: String = "")++@Serializable+data class StripeIntentRequest(val accountId: String, val amountCents: Long)++@Serializable+data class StripeIntentResponse(val clientSecret: String = "")++@Serializable+data class ErrorBody(val error: String = "", val message: String = "")
globalesim/src/main/java/com/vayunmathur/globalesim/domain/QuoteMath.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/domain/QuoteMath.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/domain/QuoteMath.ktnew file mode 100644index 0000000000..41953eb527--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/domain/QuoteMath.kt@@ -0,0 +1,20 @@+package com.vayunmathur.globalesim.domain++/**+ * Pure display math for the single-eSIM model. Integer cents only —+ * no float money anywhere. The server is authoritative; this is display-only.+ */+object QuoteMath {+ /** Rough USD headline: the cheapest rate rounds to ~$1/GB. */+ fun formatCents(cents: Long): String {+ val dollars = cents / 100+ val rem = (cents % 100).toString().padStart(2, '0')+ return "$$dollars.$rem"+ }++ /** Data MB a wallet balance buys at a per-GB price. Floor — never overpromise. */+ fun mbFor(pricePerGbCents: Long, walletCents: Long): Long {+ if (pricePerGbCents <= 0) return 0+ return walletCents * 1024 / pricePerGbCents+ }+}
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.ktnew file mode 100644index 0000000000..58a856024c--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt@@ -0,0 +1,170 @@+package com.vayunmathur.globalesim.platform++import android.app.Application+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import androidx.lifecycle.AndroidViewModel+import androidx.lifecycle.viewModelScope+import com.vayunmathur.globalesim.data.AnonymousIdStore+import com.vayunmathur.globalesim.data.api.EsimApi+import com.vayunmathur.globalesim.data.api.ProfileDto+import com.vayunmathur.globalesim.data.api.RateDto+import com.vayunmathur.globalesim.data.api.TopUpRequest+import java.util.UUID+import kotlinx.coroutines.launch++/** UI state for the single-eSIM storefront. */+data class EsimUiState(+ val loading: Boolean = false,+ val profile: ProfileDto? = null,+ val rates: List<RateDto> = emptyList(),+ val budgetCents: Long? = null,+ val transferCode: String? = null,+ val pendingClientSecret: String? = null,+ val pendingAmountCents: Long = 0,+ val error: String? = null,+)++class EsimViewModel(app: Application) : AndroidViewModel(app) {+ private val idStore = AnonymousIdStore(app.applicationContext)++ var state by mutableStateOf(EsimUiState())+ private set++ init {+ viewModelScope.launch {+ val id = idStore.getOrCreate()+ runCatching { EsimApi.register(id) }+ refreshAll()+ }+ }++ private suspend fun accountId(): String = idStore.getOrCreate()++ fun dismissError() {+ state = state.copy(error = null)+ }++ fun refreshAll() {+ refreshStatus()+ refreshRates()+ refreshBudget()+ }++ fun refreshStatus() {+ viewModelScope.launch {+ state = state.copy(loading = true, error = null)+ runCatching { EsimApi.status(accountId()) }+ .onSuccess { state = state.copy(loading = false, profile = it.profile) }+ .onFailure { state = state.copy(loading = false, error = it.message) }+ }+ }++ fun refreshRates() {+ viewModelScope.launch {+ runCatching { EsimApi.rates() }+ .onSuccess { state = state.copy(rates = it.rates) }+ .onFailure { state = state.copy(error = it.message) }+ }+ }++ fun refreshBudget() {+ viewModelScope.launch {+ runCatching { EsimApi.budget(accountId()) }+ .onSuccess { state = state.copy(budgetCents = it.budgetUsdCents) }+ .onFailure { state = state.copy(error = it.message) }+ }+ }++ /**+ * Move credit from budget to the on-SIM wallet. One attempt per call;+ * the caller disables the button while [EsimUiState.loading] so a+ * double-tap cannot double-charge. Each attempt carries a fresh+ * idempotency key and the server dedupes replays.+ */+ fun topUp(amountCents: Long) {+ viewModelScope.launch {+ state = state.copy(loading = true, error = null)+ val req = TopUpRequest(accountId(), amountCents, UUID.randomUUID().toString())+ runCatching { EsimApi.topUp(req) }+ .onSuccess {+ state = state.copy(+ loading = false,+ budgetCents = it.budgetUsdCents,+ profile = state.profile?.copy(walletUsdCents = it.walletUsdCents),+ )+ refreshStatus()+ }+ .onFailure { state = state.copy(loading = false, error = it.message) }+ }+ }++ fun setEnabled(iccid: String, enabled: Boolean) {+ viewModelScope.launch {+ runCatching {+ if (enabled) EsimApi.enable(accountId(), iccid)+ else EsimApi.disable(accountId(), iccid)+ }+ .onSuccess { refreshStatus() }+ .onFailure { state = state.copy(error = it.message) }+ }+ }++ fun transferOut() {+ viewModelScope.launch {+ state = state.copy(loading = true, error = null, transferCode = null)+ runCatching { EsimApi.transferOut(accountId()) }+ .onSuccess { state = state.copy(loading = false, transferCode = it.transferCode) }+ .onFailure { state = state.copy(loading = false, error = it.message) }+ }+ }++ /**+ * Start a card purchase: fetch the publishable key (once per process)+ * and a PaymentIntent for [amountCents]. The screen presents the+ * PaymentSheet with the resulting client secret; the server credits+ * the budget via the Stripe webhook, and [onSheetReady] fires so the+ * screen can present immediately.+ */+ fun startCardPurchase(amountCents: Long, publishableKey: String?, onKey: (String) -> Unit, onSheetReady: () -> Unit) {+ viewModelScope.launch {+ state = state.copy(loading = true, error = null, pendingClientSecret = null)+ runCatching {+ val key = publishableKey ?: EsimApi.stripeKey().publishableKey+ val intent = EsimApi.stripeIntent(accountId(), amountCents)+ Triple(key, intent.clientSecret, amountCents)+ }+ .onSuccess { (key, secret, amount) ->+ onKey(key)+ state = state.copy(+ loading = false,+ pendingClientSecret = secret,+ pendingAmountCents = amount,+ )+ onSheetReady()+ }+ .onFailure { state = state.copy(loading = false, error = it.message) }+ }+ }++ /** Clear the pending sheet secret after it completes or is cancelled. */+ fun clearPendingPurchase() {+ state = state.copy(pendingClientSecret = null, pendingAmountCents = 0, loading = false)+ }++ fun transferIn(oldAccountId: String, code: String, onDone: () -> Unit) {+ viewModelScope.launch {+ state = state.copy(loading = true, error = null)+ val fresh = UUID.randomUUID().toString()+ runCatching { EsimApi.transferIn(oldAccountId, code.trim(), fresh) }+ .onSuccess {+ idStore.replace(fresh)+ state = state.copy(loading = false, transferCode = null)+ refreshAll()+ onDone()+ }+ .onFailure { state = state.copy(loading = false, error = it.message) }+ }+ }+}
globalesim/src/main/java/com/vayunmathur/globalesim/ui/BudgetScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/BudgetScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/BudgetScreen.ktnew file mode 100644index 0000000000..c3bad43984--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/BudgetScreen.kt@@ -0,0 +1,73 @@+package com.vayunmathur.globalesim.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import com.vayunmathur.globalesim.domain.QuoteMath+import com.vayunmathur.globalesim.platform.EsimUiState+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconRefresh+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberMessenger++/**+ * Credit balance: the user-paid pool that top-ups draw from. Newly moved+ * credit can take ~15 minutes to show full speed while the network+ * confirms payment. (Stripe card top-up lands here in Phase 4.)+ */+@Composable+fun BudgetScreen(+ state: EsimUiState,+ onNavigateBack: () -> Unit,+ onRefresh: () -> Unit,+ onDismissError: () -> Unit,+) {+ val messenger = rememberMessenger()+ val error = state.error+ LaunchedEffect(error) {+ if (error != null) {+ messenger.show(error)+ onDismissError()+ }+ }+ AppScaffold(+ title = "Credit",+ scrollBehavior = appBarScrollBehavior(),+ onNavigateBack = onNavigateBack,+ actions = {+ IconButton(onClick = onRefresh) { IconRefresh() }+ },+ ) { padding ->+ Column(Modifier.padding(padding).padding(16.dp)) {+ Card(Modifier.fillMaxWidth()) {+ Column(Modifier.padding(16.dp)) {+ val cents = state.budgetCents+ Text(+ if (cents == null) "Balance unknown — pull to refresh."+ else "Credit: ${QuoteMath.formatCents(cents)}",+ )+ val wallet = state.profile?.walletUsdCents+ if (wallet != null) {+ Text(+ "On eSIM: ${QuoteMath.formatCents(wallet)}",+ modifier = Modifier.padding(top = 4.dp),+ )+ }+ if (cents != null && cents < 500) {+ Text(+ "Low credit: top up from Home before your wallet runs out.",+ modifier = Modifier.padding(top = 8.dp),+ )+ }+ }+ }+ }+ }+}
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.ktnew file mode 100644index 0000000000..5351210340--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/HomeScreen.kt@@ -0,0 +1,214 @@+package com.vayunmathur.globalesim.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.unit.dp+import com.stripe.android.PaymentConfiguration+import com.stripe.android.paymentsheet.PaymentSheet+import com.stripe.android.paymentsheet.PaymentSheetResult+import com.stripe.android.paymentsheet.rememberPaymentSheet+import com.vayunmathur.globalesim.domain.QuoteMath+import com.vayunmathur.globalesim.platform.EsimUiState+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconRefresh+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.LoadingIndicator+import com.vayunmathur.library.ui.OutlinedButton+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberMessenger++/**+ * Home: your global eSIM at a glance — status, wallet balance, one-tap+ * top-up presets, and links to rates / install / budget / transfer.+ * One eSIM per account: no country picking, no per-trip buying.+ */+@Composable+fun HomeScreen(+ state: EsimUiState,+ onTopUp: (Long) -> Unit,+ onStartCardPurchase: (amountCents: Long, publishableKey: String?, onKey: (String) -> Unit, onSheetReady: () -> Unit) -> Unit,+ onCardPurchaseDone: () -> Unit,+ onOpenInstall: () -> Unit,+ onOpenRates: () -> Unit,+ onOpenBudget: () -> Unit,+ onOpenTransfer: () -> Unit,+ onRefresh: () -> Unit,+ onDismissError: () -> Unit,+) {+ val messenger = rememberMessenger()+ val error = state.error+ LaunchedEffect(error) {+ if (error != null) {+ messenger.show(error)+ onDismissError()+ }+ }+ val context = LocalContext.current+ var publishableKey by remember { mutableStateOf<String?>(null) }+ var sheetError by remember { mutableStateOf<String?>(null) }+ val paymentSheet = rememberPaymentSheet { result ->+ when (result) {+ is PaymentSheetResult.Completed -> {+ messenger.show("Payment complete — credit lands shortly.")+ onCardPurchaseDone()+ }+ is PaymentSheetResult.Canceled -> {+ onCardPurchaseDone()+ }+ is PaymentSheetResult.Failed -> {+ sheetError = result.error.localizedMessage ?: "Payment failed"+ onCardPurchaseDone()+ }+ }+ }+ sheetError?.let { messenger.show(it) }+ // Present the sheet when the client secret lands. The secret is cleared+ // on completion/cancel so a recomposition never re-presents.+ val pendingSecret = state.pendingClientSecret+ LaunchedEffect(pendingSecret) {+ if (pendingSecret != null) {+ paymentSheet.presentWithPaymentIntent(+ pendingSecret,+ PaymentSheet.Configuration("Global eSIM"),+ )+ }+ }+ AppScaffold(+ title = "Global eSIM",+ scrollBehavior = appBarScrollBehavior(),+ actions = {+ IconButton(onClick = onRefresh) { IconRefresh() }+ },+ ) { padding ->+ Column(+ Modifier.padding(padding).padding(16.dp).verticalScroll(rememberScrollState()),+ ) {+ val profile = state.profile+ Card(Modifier.fillMaxWidth()) {+ Column(Modifier.padding(16.dp)) {+ if (state.loading && profile == null) {+ LoadingIndicator()+ } else if (profile == null) {+ Text("Setting up your eSIM…")+ Text(+ "Your global eSIM is being created. Pull to refresh.",+ modifier = Modifier.padding(top = 8.dp),+ )+ } else {+ Text("Status: ${profile.status}")+ Text(+ "Wallet: ${QuoteMath.formatCents(profile.walletUsdCents)}",+ modifier = Modifier.padding(top = 4.dp),+ )+ Text(+ "Works in 200+ countries · credit never expires",+ modifier = Modifier.padding(top = 4.dp),+ )+ }+ }+ }+ if (profile != null) {+ TopUpCard(+ loading = state.loading,+ onTopUp = onTopUp,+ onBuyWithCard = { cents ->+ onStartCardPurchase(+ cents,+ publishableKey,+ { key ->+ publishableKey = key+ PaymentConfiguration.init(context, key)+ },+ {},+ )+ },+ modifier = Modifier.padding(top = 12.dp),+ )+ OutlinedButton(+ onClick = onOpenInstall,+ modifier = Modifier.fillMaxWidth().padding(top = 12.dp),+ ) {+ Text("Install / reinstall eSIM")+ }+ OutlinedButton(+ onClick = onOpenRates,+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ ) {+ Text("Data rates by country")+ }+ OutlinedButton(+ onClick = onOpenBudget,+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ ) {+ Text("Credit balance")+ }+ OutlinedButton(+ onClick = onOpenTransfer,+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ ) {+ Text("Move to new phone")+ }+ }+ }+ }+}++/**+ * Fixed top-up presets. The button disables while a top-up is in flight+ * so a double-tap cannot double-charge; each attempt carries a fresh+ * idempotency key and the server dedupes replays.+ */+@Composable+private fun TopUpCard(+ loading: Boolean,+ onTopUp: (Long) -> Unit,+ onBuyWithCard: (Long) -> Unit,+ modifier: Modifier = Modifier,+) {+ Card(modifier.fillMaxWidth()) {+ Column(Modifier.padding(16.dp)) {+ Text("Top up credit")+ Text(+ "Tops up the eSIM wallet directly. ~$1/GB in most countries.",+ modifier = Modifier.padding(top = 4.dp),+ )+ val presets = listOf(500L to "$5", 1000L to "$10", 2000L to "$20")+ for ((cents, label) in presets) {+ Button(+ onClick = { onTopUp(cents) },+ enabled = !loading,+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ ) {+ Text("Add $label credit")+ }+ }+ Text(+ "Or pay by card — credit lands automatically after payment.",+ modifier = Modifier.padding(top = 8.dp),+ )+ for ((cents, label) in presets) {+ OutlinedButton(+ onClick = { onBuyWithCard(cents) },+ enabled = !loading,+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ ) {+ Text("Buy $label with card")+ }+ }+ }+ }+}
globalesim/src/main/java/com/vayunmathur/globalesim/ui/InstallScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/InstallScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/InstallScreen.ktnew file mode 100644index 0000000000..ab5563b9ed--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/InstallScreen.kt@@ -0,0 +1,86 @@+package com.vayunmathur.globalesim.ui++import android.content.Intent+import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.LocalContext+import androidx.compose.ui.unit.dp+import com.vayunmathur.globalesim.platform.EsimUiState+import com.vayunmathur.library.intents.euicc.EsimLink+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.LoadingIndicator+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberMessenger++/**+ * Install: one-tap direct install for the account's single eSIM. Goes+ * straight through the on-device eSIM manager ([EsimLink.provisioningUri]+ * pinned to the LPA package) — this app never duplicates LPA logic and+ * shows no code or QR. After a transfer, the same button installs the+ * reissued profile on the new phone.+ */+@Composable+fun InstallScreen(+ state: EsimUiState,+ onNavigateBack: () -> Unit,+ onDismissError: () -> Unit,+) {+ val messenger = rememberMessenger()+ val error = state.error+ LaunchedEffect(error) {+ if (error != null) {+ messenger.show(error)+ onDismissError()+ }+ }+ val context = LocalContext.current+ val profile = state.profile+ AppScaffold(+ title = "Install eSIM",+ scrollBehavior = appBarScrollBehavior(),+ onNavigateBack = onNavigateBack,+ ) { padding ->+ Column(Modifier.padding(padding).padding(16.dp)) {+ if (state.loading && profile == null) {+ LoadingIndicator()+ return@Column+ }+ if (profile == null || profile.activationCode.isEmpty()) {+ Text("Your eSIM is being created — check back in a minute.")+ return@Column+ }+ Card(Modifier.fillMaxWidth()) {+ Column(Modifier.padding(16.dp)) {+ Text("Status: ${profile.status}")+ Text(+ "One tap installs your global eSIM. It works in 200+ countries.",+ modifier = Modifier.padding(top = 4.dp),+ )+ }+ }+ Button(+ onClick = {+ val intent = Intent(+ Intent.ACTION_VIEW,+ EsimLink.provisioningUri(profile.activationCode),+ ).setPackage(EsimLink.LPA_PACKAGE)+ context.startActivity(intent)+ },+ modifier = Modifier.fillMaxWidth().padding(top = 16.dp),+ ) {+ Text("Install eSIM")+ }+ Text(+ "Already installed on another phone? Move it with a transfer code instead of installing twice.",+ modifier = Modifier.padding(top = 8.dp),+ )+ }+ }+}
globalesim/src/main/java/com/vayunmathur/globalesim/ui/RatesScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/RatesScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/RatesScreen.ktnew file mode 100644index 0000000000..fbd76a6402--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/RatesScreen.kt@@ -0,0 +1,72 @@+package com.vayunmathur.globalesim.ui++import androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.lazy.LazyColumn+import androidx.compose.foundation.lazy.items+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import com.vayunmathur.globalesim.domain.QuoteMath+import com.vayunmathur.globalesim.platform.EsimUiState+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.IconRefresh+import com.vayunmathur.library.ui.IconButton+import com.vayunmathur.library.ui.ListItem+import com.vayunmathur.library.ui.LoadingIndicator+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberMessenger++/**+ * Rate list: what one GB deducts in each country. Display-only — your+ * wallet is charged the local rate automatically as you use data.+ */+@Composable+fun RatesScreen(+ state: EsimUiState,+ onNavigateBack: () -> Unit,+ onRefresh: () -> Unit,+ onDismissError: () -> Unit,+) {+ val messenger = rememberMessenger()+ val error = state.error+ LaunchedEffect(error) {+ if (error != null) {+ messenger.show(error)+ onDismissError()+ }+ }+ AppScaffold(+ title = "Data rates",+ scrollBehavior = appBarScrollBehavior(),+ onNavigateBack = onNavigateBack,+ actions = {+ IconButton(onClick = onRefresh) { IconRefresh() }+ },+ ) { padding ->+ if (state.loading && state.rates.isEmpty()) {+ LoadingIndicator(Modifier.padding(padding))+ return@AppScaffold+ }+ if (state.rates.isEmpty()) {+ Text("Rates unavailable — pull to refresh.", Modifier.padding(padding).padding(16.dp))+ return@AppScaffold+ }+ LazyColumn(Modifier.fillMaxSize().padding(padding)) {+ items(state.rates, key = { it.countryCode }) { rate ->+ Card(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 6.dp)) {+ ListItem(+ headlineContent = { Text(rate.countryName) },+ supportingContent = {+ Text("${QuoteMath.formatCents(rate.pricePerGbUsdCents)} / GB")+ },+ )+ }+ }+ }+ }+}
globalesim/src/main/java/com/vayunmathur/globalesim/ui/TransferScreen.kt
diff --git a/globalesim/src/main/java/com/vayunmathur/globalesim/ui/TransferScreen.kt b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/TransferScreen.ktnew file mode 100644index 0000000000..fdab18793a--- /dev/null+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/ui/TransferScreen.kt@@ -0,0 +1,98 @@+package com.vayunmathur.globalesim.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.foundation.layout.fillMaxWidth+import androidx.compose.foundation.layout.padding+import androidx.compose.foundation.rememberScrollState+import androidx.compose.foundation.verticalScroll+import androidx.compose.runtime.Composable+import androidx.compose.runtime.LaunchedEffect+import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember+import androidx.compose.runtime.setValue+import androidx.compose.ui.Modifier+import androidx.compose.ui.unit.dp+import com.vayunmathur.globalesim.platform.EsimUiState+import com.vayunmathur.library.ui.AppScaffold+import com.vayunmathur.library.ui.Button+import com.vayunmathur.library.ui.Card+import com.vayunmathur.library.ui.LoadingIndicator+import com.vayunmathur.library.ui.OutlinedTextField+import com.vayunmathur.library.ui.Text+import com.vayunmathur.library.ui.appBarScrollBehavior+import com.vayunmathur.library.ui.rememberMessenger++/**+ * Device transfer: show a one-time code on the old phone, enter old id ++ * code on the new phone. The server moves the eSIM + credit and rotates+ * the code — codes are single-use.+ */+@Composable+fun TransferScreen(+ state: EsimUiState,+ onTransferOut: () -> Unit,+ onTransferIn: (oldAccountId: String, code: String) -> Unit,+ onNavigateBack: () -> Unit,+) {+ val messenger = rememberMessenger()+ val error = state.error+ // Shown once per failure, not on every recomposition.+ LaunchedEffect(error) {+ if (error != null) messenger.show(error)+ }+ var oldId by remember { mutableStateOf("") }+ var code by remember { mutableStateOf("") }+ AppScaffold(+ title = "Move to new phone",+ scrollBehavior = appBarScrollBehavior(),+ onNavigateBack = onNavigateBack,+ ) { padding ->+ Column(+ Modifier.padding(padding).padding(16.dp).verticalScroll(rememberScrollState()),+ ) {+ Card(Modifier.fillMaxWidth()) {+ Column(Modifier.padding(16.dp)) {+ Text("On this (old) phone")+ val shown = state.transferCode+ if (shown != null) {+ Text("Your code: $shown", modifier = Modifier.padding(top = 8.dp))+ Text("Enter it on the new phone. Single use.")+ } else {+ Button(+ onClick = onTransferOut,+ enabled = !state.loading,+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ ) {+ if (state.loading) LoadingIndicator() else Text("Show transfer code")+ }+ }+ }+ }+ Card(Modifier.fillMaxWidth().padding(top = 12.dp)) {+ Column(Modifier.padding(16.dp)) {+ Text("On the new phone")+ OutlinedTextField(+ value = oldId,+ onValueChange = { oldId = it },+ label = { Text("Old account id") },+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ )+ OutlinedTextField(+ value = code,+ onValueChange = { code = it },+ label = { Text("Transfer code") },+ modifier = Modifier.fillMaxWidth().padding(top = 8.dp),+ )+ Button(+ onClick = { onTransferIn(oldId, code) },+ enabled = !state.loading && oldId.isNotBlank() && code.isNotBlank(),+ modifier = Modifier.fillMaxWidth().padding(top = 12.dp),+ ) {+ Text("Claim eSIM on this phone")+ }+ }+ }+ }+ }+}
globalesim/src/main/res/values/strings.xml
diff --git a/globalesim/src/main/res/values/strings.xml b/globalesim/src/main/res/values/strings.xmlnew file mode 100644index 0000000000..41a33e0adc--- /dev/null+++ b/globalesim/src/main/res/values/strings.xml@@ -0,0 +1,4 @@+<?xml version="1.0" encoding="utf-8"?>+<resources>+ <string name="app_name">Global eSIM</string>+</resources>
globalesim/src/main/res/xml/data_extraction_rules.xml
diff --git a/globalesim/src/main/res/xml/data_extraction_rules.xml b/globalesim/src/main/res/xml/data_extraction_rules.xmlnew file mode 100644index 0000000000..f163d747a6--- /dev/null+++ b/globalesim/src/main/res/xml/data_extraction_rules.xml@@ -0,0 +1,25 @@+<?xml version="1.0" encoding="utf-8"?>+<!--+ Global eSIM. Audited state: the anonymous account id, written through+ DataStore into file/datastore/esim_account.preferences_pb. Everything else+ (rates cache, eSIM list) is refetched from api.maproj.org on launch.+ The rules include whole domains rather than that one file so that if further+ persistence is added later it is covered by default instead of being silently+ dropped.+-->+<data-extraction-rules>+ <cloud-backup>+ <include domain="root" path="." />+ <include domain="file" path="." />+ <include domain="database" path="." />+ <include domain="sharedpref" path="." />+ <include domain="external" path="." />+ </cloud-backup>+ <device-transfer>+ <include domain="root" path="." />+ <include domain="file" path="." />+ <include domain="database" path="." />+ <include domain="sharedpref" path="." />+ <include domain="external" path="." />+ </device-transfer>+</data-extraction-rules>
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.ktnew file mode 100644index 0000000000..602d1ded8f--- /dev/null+++ b/globalesim/src/screenshotTest/kotlin/com/vayunmathur/globalesim/ui/MetadataPreviews.kt@@ -0,0 +1,95 @@+package com.vayunmathur.globalesim.ui++import androidx.compose.runtime.Composable+import androidx.compose.ui.tooling.preview.Preview+import com.android.tools.screenshot.PreviewTest+import com.vayunmathur.globalesim.data.api.ProfileDto+import com.vayunmathur.globalesim.data.api.RateDto+import com.vayunmathur.globalesim.platform.EsimUiState+import com.vayunmathur.library.ui.DynamicTheme++private const val PHONE = "spec:width=411dp,height=891dp,dpi=420"++/**+ * Store listing images for `:globalesim`, rendered from Compose previews.+ * `./gradlew :globalesim:metadata` renders these into+ * `metadata_data/photos/globalesim/`. Literal state only — no ViewModel,+ * no network. Every preview needs both @PreviewTest and @Preview, must be+ * a class member, and is named Preview<N>… for listing order.+ */+class MetadataPreviews {+ private val demoProfile = ProfileDto(+ iccid = "8999201200000000001",+ status = "active",+ activationCode = "LPA:1$demo.example$CODE",+ smdpAddress = "demo.example",+ walletUsdCents = 1250,+ )+ private val demoRates = listOf(+ RateDto("US", "United States", 100),+ RateDto("JP", "Japan", 138),+ RateDto("FR", "France", 52),+ RateDto("GB", "United Kingdom", 95),+ )++ @PreviewTest+ @Preview(name = "1-home", device = PHONE, showSystemUi = true)+ @Composable+ fun Preview1Home() {+ DynamicTheme(darkTheme = true) {+ HomeScreen(+ state = EsimUiState(profile = demoProfile, budgetCents = 2000),+ onTopUp = {},+ onStartCardPurchase = { _, _, _, _ -> },+ onCardPurchaseDone = {},+ onOpenInstall = {},+ onOpenRates = {},+ onOpenBudget = {},+ onOpenTransfer = {},+ onRefresh = {},+ onDismissError = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "2-rates", device = PHONE, showSystemUi = true)+ @Composable+ fun Preview2Rates() {+ DynamicTheme(darkTheme = true) {+ RatesScreen(+ state = EsimUiState(rates = demoRates),+ onNavigateBack = {},+ onRefresh = {},+ onDismissError = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "3-install", device = PHONE, showSystemUi = true)+ @Composable+ fun Preview3Install() {+ DynamicTheme(darkTheme = true) {+ InstallScreen(+ state = EsimUiState(profile = demoProfile),+ onNavigateBack = {},+ onDismissError = {},+ )+ }+ }++ @PreviewTest+ @Preview(name = "4-budget", device = PHONE, showSystemUi = true)+ @Composable+ fun Preview4Budget() {+ DynamicTheme(darkTheme = true) {+ BudgetScreen(+ state = EsimUiState(profile = demoProfile, budgetCents = 2000),+ onNavigateBack = {},+ onRefresh = {},+ onDismissError = {},+ )+ }+ }+}
globalesim/src/test/java/com/vayunmathur/globalesim/domain/QuoteMathTest.kt
diff --git a/globalesim/src/test/java/com/vayunmathur/globalesim/domain/QuoteMathTest.kt b/globalesim/src/test/java/com/vayunmathur/globalesim/domain/QuoteMathTest.ktnew file mode 100644index 0000000000..433ea3b75f--- /dev/null+++ b/globalesim/src/test/java/com/vayunmathur/globalesim/domain/QuoteMathTest.kt@@ -0,0 +1,23 @@+package com.vayunmathur.globalesim.domain++import kotlin.test.Test+import kotlin.test.assertEquals++class QuoteMathTest {+ @Test+ fun formatsCents() {+ assertEquals("$5.00", QuoteMath.formatCents(500))+ assertEquals("$0.99", QuoteMath.formatCents(99))+ assertEquals("$20.00", QuoteMath.formatCents(2000))+ assertEquals("$0.00", QuoteMath.formatCents(0))+ }++ @Test+ fun mbForFloorsNeverOverpromises() {+ // $1 wallet at $1.38/GB ≈ 742 MB, floored.+ assertEquals(742L, QuoteMath.mbFor(138, 100))+ assertEquals(1024L, QuoteMath.mbFor(100, 100))+ assertEquals(0L, QuoteMath.mbFor(0, 100))+ assertEquals(0L, QuoteMath.mbFor(138, 0))+ }+}
metadata_data/globalesim.md
diff --git a/metadata_data/globalesim.md b/metadata_data/globalesim.mdnew file mode 100644index 0000000000..5a8db62744--- /dev/null+++ b/metadata_data/globalesim.md@@ -0,0 +1,11 @@+Global data eSIM, pay as you go, unexpiring, no KYC, ~$1/GB US, ~€0.5/GB EU++Features:+- One global eSIM that works in 200+ countries+- Pay as you go: top up credit, data deducts at the local per-GB rate+- Credit never expires and works everywhere you travel+- Anonymous account - no email or phone number needed+- Move your eSIM to a new phone with a transfer code+- Install with one tap via the on-device eSIM manager++Internet only used for: browsing rates, topping up and managing your eSIM
settings.gradle.kts
diff --git a/settings.gradle.kts b/settings.gradle.ktsindex 93d9c5c3d6..d2000c4a61 100644--- a/settings.gradle.kts+++ b/settings.gradle.kts@@ -109,6 +109,7 @@ include(":measure") include(":taxi") include(":communicate") include(":euicc")+include(":globalesim") include(":backup") include(":share") include(":launcher")