Skip to content

Commit

Permalink
feature: add geoblock feature flag (#1230)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeatt authored May 25, 2023
1 parent 0d81dc5 commit 63487d0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/Geoblock/Geoblock.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ReactNode } from 'react';
import { ReactNode } from 'react';

import { useGeoblocking } from '@/utils/hooks/use-geoblocking';

Expand Down
6 changes: 4 additions & 2 deletions src/utils/hooks/use-feature-flag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ enum FeatureFlags {
AMM = 'amm',
WALLET = 'wallet',
BANXA = 'banxa',
EARN_STRATEGIES = 'earn-strategies'
EARN_STRATEGIES = 'earn-strategies',
GEOBLOCK = 'geoblock'
}

const featureFlags: Record<FeatureFlags, string | undefined> = {
[FeatureFlags.LENDING]: process.env.REACT_APP_FEATURE_FLAG_LENDING,
[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';
Expand Down
7 changes: 6 additions & 1 deletion src/utils/hooks/use-geoblocking.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -16,7 +21,7 @@ const useGeoblocking = (): void => {
}
};
checkCountry();
}, []);
}, [isGeoblockEnabled]);
};

export { useGeoblocking };

2 comments on commit 63487d0

@vercel
Copy link

@vercel vercel bot commented on 63487d0 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on 63487d0 May 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.