Page MenuHomePhorge

D6949.1765327775.diff
No OneTemporary

Size
2 KB
Referenced Files
None
Subscribers
None

D6949.1765327775.diff

diff --git a/lib/facts/feature-flags.js b/lib/facts/feature-flags.js
new file mode 100644
--- /dev/null
+++ b/lib/facts/feature-flags.js
@@ -0,0 +1,7 @@
+// @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
new file mode 100644
--- /dev/null
+++ b/lib/utils/feature-flags-utils.js
@@ -0,0 +1,28 @@
+// @flow
+
+import featureFlags from '../facts/feature-flags.js';
+
+type FeatureFlagsConfiguration = {
+ +enabledFeatures: $ReadOnlyArray<string>,
+};
+
+async function fetchFeatureFlags(
+ platform: string,
+ isStaff: boolean,
+ codeVersion: number,
+): Promise<FeatureFlagsConfiguration> {
+ 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
--- a/native/components/feature-flags-provider.react.js
+++ b/native/components/feature-flags-provider.react.js
@@ -1,6 +1,12 @@
// @flow
import * as React from 'react';
+import { Platform } from 'react-native';
+
+import { fetchFeatureFlags } from 'lib/utils/feature-flags-utils.js';
+import { useIsCurrentUserStaff } from 'native/utils/staff-utils.js';
+
+import { codeVersion } from '../redux/persist.js';
type FeatureFlagsConfiguration = {
+[feature: string]: boolean,
@@ -24,8 +30,33 @@
};
function FeatureFlagsProvider(props: Props): React.Node {
const { children } = props;
+ const isStaff = useIsCurrentUserStaff();
+
+ const [featuresConfig, setFeaturesConfig] = React.useState(defaultContext);
+ React.useEffect(() => {
+ (async () => {
+ try {
+ const config = await fetchFeatureFlags(
+ Platform.OS,
+ isStaff,
+ codeVersion,
+ );
+ const configuration = {};
+ for (const feature of config.enabledFeatures) {
+ configuration[feature] = true;
+ }
+ setFeaturesConfig({
+ configuration,
+ loaded: true,
+ });
+ } catch (e) {
+ console.error('Feature flag retrieval failed:', e);
+ }
+ })();
+ }, [isStaff]);
+
return (
- <FeatureFlagsContext.Provider value={defaultContext}>
+ <FeatureFlagsContext.Provider value={featuresConfig}>
{children}
</FeatureFlagsContext.Provider>
);

File Metadata

Mime Type
text/plain
Expires
Wed, Dec 10, 12:49 AM (17 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5858141
Default Alt Text
D6949.1765327775.diff (2 KB)

Event Timeline