fix(ci): the Android merge passes the client gates

- wallet.ts: the Google Wallet state is read through a function after it was
  set, so TypeScript no longer narrows it to its old value (TS2367)
- iap.ts: a store listener that cannot be added is reported through
  reportNativeFailure instead of an empty catch
- iap.test.ts: the restored purchase is checked instead of asserted non-null
- trekShell.ts: the fold's rectangle is typed as a DOMRect pick, geometry the
  RTL lint does not read as text sides
This commit is contained in:
Maurice
2026-11-07 17:13:47 +01:00
parent 4461899910
commit 5ca44453ae
4 changed files with 19 additions and 11 deletions
+2 -1
View File
@@ -174,7 +174,8 @@ describe('native client on Android (Google Play Billing)', () => {
shell.storeRestore.mockResolvedValue({});
expect(await nativeIapClient.restore()).toBeNull();
shell.storeFinish.mockResolvedValue(undefined);
await nativeIapClient.finish(purchase!);
if (!purchase) throw new Error('expected the restored purchase');
await nativeIapClient.finish(purchase);
expect(shell.storeFinish).toHaveBeenCalledWith({ transactionId: 'token-2' });
});
+5 -1
View File
@@ -1,4 +1,5 @@
import { isNativeAndroid, isNativeIos } from './platform';
import { reportNativeFailure } from './reportFailure';
import { TrekShell, type StoreRestoreResult } from './trekShell';
/**
@@ -185,7 +186,10 @@ export const nativeIapClient: IapClient = {
},
onTransaction(listener) {
if (nativeStore()?.platform !== 'google') return;
void TrekShell.addListener('storeTransaction', () => listener()).catch(() => {});
void TrekShell.addListener('storeTransaction', () => listener()).catch((err: unknown) => {
// Without the listener a renewal that clears later is still picked up by the next restore; nothing to undo.
reportNativeFailure(err);
});
},
async restore() {
try {
+2 -1
View File
@@ -151,7 +151,8 @@ interface NativeWindowLayout {
orientation?: 'vertical' | 'horizontal';
separating?: boolean;
occluding?: boolean;
hinge?: { left: number; top: number; right: number; bottom: number };
/** The fold's rectangle on the screen, in CSS pixels: geometry, not text sides. */
hinge?: Pick<DOMRectReadOnly, 'left' | 'top' | 'right' | 'bottom'>;
}
/** A position, or an error shaped like GeolocationPositionError (1 denied, 2 unavailable). */
+10 -8
View File
@@ -81,6 +81,11 @@ function setGoogleState(next: typeof googleState): void {
for (const listener of googleListeners) listener();
}
/** Read through a call, so a check after setGoogleState() sees the new state rather than a narrowed one. */
function googleSaidYes(): boolean {
return googleState === 'yes';
}
export async function loadGoogleWalletAvailability(tripId: number): Promise<boolean> {
if (!canAddToGoogleWallet()) return false;
if (googleState === 'yes' || googleState === 'no') return googleState === 'yes';
@@ -94,18 +99,15 @@ export async function loadGoogleWalletAvailability(tripId: number): Promise<bool
// Offline: ask again next time.
setGoogleState('unknown');
}
return googleState === 'yes';
return googleSaidYes();
}
/** True once this server has said Google Wallet works; asks it the first time a booking shows. */
export function useGoogleWalletAvailable(tripId: number): boolean {
const available = useSyncExternalStore(
(listener) => {
googleListeners.add(listener);
return () => googleListeners.delete(listener);
},
() => googleState === 'yes'
);
const available = useSyncExternalStore((listener) => {
googleListeners.add(listener);
return () => googleListeners.delete(listener);
}, googleSaidYes);
useEffect(() => {
void loadGoogleWalletAvailability(tripId);
}, [tripId]);