diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js --- a/lib/actions/user-actions.js +++ b/lib/actions/user-actions.js @@ -1137,6 +1137,24 @@ return identityClient.findUserIdentities; } +const versionSupportedByIdentityActionTypes = Object.freeze({ + started: 'VERSION_SUPPORTED_BY_IDENTITY_STARTED', + success: 'VERSION_SUPPORTED_BY_IDENTITY_SUCCESS', + failed: 'VERSION_SUPPORTED_BY_IDENTITY_FAILED', +}); + +function useVersionSupportedByIdentity(): () => Promise<{ + +supported: boolean, +}> { + const client = React.useContext(IdentityClientContext); + const identityClient = client?.identityClient; + invariant(identityClient, 'Identity client should be set'); + return async () => { + const supported = await identityClient.versionSupported(); + return { supported }; + }; +} + export { changeKeyserverUserPasswordActionTypes, changeKeyserverUserPassword, @@ -1185,4 +1203,6 @@ processNewUserIDsActionType, findUserIdentitiesActionTypes, useFindUserIdentities, + versionSupportedByIdentityActionTypes, + useVersionSupportedByIdentity, }; diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js --- a/lib/types/redux-types.js +++ b/lib/types/redux-types.js @@ -1490,6 +1490,24 @@ +payload: Error, +loadingInfo: LoadingInfo, } + | { + +type: 'VERSION_SUPPORTED_BY_IDENTITY_STARTED', + +loadingInfo?: LoadingInfo, + +payload?: void, + } + | { + +type: 'VERSION_SUPPORTED_BY_IDENTITY_SUCCESS', + +payload: { + +supported: boolean, + }, + +loadingInfo: LoadingInfo, + } + | { + +type: 'VERSION_SUPPORTED_BY_IDENTITY_FAILED', + +error: true, + +payload: Error, + +loadingInfo: LoadingInfo, + } | { +type: 'FETCH_PENDING_UPDATES_STARTED', +loadingInfo?: LoadingInfo, diff --git a/native/components/version-supported.react.js b/native/components/version-supported.react.js --- a/native/components/version-supported.react.js +++ b/native/components/version-supported.react.js @@ -2,11 +2,15 @@ import * as React from 'react'; -import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js'; +import { + useLogOut, + logOutActionTypes, + useVersionSupportedByIdentity, + versionSupportedByIdentityActionTypes, +} from 'lib/actions/user-actions.js'; import { isLoggedIn } from 'lib/selectors/user-selectors.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; -import { commRustModule } from '../native-modules.js'; import { useSelector } from '../redux/redux-utils.js'; import { appOutOfDateAlertDetails } from '../utils/alert-messages.js'; import Alert from '../utils/alert.js'; @@ -17,6 +21,7 @@ const loggedIn = useSelector(isLoggedIn); const dispatchActionPromise = useDispatchActionPromise(); const callLogOut = useLogOut(); + const callVersionSupportedByIdentity = useVersionSupportedByIdentity(); const onUsernameAlertAcknowledged = React.useCallback(() => { if (loggedIn) { @@ -26,7 +31,12 @@ const checkVersionSupport = React.useCallback(async () => { try { - const isVersionSupported = await commRustModule.versionSupported(); + const versionSupportedPromise = callVersionSupportedByIdentity(); + void dispatchActionPromise( + versionSupportedByIdentityActionTypes, + versionSupportedPromise, + ); + const { supported: isVersionSupported } = await versionSupportedPromise; if (isVersionSupported) { return; } @@ -44,7 +54,11 @@ } catch (error) { console.log('Error checking version:', error); } - }, [onUsernameAlertAcknowledged]); + }, [ + callVersionSupportedByIdentity, + dispatchActionPromise, + onUsernameAlertAcknowledged, + ]); React.useEffect(() => { if (hasRun.current) {