From 5bbc300d984ec1de5e57e2601ca75905372a0bf7 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Wed, 23 Oct 2024 19:21:59 -0400 Subject: [PATCH 1/2] fix: URL Crash Added safety to URL Reverted to FramesStore access for full frame --- components/Chat/Chat.tsx | 4 ++-- components/Chat/Message/Message.tsx | 6 +++++- utils/messageContent.ts | 10 +++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 7239bb017..2082f43b7 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -5,7 +5,7 @@ import { 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 { @@ -89,7 +89,7 @@ const useRenderItem = ({ message={{ ...item }} colorScheme={colorScheme} isGroup={!!conversation?.isGroup} - isFrame={isFrameMessage(item, framesStore)} + isFrame={!!framesStore[item.content.toLowerCase().trim()]} /> ); }, diff --git a/components/Chat/Message/Message.tsx b/components/Chat/Message/Message.tsx index 77c39fdfc..eecbecfde 100644 --- a/components/Chat/Message/Message.tsx +++ b/components/Chat/Message/Message.tsx @@ -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); }, []); diff --git a/utils/messageContent.ts b/utils/messageContent.ts index 7c0fb3f98..c24880f3b 100644 --- a/utils/messageContent.ts +++ b/utils/messageContent.ts @@ -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) => { From a43933ecc27788b41e50b4122ecf4972b6687d29 Mon Sep 17 00:00:00 2001 From: Alex Risch Date: Wed, 23 Oct 2024 19:29:35 -0400 Subject: [PATCH 2/2] fix: URL Crashes Reverted change to set isFrames Added additional safety Attempted some improved performance --- components/Chat/Chat.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/Chat/Chat.tsx b/components/Chat/Chat.tsx index 2082f43b7..102e57e81 100644 --- a/components/Chat/Chat.tsx +++ b/components/Chat/Chat.tsx @@ -1,3 +1,4 @@ +import { useSelect } from "@data/store/storeHelpers"; import { FlashList } from "@shopify/flash-list"; import { backgroundColor, @@ -382,7 +383,7 @@ export function Chat() { styles.inChatRecommendations, ]); - const framesStore = useFramesStore().frames; + const { frames: framesStore } = useFramesStore(useSelect(["frames"])); const showPlaceholder = useIsShowingPlaceholder({ messages: listArray, @@ -538,7 +539,7 @@ export function ChatPreview() { ] ); - const framesStore = useFramesStore().frames; + const { frames: framesStore } = useFramesStore(useSelect(["frames"])); const showPlaceholder = useIsShowingPlaceholder({ messages: listArray,