Skip to content

Commit

Permalink
move types and enum to constants file
Browse files Browse the repository at this point in the history
  • Loading branch information
yogurtandjam committed Jul 1, 2024
1 parent 9061b48 commit e6c91e7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/constants/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { StatSigFlags } from '@/types/statsig';
import { RecordOf, TagsOf, UnionOf, ofType, unionize } from 'unionize';

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

import type { AbacusApiStatus, HumanReadablePlaceOrderPayload } from './abacus';
import type { OnboardingState, OnboardingSteps } from './account';
import { DialogTypesTypes } from './dialogs';
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useLocalNotifications.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createContext, useCallback, useContext, useEffect } from 'react';

import { StatSigFlags } from '@/types/statsig';
import { useQuery } from '@tanstack/react-query';

import { AnalyticsEvents } from '@/constants/analytics';
Expand All @@ -10,7 +11,6 @@ import { useAccounts } from '@/hooks/useAccounts';

import { track } from '@/lib/analytics';
import { STATUS_ERROR_GRACE_PERIOD, fetchTransferStatus, trackSkipTx } from '@/lib/squid';
import { StatSigFlags } from '@/lib/statsig';

import { useEndpointsConfig } from './useEndpointsConfig';
import { useLocalStorage } from './useLocalStorage';
Expand Down
12 changes: 5 additions & 7 deletions src/hooks/useStatsig.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useEffect, useState } from 'react';

import { StatSigFlags, StatsigConfigType } from '@/types/statsig';
import { StatsigClient } from '@statsig/js-client';
import {
StatsigProvider as StatsigProviderInternal,
useStatsigClient,
} from '@statsig/react-bindings';

import { StatSigFlags, statsigClientPromise } from '@/lib/statsig';
import { statsigClientPromise } from '@/lib/statsig';

export const StatsigProvider = ({ children }: { children: React.ReactNode }) => {
const [client, setClient] = useState<StatsigClient | null>(null);
Expand All @@ -29,10 +30,7 @@ export const useStatsigGateValue = (gate: StatSigFlags) => {

export const useAllStatsigGateValues = () => {
const { checkGate } = useStatsigClient();
return Object.values(StatSigFlags).reduce(
(acc, gate) => {
return { ...acc, [gate]: checkGate(gate) };
},
{} as { [key in StatSigFlags]?: boolean }
);
return Object.values(StatSigFlags).reduce((acc, gate) => {
return { ...acc, [gate]: checkGate(gate) };
}, {} as StatsigConfigType);
};
4 changes: 2 additions & 2 deletions src/lib/abacus/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// eslint-disable-next-line import/no-cycle
import { StatSigFlags } from '@/types/statsig';
import type { LocalWallet, SelectedGasDenom } from '@dydxprotocol/v4-client-js';

import type {
Expand Down Expand Up @@ -46,8 +48,6 @@ import { setTradeFormInputs } from '@/state/inputs';
import { getInputTradeOptions, getTransferInputs } from '@/state/inputsSelectors';

import { LocaleSeparators } from '../numbers';
// eslint-disable-next-line import/no-cycle
import { StatSigFlags } from '../statsig';
import AbacusAnalytics from './analytics';
import AbacusChainTransaction from './dydxChainTransactions';
import AbacusFileSystem from './filesystem';
Expand Down
15 changes: 5 additions & 10 deletions src/lib/statsig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { StatSigFlags, StatsigConfigType } from '@/types/statsig';
import { StatsigClient } from '@statsig/js-client';

const fetchIp = async () => {
Expand Down Expand Up @@ -35,21 +36,15 @@ const statsigCheckGatePromise = async (gateId: StatSigFlags) => {
* This function should typically be avoided in favor of the useStatsig hook
* This is used in useInitializePage to retrieve configs for abacus only once
* inside of a useEffect hook.
*
*/
export const statsigGetAllGateValuesPromise = async () => {
const results = await Promise.all(
Object.values(StatSigFlags).map(async (gate) => ({
[gate]: await statsigCheckGatePromise(gate),
}))
);
return results.reduce(
(acc, gate) => {
return { ...acc, ...gate };
},
{} as { [key in StatSigFlags]?: boolean }
);
return results.reduce((acc, gate) => {
return { ...acc, ...gate };
}, {} as StatsigConfigType);
};

export enum StatSigFlags {
ffSkipMigration = 'ff_skip_migration',
}
5 changes: 5 additions & 0 deletions src/types/statsig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type StatsigConfigType = Record<StatSigFlags, boolean>;

export enum StatSigFlags {
ffSkipMigration = 'ff_skip_migration',
}

0 comments on commit e6c91e7

Please sign in to comment.