Skip to content

Commit a3eb32b

Browse files
committed
fmt
1 parent d4a1f7b commit a3eb32b

File tree

19 files changed

+328
-775
lines changed

19 files changed

+328
-775
lines changed

apps/explorer/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
"update:lit": "pnpm update --latest --filter '@lit-protocol/*'"
1515
},
1616
"dependencies": {
17-
"@lit-protocol/access-control-conditions": "8.0.2",
18-
"@lit-protocol/auth": "8.1.2",
19-
"@lit-protocol/lit-client": "8.2.3",
20-
"@lit-protocol/naga-la-types": "^0.1.0",
21-
"@lit-protocol/networks": "8.3.2",
17+
"@lit-protocol/access-control-conditions": "workspace:*",
18+
"@lit-protocol/auth": "workspace:*",
19+
"@lit-protocol/lit-client": "workspace:*",
20+
"@lit-protocol/naga-la-types": "0.1.0",
21+
"@lit-protocol/networks": "workspace:*",
2222
"@monaco-editor/react": "^4.7.0",
2323
"@radix-ui/react-dropdown-menu": "^2.1.16",
2424
"@radix-ui/react-hover-card": "^1.1.15",

apps/explorer/plan.md

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,74 @@
1-
## Architecture Improvements Roadmap
1+
## Goal
22

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.
74

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
126

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`
1619

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
2021

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.

apps/explorer/src/_config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ export const APP_INFO = {
2828
"naga-test":
2929
import.meta.env.VITE_AUTH_SERVICE_URL_NAGA_TEST ||
3030
"https://auth-api.litprotocol.com",
31+
"naga-proto":
32+
import.meta.env.VITE_AUTH_SERVICE_URL_NAGA_PROTO ||
33+
"https://auth-api.litprotocol.com",
3134
naga:
3235
import.meta.env.VITE_AUTH_SERVICE_URL_NAGA ||
3336
"https://auth-api.litprotocol.com",

apps/explorer/src/domain/lit/chains.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import {
2+
LIT_CHAIN_EXPLORER_URL,
3+
LIT_CHAIN_ID,
4+
LIT_CHAIN_NAME,
5+
LIT_CHAIN_RPC_URL,
6+
LIT_CHAIN_SYMBOL,
7+
} from "./litChainConfig";
8+
19
export interface LitChainConfig {
210
id: number;
311
name: string;
@@ -11,6 +19,16 @@ export interface LitChainConfig {
1119
export const SUPPORTED_CHAIN_ID = 2888;
1220
const CUSTOM_CHAINS_STORAGE_KEY = "chains.custom.v1";
1321

22+
const LIT_CHAIN_BASE_CONFIG: LitChainConfig = {
23+
id: LIT_CHAIN_ID,
24+
name: LIT_CHAIN_NAME,
25+
symbol: LIT_CHAIN_SYMBOL,
26+
rpcUrl: LIT_CHAIN_RPC_URL,
27+
explorerUrl: LIT_CHAIN_EXPLORER_URL,
28+
litIdentifier: "lit-chain",
29+
testnet: false,
30+
};
31+
1432
export const DEFAULT_CHAINS: Record<string, LitChainConfig> = {
1533
yellowstone: {
1634
id: 175188,
@@ -21,6 +39,16 @@ export const DEFAULT_CHAINS: Record<string, LitChainConfig> = {
2139
litIdentifier: "yellowstone",
2240
testnet: true,
2341
},
42+
"naga-proto": {
43+
...LIT_CHAIN_BASE_CONFIG,
44+
name: "Lit Chain (naga-proto)",
45+
litIdentifier: "naga-proto",
46+
},
47+
naga: {
48+
...LIT_CHAIN_BASE_CONFIG,
49+
name: "Lit Chain (naga)",
50+
litIdentifier: "naga",
51+
},
2452
ethereum: {
2553
id: 1,
2654
name: "Ethereum",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { Chain } from "viem";
2+
3+
const DEFAULT_LIT_CHAIN_RPC_URL = "https://lit-chain-rpc.litprotocol.com/";
4+
const DEFAULT_LIT_CHAIN_EXPLORER_URL =
5+
"https://lit-chain-explorer.litprotocol.com/";
6+
const DEFAULT_LIT_CHAIN_EXPLORER_NAME = "Lit Chain Explorer";
7+
8+
export const LIT_CHAIN_ID = 175200;
9+
export const LIT_CHAIN_NAME = "Lit Chain";
10+
export const LIT_CHAIN_SYMBOL = "LITKEY";
11+
12+
export const LIT_CHAIN_RPC_URL =
13+
import.meta.env.VITE_LIT_CHAIN_RPC_URL || DEFAULT_LIT_CHAIN_RPC_URL;
14+
export const LIT_CHAIN_EXPLORER_URL =
15+
import.meta.env.VITE_LIT_CHAIN_EXPLORER_URL ||
16+
DEFAULT_LIT_CHAIN_EXPLORER_URL;
17+
export const LIT_CHAIN_EXPLORER_NAME =
18+
import.meta.env.VITE_LIT_CHAIN_EXPLORER_NAME ||
19+
DEFAULT_LIT_CHAIN_EXPLORER_NAME;
20+
21+
export const litChainViemConfig: Chain = {
22+
id: LIT_CHAIN_ID,
23+
name: LIT_CHAIN_NAME,
24+
nativeCurrency: {
25+
name: LIT_CHAIN_NAME,
26+
symbol: LIT_CHAIN_SYMBOL,
27+
decimals: 18,
28+
},
29+
rpcUrls: {
30+
default: { http: [LIT_CHAIN_RPC_URL] },
31+
public: { http: [LIT_CHAIN_RPC_URL] },
32+
},
33+
blockExplorers: {
34+
default: {
35+
name: LIT_CHAIN_EXPLORER_NAME,
36+
url: LIT_CHAIN_EXPLORER_URL,
37+
},
38+
},
39+
testnet: false,
40+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import type { SupportedNetworkName } from "@/lit-login-modal/types";
2+
3+
const KNOWN_NETWORKS = [
4+
"naga-dev",
5+
"naga-test",
6+
"naga-proto",
7+
"naga",
8+
] as const;
9+
10+
const TESTNET_NETWORKS = new Set<SupportedNetworkName>([
11+
"naga-dev",
12+
"naga-test",
13+
]);
14+
15+
const DEFAULT_CHAIN_BY_NETWORK: Record<SupportedNetworkName, string> = {
16+
"naga-dev": "yellowstone",
17+
"naga-test": "yellowstone",
18+
"naga-proto": "naga-proto",
19+
naga: "naga",
20+
};
21+
22+
function isSupportedNetworkName(value: string): value is SupportedNetworkName {
23+
return (KNOWN_NETWORKS as readonly string[]).includes(value);
24+
}
25+
26+
export function normalizeNetworkName(
27+
networkName?: string
28+
): SupportedNetworkName {
29+
const candidate = (networkName?.toLowerCase() ?? "naga-dev") as string;
30+
return isSupportedNetworkName(candidate)
31+
? (candidate as SupportedNetworkName)
32+
: "naga-dev";
33+
}
34+
35+
export function getDefaultChainForNetwork(networkName?: string): string {
36+
const normalized = normalizeNetworkName(networkName);
37+
return DEFAULT_CHAIN_BY_NETWORK[normalized];
38+
}
39+
40+
export function isTestnetNetwork(networkName?: string): boolean {
41+
const normalized = normalizeNetworkName(networkName);
42+
return TESTNET_NETWORKS.has(normalized);
43+
}

apps/explorer/src/hooks/useLitServiceSetup.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,20 @@
88
import React, { useState, useCallback, useRef } from "react";
99
import { createLitClient } from "@lit-protocol/lit-client";
1010
import { createAuthManager, storagePlugins } from "@lit-protocol/auth";
11-
import { nagaDev, nagaTest } from "@lit-protocol/networks";
11+
import { nagaDev, nagaTest, nagaProto, naga } from "@lit-protocol/networks";
1212

1313
// Configuration constants at the top
1414
const DEFAULT_APP_NAME = "lit-auth-app";
15-
type NetworkModule = typeof nagaDev | typeof nagaTest;
15+
type NetworkModule =
16+
| typeof nagaDev
17+
| typeof nagaTest
18+
| typeof nagaProto
19+
| typeof naga;
1620
const NETWORK_MODULES: Record<string, NetworkModule> = {
1721
"naga-dev": nagaDev,
1822
"naga-test": nagaTest,
23+
"naga-proto": nagaProto,
24+
naga,
1925
};
2026

2127
interface LitServiceSetupConfig {

apps/explorer/src/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const HomePage = () => {
5555
return (
5656
<LitAuthProvider
5757
appName="lit-auth-modal-demo"
58-
supportedNetworks={["naga-dev", "naga-test", "naga"]}
58+
supportedNetworks={["naga-dev", "naga-test", "naga-proto", "naga"]}
5959
defaultNetwork="naga-dev"
6060
authServiceBaseUrl={APP_INFO.litAuthServer}
6161
persistUser={false}

apps/explorer/src/lit-logged-page/LoggedInDashboard.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { getAddress } from "viem";
2727
import { formatPublicKey } from "./protectedApp/utils";
2828
import { PKPData } from "@lit-protocol/schemas";
2929
import { APP_INFO } from "@/_config";
30+
import { getDefaultChainForNetwork } from "@/domain/lit/networkDefaults";
3031

3132
enum LOGIN_STYLE {
3233
button = "button",
@@ -125,6 +126,10 @@ export default function LoggedInDashboard() {
125126
const [selectedChain, setSelectedChain] = useState<string>("yellowstone");
126127
const [, setStatus] = useState<string>("");
127128

129+
useEffect(() => {
130+
setSelectedChain(getDefaultChainForNetwork(currentNetworkName));
131+
}, [currentNetworkName]);
132+
128133
// Transaction toast state
129134
const [transactionToasts, setTransactionToasts] = useState<
130135
TransactionToast[]

apps/explorer/src/lit-logged-page/protectedApp/components/PaymentManagement/PaymentManagementDashboard.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { triggerLedgerRefresh } from "../../utils/ledgerRefresh";
66
import { usePaymentManagerInstance } from "../../hooks/usePaymentManagerInstance";
77
import { useLedgerBalance } from "../../hooks/useLedgerBalance";
88
import { useWithdrawStatus } from "../../hooks/useWithdrawStatus";
9+
import { getAllChains } from "@/domain/lit/chains";
910

1011
interface PaymentManagementDashboardProps {
1112
selectedPkp: UIPKP | null;
@@ -101,9 +102,13 @@ export const PaymentManagementDashboard: React.FC<
101102
const [error, setError] = useState<string>("");
102103
const resolvedAccountAddress =
103104
targetUserAddress || account?.address || account?.account?.address;
104-
const activeChainLabel = selectedChain
105-
? selectedChain.replace(/-/g, " ")
106-
: "unknown";
105+
const allChains = getAllChains();
106+
const selectedChainInfo = selectedChain
107+
? allChains[selectedChain as keyof typeof allChains]
108+
: undefined;
109+
const activeChainLabel =
110+
selectedChainInfo?.name ||
111+
(selectedChain ? selectedChain.replace(/-/g, " ") : "unknown");
107112

108113
// Success feedback helper
109114
const showSuccess = (actionId: string) => {

0 commit comments

Comments
 (0)