fix(native): location at the accuracy asked for, and a Play payment that clears later is redeemed

- The location shim runs at high accuracy only while a watcher wants it and
  drops back once that watcher is gone, instead of keeping the 2 s GPS rate
  for the rest of the session.
- The purchase client can hand over a Play subscription that was paid but
  never delivered (a pending payment that cleared later), and the plans screen
  redeems it at once, as a restore would, before Google Play refunds it after
  three days.
This commit is contained in:
Maurice
2026-11-07 14:57:50 +01:00
parent c1c71a12cf
commit 46f4cab1b7
6 changed files with 120 additions and 7 deletions
+27
View File
@@ -50,6 +50,14 @@ export interface IapClient {
finish(purchase: Purchase): Promise<void>;
/** The subscription this store account already holds, for a reinstall or a new device. */
restore(): Promise<Purchase | null>;
/**
* A paid subscription that was never delivered: a payment that was pending and
* cleared later (Google Play refunds it unless it is delivered within three
* days). The shell redeems it at its start, the way a restore does.
*/
unfinished(): Promise<Purchase | null>;
/** Calls `listener` when such a payment clears while the app runs. */
onTransaction(listener: () => void): void;
}
/** Every store product of the cloud starts with this. */
@@ -91,6 +99,10 @@ export const fakeIapClient: IapClient = {
async restore() {
return null;
},
async unfinished() {
return null;
},
onTransaction() {},
};
/** The store this app buys through: the App Store on iOS, Google Play on Android. */
@@ -160,6 +172,21 @@ export const nativeIapClient: IapClient = {
// Left unfinished, the store hands the transaction over again; a restore redeems it idempotently.
}
},
async unfinished() {
// StoreKit hands an interrupted first purchase over through a restore on its own; only Play needs this.
if (nativeStore()?.platform !== 'google') return null;
try {
const { purchaseToken, productId, transactionId } = await TrekShell.storeUnfinished({ prefix: PRODUCT_PREFIX });
if (!purchaseToken || !transactionId) return null;
return { platform: 'google', productId: productId ?? '', receipt: purchaseToken, transactionId };
} catch {
return null;
}
},
onTransaction(listener) {
if (nativeStore()?.platform !== 'google') return;
void TrekShell.addListener('storeTransaction', () => listener()).catch(() => {});
},
async restore() {
try {
// Google Play answers with a purchase token where the App Store answers with a signed transaction.