-
Notifications
You must be signed in to change notification settings - Fork 6
feat: runtime env #712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fmorency
wants to merge
6
commits into
manifest-network:main
Choose a base branch
from
fmorency:runtime-env
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: runtime env #712
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
866c98a
chore: add CLAUDE.md with project guidance for Claude Code
fmorency ead06b2
feat: runtime environment variables via window.__ENV__
fmorency 848c287
style: fix prettier formatting in CLAUDE.md and config/env.ts
fmorency 25f696a
refactor: move Window.__ENV__ type to global.d.ts, fix docker run exa…
fmorency a8fcff1
fix: bump timeout for flaky GroupDetails form validation test
fmorency 56cc134
fix: stabilize flaky ValidatorDetailsModal disabled button test
fmorency File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| # CLAUDE.md | ||
|
|
||
| This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. | ||
|
|
||
| ## Project Overview | ||
|
|
||
| Manifest Wallet ("Alberto") — a Next.js 15 web app for interacting with the Manifest Network blockchain and its modules (groups, factory, bank, admins). Built with the Pages Router, Cosmos SDK tooling, and multi-chain support (Manifest + Osmosis). | ||
|
|
||
| ## Commands | ||
|
|
||
| ```bash | ||
| bun install # Install dependencies | ||
| bun run dev # Dev server with Turbopack (localhost:3000) | ||
| bun run build # Production build | ||
| bun run lint # ESLint | ||
| bun run format # Prettier (write mode) | ||
| bun test # Run all unit tests (Bun test runner) | ||
| bun test path/to/file # Run a single test file | ||
| bun run test:coverage # Tests with coverage report | ||
| ``` | ||
|
|
||
| Package manager is **Bun** (not npm/yarn). Use `bun install`, `bun run`, `bun test`. | ||
|
|
||
| ## Architecture | ||
|
|
||
| ### Routing & Pages | ||
|
|
||
| Next.js **Pages Router** (`pages/` directory). Dynamic routes: `pages/factory/[id].tsx`, `pages/groups/[id].tsx`. | ||
|
|
||
| ### Provider Stack | ||
|
|
||
| `ManifestAppProviders` in `contexts/manifestAppProviders.tsx` composes the full provider tree: | ||
| `QueryClientProvider` → `ContactsProvider` → `Web3AuthProvider` → `ChainProvider` (cosmos-kit) → `ThemeProvider` → `ToastProvider` | ||
|
|
||
| ### State Management | ||
|
|
||
| - **Server state**: TanStack React Query v5 — query hooks in `hooks/useQueries.ts` | ||
| - **Blockchain transactions**: `hooks/useTx.tsx` | ||
| - **LCD queries**: `hooks/useLcdQueryClient.ts` | ||
| - **Client state**: React Context (`contexts/`) for theme, toasts, advanced mode, web3auth | ||
| - **Form state**: Formik + Yup (schemas in `schemas/`) | ||
| - **Local persistence**: `hooks/useLocalStorage.ts` | ||
|
|
||
| ### Component Organization | ||
|
|
||
| Feature-based directories under `components/`: | ||
|
|
||
| - `admins/`, `bank/`, `factory/`, `groups/`, `tokens/` — domain features | ||
| - `react/` — shared layout and UI components (Nav, Sidebar, etc.) | ||
| - `3js/` — Three.js visualizations (dynamically imported to avoid SSR issues) | ||
| - `icons/` — custom SVG icon components | ||
|
|
||
| ### Blockchain Integration | ||
|
|
||
| - **@manifest-network/manifestjs** — proto-generated types, registries, amino converters | ||
| - **cosmos-kit** — wallet management (Keplr, Cosmostation, Leap, Web3Auth social login) | ||
| - **@cosmjs** — signing, stargate client, proto-signing | ||
| - Multi-chain: Manifest (primary) + Osmosis (IBC/swaps) | ||
|
|
||
| ### Configuration & Runtime Environment Variables | ||
|
|
||
| - `config/env.ts` — centralized env var access via `getEnvVar(key)` helper. All consumer files import `env` from here. | ||
| - `config/manifestChain.ts` / `config/osmosisChain.ts` — chain registry, selected by `NEXT_PUBLIC_CHAIN_TIER` (qa/testnet/mainnet) | ||
| - `.env.test` for test environment variables | ||
|
|
||
| **Runtime env vars**: `NEXT_PUBLIC_*` variables are **not** inlined at build time. Instead: | ||
|
|
||
| - `config/env.ts` uses dynamic `process.env[key]` access (server) and `window.__ENV__[key]` (client) to avoid Next.js build-time inlining. | ||
| - `pages/_document.tsx` injects `<script src="/env-config.js" />` synchronously before React hydrates. | ||
| - `public/env-config.js` is a committed empty placeholder (`window.__ENV__ = {}`). In production Docker containers, `docker-entrypoint.mjs` overwrites it at container start with actual `NEXT_PUBLIC_*` values from the environment. | ||
| - During `bun dev`, Next.js reads `.env.local` and provides values via `process.env` server-side as usual. | ||
|
|
||
| This allows **one Docker image** to be built and configured at runtime for any environment (qa/testnet/mainnet) by passing env vars at `docker run` time. | ||
|
|
||
| ### Styling | ||
|
|
||
| Tailwind CSS v4 + DaisyUI v5. Dark/light theme via `data-theme` attribute. Custom breakpoints (`xxs: 320px`, `3xl: 2560px`). | ||
|
|
||
| ## Code Conventions | ||
|
|
||
| - TypeScript strict mode | ||
| - Path alias: `@/*` maps to project root (e.g., `@/components`, `@/hooks`) | ||
| - Prettier: 100 char width, single quotes, es5 trailing commas, sorted imports (`@trivago/prettier-plugin-sort-imports`) | ||
| - Import order: `@/` prefixed paths first, then relative `.` paths, separated by blank line | ||
| - Tests co-located in `__tests__/` directories next to source files, using `*.test.tsx` pattern | ||
| - Test setup: happy-dom for DOM simulation, `@testing-library/react` + `@testing-library/jest-dom` matchers | ||
|
|
||
| ## CI | ||
|
|
||
| GitHub Actions runs on push and PR: build check, test coverage (uploaded to Codecov), and Prettier formatting check. Docker builds trigger on `release/*` branches and version tags, deploying a single environment-agnostic image to GHCR. Environment-specific `NEXT_PUBLIC_*` vars are passed at `docker run` time, not at build time. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { writeFileSync } from 'node:fs'; | ||
| import { dirname, join } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| // Collect all NEXT_PUBLIC_* environment variables. | ||
| const runtimeEnv = {}; | ||
| for (const [key, value] of Object.entries(process.env)) { | ||
| if (key.startsWith('NEXT_PUBLIC_')) { | ||
| runtimeEnv[key] = value; | ||
| } | ||
| } | ||
|
|
||
| const keys = Object.keys(runtimeEnv); | ||
| if (keys.length === 0) { | ||
| console.warn( | ||
| '[entrypoint] WARNING: No NEXT_PUBLIC_* environment variables found. ' + | ||
| 'The app will start with empty configuration.' | ||
| ); | ||
| } | ||
|
|
||
| // Escape '<' to prevent </script> injection if values are ever served inline. | ||
| const json = JSON.stringify(runtimeEnv).replace(/</g, '\\u003c'); | ||
fmorency marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const script = `window.__ENV__ = ${json};`; | ||
|
|
||
| const outputPath = join(__dirname, 'public', 'env-config.js'); | ||
| try { | ||
| writeFileSync(outputPath, script); | ||
| console.log(`[entrypoint] Wrote env-config.js with keys: ${keys.join(', ')}`); | ||
| } catch (err) { | ||
| console.error( | ||
| `[entrypoint] FATAL: Failed to write ${outputPath}: ${err.message}\n` + | ||
| 'Ensure the public/ directory exists and is writable by the container user.' | ||
| ); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| // Start the Next.js server. | ||
| await import('./server.js'); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.