Skip to content

Commit

Permalink
fix: URL Crash (#1084)
Browse files Browse the repository at this point in the history
* fix: URL Crash

Added safety to URL
Reverted to FramesStore access for full frame

* fix: URL Crashes

Reverted change to set isFrames
Added additional safety
Attempted some improved performance
  • Loading branch information
alexrisch authored Oct 23, 2024
1 parent 67b0761 commit ccd0aa4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
9 changes: 5 additions & 4 deletions components/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useSelect } from "@data/store/storeHelpers";
import { FlashList } from "@shopify/flash-list";
import {
backgroundColor,
itemSeparatorColor,
tertiaryBackgroundColor,
} from "@styles/colors";
import { getCleanAddress } from "@utils/evm/address";
import { FrameWithType, isFrameMessage } from "@utils/frames";
import { FrameWithType } from "@utils/frames";
import differenceInCalendarDays from "date-fns/differenceInCalendarDays";
import React, { useCallback, useEffect, useMemo, useRef } from "react";
import {
Expand Down Expand Up @@ -89,7 +90,7 @@ const useRenderItem = ({
message={{ ...item }}
colorScheme={colorScheme}
isGroup={!!conversation?.isGroup}
isFrame={isFrameMessage(item, framesStore)}
isFrame={!!framesStore[item.content.toLowerCase().trim()]}
/>
);
},
Expand Down Expand Up @@ -382,7 +383,7 @@ export function Chat() {
styles.inChatRecommendations,
]);

const framesStore = useFramesStore().frames;
const { frames: framesStore } = useFramesStore(useSelect(["frames"]));

const showPlaceholder = useIsShowingPlaceholder({
messages: listArray,
Expand Down Expand Up @@ -538,7 +539,7 @@ export function ChatPreview() {
]
);

const framesStore = useFramesStore().frames;
const { frames: framesStore } = useFramesStore(useSelect(["frames"]));

const showPlaceholder = useIsShowingPlaceholder({
messages: listArray,
Expand Down
6 changes: 5 additions & 1 deletion components/Chat/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ const ChatMessage = ({
const contentType = getMessageContentType(message.contentType);

const handleUrlPress = useCallback((url: string) => {
const uri = url.toLowerCase().startsWith("http") ? url : `https://${url}`;
const cleanedUrl = url.toLowerCase().trim();

const uri = cleanedUrl.startsWith("http")
? cleanedUrl
: `https://${cleanedUrl}`;

Linking.openURL(uri);
}, []);
Expand Down
10 changes: 7 additions & 3 deletions utils/messageContent.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import emojiRegex from "emoji-regex";

export const getUrlToRender = (url: string) => {
const fullUrl = new URL(url);
return fullUrl.hostname;
export const getUrlToRender = (url: string): string | undefined => {
try {
const fullUrl = new URL(url);
return fullUrl.hostname;
} catch {
return undefined;
}
};

export const isAllEmojisAndMaxThree = (str: string) => {
Expand Down

0 comments on commit ccd0aa4

Please sign in to comment.