|
1 | | -## Architecture Improvements Roadmap |
| 1 | +## Goal |
2 | 2 |
|
3 | | -- [ ] **Decouple auth provider layers** |
4 | | - - Extract a lean `lit-auth-service` module (hooks + context) from the 2.4k‑line `LitAuthProvider`. |
5 | | - - Move modal UI, funding gate, and settings panes into dedicated presentational components that consume the new hooks. |
6 | | - - [x] Remove the direct dependency on `PaymentManagementDashboard` inside the provider by introducing a minimal funding widget + callbacks. |
| 3 | +Create a single source of truth for explorer network metadata (slugs, modules, tokens, auth URLs, default chains) so future networks can be onboarded by editing one object instead of touching multiple components. |
7 | 4 |
|
8 | | -- [x] **Modularize payment management** |
9 | | - - Split `PaymentManagementDashboard` into headless hooks (`usePaymentManager`, `useLedgerBalance`, `useWithdrawals`) and small visual components. |
10 | | - - Reuse shared types from `protectedApp/types.ts` instead of redefining them locally. |
11 | | - - Replace inline style objects with styled components or utility classes for consistency. |
| 5 | +## Files to update / add |
12 | 6 |
|
13 | | -- [ ] **Unify chain configuration + ledger helpers** |
14 | | - - [x] Move the canonical chain list and ledger balance utilities into a shared `src/domain/lit/chains.ts`. |
15 | | - - [x] Update `PKPSelectionSection`, wallet utilities, and dashboards to import the shared helpers instead of keeping local copies. |
| 7 | +1. `apps/explorer/src/domain/lit/networks.ts` (new) |
| 8 | +2. `apps/explorer/src/domain/lit/networkDefaults.ts` |
| 9 | +3. `apps/explorer/src/domain/lit/litChainConfig.ts` |
| 10 | +4. `apps/explorer/src/hooks/useLitServiceSetup.ts` |
| 11 | +5. `apps/explorer/src/lit-login-modal/LitAuthProvider.tsx` |
| 12 | +6. `apps/explorer/src/_config.ts` |
| 13 | +7. `apps/explorer/src/lit-login-modal/components/AuthSettingsPanel.tsx` |
| 14 | +8. `apps/explorer/src/lit-logged-page/LoggedInDashboard.tsx` |
| 15 | +9. `apps/explorer/src/lit-login-modal/PKPSelectionSection.tsx` |
| 16 | +10. `apps/explorer/src/lit-logged-page/protectedApp/components/pkp/PKPInfoCard.tsx` |
| 17 | +11. `apps/explorer/src/lit-logged-page/protectedApp/components/PaymentManagement/PaymentManagementDashboard.tsx` |
| 18 | +12. `apps/explorer/src/main.tsx` |
16 | 19 |
|
17 | | -- [ ] **Route-level composition** |
18 | | - - Define separate React Router child routes (`Playground`, `Permissions`, `Payments`) that each render focused page components. |
19 | | - - Keep shared state (selected PKP, balances, toasts) in a parent provider instead of a monolithic `LoggedInDashboard`. |
| 20 | +## Planned changes |
20 | 21 |
|
21 | | -- [ ] **Strengthen domain typing** |
22 | | - - Introduce typed service interfaces for permissions, payments, and ledger data instead of returning `any`. |
23 | | - - Add discriminated unions / DTOs to the contexts so consumers know which operations and states are available without casting. |
| 22 | +### 1. `domain/lit/networks.ts` (new) |
| 23 | +- **Before**: No registry; constants are duplicated across multiple files. |
| 24 | +- **After**: Export a `NETWORKS` object keyed by `SupportedNetworkName`. Each entry contains `label`, `isTestnet`, `chainSlug`, `ledgerSymbol`, `authEnvVar`, and `moduleKey`. Also export derived helpers (`SUPPORTED_NETWORKS`, `getNetworkMeta`, `getAuthUrlForNetwork(env)`, etc.). |
| 25 | + |
| 26 | +### 2. `domain/lit/networkDefaults.ts` |
| 27 | +- **Before**: Manually defines `DEFAULT_CHAIN_BY_NETWORK` and `TESTNET_NETWORKS`. |
| 28 | +- **After**: Re-export `SupportedNetworkName`, `SUPPORTED_NETWORKS`, `getDefaultChainForNetwork`, and `isTestnetNetwork` from the new registry so there is no bespoke map here. |
| 29 | + |
| 30 | +### 3. `domain/lit/litChainConfig.ts` |
| 31 | +- **Before**: Hard-codes Lit chain RPC/Explorer URLs and viem config. |
| 32 | +- **After**: Export a `getLitChainConfig(env)` helper that reads env overrides once and feeds both the Ledger registry and wagmi config. Remove duplicate Chronicle definitions from other files by exporting `chronicleChainConfig`. |
| 33 | + |
| 34 | +### 4. `hooks/useLitServiceSetup.ts` |
| 35 | +- **Before**: Imports `@lit-protocol/networks` directly, builds `NETWORK_MODULES` locally, relies on literal strings. |
| 36 | +- **After**: Import `LIT_NETWORK_MODULES` from the registry, so the hook simply looks up the module by `config.networkName`. Removes duplicate destructuring and string arrays. |
| 37 | + |
| 38 | +### 5. `lit-login-modal/LitAuthProvider.tsx` |
| 39 | +- **Before**: Contains its own `NETWORK_MODULES` and re-creates the `supportedNetworks` list, auth-service default map, and testnet logic. |
| 40 | +- **After**: Consume the registry helpers. `supportedNetworks` defaults to `SUPPORTED_NETWORKS`. `forceNetworkSelection` uses `LIT_NETWORK_MODULES`. `authServiceUrlMap` seeds from `AppEnv.authUrls`. `shouldDisplayNetworkMessage` calls `isTestnetNetwork`. |
| 41 | + |
| 42 | +### 6. `_config.ts` |
| 43 | +- **Before**: Reads env vars inline and exports `APP_INFO`. |
| 44 | +- **After**: Import `AppEnv` (new helper) so URLs are sourced from one place. Optionally expose `networkAuthServiceUrls` directly from the registry to avoid per-file duplication. |
| 45 | + |
| 46 | +### 7. `lit-login-modal/components/AuthSettingsPanel.tsx` |
| 47 | +- **Before**: Builds the network tab list from props and hard-coded labels. |
| 48 | +- **After**: Map over `SUPPORTED_NETWORKS` and read labels/testnet badges from the registry. This ensures new networks automatically appear with correct metadata. |
| 49 | + |
| 50 | +### 8. `lit-logged-page/LoggedInDashboard.tsx` |
| 51 | +- **Before**: Tracks `selectedChain` default via inline `useEffect` + `getDefaultChainForNetwork`. |
| 52 | +- **After**: Initialize state from `NETWORKS[currentNetworkName].chainSlug` and rely on the registry for network badges (e.g., the header pill). |
| 53 | + |
| 54 | +### 9. `lit-login-modal/PKPSelectionSection.tsx` |
| 55 | +- **Before**: Determines ledger symbol/testnet state via manual checks. |
| 56 | +- **After**: Use the registry meta to decide which RPC to hit and which ledger symbol to display, avoiding local ternaries. |
| 57 | + |
| 58 | +### 10. `lit-logged-page/protectedApp/components/pkp/PKPInfoCard.tsx` |
| 59 | +- **Before**: Defines `ledgerUnit` using hard-coded comparisons. |
| 60 | +- **After**: Import `NETWORKS` meta and read `ledgerSymbol`, so the UI automatically reflects any future testnet/mainnet differences. |
| 61 | + |
| 62 | +### 11. `lit-logged-page/protectedApp/components/PaymentManagement/PaymentManagementDashboard.tsx` |
| 63 | +- **Before**: Similar duplicate logic for ledger symbol and chain labels. |
| 64 | +- **After**: Use registry meta for chain labels/ledger unit, keeping UI consistent. |
| 65 | + |
| 66 | +### 12. `main.tsx` |
| 67 | +- **Before**: Repeats Chronicle/Lit RPC constants and logs env vars manually. |
| 68 | +- **After**: Consume `chronicleChainConfig` / `getLitChainConfig` plus `AppEnv` for logging. Wagmi config becomes data-driven. |
| 69 | + |
| 70 | +## Testing |
| 71 | + |
| 72 | +1. `pnpm nx run explorer:lint` |
| 73 | +2. `pnpm nx run explorer:build` |
| 74 | +3. Smoke-test the explorer dev server (`pnpm nx serve explorer`) to ensure the network selector and auth modal show the new options and ledger balances display correct tokens. |
0 commit comments