Skip to content

Chore: Cleanup NS#11

Open
Rashmi-278 wants to merge 48 commits intomainfrom
fix-ns
Open

Chore: Cleanup NS#11
Rashmi-278 wants to merge 48 commits intomainfrom
fix-ns

Conversation

@Rashmi-278
Copy link
Copy Markdown
Collaborator

@Rashmi-278 Rashmi-278 commented Feb 19, 2026

Code Structure Clean Up of /ns

Note: @craftsoldier Here's the relevant commit dba417a

Add ~50 line documentation files to each major subfolder to help
AI agents understand the codebase structure, Zcash integrations,
and testing harnesses.
- Move edits store to /ui/profile/store.ts
- Move messaging store to /ui/verification/store.ts
- Delete unused swap.ts and thread.ts stores
- Remove /lib/stores/ folder entirely
- Delete computePendingEdits logic (no longer needed)
- Update all imports to new locations
- Update AGENT.md files to reflect new structure

Stores are now colocated with the features that use them,
improving discoverability and separation of concerns.
Remove the old verification system that encoded profile changes in
Zcash memos. The new ZVS (Zcash Verification Service) uses a simpler
OTP-based flow where edits are submitted directly to the backend
after address ownership is proven.

- Remove PendingEdits/PendingProfileChange types
- Remove isLinkAuthPending function
- Remove pendingEdits state from store
- Simplify ProfileVerification to use profile ID memo
- Update AGENT.md docs for new ZVS flow
Move shared style utilities from ui/styles/ to their related component folders:
- fields.ts → ui/common/forms/styles.ts
- interactive.ts → ui/common/buttons/styles.ts
Delete all index.ts barrel files and update imports to use direct paths.
Improves tree-shaking, build performance, and eliminates circular dep risk.
New verification flow:
- Generate session with memo: zvs/{session_id},{u-address}
- OTP computed deterministically from memo using HMAC-SHA256
- Multiple sessions per user allowed (last-write-wins)
- Sessions stored in Supabase, expire after 24 hours

Added:
- lib/verification/session.ts - session ID and memo generation
- lib/verification/otp.ts - HMAC-SHA256 OTP generation/verification
- lib/verification/verificationSessionAction.ts - Supabase CRUD

Removed:
- useVerificationPolling.ts - no more backend polling
- InlineOtpForm.tsx, useOtpFlow.ts, otpMessages.ts - simplified
- ProgressStep.tsx - unused after polling removal
- confirmOtp.ts - replaced with direct HMAC verification

Updated AGENT.md files to reflect new architecture.
- Add session lockout after 3 failed OTP attempts (24h expiry)
- Block new session creation while locked session exists
- One session per profile via upsert on zcasher_id
- Decrement attempts_remaining on failed OTP verification
- Refactor ProfileVerification UI flow:
  - Generate QR: creates session locally, shows QR + memo
  - Enter OTP: writes session to Supabase, shows OTP input
  - Submit: verifies against Supabase
- Add schema.md with table DDL and apply_pending_edits_sql RPC
- Improve ZVS_SECRET_SEED handling with production check
- Add sessionId to edits store (not auto-regenerated on edit changes)
- Add regenerateSessionId action to store
- Generate QR button calls regenerateSessionId before showing QR
- Fix memo textarea styling (mb-3 spacing, better text display)
Replace URL-parsing verification with direct OAuth flow:
- User clicks provider button → OAuth → link auto-added as verified
- No more URL parsing, username comparison, or normalization
- OAuth response is the source of truth

New lib/social/ structure:
- providers.ts: provider definitions & handle extraction
- connect.ts: start OAuth flow
- useConnectCallback.ts: handle OAuth return
- verifyLink.ts: DB upsert for verified links
- avatars.ts: avatar fetching from providers
- utils.ts: URL parsing utilities

Removed 913 lines, added 630 lines (-283 net)
Replace separate "Enter Passcode" button with unified "Verify Profile"
modal that includes both the full verification flow and direct OTP entry
via tabbed interface.
- Move createVerificationSession call to handleGenerateQr so session is
  saved to DB before QR is displayed (prevents data loss if user leaves)
- Show OTP input immediately with QR (remove extra "Enter OTP" step)
- Add pending session notice when user has existing unverified session
- Add disabled prop to AmountAndWallet button
- Update modal copy for clarity
Remove database persistence for verification sessions. Users must now
complete verification in one browser session - if they navigate away,
they need to generate a new QR and send again.

- Remove verificationSessionAction.ts and SubmitOtp.tsx
- confirmOtpAction now takes memo from client instead of DB lookup
- Simplify VerifyProfileModal (remove "I Have a Code" tab)
- Update AGENT.md documentation for new flow
Prevents unauthorized social link verification by checking that the
profile's address is verified before allowing OAuth-linked accounts
to be marked as verified. Client-side check alone was bypassable.
Prevents attackers from verifying arbitrary profiles by ensuring
the address embedded in the memo matches the profile's actual address.
Move the memo display to appear directly below the header and above the
amount input. QR section now only shows the QR code.
Connect useEditsStore to confirmOtpAction so profile changes are
persisted when OTP verification succeeds. Edits are compared against
original values and only changed fields are sent to the server.
- Extract useFieldValidation hook and FieldMessages component from Input/TextArea
- Consolidate swap parameter validation and request building into shared functions
- Defer social link DB writes until after OTP verification
- Remove debug console.log from getRateAction
- Update next-env.d.ts path and clean up AGENT.md
Remove useEffect that overwrote form.links whenever originalLinks
changed, which caused user edits to be lost during the verification
flow. Also remove stale comments about auto-computed link tokens.
- Use SUPABASE_SERVICE_ROLE_KEY for server-side operations to bypass RLS
- Refactor OTP to hash only sessionId (not full memo) matching Rust impl
- Hex-decode secret seed bytes to match ZVS hex::decode behavior
- Use u32::from_be_bytes approach for hash-to-OTP conversion
Use .slice() to create a Uint8Array backed by ArrayBuffer instead of
ArrayBufferLike, satisfying the stricter BufferSource type requirement.
BUG: The OTP verification flow (confirmOtpAction) only wrote
nearest_city_id to the zcasher table but never nearest_city_name.
The zcasher_searchable view does NOT join the worldcities table to
resolve city names, so profiles edited via the OTP flow had
nearest_city_name = null — making the city invisible on the profile
card and the editor placeholder.

Profiles created via signup were unaffected because that flow writes
both fields.

Fixes:
- confirmOtpAction: now writes nearest_city_name alongside nearest_city_id
- ProfileEditsPayload: added nearest_city_name to the type
- ProfileVerification: passes nearest_city_name in the edits payload
- profileFetcher: resolves city name from worldcities table as a
  fallback when the view returns null (fixes existing broken data)

TODO: Update the zcasher_searchable view to LEFT JOIN worldcities
so nearest_city_name is always populated, then the profileFetcher
fallback can be removed.

Also adds console.log debug statements throughout the OTP verification
flow (client + server) for development tracing.
…actors

Delete 3 dead files (useProfileEvents, AuthExplainerModal, standalone
RedirectModal) and remove orphaned props/state (linkAuthTokens,
regenerateSessionId, badgeOnClick, onSelect, warning prop, compact
variant) that survived past refactors but are no longer referenced.
craftsoldier and others added 18 commits February 18, 2026 22:19
Split the monolithic ProfileCard into single-responsibility pieces:
- ProfileCardListView: compact list card (self-contained)
- ProfileCardActions: menu dropdown + share button (owns its own state)
- ProfileCardWarning: trust warning banner (owns expand/collapse state)
- ProfileCard: slim orchestrator for full view + flip layout
Move OAuth social verification flow from ProfileEditor to ProfileCard.
Users now verify links by clicking the gray "Not Authenticated" badge
on the profile card front, which triggers OAuth and persists immediately
via upsertVerifiedLink — no OTP save step required.
Eliminates the Supabase worldcities table dependency by using the
city-timezones npm package for city autocomplete search. Removes
nearest_city_id from all profile flows (signup, edit, verification)
since the FK column will be dropped in a follow-up DB migration.
Only address-verified profiles can authenticate social links:
- Client: badge not clickable for unverified users
- Server: upsertVerifiedLink checks address_verified before persisting
Prevents valid falsy values (0, "") from being incorrectly swallowed
by logical OR when the intent is to provide defaults for null/undefined.
…as verified

Previously upsertVerifiedLink trusted the client-provided URL without
cross-referencing the OAuth session. Now the server action validates the
access token via getUser(), extracts the provider identity, and confirms
the handle matches the claimed URL before persisting.
Prevents client-side brute-force attacks by generating verification
memos on the server (generateMemoAction) and tracking attempts in an
in-memory store (memoStore). Memos not issued by the server are
rejected. After 5 failed OTP attempts the memo is invalidated and a
fresh one is returned to the client.
…sed files

Remove verifyLinkAction.ts and social/utils.ts, refactor social connect
and verifyLink, update profile types and link derivation, enhance
ProfileEditor, and clean up API routes.
Move detectProviderFromUrl and extractHandleFromUrl into providers.ts.
Replace session-based avatar fetching with simple public URL approach
(GitHub .png, unavatar.io for X). Remove AvatarReauthModal and all
related plumbing from ProfileEditor.
… pattern matching

Delete lib/profile/social-lookup.ts (341 lines) and inline a simplified
version into app/api/social/route.ts. Queries now filter by the platform
column directly instead of building ILIKE patterns across every domain
variant.
Last consumer (ui/links/avatars.ts) was removed in eaed612;
no remaining imports.
@vercel
Copy link
Copy Markdown

vercel bot commented Feb 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
directory Ready Ready Preview, Comment Feb 19, 2026 2:19pm

Request Review

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.

2 participants