Skip to content
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: evm contract shortcuts #1217

Merged
merged 3 commits into from
Feb 4, 2025
Merged

Conversation

songwongtp
Copy link
Collaborator

@songwongtp songwongtp commented Feb 3, 2025

Summary by CodeRabbit

  • New Features

    • Added Ethereum contract method shortcuts on the overview page for quick read/write interactions.
    • Enhanced the contract details interface with additional sections displaying verification information and interactive command options tailored for both mobile and desktop views.
  • Bug Fixes

    • Updated the changelog to reflect new feature additions.
  • Refactor

    • Streamlined the contract details experience by replacing and reorganizing components, including improved validation for optimizer settings in contract verification.

Copy link

vercel bot commented Feb 3, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
celatone-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 4, 2025 3:49am
6 Skipped Deployments
Name Status Preview Comments Updated (UTC)
celatone-frontend-main ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 3:49am
initia-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 3:49am
neutron-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 3:49am
osmosis-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 3:49am
sei-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 3:49am
terra-celatone-frontend ⬜️ Ignored (Inspect) Visit Preview Feb 4, 2025 3:49am

Copy link

coderabbitai bot commented Feb 3, 2025

Walkthrough

The pull request updates the project’s EVM contract details functionality. The changelog now lists a new feature for adding method shortcuts on the overview section. An old overview component has been removed, and several new React components have been added to construct a revamped contract details overview, including components for command groups, contract information, verified commands, and verified information. Additionally, the main page component has been updated to import the new overview components and accept extra verification props. A new optimizer validation schema has also been introduced in the verification types.

Changes

File(s) Change Summary
CHANGELOG.md Added new feature entry under "Unreleased" for PR #1217: "evm contract method shortcuts on the overview section".
src/lib/pages/evm-contract-details/components/EvmContractDetailsOverview.tsx Removed the old EVM contract details overview component.
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/... Added new React components: EvmContractCmdGroup, OverviewInfo, OverviewVerifiedCmds, OverviewVerifiedInfo, and a new main overview component to display detailed contract information.
src/lib/pages/evm-contract-details/index.tsx Updated import to the new overview component path and added evmVerifyInfo and proxyTargetEvmVerifyInfo props.
src/lib/services/types/verification/evm.ts Introduced zEvmOptimizer schema and updated the transformation function to parse optimizer configuration using the new schema.
src/lib/components/evm-verify-section/VerifiedDetails.tsx Modified text capitalization and added font weight to the Text component.
src/lib/components/ContractCmdButton.tsx Updated cmd property type from string to Option<string> in ContractCmdButtonProps interface.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant O as EvmContractDetailsOverview
    participant VI as OverviewInfo
    participant VV as OverviewVerifiedInfo
    participant VC as OverviewVerifiedCmds
    participant CG as EvmContractCmdGroup

    U->>O: Request contract details
    O->>VI: Render basic contract information
    O->>VV: Render verification details (if available)
    O->>VC: Render verified command shortcuts
    VC->>CG: Display command group for interactions
    CG-->>U: Navigate based on command selection
Loading

Suggested reviewers

  • evilpeach
  • Poafs1

Poem

I'm a rabbit in the code garden, swift and bright,
Hopping over changes under the moonlight.
Old components vanish, new ones bloom with cheer,
Command groups and info, perfectly clear.
With every line of code, I wiggle my nose,
Celebrating progress as the magic grows!
🥕🐇 Happy coding in our digital burrow!


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (5)
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedInfo.tsx (1)

14-17: Add aria-label to the section for better accessibility.

The heading looks good, but adding an aria-label to the VStack would improve accessibility.

-  <VStack spacing={4} alignItems="flex-start">
+  <VStack spacing={4} alignItems="flex-start" aria-label="Contract Verification Information">
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/index.tsx (1)

20-34: Consider grouping related props for better maintainability.

The props interface is well-defined but could be organized better by grouping related props into sub-interfaces.

+interface ContractIdentifiers {
+  contractAddressBech: BechAddr20;
+  contractAddressHex: HexAddr20;
+  hash: Option<string>;
+  evmHash: Nullish<string>;
+}

+interface ContractMetadata {
+  sender: Option<BechAddr>;
+  created: Option<Date>;
+  isContractInfoLoading: boolean;
+}

+interface VerificationInfo {
+  evmVerifyInfo: Option<EvmVerifyInfo>;
+  proxyTargetEvmVerifyInfo: Option<EvmVerifyInfo>;
+}

 interface EvmContractDetailsOverviewProps {
-  contractAddressBech: BechAddr20;
-  contractAddressHex: HexAddr20;
-  hash: Option<string>;
-  evmHash: Nullish<string>;
-  sender: Option<BechAddr>;
-  created: Option<Date>;
-  isContractInfoLoading: boolean;
+  ...ContractIdentifiers;
+  ...ContractMetadata;
   onViewMoreAssets: () => void;
   onViewMoreTxs: () => void;
   tab: TxsTabIndex;
   setTab: (tab: TxsTabIndex) => void;
-  evmVerifyInfo: Option<EvmVerifyInfo>;
-  proxyTargetEvmVerifyInfo: Option<EvmVerifyInfo>;
+  ...VerificationInfo;
 }
src/lib/services/types/verification/evm.ts (1)

50-53: Consider adding constraints to the optimizer runs.

The optimizer runs should typically be a positive number. Consider adding validation.

 const zEvmOptimizer = z.object({
   enabled: z.boolean(),
-  runs: z.number(),
+  runs: z.number().positive(),
 });
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedCmds.tsx (1)

56-87: Consider adding loading state for proxy target info.

The proxy target section could benefit from a loading indicator while proxyTargetEvmVerifyInfo is being fetched.

-      {proxyTargetEvmVerifyInfo && (
+      {(proxyTargetEvmVerifyInfo || isProxyTargetLoading) && (
         <VStack spacing={4} alignItems="flex-start">
           <Heading as="h6" variant="h6">
             Proxy target contract
           </Heading>
+          {isProxyTargetLoading ? (
+            <Spinner size="sm" />
+          ) : (
           <HStack spacing={2} alignItems="center">
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewInfo.tsx (1)

28-39: Consider adding aria-label for better accessibility.

The Grid component could benefit from an aria-label to improve screen reader experience.

     <Grid
+      aria-label="Contract Overview Information"
       gridTemplateColumns={{
         base: "1fr",
         md: "minmax(0, 160px) repeat(3, minmax(0, 240px))",
       }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9a71b67 and 881e0e0.

📒 Files selected for processing (9)
  • CHANGELOG.md (1 hunks)
  • src/lib/pages/evm-contract-details/components/EvmContractDetailsOverview.tsx (0 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewInfo.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedCmds.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedInfo.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/index.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/index.tsx (2 hunks)
  • src/lib/services/types/verification/evm.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • src/lib/pages/evm-contract-details/components/EvmContractDetailsOverview.tsx
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🧰 Additional context used
🪛 Biome (1.9.4)
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx

[error] 17-17: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (6)
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedInfo.tsx (1)

18-41: LGTM! Well-structured grid layout.

The responsive grid layout and information display are well implemented. Good use of proper spacing and alignment.

src/lib/pages/evm-contract-details/components/evm-contract-details-overview/index.tsx (1)

51-83: LGTM! Well-structured component composition.

The component layout and conditional rendering are well implemented. Good use of the Stack component for spacing.

src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx (1)

54-81: LGTM! Well-implemented button group.

The button group implementation with proper styling and event handling is clean and maintainable.

src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewVerifiedCmds.tsx (1)

41-54: LGTM! Well-structured command group layout.

The responsive layout with conditional rendering based on mobile state is well implemented. The command groups are logically separated between read and write operations.

src/lib/pages/evm-contract-details/components/evm-contract-details-overview/OverviewInfo.tsx (1)

64-98: LGTM! Well-handled transaction hash display.

Good implementation of transaction hash display with proper fallbacks and copy functionality.

src/lib/pages/evm-contract-details/index.tsx (1)

163-177: LGTM! Props properly passed to EvmContractDetailsOverview.

The verification info props are correctly passed to the overview component, with proper loading state handling in the parent component.

Copy link

@coderabbitai coderabbitai bot left a 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 (2)
src/lib/components/ContractCmdButton.tsx (1)

2-2: LGTM! Consider improving the fallback text.

The type change to Option<string> improves type safety. However, displaying "undefined" as fallback text might not be user-friendly.

Consider using a more descriptive fallback text:

-    {cmd || "undefined"}
+    {cmd || "No command available"}

Also applies to: 4-7

src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx (1)

54-81: Consider the following improvements to the ButtonGroup implementation.

  1. Add a comparison function to sort() for consistent ordering across browsers.
  2. Move inline styles to a theme or styled component.
  3. Define the navigation path as a constant.
+const INTERACT_PATH = "/evm-contracts/[contractAddress]/[tab]";
+
+const compareAbiSections = (a: JsonFragment, b: JsonFragment) => 
+  (a.name ?? "").localeCompare(b.name ?? "");
+
 <ButtonGroup
   flexWrap="wrap"
-  sx={{
-    "> button": {
-      marginInlineStart: "0 !important",
-      marginInlineEnd: "1",
-    },
-  }}
+  className="evm-contract-cmd-group"
   gap={2}
 >
-  {abiSections.sort().map(({ name }, index) => (
+  {abiSections.sort(compareAbiSections).map(({ name }, index) => (
     <ContractCmdButton
       key={`${interactTab}-cmd-${name}-${index}`}
       cmd={name}
       onClickCmd={() => {
         navigate({
-          pathname: "/evm-contracts/[contractAddress]/[tab]",
+          pathname: INTERACT_PATH,
           query: {
             contractAddress,

Add to your theme or styled components:

const theme = {
  components: {
    ButtonGroup: {
      variants: {
        'evm-contract-cmd-group': {
          '> button': {
            marginInlineStart: '0 !important',
            marginInlineEnd: '1',
          },
        },
      },
    },
  },
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3ba427 and 0cd69c5.

📒 Files selected for processing (2)
  • src/lib/components/ContractCmdButton.tsx (1 hunks)
  • src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx

[error] 17-17: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
src/lib/pages/evm-contract-details/components/evm-contract-details-overview/EvmContractCmdGroup.tsx (2)

9-21: Remove redundant case clause in switch statement.

The case for InteractTabsIndex.WriteProxy is redundant since it falls through to the default case.

 const getGroupTitle = (interactTab: InteractTabsIndex) => {
   switch (interactTab) {
     case InteractTabsIndex.Read:
       return "Read";
     case InteractTabsIndex.Write:
       return "Write";
     case InteractTabsIndex.ReadProxy:
       return "Read as Proxy";
-    case InteractTabsIndex.WriteProxy:
     default:
       return "Write as Proxy";
   }
 };
🧰 Tools
🪛 Biome (1.9.4)

[error] 17-17: Useless case clause.

because the default clause is present:

Unsafe fix: Remove the useless case.

(lint/complexity/noUselessSwitchCase)


23-27: LGTM! Props interface is well-defined.

The interface uses appropriate types that ensure type safety and match the ethers.js library types.

@songwongtp songwongtp merged commit 674624d into develop Feb 4, 2025
13 checks passed
@songwongtp songwongtp deleted the feat/overview-cmd-shortcuts branch February 4, 2025 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants