Skip to content

fix(web): remove fake vouch XDR, externalize config, drop node-crypto fallback, split bundle - #100

Merged
EmeditWeb merged 1 commit into
mainfrom
fix/web-code-lapses-vouch-config-crypto-bundle
Sep 21, 2026
Merged

EmeditWeb merged 1 commit into
mainfrom
fix/web-code-lapses-vouch-config-crypto-bundle

Conversation

@EmeditWeb

Copy link
Copy Markdown
Member

Summary

Resolves four code-lapse issues found during the CI/quality pass on StepFi-Web. Each was code that either lied about what it did, hardcoded environment-specific values, or degraded the build — exactly the kind of lapse the quality pass exists to catch.

Changes

1. Removed vouch signing theater (correctness + trust)

Vouch.tsx and MentorDashboard.tsx built a random, fabricated XDR string, asked Freighter to sign it, then discarded the signature. It accomplished nothing functional and trained mentors to blind-sign arbitrary payloads — a real trust hazard.

Vouch approval is an authenticated, off-chain backend operation: POST /vouching/approve transitions the vouch record PENDING → APPROVED, authorized by the mentor's wallet-bound JWT (established once at wallet-connect time). There is no transaction to sign, so the signing step is removed and the handlers call the mutation directly. Dead txHash plumbing is dropped from useOptimisticVouch and vouching.service.

If on-chain vouching is wired up later, it should route through useTransaction + a backend-built XDR the way the deposit flow (#91) does — never a client-fabricated one.

2. Externalized hardcoded config

API_BASE_URL, STELLAR_NETWORK and the five CONTRACT_IDS were hardcoded. They now read from VITE_* env vars with testnet defaults — matching the existing SOROBAN_RPC_URL pattern that .env.example already advertised but the code ignored. .env.example now documents every variable.

3. Dropped browser-incompatible crypto fallback

soroban.service computeSha256 had an await import('crypto') Node fallback that triggered Vite's "'crypto' externalized for browser compatibility" warning and emitted a __vite-browser-external chunk. Web Crypto (crypto.subtle) is the single portable SHA-256 path across secure browser contexts and Node 19+, so it is now the only path.

4. Split the monolithic bundle

The router now lazy-loads every route page, so the Stellar SDK and other heavy per-page dependencies leave the initial chunk.

Before After
Initial entry ~2,008 kB (565 kB gzip) 386 kB (124 kB gzip)
stellar-sdk in the initial chunk isolated in a lazy chunk, loaded only where needed

The residual >500 kB warning on the isolated stellar-sdk chunk is left as-is on purpose — it is an honest signal about a genuinely large dependency, not something to silence with chunkSizeWarningLimit.

Test plan

  • npm run lint — clean
  • npm run test — 49/49 pass (10 files)
  • npm run build — green; crypto externalization warning gone; initial entry 386 kB
  • Reviewer: connect as a mentor and confirm approving a vouch request still transitions it (no Freighter signing prompt should appear)

Follow-up (not in this PR)

handleDecline in the vouch views is still a stubbed 600 ms timeout with no backend decline endpoint to call. Left as-is here — it needs an API endpoint before it can be wired up. Flagging for a future issue.

… fallback, split bundle

Resolve four code-lapse issues surfaced in the CI/quality pass:

- Vouch signing theater: Vouch.tsx and MentorDashboard.tsx fabricated a
  random XDR string and asked Freighter to sign it, then discarded the
  signature entirely — a blind-sign trust hazard that accomplished nothing.
  Vouch approval is an authenticated, off-chain backend transition
  (POST /vouching/approve, authorized by the mentor's wallet-bound JWT), so
  the bogus signing step is removed and the handlers call the mutation
  directly. Dead txHash plumbing dropped from useOptimisticVouch and
  vouching.service. If on-chain vouching is ever wired up, it should route
  through useTransaction + a backend-built XDR the way deposits do — never a
  client-fabricated one.

- Hardcoded config: API_BASE_URL, STELLAR_NETWORK and the five CONTRACT_IDS
  now read from VITE_* env vars with testnet defaults, matching the existing
  SOROBAN_RPC_URL pattern that .env.example already advertised but the code
  ignored. .env.example documents every variable.

- Browser-incompatible crypto: soroban.service computeSha256 dropped its
  `await import('crypto')` Node fallback, which triggered Vite's "'crypto'
  externalized for browser compatibility" warning and emitted a
  __vite-browser-external chunk. Web Crypto (crypto.subtle) is the single
  portable SHA-256 path across secure browser contexts and Node 19+.

- Monolithic bundle: the router now lazy-loads every route page, so the
  Stellar SDK and other heavy per-page deps leave the initial chunk. Initial
  entry drops from ~2,008 kB (565 kB gzip) to 386 kB (124 kB gzip); stellar-sdk
  is isolated in a lazy chunk loaded only on the pages that need it.

Verified: eslint clean, 49/49 vitest pass, production build green with the
crypto externalization warning gone.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@EmeditWeb
EmeditWeb merged commit 350fef6 into main Sep 21, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant