-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[native] VersionSupportedChecker component
Summary: this component calls the identity service and displays an alert if the client code version is not supported by the identity service. Depends on D9813 Test Plan: built the native app with an unsupported code version and saw the alert. built with the actual code version and no alert was displayed. Reviewers: ashoat, ginsu Reviewed By: ashoat Subscribers: inka, tomek, wyilio Differential Revision: https://phab.comm.dev/D9814
- Loading branch information
Showing
7 changed files
with
103 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// @flow | ||
|
||
import * as React from 'react'; | ||
|
||
import { useLogOut, logOutActionTypes } from 'lib/actions/user-actions.js'; | ||
import { preRequestUserStateForSingleKeyserverSelector } from 'lib/selectors/account-selectors.js'; | ||
import { isLoggedIn } from 'lib/selectors/user-selectors.js'; | ||
import { useDispatchActionPromise } from 'lib/utils/action-utils.js'; | ||
import { ashoatKeyserverID } from 'lib/utils/validation-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'; | ||
|
||
function VersionSupportedChecker(): React.Node { | ||
const hasRun = React.useRef(false); | ||
|
||
const loggedIn = useSelector(isLoggedIn); | ||
const preRequestUserState = useSelector( | ||
preRequestUserStateForSingleKeyserverSelector(ashoatKeyserverID), | ||
); | ||
const dispatchActionPromise = useDispatchActionPromise(); | ||
const callLogOut = useLogOut(); | ||
|
||
const onUsernameAlertAcknowledged = React.useCallback(() => { | ||
if (loggedIn) { | ||
dispatchActionPromise(logOutActionTypes, callLogOut(preRequestUserState)); | ||
} | ||
}, [callLogOut, dispatchActionPromise, loggedIn, preRequestUserState]); | ||
|
||
const checkVersionSupport = React.useCallback(async () => { | ||
try { | ||
const isVersionSupported = await commRustModule.versionSupported(); | ||
if (isVersionSupported) { | ||
return; | ||
} | ||
Alert.alert( | ||
AppOutOfDateAlertDetails.title, | ||
AppOutOfDateAlertDetails.message, | ||
[ | ||
{ | ||
text: 'OK', | ||
onPress: onUsernameAlertAcknowledged, | ||
}, | ||
], | ||
{ cancelable: false }, | ||
); | ||
} catch (error) { | ||
console.log('Error checking version:', error); | ||
} | ||
}, [onUsernameAlertAcknowledged]); | ||
|
||
React.useEffect(() => { | ||
if (hasRun.current) { | ||
return; | ||
} | ||
hasRun.current = true; | ||
checkVersionSupport(); | ||
}, [checkVersionSupport]); | ||
|
||
return null; | ||
} | ||
|
||
export default VersionSupportedChecker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// @flow | ||
|
||
import { Platform } from 'react-native'; | ||
|
||
type AlertDetails = { | ||
+title: string, | ||
+message: string, | ||
}; | ||
|
||
const platformStore = Platform.select({ | ||
ios: 'App Store', | ||
android: 'Play Store', | ||
}); | ||
|
||
export const AppOutOfDateAlertDetails: AlertDetails = { | ||
title: 'App out of date', | ||
message: | ||
'Your app version is pretty old, and the server doesn’t know how ' + | ||
`to speak to it anymore. Please use the ${platformStore} to update!`, | ||
}; |