diff --git a/lib/facts/feature-flags.js b/lib/facts/feature-flags.js deleted file mode 100644 --- a/lib/facts/feature-flags.js +++ /dev/null @@ -1,7 +0,0 @@ -// @flow - -const config = { - url: 'https://feature-flags.commtechnologies.org', -}; - -export default config; diff --git a/lib/utils/feature-flags-utils.js b/lib/utils/feature-flags-utils.js deleted file mode 100644 --- a/lib/utils/feature-flags-utils.js +++ /dev/null @@ -1,28 +0,0 @@ -// @flow - -import featureFlags from '../facts/feature-flags.js'; - -type FeatureFlagsConfiguration = { - +enabledFeatures: $ReadOnlyArray, -}; - -async function fetchFeatureFlags( - platform: string, - isStaff: boolean, - codeVersion: number, -): Promise { - const url = `${ - featureFlags.url - }/features?platform=${platform}&is_staff=${isStaff.toString()}&code_version=${codeVersion}`; - const response = await fetch(url, { - headers: { - Accept: 'application/json', - }, - }); - const json = await response.json(); - return { - enabledFeatures: json.enabled_features, - }; -} - -export { fetchFeatureFlags }; diff --git a/native/components/feature-flags-provider.react.js b/native/components/feature-flags-provider.react.js deleted file mode 100644 --- a/native/components/feature-flags-provider.react.js +++ /dev/null @@ -1,119 +0,0 @@ -// @flow - -import AsyncStorage from '@react-native-async-storage/async-storage'; -import * as React from 'react'; -import { Platform } from 'react-native'; - -import { useIsCurrentUserStaff } from 'lib/shared/staff-utils.js'; -import { fetchFeatureFlags } from 'lib/utils/feature-flags-utils.js'; -import sleep from 'lib/utils/sleep.js'; - -import { codeVersion } from '../redux/persist.js'; - -type FeatureFlagsConfiguration = { - +[feature: string]: boolean, -}; - -type FeatureFlagsContextType = { - +configuration: FeatureFlagsConfiguration, - +loadedFromService: boolean, -}; - -const defaultContext = { - configuration: {}, - loadedFromService: false, -}; - -const FeatureFlagsContext: React.Context = - React.createContext(defaultContext); - -const featureFlagsStorageKey = 'FeatureFlags'; - -type Props = { - +children: React.Node, -}; -function FeatureFlagsProvider(props: Props): React.Node { - const { children } = props; - const isStaff = useIsCurrentUserStaff(); - - const [featuresConfig, setFeaturesConfig] = React.useState(defaultContext); - - React.useEffect(() => { - void (async () => { - if (featuresConfig.loadedFromService) { - return; - } - - const persistedFeaturesConfig = await AsyncStorage.getItem( - featureFlagsStorageKey, - ); - if (!persistedFeaturesConfig) { - return; - } - - setFeaturesConfig(config => - config.loadedFromService - ? config - : { - configuration: JSON.parse(persistedFeaturesConfig), - loadedFromService: false, - }, - ); - })(); - }, [featuresConfig.loadedFromService]); - - React.useEffect(() => { - void (async () => { - try { - const config = await tryMultipleTimes( - () => fetchFeatureFlags(Platform.OS, isStaff, codeVersion), - 3, - 5000, - ); - - const configuration: { [string]: true } = {}; - for (const feature of config.enabledFeatures) { - configuration[feature] = true; - } - setFeaturesConfig({ - configuration, - loadedFromService: true, - }); - await AsyncStorage.setItem( - featureFlagsStorageKey, - JSON.stringify(configuration), - ); - } catch (e) { - console.error('Feature flag retrieval failed:', e); - } - })(); - }, [isStaff]); - - return ( - - {children} - - ); -} - -async function tryMultipleTimes( - f: () => Promise, - numberOfTries: number, - delay: number, -): Promise { - let lastError; - while (numberOfTries > 0) { - try { - return await f(); - } catch (e) { - --numberOfTries; - lastError = e; - if (numberOfTries > 0) { - await sleep(delay); - } - } - } - throw lastError; -} - -export { FeatureFlagsContext, FeatureFlagsProvider, featureFlagsStorageKey }; diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -69,7 +69,6 @@ import ConnectFarcasterAlertHandler from './components/connect-farcaster-alert-handler.react.js'; import DisplayCommunityDirectoryPromptHandler from './components/display-community-directory-prompt.react.js'; import FarcasterSyncHandler from './components/farcaster-sync-handler.react.js'; -import { FeatureFlagsProvider } from './components/feature-flags-provider.react.js'; import NonKeyserverActivityHandler from './components/non-keyserver-activity-handler.react.js'; import { NUXTipsContextProvider } from './components/nux-tips-context.react.js'; import PersistedStateGate from './components/persisted-state-gate.js'; @@ -388,68 +387,66 @@ generateAESKey={generateQRAuthAESKey} onLogInError={handleQRAuthError} > - - - - - - - - - - - - - - - - - - {gated} - - - - - - - - - - - - - - - - - {navigation} - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + {gated} + + + + + + + + + + + + + + + + + {navigation} + + + + + + + + + + + + + diff --git a/native/utils/crash-utils.js b/native/utils/crash-utils.js --- a/native/utils/crash-utils.js +++ b/native/utils/crash-utils.js @@ -4,7 +4,6 @@ import sleep from 'lib/utils/sleep.js'; -import { featureFlagsStorageKey } from '../components/feature-flags-provider.react.js'; import { clearSensitiveData } from '../data/sqlite-data-handler.js'; import { commCoreModule } from '../native-modules.js'; import { navStateAsyncStorageKey } from '../navigation/persistance.js'; @@ -14,7 +13,6 @@ await Promise.all([ __DEV__ ? AsyncStorage.removeItem(navStateAsyncStorageKey) : null, AsyncStorage.removeItem('ANDROID_REFERRER'), - AsyncStorage.removeItem(featureFlagsStorageKey), clearSensitiveData(), ]); await getPersistor().purge();