Skip to content

refactor: split dashboard app.js into 9 ES modules#193

Open
GTC6244 wants to merge 22 commits intonextfrom
GTC6244/dashboard-ceo-review
Open

refactor: split dashboard app.js into 9 ES modules#193
GTC6244 wants to merge 22 commits intonextfrom
GTC6244/dashboard-ceo-review

Conversation

@GTC6244
Copy link
Copy Markdown
Contributor

@GTC6244 GTC6244 commented Mar 27, 2026

Summary

Refactors the monolithic dashboard app.js (1553 lines) into 9 focused ES modules for maintainability and readability.

Changes

  • Module split: auth.js, ui-utils.js, billing.js, groups.js, keys.js, actions.js, wallets.js, runner.js, and slim app.js entry point
  • Bug fixes during refactor:
    • Restored auth-ready flow for returning users on page refresh
    • Removed accidental groupId: '0' param from listActions
    • Fixed deploy workflow missing setup-node step
  • CI fixes from merge with next:
    • Removed duplicate configOperator field in AccountConfigStorage struct
    • Deduplicated setup-node steps in deploy-static.yml

Architecture

  • No circular dependencies: ui-utils.jsauth.js → feature modules → app.js entry
  • All HTML construction uses escapeHtml() — no XSS vectors
  • Error handling consistent across all CRUD modules (try/catch/finally with progress indicators)

Files changed

  • 9 new JS modules under lit-static/dapps/dashboard/
  • app.js reduced from 1553 to 37 lines
  • Deploy workflow and Solidity storage fixes (merge resolution)

Test plan

  • Login with existing API key — verify dashboard loads, stat cards populate
  • Create new account — verify API key banner, auto-login
  • Navigate all tabs (groups, keys, actions, wallets) — verify tables render
  • CRUD operations on each entity type
  • Theme toggle (light/dark) persists across tab switches
  • Action runner: load code, execute with params, view result
  • Billing: open add funds modal, verify Stripe card element mounts
  • Deploy to staging via Cloudflare Pages — verify __LIT_API_BASE_URL__ injection in auth.js

🤖 Generated with Claude Code

GTC6244 and others added 3 commits March 26, 2026 22:23
Split 1553-line monolith into focused modules:
- ui-utils.js: error classification, clipboard, modals, icons
- auth.js: session state, cached API client singleton, theme, login
- billing.js: Stripe integration with payment integrity fix
- groups.js: multi-select builders, table rendering, CRUD
- keys.js: usage key table, 7-field permission modal, CRUD
- actions.js: IPFS action table, CRUD
- wallets.js: wallet table, CRUD
- runner.js: CodeJar editor, execute/getCid
- app.js: entry point orchestrating init

Bug fixes included:
- getClient() now caches singleton instead of new instance per call
- preloadAllTables uses Promise.allSettled with error banner
- Payment flow: separate confirmPayment catch for integrity
- Billing amount validation: minimum $5.00 (500 cents)
- Error classification: auth/network/server user-friendly messages
- Unified copyToClipboard utility replacing 3 inline patterns
- Button disable-on-click during async operations
- loadBillingBalance shows "Balance unavailable" on error

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…-review

# Conflicts:
#	lit-static/dapps/dashboard/actions.js
#	lit-static/dapps/dashboard/auth.js
#	lit-static/dapps/dashboard/billing.js
#	lit-static/dapps/dashboard/groups.js
#	lit-static/dapps/dashboard/keys.js
#	lit-static/dapps/dashboard/runner.js
#	lit-static/dapps/dashboard/ui-utils.js
#	lit-static/dapps/dashboard/wallets.js
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 27, 2026 02:47
GTC6244 and others added 3 commits March 26, 2026 22:56
6 items from adversarial review during PR1 ship — mostly pre-existing
patterns from the monolith. P1: initLogin null check. P2: auth ordering,
confirm dialog race. P3: listener leak, form value ordering, async fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Change sed target from app.js to auth.js (where __LIT_API_BASE_URL__
  moved during the module refactor)
- Add actions/setup-node@v4 so npm is available for wrangler-action on
  the self-hosted runner

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GTC6244 GTC6244 changed the title refactor: split dashboard app.js into 9 ES modules gstack DashBoard Review Mar 28, 2026
@GTC6244 GTC6244 self-assigned this Mar 28, 2026
GTC6244 and others added 4 commits March 30, 2026 18:02
initLogin() now calls updateAuthUI() when an existing API key is found
in sessionStorage. Without this, returning users saw an empty dashboard
because the has-api-key class was never toggled and preloadAllTables/
loadBillingBalance/updateStatCards were never called.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- deploy-static.yml: all jobs now target auth.js (module refactor moved placeholder)
- TODOS.md: keep both dashboard adversarial findings and Stripe validation TODO
- app.js: keep refactored entry point (monolith code now in separate modules)
…vior

The refactored loadActions() added groupId: '0' which was not in the
original monolith. This could filter actions to only the default group,
diverging from the "zero behavior change" intent of the refactor.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The setup-node@v4 step was only in deploy-main. Added to deploy-next
and deploy-preview for consistency across all deploy jobs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@GTC6244 GTC6244 requested a review from a team March 30, 2026 22:22
@GTC6244 GTC6244 changed the title gstack DashBoard Review refactor: split dashboard app.js into 9 ES modules Mar 30, 2026
GTC6244 and others added 11 commits March 31, 2026 21:56
Keep deploy-preview job from our branch (added in this PR).
origin/next had no changes to the end of the file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The configOperator address was referenced in AccountConfig.sol constructor,
SecurityLib, APIConfigFacet, and ViewsFacet but never declared in the
AccountConfigStorage struct, causing Solidity compilation failure.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The self-hosted runner doesn't have npm in PATH, causing
cloudflare/wrangler-action@v3 to fail when trying to install wrangler.
Add actions/setup-node@v4 with Node 20 before the deploy step, matching
the pattern used by other workflows in this repo.

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ains (#261)

- api.dev.litprotocol.com → api.chipotle.litprotocol.com
- dashboard.dev.litprotocol.com → dashboard.chipotle.litprotocol.com
- docs.dev.litprotocol.com → developer.litprotocol.com
- Fix broken swagger-ui path (/swagger-ui/ → /core/v1/swagger-ui)
- Remove broken Support navbar link
- Fix broken SDK link in encryption migration doc

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* docs: migrate README URLs from dev.litprotocol.com to new domains

Same migration as the docs/ directory (PR #261):
- api.dev.litprotocol.com → api.chipotle.litprotocol.com
- dashboard.dev.litprotocol.com → dashboard.chipotle.litprotocol.com
- docs.dev.litprotocol.com → developer.litprotocol.com

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: update "dev API" to "API" in README quickstart

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: add usage API key step to README quickstart

Adds step 2 showing how to create a scoped usage API key before
using the API, reinforcing the best practice of not embedding
the account key in apps. Renumbers subsequent steps.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* docs: reorder quickstart — add funds before usage API key

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace localhost:8000 and api.dev.litprotocol.com references in curl
examples across MDX docs with https://api.chipotle.litprotocol.com.

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
After merging next, the struct had two configOperator declarations: one
from next (replacing owner) and one from our earlier fix commit. Remove
the duplicate at the end of the struct, keeping next's version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Merge with next created duplicate setup-node steps in deploy-main and
deploy-next jobs. Also reordered deploy-preview to match consistent
pattern: checkout → setup-node → inject URL → deploy.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ref: ${{ inputs.version_tag }}

- uses: actions/setup-node@v4
with:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sed command still targets app.js but the __LIT_API_BASE_URL__ placeholder is now in auth.js after the refactor. This will cause the production deployment to use the wrong API URL (localhost fallback).

run: sed -i "s|__LIT_API_BASE_URL__|https://api.chipotle.litprotocol.com|g" lit-static/dapps/dashboard/auth.js

Spotted by Graphite

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

…ture

Merges origin/next which adds usage API key override feature. Resolves
conflict in app.js by keeping modular structure and porting the new
feature into ES modules:
- auth.js: getEffectiveApiKey, override state management, debug proxy
- app.js: override UI init, sign-out cleanup
- groups/keys/actions/wallets: use getEffectiveApiKey for CRUD ops
- runner: use getEffectiveApiKey for action execution

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants