Skip to content

Commit

Permalink
get feature flags ready for launch
Browse files Browse the repository at this point in the history
  • Loading branch information
mattupham committed Sep 18, 2024
1 parent 23b347b commit aa463a1
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions packages/web/hooks/use-feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { apiClient } from "@osmosis-labs/utils";
import { useQuery } from "@tanstack/react-query";
import { useFlags, useLDClient } from "launchdarkly-react-client-sdk";
import { useEffect, useState } from "react";

import { useWindowSize } from "~/hooks";
import { LevanaGeoBlockedResponse } from "~/pages/_app";

// NOTE: Please add a default value to any new flag you add to this list
export type AvailableFlags =
Expand Down Expand Up @@ -57,27 +60,27 @@ const defaultFlags: Record<AvailableFlags, boolean> = {
sqsActiveOrders: false,
};

// const LIMIT_ORDER_COUNTRY_CODES =
// process.env.NEXT_PUBLIC_LIMIT_ORDER_COUNTRY_CODES?.split(",").map((s) =>
// s.trim()
// ) ?? [];
const LIMIT_ORDER_COUNTRY_CODES =
process.env.NEXT_PUBLIC_LIMIT_ORDER_COUNTRY_CODES?.split(",").map((s) =>
s.trim()
) ?? [];

export function useFeatureFlags() {
const launchdarklyFlags: Record<AvailableFlags, boolean> = useFlags();
const { isMobile } = useWindowSize();
const [isInitialized, setIsInitialized] = useState(false);
const client = useLDClient();

// const { data: levanaGeoblock } = useQuery(
// ["levana-geoblocked"],
// () =>
// apiClient<LevanaGeoBlockedResponse>("https://geoblocked.levana.finance/"),
// {
// staleTime: Infinity,
// cacheTime: Infinity,
// retry: false,
// }
// );
const { data: levanaGeoblock } = useQuery(
["levana-geoblocked"],
() =>
apiClient<LevanaGeoBlockedResponse>("https://geoblocked.levana.finance/"),
{
staleTime: Infinity,
cacheTime: Infinity,
retry: false,
}
);

useEffect(() => {
if (!isInitialized && client && process.env.NODE_ENV !== "test")
Expand All @@ -99,11 +102,21 @@ export function useFeatureFlags() {
isMobile || !isInitialized
? false
: launchdarklyFlags.portfolioPageAndNewAssetsPage,
oneClickTrading:
!isMobile &&
launchdarklyFlags.swapToolSimulateFee && // 1-Click trading is dependent on the swap tool simulate fee flag
launchdarklyFlags.oneClickTrading,
_isInitialized: isDevModeWithoutClientID ? true : isInitialized,
_isClientIDPresent: !!process.env.NEXT_PUBLIC_LAUNCH_DARKLY_CLIENT_SIDE_ID,
limitOrders: true,
oneClickTrading: true,
staking: true,
limitOrders:
isInitialized &&
launchdarklyFlags.limitOrders &&
(LIMIT_ORDER_COUNTRY_CODES.length === 0 ||
LIMIT_ORDER_COUNTRY_CODES.includes(levanaGeoblock?.countryCode ?? "")),
// To test chain upgrades easily on Edgenet, uncomment the block below
// limitOrders: true,
// oneClickTrading: true,
// staking: true,
} as Record<
AvailableFlags | "_isInitialized" | "_isClientIDPresent",
boolean
Expand Down

0 comments on commit aa463a1

Please sign in to comment.