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: collapsable address/tx in auth signer #183

Merged
merged 1 commit into from
Jan 8, 2025
Merged

Conversation

chalabi2
Copy link
Collaborator

@chalabi2 chalabi2 commented Jan 8, 2025

This pr:

  • makes the address & tx info on the auth signer modal collapsable
  • adds json syntax highlighting to the auth signer tx info section
  • decodes the base64 value of every tx in the auth signer

Summary by CodeRabbit

  • New Features
    • Enhanced icon component with customizable size
    • Added new function for syntax highlighting JSON objects
    • Improved authentication signer modal with:
      • Dynamic message decoding
      • Expandable address and transaction info
      • Enhanced user interaction

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Walkthrough

The pull request introduces enhancements to multiple components, focusing on improving flexibility, user interaction, and data presentation. The changes include adding a size prop to the ArrowRightIcon, creating an objectSyntax function for JSON formatting, and updating the authSignerModal with more dynamic content display and message decoding capabilities. These modifications aim to provide more versatile and user-friendly component interactions across the application.

Changes

File Change Summary
components/icons/ArrowRightIcon.tsx Added ArrowRightIconProps interface with optional size prop, updated component to use dynamic icon sizing
components/messageSyntax.tsx Introduced objectSyntax function for formatting JSON with syntax highlighting
components/react/authSignerModal.tsx Added messageDecoders registry, enhanced DisplayDataToSign with expanded state, improved message decoding and formatting

Sequence Diagram

sequenceDiagram
    participant User
    participant AuthSignerModal
    participant MessageDecoder
    participant SyntaxHighlighter

    User->>AuthSignerModal: Interact with modal
    AuthSignerModal->>MessageDecoder: Decode message
    MessageDecoder-->>AuthSignerModal: Decoded message
    AuthSignerModal->>SyntaxHighlighter: Format decoded message
    SyntaxHighlighter-->>AuthSignerModal: Formatted message
    AuthSignerModal->>User: Display expandable message
Loading

Possibly related PRs

Suggested reviewers

  • fmorency

Poem

🐰 A rabbit's tale of code so bright,
Icons resized with pixel might,
JSON decoded, themes unfurled,
Modals dancing in our world,
Flexibility takes its flight! 🚀


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.

@chalabi2
Copy link
Collaborator Author

chalabi2 commented Jan 8, 2025

fixes #176

Copy link

codecov bot commented Jan 8, 2025

Codecov Report

Attention: Patch coverage is 18.54305% with 123 lines in your changes missing coverage. Please review.

Project coverage is 54.73%. Comparing base (12555f6) to head (e342d83).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
components/react/authSignerModal.tsx 18.93% 107 Missing ⚠️
components/messageSyntax.tsx 0.00% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #183      +/-   ##
==========================================
- Coverage   55.04%   54.73%   -0.31%     
==========================================
  Files         153      153              
  Lines       15515    15645     +130     
==========================================
+ Hits         8540     8564      +24     
- Misses       6975     7081     +106     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@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

🔭 Outside diff range comments (1)
components/react/authSignerModal.tsx (1)

Add test coverage for critical transaction signing components

The review comment is valid. The codebase has a robust testing infrastructure, but the authSignerModal.tsx component lacks test coverage despite containing security-critical functionality:

  • Message decoders for multiple Cosmos SDK transaction types
  • Transaction signing UI components
  • Error handling for decoding failures
  • Theme-aware display components

Given the security-sensitive nature of transaction signing and message decoding, comprehensive test coverage is essential to prevent potential vulnerabilities and ensure reliable operation.

🔗 Analysis chain

Line range hint 39-301: Add comprehensive test coverage.

The static analysis shows significant gaps in test coverage. Please add tests for:

  1. Message decoders
  2. Value formatting
  3. UI interactions
  4. Theme handling

Run this script to identify critical paths requiring test coverage:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all exported functions and components that need test coverage

# Find all exported entities
rg -l "export (const|function|class|interface)" | while read -r file; do
  echo "=== $file ==="
  rg "export (const|function|class|interface)" "$file"
done

# Find React components with props
ast-grep --pattern 'interface $name Props' 

Length of output: 29392


Script:

#!/bin/bash
# Search for test files related to authSignerModal and its components
echo "=== Searching for test files ==="
fd -e test.tsx -e test.ts -e spec.tsx -e spec.ts

echo -e "\n=== Searching for test utilities ==="
rg -l "render.*Provider|test-utils|jest.setup|vitest" 

echo -e "\n=== Checking imports of testing libraries ==="
rg -l "import.*[@]testing-library|import.*[@]jest|import.*vitest"

echo -e "\n=== Looking for message decoder tests ==="
rg -l "describe.*message.*decoder|test.*message.*decoder|it.*message.*decoder"

Length of output: 5902


Script:

#!/bin/bash
# Examine test utilities and decoder-related tests
echo "=== Examining test utilities ==="
cat tests/render.tsx

echo -e "\n=== Searching for decoder-related tests ==="
rg -l "decode|TxBody|AuthInfo|MsgSend"

echo -e "\n=== Searching for indirect tests ==="
rg -l "SignModal|DisplayDataToSign|messageDecoders"

echo -e "\n=== Looking for Cosmos SDK message type tests ==="
rg -l "cosmos.bank.v1beta1|cosmos.group.v1|cosmos.upgrade.v1beta1"

Length of output: 2962

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 41-42: components/react/authSignerModal.tsx#L41-L42
Added lines #L41 - L42 were not covered by tests


[warning] 45-46: components/react/authSignerModal.tsx#L45-L46
Added lines #L45 - L46 were not covered by tests


[warning] 49-50: components/react/authSignerModal.tsx#L49-L50
Added lines #L49 - L50 were not covered by tests


[warning] 53-54: components/react/authSignerModal.tsx#L53-L54
Added lines #L53 - L54 were not covered by tests


[warning] 57-58: components/react/authSignerModal.tsx#L57-L58
Added lines #L57 - L58 were not covered by tests


[warning] 61-62: components/react/authSignerModal.tsx#L61-L62
Added lines #L61 - L62 were not covered by tests


[warning] 65-66: components/react/authSignerModal.tsx#L65-L66
Added lines #L65 - L66 were not covered by tests


[warning] 69-70: components/react/authSignerModal.tsx#L69-L70
Added lines #L69 - L70 were not covered by tests


[warning] 73-74: components/react/authSignerModal.tsx#L73-L74
Added lines #L73 - L74 were not covered by tests


[warning] 77-78: components/react/authSignerModal.tsx#L77-L78
Added lines #L77 - L78 were not covered by tests


[warning] 81-82: components/react/authSignerModal.tsx#L81-L82
Added lines #L81 - L82 were not covered by tests


[warning] 85-86: components/react/authSignerModal.tsx#L85-L86
Added lines #L85 - L86 were not covered by tests


[warning] 89-90: components/react/authSignerModal.tsx#L89-L90
Added lines #L89 - L90 were not covered by tests


[warning] 93-94: components/react/authSignerModal.tsx#L93-L94
Added lines #L93 - L94 were not covered by tests


[warning] 105-105: components/react/authSignerModal.tsx#L105
Added line #L105 was not covered by tests


[warning] 110-110: components/react/authSignerModal.tsx#L110
Added line #L110 was not covered by tests


[warning] 112-114: components/react/authSignerModal.tsx#L112-L114
Added lines #L112 - L114 were not covered by tests


[warning] 119-151: components/react/authSignerModal.tsx#L119-L151
Added lines #L119 - L151 were not covered by tests

🧹 Nitpick comments (3)
components/messageSyntax.tsx (1)

35-53: Consider refactoring to reduce code duplication.

The prettyPrintJSON function and styling configuration are duplicated between messageSyntax and objectSyntax. Consider extracting these into shared utilities.

+const prettyPrintJSON = (obj: Record<string, any>): string => {
+  return JSON.stringify(obj, null, 2);
+};
+
+const getSyntaxHighlighterProps = (theme: string) => ({
+  language: "json",
+  style: theme === 'dark' ? oneDark : oneLight,
+  customStyle: {
+    backgroundColor: 'transparent',
+    padding: '1rem',
+    borderRadius: '0.5rem',
+  }
+});
+
 export function messageSyntax(fieldsToShow: string[], message: MessageType, theme: string) {
-  const prettyPrintJSON = (obj: Record<string, any>): string => {
-    return JSON.stringify(obj, null, 2);
-  };
-
   return (
     <SyntaxHighlighter
-      language="json"
-      style={theme === 'dark' ? oneDark : oneLight}
-      customStyle={{
-        backgroundColor: 'transparent',
-        padding: '1rem',
-        borderRadius: '0.5rem',
-      }}
+      {...getSyntaxHighlighterProps(theme)}
     >
       {prettyPrintJSON(
         fieldsToShow.reduce((acc: Record<string, any>, field: string) => {
           acc[field] = message[field];
           return acc;
         }, {})
       )}
     </SyntaxHighlighter>
   );
 }

 export function objectSyntax(object: Record<string, any>, theme: string) {
-  const prettyPrintJSON = (obj: Record<string, any>): string => {
-    return JSON.stringify(obj, null, 2);
-  };
-
   return (
     <SyntaxHighlighter
-      language="json"
-      style={theme === 'dark' ? oneDark : oneLight}
-      customStyle={{
-        backgroundColor: 'transparent',
-        padding: '1rem',
-        borderRadius: '0.5rem',
-      }}
+      {...getSyntaxHighlighterProps(theme)}
     >
       {prettyPrintJSON(object)}
     </SyntaxHighlighter>
   );
 }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 35-50: components/messageSyntax.tsx#L35-L50
Added lines #L35 - L50 were not covered by tests

components/react/authSignerModal.tsx (2)

39-97: Consider implementing a more maintainable message decoder registry.

The current implementation of messageDecoders has repetitive code patterns. Consider using a factory pattern or a more declarative approach.

+type MessageDecoder<T> = {
+  type: string;
+  decoder: typeof T;
+};
+
+const createMessageDecoder = <T>({ type, decoder }: MessageDecoder<T>) => ({
+  [type]: (value: Uint8Array) => {
+    const decoded = decoder.decode(value);
+    return { ...decoded };
+  }
+});
+
+const messageDecoders = {
+  ...createMessageDecoder({ type: '/cosmos.bank.v1beta1.MsgSend', decoder: MsgSend }),
+  ...createMessageDecoder({ type: '/cosmos.group.v1.MsgCreateGroupWithPolicy', decoder: MsgCreateGroupWithPolicy }),
+  // ... other decoders
+};
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 41-42: components/react/authSignerModal.tsx#L41-L42
Added lines #L41 - L42 were not covered by tests


[warning] 45-46: components/react/authSignerModal.tsx#L45-L46
Added lines #L45 - L46 were not covered by tests


[warning] 49-50: components/react/authSignerModal.tsx#L49-L50
Added lines #L49 - L50 were not covered by tests


[warning] 53-54: components/react/authSignerModal.tsx#L53-L54
Added lines #L53 - L54 were not covered by tests


[warning] 57-58: components/react/authSignerModal.tsx#L57-L58
Added lines #L57 - L58 were not covered by tests


[warning] 61-62: components/react/authSignerModal.tsx#L61-L62
Added lines #L61 - L62 were not covered by tests


[warning] 65-66: components/react/authSignerModal.tsx#L65-L66
Added lines #L65 - L66 were not covered by tests


[warning] 69-70: components/react/authSignerModal.tsx#L69-L70
Added lines #L69 - L70 were not covered by tests


[warning] 73-74: components/react/authSignerModal.tsx#L73-L74
Added lines #L73 - L74 were not covered by tests


[warning] 77-78: components/react/authSignerModal.tsx#L77-L78
Added lines #L77 - L78 were not covered by tests


[warning] 81-82: components/react/authSignerModal.tsx#L81-L82
Added lines #L81 - L82 were not covered by tests


[warning] 85-86: components/react/authSignerModal.tsx#L85-L86
Added lines #L85 - L86 were not covered by tests


[warning] 89-90: components/react/authSignerModal.tsx#L89-L90
Added lines #L89 - L90 were not covered by tests


[warning] 93-94: components/react/authSignerModal.tsx#L93-L94
Added lines #L93 - L94 were not covered by tests


119-151: Enhance error handling in message decoding.

The current implementation catches errors but only logs them. Consider:

  1. Adding structured error types
  2. Providing more context in error messages
  3. Implementing retry logic for transient failures
+type DecodingError = {
+  type: 'DECODE_ERROR' | 'PARSE_ERROR';
+  messageType: string;
+  error: Error;
+};
+
+const handleDecodingError = (error: Error, messageType: string): DecodingError => ({
+  type: 'DECODE_ERROR',
+  messageType,
+  error,
+});
+
 try {
   // ... decoding logic
 } catch (error) {
-  console.error(`Failed to decode message of type ${msg.typeUrl}:`, error);
+  const decodingError = handleDecodingError(error as Error, msg.typeUrl);
+  console.error('Message decoding failed:', decodingError);
   return {
     typeUrl: msg.typeUrl,
     value: base64Value,
+    error: decodingError,
   };
 }
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 119-151: components/react/authSignerModal.tsx#L119-L151
Added lines #L119 - L151 were not covered by tests

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12555f6 and e342d83.

📒 Files selected for processing (3)
  • components/icons/ArrowRightIcon.tsx (1 hunks)
  • components/messageSyntax.tsx (1 hunks)
  • components/react/authSignerModal.tsx (4 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/messageSyntax.tsx

[warning] 35-50: components/messageSyntax.tsx#L35-L50
Added lines #L35 - L50 were not covered by tests

components/react/authSignerModal.tsx

[warning] 41-42: components/react/authSignerModal.tsx#L41-L42
Added lines #L41 - L42 were not covered by tests


[warning] 45-46: components/react/authSignerModal.tsx#L45-L46
Added lines #L45 - L46 were not covered by tests


[warning] 49-50: components/react/authSignerModal.tsx#L49-L50
Added lines #L49 - L50 were not covered by tests


[warning] 53-54: components/react/authSignerModal.tsx#L53-L54
Added lines #L53 - L54 were not covered by tests


[warning] 57-58: components/react/authSignerModal.tsx#L57-L58
Added lines #L57 - L58 were not covered by tests


[warning] 61-62: components/react/authSignerModal.tsx#L61-L62
Added lines #L61 - L62 were not covered by tests


[warning] 65-66: components/react/authSignerModal.tsx#L65-L66
Added lines #L65 - L66 were not covered by tests


[warning] 69-70: components/react/authSignerModal.tsx#L69-L70
Added lines #L69 - L70 were not covered by tests


[warning] 73-74: components/react/authSignerModal.tsx#L73-L74
Added lines #L73 - L74 were not covered by tests


[warning] 77-78: components/react/authSignerModal.tsx#L77-L78
Added lines #L77 - L78 were not covered by tests


[warning] 81-82: components/react/authSignerModal.tsx#L81-L82
Added lines #L81 - L82 were not covered by tests


[warning] 85-86: components/react/authSignerModal.tsx#L85-L86
Added lines #L85 - L86 were not covered by tests


[warning] 89-90: components/react/authSignerModal.tsx#L89-L90
Added lines #L89 - L90 were not covered by tests


[warning] 93-94: components/react/authSignerModal.tsx#L93-L94
Added lines #L93 - L94 were not covered by tests


[warning] 105-105: components/react/authSignerModal.tsx#L105
Added line #L105 was not covered by tests


[warning] 110-110: components/react/authSignerModal.tsx#L110
Added line #L110 was not covered by tests


[warning] 112-114: components/react/authSignerModal.tsx#L112-L114
Added lines #L112 - L114 were not covered by tests


[warning] 119-151: components/react/authSignerModal.tsx#L119-L151
Added lines #L119 - L151 were not covered by tests


[warning] 185-185: components/react/authSignerModal.tsx#L185
Added line #L185 was not covered by tests


[warning] 196-200: components/react/authSignerModal.tsx#L196-L200
Added lines #L196 - L200 were not covered by tests


[warning] 203-206: components/react/authSignerModal.tsx#L203-L206
Added lines #L203 - L206 were not covered by tests


[warning] 214-227: components/react/authSignerModal.tsx#L214-L227
Added lines #L214 - L227 were not covered by tests


[warning] 230-245: components/react/authSignerModal.tsx#L230-L245
Added lines #L230 - L245 were not covered by tests


[warning] 301-301: components/react/authSignerModal.tsx#L301
Added line #L301 was not covered by tests

🔇 Additional comments (3)
components/icons/ArrowRightIcon.tsx (1)

4-11: LGTM! Well-structured prop interface and component signature.

The addition of the size prop with a default value enhances the component's reusability while maintaining backward compatibility.

components/messageSyntax.tsx (1)

35-53: Add unit tests for the new objectSyntax function.

The static analysis indicates missing test coverage for the new function. Please add tests to verify:

  • Correct JSON formatting
  • Theme-based styling
  • Handling of different object types
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 35-50: components/messageSyntax.tsx#L35-L50
Added lines #L35 - L50 were not covered by tests

components/react/authSignerModal.tsx (1)

214-245: LGTM! Well-implemented collapsible UI.

The implementation of collapsible sections with state management is clean and follows React best practices.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 214-227: components/react/authSignerModal.tsx#L214-L227
Added lines #L214 - L227 were not covered by tests


[warning] 230-245: components/react/authSignerModal.tsx#L230-L245
Added lines #L230 - L245 were not covered by tests

@fmorency fmorency merged commit 8e89206 into main Jan 8, 2025
7 of 8 checks passed
@fmorency fmorency deleted the chalabi/auth-signer branch January 8, 2025 14:49
@coderabbitai coderabbitai bot mentioned this pull request Jan 8, 2025
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