Skip to content

Commit

Permalink
Handle invalid service URLs (#3908)
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey authored May 8, 2024
1 parent 165fdb7 commit 31a8356
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/screens/Messages/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -136,13 +137,21 @@ export function MessagesScreen({navigation}: Props) {
<TextField.LabelText>Service URL</TextField.LabelText>
<TextField.Root>
<TextField.Input
value={serviceUrl}
onChangeText={text => setServiceUrl(text)}
value={serviceUrlValue}
onChangeText={text => setServiceUrlValue(text)}
autoCapitalize="none"
keyboardType="url"
label="https://"
/>
</TextField.Root>
<Button
label="Set Service URL"
size="small"
variant="solid"
color="primary"
onPress={() => setServiceUrl(serviceUrlValue)}>
<ButtonText>Set</ButtonText>
</Button>
</View>
</ScrollView>
)
Expand Down
9 changes: 8 additions & 1 deletion src/screens/Messages/Temp/useDmServiceUrlStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down

0 comments on commit 31a8356

Please sign in to comment.