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

fix: Set is Frame when ending with slash #1129

Merged
merged 1 commit into from
Oct 29, 2024
Merged

Conversation

alexrisch
Copy link
Collaborator

@alexrisch alexrisch commented Oct 29, 2024

Added handling to clean url
Updated to use util function

Summary by CodeRabbit

  • New Features

    • Enhanced message handling in the chat component to better identify frame messages.
  • Bug Fixes

    • Improved error handling for transaction frames related to specific testnets.
  • Refactor

    • Streamlined frame-checking logic by introducing a dedicated utility function, improving code clarity and maintainability.

Added handling to clean url
Updated to use util function
@alexrisch alexrisch requested a review from a team as a code owner October 29, 2024 13:58
Copy link
Contributor

coderabbitai bot commented Oct 29, 2024

Walkthrough

The changes introduced in this pull request involve the addition of a new utility function isFrameMessage in @utils/frames, which refines the logic for identifying frame messages within the ChatMessage component. This function replaces a previous direct check with a more structured approach that assesses the message type and content. The ChatMessage component's rendering logic is adjusted accordingly, while the overall structure and error handling remain unchanged. The modifications aim to enhance code clarity and maintainability without altering the component's external behavior.

Changes

File Change Summary
components/Chat/Message/Message.tsx Introduced isFrameMessage for frame message determination, adjusted message content rendering logic.
utils/frames.ts Added isFrameMessage function with updated parameters; refined logic for frame compatibility checks.

Possibly related PRs

  • fix: Render Frame on initial send #1067: This PR modifies the ChatMessage component to use the isFrameMessage utility function, which is directly related to the changes made in the main PR that introduces this utility function.
  • fix: Frames Renders on initial Send #1113: This PR updates the ChatMessage component to use hasFrames instead of isFrame, which is a semantic change related to the frame handling logic introduced in the main PR.

Suggested labels

2.0.7

Poem

In the chat where messages play,
A frame's found in a brand new way.
With logic clear, we hop and cheer,
For messages bright, now free of fear!
A little tweak, a function's grace,
Brings joy to all in this lively space! 🐇✨


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 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
Contributor

Performance Comparison Report

  • Current: 390ff3b - 2024-10-29 14:02:03Z
  • Baseline: main (92d51a4) - 2024-10-29 14:01:24Z

Significant Changes To Duration

There are no entries

Meaningless Changes To Duration

Show entries
Name Type Duration Count
Avatar Image 10 runs render 1.4 ms → 1.4 ms 1 → 1
Avatar Image 50 runs render 1.1 ms → 1.1 ms 1 → 1
Empty Avatar 10 runs render 1.0 ms → 0.8 ms (-0.2 ms, -20.0%) 🟢 1 → 1
Empty Avatar 50 runs render 0.8 ms → 0.7 ms (-0.1 ms, -7.7%) 1 → 1
Show details
Name Type Duration Count
Avatar Image 10 runs render Baseline
Mean: 1.4 ms
Stdev: 0.5 ms (36.9%)
Runs: 1 1 1 2 2 1 2 1 2 1
Warmup runs: 2

Current
Mean: 1.4 ms
Stdev: 0.5 ms (36.9%)
Runs: 1 2 1 1 2 1 1 2 2 1
Warmup runs: 3
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Avatar Image 50 runs render Baseline
Mean: 1.1 ms
Stdev: 0.3 ms (25.4%)
Runs: 1 1 1 1 1 1 1 1 2 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Warmup runs: 1

Current
Mean: 1.1 ms
Stdev: 0.3 ms (25.4%)
Runs: 1 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1
Warmup runs: 2
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 10 runs render Baseline
Mean: 1.0 ms
Stdev: 0.5 ms (47.1%)
Runs: 1 2 1 1 1 1 0 1 1 1
Warmup runs: 75

Current
Mean: 0.8 ms
Stdev: 0.4 ms (52.7%)
Runs: 1 1 1 0 1 1 1 1 0 1
Warmup runs: 8
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1
Render issues:
Empty Avatar 50 runs render Baseline
Mean: 0.8 ms
Stdev: 0.5 ms (59.6%)
Runs: 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 0 1 1 1 0 0 2 1 0 0 1 1 0 1 1 0 1 0
Warmup runs: 1

Current
Mean: 0.7 ms
Stdev: 0.5 ms (63.0%)
Runs: 1 1 0 1 1 1 0 1 0 1 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 0 1 1 0 1 0 1 0 1 1 1 1 1 1 1 0 1 0 1 1 1 0 1 0 1
Warmup runs: 1
Baseline
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Current
Mean: 1
Stdev: 0 (0.0%)
Runs: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
Render issues:

Render Count Changes

There are no entries

Render Issues

There are no entries

Added Scenarios

There are no entries

Removed Scenarios

There are no entries

Generated by 🚫 dangerJS against 35ff90e

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: 1

🧹 Outside diff range and nitpick comments (2)
utils/frames.ts (1)

274-285: LGTM! Consider adding input validation.

The implementation correctly handles URL normalization and follows good separation of concerns. However, consider adding input validation for the parameters.

 export const isFrameMessage = (
   messageIsText: boolean,
   messageContent: string,
   framesStore: {
     [frameUrl: string]: FrameWithType;
   }
 ): boolean => {
+  if (messageContent == null || framesStore == null) return false;
   if (!messageIsText) return false;
   const content = messageContent.toLowerCase().trim();
   const sanitizedContent = content.endsWith("/")
     ? content.slice(0, -1)
     : content;
   return !!framesStore[sanitizedContent];
 };
components/Chat/Message/Message.tsx (1)

Line range hint 391-397: Consider extracting URL handling logic

The URL handling logic in the handleUrlPress callback could be moved to a utility function to ensure consistent URL cleaning across the application.

-const handleUrlPress = useCallback((url: string) => {
-  const cleanedUrl = url.toLowerCase().trim();
-
-  const uri = cleanedUrl.startsWith("http")
-    ? cleanedUrl
-    : `https://${cleanedUrl}`;
-
-  Linking.openURL(uri);
-}, []);
+import { cleanAndFormatUrl } from '@utils/url';
+
+const handleUrlPress = useCallback((url: string) => {
+  Linking.openURL(cleanAndFormatUrl(url));
+}, []);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 92d51a4 and 35ff90e.

📒 Files selected for processing (2)
  • components/Chat/Message/Message.tsx (2 hunks)
  • utils/frames.ts (1 hunks)
🔇 Additional comments (3)
utils/frames.ts (1)

274-285: Verify URL handling consistency across the codebase.

Let's ensure that frame URLs are handled consistently throughout the codebase, particularly in the fetchFramesForMessage function where frames are stored.

✅ Verification successful

Let me gather more context about the frame URL handling by checking the implementation of related functions.


Based on the evidence gathered, I can now provide the final response:

URL handling is consistent across frame-related operations

The codebase demonstrates consistent URL handling patterns:

  • Frame URLs are consistently stored in lowercase: framesToSave[response.url.toLowerCase()]
  • The same normalization is applied when storing with trailing slash: framesToSave[${response.url.toLowerCase()}/]
  • The lookup in framesStore matches this pattern by normalizing the input URL similarly
  • No direct URL comparisons are found that could bypass this normalization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential inconsistencies in URL handling

# Test 1: Check if there are any direct frame URL comparisons without normalization
echo "Checking for direct URL comparisons..."
rg -i "url\s*===\s*|url\s*!==\s*|url\.equals|url\.compare" --type ts

# Test 2: Check frame URL storage patterns
echo "Checking frame URL storage patterns..."
rg "framesToSave\[.*\]|framesStore\[.*\]" --type ts

Length of output: 606


Script:

#!/bin/bash
# Check the implementation of frame-related functions
ast-grep --pattern 'function fetchFramesForMessage($_) {
  $$$
}'

# Also check for any other frame URL processing
ast-grep --pattern 'function $_ ($_) {
  $$$
  url.toLowerCase()
  $$$
}'

# Check frame validation logic
rg -A 5 "validateFrame" --type ts

Length of output: 1724

components/Chat/Message/Message.tsx (2)

10-10: LGTM: Clean import addition

The new utility import is properly placed and follows the codebase's import organization pattern.


171-177: Verify consistent usage of isFrameMessage across the codebase

The implementation looks correct, using useShallow for performance optimization. Let's verify that all other usages of isFrameMessage have been updated to match this new signature.

✅ Verification successful

No issues found with isFrameMessage usage

The implementation in utils/frames.ts matches exactly with the usage in components/Chat/Message/Message.tsx. The function signature and parameter order are consistent:

  1. messageIsText: boolean - Passed as isContentType("text", message.contentType)
  2. messageContent: string - Passed as message.content
  3. framesStore: object - Passed as s.frames

The function is correctly used within a useShallow hook to prevent unnecessary re-renders, and all parameters are passed in the expected order. The implementation in utils/frames.ts properly handles the validation of these parameters.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of isFrameMessage to ensure consistent parameter usage
rg "isFrameMessage\(" --type ts --type tsx -A 3 -B 1

Length of output: 82


Script:

#!/bin/bash
# Search for all usages of isFrameMessage without file type restrictions
rg "isFrameMessage\(" -A 3 -B 1

Length of output: 351


Script:

#!/bin/bash
# Find the definition of isFrameMessage function
ast-grep --pattern 'function isFrameMessage($_) { $$$ }'

Length of output: 58


Script:

#!/bin/bash
# Find any const/let/var declarations of isFrameMessage
ast-grep --pattern '(const|let|var) isFrameMessage = $_'

Length of output: 58


Script:

#!/bin/bash
# Find files that might contain isFrameMessage
fd "isFrameMessage"

Length of output: 19


Script:

#!/bin/bash
# Try to find isFrameMessage in any TypeScript/JavaScript file using a more flexible pattern
rg -l "isFrameMessage" --type ts --type js --type jsx --type tsx || rg -l "isFrameMessage"

Length of output: 167


Script:

#!/bin/bash
# Look for export statements containing isFrameMessage
rg "export.*isFrameMessage"

Length of output: 77


Script:

#!/bin/bash
# Search for the file content where isFrameMessage might be defined
fd -e ts -e tsx -e js -e jsx -x cat {} | rg -A 10 -B 10 "isFrameMessage.*=.*"

Length of output: 721


Script:

#!/bin/bash
# Get the full content of frames.ts to see the complete isFrameMessage implementation
cat utils/frames.ts

Length of output: 9021


Script:

#!/bin/bash
# Get the full content of Message.tsx to see the complete usage context
cat components/Chat/Message/Message.tsx

Length of output: 22852

Comment on lines +281 to +284
const content = messageContent.toLowerCase().trim();
const sanitizedContent = content.endsWith("/")
? content.slice(0, -1)
: content;
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider extracting URL normalization logic.

The URL normalization logic could be reused in other parts of the codebase. Consider extracting it into a separate utility function.

+const normalizeUrl = (url: string): string => {
+  const normalized = url.toLowerCase().trim();
+  return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
+};

 export const isFrameMessage = (
   messageIsText: boolean,
   messageContent: string,
   framesStore: {
     [frameUrl: string]: FrameWithType;
   }
 ): boolean => {
   if (!messageIsText) return false;
-  const content = messageContent.toLowerCase().trim();
-  const sanitizedContent = content.endsWith("/")
-    ? content.slice(0, -1)
-    : content;
+  const sanitizedContent = normalizeUrl(messageContent);
   return !!framesStore[sanitizedContent];
 };
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const content = messageContent.toLowerCase().trim();
const sanitizedContent = content.endsWith("/")
? content.slice(0, -1)
: content;
const normalizeUrl = (url: string): string => {
const normalized = url.toLowerCase().trim();
return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
};
export const isFrameMessage = (
messageIsText: boolean,
messageContent: string,
framesStore: {
[frameUrl: string]: FrameWithType;
}
): boolean => {
if (!messageIsText) return false;
const sanitizedContent = normalizeUrl(messageContent);
return !!framesStore[sanitizedContent];
};

@alexrisch alexrisch merged commit 4a68dd4 into main Oct 29, 2024
6 checks passed
@alexrisch alexrisch deleted the ar/frensday-requests branch October 29, 2024 15:59
alexrisch added a commit that referenced this pull request Nov 1, 2024
* [create-pull-request] automated change (#1122)

Co-authored-by: alexrisch <[email protected]>

* fix: Set is Frame when ending with slash (#1129)

Added handling to clean url
Updated to use util function

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>
alexrisch added a commit that referenced this pull request Nov 19, 2024
* [create-pull-request] automated change (#1122)

Co-authored-by: alexrisch <[email protected]>

* fix: Set is Frame when ending with slash (#1129)

Added handling to clean url
Updated to use util function

* Allow ethereum deeplinks inside frames (#1198)

* Allow ethereum deeplinks inside frames

* Set and new file

* Bump app json

* [create-pull-request] automated change (#1195)

Co-authored-by: alexrisch <[email protected]>

* [create-pull-request] automated change (#1197)

Co-authored-by: alexrisch <[email protected]>

---------

Co-authored-by: Noé Malzieu <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>

* Fix linking for ethereum: links (#1208)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>
Co-authored-by: Noé Malzieu <[email protected]>
alexrisch added a commit that referenced this pull request Nov 19, 2024
* [create-pull-request] automated change (#1122)

Co-authored-by: alexrisch <[email protected]>

* fix: Set is Frame when ending with slash (#1129)

Added handling to clean url
Updated to use util function

* Allow ethereum deeplinks inside frames (#1198)

* Allow ethereum deeplinks inside frames

* Set and new file

* Bump app json

* [create-pull-request] automated change (#1195)

Co-authored-by: alexrisch <[email protected]>

* [create-pull-request] automated change (#1197)

Co-authored-by: alexrisch <[email protected]>

---------

Co-authored-by: Noé Malzieu <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>

* Fix linking for ethereum: links (#1208)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>
Co-authored-by: Noé Malzieu <[email protected]>
@coderabbitai coderabbitai bot mentioned this pull request Dec 2, 2024
technoplato pushed a commit that referenced this pull request Dec 17, 2024
* [create-pull-request] automated change (#1122)

Co-authored-by: alexrisch <[email protected]>

* fix: Set is Frame when ending with slash (#1129)

Added handling to clean url
Updated to use util function

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>
technoplato pushed a commit that referenced this pull request Dec 17, 2024
* [create-pull-request] automated change (#1122)

Co-authored-by: alexrisch <[email protected]>

* fix: Set is Frame when ending with slash (#1129)

Added handling to clean url
Updated to use util function

* Allow ethereum deeplinks inside frames (#1198)

* Allow ethereum deeplinks inside frames

* Set and new file

* Bump app json

* [create-pull-request] automated change (#1195)

Co-authored-by: alexrisch <[email protected]>

* [create-pull-request] automated change (#1197)

Co-authored-by: alexrisch <[email protected]>

---------

Co-authored-by: Noé Malzieu <[email protected]>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>

* Fix linking for ethereum: links (#1208)

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: alexrisch <[email protected]>
Co-authored-by: Noé Malzieu <[email protected]>
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