From 63487d09bd6bf3b55ae58b7cdc3da3d2657d4011 Mon Sep 17 00:00:00 2001 From: tomjeatt <40243778+tomjeatt@users.noreply.github.com> Date: Thu, 25 May 2023 10:49:47 +0100 Subject: [PATCH] feature: add geoblock feature flag (#1230) --- src/components/Geoblock/Geoblock.tsx | 2 +- src/utils/hooks/use-feature-flag.ts | 6 ++++-- src/utils/hooks/use-geoblocking.ts | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/Geoblock/Geoblock.tsx b/src/components/Geoblock/Geoblock.tsx index 43493562d3..0a308d5619 100644 --- a/src/components/Geoblock/Geoblock.tsx +++ b/src/components/Geoblock/Geoblock.tsx @@ -1,4 +1,4 @@ -import React, { ReactNode } from 'react'; +import { ReactNode } from 'react'; import { useGeoblocking } from '@/utils/hooks/use-geoblocking'; diff --git a/src/utils/hooks/use-feature-flag.ts b/src/utils/hooks/use-feature-flag.ts index 8f9254eab3..917bd3b3c8 100644 --- a/src/utils/hooks/use-feature-flag.ts +++ b/src/utils/hooks/use-feature-flag.ts @@ -3,7 +3,8 @@ enum FeatureFlags { AMM = 'amm', WALLET = 'wallet', BANXA = 'banxa', - EARN_STRATEGIES = 'earn-strategies' + EARN_STRATEGIES = 'earn-strategies', + GEOBLOCK = 'geoblock' } const featureFlags: Record = { @@ -11,7 +12,8 @@ const featureFlags: Record = { [FeatureFlags.AMM]: process.env.REACT_APP_FEATURE_FLAG_AMM, [FeatureFlags.WALLET]: process.env.REACT_APP_FEATURE_FLAG_WALLET, [FeatureFlags.BANXA]: process.env.REACT_APP_FEATURE_FLAG_BANXA, - [FeatureFlags.EARN_STRATEGIES]: process.env.REACT_APP_FEATURE_FLAG_EARN_STRATEGIES + [FeatureFlags.EARN_STRATEGIES]: process.env.REACT_APP_FEATURE_FLAG_EARN_STRATEGIES, + [FeatureFlags.GEOBLOCK]: process.env.REACT_APP_FEATURE_FLAG_GEOBLOCK }; const useFeatureFlag = (feature: FeatureFlags): boolean => featureFlags[feature] === 'enabled'; diff --git a/src/utils/hooks/use-geoblocking.ts b/src/utils/hooks/use-geoblocking.ts index 6ca37d3a02..09805c8398 100644 --- a/src/utils/hooks/use-geoblocking.ts +++ b/src/utils/hooks/use-geoblocking.ts @@ -1,9 +1,14 @@ import { useEffect } from 'react'; import { GEOBLOCK_API_ENDPOINT, GEOBLOCK_REDIRECTION_LINK } from '@/config/links'; +import { FeatureFlags, useFeatureFlag } from '@/utils/hooks/use-feature-flag'; const useGeoblocking = (): void => { + const isGeoblockEnabled = useFeatureFlag(FeatureFlags.GEOBLOCK); + useEffect(() => { + if (!isGeoblockEnabled) return; + const checkCountry = async () => { try { const response = await fetch(GEOBLOCK_API_ENDPOINT); @@ -16,7 +21,7 @@ const useGeoblocking = (): void => { } }; checkCountry(); - }, []); + }, [isGeoblockEnabled]); }; export { useGeoblocking };