Skip to content

Commit 037d631

Browse files
committed
docs: revise hook architecture to granular query hooks with domain folders
Replace monolithic useEvents/usePortfolio hooks with granular per-query hooks organized in domain folders (hooks/events/, hooks/portfolio/). Each data hook triggers exactly one query so components only fetch what they need. Imperative hooks (trading, transactions, live-data) stay deep. Update architecture.md, hooks.md, and README.md to reflect the folder-based organization with barrel exports.
1 parent a43a3d4 commit 037d631

3 files changed

Lines changed: 216 additions & 143 deletions

File tree

app/components/UI/PredictNext/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Protocol adapters like PolymarketAdapter and the future KalshiAdapter handle ext
2020

2121
### Hooks
2222

23-
Seven hooks provide data and functionality to components. These include useEvents, usePortfolio, useTrading, useTransactions, useLiveData, usePredictNavigation, and usePredictGuard.
23+
Hooks are organized by domain in co-located folders with barrel exports. Data hooks are granular — each triggers exactly one query so components only fetch what they need. Imperative hooks (useTrading, useTransactions, useLiveData) remain deep since they manage complex stateful workflows. Domains include events, portfolio, trading, transactions, live-data, navigation, and guard.
2424

2525
### Components
2626

@@ -66,6 +66,13 @@ PredictNext/
6666
│ ├── polymarket/
6767
│ └── kalshi/ (future)
6868
├── hooks/
69+
│ ├── events/
70+
│ ├── portfolio/
71+
│ ├── trading/
72+
│ ├── transactions/
73+
│ ├── live-data/
74+
│ ├── navigation/
75+
│ └── guard/
6976
├── components/
7077
│ ├── EventCard/
7178
│ ├── OutcomeButton/

app/components/UI/PredictNext/docs/architecture.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,23 @@ See [services.md](./services.md) for detail.
209209

210210
Hooks provide React-friendly access to the service layer while preserving service ownership of business complexity.
211211

212-
Target hooks:
212+
Hooks are organized by domain in co-located folders with barrel exports:
213213

214-
- `useEvents`
215-
- `usePortfolio`
216-
- `useTrading`
217-
- `useTransactions`
218-
- `useLiveData`
219-
- `usePredictNavigation`
220-
- `usePredictGuard`
214+
- `hooks/events/``useFeaturedEvents`, `useEventList`, `useEventSearch`, `useEventDetail`, `usePriceHistory`, `usePrices`
215+
- `hooks/portfolio/``usePositions`, `useBalance`, `useActivity`, `usePnL`
216+
- `hooks/trading/``useTrading`
217+
- `hooks/transactions/``useTransactions`
218+
- `hooks/live-data/``useLiveData`
219+
- `hooks/navigation/``usePredictNavigation`
220+
- `hooks/guard/``usePredictGuard`
221221

222-
#### Thin query hooks
222+
#### Granular query hooks
223223

224-
`useEvents` and `usePortfolio` should be thin wrappers around `useQuery` from `@metamask/react-data-query`. They provide query keys and parameters; the actual read logic lives in BaseDataService-backed services via messenger.
224+
Event and portfolio hooks are granular — each hook triggers exactly one `useQuery` or `useInfiniteQuery` call from `@metamask/react-data-query`. This means a component that only needs the balance does not trigger position, activity, or P&L queries. The actual read logic lives in BaseDataService-backed services via messenger.
225225

226226
#### Deep imperative hooks
227227

228-
`useTrading`, `useTransactions`, and `useLiveData` remain somewhat deeper because they wrap imperative service operations and lifecycle concerns.
228+
`useTrading`, `useTransactions`, and `useLiveData` remain deep because they wrap imperative service operations and lifecycle concerns (order state machines, transaction orchestration, WebSocket subscriptions).
229229

230230
#### Navigation and guard hooks
231231

@@ -281,7 +281,7 @@ See [components.md](./components.md) for detail.
281281
### Reading data: events list
282282

283283
```text
284-
PredictHome → useEventsuseQuery({ queryKey: ['PredictMarketData:getEvents', params] })
284+
PredictHome → useEventList(params)useInfiniteQuery({ queryKey: ['PredictMarketData:getEvents', params] })
285285
↕ (messenger bridge)
286286
MarketDataService.getEvents() → this.fetchQuery() → PolymarketAdapter.fetchEvents() → Polymarket Gamma API
287287
```
@@ -509,15 +509,28 @@ export {
509509
TransactionsView,
510510
} from './views';
511511
export { EventCard, PositionCard, OutcomeButton } from './components';
512+
// Event query hooks
512513
export {
513-
useEvents,
514-
usePortfolio,
515-
useTrading,
516-
useTransactions,
517-
useLiveData,
518-
usePredictNavigation,
519-
usePredictGuard,
520-
} from './hooks';
514+
useFeaturedEvents,
515+
useEventList,
516+
useEventSearch,
517+
useEventDetail,
518+
usePriceHistory,
519+
usePrices,
520+
} from './hooks/events';
521+
// Portfolio query hooks
522+
export {
523+
usePositions,
524+
useBalance,
525+
useActivity,
526+
usePnL,
527+
} from './hooks/portfolio';
528+
// Imperative hooks
529+
export { useTrading } from './hooks/trading';
530+
export { useTransactions } from './hooks/transactions';
531+
export { useLiveData } from './hooks/live-data';
532+
export { usePredictNavigation } from './hooks/navigation';
533+
export { usePredictGuard } from './hooks/guard';
521534
export {
522535
selectPredictActiveOrder,
523536
selectPredictSelectedPaymentToken,

0 commit comments

Comments
 (0)