feat(android): resolve gateway origin on native, skip SW, hide MVP purchases

Make the web SPA behave correctly inside the Capacitor native shell, where the
bundle loads from a local origin:

- New lib/origin.ts gatewayOrigin(): absolute URLs resolve to VITE_GATEWAY_URL on
  native (the finished-game export/share URL in Game.svelte and the Wallet
  site-root link), falling back to the page origin on web. transport.ts already
  resolved via VITE_GATEWAY_URL and is left as-is.
- Skip the PWA service worker on the native channel (the assets are already local;
  a worker would risk serving stale content across store updates).
- Hide the money-purchase UI in the MVP: new distribution.purchasesHidden() folds
  VITE_PAYMENTS_DISABLED and the Google Play flag. The Wallet "buy" tab shows a
  neutral, pointer-free note (wallet.purchasesSoon) for the RuStore MVP and keeps
  the RuStore stub Google-Play-only. A ?nopay mock force mirrors ?gp for the e2e.
- Native env types in vite-env.d.ts.

Client-only, contour-safe: no wire/proto/schema change; web/VK/Telegram unchanged.
Tests: origin + purchasesHidden unit tests, a ?nopay wallet e2e. svelte-check
clean, vitest green, web + native vite build clean.
This commit is contained in:
Ilia Denisov
2026-07-12 14:58:35 +02:00
parent aaf2825260
commit de003e862a
13 changed files with 163 additions and 20 deletions
+25 -4
View File
@@ -1,7 +1,9 @@
// Distribution channel of the native build. Google Play forbids selling in-app currency through
// an external gate, so the Google Play build hides the purchase actions and shows a stub pointing
// the user to the RuStore build; every other build (web, VK, Telegram, RuStore native) sells
// normally. The channel is a build-time flag the Google Play build sets, not a runtime guess.
// Distribution flags for the native builds. Two independent build-time flags hide the in-app-currency
// purchase actions: VITE_GP_BUILD marks the Google Play build (Google forbids selling in-app currency
// through an external gate — it hides the actions and shows a stub pointing at the RuStore build), and
// VITE_PAYMENTS_DISABLED marks the thin native MVP that defers store billing (it hides the actions with
// no store pointer). Every other build (web, VK, Telegram, a billing-enabled RuStore native build) sells
// normally. purchasesHidden() folds both; isGooglePlayBuild() stays separate for the RuStore-pointer stub.
/**
* isGooglePlayBuild reports whether this is the Google Play native build, where in-app-currency
@@ -19,3 +21,22 @@ export function isGooglePlayBuild(): boolean {
}
return (import.meta.env as Record<string, string | undefined>).VITE_GP_BUILD === '1';
}
/**
* purchasesHidden reports whether this build hides the in-app-currency purchase actions. It is true
* for the Google Play build (external-payment policy — see isGooglePlayBuild) and for the thin native
* MVP that defers store billing (the build-time flag VITE_PAYMENTS_DISABLED set to "1"). Every other
* build sells normally. Under the mock e2e it can be forced on with a `?nopay` query parameter so the
* hidden-purchases state is exercisable without a separate build.
*/
export function purchasesHidden(): boolean {
if (isGooglePlayBuild()) return true;
if (
import.meta.env.MODE === 'mock' &&
typeof window !== 'undefined' &&
new URLSearchParams(window.location.search).has('nopay')
) {
return true;
}
return (import.meta.env as Record<string, string | undefined>).VITE_PAYMENTS_DISABLED === '1';
}