diff --git a/client/native-shell/main.ts b/client/native-shell/main.ts index a6248db0a..fb37f921a 100644 --- a/client/native-shell/main.ts +++ b/client/native-shell/main.ts @@ -432,11 +432,8 @@ async function slugStatus(slug: string): Promise { } } -interface RedeemOk { - ok: true - instanceUrl: string -} -async function redeemPurchase(slug: string, email: string, purchase: Purchase): Promise { +type RedeemResult = { ok: true; instanceUrl: string } | { ok: false; code: string } +async function redeemPurchase(slug: string, email: string, purchase: Purchase): Promise { try { const res = await CapacitorHttp.post({ url: `${CLOUD_URL}/api/iap/redeem`, @@ -561,19 +558,19 @@ function showClaim(plan: CloudPlan, interval: 'month' | 'year', opts: { back?: b } const redeemed = await redeemPurchase(slug, email, outcome.purchase) - if (redeemed.ok) { - showProvisioning(redeemed.instanceUrl) + 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') + } return } - 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') - } + showProvisioning(redeemed.instanceUrl) }) show( diff --git a/client/src/native/iap.ts b/client/src/native/iap.ts index 47ec4b0ec..37f5bc69b 100644 --- a/client/src/native/iap.ts +++ b/client/src/native/iap.ts @@ -9,7 +9,7 @@ * half-wired ever faces a customer. */ -export type IapPlatform = 'apple' | 'google'; +type IapPlatform = 'apple' | 'google'; /** The receipt a completed purchase yields, in the shape `/api/iap/redeem` takes. */ export interface Purchase { @@ -19,7 +19,7 @@ export interface Purchase { } /** What a purchase attempt came to. `cancelled` is the customer backing out, not an error. */ -export type PurchaseOutcome = +type PurchaseOutcome = | { kind: 'bought'; purchase: Purchase } | { kind: 'cancelled' } | { kind: 'failed' }; @@ -78,7 +78,7 @@ export const nativeIapClient: IapClient = { * preview build with `localStorage['trek-iap-fake'] = '1'`, so the flow can be * shown without a store. Off in a store build, where the native client decides. */ -function useFake(): boolean { +function fakeEnabled(): boolean { try { if (import.meta.env?.DEV) return true; return typeof localStorage !== 'undefined' && localStorage.getItem('trek-iap-fake') === '1'; @@ -88,5 +88,5 @@ function useFake(): boolean { } export function getIapClient(): IapClient { - return useFake() ? fakeIapClient : nativeIapClient; + return fakeEnabled() ? fakeIapClient : nativeIapClient; } diff --git a/shared/src/i18n/he/index.ts b/shared/src/i18n/he/index.ts index bcc4778a6..d5a2e196c 100644 --- a/shared/src/i18n/he/index.ts +++ b/shared/src/i18n/he/index.ts @@ -47,6 +47,7 @@ import mobileSettings from './mobileSettings'; import mobileTrip from './mobileTrip'; import mobileVacay from './mobileVacay'; import nav from './nav'; +import native from './native'; import notif from './notif'; import notifications from './notifications'; import oauth from './oauth'; @@ -124,6 +125,7 @@ const locale = { ...collab, ...perm, ...undo, + ...native, ...notifications, ...todo, ...notif,