globalesim: claiming a SIM ID adopts that id on this phone
- Commit
b27b93f241a657741e042156da1b30140be4a510- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-02 23:37 UTC (1 month ago)
- Parents
8175416
The server no longer moves the eSIM to the claiming phone's account; the SIM ID stays tied to the same ICCID. Claim now stores the claimed SIM ID as this install's account id. Drops the 'transferred' status handling and the 410 payment message.
Diff
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.ktindex 79829cff39..3417caea26 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/data/AnonymousIdStore.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/data/AnonymousIdStore.kt@@ -29,7 +29,7 @@ class AnonymousIdStore(private val context: Context) { return fresh } - /** Replaces the id (after this install's eSIM was claimed onto another phone). */+ /** Replaces the id with a SIM ID claimed from another phone. */ suspend fun replace(newId: String) { context.esimAccountStore.edit { it[KEY_ACCOUNT_ID] = newId } }
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.ktindex b275b6ab4e..983a142cbe 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimDtos.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/data/api/EsimDtos.kt@@ -60,8 +60,6 @@ data class StatusResponse( @SerialName("pending_credit_cents") val pendingCreditCents: Long = 0, /** The balance is a last-known fallback; the server couldn't read it live. */ @SerialName("balance_stale") val balanceStale: Boolean = false,- /** This account's eSIM was claimed onto another phone. */- @SerialName("transferred") val transferred: Boolean = false, ) @Serializable
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 b5d386d52a..1917d9fd43 100644--- a/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt+++ b/globalesim/src/main/java/com/vayunmathur/globalesim/platform/EsimViewModel.kt@@ -15,7 +15,6 @@ import com.vayunmathur.globalesim.data.api.RateDto import com.vayunmathur.globalesim.data.api.StatusResponse import com.vayunmathur.globalesim.domain.upgradeCheckoutUrl import java.io.IOException-import java.util.UUID import kotlin.time.Duration.Companion.minutes import kotlin.time.Duration.Companion.seconds import kotlin.time.TimeSource@@ -123,10 +122,6 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { * payment watch has nothing left to wait for. */ private suspend fun applyStatus(status: StatusResponse): Boolean {- if (status.transferred) {- onMovedAway()- return true- } val profile = status.profile val landed = profile != null && !status.balanceStale && profile.walletUsdCents > creditBaselineCents@@ -151,20 +146,6 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { } } - /** The eSIM was claimed onto another phone: start this install over fresh. */- private suspend fun onMovedAway() {- val fresh = UUID.randomUUID().toString()- idStore.replace(fresh)- state = state.copy(- simId = fresh,- profile = null,- pendingInvoiceUrl = null,- pendingCreditCents = 0,- balanceStale = false,- message = "This eSIM was moved to another phone.",- )- }- /** * Poll status until the payment shows up in the wallet. Both rails fund * the wallet from a server webhook, and NOWPayments can report `finished`@@ -289,18 +270,21 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { } } - /** Move the eSIM whose SIM ID was copied from another phone onto this one. */+ /** Adopt the SIM ID copied from another phone as this phone's account id. */ fun claim(simId: String) {+ val id = simId.trim() viewModelScope.launch { state = state.copy(loading = true)- runCatching { EsimApi.claim(simId.trim(), accountId()) }+ runCatching { EsimApi.claim(id, accountId()) } .onSuccess { creditWatch?.cancel()+ idStore.replace(id) state = state.copy(+ simId = id, loading = false, pendingInvoiceUrl = null, pendingClientSecret = null,- message = "eSIM moved to this phone.",+ message = "eSIM claimed on this phone.", ) loadStatus() }@@ -318,7 +302,6 @@ class EsimViewModel(app: Application) : AndroidViewModel(app) { private fun paymentError(t: Throwable): String = when ((t as? EsimApi.ApiError)?.statusCode) { 400 -> "Payments must be between $5 and $20."- 410 -> "This eSIM moved to another phone." else -> friendly(t) }