Add useEnvFeatures to gate fetch when unsupported on env

This commit is contained in:
jaredvu
2024-02-20 10:41:33 -08:00
parent 88fa4e26e4
commit b9024ca6df
6 changed files with 101 additions and 44 deletions
+31 -16
View File
@@ -127,7 +127,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-dev-2": {
@@ -212,7 +213,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-dev-4": {
@@ -298,7 +300,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-dev-5": {
@@ -383,7 +386,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-staging": {
@@ -470,7 +474,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-staging-forced-update": {
@@ -555,7 +560,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-staging-west": {
@@ -642,7 +648,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet": {
@@ -733,7 +740,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-dydx": {
@@ -821,7 +829,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-nodefleet": {
@@ -909,7 +918,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-kingnodes": {
@@ -997,7 +1007,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-liquify": {
@@ -1085,7 +1096,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-polkachu": {
@@ -1164,7 +1176,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-bware": {
@@ -1252,7 +1265,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-mainnet": {
@@ -1340,8 +1354,9 @@
}
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": false
}
}
}
}
}
+31 -16
View File
@@ -258,7 +258,8 @@
"faucet": "https://faucet.v4dev.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-dev-2": {
@@ -283,7 +284,8 @@
"nobleValidator": "https://noble-testnet-rpc.polkachu.com/"
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-dev-4": {
@@ -309,7 +311,8 @@
"faucet": "https://faucet.v4dev4.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-dev-5": {
@@ -334,7 +337,8 @@
"nobleValidator": "https://noble-testnet-rpc.polkachu.com/"
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-staging": {
@@ -360,7 +364,8 @@
"nobleValidator": "https://noble-testnet-rpc.polkachu.com/"
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-staging-forced-update": {
@@ -393,7 +398,8 @@
}
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-staging-west": {
@@ -419,7 +425,8 @@
"nobleValidator": "https://noble-testnet-rpc.polkachu.com/"
},
"featureFlags": {
"reduceOnlySupported": true
"reduceOnlySupported": true,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet": {
@@ -449,7 +456,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-dydx": {
@@ -475,7 +483,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-nodefleet": {
@@ -501,7 +510,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-kingnodes": {
@@ -527,7 +537,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-liquify": {
@@ -553,7 +564,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-polkachu": {
@@ -579,7 +591,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-testnet-bware": {
@@ -605,7 +618,8 @@
"faucet": "https://faucet.v4testnet.dydx.exchange"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": true
}
},
"dydxprotocol-mainnet": {
@@ -631,8 +645,9 @@
"nobleValidator": "[noble validator endpoint for mainnet]"
},
"featureFlags": {
"reduceOnlySupported": false
"reduceOnlySupported": false,
"withdrawalSafetyEnabled": false
}
}
}
}
}
+2
View File
@@ -7,6 +7,7 @@ import { useDebounce } from './useDebounce';
import { useInterval } from './useInterval';
import { useDocumentTitle } from './useDocumentTitle';
import { useDydxClient } from './useDydxClient';
import { useEnvFeatures } from './useEnvFeatures';
import { useGovernanceVariables } from './useGovernanceVariables';
import { useAccountBalance } from './useAccountBalance';
import { useAccounts } from './useAccounts';
@@ -37,6 +38,7 @@ export {
useDebounce,
useDocumentTitle,
useDydxClient,
useEnvFeatures,
useGovernanceVariables,
useAccountBalance,
useAccounts,
+15
View File
@@ -0,0 +1,15 @@
import { useSelector } from 'react-redux';
import { ENVIRONMENT_CONFIG_MAP } from '@/constants/networks';
import { getSelectedNetwork } from '@/state/appSelectors';
export interface EnvironmentFeatures {
reduceOnlySupported: boolean;
withdrawalSafetyEnabled: boolean;
}
export const useEnvFeatures = (): EnvironmentFeatures => {
const selectedNetwork = useSelector(getSelectedNetwork);
return ENVIRONMENT_CONFIG_MAP[selectedNetwork].featureFlags;
};
+18 -8
View File
@@ -7,6 +7,7 @@ import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { DialogTypes } from '@/constants/dialogs';
import { isMainnet } from '@/constants/networks';
import { useEnvFeatures } from './useEnvFeatures';
import { getApiState } from '@/state/appSelectors';
import { closeDialog, openDialog } from '@/state/dialogs';
@@ -31,8 +32,10 @@ export const useWithdrawalInfo = ({
const { height } = apiState || {};
const selectedLocale = useSelector(getSelectedLocale);
const dispatch = useDispatch();
const { withdrawalSafetyEnabled } = useEnvFeatures();
const { data: usdcWithdawalCapacity } = useQuery({
const { data: usdcWithdrawalCapacity } = useQuery({
enabled: withdrawalSafetyEnabled,
queryKey: 'usdcWithdrawalCapacity',
queryFn: async () => {
try {
@@ -47,6 +50,7 @@ export const useWithdrawalInfo = ({
});
const { data: withdrawalAndTransferGatingStatus } = useQuery({
enabled: withdrawalSafetyEnabled,
queryKey: 'withdrawalTransferGateStatus',
queryFn: getWithdrawalAndTransferGatingStatus,
refetchInterval: 60_000,
@@ -54,8 +58,12 @@ export const useWithdrawalInfo = ({
});
const capacity = useMemo(() => {
const capacityList = usdcWithdawalCapacity?.limiterCapacityList;
const capacityList = usdcWithdrawalCapacity?.limiterCapacityList;
if (!capacityList || capacityList.length < 2) {
if (!withdrawalSafetyEnabled) {
return BigNumber(Infinity);
}
return BIG_NUMBERS.ZERO;
}
@@ -63,14 +71,15 @@ export const useWithdrawalInfo = ({
const dailyBN = MustBigNumber(daily);
const weeklyBN = MustBigNumber(weekly);
return BigNumber.minimum(dailyBN, weeklyBN).div(10 ** usdcDecimals);
}, [usdcDecimals, usdcWithdawalCapacity]);
}, [usdcDecimals, usdcWithdrawalCapacity]);
const withdrawalAndTransferGatingStatusValue = useMemo(() => {
const { withdrawalsAndTransfersUnblockedAtBlock } = withdrawalAndTransferGatingStatus ?? {};
if (
height &&
withdrawalsAndTransfersUnblockedAtBlock &&
height < withdrawalsAndTransfersUnblockedAtBlock
height < withdrawalsAndTransfersUnblockedAtBlock &&
withdrawalSafetyEnabled
) {
return {
estimatedUnblockTime: formatRelativeTime(
@@ -87,12 +96,13 @@ export const useWithdrawalInfo = ({
estimatedUnblockTime: null,
isGated: false,
};
}, [height, withdrawalAndTransferGatingStatus]);
}, [height, withdrawalAndTransferGatingStatus, withdrawalSafetyEnabled]);
useEffect(() => {
if (
withdrawalAndTransferGatingStatusValue.isGated &&
withdrawalAndTransferGatingStatusValue.estimatedUnblockTime
withdrawalAndTransferGatingStatusValue.estimatedUnblockTime &&
withdrawalSafetyEnabled
) {
dispatch(closeDialog());
dispatch(
@@ -105,10 +115,10 @@ export const useWithdrawalInfo = ({
})
);
}
}, [withdrawalAndTransferGatingStatusValue.isGated]);
}, [withdrawalAndTransferGatingStatusValue.isGated, withdrawalSafetyEnabled]);
return {
usdcWithdawalCapacity: capacity,
usdcWithdrawalCapacity: capacity,
withdrawalAndTransferGatingStatus,
};
};
@@ -89,7 +89,7 @@ export const WithdrawForm = () => {
const [slippage, setSlippage] = useState(isCctp ? 0 : 0.01); // 0.1% slippage
const debouncedAmount = useDebounce<string>(withdrawAmount, 500);
const { usdcLabel } = useTokenConfigs();
const { usdcWithdawalCapacity } = useWithdrawalInfo({ transferType: 'withdrawal' });
const { usdcWithdrawalCapacity } = useWithdrawalInfo({ transferType: 'withdrawal' });
const isValidAddress = toAddress && isAddress(toAddress);
@@ -402,7 +402,7 @@ export const WithdrawForm = () => {
}
// Withdrawal Safety
if (usdcWithdawalCapacity.gt(0) && debouncedAmountBN.gt(usdcWithdawalCapacity)) {
if (usdcWithdrawalCapacity.gt(0) && debouncedAmountBN.gt(usdcWithdrawalCapacity)) {
return {
alertType: AlertType.Warning,
errorMessage: stringGetter({
@@ -410,7 +410,7 @@ export const WithdrawForm = () => {
params: {
USDC_LIMIT: (
<span>
{usdcWithdawalCapacity.toFormat(TOKEN_DECIMALS)}
{usdcWithdrawalCapacity.toFormat(TOKEN_DECIMALS)}
<Styled.Tag>{usdcLabel}</Styled.Tag>
</span>
),
@@ -434,7 +434,7 @@ export const WithdrawForm = () => {
sanctionedAddresses,
stringGetter,
summary,
usdcWithdawalCapacity,
usdcWithdrawalCapacity,
]);
const isInvalidNobleAddress = Boolean(