From 91defd40fdd27a280f5049558b08adc1508b5b25 Mon Sep 17 00:00:00 2001 From: Maurice Date: Thu, 5 Nov 2026 16:53:04 +0100 Subject: [PATCH] fix(native): a flat redeem result, so the claim flow typechecks The discriminated union did not narrow under the native-shell tsconfig, so the failure code read as absent on the whole type. Use a flat result with optional instanceUrl and code instead: both are always present on the type, no narrowing needed, and the ok plus instanceUrl guard still routes success from refusal. --- client/native-shell/main.ts | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/client/native-shell/main.ts b/client/native-shell/main.ts index fb37f921a..65f5cbaef 100644 --- a/client/native-shell/main.ts +++ b/client/native-shell/main.ts @@ -432,7 +432,13 @@ async function slugStatus(slug: string): Promise { } } -type RedeemResult = { ok: true; instanceUrl: string } | { ok: false; code: string } +interface RedeemResult { + ok: boolean + /** Set when ok: the address the app loads. */ + instanceUrl?: string + /** Set when not ok: a stable refusal code. */ + code?: string +} async function redeemPurchase(slug: string, email: string, purchase: Purchase): Promise { try { const res = await CapacitorHttp.post({ @@ -558,19 +564,19 @@ function showClaim(plan: CloudPlan, interval: 'month' | 'year', opts: { back?: b } const redeemed = await redeemPurchase(slug, email, outcome.purchase) - if (!redeemed.ok) { - void notify(NotificationType.Error) - restore() - if (redeemed.code === 'slug-taken') { - shake(slugField) - slugNote.textContent = t('native.claim.taken') - slugNote.className = 'hint bad' - } else { - error.textContent = t('native.claim.redeemFailed') - } + if (redeemed.ok && redeemed.instanceUrl) { + showProvisioning(redeemed.instanceUrl) return } - showProvisioning(redeemed.instanceUrl) + void notify(NotificationType.Error) + restore() + if (redeemed.code === 'slug-taken') { + shake(slugField) + slugNote.textContent = t('native.claim.taken') + slugNote.className = 'hint bad' + } else { + error.textContent = t('native.claim.redeemFailed') + } }) show(