From 31a8356aef278414d4e70985ddbf3f76e6a455f1 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 7 May 2024 21:09:02 -0500 Subject: [PATCH] Handle invalid service URLs (#3908) --- src/screens/Messages/List/index.tsx | 13 +++++++++++-- .../Messages/Temp/useDmServiceUrlStorage.tsx | 9 ++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/screens/Messages/List/index.tsx b/src/screens/Messages/List/index.tsx index ce8f52af..ca757fac 100644 --- a/src/screens/Messages/List/index.tsx +++ b/src/screens/Messages/List/index.tsx @@ -47,6 +47,7 @@ export function MessagesScreen({navigation}: Props) { // TEMP const {serviceUrl, setServiceUrl} = useDmServiceUrlStorage() + const [serviceUrlValue, setServiceUrlValue] = useState(serviceUrl) const hasValidServiceUrl = useMemo(() => { const hash = sha256(serviceUrl) return ( @@ -136,13 +137,21 @@ export function MessagesScreen({navigation}: Props) { Service URL setServiceUrl(text)} + value={serviceUrlValue} + onChangeText={text => setServiceUrlValue(text)} autoCapitalize="none" keyboardType="url" label="https://" /> + ) diff --git a/src/screens/Messages/Temp/useDmServiceUrlStorage.tsx b/src/screens/Messages/Temp/useDmServiceUrlStorage.tsx index d78128b5..0e3f8760 100644 --- a/src/screens/Messages/Temp/useDmServiceUrlStorage.tsx +++ b/src/screens/Messages/Temp/useDmServiceUrlStorage.tsx @@ -35,7 +35,14 @@ export function DmServiceUrlProvider({children}: {children: React.ReactNode}) { React.useEffect(() => { ;(async () => { const v = await getItem() - setServiceUrl(v ?? '') + try { + if (v) { + new URL(v) + setServiceUrl(v) + } + } catch (e) { + console.error('Invalid service URL stored in async storage:', v) + } })() }, [getItem])