diff --git a/lib/shared/keyserver-utils.js b/lib/shared/keyserver-utils.js --- a/lib/shared/keyserver-utils.js +++ b/lib/shared/keyserver-utils.js @@ -15,6 +15,7 @@ const serverCallParamOverride = React.useMemo( () => ({ urlPrefix: keyserverURL, + connectionStatus: 'connecting', }), [keyserverURL], ); diff --git a/native/profile/add-keyserver.react.js b/native/profile/add-keyserver.react.js --- a/native/profile/add-keyserver.react.js +++ b/native/profile/add-keyserver.react.js @@ -6,6 +6,7 @@ import { useDispatch } from 'react-redux'; import { addKeyserverActionType } from 'lib/actions/keyserver-actions.js'; +import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js'; import type { KeyserverInfo } from 'lib/types/keyserver-types.js'; import { defaultConnectionInfo } from 'lib/types/socket-types.js'; @@ -26,12 +27,22 @@ const styles = useStyles(unboundStyles); const [urlInput, setUrlInput] = React.useState(''); + const [showErrorMessage, setShowErrorMessage] = React.useState(false); - const onPressSave = React.useCallback(() => { + const isKeyserverURLValidCallback = useIsKeyserverURLValid(urlInput); + + const onPressSave = React.useCallback(async () => { + setShowErrorMessage(false); if (!currentUserID || !urlInput) { return; } + const isKeyserverURLValid = await isKeyserverURLValidCallback(); + if (!isKeyserverURLValid) { + setShowErrorMessage(true); + return; + } + const newKeyserverInfo: KeyserverInfo = { cookie: null, updatesCurrentAsOf: 0, @@ -49,7 +60,7 @@ }); goBack(); - }, [currentUserID, dispatch, goBack, urlInput]); + }, [currentUserID, dispatch, goBack, isKeyserverURLValidCallback, urlInput]); React.useEffect(() => { setOptions({ @@ -65,6 +76,19 @@ [], ); + const errorMessage = React.useMemo(() => { + if (!showErrorMessage) { + return null; + } + + return ( + + Cannot connect to keyserver. Please check the URL or your connection and + try again. + + ); + }, [showErrorMessage, styles.errorMessage]); + return ( KEYSERVER URL @@ -80,6 +104,7 @@ autoCorrect={false} /> + {errorMessage} ); } @@ -113,6 +138,11 @@ paddingVertical: 0, borderBottomColor: 'transparent', }, + errorMessage: { + marginTop: 8, + marginHorizontal: 16, + color: 'redText', + }, }; export default AddKeyserver;