Skip to content

Commit

Permalink
fix(notifications): follow up to make dynamic config more robust to n…
Browse files Browse the repository at this point in the history
…on existent flags (#956)
  • Loading branch information
moo-onthelawn authored Aug 27, 2024
1 parent 3cb94be commit 284f32c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion public/configs/v1/env.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
"stakingAndClaimingRewardsLearnMore": "[HTTP link to staking and claiming rewards learn more]",
"predictionMarketLearnMore": "[HTTP link to prediction market learn more]",
"discoveryProgram": "[HTTP link to discovery program learn more]",
"getInTouch": "[HTTP link to get in touch with traders]"
"getInTouch": "[HTTP link to get in touch with traders]"
}
},
"wallets": {
Expand Down
6 changes: 4 additions & 2 deletions src/constants/statsig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export enum StatSigFlags {
ffEnableKeplr = 'ff_enable_keplr',
}

export type StatsigDynamicConfigType = Record<StatsigDynamicConfigs, any>;

export enum StatsigDynamicConfigs {
dcMaxSafeBridgeFees = 'dc_max_safe_bridge_fees',
dcHighestVolumeUsers = 'dc_highest_volume_users',
dcMaxSafeBridgeFees = 'dc_max_safe_bridge_fees', // returns number
dcHighestVolumeUsers = 'dc_highest_volume_users', // returns string[]
}
9 changes: 5 additions & 4 deletions src/hooks/useNotificationTypes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ import { useApiState } from './useApiState';
import { useComplianceState } from './useComplianceState';
import { useIncentivesSeason } from './useIncentivesSeason';
import { useQueryChaosLabsIncentives } from './useQueryChaosLabsIncentives';
import { useAllStatsigGateValues, useStatsigDynamicConfigValue } from './useStatsig';
import { useAllStatsigGateValues, useAllStatsigDynamicConfigValues } from './useStatsig';
import { useStringGetter } from './useStringGetter';
import { useTokenConfigs } from './useTokenConfigs';
import { useURLConfigs } from './useURLConfigs';
Expand Down Expand Up @@ -670,11 +670,12 @@ export const notificationTypes: NotificationTypeConfig[] = [
useTrigger: ({ trigger }) => {
const { dydxAddress } = useAccounts();
const { getInTouch } = useURLConfigs();
const feedbackRequestWalletAddresses = useStatsigDynamicConfigValue(
StatsigDynamicConfigs.dcHighestVolumeUsers
) as string[];
const stringGetter = useStringGetter();

const dynamicConfigs = useAllStatsigDynamicConfigValues();
const feedbackRequestWalletAddresses =
dynamicConfigs?.[StatsigDynamicConfigs.dcHighestVolumeUsers];

useEffect(() => {
if (dydxAddress && feedbackRequestWalletAddresses?.includes(dydxAddress) && getInTouch) {
trigger(FeedbackRequestNotificationIds.Top100UserSupport, {
Expand Down
19 changes: 13 additions & 6 deletions src/hooks/useStatsig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import {
useStatsigClient,
} from '@statsig/react-bindings';

import { StatSigFlags, StatsigConfigType, StatsigDynamicConfigs } from '@/constants/statsig';
import {
StatSigFlags,
StatsigConfigType,
StatsigDynamicConfigType,
StatsigDynamicConfigs,
} from '@/constants/statsig';

import { initStatsigAsync } from '@/lib/statsig';

Expand All @@ -28,12 +33,14 @@ export const useStatsigGateValue = (gate: StatSigFlags) => {
return checkGate(gate);
};

export const useStatsigDynamicConfigValue = (
configName: StatsigDynamicConfigs,
keyOverride: string = 'value'
) => {
export const useAllStatsigDynamicConfigValues = () => {
const { getDynamicConfig } = useStatsigClient();
return getDynamicConfig(configName)?.get(keyOverride);
const allDynamicConfigValues = useMemo(() => {
return Object.values(StatsigDynamicConfigs).reduce((acc, gate) => {
return { ...acc, [gate]: getDynamicConfig(gate).get('value') };
}, {} as StatsigDynamicConfigType);
}, [getDynamicConfig]);
return allDynamicConfigValues;
};

export const useAllStatsigGateValues = () => {
Expand Down

0 comments on commit 284f32c

Please sign in to comment.