Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@
<head>
<meta charset="UTF-8">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<link rel="icon" type="image/x-icon" href="/favicon.ico" sizes="any">
<link rel="apple-touch-icon" href="/apple-touch-icon-180x180.png">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="theme-color" content="#0a0a0f">
<!-- `mobile-web-app-capable` is the standardized name (Chrome ≥122
marks the apple-prefixed form as deprecated). iOS Safari still
requires the apple-prefixed name pre-iOS 17 for the standalone
home-screen behavior, so we include both. -->
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
>
<meta name="apple-mobile-web-app-title" content="PushFlip">
<title>Pushflip</title>
<script>
"use strict";
Expand Down
9 changes: 7 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
"lint": "biome check",
"lint:fix": "biome check --fix",
"format": "biome format --write",
"preview": "vite preview"
"preview": "vite preview",
"pwa-assets": "pwa-assets-generator --preset minimal-2023 public/favicon.svg"
},
"dependencies": {
"@fontsource-variable/geist": "^5.2.8",
"@pushflip/client": "workspace:*",
"@solana-mobile/wallet-adapter-mobile": "^2.2.8",
"@solana-program/token": "^0.13.0",
"@solana/compat": "^6.8.0",
"@solana/kit": "^6.8.0",
Expand Down Expand Up @@ -51,11 +53,14 @@
"@types/node": "^24.12.2",
"@types/react": "^19.2.14",
"@types/react-dom": "^19.2.3",
"@vite-pwa/assets-generator": "^1.0.2",
"@vitejs/plugin-react": "^6.0.1",
"tailwindcss": "^4.2.2",
"tsx": "^4.19.0",
"typescript": "~6.0.2",
"ultracite": "^7.4.4",
"vite": "^8.0.4"
"vite": "^8.0.4",
"vite-plugin-pwa": "^1.2.0",
"workbox-window": "^7.4.0"
}
}
Binary file added app/public/apple-touch-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/favicon.ico
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/maskable-icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/pwa-1024x1024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/pwa-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/pwa-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/pwa-64x64.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions app/pwa-assets.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {
defineConfig,
minimal2023Preset as preset,
} from "@vite-pwa/assets-generator/config";

// PWA icon set generated from `public/favicon.svg`.
//
// `minimal-2023` preset produces the canonical set required for both
// browser PWA install + the Solana Seeker / dApp Store TWA path:
// - public/pwa-64x64.png (legacy/maskable fallback)
// - public/pwa-192x192.png (manifest standard)
// - public/pwa-512x512.png (manifest standard + Bubblewrap source)
// - public/maskable-icon-512x512.png (Android adaptive)
// - public/apple-touch-icon-180x180.png (iOS home-screen)
// - public/favicon.ico (legacy)
//
// The 1024×1024 source asset that the Solana dApp Store listing
// expects (per docs/GO_TO_SEEKER.md Phase 4) gets generated separately
// in `transparent.sizes` below.
//
// Run with: `pnpm --filter @pushflip/app run pwa-assets`
export default defineConfig({
preset: {
...preset,
transparent: {
...preset.transparent,
// Add the dApp Store source asset alongside the standard set.
sizes: [...preset.transparent.sizes, 1024],
},
},
images: ["public/favicon.svg"],
});
9 changes: 9 additions & 0 deletions app/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { GameBoard } from "@/components/game/game-board";
import { DemoStageBanner } from "@/components/misc/demo-stage-banner";
import { UpdateBanner } from "@/components/misc/update-banner";
import { Toaster } from "@/components/ui/sonner";
import { ClusterHint } from "@/components/wallet/cluster-hint";
import { ConnectionStatus } from "@/components/wallet/connection-status";
Expand Down Expand Up @@ -42,6 +43,14 @@ function App() {
</div>
</header>

{/* PWA update notice. Renders only when the service worker
registered by vite-plugin-pwa detects a newer deploy.
Kept ABOVE the other banners so a stale-build user who
dismisses everything still sees the update prompt — the
only banner whose action (reload) materially affects
correctness, not just UX context. */}
<UpdateBanner />

{/* Demo-stage notice. Always-on (until dismissed) so first-
time visitors understand the deploy scope: faucet + join
work, full gameplay needs the not-yet-deployed dealer.
Expand Down
109 changes: 109 additions & 0 deletions app/src/components/misc/update-banner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* UpdateBanner — surfaces "new version available" when the service
* worker registered by `vite-plugin-pwa` detects a deploy newer than
* the one currently running in this tab.
*
* **Why this exists**: with `registerType: "prompt"` (see
* `vite.config.ts`), Workbox installs the new SW in the background but
* waits for an explicit `skipWaiting()` before activating. That keeps
* users from getting a surprise reload mid-game when tucker pushes a
* new build, but it ALSO means the user is silently running stale code
* until they manually reload. This banner closes the loop: the user
* sees "Update available" and can opt-in with one click.
*
* Pairs with the existing dismissible-banner pattern
* (<DemoStageBanner>, <ClusterHint>). Distinct emerald palette so the
* three banners are visually distinguishable when stacked:
* - slate (info, deploy stage),
* - amber (warning, cluster mismatch),
* - emerald (action available, fresh build).
*
* The banner only renders when an update is actually pending — there
* is no dismissed-flag persistence. Closing the X dismisses for THIS
* pending update only; if a newer build arrives later, the banner
* reappears. (Persisting dismissal would mean a user who clicks X
* never updates, which is the wrong default for a crypto app where
* stale code can mean wrong tx semantics.)
*/

import { useRegisterSW } from "virtual:pwa-register/react";
import { RotateCwIcon, XIcon } from "lucide-react";
import { useCallback } from "react";

import { cn } from "@/lib/utils";

export interface UpdateBannerProps {
className?: string;
}

export function UpdateBanner({ className }: UpdateBannerProps) {
const {
needRefresh: [needRefresh, setNeedRefresh],
updateServiceWorker,
} = useRegisterSW({
onRegisterError(error) {
// SW registration failures are non-fatal — the app still works,
// just without offline support or update detection. Log so we
// can spot it in dev tools without leaking to user-facing UI.
console.warn("[pwa] service worker registration failed", error);
},
});

const handleUpdate = useCallback(() => {
// `true` triggers the SW's `skipWaiting()` + `clients.claim()` and
// reloads the page once the new SW is active. The reload is
// unavoidable here — we need a fresh module graph since the bundle
// hash has changed. Workbox's promise resolves AFTER navigation,
// so awaiting it inside an event handler just defers a tear-down
// we can't observe; fire-and-forget is the documented pattern.
updateServiceWorker(true).catch((error: unknown) => {
console.warn("[pwa] update failed", error);
});
}, [updateServiceWorker]);

const handleDismiss = useCallback(() => {
setNeedRefresh(false);
}, [setNeedRefresh]);

if (!needRefresh) {
return null;
}

return (
<div
aria-label="Update available"
className={cn(
"border-emerald-400/60 border-b bg-emerald-100/70 px-4 py-2 text-emerald-950 text-sm dark:border-emerald-400/40 dark:bg-emerald-500/10 dark:text-emerald-100",
className
)}
role="status"
>
<div className="mx-auto flex max-w-3xl items-start gap-2">
<RotateCwIcon
aria-hidden="true"
className="mt-0.5 shrink-0 text-emerald-700 dark:text-emerald-300"
size={16}
/>
<p className="min-w-0 flex-1 leading-relaxed">
<span className="font-semibold">Update available.</span> A new version
of pushflip is ready.{" "}
<button
className="font-medium underline underline-offset-2 hover:text-emerald-700 dark:hover:text-emerald-50"
onClick={handleUpdate}
type="button"
>
Reload now
</button>
</p>
<button
aria-label="Dismiss update notice"
className="shrink-0 rounded p-1 text-emerald-700 hover:bg-emerald-200/50 dark:text-emerald-200 dark:hover:bg-emerald-400/10"
onClick={handleDismiss}
type="button"
>
<XIcon aria-hidden="true" size={14} />
</button>
</div>
</div>
);
}
18 changes: 18 additions & 0 deletions app/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,21 @@ export const TOKEN_MINT = TEST_FLIP_MINT;
* the vault.
*/
export const GAME_ID = 2n;

/**
* Mobile Wallet Adapter (MWA) chain identifier — passed to
* `SolanaMobileWalletAdapter`'s `chain` field, which tells the on-device
* wallet (Seed Vault on Seeker, Phantom Mobile, etc.) which network to
* authorize the session for.
*
* Format follows CAIP-2 / Wallet Standard: `solana:devnet`,
* `solana:mainnet`, `solana:testnet`. Pushflip is devnet-only today;
* when the mainnet decision (Open Question #1 in `docs/GO_TO_SEEKER.md`)
* lands, this becomes a build-time env var alongside `VITE_RPC_ENDPOINT`.
*
* This is INDEPENDENT of `RPC_ENDPOINT` because the wallet's network
* choice and the app's RPC choice are decoupled — a private Helius
* mainnet RPC and `solana:mainnet` is a valid combo, as is the
* default public-devnet RPC and `solana:devnet`.
*/
export const MWA_CHAIN = "solana:devnet" as const;
76 changes: 55 additions & 21 deletions app/src/providers/wallet-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,41 +22,75 @@ import {
ConnectionProvider,
} from "@solana/wallet-adapter-react";
import { WalletModalProvider } from "@solana/wallet-adapter-react-ui";
import {
createDefaultAddressSelector,
createDefaultAuthorizationResultCache,
createDefaultWalletNotFoundHandler,
SolanaMobileWalletAdapter,
} from "@solana-mobile/wallet-adapter-mobile";
import "@solana/wallet-adapter-react-ui/styles.css";
import { type ReactNode, useCallback, useMemo } from "react";
import { toast } from "sonner";

import { RPC_ENDPOINT } from "@/lib/constants";
import { MWA_CHAIN, RPC_ENDPOINT } from "@/lib/constants";

interface WalletProviderProps {
children: ReactNode;
}

export function WalletProvider({ children }: WalletProviderProps) {
// Empty wallets array — every modern Solana wallet (Phantom 2024+,
// Solflare 2024+, Backpack, Glow, ...) registers itself via the
// Wallet Standard protocol on `window.navigator.wallets`, and
// `@solana/wallet-adapter-react@0.15.30+` discovers them
// automatically without needing explicit adapter constructors.
// Wallet list contains exactly one explicit adapter — the Mobile
// Wallet Adapter (MWA) for the Solana Seeker / dApp Store TWA path
// (Phase 2 of `docs/GO_TO_SEEKER.md`).
//
// Earlier versions of this provider passed
// `[new PhantomWalletAdapter(), new SolflareWalletAdapter()]` here,
// which produced two console warnings on every page load:
// Desktop wallets (Phantom 2024+, Solflare 2024+, Backpack, Glow,
// ...) still auto-discover via the Wallet Standard protocol on
// `window.navigator.wallets`; we don't list them explicitly. MWA is
// the exception because it doesn't have a window-injected sibling —
// the host wallet (Seed Vault on Seeker, Phantom Mobile, etc.)
// talks via an Android intent bridge, not via `window.solana`.
//
// "Phantom was registered as a Standard Wallet. The Wallet
// Adapter for Phantom can be removed from your app."
// "Solflare was registered as a Standard Wallet. The Wallet
// Adapter for Solflare can be removed from your app."
// Why include MWA on non-Android contexts: its `readyState` reports
// as `Unsupported` outside of an MWA-capable Android browser, so the
// wallet modal hides it automatically. Including it unconditionally
// is the documented Solana Mobile pattern — gating it ourselves
// would mean shipping browser-detection that the adapter already
// does internally.
//
// Removing the explicit adapters drops both warnings, slims the
// bundle (the `@solana/wallet-adapter-phantom` and
// `@solana/wallet-adapter-solflare` packages can also be removed
// from package.json in a follow-up — they're now unused).
// `appIdentity.uri` MUST match the domain claimed by the
// `assetlinks.json` we'll publish in Phase 3 — mismatch fails the
// MWA handshake silently. We derive it from `window.location.origin`
// at construction time so dev (`http://localhost:5173`) and
// production (`https://play.pushflip.xyz`) both work without an
// env-var step.
//
// The memoized empty array still gets a stable reference so
// `BaseWalletProvider` doesn't tear down its internal state on
// every render.
const wallets = useMemo(() => [], []);
// The `useMemo([])` is critical: `BaseWalletProvider` tears down
// its internal state when the wallets array reference changes.
// Constructing the adapter inside the memo guarantees one instance
// for the lifetime of the provider mount.
const wallets = useMemo(() => {
// Belt-and-suspenders SSR guard. Vite doesn't SSR our app today,
// but the adapter constructor reads `navigator` and would throw
// at module-init time if it ever ran in a Node context.
if (typeof window === "undefined") {
return [];
}
return [
new SolanaMobileWalletAdapter({
addressSelector: createDefaultAddressSelector(),
appIdentity: {
name: "PushFlip",
uri: window.location.origin,
// Resolved against `appIdentity.uri` — same SVG as the
// browser favicon and PWA manifest icon source.
icon: "/favicon.svg",
},
authorizationResultCache: createDefaultAuthorizationResultCache(),
chain: MWA_CHAIN,
onWalletNotFound: createDefaultWalletNotFoundHandler(),
}),
];
}, []);

const onError = useCallback((error: WalletError) => {
// Surface adapter errors as toasts so the user sees them. The wallet
Expand Down
2 changes: 2 additions & 0 deletions app/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/// <reference types="vite/client" />
/// <reference types="vite-plugin-pwa/react" />
/// <reference types="vite-plugin-pwa/info" />

/**
* Augment Vite's `ImportMetaEnv` so that `VITE_*` env-var typos are caught at
Expand Down
Loading
Loading