Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3351886
D9666.id34246.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D9666.id34246.diff
View Options
diff --git a/lib/shared/keyserver-utils.js b/lib/shared/keyserver-utils.js
new file mode 100644
--- /dev/null
+++ b/lib/shared/keyserver-utils.js
@@ -0,0 +1,48 @@
+// @flow
+
+import * as React from 'react';
+
+import {
+ useGetVersion,
+ getVersionActionTypes,
+} from '../actions/device-actions.js';
+import { useDispatchActionPromise } from '../utils/action-utils.js';
+
+function useIsKeyserverURLValid(keyserverURL?: string): () => Promise<boolean> {
+ const serverCallParamOverride = React.useMemo(() => {
+ if (!keyserverURL) {
+ return undefined;
+ }
+
+ return {
+ keyserverInfos: {
+ [(keyserverURL: string)]: {
+ urlPrefix: keyserverURL,
+ },
+ },
+ };
+ }, [keyserverURL]);
+
+ const getVersionCall = useGetVersion(serverCallParamOverride);
+
+ const dispatchActionPromise = useDispatchActionPromise();
+
+ return React.useCallback(async () => {
+ if (!keyserverURL) {
+ return false;
+ }
+
+ const getVersionPromise = getVersionCall();
+ dispatchActionPromise(getVersionActionTypes, getVersionPromise);
+
+ // We don't care about the result; just need to make sure this doesn't throw
+ try {
+ await getVersionPromise;
+ return true;
+ } catch (e) {
+ return false;
+ }
+ }, [dispatchActionPromise, getVersionCall, keyserverURL]);
+}
+
+export { useIsKeyserverURLValid };
diff --git a/native/account/registration/keyserver-selection.react.js b/native/account/registration/keyserver-selection.react.js
--- a/native/account/registration/keyserver-selection.react.js
+++ b/native/account/registration/keyserver-selection.react.js
@@ -4,12 +4,9 @@
import * as React from 'react';
import { Text, View, TextInput } from 'react-native';
-import {
- useGetVersion,
- getVersionActionTypes,
-} from 'lib/actions/device-actions.js';
+import { getVersionActionTypes } from 'lib/actions/device-actions.js';
import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js';
-import { useDispatchActionPromise } from 'lib/utils/action-utils.js';
+import { useIsKeyserverURLValid } from 'lib/shared/keyserver-utils.js';
import RegistrationButtonContainer from './registration-button-container.react.js';
import RegistrationButton from './registration-button.react.js';
@@ -108,34 +105,18 @@
buttonState = 'loading';
}
- const serverCallParamOverride = React.useMemo(
- () => ({
- keyserverInfos: {
- [(keyserverURL: string)]: {
- urlPrefix: keyserverURL,
- },
- },
- }),
- [keyserverURL],
- );
- const getVersionCall = useGetVersion(serverCallParamOverride);
+ const isKeyserverURLValidPromiseCallback =
+ useIsKeyserverURLValid(keyserverURL);
- const dispatchActionPromise = useDispatchActionPromise();
const { navigate } = props.navigation;
const { coolOrNerdMode } = props.route.params.userSelections;
+
const onSubmit = React.useCallback(async () => {
setError(undefined);
- if (!keyserverURL) {
- return;
- }
- const getVersionPromise = getVersionCall();
- dispatchActionPromise(getVersionActionTypes, getVersionPromise);
+ const isKeyserverURLValid = await isKeyserverURLValidPromiseCallback();
- // We don't care about the result; just need to make sure this doesn't throw
- try {
- await getVersionPromise;
- } catch {
+ if (!isKeyserverURLValid) {
setError('cant_reach_keyserver');
return;
}
@@ -149,12 +130,11 @@
params: { userSelections: { coolOrNerdMode, keyserverURL } },
});
}, [
- navigate,
- coolOrNerdMode,
keyserverURL,
+ isKeyserverURLValidPromiseCallback,
setCachedSelections,
- dispatchActionPromise,
- getVersionCall,
+ navigate,
+ coolOrNerdMode,
]);
const styles = useStyles(unboundStyles);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 3:57 AM (20 h, 56 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2573283
Default Alt Text
D9666.id34246.diff (3 KB)
Attached To
Mode
D9666: [lib/native] introduce useIsKeyserverURLValid hook
Attached
Detach File
Event Timeline
Log In to Comment