-
Notifications
You must be signed in to change notification settings - Fork 260
Embed calculator #931
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
Embed calculator #931
Conversation
Warning Rate limit exceeded@krofax has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 14 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. WalkthroughThe changes introduce a new fee parameter calculator feature within a blockchain application. This includes the creation of various React components for user input, such as Changes
Possibly related PRs
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 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
Documentation and Community
|
✅ Deploy Preview for docs-optimism 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: 39
🧹 Outside diff range and nitpick comments (9)
pages/builders/tools/fee-calculator.mdx (1)
9-11
: LGTM with suggestion: Consider adding a brief introduction.The content is correctly formatted:
- The header "Fee Parameter Calculator" uses proper title case and matches the frontmatter title.
- The
ChainParametersForm
component is correctly included.However, to improve user understanding, consider adding a brief introduction or description of the Fee Parameter Calculator between the header and the component. This would provide context for users and explain the purpose of the calculator.
Example:
# Fee Parameter Calculator +The Fee Parameter Calculator helps you determine the optimal fee parameters for your Fjord network. Input your chain's specifications to calculate the recommended fee structure. + <ChainParametersForm />components/calculator/Inputs/CheckboxInput.tsx (1)
1-31
: Add unit tests for the CheckboxInput componentWhile the component implementation looks good overall, it's important to ensure its functionality through unit tests. Consider adding tests that cover:
- Rendering of the component with different prop combinations (with/without label, description, etc.).
- Proper functioning of the checkbox toggle.
- Correct application of custom className.
- Memoization effectiveness.
Would you like me to provide a basic structure for these unit tests or open a GitHub issue to track this task?
utils/transaction-types.ts (1)
1-50
: Consider revising naming conventions for consistencyWhile the main
transactionTypes
object follows camelCase convention, there are some inconsistencies in naming:
- Transaction type names are strings with spaces, which might make property access less convenient.
- Metric names use PascalCase, which is atypical for JavaScript/TypeScript object properties.
Consider the following suggestions:
- Use camelCase for metric names (e.g.,
transactionsPerDay
instead ofTransactionsPerDay
).- If possible, use camelCase identifiers for transaction types to allow easier property access (e.g.,
generalOpMainnet
instead of"General OP Mainnet"
).Example of suggested changes:
export const transactionTypes = { generalOpMainnet: { transactionsPerDay: 489109, avgCalldataBytesPerTx: 1007.8, // ... other properties }, // ... other transaction types };components/calculator/Inputs/SelectInput.tsx (1)
13-14
: Good use of memoization, consider simplifying component definitionThe use of
React.memo
is a good practice for optimizing performance, especially if this component might re-render frequently with the same props.Consider simplifying the component definition by removing
React.FC
:export const SelectInput = React.memo( ({ className, labelClass, description, otherProps, label, data, onSelect }: Props) => { // ... component body } );This change doesn't affect functionality but aligns with modern TypeScript practices in React.
components/calculator/Loader.tsx (2)
5-6
: Consider adding CSS for the loader container.The SVG structure looks good, but the
loader-container
div might benefit from some CSS styling to control the size and positioning of the loader. This would ensure consistent appearance across different contexts where the loader is used.Consider adding a CSS module or styled-component for the loader container, for example:
.loader-container { display: flex; justify-content: center; align-items: center; width: 100%; height: 100%; }
1-66
: Consider adding basic tests for the Loader component.The Loader component looks good and fulfills its purpose. However, to ensure its reliability and prevent regressions, consider adding some basic tests. While testing visual components can be challenging, even simple render tests can be valuable.
Here are some test ideas:
- Test that the component renders without crashing.
- Snapshot test to catch unexpected changes in the rendered output.
- Test for the presence of key elements (e.g., SVG, circles).
Would you like me to generate some example test code or create a GitHub issue to track this task?
pages/builders/tools/overview.mdx (1)
Line range hint
11-13
: Enhance the welcome message for consistency and emphasis.The welcome message can be improved to better align with the coding guidelines:
Consider updating the welcome message as follows:
-Welcome to the Optimism developer tools! - -If you are already familiar with [building on OP Mainnet](/chain/getting-started) and just need the tools to get cracking, you are in the right place! +Welcome to the Optimism Developer Tools! + +For developers familiar with [building on OP Mainnet](/chain/getting-started) who need tools to start development, this is the right place.This change:
- Uses proper title case for "Developer Tools"
- Removes the informal phrase "to get cracking"
- Rephrases the sentence to use a more formal tone and avoid personal pronouns
components/calculator/ChainParametersForm.tsx (2)
48-48
: Specify explicit type for event parameter in 'handleSubmit'Using
any
for the event parameter reduces type safety. It's better to specify the event type explicitly.Apply this diff to update the event type:
-const handleSubmit = async (e: any) => { +const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {Ensure you import
FormEvent
from React:import type { ReactElement } from "react"; +import type { FormEvent } from "react";
30-31
: Unused state variable 'maxBlobsPerL1Transaction'The state variable
maxBlobsPerL1Transaction
is declared but not used within the component. This might be unintended.Consider removing it if it's unnecessary or utilizing it in your calculations if it was intended to be part of the logic.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (2)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
public/img/icons/caret-down.svg
is excluded by!**/*.svg
📒 Files selected for processing (16)
- components/calculator/ChainParametersForm.tsx (1 hunks)
- components/calculator/Inputs/CheckboxInput.tsx (1 hunks)
- components/calculator/Inputs/SelectInput.tsx (1 hunks)
- components/calculator/Inputs/TextInput.tsx (1 hunks)
- components/calculator/Inputs/index.ts (1 hunks)
- components/calculator/Loader.tsx (1 hunks)
- components/calculator/ResultsTable.tsx (1 hunks)
- package.json (0 hunks)
- pages/builders/tools/_meta.json (1 hunks)
- pages/builders/tools/fee-calculator.mdx (1 hunks)
- pages/builders/tools/overview.mdx (1 hunks)
- pages/index.mdx (2 hunks)
- styles/calculator.css (1 hunks)
- styles/global.css (1 hunks)
- utils/calculator-helpers.ts (1 hunks)
- utils/transaction-types.ts (1 hunks)
💤 Files not reviewed due to no reviewable changes (1)
- package.json
🧰 Additional context used
📓 Path-based instructions (3)
pages/builders/tools/fee-calculator.mdx (1)
Pattern
**/*.mdx
: "ALWAYS review Markdown content THOROUGHLY with the following criteria:
- Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
- Avoid gender-specific language and use the imperative form.
- Monitor capitalization for emphasis. Use bold for prominence instead of all caps or italics.
- Ensure proper nouns are capitalized in sentences.
- Apply the Oxford comma.
- Use proper title case for headers, buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
- Use correct spelling and grammar at all times (IMPORTANT).
"pages/builders/tools/overview.mdx (1)
Pattern
**/*.mdx
: "ALWAYS review Markdown content THOROUGHLY with the following criteria:
- Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
- Avoid gender-specific language and use the imperative form.
- Monitor capitalization for emphasis. Use bold for prominence instead of all caps or italics.
- Ensure proper nouns are capitalized in sentences.
- Apply the Oxford comma.
- Use proper title case for headers, buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
- Use correct spelling and grammar at all times (IMPORTANT).
"pages/index.mdx (1)
Pattern
**/*.mdx
: "ALWAYS review Markdown content THOROUGHLY with the following criteria:
- Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
- Avoid gender-specific language and use the imperative form.
- Monitor capitalization for emphasis. Use bold for prominence instead of all caps or italics.
- Ensure proper nouns are capitalized in sentences.
- Apply the Oxford comma.
- Use proper title case for headers, buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
- Use correct spelling and grammar at all times (IMPORTANT).
"
🪛 Biome
components/calculator/ChainParametersForm.tsx
[error] 177-177: Unnecessary use of boolean literals in conditional expression.
Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with(lint/complexity/noUselessTernary)
components/calculator/ResultsTable.tsx
[error] 67-67: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
[error] 69-69: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
[error] 70-70: The assignment should not be in an expression.
The use of assignments in expressions is confusing.
Expressions are often considered as side-effect free.(lint/suspicious/noAssignInExpressions)
🔇 Additional comments (16)
components/calculator/Inputs/index.ts (2)
1-5
: LGTM: Barrel file pattern implementationThe use of a barrel file pattern is a good practice for organizing and exporting related components. It simplifies imports in other parts of the application by providing a single entry point for multiple related components.
1-1
: Confirm the necessity of the "use client" directiveThe "use client" directive indicates that this component will be rendered on the client side. Ensure that this is the intended behavior for all the exported components.
Please verify if all the imported components (TextInput, SelectInput, and CheckboxInput) are also client components. If not, consider moving the "use client" directive to the specific components that require client-side rendering.
pages/builders/tools/_meta.json (1)
6-7
: LGTM! The addition of the Fee Calculator entry is consistent and appropriate.The new entry "fee-calculator": "Fee Calculator" has been added correctly to the _meta.json file. It follows the existing naming conventions and structure, which is good for maintaining consistency.
To ensure this change is fully implemented, please verify that:
- The corresponding documentation page for the Fee Calculator exists.
- The navigation UI has been updated to include this new tool.
You can use the following script to check for the existence of the documentation file:
If the file doesn't exist, consider creating it to complete the documentation for this new tool.
pages/builders/tools/fee-calculator.mdx (2)
1-4
: LGTM: Frontmatter is correctly formatted.The frontmatter follows the coding guidelines:
- The title "Fee Parameter Calculator" uses proper title case.
- The language is correctly specified as "en-US".
6-6
: LGTM: Import statement is correct.The import statement for the
ChainParametersForm
component is properly formatted and uses a relative path.components/calculator/Inputs/CheckboxInput.tsx (1)
31-31
: Good practice: Setting display nameSetting the display name explicitly for the memoized component is a good practice. It enhances debugging experience and improves the component's representation in React DevTools.
components/calculator/Inputs/TextInput.tsx (1)
1-1
: LGTM: Imports are correct and minimal.The import statement is appropriate for creating a React functional component.
utils/transaction-types.ts (2)
1-50
: LGTM: Well-structured constant object for transaction typesThe overall structure of the
transactionTypes
object is well-organized and consistent. Exporting it as a constant ensures immutability, which is a good practice for this type of data.
42-49
: Verify data accuracy for "Metal" transaction typeThe "Metal" transaction type has some unusual values that require verification:
AvgBlobgasPerL2Tx
is extremely high (947549.16) compared to other transaction types.- Both
EstimatedSizeBlobgasRatio
andEstimatedSizeCalldataGasRatio
are 0.0.These values significantly deviate from the patterns observed in other transaction types. Please confirm if these numbers are accurate or if they represent a special case.
To help verify this data, you can run the following script to check for any additional context or comments about the "Metal" transaction type in the codebase:
components/calculator/Inputs/SelectInput.tsx (1)
51-51
: Good use of display nameSetting the display name to "SelectInput" is a good practice. It helps with debugging and makes the component easier to identify in React DevTools.
styles/global.css (1)
5-5
: Approve import with suggestions for improvementThe addition of the
calculator.css
import aligns with the PR objective of introducing the Fjord Fee Parameter Calculator component. However, consider the following points:
- Ensure that the styles in
calculator.css
use specific selectors to avoid potential conflicts with existing global styles.- Consider moving component-specific styles to a dedicated directory (e.g.,
styles/components/
) for better organization.- Verify that the relative path
'calculator.css'
is correct and the file exists in the same directory asglobal.css
.To verify the existence and location of the
calculator.css
file, run the following script:✅ Verification successful
Approve import with confirmation of selector specificity
The
calculator.css
file is correctly imported instyles/global.css
and the selectors withincalculator.css
are sufficiently specific, reducing the risk of conflicts with existing global styles.For better organization and maintainability, consider moving component-specific styles to a dedicated directory (e.g.,
styles/components/
).🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the existence and location of calculator.css # Test 1: Check if calculator.css exists in the same directory as global.css if fd -p "styles/calculator.css"; then echo "calculator.css found in the styles directory" else echo "calculator.css not found in the styles directory" # Test 2: Search for calculator.css in the entire project if fd "calculator.css"; then echo "calculator.css found in a different location" else echo "calculator.css not found in the project" fi fiLength of output: 150
Script:
#!/bin/bash # Description: Extract and list all CSS selectors from calculator.css to assess their specificity # Extract selectors from calculator.css rg '^[\s]*([.#]?[a-zA-Z0-9_-]+)' styles/calculator.css | sed 's/{.*//' | sort | uniqLength of output: 2788
Script:
#!/bin/bash # Description: Accurately extract and list all CSS selectors from calculator.css to assess their specificity # Extract selectors from calculator.css by identifying lines ending with '{' rg '^[\s]*([.#]?[a-zA-Z0-9_-]+[,\s]*)+\{' styles/calculator.css | sed 's/{.*//' | tr ',' '\n' | sed 's/^\s*//;s/\s*$//' | sort | uniqLength of output: 765
components/calculator/Loader.tsx (2)
1-3
: LGTM: Component declaration and import look good.The import statement and component declaration follow React and TypeScript best practices. The component is correctly exported for use in other parts of the application.
66-66
: LGTM: Display name is correctly set.Setting the display name to "Loader" is good practice. It aids in debugging, especially when using minification in production builds.
pages/builders/tools/overview.mdx (1)
60-62
: Verify the href path and consider refining the card title.The addition of the Fee Parameter Calculator card is consistent with the existing structure. However, there are two points to consider:
The href path "/builders/app-developers/tools/ecosystem-overview" differs from other tool links in this section, which are mostly external URLs. Please verify if this is the correct path or if it should be an external link like the other tools.
To maintain consistency with other card titles, consider capitalizing "Parameter" in the title.
To confirm the existence and correctness of the linked page, run the following command:
Consider updating the card title for consistency:
- <Card title="Fee Parameter Calculator" href="/builders/app-developers/tools/ecosystem-overview" icon={<img src="/img/icons/shapes.svg" />} /> + <Card title="Fee Parameter Calculator" href="/builders/app-developers/tools/ecosystem-overview" icon={<img src="/img/icons/shapes.svg" />} />✅ Verification successful
The href path "/builders/app-developers/tools/ecosystem-overview" is valid and points to an existing page.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Check if the linked page exists fd -e mdx -e md ecosystem-overviewLength of output: 95
pages/index.mdx (2)
28-28
: Improved readability with additional spacing.The added blank line after the "Developer Tools" card enhances the visual separation between different card sections, improving overall readability.
Line range hint
1-45
: Overall, the changes enhance the document without disrupting its structure.The addition of the Fee Parameter Calculator card and the improved spacing contribute positively to the document's content and readability. The changes align with the existing style and maintain consistency in language use and formatting.
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: 2
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (3)
- package.json (1 hunks)
- pages/builders/tools/fee-calculator.mdx (1 hunks)
- pages/index.mdx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- package.json
- pages/index.mdx
🧰 Additional context used
📓 Path-based instructions (1)
pages/builders/tools/fee-calculator.mdx (1)
Pattern
**/*.mdx
: "ALWAYS review Markdown content THOROUGHLY with the following criteria:
- Use proper nouns in place of personal pronouns like 'We' and 'Our' to maintain consistency in communal documentation.
- Avoid gender-specific language and use the imperative form.
- Monitor capitalization for emphasis. Use bold for prominence instead of all caps or italics.
- Ensure proper nouns are capitalized in sentences.
- Apply the Oxford comma.
- Use proper title case for headers, buttons, tab names, page names, and links. Sentence case should be used for body content and short phrases, even in links.
- Use correct spelling and grammar at all times (IMPORTANT).
"
🪛 GitHub Check: lint
pages/builders/tools/fee-calculator.mdx
[warning] 1-1:
Must have required property 'description' • /home/runner/work/docs/docs/utils/schemas/page.schema.yaml • #/required
🔇 Additional comments (1)
pages/builders/tools/fee-calculator.mdx (1)
6-6
: LGTM: Import statement is correct.The import statement for the
ChainParametersForm
component is properly formatted and follows React component naming conventions.
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: 5
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (1)
- utils/calculator-helpers.ts (1 hunks)
🧰 Additional context used
🪛 Biome
utils/calculator-helpers.ts
[error] 113-113: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.(lint/suspicious/noGlobalIsNan)
[error] 531-531: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.
See the MDN documentation for more details.
Unsafe fix: Use Number.isNaN instead.(lint/suspicious/noGlobalIsNan)
🔇 Additional comments (3)
utils/calculator-helpers.ts (3)
543-549
: Add error handling ingetBlobBaseFee
for network and parsing errorsThe
getBlobBaseFee
function lacks error handling for network failures or invalid responses, which could result in unhandled exceptions.
132-136
: Handle potential undefined values ingetAvgEstimatedSizePerTx
Accessing
transactionTypes[comparableTxnType]
without validation may result in runtime errors if an invalidcomparableTxnType
is passed.
1001-1016
: Improve variable naming for clarity incalculateModeledDAPlusStateRevenueOnL2
Using descriptive parameter names enhances readability and maintainability. Consider renaming parameters like
e14
,e15
,e37
, ande38
to more meaningful names.
Description
Added component for Fjord Fee Parameter Calculator
Additional context
Live demo link: https://op-docs-embed-calculator.vercel.app/builders/tools/fee-calculator
Metadata