Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(mobile): Never show the onboarding paywall to a paid account (#2445)
Chad Pihad0055f4c4c99
diff --git a/openwhispr-mobile/src/screens/onboarding/steps/PaywallStep.tsx b/openwhispr-mobile/src/screens/onboarding/steps/PaywallStep.tsxindex 640543910..32e4ef72d 100644--- a/openwhispr-mobile/src/screens/onboarding/steps/PaywallStep.tsx+++ b/openwhispr-mobile/src/screens/onboarding/steps/PaywallStep.tsx@@ -5,7 +5,7 @@ import { Text } from '@/components/ui/Text';import { OnboardingShell } from '@/components/onboarding/OnboardingShell';import { SystemIcon, type LucideIconName } from '@/components/ui/SystemIcon';import { useAuthStore } from '@/store/useAuthStore';-import { useUsageStore } from '@/store/useUsageStore';+import { getUsageOwnerKey, useUsageStore } from '@/store/useUsageStore';import { useSuperwallGate } from '@/hooks/useSuperwallGate';import { SUPERWALL_PLACEMENTS } from '@/lib/superwall';import { describeOnboardingError } from '@/lib/onboardingErrors';@@ -19,7 +19,8 @@ const HIGHLIGHTS: { icon: string; mdIcon: LucideIconName; label: string }[] = [// A cold launch that resumes on this step arrives before the SDK's configure// round trip has finished; registering then is answered immediately for a// non-transactional placement and would skip the paywall for good. Wait this-// long for it, then present anyway so a broken SDK cannot hold the step.+// long for it, then present anyway so a broken SDK cannot hold the step. Only a+// confirmed free account ever waits here.export const PAYWALL_READY_GRACE_MS = 3_000;// How long Continue stays inert after registering: long enough for the SDK to// actually present (or report it can't), short enough that a paywall which@@ -34,7 +35,15 @@ export const PAYWALL_ESCAPE_MS = 8_000;export function PaywallStep() {const { goNext } = useOnboardingStep('paywall');const user = useAuthStore((s) => s.user);- const isSubscribed = useUsageStore((s) => s.usage?.isSubscribed ?? false);+ const usage = useUsageStore((s) => s.usage);+ const usageOwnerKey = useUsageStore((s) => s.ownerKey);+ // Usage is only this account's when the store loaded it for the current+ // session; an older account's usage, or none yet, says nothing about the plan.+ const isConfirmedFree =+ usage !== null &&+ usageOwnerKey !== null &&+ usageOwnerKey === getUsageOwnerKey() &&+ !usage.isSubscribed;const { register, state, isConfigured } = useSuperwallGate();const hasPresentedRef = useRef(false);const hasAdvancedRef = useRef(false);@@ -42,6 +51,7 @@ export function PaywallStep() {const registrationRef = useRef<AbortController | null>(null);const [readyGraceElapsed, setReadyGraceElapsed] = useState(false);const [presenting, setPresenting] = useState(false);+ const [skipping, setSkipping] = useState(false);const [escapeElapsed, setEscapeElapsed] = useState(false);const [advanceError, setAdvanceError] = useState<string | null>(null);@@ -87,9 +97,12 @@ export function PaywallStep() {// No session means no billing identity, so a purchase made now could not// be attributed to anyone and would be lost; a subscriber has nothing to- // buy. Either way there is no paywall worth presenting.- if (!user || isSubscribed) {+ // buy. A plan that hasn't loaded skips too rather than holding the user for+ // a usage round trip: a paid account must never see the offer, and a free+ // one still meets the usage limit and feature paywalls later.+ if (!user || !isConfirmedFree) {hasPresentedRef.current = true;+ setSkipping(true);void advance();return;}@@ -109,13 +122,30 @@ export function PaywallStep() {.finally(() => {if (!unmountedRef.current) void advance();});- }, [advance, isConfigured, isSubscribed, readyGraceElapsed, register, user]);+ }, [advance, isConfigured, isConfirmedFree, readyGraceElapsed, register, user]);// Between registering and the SDK presenting, this backdrop looks like an// ordinary screen with a primary button; tapping it would mount the next// step underneath a paywall that then presents on top of it.const ctaDisabled = !advanceError && presenting && state.status === 'idle' && !escapeElapsed;+ const errorNotice = advanceError ? (+ <Text accessibilityRole="alert" className="text-systemRed">+ {advanceError}+ </Text>+ ) : null;++ // Decided in render, not after the effect, so the Pro pitch never flashes for+ // a paid or unconfirmed account. Continue stays so a failed save can retry.+ const showsOffer = presenting || (!skipping && user !== null && isConfirmedFree);+ if (!showsOffer) {+ return (+ <OnboardingShell title="" titleNode={<View />} ctaLabel="Continue" onCta={advance}>+ {errorNotice}+ </OnboardingShell>+ );+ }+return (<OnboardingShelltitle="Go further with OpenWhispr Pro."@@ -126,11 +156,7 @@ export function PaywallStep() {onCta={advance}><View className="gap-4 pt-2">- {advanceError ? (- <Text accessibilityRole="alert" className="text-systemRed">- {advanceError}- </Text>- ) : null}+ {errorNotice}{HIGHLIGHTS.map((item) => (<View key={item.label} className="flex-row items-center gap-3"><SystemIcon name={item.icon} mdName={item.mdIcon} size={20} />diff --git a/openwhispr-mobile/src/screens/onboarding/steps/__tests__/PaywallStep.test.tsx b/openwhispr-mobile/src/screens/onboarding/steps/__tests__/PaywallStep.test.tsxindex 8ee051037..6d23dabf8 100644--- a/openwhispr-mobile/src/screens/onboarding/steps/__tests__/PaywallStep.test.tsx+++ b/openwhispr-mobile/src/screens/onboarding/steps/__tests__/PaywallStep.test.tsx@@ -28,12 +28,25 @@ jest.mock('@/store/useAuthStore', () => ({useAuthStore: (selector: (s: MockAuthState) => unknown) => selector(mockAuthState),}));-type MockUsageState = { usage: { isSubscribed: boolean } | null };-let mockUsageState: MockUsageState = { usage: null };+type MockUsage = { isSubscribed: boolean };+type MockUsageState = { usage: MockUsage | null; ownerKey: string | null };+const OWNER = 'user-1:cookie';+let mockUsageState: MockUsageState = { usage: null, ownerKey: null };+let mockCurrentOwnerKey: string | null = OWNER;+const mockLoad = jest.fn();jest.mock('@/store/useUsageStore', () => ({- useUsageStore: (selector: (s: MockUsageState) => unknown) => selector(mockUsageState),+ useUsageStore: Object.assign(+ (selector: (s: MockUsageState) => unknown) => selector(mockUsageState),+ { getState: () => ({ ...mockUsageState, load: mockLoad }) },+ ),+ getUsageOwnerKey: () => mockCurrentOwnerKey,}));+const FREE: MockUsage = { isSubscribed: false };+const SUBSCRIBED: MockUsage = { isSubscribed: true };+const PRO_TITLE = 'Go further with OpenWhispr Pro.';+const PRO_HIGHLIGHT = 'Sync notes across devices';+import { PAYWALL_ESCAPE_MS, PAYWALL_READY_GRACE_MS, PaywallStep } from '../PaywallStep';import { SUPERWALL_PLACEMENTS } from '@/lib/superwall';@@ -42,7 +55,8 @@ beforeEach(() => {mockGoNext.mockResolvedValue(undefined);mockRegister.mockResolvedValue(true);mockAuthState = { user: { id: 'anon-user', isAnonymous: true } };- mockUsageState = { usage: null };+ mockUsageState = { usage: FREE, ownerKey: OWNER };+ mockCurrentOwnerKey = OWNER;mockGate = { isConfigured: true, state: { status: 'idle' } };});@@ -79,6 +93,8 @@ describe('PaywallStep', () => {mockRegister.mockReturnValue(new Promise<boolean>(() => {}));const { getByText } = render(<PaywallStep />);+ await act(async () => {});+ expect(mockRegister).toHaveBeenCalledTimes(1);await act(async () => {jest.advanceTimersByTime(PAYWALL_ESCAPE_MS);});@@ -97,6 +113,7 @@ describe('PaywallStep', () => {mockRegister.mockReturnValue(new Promise<boolean>(() => {}));const { getByText } = render(<PaywallStep />);+ await waitFor(() => expect(mockRegister).toHaveBeenCalledTimes(1));await act(async () => {fireEvent.press(getByText('Continue'));});@@ -107,6 +124,7 @@ describe('PaywallStep', () => {it('re-enables Continue once the SDK reports the paywall failed to present', async () => {mockRegister.mockReturnValue(new Promise<boolean>(() => {}));const { getByText, rerender } = render(<PaywallStep />);+ await waitFor(() => expect(mockRegister).toHaveBeenCalledTimes(1));mockGate = { isConfigured: true, state: { status: 'error' } };rerender(<PaywallStep />);@@ -152,7 +170,10 @@ describe('PaywallStep', () => {}),);+ mockGate = { isConfigured: true, state: { status: 'error' } };+const { getByText } = render(<PaywallStep />);+ await waitFor(() => expect(mockRegister).toHaveBeenCalledTimes(1));await act(async () => {fireEvent.press(getByText('Continue'));});@@ -174,7 +195,7 @@ describe('PaywallStep', () => {});it('skips the paywall for a user who is already subscribed', async () => {- mockUsageState = { usage: { isSubscribed: true } };+ mockUsageState = { usage: SUBSCRIBED, ownerKey: OWNER };render(<PaywallStep />);@@ -182,6 +203,121 @@ describe('PaywallStep', () => {expect(mockRegister).not.toHaveBeenCalled();});+ // Until /api/usage answers, `usage` is null, which used to read as "not+ // subscribed" and showed a paid user the offer. An unconfirmed plan skips at+ // once: holding everyone for a usage round trip costs more than a free user+ // missing this one offer, and later limit and feature paywalls still reach them.+ describe('when the plan is not confirmed', () => {+ it('advances at once, without loading usage, when usage has not loaded', async () => {+ jest.useFakeTimers();+ mockUsageState = { usage: null, ownerKey: null };++ render(<PaywallStep />);+ await act(async () => {});++ expect(mockGoNext).toHaveBeenCalledTimes(1);+ expect(mockRegister).not.toHaveBeenCalled();+ expect(mockLoad).not.toHaveBeenCalled();+ });++ it('advances when the loaded usage belongs to another account', async () => {+ mockUsageState = { usage: FREE, ownerKey: 'previous-user:cookie' };++ render(<PaywallStep />);++ await waitFor(() => expect(mockGoNext).toHaveBeenCalledTimes(1));+ expect(mockRegister).not.toHaveBeenCalled();+ });++ it('advances when the session has no usage owner', async () => {+ mockCurrentOwnerKey = null;++ render(<PaywallStep />);++ await waitFor(() => expect(mockGoNext).toHaveBeenCalledTimes(1));+ expect(mockRegister).not.toHaveBeenCalled();+ });++ it('does not present when usage arrives after the step has skipped', async () => {+ let releaseGoNext: () => void = () => {};+ mockGoNext.mockReturnValue(+ new Promise<void>((resolve) => {+ releaseGoNext = resolve;+ }),+ );+ mockUsageState = { usage: null, ownerKey: null };++ const { rerender, queryByText } = render(<PaywallStep />);+ mockUsageState = { usage: FREE, ownerKey: OWNER };+ rerender(<PaywallStep />);+ await act(async () => {});++ expect(mockRegister).not.toHaveBeenCalled();+ expect(queryByText(PRO_TITLE)).toBeNull();+ releaseGoNext();+ });++ it('lets the user retry when saving progress fails on the skip path', async () => {+ mockGoNext.mockRejectedValueOnce(new Error('disk full'));+ mockUsageState = { usage: null, ownerKey: null };++ const screen = render(<PaywallStep />);+ expect(await screen.findByText('Could not save progress. Try again.')).toBeTruthy();+ fireEvent.press(screen.getByText('Continue'));++ await waitFor(() => expect(mockGoNext).toHaveBeenCalledTimes(2));+ expect(mockRegister).not.toHaveBeenCalled();+ });+ });++ // A paid or unconfirmed account must not see the Pro pitch even for the+ // frame before the step advances.+ describe('Pro copy', () => {+ it.each([+ ['usage has not loaded', { usage: null, ownerKey: null }],+ ['the account is subscribed', { usage: SUBSCRIBED, ownerKey: OWNER }],+ ['usage belongs to another account', { usage: FREE, ownerKey: 'previous-user:cookie' }],+ ])('is not rendered when %s', (_label, usageState: MockUsageState) => {+ mockGoNext.mockReturnValue(new Promise<void>(() => {}));+ mockUsageState = usageState;++ const { queryByText } = render(<PaywallStep />);++ expect(queryByText(PRO_TITLE)).toBeNull();+ expect(queryByText(PRO_HIGHLIGHT)).toBeNull();+ });++ it('is not rendered when there is no session', () => {+ mockGoNext.mockReturnValue(new Promise<void>(() => {}));+ mockAuthState = { user: null };++ const { queryByText } = render(<PaywallStep />);++ expect(queryByText(PRO_TITLE)).toBeNull();+ });++ it('is rendered for a free account while the paywall is on its way', () => {+ mockGate = { isConfigured: false, state: { status: 'idle' } };++ const { getByText } = render(<PaywallStep />);++ expect(getByText(PRO_TITLE)).toBeTruthy();+ expect(getByText(PRO_HIGHLIGHT)).toBeTruthy();+ });++ it('is withdrawn when a free account turns out to be subscribed before presenting', async () => {+ mockGate = { isConfigured: false, state: { status: 'idle' } };+ const { rerender, queryByText } = render(<PaywallStep />);++ mockUsageState = { usage: SUBSCRIBED, ownerKey: OWNER };+ rerender(<PaywallStep />);++ await waitFor(() => expect(mockGoNext).toHaveBeenCalledTimes(1));+ expect(queryByText(PRO_TITLE)).toBeNull();+ expect(mockRegister).not.toHaveBeenCalled();+ });+ });+it('does not advance after unmounting mid-presentation', async () => {let releaseRegister: (value: boolean) => void = () => {};mockRegister.mockReturnValue(diff --git a/openwhispr-mobile/src/store/useUsageStore.ts b/openwhispr-mobile/src/store/useUsageStore.tsindex 299543d4e..84c16b592 100644--- a/openwhispr-mobile/src/store/useUsageStore.ts+++ b/openwhispr-mobile/src/store/useUsageStore.ts@@ -25,7 +25,7 @@ interface UsageStore {let nextRequestId = 0;-function getUsageOwnerKey(): string | null {+export function getUsageOwnerKey(): string | null {const { user, isGuest, sessionCookie } = useAuthStore.getState();if (!user || isGuest || !sessionCookie) return null;return `${user.id}:${sessionCookie}`;