Skip to content

Commit

Permalink
refactor: remove unused feature foags (#1402)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjeatt authored Jul 5, 2023
1 parent 8a9226f commit b4223c3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 69 deletions.
3 changes: 0 additions & 3 deletions .env.dev
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@

/* FEATURE FLAGS */
REACT_APP_FEATURE_FLAG_LENDING=enabled
REACT_APP_FEATURE_FLAG_AMM=enabled
REACT_APP_FEATURE_FLAG_WALLET=enabled
REACT_APP_FEATURE_FLAG_BANXA=enabled
REACT_APP_FEATURE_FLAG_STRATEGIES=enabled
REACT_APP_FEATURE_FLAG_ONBOARDING=enabled
Expand Down
39 changes: 15 additions & 24 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ const App = (): JSX.Element => {

const { bridgeLoaded } = useSelector((state: StoreType) => state.general);
const dispatch = useDispatch();
const isLendingEnabled = useFeatureFlag(FeatureFlags.LENDING);
const isAMMEnabled = useFeatureFlag(FeatureFlags.AMM);
const isWalletEnabled = useFeatureFlag(FeatureFlags.WALLET);
const isStrategiesEnabled = useFeatureFlag(FeatureFlags.STRATEGIES);
const isOnboardingEnabled = useFeatureFlag(FeatureFlags.ONBOARDING);

Expand Down Expand Up @@ -193,26 +190,20 @@ const App = (): JSX.Element => {
<Route path={PAGES.TRANSFER}>
<Transfer />
</Route>
{isLendingEnabled && (
<Route path={PAGES.LOANS}>
<Loans />
</Route>
)}
{isAMMEnabled && (
<Route path={PAGES.SWAP}>
<Swap />
</Route>
)}
{isAMMEnabled && (
<Route path={PAGES.POOLS}>
<Pools />
</Route>
)}
{isWalletEnabled && (
<Route path={PAGES.WALLET}>
<Wallet />
</Route>
)}
<Route path={PAGES.LOANS}>
<Loans />
</Route>
<Route path={PAGES.SWAP}>
<Swap />
</Route>

<Route path={PAGES.POOLS}>
<Pools />
</Route>

<Route path={PAGES.WALLET}>
<Wallet />
</Route>
{isStrategiesEnabled && (
<Route path={PAGES.STRATEGIES}>
<Strategies />
Expand All @@ -226,7 +217,7 @@ const App = (): JSX.Element => {
<Route path={PAGES.ACTIONS}>
<Actions />
</Route>
<Redirect exact from={PAGES.HOME} to={isWalletEnabled ? PAGES.WALLET : PAGES.BRIDGE} />
<Redirect exact from={PAGES.HOME} to={PAGES.WALLET} />
<Route path='*'>
<NoMatch />
</Route>
Expand Down
17 changes: 5 additions & 12 deletions src/parts/Sidebar/SidebarContent/Navigation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ const Navigation = ({
const { t } = useTranslation();
const { selectedAccount } = useSubstrateSecureState();
const { vaultClientLoaded } = useSelector((state: StoreType) => state.general);
const isLendingEnabled = useFeatureFlag(FeatureFlags.LENDING);
const isAMMEnabled = useFeatureFlag(FeatureFlags.AMM);
const isWalletEnabled = useFeatureFlag(FeatureFlags.WALLET);
const isStrategiesEnabled = useFeatureFlag(FeatureFlags.STRATEGIES);
const isOnboardingEnabled = useFeatureFlag(FeatureFlags.ONBOARDING);

Expand All @@ -74,8 +71,7 @@ const Navigation = ({
{
name: 'nav_wallet',
link: PAGES.WALLET,
icon: UserIcon,
disabled: !isWalletEnabled
icon: UserIcon
},
{
name: 'nav_strategies',
Expand All @@ -97,20 +93,17 @@ const Navigation = ({
{
name: 'nav_lending',
link: PAGES.LOANS,
icon: PresentationChartBarIcon,
disabled: !isLendingEnabled
icon: PresentationChartBarIcon
},
{
name: 'nav_swap',
link: PAGES.SWAP,
icon: ArrowPathRoundedSquareIcon,
disabled: !isAMMEnabled
icon: ArrowPathRoundedSquareIcon
},
{
name: 'nav_pools',
link: PAGES.POOLS,
icon: Square3Stack3DIcon,
disabled: !isAMMEnabled
icon: Square3Stack3DIcon
},
{
name: 'nav_staking',
Expand All @@ -136,7 +129,7 @@ const Navigation = ({
separator: true
}
],
[isWalletEnabled, isStrategiesEnabled, isLendingEnabled, isAMMEnabled, selectedAccount?.address, vaultClientLoaded]
[isStrategiesEnabled, selectedAccount?.address, vaultClientLoaded]
);

const SECONDARY_NAVIGATION_ITEMS = React.useMemo(
Expand Down
13 changes: 4 additions & 9 deletions src/utils/hooks/api/use-get-currencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,27 @@ import { useQuery, UseQueryResult } from 'react-query';
import { CurrencySquidFormat } from '@/types/currency';
import { NATIVE_CURRENCIES } from '@/utils/constants/currency';

import { FeatureFlags, useFeatureFlag } from '../use-feature-flag';

type UseGetCurrenciesResult = UseQueryResult<Array<CurrencyExt>> & {
getCurrencyFromTicker: (ticker: string) => CurrencyExt;
getForeignCurrencyFromId: (id: number) => CurrencyExt;
getCurrencyFromIdPrimitive: (currencyPrimitive: InterbtcPrimitivesCurrencyId) => CurrencyExt;
getCurrencyFromSquidFormat: (currencySquidFormat: CurrencySquidFormat) => CurrencyExt;
};

const getCurrencies = async (featureFlags: { lending: boolean; amm: boolean }): Promise<Array<CurrencyExt>> => {
const getCurrencies = async (): Promise<Array<CurrencyExt>> => {
const [foreignCurrencies, lendCurrencies, lpTokens] = await Promise.all([
window.bridge.assetRegistry.getForeignAssets(),
featureFlags.lending ? window.bridge.loans.getLendTokens() : [],
featureFlags.amm ? window.bridge.amm.getLpTokens() : []
window.bridge.loans.getLendTokens(),
window.bridge.amm.getLpTokens()
]);
return [...NATIVE_CURRENCIES, ...foreignCurrencies, ...lendCurrencies, ...lpTokens];
};

// Returns all currencies, both native and foreign and helping utils to get CurrencyExt object.
const useGetCurrencies = (bridgeLoaded: boolean): UseGetCurrenciesResult => {
const isLendingEnabled = useFeatureFlag(FeatureFlags.LENDING);
const isAMMEnabled = useFeatureFlag(FeatureFlags.AMM);

const queryResult = useQuery({
queryKey: 'getCurrencies',
queryFn: () => getCurrencies({ lending: isLendingEnabled, amm: isAMMEnabled }),
queryFn: () => getCurrencies(),
enabled: bridgeLoaded
});

Expand Down
21 changes: 6 additions & 15 deletions src/utils/hooks/api/use-get-prices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { StoreType } from '@/common/types/util.types';
import { PRICES_API, REFETCH_INTERVAL } from '@/utils/constants/api';
import { COINGECKO_ID_BY_CURRENCY_TICKER } from '@/utils/constants/currency';

import { FeatureFlags, useFeatureFlag } from '../use-feature-flag';
import { useGetCurrencies } from './use-get-currencies';

// MEMO: Returns `undefined` for currencies without coingecko ID.
Expand Down Expand Up @@ -72,10 +71,7 @@ const getPricesByTicker = (currencies: CurrencyExt[], prices: Prices, lendTokenP
return { ...acc, [currency.ticker]: prices[coingeckoId] };
}, {});

const getPrices = async (
currencies: CurrencyExt[] | undefined,
isLendingEnabled: boolean
): Promise<Prices | undefined> => {
const getPrices = async (currencies: CurrencyExt[] | undefined): Promise<Prices | undefined> => {
if (!currencies) {
return;
}
Expand All @@ -86,7 +82,7 @@ const getPrices = async (

const [pricesByCoingeckoId, lendTokenPrices] = await Promise.all([
fetchPricesFromCoingecko(endpoint),
isLendingEnabled ? window.bridge.loans.getLendTokenExchangeRates() : {}
window.bridge.loans.getLendTokenExchangeRates()
]);

return getPricesByTicker(allCurrencies, pricesByCoingeckoId, lendTokenPrices);
Expand All @@ -104,17 +100,12 @@ type Prices = {
const useGetPrices = (): Prices | undefined => {
const { bridgeLoaded } = useSelector((state: StoreType) => state.general);
const { data: currencies, isSuccess: isGetCurrenciesSuccess } = useGetCurrencies(bridgeLoaded);
const isLendingEnabled = useFeatureFlag(FeatureFlags.LENDING);

// TODO: error prone because the key computation is not complete
const { data, error } = useQuery<Prices | undefined, Error>(
['prices'],
() => getPrices(currencies, isLendingEnabled),
{
enabled: isGetCurrenciesSuccess,
refetchInterval: REFETCH_INTERVAL.MINUTE
}
);
const { data, error } = useQuery<Prices | undefined, Error>(['prices'], () => getPrices(currencies), {
enabled: isGetCurrenciesSuccess,
refetchInterval: REFETCH_INTERVAL.MINUTE
});

useEffect(() => {
if (!error) return;
Expand Down
6 changes: 0 additions & 6 deletions src/utils/hooks/use-feature-flag.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
enum FeatureFlags {
LENDING = 'lending',
AMM = 'amm',
WALLET = 'wallet',
BANXA = 'banxa',
STRATEGIES = 'strategies',
GEOBLOCK = 'geoblock',
ONBOARDING = 'onboarding'
}

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.STRATEGIES]: process.env.REACT_APP_FEATURE_FLAG_EARN_STRATEGIES,
[FeatureFlags.GEOBLOCK]: process.env.REACT_APP_FEATURE_FLAG_GEOBLOCK,
Expand Down

2 comments on commit b4223c3

@vercel
Copy link

@vercel vercel bot commented on b4223c3 Jul 5, 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 b4223c3 Jul 5, 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.