Add offline dev mode (?mock): run & verify a mod with no chain, phone, or deploy#12
Add offline dev mode (?mock): run & verify a mod with no chain, phone, or deploy#12sacha-l wants to merge 1 commit into
Conversation
…deploy
A freshly-modded app can currently only be exercised against a live,
phone-signed, funded on-chain deploy — so there is no way to confirm a mod works
before the irreversible deploy step, and the only way to discover a problem is to
deploy. This adds a fully offline dev mode.
- `http://localhost:3000/?mock` stubs the product account and backs the
leaderboard with an in-memory contract matching the live surface (register /
updateResult / isRegistered / getPlayerCid / getPlayerPoints / getPlayerCount /
getPlayerAt), same `{ success, value }` query shape and origin-mutating txs, so
the pages need zero changes.
- Bulletin upload/read are stubbed via a local blob store keyed by the
(pure-computed) CID, so Solo's "upload history then store CID" round-trips
offline. State persists in localStorage; two opponents are seeded so the board
is populated.
- getContract()/ensureMapping()/uploadToBulletin()/fetchFromGateway() short-circuit
under `_devMode`, set only under `import.meta.env.DEV` — the whole path is
tree-shaken from production builds (verified: no dev strings in dist).
- README documents `?mock` as the way to build and verify a mod before deploying.
Verified in a plain browser (no host): register -> play best-of-3 -> save ->
leaderboard renders all players sorted, 0 console errors. Multiplayer still needs
the host (Statement Store); Solo + leaderboard + profile work fully offline.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Part of the modding-DX umbrella: #13 (this PR is item 3 — offline dev mode). |
|
Two issues to fix before merge:
|
What this is
An offline dev mode for the template: open
http://localhost:3000/?mockand the whole app runs in a plain browser — register, Solo play, profile, and leaderboard — backed by an in-memory leaderboard and a local Bulletin blob store. No Polkadot host, no chain, no phone, no funding, no deploy.Why it's needed
Today the template ships only the live, phone-signed, funded, on-chain path. A freshly-modded app cannot be run or verified without an irreversible deploy that binds contract ownership to your signer. That has two costs:
A dev mode closes that loop: build and verify a mod in seconds, then deploy once you know it works.
What it fixes
How it works
?mockstubs the product account (gated byimport.meta.env.DEV).createDevLeaderboard()implements the exact live contract surface —register/updateResult/isRegistered/getPlayerCid/getPlayerPoints/getPlayerCount/getPlayerAt— with the same{ success, value }query shape and origin-mutating txs, so the pages need zero changes.uploadToBulletin/fetchFromGatewayare stubbed via a local blob store keyed by the (pure-computed) CID, so Solo's "upload history → store CID → read it back" round-trips fully offline.getContract()/ensureMapping()/uploadToBulletin()/fetchFromGateway()short-circuit under_devMode. State persists inlocalStorage; two opponents are seeded so the board is populated.Production safety
_devModecan only be set underimport.meta.env.DEV, so esbuild constant-folds it tofalseand tree-shakes the entire dev path out of production builds — verified: no dev strings (rps:dev:*) indist/. No production behavior change.Verification
In a plain browser (no host): load
?mock→ play a best-of-3 → Save to Chain (uploadToBulletin→register→updateResult(cid, delta)) → Home → Leaderboard renders all players sorted — 0 console errors throughout.tsc -bpasses; prod build succeeds and strips the dev code.Relation to #11
Complements #11 (collision-free naming). Together they make the standard flow:
npm run name:new→ verify at?mock→ deploy once. Independent — either can merge alone.