-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: improve constructor args, add optimizer config #1193
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
6 Skipped Deployments
|
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces enhancements to the EVM contract verification page, focusing on adding optimizer configuration, improving constructor argument handling, and integrating Zod type validation. The changes span multiple components, including the addition of a new Changes
Sequence DiagramsequenceDiagram
participant User
participant VerifyPage
participant ConstructorArgs
participant OptimizerConfig
participant FormValidation
User->>VerifyPage: Select Language/Option
VerifyPage->>FormValidation: Initialize Form
FormValidation-->>VerifyPage: Set Initial Values
VerifyPage->>ConstructorArgs: Render Constructor Args
VerifyPage->>OptimizerConfig: Render Optimizer Config
User->>ConstructorArgs: Toggle/Input Args
User->>OptimizerConfig: Configure Optimization
FormValidation->>FormValidation: Validate Inputs
Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
Finishing Touches
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
CodeRabbit Configuration File (
|
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
🧹 Nitpick comments (10)
src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx (2)
34-41
: Enhance accessibility with ARIA labels.Add aria-label to improve screen reader support.
<Checkbox isChecked={enabled} onChange={(e) => field.onChange({ ...field.value, enabled: e.target.checked }) } + aria-label="Toggle optimization" > <Text>Optimization Enabled</Text> </Checkbox>
29-31
: Add tooltip explaining optimization impact.The description could be more informative about the impact of optimization on contract deployment.
<Text variant="body2" color="text.dark"> - Provide optimization settings for the contract + Configure compiler optimization to reduce gas costs. Higher optimization runs may increase compilation time. </Text>src/lib/pages/evm-contract-verify/components/helper.ts (3)
12-15
: Extract magic number to a named constant.The optimizer runs default value of 200 should be defined as a named constant for better maintainability.
+const DEFAULT_OPTIMIZER_RUNS = 200; + const optimizerConfig = { enabled: false, - runs: 200, + runs: DEFAULT_OPTIMIZER_RUNS, };
17-60
: Reduce code duplication in switch statements.The switch cases contain repeated code structures. Consider extracting common configurations.
+const getBaseConfig = (verificationOption: VerificationOptions) => ({ + option: verificationOption, + constructorArgs, +}); + +const getSolidityConfig = (verificationOption: VerificationOptions) => { + const baseConfig = getBaseConfig(verificationOption); + + switch (verificationOption) { + case VerificationOptions.UploadFiles: + return { + ...baseConfig, + optimizerConfig, + evmVersion: undefined, + }; + case VerificationOptions.ContractCode: + return { + ...baseConfig, + optimizerConfig, + }; + case VerificationOptions.JsonInput: + return baseConfig; + default: + throw new Error("Invalid verification option for Solidity"); + } +};
3-6
: Improve type safety with literal types.Consider using literal types for better type safety and IDE support.
-export const getVerifyFormInitialValue = ( - language: EvmProgrammingLanguage, - verificationOption: VerificationOptions -) => { +export const getVerifyFormInitialValue = < + L extends EvmProgrammingLanguage, + V extends VerificationOptions +>(language: L, verificationOption: V) => {src/lib/pages/evm-contract-verify/types.ts (1)
19-22
: Consider adding upper bound validation for optimizer runs.The
runs
field should have an upper bound to prevent unreasonable values that could cause optimization to fail or take too long.const zOptimizerConfig = z.object({ enabled: z.boolean(), - runs: z.number().nonnegative(), + runs: z.number().nonnegative().max(999999, "Maximum optimizer runs exceeded"), });src/lib/pages/evm-contract-verify/components/ConstructorArgs.tsx (1)
52-62
: Consider formatting the placeholder hex string for better readability.The current placeholder is a long hex string without any visual breaks. Consider adding '0x' prefix and breaking it into segments for better readability.
- placeholder="ex.000000000000000000000000c005dc82818d67af737725bd4bf75435d065d239" + placeholder="ex. 0x000000000000_0000000000_c005dc82818d67af_737725bd4bf75435_d065d239"src/lib/pages/evm-contract-verify/components/EvmContractVerifyOptions.tsx (1)
27-29
: Consider adding type assertion for the field value.The
field.onChange
is called with the result ofgetVerifyFormInitialValue
without type checking. Consider adding type assertion or validation.const handleOptionChange = (nextVal: VerificationOptions) => { - field.onChange(getVerifyFormInitialValue(language, nextVal)); + const initialValue = getVerifyFormInitialValue(language, nextVal); + if (language === EvmProgrammingLanguage.Solidity || language === EvmProgrammingLanguage.Vyper) { + field.onChange(initialValue); + } };src/lib/components/forms/ControllerInput.tsx (1)
175-181
: Consider simplifying the conditional rendering logic.The current implementation can be made more concise by using the logical OR operator directly.
- {(status?.message || helperText) && ( - <FormHelperText className="helper-text"> - {status?.message - ? getResponseMsg(status, helperText) - : helperText} - </FormHelperText> - )} + {(status?.message || helperText) && ( + <FormHelperText className="helper-text"> + {status?.message && getResponseMsg(status, helperText) || helperText} + </FormHelperText> + )}src/lib/pages/evm-contract-verify/index.tsx (1)
207-214
: LGTM! Consider adding error handling.The refactoring to use
getVerifyFormInitialValue
improves code maintainability by centralizing the form initialization logic.Consider adding error handling for cases where
getVerifyFormInitialValue
might return undefined:setValue( "verifyForm.form", + getVerifyFormInitialValue( + selectedOption.value, + selectedOption.value === EvmProgrammingLanguage.Solidity + ? VerificationOptions.UploadFiles + : VerificationOptions.UploadFile + ) ?? { option: VerificationOptions.UploadFiles } // Provide fallback - getVerifyFormInitialValue( - selectedOption.value, - selectedOption.value === EvmProgrammingLanguage.Solidity - ? VerificationOptions.UploadFiles - : VerificationOptions.UploadFile - ) );
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
CHANGELOG.md
(1 hunks)src/lib/components/forms/ControllerInput.tsx
(1 hunks)src/lib/pages/evm-contract-verify/components/ConstructorArgs.tsx
(2 hunks)src/lib/pages/evm-contract-verify/components/EvmContractVerifyOptions.tsx
(2 hunks)src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx
(1 hunks)src/lib/pages/evm-contract-verify/components/helper.ts
(1 hunks)src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityUploadFiles.tsx
(2 hunks)src/lib/pages/evm-contract-verify/index.tsx
(2 hunks)src/lib/pages/evm-contract-verify/types.ts
(3 hunks)src/lib/styles/theme/components/input.ts
(1 hunks)
🔇 Additional comments (6)
src/lib/pages/evm-contract-verify/components/solidity/EvmContractVerifySolidityUploadFiles.tsx (2)
Line range hint
15-15
: Address the TODO comment.The TODO comment indicates incomplete implementation. Please ensure this is addressed before merging.
Would you like me to help implement the missing functionality or create a GitHub issue to track this task?
19-20
: LGTM! Clean integration of OptimizerConfiguration.The OptimizerConfiguration component is properly integrated with consistent spacing and receives the required control prop.
src/lib/styles/theme/components/input.ts (1)
25-27
: LGTM! Enhanced disabled state styling.The changes improve visual feedback for disabled inputs while maintaining accessibility:
- Opacity maintains readability
- Background color provides good contrast
- Pointer events properly prevent interaction
src/lib/pages/evm-contract-verify/types.ts (1)
39-41
: LGTM! Schema integration is consistent.The new schemas are properly integrated across all form types, maintaining consistency between Solidity and Vyper implementations.
Also applies to: 46-47, 52-52, 66-66, 71-71, 76-76
src/lib/pages/evm-contract-verify/components/ConstructorArgs.tsx (1)
11-21
: LGTM! Error handling is well implemented.The separation of concerns between enabled state and value controllers, along with proper error handling integration, makes the component more robust.
CHANGELOG.md (1)
42-42
: LGTM! Changelog entry follows the established format.The entry is properly placed under "Unreleased" section, includes the PR number, and clearly describes the changes.
src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx
Outdated
Show resolved
Hide resolved
src/lib/pages/evm-contract-verify/components/ConstructorArgs.tsx
Outdated
Show resolved
Hide resolved
src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx
Outdated
Show resolved
Hide resolved
src/lib/pages/evm-contract-verify/components/OptimizerConfiguration.tsx
Outdated
Show resolved
Hide resolved
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.
ok
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes
Style