-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(web): courts-stat #1826
Conversation
WalkthroughThe pull request introduces a comprehensive refactoring of the court statistics display functionality in the web application. The changes involve removing the existing Changes
Possibly related PRs
Suggested Labels
Suggested Reviewers
Poem
Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
✅ Deploy Preview for kleros-v2-testnet ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-testnet-devtools ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
✅ Deploy Preview for kleros-v2-university ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (2)
web/src/pages/Courts/CourtDetails/Stats/index.tsx (1)
66-74
: Improve type safety in StyledAccordionThe component is using a default expanded index without type checking.
Consider using a type-safe approach:
- defaultExpanded={0} + defaultExpanded={0 as const}web/src/pages/Courts/CourtDetails/Stats/StatsContent.tsx (1)
65-76
: Reduce code duplication in stat renderingThe same mapping logic is repeated three times with different slices of the stats array.
Extract the mapping logic into a reusable component:
interface StatSectionProps { stats: typeof stats; startIndex: number; endIndex: number; court: CourtDetailsQuery["court"]; pricesData: PricesData; coinIds: string[]; } const StatSection: React.FC<StatSectionProps> = ({ stats, startIndex, endIndex, court, pricesData, coinIds }) => ( <StyledCard> {stats.slice(startIndex, endIndex).map(({ title, coinId, getText, getSubtext, color, icon }) => { const coinPrice = !isUndefined(pricesData) ? pricesData[coinIds[coinId!]]?.price : undefined; return ( <StatDisplay key={title} {...{ title, color, icon }} text={court ? getText(court) : <StyledSkeleton />} subtext={calculateSubtextRender(court, getSubtext, coinPrice)} isSmallDisplay={true} /> ); })} </StyledCard> );Also applies to: 85-96, 105-116
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
web/src/pages/Courts/CourtDetails/Stats.tsx
(0 hunks)web/src/pages/Courts/CourtDetails/Stats/StatsContent.tsx
(1 hunks)web/src/pages/Courts/CourtDetails/Stats/index.tsx
(1 hunks)web/src/pages/Courts/CourtDetails/Stats/stats.ts
(1 hunks)web/src/pages/Courts/CourtDetails/index.tsx
(1 hunks)
💤 Files with no reviewable changes (1)
- web/src/pages/Courts/CourtDetails/Stats.tsx
✅ Files skipped from review due to trivial changes (1)
- web/src/pages/Courts/CourtDetails/index.tsx
⏰ Context from checks skipped due to timeout of 90000ms (19)
- GitHub Check: Redirect rules - kleros-v2-university
- GitHub Check: Header rules - kleros-v2-university
- GitHub Check: Pages changed - kleros-v2-university
- GitHub Check: Redirect rules - kleros-v2-testnet-devtools
- GitHub Check: Header rules - kleros-v2-testnet-devtools
- GitHub Check: Pages changed - kleros-v2-testnet-devtools
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Copy labels from linked issues
- GitHub Check: SonarCloud
- GitHub Check: dependency-review
- GitHub Check: Copy labels from linked issues
- GitHub Check: contracts-testing
- GitHub Check: Analyze (javascript)
- GitHub Check: Mend Security Check
🔇 Additional comments (2)
web/src/pages/Courts/CourtDetails/Stats/stats.ts (2)
96-96
: Handle potential negative case countThe calculation
data?.numberDisputes - data?.numberClosedDisputes
could result in a negative number if the data is inconsistent.Add a safety check:
- getText: (data) => data?.numberDisputes - data?.numberClosedDisputes, + getText: (data) => Math.max(0, (data?.numberDisputes ?? 0) - (data?.numberClosedDisputes ?? 0)),
67-68
: Add null check for feeForJurorThe code assumes
data?.feeForJuror
is always defined.Add a null check or provide a default value:
- const jurorReward = formatUnitsWei(data?.feeForJuror); + const jurorReward = formatUnitsWei(data?.feeForJuror ?? '0');
✅ Deploy Preview for kleros-v2-neo ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
web/src/hooks/useCoinPrice.tsx (3)
9-11
: Add JSDoc documentation for the Prices type.While the type definition is well-structured, adding documentation would help consumers understand the expected format of coin IDs and the meaning of the price value.
+/** + * Represents a mapping of coin IDs to their current prices + * @example + * { + * "coingecko:ethereum": { price: 2000.50 }, + * "coingecko:bitcoin": { price: 35000.00 } + * } + */ export type Prices = { [coinId: string]: { price: number }; };
16-16
: Improve query key structure to avoid collisions.The current query key might cause collisions if multiple instances of the hook are used with different coin IDs. Consider using an array-based key structure.
- queryKey: [`coinPrice${coinIds}`], + queryKey: ['coinPrice', ...coinIds],
Line range hint
16-20
: Consider enhancing error handling.The hook returns
isError
but doesn't provide error details. Consider adding error type information and returning the error message for better error handling in consuming components.- const { data: prices, isError } = useQuery<Prices>({ + const { data: prices, isError, error } = useQuery<Prices, Error>({ queryKey: [`coinPrice${coinIds}`], enabled: isEnabled, queryFn: async () => fetchCoinPrices(coinIds), }); return { prices, isError, + error: error?.message };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
web/src/hooks/useCoinPrice.tsx
(1 hunks)web/src/pages/Courts/CourtDetails/Stats/StatsContent.tsx
(1 hunks)web/src/pages/Courts/CourtDetails/Stats/stats.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- web/src/pages/Courts/CourtDetails/Stats/stats.ts
- web/src/pages/Courts/CourtDetails/Stats/StatsContent.tsx
⏰ Context from checks skipped due to timeout of 90000ms (17)
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Redirect rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Header rules - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Pages changed - kleros-v2-testnet
- GitHub Check: Redirect rules - kleros-v2-testnet-devtools
- GitHub Check: Header rules - kleros-v2-testnet-devtools
- GitHub Check: Pages changed - kleros-v2-testnet-devtools
- GitHub Check: Redirect rules - kleros-v2-university
- GitHub Check: Header rules - kleros-v2-university
- GitHub Check: Pages changed - kleros-v2-university
- GitHub Check: Copy labels from linked issues
- GitHub Check: dependency-review
- GitHub Check: contracts-testing
- GitHub Check: SonarCloud
- GitHub Check: Analyze (javascript)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Code Climate has analyzed commit 743b960 and detected 8 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
Quality Gate passedIssues Measures |
PR-Codex overview
This PR primarily focuses on enhancing the
Stats
component within theCourtDetails
page by adding new features and improving the structure of the code, particularly around the handling of coin prices and displaying statistics.Detailed summary
Stats.tsx
file.Prices
inuseCoinPrice.tsx
.useCoinPrice
to use the newPrices
type.Stats
andStatsContent
components inStats/index.tsx
andStats/StatsContent.tsx
.stats.ts
file to define statistical metrics with associated icons and formatting functions.Summary by CodeRabbit
Release Notes
New Features
StatsContent
component for displaying court-related statistics.Stats
component that conditionally renders statistics based on device type.Bug Fixes
Stats
component to streamline the statistics display.Refactor
Improvements