#377 [Frontend] [Feature] Integrate Soroban/Backend Search API for Global Certificate Search FIXED - #479
Merged
Conversation
… for Global Certificate Search FIXED
|
@veloura-dev is attempting to deploy a commit to the DaniBravo Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
Author
|
@Tybrvo |
Contributor
Author
|
@Tybravo review pls |
Owner
|
Good job done Thanks. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CLOSE #377
Findings & Fix Features
(Note: the sandbox dropped .git between sessions — all 13 fix files are intact and suites re-verified green post-restore, and the complete fix is packaged as
stellarproof-search-api-fix.patch
so the diff remains reproducible.)
A. FINDINGS — what was wrong on main
Finding 1 — The search page never talked to any API (the core issue).
frontend/app/search/services/searchService.ts shipped a mock: a hard-coded 7-item MOCK_RESULTS array plus a fake 600 ms setTimeout. Its own header comment admitted it: "Replace searchCertificates() with a live oracle / indexer call once the registry backend is wired up." So the UI could only ever render fake certificates.
Finding 2 — The backend couldn't serve a global search at all.
GET /api/v1/certificates required a per-user Mongo creatorId ObjectId (Zod-enforced) and had no search parameter — a global public certificate index was impossible to express against it.
Finding 3 — main did not compile. 🚨
next build on pristine main fails at the issue's own affected path:
text
./app/search/page.tsx:321:13
Type error: Type 'SearchResult[]' is not assignable to type 'Certificate[]'.
Type 'SearchResult' is missing: title, thumbnailUrl, issuerName, issueDate
The gridResults adapter was computed and then thrown away — raw results was passed to GridView (introduced by the grid-view PR #463).
Finding 4 — The in-scope test suite was 100% broken at baseline (7/7 failing).
app/search/tests/search.test.tsx targeted a superseded page design (commit bfe5ec4: search button, ID/hash field toggle) that no longer matches the current debounced live-search page.
Finding 5 — The clear (✕) button left stale results on screen.
It only cleared the input (setQuery("")) and never restored the cached index.
Finding 6 — GridView thumbnails would crash at runtime.
next/image served picsum.photos URLs that weren't in next.config.ts images.remotePatterns → Invalid src runtime error in grid mode.
B. FIX FEATURES — what the fix does
Frontend (the issue's declared path):
Real API data fetching (Axios/fetch → fetch, matching repo conventions): searchService.ts is now a live client calling GET {NEXT_PUBLIC_API_URL}/api/v1/certificates?search=…&limit=50&skip=0 — fetchAllCertificates() (no query → global index) and searchCertificates(query) (debounced search), both with AbortSignal support.
Envelope + type mapping: unwraps the backend's { success, data: {certificates, total} } shape and maps each document → SearchResult (id ← Soroban certificateId, hash ← manifest contentHash/tx hash, creator ← on-chain Stellar creator, name/type ← populated asset, MIME bucketed to Image/Video/Audio/Document/3D Model).
Loading states preserved & hardened: skeleton/spinner on initial load and on every debounced keystroke; aborted requests never flash false error banners.
Robust error handling: non-2xx → surfaces the server's message; network down → friendly "Unable to reach the StellarProof API…"; malformed payload → explicit shape error.
Build-breaker removed: GridView now receives the adapted Certificate[]:
Diff
Correct data passing to both views: ListView ← SearchResult[], GridView ← adapted Certificate[] (type-safe).
✕ clear restores the cached index instantly — no redundant fetch, no stale rows.
Runtime crash closed: picsum.photos added to images.remotePatterns; .env.example documents NEXT_PUBLIC_API_URL (and is whitelisted in .gitignore — .env* was swallowing it).
Backend (additive, required for "real data", creatorId legacy callers unaffected):
9. Global index: creatorId now optional — omitting it returns the public global certificate index sorted newest-first.
10. Search filter: new Zod-validated search? param → regex-escaped, case-insensitive $or across certificateId, transactionHash, contractAddress; combines with creatorId under $and.
11. Richer records: list query now .populate()s assetId (name/type) and manifestId (content hash/creator/description) so the UI renders human-readable rows in one round-trip.
Acceptance criteria all met — each backed by automated tests: ✅ real data from API • ✅ spinners during fetch • ✅ loading/error states • ✅ data passed to List/Grid • PR-ready (
stellarproof-search-api-fix.patch
; remember Closes #[issue_id]).
Verified (post-restore): search 17/17 ✅ · backend 56/56 (11 suites) ✅ · next build ✓ with /search ✅ · ESLint clean on all touched files ✅