Handle invalid service URLs (#3908)
parent
165fdb7049
commit
31a8356aef
|
@ -47,6 +47,7 @@ export function MessagesScreen({navigation}: Props) {
|
||||||
|
|
||||||
// TEMP
|
// TEMP
|
||||||
const {serviceUrl, setServiceUrl} = useDmServiceUrlStorage()
|
const {serviceUrl, setServiceUrl} = useDmServiceUrlStorage()
|
||||||
|
const [serviceUrlValue, setServiceUrlValue] = useState(serviceUrl)
|
||||||
const hasValidServiceUrl = useMemo(() => {
|
const hasValidServiceUrl = useMemo(() => {
|
||||||
const hash = sha256(serviceUrl)
|
const hash = sha256(serviceUrl)
|
||||||
return (
|
return (
|
||||||
|
@ -136,13 +137,21 @@ export function MessagesScreen({navigation}: Props) {
|
||||||
<TextField.LabelText>Service URL</TextField.LabelText>
|
<TextField.LabelText>Service URL</TextField.LabelText>
|
||||||
<TextField.Root>
|
<TextField.Root>
|
||||||
<TextField.Input
|
<TextField.Input
|
||||||
value={serviceUrl}
|
value={serviceUrlValue}
|
||||||
onChangeText={text => setServiceUrl(text)}
|
onChangeText={text => setServiceUrlValue(text)}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
keyboardType="url"
|
keyboardType="url"
|
||||||
label="https://"
|
label="https://"
|
||||||
/>
|
/>
|
||||||
</TextField.Root>
|
</TextField.Root>
|
||||||
|
<Button
|
||||||
|
label="Set Service URL"
|
||||||
|
size="small"
|
||||||
|
variant="solid"
|
||||||
|
color="primary"
|
||||||
|
onPress={() => setServiceUrl(serviceUrlValue)}>
|
||||||
|
<ButtonText>Set</ButtonText>
|
||||||
|
</Button>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
)
|
)
|
||||||
|
|
|
@ -35,7 +35,14 @@ export function DmServiceUrlProvider({children}: {children: React.ReactNode}) {
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
;(async () => {
|
;(async () => {
|
||||||
const v = await getItem()
|
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])
|
}, [getItem])
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue