diff --git a/src/ONYXKEYS.js b/src/ONYXKEYS.js index f38f281b8939..01fefe9dacdb 100755 --- a/src/ONYXKEYS.js +++ b/src/ONYXKEYS.js @@ -179,4 +179,7 @@ export default { // Whether we should show the compose input or not SHOULD_SHOW_COMPOSE_INPUT: 'shouldShowComposeInput', + + // Is app in beta version + IS_BETA: 'isBeta', }; diff --git a/src/libs/Environment/betaChecker/index.android.js b/src/libs/Environment/betaChecker/index.android.js index 3b38f37bcb52..8fbe93f84c0c 100644 --- a/src/libs/Environment/betaChecker/index.android.js +++ b/src/libs/Environment/betaChecker/index.android.js @@ -1,6 +1,15 @@ import semver from 'semver'; +import Onyx from 'react-native-onyx'; import CONST from '../../../CONST'; import pkg from '../../../../package.json'; +import ONYXKEYS from '../../../ONYXKEYS'; +import * as AppUpdate from '../../actions/AppUpdate'; + +let isLastSavedBeta = false; +Onyx.connect({ + key: ONYXKEYS.IS_BETA, + callback: value => isLastSavedBeta = value, +}); /** * Check the GitHub releases to see if the current build is a beta build or production build @@ -14,15 +23,18 @@ function isBetaBuild() { .then((json) => { const productionVersion = json.tag_name; if (!productionVersion) { + AppUpdate.setIsAppInBeta(false); resolve(false); } // If the current version we are running is greater than the production version, we are on a beta version of Android const isBeta = semver.gt(pkg.version, productionVersion); + AppUpdate.setIsAppInBeta(isBeta); resolve(isBeta); }) .catch(() => { - resolve(false); + // Use isLastSavedBeta in case we fail to fetch the new one, e.g. when we are offline + resolve(isLastSavedBeta); }); }); } diff --git a/src/libs/actions/AppUpdate.js b/src/libs/actions/AppUpdate.js index 1ba2f5fb8384..c198c0e1adbb 100644 --- a/src/libs/actions/AppUpdate.js +++ b/src/libs/actions/AppUpdate.js @@ -5,7 +5,14 @@ function triggerUpdateAvailable() { Onyx.set(ONYXKEYS.UPDATE_AVAILABLE, true); } +/** + * @param {Boolean} isBeta + */ +function setIsAppInBeta(isBeta) { + Onyx.set(ONYXKEYS.IS_BETA, isBeta); +} + export { - // eslint-disable-next-line import/prefer-default-export triggerUpdateAvailable, + setIsAppInBeta, };