Skip to content

Commit 59ef7e1

Browse files
committed
fix(wallet): use subgraph for staking/orchestrators (Browse All root cause)
The staking/orchestrators route (used by Browse All via useOrchestratorCache) was purely DB-based, returning only 7 records from the unpopulated production DB. The Express backend calls getOrchestrators() (subgraph) directly. Fixed to match Express: call getOrchestrators() from subgraph, returning ~100 active orchestrators. Also cleaned up diagnostic logging from enhanced route and subgraph utility. Made-with: Cursor
1 parent a9ca5db commit 59ef7e1

3 files changed

Lines changed: 10 additions & 38 deletions

File tree

apps/web-next/src/app/api/v1/wallet/orchestrators/enhanced/route.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,9 @@ export async function GET(request: NextRequest) {
2626
},
2727
},
2828
}),
29-
getOrchestrators().catch((err) => {
30-
console.error('[orchestrators/enhanced] subgraph failed, falling back to DB:', err?.message || err);
31-
return [] as any[];
32-
}),
29+
getOrchestrators().catch(() => [] as any[]),
3330
]);
3431

35-
console.log(`[orchestrators/enhanced] db=${dbOrchestrators.length} live=${liveOrchestrators.length}`);
36-
3732
const dbMap = new Map(
3833
dbOrchestrators.map((o) => [o.address.toLowerCase(), o]),
3934
);
@@ -109,11 +104,7 @@ export async function GET(request: NextRequest) {
109104
}));
110105
}
111106

112-
return NextResponse.json({
113-
data,
114-
synced,
115-
_debug: { dbCount: dbOrchestrators.length, liveCount: liveOrchestrators.length, source: liveOrchestrators.length > 0 ? 'subgraph' : 'db' },
116-
});
107+
return NextResponse.json({ data, synced });
117108
} catch (err) {
118109
console.error('[orchestrators/enhanced] Error:', err);
119110
return errors.internal('Failed to fetch enhanced orchestrators');

apps/web-next/src/app/api/v1/wallet/staking/orchestrators/route.ts

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/**
22
* Wallet Staking Orchestrators API Routes
33
* GET /api/v1/wallet/staking/orchestrators - List orchestrators
4+
*
5+
* Mirrors the Express backend: always fetches live data from the subgraph.
46
*/
57

6-
import {NextRequest, NextResponse } from 'next/server';
7-
import { prisma } from '@/lib/db';
8+
import { NextRequest, NextResponse } from 'next/server';
89
import { validateSession } from '@/lib/api/auth';
9-
import { success, errors, getAuthToken } from '@/lib/api/response';
10+
import { errors, getAuthToken } from '@/lib/api/response';
11+
import { getOrchestrators } from '@/lib/wallet/subgraph';
1012

1113
export async function GET(request: NextRequest): Promise<NextResponse> {
1214
try {
@@ -20,24 +22,9 @@ export async function GET(request: NextRequest): Promise<NextResponse> {
2022
return errors.unauthorized('Invalid or expired session');
2123
}
2224

23-
const searchParams = request.nextUrl.searchParams;
24-
const chainId = searchParams.get('chainId');
25-
const activeOnly = searchParams.get('activeOnly') !== 'false';
25+
const orchestrators = await getOrchestrators();
2626

27-
const where: {
28-
chainId?: number;
29-
isActive?: boolean;
30-
} = {};
31-
32-
if (chainId) where.chainId = parseInt(chainId, 10);
33-
if (activeOnly) where.isActive = true;
34-
35-
const orchestrators = await prisma.walletOrchestrator.findMany({
36-
where,
37-
orderBy: { totalStake: 'desc' },
38-
});
39-
40-
return success({ orchestrators });
27+
return NextResponse.json({ data: { orchestrators } });
4128
} catch (err) {
4229
console.error('Error fetching orchestrators:', err);
4330
return errors.internal('Failed to fetch orchestrators');

apps/web-next/src/lib/wallet/subgraph.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,11 @@ export async function querySubgraph<T = any>(query: string): Promise<T> {
2626
body: JSON.stringify({ query }),
2727
signal: AbortSignal.timeout(15_000),
2828
});
29-
if (!res.ok) {
30-
const body = await res.text().catch(() => '');
31-
throw new Error(`Subgraph ${res.status}: ${body.slice(0, 200)}`);
32-
}
29+
if (!res.ok) throw new Error(`Subgraph ${res.status}`);
3330
const json = await res.json();
3431
if (json.errors?.length) throw new Error(json.errors[0].message);
3532
return json.data as T;
3633
} catch (err) {
37-
console.error(`[querySubgraph] URL ${url.slice(0, 60)}... failed:`, (err as Error).message);
3834
lastErr = err as Error;
3935
}
4036
}
@@ -44,8 +40,6 @@ export async function querySubgraph<T = any>(query: string): Promise<T> {
4440
export async function getOrchestrators() {
4541
const protocol = await getProtocol();
4642
const round = protocol.currentRound;
47-
console.log(`[getOrchestrators] round=${round}, SUBGRAPH_API_KEY=${process.env.SUBGRAPH_API_KEY ? 'set' : 'MISSING'}`);
48-
4943
const data = await querySubgraph<{ transcoders: any[] }>(`{
5044
transcoders(
5145
first: 100

0 commit comments

Comments
 (0)