feat: add chains dynamicconfig for feature flags (#7389)

* feat: add feature flags dynamic config for chains

* fix

* add better chainid error checking

* quiet linter

* refactor & should be quick_route_chains only
This commit is contained in:
Kristie Huang 2023-09-29 14:53:01 -04:00 committed by GitHub
parent 3a4dc91e49
commit cbec108172
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

@ -0,0 +1,10 @@
import { DynamicConfig, useConfig } from 'statsig-react'
export enum DynamicConfigName {
quickRouteChains = 'quick_route_chains',
}
export function useDynamicConfig(configName: DynamicConfigName): DynamicConfig {
const { config } = useConfig(configName)
return config
}

@ -0,0 +1,15 @@
import { ChainId } from '@uniswap/sdk-core'
import { DynamicConfigName, useDynamicConfig } from '.'
// eslint-disable-next-line import/no-unused-modules
export function useQuickRouteChains(): ChainId[] {
const config = useDynamicConfig(DynamicConfigName.quickRouteChains)
const chains = config.get('chains', [])
if (chains.every((c) => Object.values(ChainId).includes(c))) {
return chains as ChainId[]
} else {
console.error('feature flag config chains contain invalid ChainId')
return []
}
}

@ -57,7 +57,7 @@ export function useUpdateFlag() {
}
export function FeatureFlagsProvider({ children }: { children: ReactNode }) {
// TODO(vm): `isLoaded` to `true` so `App.tsx` will render. Later, this will be dependent on
// TODO: `isLoaded` to `true` so `App.tsx` will render. Later, this will be dependent on
// flags loading from Amplitude, with a timeout.
const featureFlags = useAtomValue(featureFlagSettings)
const value = {