From ebd5dea412e1e144e423c1d49f897332a7e2fe23 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Fri, 26 Jan 2024 16:08:18 +0300 Subject: [PATCH 01/48] feat: intermediate commit --- pages/settings.tsx | 5 +++-- providers/index.tsx | 27 +++++++++++++++------------ providers/one-config.tsx | 34 ++++++++++++++++++++++++++++++++++ utils/isClientSide.ts | 1 + 4 files changed, 53 insertions(+), 14 deletions(-) create mode 100644 providers/one-config.tsx diff --git a/pages/settings.tsx b/pages/settings.tsx index c7c0ce847..641216997 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,9 +1,9 @@ import { FC } from 'react'; import { GetStaticProps } from 'next'; -import { dynamics } from 'config'; import { Layout } from 'shared/components'; import { SettingsForm } from 'features/settings/settings-form'; +import { getOneConfig } from 'providers/one-config'; const Settings: FC = () => { return ( @@ -16,7 +16,8 @@ const Settings: FC = () => { export default Settings; export const getStaticProps: GetStaticProps = async () => { - if (!dynamics.ipfsMode) return { notFound: true }; + const { ipfsMode } = getOneConfig(); + if (!ipfsMode) return { notFound: true }; return { props: {} }; }; diff --git a/providers/index.tsx b/providers/index.tsx index 8d250854c..76e4f3a89 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -3,6 +3,7 @@ import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; import { AppFlagProvider } from './app-flag'; +import { OneConfigProvider } from './one-config'; import { ClientConfigProvider } from './client-config'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; import ModalProvider from './modals'; @@ -11,16 +12,18 @@ import Web3Provider from './web3'; export { MODAL, ModalContext } from './modals'; export const Providers: FC = ({ children }) => ( - - - - - - - {children} - - - - - + + + + + + + + {children} + + + + + + ); diff --git a/providers/one-config.tsx b/providers/one-config.tsx new file mode 100644 index 000000000..4739b9425 --- /dev/null +++ b/providers/one-config.tsx @@ -0,0 +1,34 @@ +import { PropsWithChildren, useContext, createContext } from 'react'; +import invariant from 'tiny-invariant'; + +import getConfig from 'next/config'; +const { serverRuntimeConfig } = getConfig(); + +import { dynamics } from 'config'; + +export const OneConfigContext = createContext(null); + +export const getOneConfig = () => { + return { + ...dynamics, + ...serverRuntimeConfig, + isClientSide: typeof window !== 'undefined', + }; +}; + +export const useOneConfig = () => { + const context = useContext(OneConfigContext); + invariant(context, 'Attempt to use `one config` outside of provider'); + return context; +}; + +export const OneConfigProvider = ({ children }: PropsWithChildren) => { + // TODO: check object destructuring is fast or use memo? + const contextValue = getOneConfig(); + + return ( + + {children} + + ); +}; diff --git a/utils/isClientSide.ts b/utils/isClientSide.ts index 52ecb6f66..6706cb60e 100644 --- a/utils/isClientSide.ts +++ b/utils/isClientSide.ts @@ -1,3 +1,4 @@ +/* Deprecated: see one-config */ export const isClientSide = () => { return typeof window !== 'undefined'; }; From 47832d662083a503601114a559bee52d793bc6a9 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Tue, 20 Feb 2024 15:37:59 +0300 Subject: [PATCH 02/48] refactor: intermediate commit (config --> consts) --- config/estimate.ts | 4 ++++ config/index.ts | 9 --------- config/ipfs.ts | 2 ++ config/rateLimit.ts | 1 + config/rpc.ts | 1 + config/stake.ts | 6 ++++++ config/types.ts | 1 + config/units.ts | 3 --- {config => consts}/aggregator.ts | 0 {config => consts}/api.ts | 3 --- {config => consts}/external-links.ts | 0 .../matomo-click-events.ts | 0 .../matomo-wallets-events.ts | 0 {config => consts}/metrics.ts | 0 {config => consts}/storage.ts | 2 +- {config => consts}/text.ts | 0 {config => consts}/tx.ts | 0 {config => consts}/urls.ts | 0 features/ipfs/home-page-ipfs.tsx | 2 +- .../rpc-availability-check-result-box.tsx | 2 +- .../rewards/components/CurrencySelector.tsx | 2 +- .../errorBlocks/ErrorBlockNoSteth.tsx | 2 +- features/stake/lido-stats/lido-stats-item.tsx | 2 +- features/stake/lido-stats/lido-stats.tsx | 8 +++----- .../stake-faq/list/how-can-i-get-steth.tsx | 6 +++--- .../stake-faq/list/how-can-i-unstake-steth.tsx | 6 +++--- .../stake-faq/list/how-can-i-use-steth.tsx | 2 +- features/stake/stake-faq/list/lido-eth-apr.tsx | 2 +- features/stake/stake-faq/list/lido-fee.tsx | 3 ++- .../list/risks-of-staking-with-lido.tsx | 2 +- .../stake-faq/list/safe-work-with-lido.tsx | 2 +- .../list/where-can-i-cover-my-steth.tsx | 2 +- features/stake/stake-form/stake-form-info.tsx | 8 ++++---- features/stake/stake-form/wallet/wallet.tsx | 12 +++++++----- .../swap-discount-banner.tsx | 10 +++++----- .../claim/tx-modal/tx-claim-modal.tsx | 6 ++---- .../controls/token-amount-input-request.tsx | 6 ++---- .../request/form/options/dex-options.tsx | 17 ++++++++--------- .../request/form/options/lido-option.tsx | 6 ++---- .../request/form/options/options-picker.tsx | 13 ++++++------- .../tx-modal/tx-request-stage-success.tsx | 10 ++++------ .../request/wallet/wallet-queue-tooltip.tsx | 8 +++----- .../wallet-my-requests/wallet-my-requests.tsx | 4 ++-- .../withdrawals-faq/list/add-nft.tsx | 4 ++-- .../list/convert-steth-to-eth.tsx | 2 +- .../list/convert-wsteth-to-eth.tsx | 2 +- .../list/how-long-to-withdraw.tsx | 2 +- .../withdrawals-faq/list/how-to-withdraw.tsx | 2 +- .../withdrawals-faq/list/separate-claim.tsx | 2 +- .../withdrawals-faq/list/what-is-slashing.tsx | 2 +- features/withdrawals/withdrawals-tabs.tsx | 2 +- .../list/do_i_need_to_unwrap_my_wsteth.tsx | 6 +++--- .../wrap-faq/list/how-can-i-get-wsteth.tsx | 6 +++--- .../wrap-faq/list/how-can-i-use-wsteth.tsx | 2 +- .../list/how-could-i-unwrap-wsteth-to-steth.tsx | 6 +++--- .../wsteth/unwrap/hooks/use-unwrap-gas-limit.ts | 3 ++- .../wsteth/unwrap/unwrap-form/unwrap-form.tsx | 6 +++--- features/wsteth/wrap-unwrap-tabs.tsx | 2 +- .../wsteth/wrap/hooks/use-approve-gas-limit.tsx | 12 +++++------- .../wsteth/wrap/hooks/use-wrap-gas-limit.ts | 6 +++--- .../wrap-form-controls/token-select-wrap.tsx | 2 +- features/wsteth/wrap/wrap-form/wrap-form.tsx | 2 +- pages/api/eth-apr.ts | 3 ++- pages/api/eth-price.ts | 5 +++-- pages/api/ldo-stats.ts | 4 +++- pages/api/lido-stats.ts | 4 +++- pages/api/lidostats.ts | 3 ++- pages/api/metrics.ts | 2 +- pages/api/oneinch-rate.ts | 7 ++----- pages/api/rewards.ts | 3 ++- pages/api/rpc.ts | 4 +++- pages/api/short-lido-stats.ts | 7 ++----- pages/api/sma-steth-apr.ts | 7 ++----- pages/api/totalsupply.ts | 2 +- providers/client-config.tsx | 2 +- providers/ipfs-info-box-statuses.tsx | 7 +++---- providers/modals.tsx | 5 +++-- providers/one-config.tsx | 12 +++++++++--- shared/banners/curve/curve.tsx | 4 +++- shared/banners/l2-low-fee/l2-low-fee.tsx | 2 +- shared/banners/l2-wsteth/l2-wsteth.tsx | 6 ++++-- .../modal-pool-banners/modal-pool-banners.tsx | 2 +- .../components/header-settings-button.tsx | 2 +- .../header/components/navigation/navigation.tsx | 2 +- shared/components/matomo-link/matomo-link.tsx | 6 +++++- shared/formatters/format-price.tsx | 3 ++- shared/hooks/use-router-path.ts | 2 +- shared/hooks/useLidoStats.ts | 3 ++- shared/hooks/useMatomoEventHandle.ts | 5 ++++- shared/wallet/connect/connect.tsx | 3 ++- test/pages/widget.page.ts | 2 +- .../track-matomo-event.ts | 6 ++---- utilsApi/contractAddressesMetricsMap.ts | 9 ++++++--- utilsApi/fetchRPC.ts | 2 +- utilsApi/getLdoStats.ts | 2 +- utilsApi/getLidoStats.ts | 5 +++-- utilsApi/getStEthPrice.ts | 8 +++++--- utilsApi/getTotalStaked.ts | 6 ++++-- utilsApi/metrics/metrics.ts | 7 +++++-- utilsApi/metrics/request.ts | 2 +- utilsApi/metrics/subgraph.ts | 2 +- utilsApi/rpcProviders.ts | 3 ++- 102 files changed, 218 insertions(+), 199 deletions(-) delete mode 100644 config/units.ts rename {config => consts}/aggregator.ts (100%) rename {config => consts}/api.ts (85%) rename {config => consts}/external-links.ts (100%) rename config/matomoClickEvents.ts => consts/matomo-click-events.ts (100%) rename config/matomoWalletsEvents.ts => consts/matomo-wallets-events.ts (100%) rename {config => consts}/metrics.ts (100%) rename {config => consts}/storage.ts (77%) rename {config => consts}/text.ts (100%) rename {config => consts}/tx.ts (100%) rename {config => consts}/urls.ts (100%) rename config/trackMatomoEvent.ts => utils/track-matomo-event.ts (72%) diff --git a/config/estimate.ts b/config/estimate.ts index 6a6158438..f83c2ab42 100644 --- a/config/estimate.ts +++ b/config/estimate.ts @@ -2,9 +2,13 @@ import { parseEther } from '@ethersproject/units'; // account for gas estimation // will always have >=0.001 ether, >=0.001 stETH, >=0.001 wstETH // on Mainnet, Goerli, Holesky +// TODO: move to OneConfig export const ESTIMATE_ACCOUNT = '0x87c0e047F4e4D3e289A56a36570D4CB957A37Ef1'; + +// TODO: const export const ESTIMATE_AMOUNT = parseEther('0.001'); +// TODO: TO CONFIG/WITHDRAWAL_QUEUE_ESTIMATE.TS // fallback gas limits per 1 withdraw request export const WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT = 255350; export const WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT = 312626; diff --git a/config/index.ts b/config/index.ts index 43bc74858..da5a53fdb 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,20 +1,11 @@ import getConfig from 'next/config'; export const { serverRuntimeConfig } = getConfig(); export { default as dynamics } from './dynamics'; -export * from './aggregator'; -export * from './api'; export * from './cache'; export * from './estimate'; export * from './locale'; export * from './ipfs'; -export * from './metrics'; export * from './rpc'; -export * from './storage'; -export * from './text'; -export * from './tx'; export * from './types'; -export * from './units'; -export * from './metrics'; export * from './rateLimit'; export * from './stake'; -export * from './matomoClickEvents'; diff --git a/config/ipfs.ts b/config/ipfs.ts index 5cc056718..85e28aa05 100644 --- a/config/ipfs.ts +++ b/config/ipfs.ts @@ -4,6 +4,8 @@ import dynamics from './dynamics'; const { serverRuntimeConfig } = getConfig(); const { basePath = '' } = serverRuntimeConfig; +// TODO: move to OneConfig export const BASE_PATH_ASSET = dynamics.ipfsMode ? '.' : basePath; +// TODO: move to OneConfig export const IPFS_REFERRAL_ADDRESS = '0x74d6e4Fd83A0b5623BDE3B2dF9a9A7F31fE02325'; diff --git a/config/rateLimit.ts b/config/rateLimit.ts index e0eb25c41..49cbc0639 100644 --- a/config/rateLimit.ts +++ b/config/rateLimit.ts @@ -2,6 +2,7 @@ import getConfig from 'next/config'; const { serverRuntimeConfig } = getConfig(); const { rateLimit, rateLimitTimeFrame } = serverRuntimeConfig; +// TODO: move to OneConfig // requests per RATE_LIMIT_TIME_FRAME export const RATE_LIMIT = rateLimit; export const RATE_LIMIT_TIME_FRAME = rateLimitTimeFrame; diff --git a/config/rpc.ts b/config/rpc.ts index 7782ecf16..2615591f0 100644 --- a/config/rpc.ts +++ b/config/rpc.ts @@ -7,6 +7,7 @@ import { CHAINS } from 'utils/chains'; import dynamics from './dynamics'; +// TODO: one config export const getBackendRPCPath = (chainId: string | number): string => { const BASE_URL = typeof window === 'undefined' ? '' : window.location.origin; return `${BASE_URL}/api/rpc?chainId=${chainId}`; diff --git a/config/stake.ts b/config/stake.ts index 58d1c8fb4..55bda9873 100644 --- a/config/stake.ts +++ b/config/stake.ts @@ -4,21 +4,27 @@ import dynamics from './dynamics'; import { IPFS_REFERRAL_ADDRESS } from './ipfs'; import { AddressZero } from '@ethersproject/constants'; +// TODO: const export const PRECISION = 10 ** 6; +// TODO: const // how much to leave out on user balance when max is pressed export const BALANCE_PADDING = parseEther('0.01'); +// TODO: const export const SUBMIT_EXTRA_GAS_TRANSACTION_RATIO = 1.05; +// TODO: const export const STETH_SUBMIT_GAS_LIMIT_DEFAULT = 90000; +// TODO: const export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( Math.floor( STETH_SUBMIT_GAS_LIMIT_DEFAULT * SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, ), ); +// TODO: move to OneConfig export const STAKE_FALLBACK_REFERRAL_ADDRESS = dynamics.ipfsMode ? IPFS_REFERRAL_ADDRESS : AddressZero; diff --git a/config/types.ts b/config/types.ts index 48c21d7bb..c9743953c 100644 --- a/config/types.ts +++ b/config/types.ts @@ -1,5 +1,6 @@ import { CHAINS } from 'utils/chains'; +// TODO: config/features/client-config/* export type EnvConfigRaw = { defaultChain: string | number; supportedChains: number[]; diff --git a/config/units.ts b/config/units.ts deleted file mode 100644 index 125b4f57d..000000000 --- a/config/units.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { BigNumber } from 'ethers'; - -export const ONE_GWEI = BigNumber.from(10 ** 9); diff --git a/config/aggregator.ts b/consts/aggregator.ts similarity index 100% rename from config/aggregator.ts rename to consts/aggregator.ts diff --git a/config/api.ts b/consts/api.ts similarity index 85% rename from config/api.ts rename to consts/api.ts index 149c1df35..2ef35cb79 100644 --- a/config/api.ts +++ b/consts/api.ts @@ -1,6 +1,3 @@ -export const DEFAULT_API_ERROR_MESSAGE = - 'Something went wrong. Sorry, try again later :('; - export const ETHPLORER_TOKEN_ENDPOINT = 'https://api.ethplorer.io/getTokenInfo/'; diff --git a/config/external-links.ts b/consts/external-links.ts similarity index 100% rename from config/external-links.ts rename to consts/external-links.ts diff --git a/config/matomoClickEvents.ts b/consts/matomo-click-events.ts similarity index 100% rename from config/matomoClickEvents.ts rename to consts/matomo-click-events.ts diff --git a/config/matomoWalletsEvents.ts b/consts/matomo-wallets-events.ts similarity index 100% rename from config/matomoWalletsEvents.ts rename to consts/matomo-wallets-events.ts diff --git a/config/metrics.ts b/consts/metrics.ts similarity index 100% rename from config/metrics.ts rename to consts/metrics.ts diff --git a/config/storage.ts b/consts/storage.ts similarity index 77% rename from config/storage.ts rename to consts/storage.ts index e853efb18..dca7f5bd5 100644 --- a/config/storage.ts +++ b/consts/storage.ts @@ -1,4 +1,4 @@ -export const STORAGE_TERMS_KEY = 'lido-terms-agree'; +// TODO: or move to OneConfig??? export const STORAGE_CURRENCY_KEY = 'lido-currency'; export const STORAGE_CLIENT_CONFIG = 'lido-client-config'; export const STORAGE_IPFS_INFO_DISMISS = 'lido-ipfs-info-dismiss'; diff --git a/config/text.ts b/consts/text.ts similarity index 100% rename from config/text.ts rename to consts/text.ts diff --git a/config/tx.ts b/consts/tx.ts similarity index 100% rename from config/tx.ts rename to consts/tx.ts diff --git a/config/urls.ts b/consts/urls.ts similarity index 100% rename from config/urls.ts rename to consts/urls.ts diff --git a/features/ipfs/home-page-ipfs.tsx b/features/ipfs/home-page-ipfs.tsx index 0c9a85fb2..692d67036 100644 --- a/features/ipfs/home-page-ipfs.tsx +++ b/features/ipfs/home-page-ipfs.tsx @@ -10,7 +10,7 @@ import { WITHDRAWALS_REQUEST_PATH, WRAP_PATH, REFERRAL_PATH, -} from 'config/urls'; +} from 'consts/urls'; import NoSSRWrapper from 'shared/components/no-ssr-wrapper'; import { usePrefixedReplace } from 'shared/hooks/use-prefixed-history'; diff --git a/features/ipfs/rpc-availability-check-result-box/rpc-availability-check-result-box.tsx b/features/ipfs/rpc-availability-check-result-box/rpc-availability-check-result-box.tsx index fa2488ac1..f23b73531 100644 --- a/features/ipfs/rpc-availability-check-result-box/rpc-availability-check-result-box.tsx +++ b/features/ipfs/rpc-availability-check-result-box/rpc-availability-check-result-box.tsx @@ -1,7 +1,7 @@ import { useCallback } from 'react'; import { Check, Close } from '@lidofinance/lido-ui'; -import { SETTINGS_PATH } from 'config/urls'; +import { SETTINGS_PATH } from 'consts/urls'; import { useIPFSInfoBoxStatuses } from 'providers/ipfs-info-box-statuses'; import { usePrefixedPush } from 'shared/hooks/use-prefixed-history'; import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; diff --git a/features/rewards/components/CurrencySelector.tsx b/features/rewards/components/CurrencySelector.tsx index 19e11ad6e..344e54031 100644 --- a/features/rewards/components/CurrencySelector.tsx +++ b/features/rewards/components/CurrencySelector.tsx @@ -3,8 +3,8 @@ import styled from 'styled-components'; import { Box, Select, Option } from '@lidofinance/lido-ui'; +import { STORAGE_CURRENCY_KEY } from 'consts/storage'; import { CURRENCIES, type CurrencyType } from 'features/rewards/constants'; -import { STORAGE_CURRENCY_KEY } from 'config'; const StyledSelect = styled(Select)` height: 32px; diff --git a/features/rewards/components/errorBlocks/ErrorBlockNoSteth.tsx b/features/rewards/components/errorBlocks/ErrorBlockNoSteth.tsx index c7f16f8f6..c847ff84d 100644 --- a/features/rewards/components/errorBlocks/ErrorBlockNoSteth.tsx +++ b/features/rewards/components/errorBlocks/ErrorBlockNoSteth.tsx @@ -1,5 +1,5 @@ import { Box, Button } from '@lidofinance/lido-ui'; -import { HOME_PATH } from 'config/urls'; +import { HOME_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; export const ErrorBlockNoSteth = () => ( diff --git a/features/stake/lido-stats/lido-stats-item.tsx b/features/stake/lido-stats/lido-stats-item.tsx index 76b67f4a8..78c9f856a 100644 --- a/features/stake/lido-stats/lido-stats-item.tsx +++ b/features/stake/lido-stats/lido-stats-item.tsx @@ -1,6 +1,6 @@ import { FC, memo, PropsWithChildren, ReactNode } from 'react'; import { DataTableRow } from '@lidofinance/lido-ui'; -import { DATA_UNAVAILABLE } from 'config'; +import { DATA_UNAVAILABLE } from 'consts/text'; type LidoStatsItemProps = { show: boolean; diff --git a/features/stake/lido-stats/lido-stats.tsx b/features/stake/lido-stats/lido-stats.tsx index 84211e3a7..5dcf69de3 100644 --- a/features/stake/lido-stats/lido-stats.tsx +++ b/features/stake/lido-stats/lido-stats.tsx @@ -7,11 +7,9 @@ import { Block, DataTable, Question, Tooltip } from '@lidofinance/lido-ui'; import { Section, MatomoLink } from 'shared/components'; import { useLidoApr, useLidoStats } from 'shared/hooks'; -import { - LIDO_APR_TOOLTIP_TEXT, - MATOMO_CLICK_EVENTS_TYPES, - dynamics, -} from 'config'; +import { dynamics } from 'config'; +import { LIDO_APR_TOOLTIP_TEXT } from 'consts/text'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; import { FlexCenterVertical } from './styles'; import { LidoStatsItem } from './lido-stats-item'; diff --git a/features/stake/stake-faq/list/how-can-i-get-steth.tsx b/features/stake/stake-faq/list/how-can-i-get-steth.tsx index 5d7f6ad71..48b9b33e0 100644 --- a/features/stake/stake-faq/list/how-can-i-get-steth.tsx +++ b/features/stake/stake-faq/list/how-can-i-get-steth.tsx @@ -1,9 +1,9 @@ import { FC } from 'react'; import { Accordion, Link as OuterLink } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; -import { trackMatomoEvent } from 'config/trackMatomoEvent'; -import { HOME_PATH } from 'config/urls'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; +import { HOME_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; export const HowCanIGetSteth: FC = () => { diff --git a/features/stake/stake-faq/list/how-can-i-unstake-steth.tsx b/features/stake/stake-faq/list/how-can-i-unstake-steth.tsx index ad1365c54..642c7dc9f 100644 --- a/features/stake/stake-faq/list/how-can-i-unstake-steth.tsx +++ b/features/stake/stake-faq/list/how-can-i-unstake-steth.tsx @@ -2,9 +2,9 @@ import { FC } from 'react'; import { Accordion, Link as OuterLink } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; -import { WITHDRAWALS_CLAIM_PATH } from 'config/urls'; -import { trackMatomoEvent } from 'config/trackMatomoEvent'; +import { WITHDRAWALS_CLAIM_PATH } from 'consts/urls'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { LocalLink } from 'shared/components/local-link'; export const HowCanIUnstakeSteth: FC = () => { diff --git a/features/stake/stake-faq/list/how-can-i-use-steth.tsx b/features/stake/stake-faq/list/how-can-i-use-steth.tsx index 64efd0805..c728f5eb9 100644 --- a/features/stake/stake-faq/list/how-can-i-use-steth.tsx +++ b/features/stake/stake-faq/list/how-can-i-use-steth.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const HowCanIUseSteth: FC = () => { return ( diff --git a/features/stake/stake-faq/list/lido-eth-apr.tsx b/features/stake/stake-faq/list/lido-eth-apr.tsx index d51ba8a1c..573cbbcb1 100644 --- a/features/stake/stake-faq/list/lido-eth-apr.tsx +++ b/features/stake/stake-faq/list/lido-eth-apr.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const LidoEthApr: FC = () => { return ( diff --git a/features/stake/stake-faq/list/lido-fee.tsx b/features/stake/stake-faq/list/lido-fee.tsx index 4f35579fc..afb74b737 100644 --- a/features/stake/stake-faq/list/lido-fee.tsx +++ b/features/stake/stake-faq/list/lido-fee.tsx @@ -1,7 +1,8 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; import { useContractSWR, useSTETHContractRPC } from '@lido-sdk/react'; -import { DATA_UNAVAILABLE } from 'config'; + +import { DATA_UNAVAILABLE } from 'consts/text'; export const LidoFee: FC = () => { const contractRpc = useSTETHContractRPC(); diff --git a/features/stake/stake-faq/list/risks-of-staking-with-lido.tsx b/features/stake/stake-faq/list/risks-of-staking-with-lido.tsx index f17cd9ea3..0302e8847 100644 --- a/features/stake/stake-faq/list/risks-of-staking-with-lido.tsx +++ b/features/stake/stake-faq/list/risks-of-staking-with-lido.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const RisksOfStakingWithLido: FC = () => { return ( diff --git a/features/stake/stake-faq/list/safe-work-with-lido.tsx b/features/stake/stake-faq/list/safe-work-with-lido.tsx index cbcb28f0b..700c298a7 100644 --- a/features/stake/stake-faq/list/safe-work-with-lido.tsx +++ b/features/stake/stake-faq/list/safe-work-with-lido.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const SafeWorkWithLido: FC = () => { return ( diff --git a/features/stake/stake-faq/list/where-can-i-cover-my-steth.tsx b/features/stake/stake-faq/list/where-can-i-cover-my-steth.tsx index 745b468a3..f8721e053 100644 --- a/features/stake/stake-faq/list/where-can-i-cover-my-steth.tsx +++ b/features/stake/stake-faq/list/where-can-i-cover-my-steth.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const WhereCanICoverMySteth: FC = () => { return ( diff --git a/features/stake/stake-form/stake-form-info.tsx b/features/stake/stake-form/stake-form-info.tsx index 33b41ebdb..588d3ebe3 100644 --- a/features/stake/stake-form/stake-form-info.tsx +++ b/features/stake/stake-form/stake-form-info.tsx @@ -1,16 +1,16 @@ -import { DataTable, DataTableRow } from '@lidofinance/lido-ui'; import { useWatch } from 'react-hook-form'; + +import { DataTable, DataTableRow } from '@lidofinance/lido-ui'; import { useContractSWR, useSTETHContractRPC } from '@lido-sdk/react'; import { Zero } from '@ethersproject/constants'; +import { DATA_UNAVAILABLE } from 'consts/text'; import { FormatPrice, FormatToken } from 'shared/formatters'; +import { useEthUsd } from 'shared/hooks/use-eth-usd'; import { STRATEGY_CONSTANT } from 'utils/swrStrategies'; -import { DATA_UNAVAILABLE } from 'config'; import { StakeFormInput, useStakeFormData } from './stake-form-context'; -import { useEthUsd } from 'shared/hooks/use-eth-usd'; - export const StakeFormInfo = () => { const { gasCost } = useStakeFormData(); const amount = useWatch({ name: 'amount' }); diff --git a/features/stake/stake-form/wallet/wallet.tsx b/features/stake/stake-form/wallet/wallet.tsx index fae06c391..ed134f146 100644 --- a/features/stake/stake-form/wallet/wallet.tsx +++ b/features/stake/stake-form/wallet/wallet.tsx @@ -1,19 +1,21 @@ +import { memo } from 'react'; +import { useWeb3 } from 'reef-knot/web3-react'; + import { TOKENS } from '@lido-sdk/constants'; import { useSDK, useSTETHBalance, useTokenAddress } from '@lido-sdk/react'; -import { useWeb3 } from 'reef-knot/web3-react'; import { Divider, Question, Tooltip } from '@lidofinance/lido-ui'; -import { LIDO_APR_TOOLTIP_TEXT } from 'config'; -import { memo } from 'react'; + +import { LIDO_APR_TOOLTIP_TEXT, DATA_UNAVAILABLE } from 'consts/text'; import { TokenToWallet } from 'shared/components'; import { FormatToken } from 'shared/formatters'; import { useLidoApr } from 'shared/hooks'; -import { DATA_UNAVAILABLE } from 'config'; import { CardAccount, CardBalance, CardRow, Fallback } from 'shared/wallet'; import type { WalletComponentType } from 'shared/wallet/types'; +import { STRATEGY_LAZY } from 'utils/swrStrategies'; + import { LimitMeter } from './limit-meter'; import { FlexCenter, LidoAprStyled, StyledCard } from './styles'; import { useStakeFormData } from '../stake-form-context'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; const WalletComponent: WalletComponentType = (props) => { const { account } = useSDK(); diff --git a/features/stake/swap-discount-banner/swap-discount-banner.tsx b/features/stake/swap-discount-banner/swap-discount-banner.tsx index d697abd50..866a5c154 100644 --- a/features/stake/swap-discount-banner/swap-discount-banner.tsx +++ b/features/stake/swap-discount-banner/swap-discount-banner.tsx @@ -1,13 +1,13 @@ +import { parseEther } from '@ethersproject/units'; +import { TOKENS } from '@lido-sdk/constants'; +import { useLidoSWR } from '@lido-sdk/react'; import { Button } from '@lidofinance/lido-ui'; import { trackEvent } from '@lidofinance/analytics-matomo'; -import { MATOMO_CLICK_EVENTS } from 'config'; -import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'config/external-links'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; +import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'consts/external-links'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { getOpenOceanRate } from 'utils/get-open-ocean-rate'; -import { parseEther } from '@ethersproject/units'; -import { TOKENS } from '@lido-sdk/constants'; -import { useLidoSWR } from '@lido-sdk/react'; import { enableQaHelpers } from 'utils'; import { Wrap, TextWrap, OpenOceanIcon, OverlayLink } from './styles'; diff --git a/features/withdrawals/claim/tx-modal/tx-claim-modal.tsx b/features/withdrawals/claim/tx-modal/tx-claim-modal.tsx index 0a4309d6a..1cdfbe3c4 100644 --- a/features/withdrawals/claim/tx-modal/tx-claim-modal.tsx +++ b/features/withdrawals/claim/tx-modal/tx-claim-modal.tsx @@ -1,6 +1,8 @@ import { useMemo } from 'react'; import { formatBalance } from 'utils'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { TxStageModal, TxStagePending, @@ -10,10 +12,6 @@ import { TxStageFail, } from 'features/withdrawals/shared/tx-stage-modal'; import { useTransactionModal, TX_STAGE } from 'shared/transaction-modal'; -import { - trackMatomoEvent, - MATOMO_CLICK_EVENTS_TYPES, -} from 'config/trackMatomoEvent'; import { withOptionaTooltip } from 'shared/components/tx-stage-modal/text-utils'; export const TxClaimModal = () => { diff --git a/features/withdrawals/request/form/controls/token-amount-input-request.tsx b/features/withdrawals/request/form/controls/token-amount-input-request.tsx index e0f4f2db0..7bdcefd82 100644 --- a/features/withdrawals/request/form/controls/token-amount-input-request.tsx +++ b/features/withdrawals/request/form/controls/token-amount-input-request.tsx @@ -1,9 +1,7 @@ import { useController, useWatch } from 'react-hook-form'; -import { - MATOMO_CLICK_EVENTS_TYPES, - trackMatomoEvent, -} from 'config/trackMatomoEvent'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { TokenAmountInputHookForm } from 'shared/hook-form/controls/token-amount-input-hook-form'; import { InputDecoratorTvlStake } from 'features/withdrawals/shared/input-decorator-tvl-stake'; import { diff --git a/features/withdrawals/request/form/options/dex-options.tsx b/features/withdrawals/request/form/options/dex-options.tsx index d69f9960f..1dff24b7d 100644 --- a/features/withdrawals/request/form/options/dex-options.tsx +++ b/features/withdrawals/request/form/options/dex-options.tsx @@ -1,14 +1,17 @@ import { BigNumber } from 'ethers'; +import { useMemo } from 'react'; + +import { formatEther } from '@ethersproject/units'; import { CHAINS, getTokenAddress, TOKENS } from '@lido-sdk/constants'; -import { useMemo } from 'react'; +// @ts-expect-error https://www.npmjs.com/package/@svgr/webpack +import { ReactComponent as AttentionTriangle } from 'assets/icons/attention-triangle.svg'; +import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'consts/external-links'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; import { useWithdrawalRates } from 'features/withdrawals/hooks/useWithdrawalRates'; import { FormatToken } from 'shared/formatters/format-token'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; -import { - trackMatomoEvent, - MATOMO_CLICK_EVENTS_TYPES, -} from 'config/trackMatomoEvent'; import { DexOptionBlockLink, DexOptionBlockTitle, @@ -21,10 +24,6 @@ import { ParaSwapIcon, DexWarning, } from './styles'; -import { formatEther } from '@ethersproject/units'; -import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'config/external-links'; -// @ts-expect-error https://www.npmjs.com/package/@svgr/webpack -import { ReactComponent as AttentionTriangle } from 'assets/icons/attention-triangle.svg'; const placeholder = Array.from({ length: 1 }).fill(null); diff --git a/features/withdrawals/request/form/options/lido-option.tsx b/features/withdrawals/request/form/options/lido-option.tsx index 8fd331301..e9c824a97 100644 --- a/features/withdrawals/request/form/options/lido-option.tsx +++ b/features/withdrawals/request/form/options/lido-option.tsx @@ -7,10 +7,8 @@ import { useEthAmountByStethWsteth } from 'features/withdrawals/hooks'; import { useInpageNavigation } from 'providers/inpage-navigation'; import { RequestFormInputType } from 'features/withdrawals/request/request-form-context'; -import { - trackMatomoEvent, - MATOMO_CLICK_EVENTS_TYPES, -} from 'config/trackMatomoEvent'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { FormatTokenStyled, diff --git a/features/withdrawals/request/form/options/options-picker.tsx b/features/withdrawals/request/form/options/options-picker.tsx index 7719f6f7a..2c6b8fdbd 100644 --- a/features/withdrawals/request/form/options/options-picker.tsx +++ b/features/withdrawals/request/form/options/options-picker.tsx @@ -1,9 +1,15 @@ +import { useWatch } from 'react-hook-form'; import { formatEther, parseEther } from '@ethersproject/units'; +import { TOKENS } from '@lido-sdk/constants'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; + +import { RequestFormInputType } from 'features/withdrawals/request/request-form-context'; import { useWaitingTime } from 'features/withdrawals/hooks/useWaitingTime'; import { useWithdrawalRates } from 'features/withdrawals/hooks/useWithdrawalRates'; import { useWstethToStethRatio } from 'shared/components/data-table-row-steth-by-wsteth'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { formatBalance } from 'utils/formatBalance'; import { @@ -18,13 +24,6 @@ import { OpenOceanIcon, ParaSwapIcon, } from './styles'; -import { - trackMatomoEvent, - MATOMO_CLICK_EVENTS_TYPES, -} from 'config/trackMatomoEvent'; -import { useWatch } from 'react-hook-form'; -import { RequestFormInputType } from 'features/withdrawals/request/request-form-context'; -import { TOKENS } from '@lido-sdk/constants'; type OptionButtonProps = { onClick: React.ComponentProps<'button'>['onClick']; diff --git a/features/withdrawals/request/tx-modal/tx-request-stage-success.tsx b/features/withdrawals/request/tx-modal/tx-request-stage-success.tsx index 5bd0e4380..bcbd97861 100644 --- a/features/withdrawals/request/tx-modal/tx-request-stage-success.tsx +++ b/features/withdrawals/request/tx-modal/tx-request-stage-success.tsx @@ -1,15 +1,13 @@ import { useSDK } from '@lido-sdk/react'; import { Link, Loader } from '@lidofinance/lido-ui'; -import { LocalLink } from 'shared/components/local-link'; -import { - trackMatomoEvent, - MATOMO_CLICK_EVENTS_TYPES, -} from 'config/trackMatomoEvent'; -import { WITHDRAWALS_CLAIM_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH } from 'consts/urls'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { useNftDataByTxHash } from 'features/withdrawals/hooks/useNftDataByTxHash'; import { TxStageSuccess } from 'features/withdrawals/shared/tx-stage-modal'; import { TxLinkEtherscan } from 'shared/components/tx-link-etherscan'; +import { LocalLink } from 'shared/components/local-link'; import { Title, diff --git a/features/withdrawals/request/wallet/wallet-queue-tooltip.tsx b/features/withdrawals/request/wallet/wallet-queue-tooltip.tsx index 944de18dc..8ee5c1a3c 100644 --- a/features/withdrawals/request/wallet/wallet-queue-tooltip.tsx +++ b/features/withdrawals/request/wallet/wallet-queue-tooltip.tsx @@ -1,15 +1,13 @@ import { Question, Tooltip } from '@lidofinance/lido-ui'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; import { FormatToken } from 'shared/formatters'; import { useWaitingTime } from 'features/withdrawals/hooks'; +import { useInpageNavigation } from 'providers/inpage-navigation'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; -import { - trackMatomoEvent, - MATOMO_CLICK_EVENTS_TYPES, -} from 'config/trackMatomoEvent'; import { QueueInfoStyled, DataTableRowStyled } from './styles'; import { useRequestFormData } from '../request-form-context'; -import { useInpageNavigation } from 'providers/inpage-navigation'; export const WalletQueueTooltip = () => { const waitingTime = useWaitingTime(''); diff --git a/features/withdrawals/shared/wallet-my-requests/wallet-my-requests.tsx b/features/withdrawals/shared/wallet-my-requests/wallet-my-requests.tsx index 0021a209d..eeb8c5193 100644 --- a/features/withdrawals/shared/wallet-my-requests/wallet-my-requests.tsx +++ b/features/withdrawals/shared/wallet-my-requests/wallet-my-requests.tsx @@ -1,9 +1,9 @@ import { FC, PropsWithChildren } from 'react'; import { Tooltip, TimeSquare, TickSquare } from '@lidofinance/lido-ui'; -import { CardBalance } from 'shared/wallet'; +import { DATA_UNAVAILABLE } from 'consts/text'; import { useClaimData } from 'features/withdrawals/contexts/claim-data-context'; -import { DATA_UNAVAILABLE } from 'config'; +import { CardBalance } from 'shared/wallet'; import { RequestCounterStyled } from './styles'; diff --git a/features/withdrawals/withdrawals-faq/list/add-nft.tsx b/features/withdrawals/withdrawals-faq/list/add-nft.tsx index c98ca8ea8..fda4598dc 100644 --- a/features/withdrawals/withdrawals-faq/list/add-nft.tsx +++ b/features/withdrawals/withdrawals-faq/list/add-nft.tsx @@ -1,6 +1,6 @@ import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; -import { LINK_ADD_NFT_GUIDE } from 'config/external-links'; +import { LINK_ADD_NFT_GUIDE } from 'consts/external-links'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const HowToAddNFT = () => { return ( diff --git a/features/withdrawals/withdrawals-faq/list/convert-steth-to-eth.tsx b/features/withdrawals/withdrawals-faq/list/convert-steth-to-eth.tsx index 3456f62e1..ed1ac6115 100644 --- a/features/withdrawals/withdrawals-faq/list/convert-steth-to-eth.tsx +++ b/features/withdrawals/withdrawals-faq/list/convert-steth-to-eth.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; export const ConvertSTETHtoETH: FC = () => { diff --git a/features/withdrawals/withdrawals-faq/list/convert-wsteth-to-eth.tsx b/features/withdrawals/withdrawals-faq/list/convert-wsteth-to-eth.tsx index 7cd3f6a35..e84a927d3 100644 --- a/features/withdrawals/withdrawals-faq/list/convert-wsteth-to-eth.tsx +++ b/features/withdrawals/withdrawals-faq/list/convert-wsteth-to-eth.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; export const ConvertWSTETHtoETH: FC = () => { diff --git a/features/withdrawals/withdrawals-faq/list/how-long-to-withdraw.tsx b/features/withdrawals/withdrawals-faq/list/how-long-to-withdraw.tsx index 639590851..340f081b0 100644 --- a/features/withdrawals/withdrawals-faq/list/how-long-to-withdraw.tsx +++ b/features/withdrawals/withdrawals-faq/list/how-long-to-withdraw.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { WITHDRAWALS_CLAIM_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; import { NoBr } from '../styles'; diff --git a/features/withdrawals/withdrawals-faq/list/how-to-withdraw.tsx b/features/withdrawals/withdrawals-faq/list/how-to-withdraw.tsx index 4241871d6..679af625a 100644 --- a/features/withdrawals/withdrawals-faq/list/how-to-withdraw.tsx +++ b/features/withdrawals/withdrawals-faq/list/how-to-withdraw.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; export const HowToWithdraw: FC = () => { diff --git a/features/withdrawals/withdrawals-faq/list/separate-claim.tsx b/features/withdrawals/withdrawals-faq/list/separate-claim.tsx index e4e588a3f..fdf21768f 100644 --- a/features/withdrawals/withdrawals-faq/list/separate-claim.tsx +++ b/features/withdrawals/withdrawals-faq/list/separate-claim.tsx @@ -1,7 +1,7 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { WITHDRAWALS_CLAIM_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; export const SeparateClaim: FC = () => { diff --git a/features/withdrawals/withdrawals-faq/list/what-is-slashing.tsx b/features/withdrawals/withdrawals-faq/list/what-is-slashing.tsx index 6317d819c..6574756a5 100644 --- a/features/withdrawals/withdrawals-faq/list/what-is-slashing.tsx +++ b/features/withdrawals/withdrawals-faq/list/what-is-slashing.tsx @@ -1,5 +1,5 @@ import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; const PENALTIES_INFO_LINK = 'https://help.lido.fi/en/articles/5232780-what-are-staking-validator-penalties'; diff --git a/features/withdrawals/withdrawals-tabs.tsx b/features/withdrawals/withdrawals-tabs.tsx index 5011b0a03..ec511268b 100644 --- a/features/withdrawals/withdrawals-tabs.tsx +++ b/features/withdrawals/withdrawals-tabs.tsx @@ -1,6 +1,6 @@ import { Switch } from 'shared/components'; -import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'config/urls'; +import { WITHDRAWALS_CLAIM_PATH, WITHDRAWALS_REQUEST_PATH } from 'consts/urls'; import { ClaimDataProvider } from './contexts/claim-data-context'; import { useWithdrawals } from './contexts/withdrawals-context'; diff --git a/features/wsteth/shared/wrap-faq/list/do_i_need_to_unwrap_my_wsteth.tsx b/features/wsteth/shared/wrap-faq/list/do_i_need_to_unwrap_my_wsteth.tsx index 636a1fd30..a7439b4ca 100644 --- a/features/wsteth/shared/wrap-faq/list/do_i_need_to_unwrap_my_wsteth.tsx +++ b/features/wsteth/shared/wrap-faq/list/do_i_need_to_unwrap_my_wsteth.tsx @@ -1,10 +1,10 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; -import { WITHDRAWALS_REQUEST_PATH } from 'config/urls'; -import { trackMatomoEvent } from 'config/trackMatomoEvent'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { WITHDRAWALS_REQUEST_PATH } from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; export const DoINeedToUnwrapMyWsteth: FC = () => { return ( diff --git a/features/wsteth/shared/wrap-faq/list/how-can-i-get-wsteth.tsx b/features/wsteth/shared/wrap-faq/list/how-can-i-get-wsteth.tsx index 35362d0f6..9ad8752f4 100644 --- a/features/wsteth/shared/wrap-faq/list/how-can-i-get-wsteth.tsx +++ b/features/wsteth/shared/wrap-faq/list/how-can-i-get-wsteth.tsx @@ -1,9 +1,9 @@ import { FC } from 'react'; import { Accordion, Link as OuterLink } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; -import { WRAP_PATH } from 'config/urls'; -import { trackMatomoEvent } from 'config/trackMatomoEvent'; +import { WRAP_PATH } from 'consts/urls'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { LocalLink } from 'shared/components/local-link'; export const HowCanIGetWsteth: FC = () => { diff --git a/features/wsteth/shared/wrap-faq/list/how-can-i-use-wsteth.tsx b/features/wsteth/shared/wrap-faq/list/how-can-i-use-wsteth.tsx index c0b63fffd..e563deb1a 100644 --- a/features/wsteth/shared/wrap-faq/list/how-can-i-use-wsteth.tsx +++ b/features/wsteth/shared/wrap-faq/list/how-can-i-use-wsteth.tsx @@ -1,6 +1,6 @@ import { FC } from 'react'; import { Accordion, Link } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from '../../../../../config'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; export const HowCanIUseWsteth: FC = () => { return ( diff --git a/features/wsteth/shared/wrap-faq/list/how-could-i-unwrap-wsteth-to-steth.tsx b/features/wsteth/shared/wrap-faq/list/how-could-i-unwrap-wsteth-to-steth.tsx index 96ceb9cbb..b274c5514 100644 --- a/features/wsteth/shared/wrap-faq/list/how-could-i-unwrap-wsteth-to-steth.tsx +++ b/features/wsteth/shared/wrap-faq/list/how-could-i-unwrap-wsteth-to-steth.tsx @@ -1,9 +1,9 @@ import { FC } from 'react'; import { Accordion } from '@lidofinance/lido-ui'; -import { MATOMO_CLICK_EVENTS_TYPES } from 'config'; -import { trackMatomoEvent } from 'config/trackMatomoEvent'; -import { WRAP_UNWRAP_PATH } from 'config/urls'; +import { WRAP_UNWRAP_PATH } from 'consts/urls'; +import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; +import { trackMatomoEvent } from 'utils/track-matomo-event'; import { LocalLink } from 'shared/components/local-link'; export const HowCouldIUnwrapWstethToSteth: FC = () => { diff --git a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts index 4aa9ff918..0bfc555db 100644 --- a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts +++ b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts @@ -1,5 +1,6 @@ import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; -import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT, UNWRAP_GAS_LIMIT } from 'config'; +import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } from 'config/estimate'; +import { UNWRAP_GAS_LIMIT } from 'consts/tx'; import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; diff --git a/features/wsteth/unwrap/unwrap-form/unwrap-form.tsx b/features/wsteth/unwrap/unwrap-form/unwrap-form.tsx index 16d8c6137..b431c6e97 100644 --- a/features/wsteth/unwrap/unwrap-form/unwrap-form.tsx +++ b/features/wsteth/unwrap/unwrap-form/unwrap-form.tsx @@ -1,16 +1,16 @@ import { memo, FC } from 'react'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { L2Wsteth } from 'shared/banners/l2-wsteth'; +import { FormController } from 'shared/hook-form/form-controller/form-controller'; +import { TransactionModalProvider } from 'shared/transaction-modal'; import { InputWrap, WrapBlock } from 'features/wsteth/shared/styles'; import { UnwrapStats } from './unwrap-stats'; import { UnwrapFormTxModal } from './unwrap-form-tx-modal'; -import { TransactionModalProvider } from 'shared/transaction-modal'; import { UnwrapFormProvider } from '../unwrap-form-context'; -import { FormController } from 'shared/hook-form/form-controller/form-controller'; import { TokenAmountInputUnwrap } from '../unwrap-form-controls/amount-input-unwrap'; import { SubmitButtonUnwrap } from '../unwrap-form-controls/submit-button-unwrap'; -import { MATOMO_CLICK_EVENTS } from 'config'; export const UnwrapForm: FC = memo(() => { return ( diff --git a/features/wsteth/wrap-unwrap-tabs.tsx b/features/wsteth/wrap-unwrap-tabs.tsx index 002fd1443..82d7cceff 100644 --- a/features/wsteth/wrap-unwrap-tabs.tsx +++ b/features/wsteth/wrap-unwrap-tabs.tsx @@ -1,4 +1,4 @@ -import { WRAP_PATH, WRAP_UNWRAP_PATH } from 'config/urls'; +import { WRAP_PATH, WRAP_UNWRAP_PATH } from 'consts/urls'; import { Wallet } from 'features/wsteth/shared/wallet'; import { WrapForm } from 'features/wsteth/wrap/wrap-form/wrap-form'; import { Switch } from 'shared/components/switch'; diff --git a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx index 27340672b..2750d392d 100644 --- a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx +++ b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx @@ -1,15 +1,13 @@ +import { BigNumber } from 'ethers'; +import { useWeb3 } from 'reef-knot/web3-react'; import { useLidoSWR, useSTETHContractRPC, useWSTETHContractRPC, } from '@lido-sdk/react'; -import { useWeb3 } from 'reef-knot/web3-react'; -import { - ESTIMATE_ACCOUNT, - ESTIMATE_AMOUNT, - WSTETH_APPROVE_GAS_LIMIT, -} from 'config'; -import { BigNumber } from 'ethers'; + +import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } from 'config/estimate'; +import { WSTETH_APPROVE_GAS_LIMIT } from 'consts/tx'; import { STRATEGY_IMMUTABLE } from 'utils/swrStrategies'; export const useApproveGasLimit = () => { diff --git a/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts b/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts index b63811fd1..7bad9f757 100644 --- a/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts +++ b/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts @@ -2,13 +2,13 @@ import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; import { useWeb3 } from 'reef-knot/web3-react'; import { CHAINS } from '@lido-sdk/constants'; +import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } from 'config/estimate'; import { - ESTIMATE_ACCOUNT, - ESTIMATE_AMOUNT, WRAP_FROM_ETH_GAS_LIMIT, WRAP_GAS_LIMIT, WRAP_GAS_LIMIT_GOERLI, -} from 'config'; +} from 'consts/tx'; + import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; import { applyGasLimitRatio } from 'features/stake/stake-form/utils'; diff --git a/features/wsteth/wrap/wrap-form-controls/token-select-wrap.tsx b/features/wsteth/wrap/wrap-form-controls/token-select-wrap.tsx index 0e5fb68ee..aede6fe1e 100644 --- a/features/wsteth/wrap/wrap-form-controls/token-select-wrap.tsx +++ b/features/wsteth/wrap/wrap-form-controls/token-select-wrap.tsx @@ -1,6 +1,6 @@ import { trackEvent } from '@lidofinance/analytics-matomo'; import { TOKENS_TO_WRAP } from 'features/wsteth/shared/types'; -import { MATOMO_CLICK_EVENTS } from 'config'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { TokenSelectHookForm } from 'shared/hook-form/controls/token-select-hook-form'; const OPTIONS = [ diff --git a/features/wsteth/wrap/wrap-form/wrap-form.tsx b/features/wsteth/wrap/wrap-form/wrap-form.tsx index c37634888..da66514fe 100644 --- a/features/wsteth/wrap/wrap-form/wrap-form.tsx +++ b/features/wsteth/wrap/wrap-form/wrap-form.tsx @@ -12,7 +12,7 @@ import { SubmitButtonWrap } from '../wrap-form-controls/submit-button-wrap'; import { TransactionModalProvider } from 'shared/transaction-modal/transaction-modal-context'; import { InputGroupHookForm } from 'shared/hook-form/controls/input-group-hook-form'; import { L2Wsteth } from 'shared/banners/l2-wsteth'; -import { MATOMO_CLICK_EVENTS } from 'config'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; export const WrapForm: React.FC = memo(() => { return ( diff --git a/pages/api/eth-apr.ts b/pages/api/eth-apr.ts index b9dcb979c..8693a061c 100644 --- a/pages/api/eth-apr.ts +++ b/pages/api/eth-apr.ts @@ -1,6 +1,7 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_ETH_APR_KEY, CACHE_ETH_APR_TTL, API_ROUTES } from 'config'; +import { CACHE_ETH_APR_KEY, CACHE_ETH_APR_TTL } from 'config/cache'; +import { API_ROUTES } from 'consts/api'; import { getEthApr, errorAndCacheDefaultWrappers, diff --git a/pages/api/eth-price.ts b/pages/api/eth-price.ts index dae04ebca..4908b57a1 100644 --- a/pages/api/eth-price.ts +++ b/pages/api/eth-price.ts @@ -3,12 +3,13 @@ import { wrapRequest as wrapNextRequest, cacheControl, } from '@lidofinance/next-api-wrapper'; + import { CACHE_ETH_PRICE_KEY, CACHE_ETH_PRICE_TTL, CACHE_ETH_PRICE_HEADERS, - API_ROUTES, -} from 'config'; +} from 'config/cache'; +import { API_ROUTES } from 'consts/api'; import { getEthPrice, defaultErrorHandler, diff --git a/pages/api/ldo-stats.ts b/pages/api/ldo-stats.ts index 38031b314..f0e2b1860 100644 --- a/pages/api/ldo-stats.ts +++ b/pages/api/ldo-stats.ts @@ -1,6 +1,8 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LDO_STATS_KEY, CACHE_LDO_STATS_TTL, API_ROUTES } from 'config'; + +import { CACHE_LDO_STATS_KEY, CACHE_LDO_STATS_TTL } from 'config/cache'; +import { API_ROUTES } from 'consts/api'; import { getLdoStats, errorAndCacheDefaultWrappers, diff --git a/pages/api/lido-stats.ts b/pages/api/lido-stats.ts index 3e04ba299..9b64b4968 100644 --- a/pages/api/lido-stats.ts +++ b/pages/api/lido-stats.ts @@ -1,6 +1,8 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL, API_ROUTES } from 'config'; +import { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } from 'config/cache'; + +import { API_ROUTES } from 'consts/api'; import { getLidoStats, errorAndCacheDefaultWrappers, diff --git a/pages/api/lidostats.ts b/pages/api/lidostats.ts index 4953fcd68..777a9427c 100644 --- a/pages/api/lidostats.ts +++ b/pages/api/lidostats.ts @@ -1,6 +1,7 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL, API_ROUTES } from 'config'; +import { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } from 'config'; +import { API_ROUTES } from 'consts/api'; import { getLidoStats, responseTimeMetric, diff --git a/pages/api/metrics.ts b/pages/api/metrics.ts index 26968d9d2..44913d34a 100644 --- a/pages/api/metrics.ts +++ b/pages/api/metrics.ts @@ -1,5 +1,5 @@ import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { API_ROUTES } from 'config'; +import { API_ROUTES } from 'consts/api'; import { responseTimeMetric, errorAndCacheDefaultWrappers, diff --git a/pages/api/oneinch-rate.ts b/pages/api/oneinch-rate.ts index b727ec320..2602d1b22 100644 --- a/pages/api/oneinch-rate.ts +++ b/pages/api/oneinch-rate.ts @@ -5,11 +5,8 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; import { CHAINS, TOKENS, getTokenAddress } from '@lido-sdk/constants'; -import { - CACHE_ONE_INCH_RATE_KEY, - CACHE_ONE_INCH_RATE_TTL, - API_ROUTES, -} from 'config'; +import { CACHE_ONE_INCH_RATE_KEY, CACHE_ONE_INCH_RATE_TTL } from 'config'; +import { API_ROUTES } from 'consts/api'; import { getOneInchRate, responseTimeMetric, diff --git a/pages/api/rewards.ts b/pages/api/rewards.ts index abfaed6a9..6b4b6e9d9 100644 --- a/pages/api/rewards.ts +++ b/pages/api/rewards.ts @@ -13,7 +13,8 @@ import { cors, } from 'utilsApi'; import Metrics from 'utilsApi/metrics'; -import { CACHE_REWARDS_HEADERS, API_ROUTES } from 'config'; +import { CACHE_REWARDS_HEADERS } from 'config/cache'; +import { API_ROUTES } from 'consts/api'; import { API } from 'types'; import { standardFetcher } from 'utils/standardFetcher'; diff --git a/pages/api/rpc.ts b/pages/api/rpc.ts index 0655d14b0..ef6a624af 100644 --- a/pages/api/rpc.ts +++ b/pages/api/rpc.ts @@ -1,6 +1,8 @@ import { rpcFactory } from '@lidofinance/next-pages'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { dynamics, METRICS_PREFIX, API_ROUTES } from 'config'; +import { dynamics } from 'config'; +import { API_ROUTES } from 'consts/api'; +import { METRICS_PREFIX } from 'consts/metrics'; import { fetchRPC, rateLimit, diff --git a/pages/api/short-lido-stats.ts b/pages/api/short-lido-stats.ts index 37de0a089..75888080f 100644 --- a/pages/api/short-lido-stats.ts +++ b/pages/api/short-lido-stats.ts @@ -2,11 +2,8 @@ import getConfig from 'next/config'; import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { - API_ROUTES, - CACHE_LIDO_SHORT_STATS_KEY, - CACHE_LIDO_SHORT_STATS_TTL, -} from 'config'; +import { CACHE_LIDO_SHORT_STATS_KEY, CACHE_LIDO_SHORT_STATS_TTL } from 'config'; +import { API_ROUTES } from 'consts/api'; import { API, SubgraphChains } from 'types'; import { cors, diff --git a/pages/api/sma-steth-apr.ts b/pages/api/sma-steth-apr.ts index 9a71bbf27..0323f8e9b 100644 --- a/pages/api/sma-steth-apr.ts +++ b/pages/api/sma-steth-apr.ts @@ -1,11 +1,8 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; import { API } from 'types'; -import { - CACHE_SMA_STETH_APR_KEY, - CACHE_SMA_STETH_APR_TTL, - API_ROUTES, -} from 'config'; +import { CACHE_SMA_STETH_APR_KEY, CACHE_SMA_STETH_APR_TTL } from 'config'; +import { API_ROUTES } from 'consts/api'; import { responseTimeMetric, errorAndCacheDefaultWrappers, diff --git a/pages/api/totalsupply.ts b/pages/api/totalsupply.ts index 83e8b3fed..5acad8bd0 100644 --- a/pages/api/totalsupply.ts +++ b/pages/api/totalsupply.ts @@ -7,8 +7,8 @@ import { CACHE_TOTAL_SUPPLY_KEY, CACHE_TOTAL_SUPPLY_TTL, CACHE_TOTAL_SUPPLY_HEADERS, - API_ROUTES, } from 'config'; +import { API_ROUTES } from 'consts/api'; import { getTotalStaked, defaultErrorHandler, diff --git a/providers/client-config.tsx b/providers/client-config.tsx index f5e40f737..6de132ee3 100644 --- a/providers/client-config.tsx +++ b/providers/client-config.tsx @@ -11,8 +11,8 @@ import invariant from 'tiny-invariant'; import { useLocalStorage } from '@lido-sdk/react'; import { dynamics } from 'config'; -import { STORAGE_CLIENT_CONFIG } from 'config/storage'; import { EnvConfigParsed } from 'config/types'; +import { STORAGE_CLIENT_CONFIG } from 'consts/storage'; import { CHAINS } from 'utils/chains'; import { parseEnvConfig } from 'utils/parse-env-config'; diff --git a/providers/ipfs-info-box-statuses.tsx b/providers/ipfs-info-box-statuses.tsx index 59fd51260..23dd21f6d 100644 --- a/providers/ipfs-info-box-statuses.tsx +++ b/providers/ipfs-info-box-statuses.tsx @@ -9,13 +9,12 @@ import { import { useLidoSWR, useLocalStorage, useSDK } from '@lido-sdk/react'; import invariant from 'tiny-invariant'; -import { useCSPViolation } from 'features/ipfs/csp-violation-box/use-csp-violation'; import { useRpcUrl } from 'config/rpc'; -import { STORAGE_IPFS_INFO_DISMISS } from 'config/storage'; -import { SETTINGS_PATH } from 'config/urls'; +import { STORAGE_IPFS_INFO_DISMISS } from 'consts/storage'; +import { SETTINGS_PATH } from 'consts/urls'; +import { useCSPViolation } from 'features/ipfs/csp-violation-box/use-csp-violation'; import { useRouterPath } from 'shared/hooks/use-router-path'; - import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { checkRpcUrl } from 'utils/check-rpc-url'; diff --git a/providers/modals.tsx b/providers/modals.tsx index cac3194c7..77684accc 100644 --- a/providers/modals.tsx +++ b/providers/modals.tsx @@ -7,10 +7,11 @@ import { useState, FC, } from 'react'; +import { WalletsModalForEth } from 'reef-knot/connect-wallet-modal'; import { useThemeToggle } from '@lidofinance/lido-ui'; + +import { walletsMetrics } from 'consts/matomo-wallets-events'; import { Modal } from 'shared/wallet'; -import { WalletsModalForEth } from 'reef-knot/connect-wallet-modal'; -import { walletsMetrics } from 'config/matomoWalletsEvents'; export type ModalContextValue = { openModal: (modal: MODAL) => void; diff --git a/providers/one-config.tsx b/providers/one-config.tsx index 4739b9425..619f07455 100644 --- a/providers/one-config.tsx +++ b/providers/one-config.tsx @@ -9,10 +9,16 @@ import { dynamics } from 'config'; export const OneConfigContext = createContext(null); export const getOneConfig = () => { + const isClientSide = typeof window !== 'undefined'; + const isServerSide = typeof window === 'undefined'; + return { - ...dynamics, - ...serverRuntimeConfig, - isClientSide: typeof window !== 'undefined', + isClientSide, + isServerSide, + // ...dynamics, + ...(isClientSide && dynamics), + // ...serverRuntimeConfig, + ...(isServerSide && serverRuntimeConfig && { env: process.env }), }; }; diff --git a/shared/banners/curve/curve.tsx b/shared/banners/curve/curve.tsx index 8a731e39f..93fb7ac7c 100644 --- a/shared/banners/curve/curve.tsx +++ b/shared/banners/curve/curve.tsx @@ -1,7 +1,9 @@ import { FC } from 'react'; import { Button, InlineLoader } from '@lidofinance/lido-ui'; import { trackEvent } from '@lidofinance/analytics-matomo'; -import { MATOMO_CLICK_EVENTS, DATA_UNAVAILABLE } from 'config'; + +import { DATA_UNAVAILABLE } from 'consts/text'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { Banner } from 'shared/components'; import { useCurve } from './useCurve'; diff --git a/shared/banners/l2-low-fee/l2-low-fee.tsx b/shared/banners/l2-low-fee/l2-low-fee.tsx index 88df2d7d6..e486affd8 100644 --- a/shared/banners/l2-low-fee/l2-low-fee.tsx +++ b/shared/banners/l2-low-fee/l2-low-fee.tsx @@ -1,6 +1,6 @@ import { useCallback } from 'react'; import { trackEvent } from '@lidofinance/analytics-matomo'; -import { MATOMO_CLICK_EVENTS } from 'config'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { L2Banner, L2_DISCOVERY_LINK } from '../l2-banner'; diff --git a/shared/banners/l2-wsteth/l2-wsteth.tsx b/shared/banners/l2-wsteth/l2-wsteth.tsx index d5ce1b19c..16eef92a9 100644 --- a/shared/banners/l2-wsteth/l2-wsteth.tsx +++ b/shared/banners/l2-wsteth/l2-wsteth.tsx @@ -1,8 +1,10 @@ import { useCallback } from 'react'; -import { L2Banner } from '../l2-banner'; -import { MATOMO_CLICK_EVENTS } from 'config'; import { trackEvent } from '@lidofinance/analytics-matomo'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; + +import { L2Banner } from '../l2-banner'; + type L2WstethProps = { matomoEventLink: | typeof MATOMO_CLICK_EVENTS.l2BannerWrap diff --git a/shared/banners/modal-pool-banners/modal-pool-banners.tsx b/shared/banners/modal-pool-banners/modal-pool-banners.tsx index d299d5cee..16c0f1786 100644 --- a/shared/banners/modal-pool-banners/modal-pool-banners.tsx +++ b/shared/banners/modal-pool-banners/modal-pool-banners.tsx @@ -1,6 +1,6 @@ import { trackEvent } from '@lidofinance/analytics-matomo'; import { Curve } from 'shared/banners/curve'; -import { MATOMO_CLICK_EVENTS } from 'config'; +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { TextStyles, DescStyles, ButtonLinkWrap, ButtonStyled } from './styles'; diff --git a/shared/components/layout/header/components/header-settings-button.tsx b/shared/components/layout/header/components/header-settings-button.tsx index 94c7131a7..cb76e00af 100644 --- a/shared/components/layout/header/components/header-settings-button.tsx +++ b/shared/components/layout/header/components/header-settings-button.tsx @@ -2,7 +2,7 @@ import { useCallback } from 'react'; // @ts-expect-error https://www.npmjs.com/package/@svgr/webpack import { ReactComponent as GearIcon } from 'assets/icons/gear.svg'; -import { SETTINGS_PATH } from 'config/urls'; +import { SETTINGS_PATH } from 'consts/urls'; import { useRouterPath } from 'shared/hooks/use-router-path'; import { usePrefixedPush } from 'shared/hooks/use-prefixed-history'; diff --git a/shared/components/layout/header/components/navigation/navigation.tsx b/shared/components/layout/header/components/navigation/navigation.tsx index d2da2d56d..a1823bf7e 100644 --- a/shared/components/layout/header/components/navigation/navigation.tsx +++ b/shared/components/layout/header/components/navigation/navigation.tsx @@ -8,7 +8,7 @@ import { WITHDRAWALS_CLAIM_PATH, REWARDS_PATH, getPathWithoutFirstSlash, -} from 'config/urls'; +} from 'consts/urls'; import { LocalLink } from 'shared/components/local-link'; import { useRouterPath } from 'shared/hooks/use-router-path'; diff --git a/shared/components/matomo-link/matomo-link.tsx b/shared/components/matomo-link/matomo-link.tsx index e20086652..5b7f7cfe8 100644 --- a/shared/components/matomo-link/matomo-link.tsx +++ b/shared/components/matomo-link/matomo-link.tsx @@ -1,7 +1,11 @@ import { FC } from 'react'; import { Link, LinkProps } from '@lidofinance/lido-ui'; import { trackEvent } from '@lidofinance/analytics-matomo'; -import { MATOMO_CLICK_EVENTS_TYPES, MATOMO_CLICK_EVENTS } from 'config'; + +import { + MATOMO_CLICK_EVENTS_TYPES, + MATOMO_CLICK_EVENTS, +} from 'consts/matomo-click-events'; interface MatomoLinkProps extends LinkProps { matomoEvent: MATOMO_CLICK_EVENTS_TYPES; diff --git a/shared/formatters/format-price.tsx b/shared/formatters/format-price.tsx index 60660f4f9..f415384f2 100644 --- a/shared/formatters/format-price.tsx +++ b/shared/formatters/format-price.tsx @@ -1,5 +1,6 @@ import { Tooltip } from '@lidofinance/lido-ui'; -import { DATA_UNAVAILABLE, LOCALE } from 'config'; +import { LOCALE } from 'config'; +import { DATA_UNAVAILABLE } from 'consts/text'; import { Component } from 'types'; export type FormatPriceComponent = Component< diff --git a/shared/hooks/use-router-path.ts b/shared/hooks/use-router-path.ts index 8d93418f4..eeb1af928 100644 --- a/shared/hooks/use-router-path.ts +++ b/shared/hooks/use-router-path.ts @@ -1,7 +1,7 @@ import { useRouter } from 'next/router'; import { isClientSide } from 'utils/isClientSide'; import { dynamics } from 'config'; -import { HOME_PATH } from 'config/urls'; +import { HOME_PATH } from 'consts/urls'; export const useRouterPath = () => { const router = useRouter(); diff --git a/shared/hooks/useLidoStats.ts b/shared/hooks/useLidoStats.ts index 5fa1521f8..350aa38d8 100644 --- a/shared/hooks/useLidoStats.ts +++ b/shared/hooks/useLidoStats.ts @@ -1,7 +1,8 @@ import { useMemo } from 'react'; import { useSDK, useLidoSWR } from '@lido-sdk/react'; -import { DATA_UNAVAILABLE, dynamics } from 'config'; +import { dynamics } from 'config'; +import { DATA_UNAVAILABLE } from 'consts/text'; import { prependBasePath } from 'utils'; import { standardFetcher } from 'utils/standardFetcher'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; diff --git a/shared/hooks/useMatomoEventHandle.ts b/shared/hooks/useMatomoEventHandle.ts index adb8cc36f..2b90be5bd 100644 --- a/shared/hooks/useMatomoEventHandle.ts +++ b/shared/hooks/useMatomoEventHandle.ts @@ -1,5 +1,8 @@ import { trackEvent } from '@lidofinance/analytics-matomo'; -import { MATOMO_CLICK_EVENTS, MATOMO_CLICK_EVENTS_TYPES } from 'config'; +import { + MATOMO_CLICK_EVENTS_TYPES, + MATOMO_CLICK_EVENTS, +} from 'consts/matomo-click-events'; const onClickHandler = (event: React.MouseEvent) => { const { target } = event; diff --git a/shared/wallet/connect/connect.tsx b/shared/wallet/connect/connect.tsx index f7276520d..0594905fb 100644 --- a/shared/wallet/connect/connect.tsx +++ b/shared/wallet/connect/connect.tsx @@ -1,9 +1,10 @@ import { FC } from 'react'; import { Button, ButtonProps } from '@lidofinance/lido-ui'; import { wrapWithEventTrack } from '@lidofinance/analytics-matomo'; + +import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { useModal } from 'shared/hooks'; import { MODAL } from 'providers'; -import { MATOMO_CLICK_EVENTS } from 'config'; export const Connect: FC = (props) => { const { onClick, ...rest } = props; diff --git a/test/pages/widget.page.ts b/test/pages/widget.page.ts index 0979783fb..a26393e30 100644 --- a/test/pages/widget.page.ts +++ b/test/pages/widget.page.ts @@ -1,5 +1,5 @@ import { expect, Locator, Page } from '@playwright/test'; -import { HOME_PATH } from 'config/urls'; +import { HOME_PATH } from 'consts/urls'; export class WidgetPage { readonly page: Page; diff --git a/config/trackMatomoEvent.ts b/utils/track-matomo-event.ts similarity index 72% rename from config/trackMatomoEvent.ts rename to utils/track-matomo-event.ts index 142eff38e..85d431925 100644 --- a/config/trackMatomoEvent.ts +++ b/utils/track-matomo-event.ts @@ -1,10 +1,8 @@ +import { trackEvent } from '@lidofinance/analytics-matomo'; import { MATOMO_CLICK_EVENTS_TYPES, MATOMO_CLICK_EVENTS, -} from './matomoClickEvents'; -import { trackEvent } from '@lidofinance/analytics-matomo'; - -export { MATOMO_CLICK_EVENTS_TYPES } from './matomoClickEvents'; +} from 'consts/matomo-click-events'; export const trackMatomoEvent = (eventType: MATOMO_CLICK_EVENTS_TYPES) => { trackEvent(...MATOMO_CLICK_EVENTS[eventType]); diff --git a/utilsApi/contractAddressesMetricsMap.ts b/utilsApi/contractAddressesMetricsMap.ts index 17d4a5ea8..fab4d39df 100644 --- a/utilsApi/contractAddressesMetricsMap.ts +++ b/utilsApi/contractAddressesMetricsMap.ts @@ -1,3 +1,6 @@ +import { utils } from 'ethers'; +import { invert, isNull, memoize, omitBy } from 'lodash'; + import { CHAINS, TOKENS, @@ -10,13 +13,13 @@ import { WithdrawalQueueAbiFactory, WstethAbiFactory, } from '@lido-sdk/contracts'; -import { dynamics, getAggregatorStEthUsdPriceFeedAddress } from 'config'; -import { utils } from 'ethers'; + +import { dynamics } from 'config'; +import { getAggregatorStEthUsdPriceFeedAddress } from 'consts/aggregator'; import { AggregatorAbi__factory, AggregatorEthUsdPriceFeedAbi__factory, } from 'generated'; -import { invert, isNull, memoize, omitBy } from 'lodash'; export const CONTRACT_NAMES = { stETH: 'stETH', diff --git a/utilsApi/fetchRPC.ts b/utilsApi/fetchRPC.ts index d5159fd66..152a16e19 100644 --- a/utilsApi/fetchRPC.ts +++ b/utilsApi/fetchRPC.ts @@ -1,6 +1,6 @@ import { trackedFetchRpcFactory } from '@lidofinance/api-rpc'; +import { METRICS_PREFIX } from 'consts/metrics'; import Metrics from 'utilsApi/metrics'; -import { METRICS_PREFIX } from 'config'; export const fetchRPC = trackedFetchRpcFactory({ registry: Metrics.registry, diff --git a/utilsApi/getLdoStats.ts b/utilsApi/getLdoStats.ts index dc911e653..b8a588a23 100644 --- a/utilsApi/getLdoStats.ts +++ b/utilsApi/getLdoStats.ts @@ -1,6 +1,6 @@ import { CHAINS } from 'utils/chains'; import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; -import { ETHPLORER_TOKEN_ENDPOINT } from 'config'; +import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import getConfig from 'next/config'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; diff --git a/utilsApi/getLidoStats.ts b/utilsApi/getLidoStats.ts index c453538ce..d5fc56a19 100644 --- a/utilsApi/getLidoStats.ts +++ b/utilsApi/getLidoStats.ts @@ -1,8 +1,9 @@ -import { ETHPLORER_TOKEN_ENDPOINT } from 'config'; import getConfig from 'next/config'; +import { TOKENS, getTokenAddress, CHAINS } from '@lido-sdk/constants'; + +import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -import { TOKENS, getTokenAddress, CHAINS } from '@lido-sdk/constants'; const { serverRuntimeConfig } = getConfig(); const { ethplorerApiKey } = serverRuntimeConfig; diff --git a/utilsApi/getStEthPrice.ts b/utilsApi/getStEthPrice.ts index 314a04b6d..3963f10e1 100644 --- a/utilsApi/getStEthPrice.ts +++ b/utilsApi/getStEthPrice.ts @@ -1,10 +1,12 @@ -import { getStaticRpcBatchProvider } from './rpcProviders'; -import { getAggregatorStEthUsdPriceFeedAddress } from 'config'; -import { rpcUrls } from './rpcUrls'; import { iterateUrls } from '@lidofinance/rpc'; import { CHAINS } from '@lido-sdk/constants'; import { getAggregatorContract } from '@lido-sdk/contracts'; +import { getAggregatorStEthUsdPriceFeedAddress } from 'consts/aggregator'; + +import { getStaticRpcBatchProvider } from './rpcProviders'; +import { rpcUrls } from './rpcUrls'; + export const getStEthPrice = async (): Promise => { const urls = rpcUrls[CHAINS.Mainnet]; return iterateUrls( diff --git a/utilsApi/getTotalStaked.ts b/utilsApi/getTotalStaked.ts index b69601d70..ba1f19a9b 100644 --- a/utilsApi/getTotalStaked.ts +++ b/utilsApi/getTotalStaked.ts @@ -1,9 +1,11 @@ import { formatEther } from '@ethersproject/units'; -import { getStaticRpcBatchProvider } from './rpcProviders'; import { StethAbiFactory } from '@lido-sdk/contracts'; import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; + +import { HEALTHY_RPC_SERVICES_ARE_OVER } from 'consts/api'; import { CHAINS } from 'utils/chains'; -import { HEALTHY_RPC_SERVICES_ARE_OVER } from 'config'; + +import { getStaticRpcBatchProvider } from './rpcProviders'; import { rpcUrls } from './rpcUrls'; export const getTotalStaked = async ( diff --git a/utilsApi/metrics/metrics.ts b/utilsApi/metrics/metrics.ts index 28ebe8b72..f110be9b6 100644 --- a/utilsApi/metrics/metrics.ts +++ b/utilsApi/metrics/metrics.ts @@ -1,7 +1,10 @@ import { collectDefaultMetrics, Registry } from 'prom-client'; -import { dynamics, METRICS_PREFIX } from 'config'; -import buildInfoJson from 'build-info.json'; import { collectStartupMetrics } from '@lidofinance/api-metrics'; + +import { dynamics } from 'config'; +import { METRICS_PREFIX } from 'consts/metrics'; +import buildInfoJson from 'build-info.json'; + import { RequestMetrics } from './request'; import { SubgraphMetrics } from './subgraph'; diff --git a/utilsApi/metrics/request.ts b/utilsApi/metrics/request.ts index d62b78f25..1553528e4 100644 --- a/utilsApi/metrics/request.ts +++ b/utilsApi/metrics/request.ts @@ -1,5 +1,5 @@ import { Counter, Histogram, Registry } from 'prom-client'; -import { METRICS_PREFIX, METRIC_NAMES } from 'config'; +import { METRICS_PREFIX, METRIC_NAMES } from 'consts/metrics'; export class RequestMetrics { apiTimings: Histogram<'hostname' | 'route' | 'entity' | 'status'>; diff --git a/utilsApi/metrics/subgraph.ts b/utilsApi/metrics/subgraph.ts index b0fa2b549..fef942f47 100644 --- a/utilsApi/metrics/subgraph.ts +++ b/utilsApi/metrics/subgraph.ts @@ -1,5 +1,5 @@ import { Histogram, Registry } from 'prom-client'; -import { METRICS_PREFIX, METRIC_NAMES } from 'config'; +import { METRICS_PREFIX, METRIC_NAMES } from 'consts/metrics'; export class SubgraphMetrics { subgraphsResponseTime: Histogram<'subgraphs'>; diff --git a/utilsApi/rpcProviders.ts b/utilsApi/rpcProviders.ts index e3d9dd444..b72fc57ad 100644 --- a/utilsApi/rpcProviders.ts +++ b/utilsApi/rpcProviders.ts @@ -3,8 +3,9 @@ import { StaticJsonRpcBatchProvider, } from '@lidofinance/eth-providers'; import { trackedJsonRpcProvider } from '@lidofinance/eth-api-providers'; + +import { METRICS_PREFIX } from 'consts/metrics'; import Metrics from 'utilsApi/metrics'; -import { METRICS_PREFIX } from '../config'; export const getStaticRpcBatchProvider = providerFactory( trackedJsonRpcProvider({ From efaa42343b54fbdf5a11db63c00b889e2688e503 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sat, 24 Feb 2024 00:06:57 +0300 Subject: [PATCH 03/48] refactor: client-config --- config/client-config/hooks.ts | 11 +++++++++++ .../client-config/provider.tsx | 16 ++++++---------- config/{ => client-config}/types.ts | 0 .../client-config/utils.ts | 2 +- config/index.ts | 1 - config/rpc.ts | 5 ++--- .../settings/settings-form/settings-form.tsx | 2 +- providers/index.tsx | 2 +- providers/web3.tsx | 2 +- 9 files changed, 23 insertions(+), 18 deletions(-) create mode 100644 config/client-config/hooks.ts rename providers/client-config.tsx => config/client-config/provider.tsx (81%) rename config/{ => client-config}/types.ts (100%) rename utils/parse-env-config.ts => config/client-config/utils.ts (87%) diff --git a/config/client-config/hooks.ts b/config/client-config/hooks.ts new file mode 100644 index 000000000..d19305a4e --- /dev/null +++ b/config/client-config/hooks.ts @@ -0,0 +1,11 @@ +import { useContext } from 'react'; +import invariant from 'tiny-invariant'; + +import { ClientConfigContext } from './provider'; + +// TODO: 'useClientConfig' --> 'useUserConfig' +export const useClientConfig = () => { + const context = useContext(ClientConfigContext); + invariant(context, 'Attempt to use `client config` outside of provider'); + return context; +}; diff --git a/providers/client-config.tsx b/config/client-config/provider.tsx similarity index 81% rename from providers/client-config.tsx rename to config/client-config/provider.tsx index 6de132ee3..d30b81043 100644 --- a/providers/client-config.tsx +++ b/config/client-config/provider.tsx @@ -2,19 +2,20 @@ import { PropsWithChildren, useMemo, useState, - useContext, useCallback, createContext, } from 'react'; -import invariant from 'tiny-invariant'; import { useLocalStorage } from '@lido-sdk/react'; import { dynamics } from 'config'; -import { EnvConfigParsed } from 'config/types'; import { STORAGE_CLIENT_CONFIG } from 'consts/storage'; import { CHAINS } from 'utils/chains'; -import { parseEnvConfig } from 'utils/parse-env-config'; + +import { parseEnvConfig } from './utils'; +import { EnvConfigParsed } from './types'; + +// TODO whole file: '*Сlient*' --> '*User*', 'client' --> 'user' type SavedClientConfig = { rpcUrls: Partial>; @@ -29,16 +30,11 @@ export const ClientConfigContext = createContext( null, ); -export const useClientConfig = () => { - const context = useContext(ClientConfigContext); - invariant(context, 'Attempt to use `client config` outside of provider'); - return context; -}; - const DEFAULT_STATE: SavedClientConfig = { rpcUrls: {}, }; +// TODO: 'ClientConfigProvider' --> 'UserConfigProvider' export const ClientConfigProvider = ({ children }: PropsWithChildren) => { const [restoredSettings, setLocalStorage] = useLocalStorage( STORAGE_CLIENT_CONFIG, diff --git a/config/types.ts b/config/client-config/types.ts similarity index 100% rename from config/types.ts rename to config/client-config/types.ts diff --git a/utils/parse-env-config.ts b/config/client-config/utils.ts similarity index 87% rename from utils/parse-env-config.ts rename to config/client-config/utils.ts index c6fc5e252..f587b4af5 100644 --- a/utils/parse-env-config.ts +++ b/config/client-config/utils.ts @@ -1,4 +1,4 @@ -import { EnvConfigRaw, EnvConfigParsed } from 'config/types'; +import { EnvConfigRaw, EnvConfigParsed } from 'config/client-config/types'; import { CHAINS } from 'utils/chains'; export const parseEnvConfig = (envConfig: EnvConfigRaw): EnvConfigParsed => { diff --git a/config/index.ts b/config/index.ts index da5a53fdb..5f33d6e5d 100644 --- a/config/index.ts +++ b/config/index.ts @@ -6,6 +6,5 @@ export * from './estimate'; export * from './locale'; export * from './ipfs'; export * from './rpc'; -export * from './types'; export * from './rateLimit'; export * from './stake'; diff --git a/config/rpc.ts b/config/rpc.ts index 2615591f0..707880ecc 100644 --- a/config/rpc.ts +++ b/config/rpc.ts @@ -2,7 +2,7 @@ import { useCallback } from 'react'; import invariant from 'tiny-invariant'; import { useSDK } from '@lido-sdk/react'; -import { useClientConfig } from 'providers/client-config'; +import { useClientConfig } from './client-config/hooks'; import { CHAINS } from 'utils/chains'; import dynamics from './dynamics'; @@ -51,6 +51,5 @@ export const useGetRpcUrlByChainId = () => { export const useRpcUrl = () => { const { chainId } = useSDK(); - const getRpcUrlByChainId = useGetRpcUrlByChainId(); - return getRpcUrlByChainId(chainId as number); + return useGetRpcUrlByChainId()(chainId as number); }; diff --git a/features/settings/settings-form/settings-form.tsx b/features/settings/settings-form/settings-form.tsx index 778aa738d..f87e1d40e 100644 --- a/features/settings/settings-form/settings-form.tsx +++ b/features/settings/settings-form/settings-form.tsx @@ -4,7 +4,7 @@ import { useForm } from 'react-hook-form'; import { useSDK } from '@lido-sdk/react'; import { Button, ToastSuccess, Block, Input } from '@lidofinance/lido-ui'; -import { useClientConfig } from 'providers/client-config'; +import { useClientConfig } from 'config/client-config/hooks'; import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; import { RPCErrorType, checkRpcUrl } from 'utils/check-rpc-url'; import { CHAINS } from 'utils/chains'; diff --git a/providers/index.tsx b/providers/index.tsx index 8ec0dce98..3a7b8e2c7 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -2,9 +2,9 @@ import { FC, PropsWithChildren } from 'react'; import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; +import { ClientConfigProvider } from 'config/client-config/provider'; import { AppFlagProvider } from './app-flag'; import { OneConfigProvider } from './one-config'; -import { ClientConfigProvider } from './client-config'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; import { InpageNavigationProvider } from './inpage-navigation'; import ModalProvider from './modals'; diff --git a/providers/web3.tsx b/providers/web3.tsx index 017c02cc5..8ade87b04 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -7,7 +7,7 @@ import * as wagmiChains from 'wagmi/chains'; import { CHAINS } from 'utils/chains'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; -import { useClientConfig } from 'providers/client-config'; +import { useClientConfig } from 'config/client-config/hooks'; import { dynamics, useGetRpcUrlByChainId } from 'config'; const Web3Provider: FC = ({ children }) => { From 9694af72b907425ed63992582e98ce5e009c3449 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sat, 24 Feb 2024 22:52:04 +0300 Subject: [PATCH 04/48] refactor: using dynamics through `one-config` --- config/cache.ts | 2 + config/client-config/provider.tsx | 6 ++- config/ipfs.ts | 6 ++- config/{ => one-config}/dynamics.ts | 2 +- config/one-config/hooks.ts | 9 +++++ config/one-config/provider.tsx | 16 ++++++++ config/one-config/utils.ts | 19 +++++++++ config/rpc.ts | 5 ++- config/stake.ts | 11 +++-- .../rewards/components/CopyAddressUrl.tsx | 6 ++- features/rewards/components/IndexerLink.tsx | 6 ++- features/rewards/components/stats/Stats.tsx | 6 ++- .../fetchers/requesters/json/backend.ts | 7 ++-- .../fetchers/requesters/rpc/stEthEth.ts | 6 ++- features/rewards/hooks/useRewardsDataLoad.ts | 9 +++-- features/stake/lido-stats/lido-stats.tsx | 14 ++++--- features/withdrawals/hooks/useWaitingTime.ts | 6 ++- .../withdrawals/hooks/useWithdrawTxPrice.ts | 11 +++-- pages/_app.tsx | 6 ++- pages/_document.tsx | 10 +++-- pages/api/rpc.ts | 7 +++- pages/index.tsx | 5 ++- pages/settings.tsx | 2 +- providers/index.tsx | 5 ++- providers/inpage-navigation.tsx | 11 +++-- providers/one-config.tsx | 40 ------------------- providers/web3.tsx | 12 ++++-- shared/banners/curve/useCurve.ts | 6 ++- .../header/components/header-wallet.tsx | 8 ++-- shared/components/layout/layout.tsx | 6 ++- shared/components/local-link/index.tsx | 6 ++- shared/hooks/use-compare-with-router-path.ts | 7 +++- shared/hooks/use-router-path.ts | 9 ++++- shared/hooks/useLidoApr.ts | 7 +++- shared/hooks/useLidoStats.ts | 8 ++-- shared/hooks/useWeb3Key.ts | 6 ++- utils/get-ipfs-base-path.ts | 7 +++- utils/qa.ts | 5 ++- utilsApi/contractAddressesMetricsMap.ts | 8 ++-- utilsApi/metrics/metrics.ts | 8 ++-- utilsApi/withCSP.ts | 10 +++-- 41 files changed, 215 insertions(+), 131 deletions(-) rename config/{ => one-config}/dynamics.ts (85%) create mode 100644 config/one-config/hooks.ts create mode 100644 config/one-config/provider.tsx create mode 100644 config/one-config/utils.ts delete mode 100644 providers/one-config.tsx diff --git a/config/cache.ts b/config/cache.ts index 9d0a050e5..c3f7a4202 100644 --- a/config/cache.ts +++ b/config/cache.ts @@ -1,5 +1,7 @@ import ms from 'ms'; +// TODO: move to './config/values/cache.ts' + export const CACHE_STETH_APR_KEY = 'cache-steth-apr'; export const CACHE_STETH_APR_TTL = ms('1h'); diff --git a/config/client-config/provider.tsx b/config/client-config/provider.tsx index d30b81043..20eced727 100644 --- a/config/client-config/provider.tsx +++ b/config/client-config/provider.tsx @@ -8,8 +8,8 @@ import { import { useLocalStorage } from '@lido-sdk/react'; -import { dynamics } from 'config'; import { STORAGE_CLIENT_CONFIG } from 'consts/storage'; +import * as dynamicsOnBackend from 'env-dynamics.mjs'; import { CHAINS } from 'utils/chains'; import { parseEnvConfig } from './utils'; @@ -53,7 +53,9 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => { ); const contextValue = useMemo(() => { - const envConfig = parseEnvConfig(dynamics); + const envConfig = parseEnvConfig( + typeof window !== 'undefined' ? window.__env__ : dynamicsOnBackend, + ); return { ...envConfig, diff --git a/config/ipfs.ts b/config/ipfs.ts index 85e28aa05..d92e092bf 100644 --- a/config/ipfs.ts +++ b/config/ipfs.ts @@ -1,11 +1,13 @@ import getConfig from 'next/config'; -import dynamics from './dynamics'; + +import { getOneConfig } from './one-config/utils'; +const { ipfsMode } = getOneConfig(); const { serverRuntimeConfig } = getConfig(); const { basePath = '' } = serverRuntimeConfig; // TODO: move to OneConfig -export const BASE_PATH_ASSET = dynamics.ipfsMode ? '.' : basePath; +export const BASE_PATH_ASSET = ipfsMode ? '.' : basePath; // TODO: move to OneConfig export const IPFS_REFERRAL_ADDRESS = '0x74d6e4Fd83A0b5623BDE3B2dF9a9A7F31fE02325'; diff --git a/config/dynamics.ts b/config/one-config/dynamics.ts similarity index 85% rename from config/dynamics.ts rename to config/one-config/dynamics.ts index 4bbc22b41..9633e4c6d 100644 --- a/config/dynamics.ts +++ b/config/one-config/dynamics.ts @@ -1,4 +1,4 @@ -import * as dynamics from '../env-dynamics.mjs'; +import * as dynamics from 'env-dynamics.mjs'; // We're making dynamic env variables // so we can inject selected envs from Docker runtime too, // not only during build-time for static pages diff --git a/config/one-config/hooks.ts b/config/one-config/hooks.ts new file mode 100644 index 000000000..d4725f29a --- /dev/null +++ b/config/one-config/hooks.ts @@ -0,0 +1,9 @@ +import { useContext } from 'react'; +import invariant from 'tiny-invariant'; +import { OneConfigContext } from './provider'; + +export const useOneConfig = () => { + const context = useContext(OneConfigContext); + invariant(context, 'Attempt to use `one config` outside of provider'); + return context; +}; diff --git a/config/one-config/provider.tsx b/config/one-config/provider.tsx new file mode 100644 index 000000000..c1d1ba718 --- /dev/null +++ b/config/one-config/provider.tsx @@ -0,0 +1,16 @@ +import { PropsWithChildren, createContext } from 'react'; + +import { getOneConfig } from './utils'; + +export const OneConfigContext = createContext(null); + +export const OneConfigProvider = ({ children }: PropsWithChildren) => { + // TODO: check object destructuring is fast or use memo? + const contextValue = getOneConfig(); + + return ( + + {children} + + ); +}; diff --git a/config/one-config/utils.ts b/config/one-config/utils.ts new file mode 100644 index 000000000..e6cfa99ed --- /dev/null +++ b/config/one-config/utils.ts @@ -0,0 +1,19 @@ +import getConfig from 'next/config'; +const { serverRuntimeConfig } = getConfig(); + +import { default as dynamics } from './dynamics'; + +// TODO: add return type +export const getOneConfig = () => { + const isClientSide = typeof window !== 'undefined'; + const isServerSide = typeof window === 'undefined'; + + return { + isClientSide, + isServerSide, + // ...dynamics, + ...(typeof window !== 'undefined' ? window.__env__ : dynamics), + // ...serverRuntimeConfig, + ...(isServerSide && serverRuntimeConfig && { env: process.env }), + }; +}; diff --git a/config/rpc.ts b/config/rpc.ts index 707880ecc..1ba0a0ce7 100644 --- a/config/rpc.ts +++ b/config/rpc.ts @@ -5,7 +5,8 @@ import { useSDK } from '@lido-sdk/react'; import { useClientConfig } from './client-config/hooks'; import { CHAINS } from 'utils/chains'; -import dynamics from './dynamics'; +import { getOneConfig } from './one-config/utils'; +const { ipfsMode } = getOneConfig(); // TODO: one config export const getBackendRPCPath = (chainId: string | number): string => { @@ -31,7 +32,7 @@ export const useGetRpcUrlByChainId = () => { return ''; } - if (dynamics.ipfsMode) { + if (ipfsMode) { const rpc = clientConfig.savedClientConfig.rpcUrls[chainId] || clientConfig.prefillUnsafeElRpcUrls[chainId]?.[0]; diff --git a/config/stake.ts b/config/stake.ts index 55bda9873..8e26495b4 100644 --- a/config/stake.ts +++ b/config/stake.ts @@ -1,9 +1,12 @@ -import { parseEther } from '@ethersproject/units'; import { BigNumber } from 'ethers'; -import dynamics from './dynamics'; -import { IPFS_REFERRAL_ADDRESS } from './ipfs'; +import { parseEther } from '@ethersproject/units'; import { AddressZero } from '@ethersproject/constants'; +import { getOneConfig } from './one-config/utils'; +const { ipfsMode } = getOneConfig(); + +import { IPFS_REFERRAL_ADDRESS } from './ipfs'; + // TODO: const export const PRECISION = 10 ** 6; @@ -25,6 +28,6 @@ export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( ); // TODO: move to OneConfig -export const STAKE_FALLBACK_REFERRAL_ADDRESS = dynamics.ipfsMode +export const STAKE_FALLBACK_REFERRAL_ADDRESS = ipfsMode ? IPFS_REFERRAL_ADDRESS : AddressZero; diff --git a/features/rewards/components/CopyAddressUrl.tsx b/features/rewards/components/CopyAddressUrl.tsx index 7af3cc96f..3bdab4a0a 100644 --- a/features/rewards/components/CopyAddressUrl.tsx +++ b/features/rewards/components/CopyAddressUrl.tsx @@ -1,7 +1,9 @@ import { useMemo } from 'react'; import { ButtonIcon, Copy } from '@lidofinance/lido-ui'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { useCopyToClipboard } from 'shared/hooks'; import { getBasedHashHref } from 'utils/get-based-hash-href'; @@ -10,7 +12,7 @@ const CopyAddressUrl = ({ address }: { address: string }) => { const url = useMemo(() => { const { href } = location; - if (dynamics.ipfsMode) { + if (ipfsMode) { let withoutHashAndQuery = href.split('?')[0].split('#')[0]; if (withoutHashAndQuery[withoutHashAndQuery.length - 1] === '/') { // Remove first '/' diff --git a/features/rewards/components/IndexerLink.tsx b/features/rewards/components/IndexerLink.tsx index d2232ec91..1812a0a4e 100644 --- a/features/rewards/components/IndexerLink.tsx +++ b/features/rewards/components/IndexerLink.tsx @@ -1,6 +1,8 @@ import { Box, External as ExternalLinkIcon } from '@lidofinance/lido-ui'; import { getEtherscanTxLink } from '@lido-sdk/helpers'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain } = getOneConfig(); // TODO: move to separate folders type Props = { @@ -10,7 +12,7 @@ type Props = { const IndexerLink = ({ transactionHash }: Props) => { if (!transactionHash) return null; - const link = getEtherscanTxLink(dynamics.defaultChain, transactionHash); + const link = getEtherscanTxLink(defaultChain, transactionHash); return ( diff --git a/features/rewards/components/stats/Stats.tsx b/features/rewards/components/stats/Stats.tsx index b24d81fe7..94ebbd9b7 100644 --- a/features/rewards/components/stats/Stats.tsx +++ b/features/rewards/components/stats/Stats.tsx @@ -6,7 +6,9 @@ import { Box, Link } from '@lidofinance/lido-ui'; import { useSDK, useTokenBalance } from '@lido-sdk/react'; import { TOKENS, getTokenAddress } from '@lido-sdk/constants'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain } = getOneConfig(); + import { stEthEthRequest } from 'features/rewards/fetchers/requesters'; import EthSymbol from 'features/rewards/components/EthSymbol'; import NumberFormat from 'features/rewards/components/NumberFormat'; @@ -35,7 +37,7 @@ export const Stats: FC = (props) => { const mainnetStaticRpcProvider = useMainnetStaticRpcProvider(); const getStEthEth = useCallback(async () => { - if (dynamics.defaultChain !== 1) { + if (defaultChain !== 1) { setStEthEth(constants.WeiPerEther); } else { const stEthEth = await stEthEthRequest(mainnetStaticRpcProvider); diff --git a/features/rewards/fetchers/requesters/json/backend.ts b/features/rewards/fetchers/requesters/json/backend.ts index 8fde861da..d22f6b0aa 100644 --- a/features/rewards/fetchers/requesters/json/backend.ts +++ b/features/rewards/fetchers/requesters/json/backend.ts @@ -1,4 +1,5 @@ -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode, widgetApiBasePathForIpfs } = getOneConfig(); export type BackendQuery = { address: string; @@ -15,8 +16,8 @@ export const backendRequest = async (query: BackendQuery) => { Object.entries(query).forEach(([k, v]) => params.append(k, v.toString())); const apiRewardsPath = `/api/rewards?${params.toString()}`; - const apiRewardsUrl = dynamics.ipfsMode - ? `${dynamics.widgetApiBasePathForIpfs}${apiRewardsPath}` + const apiRewardsUrl = ipfsMode + ? `${widgetApiBasePathForIpfs}${apiRewardsPath}` : apiRewardsPath; const requested = await fetch(apiRewardsUrl); diff --git a/features/rewards/fetchers/requesters/rpc/stEthEth.ts b/features/rewards/fetchers/requesters/rpc/stEthEth.ts index c02cc631c..a76291b8e 100644 --- a/features/rewards/fetchers/requesters/rpc/stEthEth.ts +++ b/features/rewards/fetchers/requesters/rpc/stEthEth.ts @@ -2,7 +2,9 @@ import { constants } from 'ethers'; import type { BigNumber as EthersBigNumber } from 'ethers'; import { StaticJsonRpcBatchProvider } from '@lidofinance/eth-providers'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain } = getOneConfig(); + import rpcFetch from 'features/rewards/fetchers/rpcFetch'; const MAINNET_CURVE = '0xDC24316b9AE028F1497c275EB9192a3Ea0f67022'; @@ -13,7 +15,7 @@ For testnet simply provide 1-1 ratio for UI to work **/ export const stEthEthRequest = (mainnetProvider: StaticJsonRpcBatchProvider) => - dynamics.defaultChain === 1 + defaultChain === 1 ? rpcFetch( mainnetProvider, MAINNET_CURVE, diff --git a/features/rewards/hooks/useRewardsDataLoad.ts b/features/rewards/hooks/useRewardsDataLoad.ts index e2c987a3d..0a76a54c3 100644 --- a/features/rewards/hooks/useRewardsDataLoad.ts +++ b/features/rewards/hooks/useRewardsDataLoad.ts @@ -1,6 +1,9 @@ import { useEffect, useRef } from 'react'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode, widgetApiBasePathForIpfs } = getOneConfig(); + import { Backend } from 'features/rewards/types'; -import { dynamics } from 'config'; import { useLidoSWR } from 'shared/hooks'; import { swrAbortableMiddleware } from 'utils'; @@ -46,8 +49,8 @@ export const useRewardsDataLoad: UseRewardsDataLoad = (props) => { ); const apiRewardsPath = `/api/rewards?${params.toString()}`; - const apiRewardsUrl = dynamics.ipfsMode - ? `${dynamics.widgetApiBasePathForIpfs}${apiRewardsPath}` + const apiRewardsUrl = ipfsMode + ? `${widgetApiBasePathForIpfs}${apiRewardsPath}` : apiRewardsPath; const { data, ...rest } = useLidoSWR( diff --git a/features/stake/lido-stats/lido-stats.tsx b/features/stake/lido-stats/lido-stats.tsx index 5dcf69de3..ee00de3ad 100644 --- a/features/stake/lido-stats/lido-stats.tsx +++ b/features/stake/lido-stats/lido-stats.tsx @@ -7,7 +7,10 @@ import { Block, DataTable, Question, Tooltip } from '@lidofinance/lido-ui'; import { Section, MatomoLink } from 'shared/components'; import { useLidoApr, useLidoStats } from 'shared/hooks'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { LIDO_APR_TOOLTIP_TEXT } from 'consts/text'; import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; @@ -30,13 +33,12 @@ export const LidoStats: FC = memo(() => { const lidoApr = useLidoApr(); const lidoStats = useLidoStats(); - const showApr = !dynamics.ipfsMode || isStatItemAvailable(lidoApr.apr); + const showApr = !ipfsMode || isStatItemAvailable(lidoApr.apr); const showTotalStaked = - !dynamics.ipfsMode || isStatItemAvailable(lidoStats.data.totalStaked); - const showStakers = - !dynamics.ipfsMode || isStatItemAvailable(lidoStats.data.stakers); + !ipfsMode || isStatItemAvailable(lidoStats.data.totalStaked); + const showStakers = !ipfsMode || isStatItemAvailable(lidoStats.data.stakers); const showMarketCap = - !dynamics.ipfsMode || isStatItemAvailable(lidoStats.data.marketCap); + !ipfsMode || isStatItemAvailable(lidoStats.data.marketCap); if (!showApr && !showTotalStaked && !showStakers && !showMarketCap) { return null; diff --git a/features/withdrawals/hooks/useWaitingTime.ts b/features/withdrawals/hooks/useWaitingTime.ts index 5142ed658..cf1205474 100644 --- a/features/withdrawals/hooks/useWaitingTime.ts +++ b/features/withdrawals/hooks/useWaitingTime.ts @@ -1,6 +1,8 @@ import { useMemo } from 'react'; import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { wqAPIBasePath } = getOneConfig(); import { useDebouncedValue } from 'shared/hooks'; import { encodeURLQuery } from 'utils/encodeURLQuery'; @@ -32,7 +34,7 @@ export const useWaitingTime = ( const { isApproximate } = options; const debouncedAmount = useDebouncedValue(amount, 1000); const url = useMemo(() => { - const basePath = dynamics.wqAPIBasePath; + const basePath = wqAPIBasePath; const params = encodeURLQuery({ amount: debouncedAmount }); const queryString = params ? `?${params}` : ''; return `${basePath}/v1/request-time${queryString}`; diff --git a/features/withdrawals/hooks/useWithdrawTxPrice.ts b/features/withdrawals/hooks/useWithdrawTxPrice.ts index ac1d1823a..2e31228c5 100644 --- a/features/withdrawals/hooks/useWithdrawTxPrice.ts +++ b/features/withdrawals/hooks/useWithdrawTxPrice.ts @@ -8,8 +8,11 @@ import { WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT, WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT, WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT, - dynamics, } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { wqAPIBasePath } = getOneConfig(); + import { MAX_REQUESTS_COUNT } from 'features/withdrawals/withdrawals-constants'; import { useWeb3 } from 'reef-knot/web3-react'; @@ -43,14 +46,14 @@ export const useRequestTxPrice = ({ ? WITHDRAWAL_QUEUE_REQUEST_STETH_APPROVED_GAS_LIMIT_DEFAULT : WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT : isApprovalFlow - ? WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT - : WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT; + ? WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT + : WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT; const cappedRequestCount = Math.min(requestCount || 1, MAX_REQUESTS_COUNT); const debouncedRequestCount = useDebouncedValue(cappedRequestCount, 2000); const url = useMemo(() => { - const basePath = dynamics.wqAPIBasePath; + const basePath = wqAPIBasePath; const params = encodeURLQuery({ token, requestCount: debouncedRequestCount, diff --git a/pages/_app.tsx b/pages/_app.tsx index 4387ff2dd..4d779c484 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -9,7 +9,9 @@ import { migrationThemeCookiesToCrossDomainCookiesClientSide, } from '@lidofinance/lido-ui'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { Providers } from 'providers'; import { BackgroundGradient } from 'shared/components/background-gradient/background-gradient'; import { nprogress, COOKIES_ALLOWED_FULL_KEY } from 'utils'; @@ -51,6 +53,6 @@ const AppWrapper = (props: AppProps): JSX.Element => { ); }; -export default dynamics.ipfsMode || process.env.NODE_ENV === 'development' +export default ipfsMode || process.env.NODE_ENV === 'development' ? AppWrapper : withCsp(AppWrapper); diff --git a/pages/_document.tsx b/pages/_document.tsx index 5999ad6ec..4b238529b 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -10,7 +10,11 @@ import { createHeadersObject } from 'next-secure-headers'; import { ServerStyleSheet } from 'styled-components'; import { Fonts, LidoUIHead } from '@lidofinance/lido-ui'; -import { dynamics, BASE_PATH_ASSET } from 'config'; +import { BASE_PATH_ASSET } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain, ipfsMode } = getOneConfig(); + import { InsertIpfsBaseScript } from 'features/ipfs/ipfs-base-script'; import { contentSecurityPolicy } from 'utilsApi/withCSP'; @@ -79,7 +83,7 @@ export default class MyDocument extends Document { name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> - {dynamics.ipfsMode && ( + {ipfsMode && ( - + diff --git a/pages/api/rpc.ts b/pages/api/rpc.ts index ef6a624af..4bffcec2e 100644 --- a/pages/api/rpc.ts +++ b/pages/api/rpc.ts @@ -1,6 +1,9 @@ import { rpcFactory } from '@lidofinance/next-pages'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain } = getOneConfig(); + import { API_ROUTES } from 'consts/api'; import { METRICS_PREFIX } from 'consts/metrics'; import { @@ -38,7 +41,7 @@ const rpc = rpcFactory({ 'eth_chainId', 'net_version', ], - defaultChain: `${dynamics.defaultChain}`, + defaultChain: `${defaultChain}`, providers: rpcUrls, }); diff --git a/pages/index.tsx b/pages/index.tsx index 7f1467a67..c3abd8e44 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,6 +1,7 @@ -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); import { StakePage } from 'features/stake'; import HomePageIpfs from 'features/ipfs/home-page-ipfs'; -export default dynamics.ipfsMode ? HomePageIpfs : StakePage; +export default ipfsMode ? HomePageIpfs : StakePage; diff --git a/pages/settings.tsx b/pages/settings.tsx index 641216997..32889c97c 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -3,7 +3,7 @@ import { GetStaticProps } from 'next'; import { Layout } from 'shared/components'; import { SettingsForm } from 'features/settings/settings-form'; -import { getOneConfig } from 'providers/one-config'; +import { getOneConfig } from 'config/one-config/utils'; const Settings: FC = () => { return ( diff --git a/providers/index.tsx b/providers/index.tsx index 3a7b8e2c7..8a86abc7d 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -1,10 +1,11 @@ import { FC, PropsWithChildren } from 'react'; import { CookieThemeProvider } from '@lidofinance/lido-ui'; -import { GlobalStyle } from 'styles'; +import { GlobalStyle } from 'styles'; import { ClientConfigProvider } from 'config/client-config/provider'; +import { OneConfigProvider } from 'config/one-config/provider'; + import { AppFlagProvider } from './app-flag'; -import { OneConfigProvider } from './one-config'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; import { InpageNavigationProvider } from './inpage-navigation'; import ModalProvider from './modals'; diff --git a/providers/inpage-navigation.tsx b/providers/inpage-navigation.tsx index c2be00598..afeb26cc2 100644 --- a/providers/inpage-navigation.tsx +++ b/providers/inpage-navigation.tsx @@ -9,7 +9,10 @@ import { useEffect, } from 'react'; import invariant from 'tiny-invariant'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { useRouter } from 'next/router'; export type InpageNavigationContextValue = { @@ -31,7 +34,7 @@ export const InpageNavigationProvider: FC = ({ const [hashNav, setHash] = useState(''); useEffect(() => { - if (dynamics.ipfsMode) return; // Hash is reserved in ipfs mode, ignored here + if (ipfsMode) return; // Hash is reserved in ipfs mode, ignored here const hash = asPath.split('#')[1]; setHash(hash); }, [asPath]); @@ -53,7 +56,7 @@ export const InpageNavigationProvider: FC = ({ // Change the hash for non-ipfs ui, without scrolling the page // We have done animated scroll already on next step - if (!dynamics.ipfsMode) { + if (!ipfsMode) { history.pushState({}, '', `#${hash}`); } }, @@ -62,7 +65,7 @@ export const InpageNavigationProvider: FC = ({ const resetInpageAnchor = useCallback(() => { setHash(''); - if (!dynamics.ipfsMode) { + if (!ipfsMode) { const hashTrimmed = asPath.split('#')[0]; history.pushState({}, '', hashTrimmed); } diff --git a/providers/one-config.tsx b/providers/one-config.tsx deleted file mode 100644 index 619f07455..000000000 --- a/providers/one-config.tsx +++ /dev/null @@ -1,40 +0,0 @@ -import { PropsWithChildren, useContext, createContext } from 'react'; -import invariant from 'tiny-invariant'; - -import getConfig from 'next/config'; -const { serverRuntimeConfig } = getConfig(); - -import { dynamics } from 'config'; - -export const OneConfigContext = createContext(null); - -export const getOneConfig = () => { - const isClientSide = typeof window !== 'undefined'; - const isServerSide = typeof window === 'undefined'; - - return { - isClientSide, - isServerSide, - // ...dynamics, - ...(isClientSide && dynamics), - // ...serverRuntimeConfig, - ...(isServerSide && serverRuntimeConfig && { env: process.env }), - }; -}; - -export const useOneConfig = () => { - const context = useContext(OneConfigContext); - invariant(context, 'Attempt to use `one config` outside of provider'); - return context; -}; - -export const OneConfigProvider = ({ children }: PropsWithChildren) => { - // TODO: check object destructuring is fast or use memo? - const contextValue = getOneConfig(); - - return ( - - {children} - - ); -}; diff --git a/providers/web3.tsx b/providers/web3.tsx index 8ade87b04..45642d94d 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -8,7 +8,13 @@ import { CHAINS } from 'utils/chains'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; import { useClientConfig } from 'config/client-config/hooks'; -import { dynamics, useGetRpcUrlByChainId } from 'config'; +import { useGetRpcUrlByChainId } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { + defaultChain: defaultChainFromConfig, + supportedChains: supportedChainsFromConfig, +} = getOneConfig(); const Web3Provider: FC = ({ children }) => { const { defaultChain, supportedChainIds, walletconnectProjectId } = @@ -31,7 +37,7 @@ const Web3Provider: FC = ({ children }) => { const client = useMemo(() => { const wagmiChainsArray = Object.values({ ...wagmiChains, holesky }); const supportedChains = wagmiChainsArray.filter((chain) => - dynamics.supportedChains.includes(chain.id), + supportedChainsFromConfig.includes(chain.id), ); // Adding Mumbai as a temporary workaround @@ -42,7 +48,7 @@ const Web3Provider: FC = ({ children }) => { supportedChains.push(wagmiChains.polygonMumbai); const defaultChain = - wagmiChainsArray.find((chain) => chain.id === dynamics.defaultChain) || + wagmiChainsArray.find((chain) => chain.id === defaultChainFromConfig) || supportedChains[0]; // first supported chain as fallback const jsonRpcBatchProvider = (chain: Chain) => ({ diff --git a/shared/banners/curve/useCurve.ts b/shared/banners/curve/useCurve.ts index f39954d2e..ae310f296 100644 --- a/shared/banners/curve/useCurve.ts +++ b/shared/banners/curve/useCurve.ts @@ -1,13 +1,15 @@ import { useLidoSWR } from '@lido-sdk/react'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ethAPIBasePath } = getOneConfig(); + import { standardFetcher } from 'utils/standardFetcher'; import { CurveResponse } from './types'; export const useCurve = () => { return useLidoSWR( - `${dynamics.ethAPIBasePath ?? ''}/v1/pool/curve/steth-eth/apr/last`, + `${ethAPIBasePath ?? ''}/v1/pool/curve/steth-eth/apr/last`, standardFetcher, ); }; diff --git a/shared/components/layout/header/components/header-wallet.tsx b/shared/components/layout/header/components/header-wallet.tsx index 5776b08fd..132f237cc 100644 --- a/shared/components/layout/header/components/header-wallet.tsx +++ b/shared/components/layout/header/components/header-wallet.tsx @@ -6,7 +6,9 @@ import { CHAINS, getChainColor } from '@lido-sdk/constants'; import { ThemeToggler } from '@lidofinance/lido-ui'; import NoSSRWrapper from '../../../no-ssr-wrapper'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box'; import { Button, Connect } from 'shared/wallet'; @@ -42,9 +44,9 @@ const HeaderWallet: FC = () => { ) : ( )} - {dynamics.ipfsMode && } + {ipfsMode && } {!queryTheme && } - {dynamics.ipfsMode && ( + {ipfsMode && ( diff --git a/shared/components/layout/layout.tsx b/shared/components/layout/layout.tsx index 07f81a1be..208a46d89 100644 --- a/shared/components/layout/layout.tsx +++ b/shared/components/layout/layout.tsx @@ -2,7 +2,9 @@ import { ReactNode, FC, PropsWithChildren } from 'react'; import { ContainerProps } from '@lidofinance/lido-ui'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box'; import { Header } from './header/header'; @@ -28,7 +30,7 @@ export const Layout: FC> = (props) => { <>
- {dynamics.ipfsMode && ( + {ipfsMode && ( diff --git a/shared/components/local-link/index.tsx b/shared/components/local-link/index.tsx index f2379aa26..565d3c85f 100644 --- a/shared/components/local-link/index.tsx +++ b/shared/components/local-link/index.tsx @@ -2,7 +2,9 @@ import React, { FC, PropsWithChildren } from 'react'; import { useRouter } from 'next/router'; import Link, { LinkProps } from 'next/link'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { LinkIpfs } from 'shared/components/link-ipfs'; export const LocalLink: FC> = (props) => { @@ -18,7 +20,7 @@ export const LocalLink: FC> = (props) => { if (theme && typeof theme === 'string') extraQuery.theme = theme; if (typeof href === 'string') { - if (dynamics.ipfsMode) { + if (ipfsMode) { return ; } diff --git a/shared/hooks/use-compare-with-router-path.ts b/shared/hooks/use-compare-with-router-path.ts index e4b44ef24..71ec136d8 100644 --- a/shared/hooks/use-compare-with-router-path.ts +++ b/shared/hooks/use-compare-with-router-path.ts @@ -1,6 +1,9 @@ import { useMemo } from 'react'; import { useRouter } from 'next/router'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { compareWithRouterPathInIPFS, compareWithRouterPathInInfra, @@ -11,7 +14,7 @@ export const useCompareWithRouterPath = (href: string) => { return useMemo( () => - dynamics.ipfsMode + ipfsMode ? compareWithRouterPathInIPFS(router.asPath, href) : compareWithRouterPathInInfra(router.asPath, href), [router.asPath, href], diff --git a/shared/hooks/use-router-path.ts b/shared/hooks/use-router-path.ts index eeb1af928..d23771fbb 100644 --- a/shared/hooks/use-router-path.ts +++ b/shared/hooks/use-router-path.ts @@ -1,12 +1,17 @@ import { useRouter } from 'next/router'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + +// TODO import { isClientSide } from 'utils/isClientSide'; -import { dynamics } from 'config'; + import { HOME_PATH } from 'consts/urls'; export const useRouterPath = () => { const router = useRouter(); - if (dynamics.ipfsMode) { + if (ipfsMode) { if (!isClientSide()) return HOME_PATH; return location.hash.replace('#', '') || HOME_PATH; } diff --git a/shared/hooks/useLidoApr.ts b/shared/hooks/useLidoApr.ts index cc701b385..229add157 100644 --- a/shared/hooks/useLidoApr.ts +++ b/shared/hooks/useLidoApr.ts @@ -1,7 +1,10 @@ import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; import { CHAINS } from '@lido-sdk/constants'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ethAPIBasePath } = getOneConfig(); + import { standardFetcher } from 'utils/standardFetcher'; -import { dynamics } from 'config'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; type SMA_APR_RESPONSE = { @@ -53,7 +56,7 @@ export const useLidoApr = (): SWRResponse & { apr?: string; } => { const { data, ...rest } = useLidoSWR( - `${dynamics.ethAPIBasePath ?? ''}/v1/protocol/steth/apr/sma`, + `${ethAPIBasePath ?? ''}/v1/protocol/steth/apr/sma`, standardFetcher, STRATEGY_LAZY, ); diff --git a/shared/hooks/useLidoStats.ts b/shared/hooks/useLidoStats.ts index 350aa38d8..2593e4ede 100644 --- a/shared/hooks/useLidoStats.ts +++ b/shared/hooks/useLidoStats.ts @@ -1,7 +1,9 @@ import { useMemo } from 'react'; import { useSDK, useLidoSWR } from '@lido-sdk/react'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode, widgetApiBasePathForIpfs } = getOneConfig(); + import { DATA_UNAVAILABLE } from 'consts/text'; import { prependBasePath } from 'utils'; import { standardFetcher } from 'utils/standardFetcher'; @@ -25,8 +27,8 @@ export const useLidoStats = (): { const { chainId } = useSDK(); const apiShortLidoStatsPath = `api/short-lido-stats?chainId=${chainId}`; const lidoStats = useLidoSWR( - dynamics.ipfsMode - ? `${dynamics.widgetApiBasePathForIpfs}/${apiShortLidoStatsPath}` + ipfsMode + ? `${widgetApiBasePathForIpfs}/${apiShortLidoStatsPath}` : prependBasePath(apiShortLidoStatsPath), standardFetcher, STRATEGY_LAZY, diff --git a/shared/hooks/useWeb3Key.ts b/shared/hooks/useWeb3Key.ts index a314b4792..466f39d73 100644 --- a/shared/hooks/useWeb3Key.ts +++ b/shared/hooks/useWeb3Key.ts @@ -1,9 +1,11 @@ -import { dynamics } from 'config'; import { useWeb3 } from 'reef-knot/web3-react'; +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain } = getOneConfig(); + // In order to simplify side effects of switching wallets/chains // we can remount by this key, resetting all internal states export const useWeb3Key = () => { const { account, chainId } = useWeb3(); - return `${account ?? 'NO_ACCOUNT'}_${chainId ?? dynamics.defaultChain}`; + return `${account ?? 'NO_ACCOUNT'}_${chainId ?? defaultChain}`; }; diff --git a/utils/get-ipfs-base-path.ts b/utils/get-ipfs-base-path.ts index 69aecd26c..68d661e82 100644 --- a/utils/get-ipfs-base-path.ts +++ b/utils/get-ipfs-base-path.ts @@ -1,5 +1,8 @@ import memoize from 'lodash/memoize'; -import { dynamics } from 'config'; + +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + import { encodeURLQuery } from './encodeURLQuery'; export const getIpfsBasePath = memoize(() => { @@ -12,6 +15,6 @@ export const prefixUrl = (url: string, query?: Record) => { const queryString = query && Object.keys(query).length > 0 ? `?${encodeURLQuery(query)}` : ''; - if (dynamics.ipfsMode) return `${getIpfsBasePath()}${queryString}#${url}`; + if (ipfsMode) return `${getIpfsBasePath()}${queryString}#${url}`; return url; }; diff --git a/utils/qa.ts b/utils/qa.ts index 022bc263a..3c03b8023 100644 --- a/utils/qa.ts +++ b/utils/qa.ts @@ -1,3 +1,4 @@ -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +export const { enableQaHelpers } = getOneConfig(); -export const enableQaHelpers = dynamics.enableQaHelpers; +// TODO diff --git a/utilsApi/contractAddressesMetricsMap.ts b/utilsApi/contractAddressesMetricsMap.ts index fab4d39df..e9a236c94 100644 --- a/utilsApi/contractAddressesMetricsMap.ts +++ b/utilsApi/contractAddressesMetricsMap.ts @@ -14,7 +14,9 @@ import { WstethAbiFactory, } from '@lido-sdk/contracts'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { supportedChains } = getOneConfig(); + import { getAggregatorStEthUsdPriceFeedAddress } from 'consts/aggregator'; import { AggregatorAbi__factory, @@ -59,9 +61,7 @@ const getAddressOrNull = < } }; -export const METRIC_CONTRACT_ADDRESSES = ( - dynamics.supportedChains as CHAINS[] -).reduce( +export const METRIC_CONTRACT_ADDRESSES = (supportedChains as CHAINS[]).reduce( (mapped, chainId) => { const map = { [CONTRACT_NAMES.stETH]: getAddressOrNull( diff --git a/utilsApi/metrics/metrics.ts b/utilsApi/metrics/metrics.ts index f110be9b6..9fd790598 100644 --- a/utilsApi/metrics/metrics.ts +++ b/utilsApi/metrics/metrics.ts @@ -1,7 +1,9 @@ import { collectDefaultMetrics, Registry } from 'prom-client'; import { collectStartupMetrics } from '@lidofinance/api-metrics'; -import { dynamics } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain, supportedChains } = getOneConfig(); + import { METRICS_PREFIX } from 'consts/metrics'; import buildInfoJson from 'build-info.json'; @@ -24,8 +26,8 @@ class Metrics { collectStartupMetrics({ prefix: METRICS_PREFIX, registry: this.registry, - defaultChain: `${dynamics.defaultChain}`, - supportedChains: dynamics.supportedChains.map((chain) => `${chain}`), + defaultChain: `${defaultChain}`, + supportedChains: supportedChains.map((chain: number) => `${chain}`), version: buildInfoJson.version, commit: buildInfoJson.commit, branch: buildInfoJson.branch, diff --git a/utilsApi/withCSP.ts b/utilsApi/withCSP.ts index 49c078529..9a98a3949 100644 --- a/utilsApi/withCSP.ts +++ b/utilsApi/withCSP.ts @@ -1,12 +1,14 @@ import { FC } from 'react'; import { AppProps } from 'next/app'; -import getConfig from 'next/config'; import { withSecureHeaders } from 'next-secure-headers'; - -import { dynamics } from 'config'; import type { ContentSecurityPolicyOption } from 'next-secure-headers/lib/rules'; +import { getOneConfig } from 'config/one-config/utils'; +const { ipfsMode } = getOneConfig(); + +import getConfig from 'next/config'; const { serverRuntimeConfig } = getConfig(); + const { cspTrustedHosts, cspReportOnly, cspReportUri, developmentMode } = serverRuntimeConfig; @@ -36,7 +38,7 @@ export const contentSecurityPolicy: ContentSecurityPolicyOption = { ...(developmentMode ? ['ws:'] : []), ], - ...(!dynamics.ipfsMode && { + ...(!ipfsMode && { // CSP directive 'frame-ancestors' is ignored when delivered via a element. // CSP directive 'report-uri' is ignored when delivered via a element. frameAncestors: ['*'], From 7f9322006629019ca2a29dbf16e9cb6f55641c27 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sat, 24 Feb 2024 22:52:24 +0300 Subject: [PATCH 05/48] refactor: using dynamics through `one-config` --- config/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/index.ts b/config/index.ts index 5f33d6e5d..e45ea00cd 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,6 +1,6 @@ -import getConfig from 'next/config'; -export const { serverRuntimeConfig } = getConfig(); -export { default as dynamics } from './dynamics'; +// import getConfig from 'next/config'; +// export const { serverRuntimeConfig } = getConfig(); + export * from './cache'; export * from './estimate'; export * from './locale'; From de2f6f0ac4fda1296584eb4d7c4526680e985516 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 25 Feb 2024 00:19:05 +0300 Subject: [PATCH 06/48] refactor: moved utils/qa to one-config --- features/stake/stake-form/use-stake.ts | 8 ++++++-- .../swap-discount-banner/swap-discount-banner.tsx | 5 ++++- shared/hooks/use-router-path.ts | 5 +---- shared/hooks/useStakingLimitInfo.ts | 10 +++++++--- utils/chains.ts | 1 + utils/index.ts | 1 - utils/isClientSide.ts | 4 ---- utils/qa.ts | 4 ---- utils/swrStrategies.ts | 2 ++ 9 files changed, 21 insertions(+), 19 deletions(-) delete mode 100644 utils/isClientSide.ts delete mode 100644 utils/qa.ts diff --git a/features/stake/stake-form/use-stake.ts b/features/stake/stake-form/use-stake.ts index 8ef5107f6..d925f91de 100644 --- a/features/stake/stake-form/use-stake.ts +++ b/features/stake/stake-form/use-stake.ts @@ -4,7 +4,12 @@ import { useCallback } from 'react'; import { useWeb3 } from 'reef-knot/web3-react'; import invariant from 'tiny-invariant'; -import { enableQaHelpers, runWithTransactionLogger } from 'utils'; +import { runWithTransactionLogger } from 'utils'; + +import { STAKE_FALLBACK_REFERRAL_ADDRESS } from 'config'; +import { getOneConfig } from 'config/one-config/utils'; +export const { enableQaHelpers } = getOneConfig(); + import { getErrorMessage } from 'utils/getErrorMessage'; import { isContract } from 'utils/isContract'; import { TX_OPERATION, useTransactionModal } from 'shared/transaction-modal'; @@ -12,7 +17,6 @@ import { MockLimitReachedError, getAddress, applyGasLimitRatio } from './utils'; import { getFeeData } from 'utils/getFeeData'; import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; -import { STAKE_FALLBACK_REFERRAL_ADDRESS } from 'config'; type StakeArguments = { amount: BigNumber | null; diff --git a/features/stake/swap-discount-banner/swap-discount-banner.tsx b/features/stake/swap-discount-banner/swap-discount-banner.tsx index 866a5c154..52937a3b3 100644 --- a/features/stake/swap-discount-banner/swap-discount-banner.tsx +++ b/features/stake/swap-discount-banner/swap-discount-banner.tsx @@ -6,9 +6,12 @@ import { trackEvent } from '@lidofinance/analytics-matomo'; import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'consts/external-links'; + +import { getOneConfig } from 'config/one-config/utils'; +export const { enableQaHelpers } = getOneConfig(); + import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { getOpenOceanRate } from 'utils/get-open-ocean-rate'; -import { enableQaHelpers } from 'utils'; import { Wrap, TextWrap, OpenOceanIcon, OverlayLink } from './styles'; diff --git a/shared/hooks/use-router-path.ts b/shared/hooks/use-router-path.ts index d23771fbb..f79544e83 100644 --- a/shared/hooks/use-router-path.ts +++ b/shared/hooks/use-router-path.ts @@ -1,10 +1,7 @@ import { useRouter } from 'next/router'; import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); - -// TODO -import { isClientSide } from 'utils/isClientSide'; +const { ipfsMode, isClientSide } = getOneConfig(); import { HOME_PATH } from 'consts/urls'; diff --git a/shared/hooks/useStakingLimitInfo.ts b/shared/hooks/useStakingLimitInfo.ts index dd745e513..a2b384ea0 100644 --- a/shared/hooks/useStakingLimitInfo.ts +++ b/shared/hooks/useStakingLimitInfo.ts @@ -1,10 +1,14 @@ +import { BigNumber } from 'ethers'; +import useSwr from 'swr'; + import { parseEther } from '@ethersproject/units'; import { CHAINS } from '@lido-sdk/constants'; import { StethAbi } from '@lido-sdk/contracts'; import { useSDK, useSTETHContractRPC } from '@lido-sdk/react'; -import { enableQaHelpers } from 'utils'; -import useSwr from 'swr'; -import { BigNumber } from 'ethers'; + +import { getOneConfig } from 'config/one-config/utils'; +export const { enableQaHelpers } = getOneConfig(); + import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { LIMIT_LEVEL } from 'types'; diff --git a/utils/chains.ts b/utils/chains.ts index 2b2a5f95c..98249eb96 100644 --- a/utils/chains.ts +++ b/utils/chains.ts @@ -1,3 +1,4 @@ +// TODO: move to consts export const enum CHAINS { Mainnet = 1, Goerli = 5, diff --git a/utils/index.ts b/utils/index.ts index c0d24726d..bb31f01e3 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -8,7 +8,6 @@ export * from './weiToEth'; export * from './nprogress'; export * from './getErrorMessage'; export * from './parallelizePromises'; -export * from './qa'; export * from './extractErrorMessage'; export * from './swrAbortableMiddleware'; export * from './getNFTUrl'; diff --git a/utils/isClientSide.ts b/utils/isClientSide.ts deleted file mode 100644 index 6706cb60e..000000000 --- a/utils/isClientSide.ts +++ /dev/null @@ -1,4 +0,0 @@ -/* Deprecated: see one-config */ -export const isClientSide = () => { - return typeof window !== 'undefined'; -}; diff --git a/utils/qa.ts b/utils/qa.ts deleted file mode 100644 index 3c03b8023..000000000 --- a/utils/qa.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { getOneConfig } from 'config/one-config/utils'; -export const { enableQaHelpers } = getOneConfig(); - -// TODO diff --git a/utils/swrStrategies.ts b/utils/swrStrategies.ts index 13af19fba..5c55eca63 100644 --- a/utils/swrStrategies.ts +++ b/utils/swrStrategies.ts @@ -1,5 +1,7 @@ import type { SWRConfiguration } from 'swr'; +// TODO: move to consts + const MINUTE_MS = 1000 * 60; type StrategyConfig = Pick< From edae968f16602a4109f42ab702ab9639ff8b89dd Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 25 Feb 2024 00:57:52 +0300 Subject: [PATCH 07/48] refactor: client config (not finished) --- config/client-config/provider.tsx | 13 +++++-------- config/client-config/types.ts | 14 +------------- config/client-config/utils.ts | 27 ++++++++++++++++++--------- config/one-config/utils.ts | 4 +--- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/config/client-config/provider.tsx b/config/client-config/provider.tsx index 20eced727..ba4c26fe9 100644 --- a/config/client-config/provider.tsx +++ b/config/client-config/provider.tsx @@ -9,11 +9,10 @@ import { import { useLocalStorage } from '@lido-sdk/react'; import { STORAGE_CLIENT_CONFIG } from 'consts/storage'; -import * as dynamicsOnBackend from 'env-dynamics.mjs'; import { CHAINS } from 'utils/chains'; -import { parseEnvConfig } from './utils'; -import { EnvConfigParsed } from './types'; +import { getUserConfigDefault } from './utils'; +import { UserConfigDefaultType } from './types'; // TODO whole file: '*Сlient*' --> '*User*', 'client' --> 'user' @@ -21,7 +20,7 @@ type SavedClientConfig = { rpcUrls: Partial>; }; -type ClientConfigContext = EnvConfigParsed & { +type ClientConfigContext = UserConfigDefaultType & { savedClientConfig: SavedClientConfig; setSavedClientConfig: (config: SavedClientConfig) => void; }; @@ -53,12 +52,10 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => { ); const contextValue = useMemo(() => { - const envConfig = parseEnvConfig( - typeof window !== 'undefined' ? window.__env__ : dynamicsOnBackend, - ); + const userConfigDefault = getUserConfigDefault(); return { - ...envConfig, + ...userConfigDefault, savedClientConfig, setSavedClientConfig: setSavedConfigAndRemember, }; diff --git a/config/client-config/types.ts b/config/client-config/types.ts index c9743953c..4df670173 100644 --- a/config/client-config/types.ts +++ b/config/client-config/types.ts @@ -1,17 +1,6 @@ import { CHAINS } from 'utils/chains'; -// TODO: config/features/client-config/* -export type EnvConfigRaw = { - defaultChain: string | number; - supportedChains: number[]; - prefillUnsafeElRpcUrls1: string[]; - prefillUnsafeElRpcUrls5: string[]; - prefillUnsafeElRpcUrls17000: string[]; - ipfsMode: boolean; - walletconnectProjectId: string; -}; - -export type EnvConfigParsed = { +export type UserConfigDefaultType = { defaultChain: number; supportedChainIds: number[]; prefillUnsafeElRpcUrls: { @@ -19,6 +8,5 @@ export type EnvConfigParsed = { [CHAINS.Goerli]: string[]; [CHAINS.Holesky]: string[]; }; - ipfsMode: boolean; walletconnectProjectId: string; }; diff --git a/config/client-config/utils.ts b/config/client-config/utils.ts index f587b4af5..8d266eebd 100644 --- a/config/client-config/utils.ts +++ b/config/client-config/utils.ts @@ -1,16 +1,25 @@ -import { EnvConfigRaw, EnvConfigParsed } from 'config/client-config/types'; +import { UserConfigDefaultType } from 'config/client-config/types'; import { CHAINS } from 'utils/chains'; -export const parseEnvConfig = (envConfig: EnvConfigRaw): EnvConfigParsed => { +import { getOneConfig } from 'config/one-config/utils'; +const { + defaultChain, + supportedChains, + prefillUnsafeElRpcUrls1, + prefillUnsafeElRpcUrls5, + prefillUnsafeElRpcUrls17000, + walletconnectProjectId, +} = getOneConfig(); + +export const getUserConfigDefault = (): UserConfigDefaultType => { return { - defaultChain: Number(envConfig.defaultChain), - supportedChainIds: envConfig.supportedChains, + defaultChain: Number(defaultChain), + supportedChainIds: supportedChains, prefillUnsafeElRpcUrls: { - [CHAINS.Mainnet]: envConfig.prefillUnsafeElRpcUrls1, - [CHAINS.Goerli]: envConfig.prefillUnsafeElRpcUrls5, - [CHAINS.Holesky]: envConfig.prefillUnsafeElRpcUrls17000, + [CHAINS.Mainnet]: prefillUnsafeElRpcUrls1, + [CHAINS.Goerli]: prefillUnsafeElRpcUrls5, + [CHAINS.Holesky]: prefillUnsafeElRpcUrls17000, }, - ipfsMode: envConfig.ipfsMode, - walletconnectProjectId: envConfig.walletconnectProjectId, + walletconnectProjectId: walletconnectProjectId, }; }; diff --git a/config/one-config/utils.ts b/config/one-config/utils.ts index e6cfa99ed..8a9e27d06 100644 --- a/config/one-config/utils.ts +++ b/config/one-config/utils.ts @@ -11,9 +11,7 @@ export const getOneConfig = () => { return { isClientSide, isServerSide, - // ...dynamics, ...(typeof window !== 'undefined' ? window.__env__ : dynamics), - // ...serverRuntimeConfig, - ...(isServerSide && serverRuntimeConfig && { env: process.env }), + ...serverRuntimeConfig, }; }; From 66b8fb82c28d5d0ef24ea33a3b4ee1abb0a37e00 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 25 Feb 2024 01:15:52 +0300 Subject: [PATCH 08/48] refactor: using serverRuntimeConfig through `one-config` --- config/index.ts | 3 --- config/ipfs.ts | 7 +------ config/rateLimit.ts | 5 ++--- pages/api/rewards.ts | 5 ++--- pages/api/short-lido-stats.ts | 5 ++--- shared/hooks/useLidoSwr.ts | 7 +++---- utils/prependBasePath.ts | 6 ++---- utilsApi/getLdoStats.ts | 5 ++--- utilsApi/getLidoHoldersViaSubgraphs.ts | 8 ++++---- utilsApi/getLidoStats.ts | 5 ++--- utilsApi/getSmaStethApr.ts | 6 ++---- utilsApi/getSubgraphUrl.ts | 11 ++++++----- utilsApi/rpcUrls.ts | 5 ++--- utilsApi/withCSP.ts | 14 +++++++------- 14 files changed, 37 insertions(+), 55 deletions(-) diff --git a/config/index.ts b/config/index.ts index e45ea00cd..0e911f996 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,6 +1,3 @@ -// import getConfig from 'next/config'; -// export const { serverRuntimeConfig } = getConfig(); - export * from './cache'; export * from './estimate'; export * from './locale'; diff --git a/config/ipfs.ts b/config/ipfs.ts index d92e092bf..80a4f767f 100644 --- a/config/ipfs.ts +++ b/config/ipfs.ts @@ -1,10 +1,5 @@ -import getConfig from 'next/config'; - import { getOneConfig } from './one-config/utils'; -const { ipfsMode } = getOneConfig(); - -const { serverRuntimeConfig } = getConfig(); -const { basePath = '' } = serverRuntimeConfig; +const { ipfsMode, basePath = '' } = getOneConfig(); // TODO: move to OneConfig export const BASE_PATH_ASSET = ipfsMode ? '.' : basePath; diff --git a/config/rateLimit.ts b/config/rateLimit.ts index 49cbc0639..e92c5db34 100644 --- a/config/rateLimit.ts +++ b/config/rateLimit.ts @@ -1,6 +1,5 @@ -import getConfig from 'next/config'; -const { serverRuntimeConfig } = getConfig(); -const { rateLimit, rateLimitTimeFrame } = serverRuntimeConfig; +import { getOneConfig } from './one-config/utils'; +const { rateLimit, rateLimitTimeFrame = '' } = getOneConfig(); // TODO: move to OneConfig // requests per RATE_LIMIT_TIME_FRAME diff --git a/pages/api/rewards.ts b/pages/api/rewards.ts index 6b4b6e9d9..b4019b234 100644 --- a/pages/api/rewards.ts +++ b/pages/api/rewards.ts @@ -1,4 +1,3 @@ -import getConfig from 'next/config'; import { wrapRequest as wrapNextRequest, cacheControl, @@ -18,8 +17,8 @@ import { API_ROUTES } from 'consts/api'; import { API } from 'types'; import { standardFetcher } from 'utils/standardFetcher'; -const { serverRuntimeConfig } = getConfig(); -const { rewardsBackendAPI } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { rewardsBackendAPI } = getOneConfig(); const TIMEOUT = 10_000; diff --git a/pages/api/short-lido-stats.ts b/pages/api/short-lido-stats.ts index 75888080f..353020020 100644 --- a/pages/api/short-lido-stats.ts +++ b/pages/api/short-lido-stats.ts @@ -1,4 +1,3 @@ -import getConfig from 'next/config'; import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; @@ -19,8 +18,8 @@ import { import Metrics from 'utilsApi/metrics'; import { parallelizePromises } from 'utils'; -const { serverRuntimeConfig } = getConfig(); -const { defaultChain } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { defaultChain } = getOneConfig(); const cache = new Cache(); diff --git a/shared/hooks/useLidoSwr.ts b/shared/hooks/useLidoSwr.ts index 76142d6ea..10ec01fc7 100644 --- a/shared/hooks/useLidoSwr.ts +++ b/shared/hooks/useLidoSwr.ts @@ -1,10 +1,9 @@ -import { useLidoSWR as useLidoSWRDefault, SWRResponse } from '@lido-sdk/react'; import { SWRConfiguration } from 'swr'; -import getConfig from 'next/config'; +import { useLidoSWR as useLidoSWRDefault, SWRResponse } from '@lido-sdk/react'; import { standardFetcher } from 'utils/standardFetcher'; -const { serverRuntimeConfig } = getConfig(); -const { basePath } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { basePath = '' } = getOneConfig(); export const useLidoSWR = function ( path: string | null, diff --git a/utils/prependBasePath.ts b/utils/prependBasePath.ts index f7a3dc229..f08d8afda 100644 --- a/utils/prependBasePath.ts +++ b/utils/prependBasePath.ts @@ -1,7 +1,5 @@ -import getConfig from 'next/config'; - -const { serverRuntimeConfig } = getConfig(); -const { basePath } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { basePath } = getOneConfig(); export const prependBasePath = (route: string): string => { return `${basePath ?? ''}/${route}`; diff --git a/utilsApi/getLdoStats.ts b/utilsApi/getLdoStats.ts index b8a588a23..64955ce30 100644 --- a/utilsApi/getLdoStats.ts +++ b/utilsApi/getLdoStats.ts @@ -1,12 +1,11 @@ import { CHAINS } from 'utils/chains'; import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; -import getConfig from 'next/config'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -const { serverRuntimeConfig } = getConfig(); -const { ethplorerApiKey } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { ethplorerApiKey } = getOneConfig(); type GetLdoStats = () => Promise; diff --git a/utilsApi/getLidoHoldersViaSubgraphs.ts b/utilsApi/getLidoHoldersViaSubgraphs.ts index f9b3889c3..a499c3ac7 100644 --- a/utilsApi/getLidoHoldersViaSubgraphs.ts +++ b/utilsApi/getLidoHoldersViaSubgraphs.ts @@ -1,3 +1,4 @@ +import ms from 'ms'; import { Cache } from 'memory-cache'; import Metrics from 'utilsApi/metrics'; import { standardFetcher } from 'utils/standardFetcher'; @@ -7,9 +8,8 @@ import { CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY, CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL, } from 'config'; -import getConfig from 'next/config'; -import ms from 'ms'; -const { serverRuntimeConfig } = getConfig(); +import { getOneConfig } from 'config/one-config/utils'; +const { subgraphRequestTimeout } = getOneConfig(); const SUBGRAPH_ERROR_MESSAGE = '[getLidoHoldersViaSubgraphs] Subgraph request failed.'; @@ -46,7 +46,7 @@ export const getLidoHoldersViaSubgraphs: GetLidoHoldersViaSubgraphs = async ( const controller = new AbortController(); - const TIMEOUT = +serverRuntimeConfig.subgraphRequestTimeout || ms('5s'); + const TIMEOUT = +subgraphRequestTimeout || ms('5s'); const timeoutId = setTimeout(() => controller.abort(), TIMEOUT); const params = { diff --git a/utilsApi/getLidoStats.ts b/utilsApi/getLidoStats.ts index d5fc56a19..293182864 100644 --- a/utilsApi/getLidoStats.ts +++ b/utilsApi/getLidoStats.ts @@ -1,12 +1,11 @@ -import getConfig from 'next/config'; import { TOKENS, getTokenAddress, CHAINS } from '@lido-sdk/constants'; import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -const { serverRuntimeConfig } = getConfig(); -const { ethplorerApiKey } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { ethplorerApiKey } = getOneConfig(); type GetLidoStats = () => Promise; diff --git a/utilsApi/getSmaStethApr.ts b/utilsApi/getSmaStethApr.ts index b88331966..d589e9c08 100644 --- a/utilsApi/getSmaStethApr.ts +++ b/utilsApi/getSmaStethApr.ts @@ -1,11 +1,9 @@ -import getConfig from 'next/config'; import { CHAINS } from 'utils/chains'; - import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -const { serverRuntimeConfig } = getConfig(); -const { ethAPIBasePath } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { ethAPIBasePath } = getOneConfig(); type SMA_APR_RESPONSE = { data: { diff --git a/utilsApi/getSubgraphUrl.ts b/utilsApi/getSubgraphUrl.ts index 7343f5cf1..e73925b0a 100644 --- a/utilsApi/getSubgraphUrl.ts +++ b/utilsApi/getSubgraphUrl.ts @@ -1,12 +1,13 @@ -import getConfig from 'next/config'; import { CHAINS } from 'utils/chains'; import { SubgraphChains } from 'types'; -const { serverRuntimeConfig } = getConfig(); +import { getOneConfig } from 'config/one-config/utils'; +const { subgraphMainnet, subgraphGoerli, subgraphHolesky } = getOneConfig(); + export const SUBGRAPH_URL = { - [CHAINS.Mainnet]: serverRuntimeConfig.subgraphMainnet, - [CHAINS.Goerli]: serverRuntimeConfig.subgraphGoerli, - [CHAINS.Holesky]: serverRuntimeConfig.subgraphHolesky, + [CHAINS.Mainnet]: subgraphMainnet, + [CHAINS.Goerli]: subgraphGoerli, + [CHAINS.Holesky]: subgraphHolesky, } as const; export const getSubgraphUrl = (chainId: SubgraphChains): string | undefined => { diff --git a/utilsApi/rpcUrls.ts b/utilsApi/rpcUrls.ts index 27d5855fe..868f824ce 100644 --- a/utilsApi/rpcUrls.ts +++ b/utilsApi/rpcUrls.ts @@ -1,8 +1,7 @@ -import getConfig from 'next/config'; import { CHAINS } from 'utils/chains'; -const { serverRuntimeConfig } = getConfig(); -const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = serverRuntimeConfig; +import { getOneConfig } from 'config/one-config/utils'; +const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = getOneConfig(); export const rpcUrls: Record = { [CHAINS.Mainnet]: rpcUrls_1, diff --git a/utilsApi/withCSP.ts b/utilsApi/withCSP.ts index 9a98a3949..4e06b7ab1 100644 --- a/utilsApi/withCSP.ts +++ b/utilsApi/withCSP.ts @@ -4,13 +4,13 @@ import { withSecureHeaders } from 'next-secure-headers'; import type { ContentSecurityPolicyOption } from 'next-secure-headers/lib/rules'; import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); - -import getConfig from 'next/config'; -const { serverRuntimeConfig } = getConfig(); - -const { cspTrustedHosts, cspReportOnly, cspReportUri, developmentMode } = - serverRuntimeConfig; +const { + cspTrustedHosts, + cspReportOnly, + cspReportUri, + developmentMode, + ipfsMode, +} = getOneConfig(); const trustedHosts = cspTrustedHosts ? cspTrustedHosts.split(',') : []; From e4512606fe40e62360db5bdd09bf6a26a5193a0f Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 25 Feb 2024 21:39:34 +0300 Subject: [PATCH 09/48] refactor: using 'getConfig' from 'config' --- config/client-config/utils.ts | 4 +- config/{one-config => }/dynamics.ts | 6 ++ config/get-config.ts | 56 +++++++++++++++++++ config/{ => groups}/cache.ts | 2 - config/groups/estimate.ts | 7 +++ config/groups/ipfs.ts | 7 +++ config/{ => groups}/locale.ts | 0 config/{ => groups}/stake.ts | 18 +----- .../withdrawal-queue-estimate.ts} | 11 ---- config/index.ts | 9 +-- config/ipfs.ts | 8 --- config/one-config/provider.tsx | 16 ------ config/one-config/utils.ts | 17 ------ config/provider.tsx | 16 ++++++ config/rateLimit.ts | 7 --- config/rpc.ts | 5 +- config/{one-config/hooks.ts => use-config.ts} | 6 +- .../rewards/components/CopyAddressUrl.tsx | 4 +- features/rewards/components/IndexerLink.tsx | 4 +- features/rewards/components/stats/Stats.tsx | 4 +- .../fetchers/requesters/json/backend.ts | 4 +- .../fetchers/requesters/rpc/stEthEth.ts | 4 +- features/rewards/hooks/useRewardsDataLoad.ts | 4 +- features/stake/lido-stats/lido-stats.tsx | 4 +- features/stake/stake-form/hooks.ts | 12 ++-- .../stake-form-context/stake-form-context.tsx | 4 +- features/stake/stake-form/use-stake.ts | 5 +- features/stake/stake-form/utils.ts | 6 +- .../swap-discount-banner.tsx | 4 +- features/withdrawals/hooks/useWaitingTime.ts | 4 +- .../withdrawals/hooks/useWithdrawTxPrice.ts | 25 ++++----- .../list/unstake-amount-boundaries.tsx | 4 +- .../unwrap/hooks/use-unwrap-gas-limit.ts | 5 +- .../wrap/hooks/use-approve-gas-limit.tsx | 4 +- .../wsteth/wrap/hooks/use-wrap-gas-limit.ts | 4 +- next.config.mjs | 5 +- pages/_app.tsx | 4 +- pages/_document.tsx | 6 +- pages/api/eth-apr.ts | 5 +- pages/api/eth-price.ts | 9 ++- pages/api/ldo-stats.ts | 4 +- pages/api/lido-stats.ts | 3 +- pages/api/oneinch-rate.ts | 4 +- pages/api/rewards.ts | 5 +- pages/api/rpc.ts | 4 +- pages/api/short-lido-stats.ts | 6 +- pages/api/sma-steth-apr.ts | 5 +- pages/index.tsx | 4 +- pages/settings.tsx | 4 +- providers/index.tsx | 6 +- providers/inpage-navigation.tsx | 7 +-- providers/web3.tsx | 8 ++- shared/banners/curve/useCurve.ts | 4 +- .../header/components/header-wallet.tsx | 4 +- shared/components/layout/layout.tsx | 4 +- shared/components/local-link/index.tsx | 4 +- shared/formatters/format-date.tsx | 4 +- shared/formatters/format-percent.tsx | 4 +- shared/formatters/format-price.tsx | 5 +- shared/hooks/use-compare-with-router-path.ts | 4 +- shared/hooks/use-router-path.ts | 4 +- shared/hooks/useLidoApr.ts | 4 +- shared/hooks/useLidoStats.ts | 4 +- shared/hooks/useLidoSwr.ts | 4 +- shared/hooks/useStakingLimitInfo.ts | 4 +- shared/hooks/useWeb3Key.ts | 4 +- utils/get-ipfs-base-path.ts | 4 +- utils/prependBasePath.ts | 4 +- utilsApi/contractAddressesMetricsMap.ts | 4 +- utilsApi/getLdoStats.ts | 4 +- utilsApi/getLidoHoldersViaSubgraphs.ts | 17 +++--- utilsApi/getLidoStats.ts | 4 +- utilsApi/getSmaStethApr.ts | 4 +- utilsApi/getSubgraphUrl.ts | 4 +- utilsApi/metrics/metrics.ts | 4 +- utilsApi/nextApiWrappers.ts | 13 +++-- utilsApi/rpcUrls.ts | 4 +- utilsApi/withCSP.ts | 6 +- 78 files changed, 285 insertions(+), 233 deletions(-) rename config/{one-config => }/dynamics.ts (70%) create mode 100644 config/get-config.ts rename config/{ => groups}/cache.ts (97%) create mode 100644 config/groups/estimate.ts create mode 100644 config/groups/ipfs.ts rename config/{ => groups}/locale.ts (100%) rename config/{ => groups}/stake.ts (55%) rename config/{estimate.ts => groups/withdrawal-queue-estimate.ts} (52%) delete mode 100644 config/ipfs.ts delete mode 100644 config/one-config/provider.tsx delete mode 100644 config/one-config/utils.ts create mode 100644 config/provider.tsx delete mode 100644 config/rateLimit.ts rename config/{one-config/hooks.ts => use-config.ts} (56%) diff --git a/config/client-config/utils.ts b/config/client-config/utils.ts index 8d266eebd..63e2ac57f 100644 --- a/config/client-config/utils.ts +++ b/config/client-config/utils.ts @@ -1,7 +1,7 @@ import { UserConfigDefaultType } from 'config/client-config/types'; import { CHAINS } from 'utils/chains'; -import { getOneConfig } from 'config/one-config/utils'; +import { getConfig } from 'config'; const { defaultChain, supportedChains, @@ -9,7 +9,7 @@ const { prefillUnsafeElRpcUrls5, prefillUnsafeElRpcUrls17000, walletconnectProjectId, -} = getOneConfig(); +} = getConfig(); export const getUserConfigDefault = (): UserConfigDefaultType => { return { diff --git a/config/one-config/dynamics.ts b/config/dynamics.ts similarity index 70% rename from config/one-config/dynamics.ts rename to config/dynamics.ts index 9633e4c6d..a15bcd00d 100644 --- a/config/one-config/dynamics.ts +++ b/config/dynamics.ts @@ -9,4 +9,10 @@ declare global { } } +// Not use dynamics directly! +// Only through: +// code``` +// import { getConfig } from 'config'; +// const { ... } = getConfig(); +// ``` export default typeof window !== 'undefined' ? window.__env__ : dynamics; diff --git a/config/get-config.ts b/config/get-config.ts new file mode 100644 index 000000000..f814496f2 --- /dev/null +++ b/config/get-config.ts @@ -0,0 +1,56 @@ +import { AddressZero } from '@ethersproject/constants'; + +import getConfigNext from 'next/config'; +const { serverRuntimeConfig, publicRuntimeConfig } = getConfigNext(); + +import { default as dynamics } from './dynamics'; +import * as cache from './groups/cache'; +import * as estimate from './groups/estimate'; +import * as ipfs from './groups/ipfs'; +import * as locale from './groups/locale'; +import * as stake from './groups/stake'; +import * as withdrawalQueueEstimate from './groups/withdrawal-queue-estimate'; + +// TODO: type serverRuntimeConfig? +// type ConfigType = { isClientSide: boolean, isServerSide: boolean } +// & typeof cache +// & typeof estimate +// & typeof ipfs +// & typeof locale +// & typeof rateLimit +// & typeof rateLimit +// & typeof stake +// & typeof withdrawalQueueEstimate +// & typeof dynamics; + +export const getConfig = (): any => { + const isClientSide = typeof window !== 'undefined'; + const isServerSide = typeof window === 'undefined'; + + const STAKE_FALLBACK_REFERRAL_ADDRESS = dynamics.ipfsMode + ? ipfs.IPFS_REFERRAL_ADDRESS + : AddressZero; + const BASE_PATH_ASSET = dynamics.ipfsMode + ? '.' + : serverRuntimeConfig.basePath || publicRuntimeConfig.basePath; + + return { + isClientSide, + isServerSide, + + ...cache, + ...estimate, + + ...ipfs, + ...locale, + ...stake, + ...withdrawalQueueEstimate, + + STAKE_FALLBACK_REFERRAL_ADDRESS, + BASE_PATH_ASSET, + + // highest priority + ...(typeof window !== 'undefined' ? window.__env__ : dynamics), + ...serverRuntimeConfig, + }; +}; diff --git a/config/cache.ts b/config/groups/cache.ts similarity index 97% rename from config/cache.ts rename to config/groups/cache.ts index c3f7a4202..9d0a050e5 100644 --- a/config/cache.ts +++ b/config/groups/cache.ts @@ -1,7 +1,5 @@ import ms from 'ms'; -// TODO: move to './config/values/cache.ts' - export const CACHE_STETH_APR_KEY = 'cache-steth-apr'; export const CACHE_STETH_APR_TTL = ms('1h'); diff --git a/config/groups/estimate.ts b/config/groups/estimate.ts new file mode 100644 index 000000000..5717db655 --- /dev/null +++ b/config/groups/estimate.ts @@ -0,0 +1,7 @@ +import { parseEther } from '@ethersproject/units'; +// account for gas estimation +// will always have >=0.001 ether, >=0.001 stETH, >=0.001 wstETH +// on Mainnet, Goerli, Holesky +export const ESTIMATE_ACCOUNT = '0x87c0e047F4e4D3e289A56a36570D4CB957A37Ef1'; + +export const ESTIMATE_AMOUNT = parseEther('0.001'); diff --git a/config/groups/ipfs.ts b/config/groups/ipfs.ts new file mode 100644 index 000000000..b2f657265 --- /dev/null +++ b/config/groups/ipfs.ts @@ -0,0 +1,7 @@ +// import { getConfig } from '../get-config'; +// const { ipfsMode, basePath = '' } = getConfig(); +// +// export const BASE_PATH_ASSET = ipfsMode ? '.' : basePath; + +export const IPFS_REFERRAL_ADDRESS = + '0x74d6e4Fd83A0b5623BDE3B2dF9a9A7F31fE02325'; diff --git a/config/locale.ts b/config/groups/locale.ts similarity index 100% rename from config/locale.ts rename to config/groups/locale.ts diff --git a/config/stake.ts b/config/groups/stake.ts similarity index 55% rename from config/stake.ts rename to config/groups/stake.ts index 8e26495b4..57ba7c013 100644 --- a/config/stake.ts +++ b/config/groups/stake.ts @@ -1,33 +1,21 @@ import { BigNumber } from 'ethers'; import { parseEther } from '@ethersproject/units'; -import { AddressZero } from '@ethersproject/constants'; -import { getOneConfig } from './one-config/utils'; -const { ipfsMode } = getOneConfig(); - -import { IPFS_REFERRAL_ADDRESS } from './ipfs'; - -// TODO: const export const PRECISION = 10 ** 6; -// TODO: const // how much to leave out on user balance when max is pressed export const BALANCE_PADDING = parseEther('0.01'); -// TODO: const export const SUBMIT_EXTRA_GAS_TRANSACTION_RATIO = 1.05; -// TODO: const export const STETH_SUBMIT_GAS_LIMIT_DEFAULT = 90000; -// TODO: const export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( Math.floor( STETH_SUBMIT_GAS_LIMIT_DEFAULT * SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, ), ); -// TODO: move to OneConfig -export const STAKE_FALLBACK_REFERRAL_ADDRESS = ipfsMode - ? IPFS_REFERRAL_ADDRESS - : AddressZero; +// export const STAKE_FALLBACK_REFERRAL_ADDRESS = ipfsMode +// ? IPFS_REFERRAL_ADDRESS +// : AddressZero; diff --git a/config/estimate.ts b/config/groups/withdrawal-queue-estimate.ts similarity index 52% rename from config/estimate.ts rename to config/groups/withdrawal-queue-estimate.ts index f83c2ab42..f4faff395 100644 --- a/config/estimate.ts +++ b/config/groups/withdrawal-queue-estimate.ts @@ -1,14 +1,3 @@ -import { parseEther } from '@ethersproject/units'; -// account for gas estimation -// will always have >=0.001 ether, >=0.001 stETH, >=0.001 wstETH -// on Mainnet, Goerli, Holesky -// TODO: move to OneConfig -export const ESTIMATE_ACCOUNT = '0x87c0e047F4e4D3e289A56a36570D4CB957A37Ef1'; - -// TODO: const -export const ESTIMATE_AMOUNT = parseEther('0.001'); - -// TODO: TO CONFIG/WITHDRAWAL_QUEUE_ESTIMATE.TS // fallback gas limits per 1 withdraw request export const WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT = 255350; export const WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT = 312626; diff --git a/config/index.ts b/config/index.ts index 0e911f996..098e6adb2 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,7 +1,4 @@ -export * from './cache'; -export * from './estimate'; -export * from './locale'; -export * from './ipfs'; +export * from './get-config'; +export * from './provider'; export * from './rpc'; -export * from './rateLimit'; -export * from './stake'; +export * from './use-config'; diff --git a/config/ipfs.ts b/config/ipfs.ts deleted file mode 100644 index 80a4f767f..000000000 --- a/config/ipfs.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { getOneConfig } from './one-config/utils'; -const { ipfsMode, basePath = '' } = getOneConfig(); - -// TODO: move to OneConfig -export const BASE_PATH_ASSET = ipfsMode ? '.' : basePath; -// TODO: move to OneConfig -export const IPFS_REFERRAL_ADDRESS = - '0x74d6e4Fd83A0b5623BDE3B2dF9a9A7F31fE02325'; diff --git a/config/one-config/provider.tsx b/config/one-config/provider.tsx deleted file mode 100644 index c1d1ba718..000000000 --- a/config/one-config/provider.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import { PropsWithChildren, createContext } from 'react'; - -import { getOneConfig } from './utils'; - -export const OneConfigContext = createContext(null); - -export const OneConfigProvider = ({ children }: PropsWithChildren) => { - // TODO: check object destructuring is fast or use memo? - const contextValue = getOneConfig(); - - return ( - - {children} - - ); -}; diff --git a/config/one-config/utils.ts b/config/one-config/utils.ts deleted file mode 100644 index 8a9e27d06..000000000 --- a/config/one-config/utils.ts +++ /dev/null @@ -1,17 +0,0 @@ -import getConfig from 'next/config'; -const { serverRuntimeConfig } = getConfig(); - -import { default as dynamics } from './dynamics'; - -// TODO: add return type -export const getOneConfig = () => { - const isClientSide = typeof window !== 'undefined'; - const isServerSide = typeof window === 'undefined'; - - return { - isClientSide, - isServerSide, - ...(typeof window !== 'undefined' ? window.__env__ : dynamics), - ...serverRuntimeConfig, - }; -}; diff --git a/config/provider.tsx b/config/provider.tsx new file mode 100644 index 000000000..632951a4e --- /dev/null +++ b/config/provider.tsx @@ -0,0 +1,16 @@ +import { PropsWithChildren, createContext } from 'react'; + +import { getConfig } from './get-config'; + +export const ConfigContext = createContext(null); + +export const ConfigProvider = ({ children }: PropsWithChildren) => { + // TODO: check object destructuring is fast or use memo? + const contextValue = getConfig(); + + return ( + + {children} + + ); +}; diff --git a/config/rateLimit.ts b/config/rateLimit.ts deleted file mode 100644 index e92c5db34..000000000 --- a/config/rateLimit.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { getOneConfig } from './one-config/utils'; -const { rateLimit, rateLimitTimeFrame = '' } = getOneConfig(); - -// TODO: move to OneConfig -// requests per RATE_LIMIT_TIME_FRAME -export const RATE_LIMIT = rateLimit; -export const RATE_LIMIT_TIME_FRAME = rateLimitTimeFrame; diff --git a/config/rpc.ts b/config/rpc.ts index 1ba0a0ce7..ccfecf503 100644 --- a/config/rpc.ts +++ b/config/rpc.ts @@ -5,10 +5,9 @@ import { useSDK } from '@lido-sdk/react'; import { useClientConfig } from './client-config/hooks'; import { CHAINS } from 'utils/chains'; -import { getOneConfig } from './one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from './get-config'; +const { ipfsMode } = getConfig(); -// TODO: one config export const getBackendRPCPath = (chainId: string | number): string => { const BASE_URL = typeof window === 'undefined' ? '' : window.location.origin; return `${BASE_URL}/api/rpc?chainId=${chainId}`; diff --git a/config/one-config/hooks.ts b/config/use-config.ts similarity index 56% rename from config/one-config/hooks.ts rename to config/use-config.ts index d4725f29a..70eec2b85 100644 --- a/config/one-config/hooks.ts +++ b/config/use-config.ts @@ -1,9 +1,9 @@ import { useContext } from 'react'; import invariant from 'tiny-invariant'; -import { OneConfigContext } from './provider'; +import { ConfigContext } from './provider'; -export const useOneConfig = () => { - const context = useContext(OneConfigContext); +export const useConfig = () => { + const context = useContext(ConfigContext); invariant(context, 'Attempt to use `one config` outside of provider'); return context; }; diff --git a/features/rewards/components/CopyAddressUrl.tsx b/features/rewards/components/CopyAddressUrl.tsx index 3bdab4a0a..6f25a415e 100644 --- a/features/rewards/components/CopyAddressUrl.tsx +++ b/features/rewards/components/CopyAddressUrl.tsx @@ -1,8 +1,8 @@ import { useMemo } from 'react'; import { ButtonIcon, Copy } from '@lidofinance/lido-ui'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { useCopyToClipboard } from 'shared/hooks'; import { getBasedHashHref } from 'utils/get-based-hash-href'; diff --git a/features/rewards/components/IndexerLink.tsx b/features/rewards/components/IndexerLink.tsx index 1812a0a4e..1ec1ba0f6 100644 --- a/features/rewards/components/IndexerLink.tsx +++ b/features/rewards/components/IndexerLink.tsx @@ -1,8 +1,8 @@ import { Box, External as ExternalLinkIcon } from '@lidofinance/lido-ui'; import { getEtherscanTxLink } from '@lido-sdk/helpers'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain } = getConfig(); // TODO: move to separate folders type Props = { diff --git a/features/rewards/components/stats/Stats.tsx b/features/rewards/components/stats/Stats.tsx index 94ebbd9b7..06fb8a046 100644 --- a/features/rewards/components/stats/Stats.tsx +++ b/features/rewards/components/stats/Stats.tsx @@ -6,8 +6,8 @@ import { Box, Link } from '@lidofinance/lido-ui'; import { useSDK, useTokenBalance } from '@lido-sdk/react'; import { TOKENS, getTokenAddress } from '@lido-sdk/constants'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain } = getConfig(); import { stEthEthRequest } from 'features/rewards/fetchers/requesters'; import EthSymbol from 'features/rewards/components/EthSymbol'; diff --git a/features/rewards/fetchers/requesters/json/backend.ts b/features/rewards/fetchers/requesters/json/backend.ts index d22f6b0aa..5d5d03976 100644 --- a/features/rewards/fetchers/requesters/json/backend.ts +++ b/features/rewards/fetchers/requesters/json/backend.ts @@ -1,5 +1,5 @@ -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode, widgetApiBasePathForIpfs } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); export type BackendQuery = { address: string; diff --git a/features/rewards/fetchers/requesters/rpc/stEthEth.ts b/features/rewards/fetchers/requesters/rpc/stEthEth.ts index a76291b8e..a3ed2a784 100644 --- a/features/rewards/fetchers/requesters/rpc/stEthEth.ts +++ b/features/rewards/fetchers/requesters/rpc/stEthEth.ts @@ -2,8 +2,8 @@ import { constants } from 'ethers'; import type { BigNumber as EthersBigNumber } from 'ethers'; import { StaticJsonRpcBatchProvider } from '@lidofinance/eth-providers'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain } = getConfig(); import rpcFetch from 'features/rewards/fetchers/rpcFetch'; diff --git a/features/rewards/hooks/useRewardsDataLoad.ts b/features/rewards/hooks/useRewardsDataLoad.ts index 0a76a54c3..670f7e711 100644 --- a/features/rewards/hooks/useRewardsDataLoad.ts +++ b/features/rewards/hooks/useRewardsDataLoad.ts @@ -1,7 +1,7 @@ import { useEffect, useRef } from 'react'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode, widgetApiBasePathForIpfs } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); import { Backend } from 'features/rewards/types'; import { useLidoSWR } from 'shared/hooks'; diff --git a/features/stake/lido-stats/lido-stats.tsx b/features/stake/lido-stats/lido-stats.tsx index ee00de3ad..5d1d4bb46 100644 --- a/features/stake/lido-stats/lido-stats.tsx +++ b/features/stake/lido-stats/lido-stats.tsx @@ -8,8 +8,8 @@ import { Block, DataTable, Question, Tooltip } from '@lidofinance/lido-ui'; import { Section, MatomoLink } from 'shared/components'; import { useLidoApr, useLidoStats } from 'shared/hooks'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { LIDO_APR_TOOLTIP_TEXT } from 'consts/text'; import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; diff --git a/features/stake/stake-form/hooks.ts b/features/stake/stake-form/hooks.ts index b7137a02d..18ff4809a 100644 --- a/features/stake/stake-form/hooks.ts +++ b/features/stake/stake-form/hooks.ts @@ -1,11 +1,11 @@ +import { BigNumber } from 'ethers'; import { AddressZero } from '@ethersproject/constants'; import { useLidoSWR, useSDK, useSTETHContractRPC } from '@lido-sdk/react'; -import { - ESTIMATE_ACCOUNT, - ESTIMATE_AMOUNT, - STAKE_GASLIMIT_FALLBACK, -} from 'config'; -import { BigNumber } from 'ethers'; + +import { getConfig } from 'config'; +const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT, STAKE_GASLIMIT_FALLBACK } = + getConfig(); + import { STRATEGY_CONSTANT } from 'utils/swrStrategies'; import { applyGasLimitRatio } from './utils'; diff --git a/features/stake/stake-form/stake-form-context/stake-form-context.tsx b/features/stake/stake-form/stake-form-context/stake-form-context.tsx index 3fe205198..aa70c8180 100644 --- a/features/stake/stake-form/stake-form-context/stake-form-context.tsx +++ b/features/stake/stake-form/stake-form-context/stake-form-context.tsx @@ -34,7 +34,9 @@ import { type StakeFormNetworkData, } from './types'; import { useTokenMaxAmount } from 'shared/hooks/use-token-max-amount'; -import { BALANCE_PADDING } from 'config'; + +import { getConfig } from 'config'; +const { BALANCE_PADDING } = getConfig(); // // Data context diff --git a/features/stake/stake-form/use-stake.ts b/features/stake/stake-form/use-stake.ts index d925f91de..0be437238 100644 --- a/features/stake/stake-form/use-stake.ts +++ b/features/stake/stake-form/use-stake.ts @@ -6,9 +6,8 @@ import invariant from 'tiny-invariant'; import { runWithTransactionLogger } from 'utils'; -import { STAKE_FALLBACK_REFERRAL_ADDRESS } from 'config'; -import { getOneConfig } from 'config/one-config/utils'; -export const { enableQaHelpers } = getOneConfig(); +import { getConfig } from 'config'; +const { enableQaHelpers, STAKE_FALLBACK_REFERRAL_ADDRESS } = getConfig(); import { getErrorMessage } from 'utils/getErrorMessage'; import { isContract } from 'utils/isContract'; diff --git a/features/stake/stake-form/utils.ts b/features/stake/stake-form/utils.ts index b048e48ef..a83e9b200 100644 --- a/features/stake/stake-form/utils.ts +++ b/features/stake/stake-form/utils.ts @@ -1,7 +1,9 @@ +import { BigNumber } from 'ethers'; import { isAddress } from 'ethers/lib/utils'; import type { BaseProvider } from '@ethersproject/providers'; -import { BigNumber } from 'ethers'; -import { SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, PRECISION } from 'config'; + +import { getConfig } from 'config'; +const { SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, PRECISION } = getConfig(); export const applyGasLimitRatio = (gasLimit: BigNumber): BigNumber => gasLimit.mul(SUBMIT_EXTRA_GAS_TRANSACTION_RATIO * PRECISION).div(PRECISION); diff --git a/features/stake/swap-discount-banner/swap-discount-banner.tsx b/features/stake/swap-discount-banner/swap-discount-banner.tsx index 52937a3b3..bfb47512c 100644 --- a/features/stake/swap-discount-banner/swap-discount-banner.tsx +++ b/features/stake/swap-discount-banner/swap-discount-banner.tsx @@ -7,8 +7,8 @@ import { trackEvent } from '@lidofinance/analytics-matomo'; import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'consts/external-links'; -import { getOneConfig } from 'config/one-config/utils'; -export const { enableQaHelpers } = getOneConfig(); +import { getConfig } from 'config'; +const { enableQaHelpers } = getConfig(); import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { getOpenOceanRate } from 'utils/get-open-ocean-rate'; diff --git a/features/withdrawals/hooks/useWaitingTime.ts b/features/withdrawals/hooks/useWaitingTime.ts index cf1205474..61a98bfd7 100644 --- a/features/withdrawals/hooks/useWaitingTime.ts +++ b/features/withdrawals/hooks/useWaitingTime.ts @@ -1,8 +1,8 @@ import { useMemo } from 'react'; import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; -import { getOneConfig } from 'config/one-config/utils'; -const { wqAPIBasePath } = getOneConfig(); +import { getConfig } from 'config'; +const { wqAPIBasePath } = getConfig(); import { useDebouncedValue } from 'shared/hooks'; import { encodeURLQuery } from 'utils/encodeURLQuery'; diff --git a/features/withdrawals/hooks/useWithdrawTxPrice.ts b/features/withdrawals/hooks/useWithdrawTxPrice.ts index 2e31228c5..60746cb5b 100644 --- a/features/withdrawals/hooks/useWithdrawTxPrice.ts +++ b/features/withdrawals/hooks/useWithdrawTxPrice.ts @@ -1,30 +1,29 @@ import { useMemo } from 'react'; +import { BigNumber } from 'ethers'; +import invariant from 'tiny-invariant'; +import { useWeb3 } from 'reef-knot/web3-react'; +import { TOKENS } from '@lido-sdk/constants'; import { useLidoSWR, useSDK } from '@lido-sdk/react'; -import { standardFetcher } from 'utils/standardFetcher'; -import { + +import { getConfig } from 'config'; +const { ESTIMATE_ACCOUNT, WITHDRAWAL_QUEUE_CLAIM_GAS_LIMIT_DEFAULT, WITHDRAWAL_QUEUE_REQUEST_STETH_APPROVED_GAS_LIMIT_DEFAULT, WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT, WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT, WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT, -} from 'config'; - -import { getOneConfig } from 'config/one-config/utils'; -const { wqAPIBasePath } = getOneConfig(); + wqAPIBasePath, +} = getConfig(); import { MAX_REQUESTS_COUNT } from 'features/withdrawals/withdrawals-constants'; - -import { useWeb3 } from 'reef-knot/web3-react'; -import { TOKENS } from '@lido-sdk/constants'; - -import { useWithdrawalsContract } from './contract/useWithdrawalsContract'; import { useTxCostInUsd } from 'shared/hooks/txCost'; import { useDebouncedValue } from 'shared/hooks/useDebouncedValue'; import { encodeURLQuery } from 'utils/encodeURLQuery'; -import { BigNumber } from 'ethers'; -import invariant from 'tiny-invariant'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { standardFetcher } from 'utils/standardFetcher'; + +import { useWithdrawalsContract } from './contract/useWithdrawalsContract'; import { RequestStatusClaimable } from '../types/request-status'; type UseRequestTxPriceOptions = { diff --git a/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx b/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx index 58f8050d2..3ce38ac93 100644 --- a/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx +++ b/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx @@ -1,9 +1,11 @@ import { Accordion } from '@lidofinance/lido-ui'; import { weiToEth } from 'utils'; -import { LOCALE } from 'config'; import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; +import { getConfig } from 'config'; +const { LOCALE } = getConfig(); + const formatAmount = (value: number | undefined) => value ? value.toLocaleString(LOCALE, { maximumFractionDigits: 18 }) : '...'; diff --git a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts index 0bfc555db..b62063121 100644 --- a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts +++ b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts @@ -1,5 +1,8 @@ import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; -import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } from 'config/estimate'; + +import { getConfig } from 'config'; +const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); + import { UNWRAP_GAS_LIMIT } from 'consts/tx'; import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; diff --git a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx index 2750d392d..3c3fefd54 100644 --- a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx +++ b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx @@ -6,10 +6,12 @@ import { useWSTETHContractRPC, } from '@lido-sdk/react'; -import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } from 'config/estimate'; import { WSTETH_APPROVE_GAS_LIMIT } from 'consts/tx'; import { STRATEGY_IMMUTABLE } from 'utils/swrStrategies'; +import { getConfig } from 'config'; +const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); + export const useApproveGasLimit = () => { const steth = useSTETHContractRPC(); const wsteth = useWSTETHContractRPC(); diff --git a/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts b/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts index 7bad9f757..63f140cde 100644 --- a/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts +++ b/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts @@ -2,13 +2,15 @@ import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; import { useWeb3 } from 'reef-knot/web3-react'; import { CHAINS } from '@lido-sdk/constants'; -import { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } from 'config/estimate'; import { WRAP_FROM_ETH_GAS_LIMIT, WRAP_GAS_LIMIT, WRAP_GAS_LIMIT_GOERLI, } from 'consts/tx'; +import { getConfig } from 'config'; +const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); + import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; import { applyGasLimitRatio } from 'features/stake/stake-form/utils'; diff --git a/next.config.mjs b/next.config.mjs index 324af3b91..1259062d8 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -7,7 +7,7 @@ buildDynamics(); const ipfsMode = process.env.IPFS_MODE; // https://nextjs.org/docs/pages/api-reference/next-config-js/basePath -const basePath = process.env.BASE_PATH; +const basePath = process.env.BASE_PATH ?? ''; const rpcUrls_1 = process.env.EL_RPC_URLS_1?.split(',') ?? []; const rpcUrls_5 = process.env.EL_RPC_URLS_5?.split(',') ?? []; @@ -182,4 +182,7 @@ export default withBundleAnalyzer({ defaultChain, developmentMode, }, + publicRuntimeConfig: { + basePath, + }, }); diff --git a/pages/_app.tsx b/pages/_app.tsx index 4d779c484..a925d6e1a 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -9,8 +9,8 @@ import { migrationThemeCookiesToCrossDomainCookiesClientSide, } from '@lidofinance/lido-ui'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { Providers } from 'providers'; import { BackgroundGradient } from 'shared/components/background-gradient/background-gradient'; diff --git a/pages/_document.tsx b/pages/_document.tsx index 4b238529b..e7ceb23fe 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -10,10 +10,8 @@ import { createHeadersObject } from 'next-secure-headers'; import { ServerStyleSheet } from 'styled-components'; import { Fonts, LidoUIHead } from '@lidofinance/lido-ui'; -import { BASE_PATH_ASSET } from 'config'; - -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain, ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { BASE_PATH_ASSET, defaultChain, ipfsMode } = getConfig(); import { InsertIpfsBaseScript } from 'features/ipfs/ipfs-base-script'; import { contentSecurityPolicy } from 'utilsApi/withCSP'; diff --git a/pages/api/eth-apr.ts b/pages/api/eth-apr.ts index 8693a061c..41a1988e0 100644 --- a/pages/api/eth-apr.ts +++ b/pages/api/eth-apr.ts @@ -1,6 +1,9 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_ETH_APR_KEY, CACHE_ETH_APR_TTL } from 'config/cache'; + +import { getConfig } from 'config'; +const { CACHE_ETH_APR_KEY, CACHE_ETH_APR_TTL } = getConfig(); + import { API_ROUTES } from 'consts/api'; import { getEthApr, diff --git a/pages/api/eth-price.ts b/pages/api/eth-price.ts index 4908b57a1..e196db6e8 100644 --- a/pages/api/eth-price.ts +++ b/pages/api/eth-price.ts @@ -4,11 +4,10 @@ import { cacheControl, } from '@lidofinance/next-api-wrapper'; -import { - CACHE_ETH_PRICE_KEY, - CACHE_ETH_PRICE_TTL, - CACHE_ETH_PRICE_HEADERS, -} from 'config/cache'; +import { getConfig } from 'config'; +const { CACHE_ETH_PRICE_KEY, CACHE_ETH_PRICE_TTL, CACHE_ETH_PRICE_HEADERS } = + getConfig(); + import { API_ROUTES } from 'consts/api'; import { getEthPrice, diff --git a/pages/api/ldo-stats.ts b/pages/api/ldo-stats.ts index f0e2b1860..5e0da1382 100644 --- a/pages/api/ldo-stats.ts +++ b/pages/api/ldo-stats.ts @@ -1,7 +1,9 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LDO_STATS_KEY, CACHE_LDO_STATS_TTL } from 'config/cache'; +import { getConfig } from 'config'; +const { CACHE_LDO_STATS_KEY, CACHE_LDO_STATS_TTL } = getConfig(); + import { API_ROUTES } from 'consts/api'; import { getLdoStats, diff --git a/pages/api/lido-stats.ts b/pages/api/lido-stats.ts index 9b64b4968..9b4feadf6 100644 --- a/pages/api/lido-stats.ts +++ b/pages/api/lido-stats.ts @@ -1,6 +1,7 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } from 'config/cache'; +import { getConfig } from 'config'; +const { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } = getConfig(); import { API_ROUTES } from 'consts/api'; import { diff --git a/pages/api/oneinch-rate.ts b/pages/api/oneinch-rate.ts index 2602d1b22..60a34e479 100644 --- a/pages/api/oneinch-rate.ts +++ b/pages/api/oneinch-rate.ts @@ -5,7 +5,9 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; import { CHAINS, TOKENS, getTokenAddress } from '@lido-sdk/constants'; -import { CACHE_ONE_INCH_RATE_KEY, CACHE_ONE_INCH_RATE_TTL } from 'config'; +import { getConfig } from 'config'; +const { CACHE_ONE_INCH_RATE_KEY, CACHE_ONE_INCH_RATE_TTL } = getConfig(); + import { API_ROUTES } from 'consts/api'; import { getOneInchRate, diff --git a/pages/api/rewards.ts b/pages/api/rewards.ts index b4019b234..292ee96de 100644 --- a/pages/api/rewards.ts +++ b/pages/api/rewards.ts @@ -12,13 +12,12 @@ import { cors, } from 'utilsApi'; import Metrics from 'utilsApi/metrics'; -import { CACHE_REWARDS_HEADERS } from 'config/cache'; import { API_ROUTES } from 'consts/api'; import { API } from 'types'; import { standardFetcher } from 'utils/standardFetcher'; -import { getOneConfig } from 'config/one-config/utils'; -const { rewardsBackendAPI } = getOneConfig(); +import { getConfig } from 'config'; +const { rewardsBackendAPI, CACHE_REWARDS_HEADERS } = getConfig(); const TIMEOUT = 10_000; diff --git a/pages/api/rpc.ts b/pages/api/rpc.ts index 4bffcec2e..5be35db28 100644 --- a/pages/api/rpc.ts +++ b/pages/api/rpc.ts @@ -1,8 +1,8 @@ import { rpcFactory } from '@lidofinance/next-pages'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain } = getConfig(); import { API_ROUTES } from 'consts/api'; import { METRICS_PREFIX } from 'consts/metrics'; diff --git a/pages/api/short-lido-stats.ts b/pages/api/short-lido-stats.ts index 353020020..3f0c8a405 100644 --- a/pages/api/short-lido-stats.ts +++ b/pages/api/short-lido-stats.ts @@ -1,7 +1,6 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LIDO_SHORT_STATS_KEY, CACHE_LIDO_SHORT_STATS_TTL } from 'config'; import { API_ROUTES } from 'consts/api'; import { API, SubgraphChains } from 'types'; import { @@ -18,8 +17,9 @@ import { import Metrics from 'utilsApi/metrics'; import { parallelizePromises } from 'utils'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain, CACHE_LIDO_SHORT_STATS_KEY, CACHE_LIDO_SHORT_STATS_TTL } = + getConfig(); const cache = new Cache(); diff --git a/pages/api/sma-steth-apr.ts b/pages/api/sma-steth-apr.ts index 0323f8e9b..9d79da491 100644 --- a/pages/api/sma-steth-apr.ts +++ b/pages/api/sma-steth-apr.ts @@ -1,7 +1,10 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; import { API } from 'types'; -import { CACHE_SMA_STETH_APR_KEY, CACHE_SMA_STETH_APR_TTL } from 'config'; + +import { getConfig } from 'config'; +const { CACHE_SMA_STETH_APR_KEY, CACHE_SMA_STETH_APR_TTL } = getConfig(); + import { API_ROUTES } from 'consts/api'; import { responseTimeMetric, diff --git a/pages/index.tsx b/pages/index.tsx index c3abd8e44..b066262ba 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,5 +1,5 @@ -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { StakePage } from 'features/stake'; import HomePageIpfs from 'features/ipfs/home-page-ipfs'; diff --git a/pages/settings.tsx b/pages/settings.tsx index 32889c97c..293a475dc 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,9 +1,9 @@ import { FC } from 'react'; import { GetStaticProps } from 'next'; +import { getConfig } from 'config'; import { Layout } from 'shared/components'; import { SettingsForm } from 'features/settings/settings-form'; -import { getOneConfig } from 'config/one-config/utils'; const Settings: FC = () => { return ( @@ -16,7 +16,7 @@ const Settings: FC = () => { export default Settings; export const getStaticProps: GetStaticProps = async () => { - const { ipfsMode } = getOneConfig(); + const { ipfsMode } = getConfig(); if (!ipfsMode) return { notFound: true }; return { props: {} }; diff --git a/providers/index.tsx b/providers/index.tsx index 8a86abc7d..dec32657e 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -3,7 +3,7 @@ import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; import { ClientConfigProvider } from 'config/client-config/provider'; -import { OneConfigProvider } from 'config/one-config/provider'; +import { ConfigProvider } from 'config'; import { AppFlagProvider } from './app-flag'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; @@ -14,7 +14,7 @@ import Web3Provider from './web3'; export { MODAL, ModalContext } from './modals'; export const Providers: FC = ({ children }) => ( - + @@ -29,5 +29,5 @@ export const Providers: FC = ({ children }) => ( - + ); diff --git a/providers/inpage-navigation.tsx b/providers/inpage-navigation.tsx index afeb26cc2..77301ddda 100644 --- a/providers/inpage-navigation.tsx +++ b/providers/inpage-navigation.tsx @@ -9,12 +9,11 @@ import { useEffect, } from 'react'; import invariant from 'tiny-invariant'; - -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); - import { useRouter } from 'next/router'; +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); + export type InpageNavigationContextValue = { hashNav: string; navigateInpageAnchor: (e: React.MouseEvent) => void; diff --git a/providers/web3.tsx b/providers/web3.tsx index 45642d94d..37fae2d21 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -8,13 +8,15 @@ import { CHAINS } from 'utils/chains'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; import { useClientConfig } from 'config/client-config/hooks'; -import { useGetRpcUrlByChainId } from 'config'; -import { getOneConfig } from 'config/one-config/utils'; +// TODO +import { useGetRpcUrlByChainId } from 'config/rpc'; + +import { getConfig } from 'config'; const { defaultChain: defaultChainFromConfig, supportedChains: supportedChainsFromConfig, -} = getOneConfig(); +} = getConfig(); const Web3Provider: FC = ({ children }) => { const { defaultChain, supportedChainIds, walletconnectProjectId } = diff --git a/shared/banners/curve/useCurve.ts b/shared/banners/curve/useCurve.ts index ae310f296..c26290fa1 100644 --- a/shared/banners/curve/useCurve.ts +++ b/shared/banners/curve/useCurve.ts @@ -1,7 +1,7 @@ import { useLidoSWR } from '@lido-sdk/react'; -import { getOneConfig } from 'config/one-config/utils'; -const { ethAPIBasePath } = getOneConfig(); +import { getConfig } from 'config'; +const { ethAPIBasePath } = getConfig(); import { standardFetcher } from 'utils/standardFetcher'; diff --git a/shared/components/layout/header/components/header-wallet.tsx b/shared/components/layout/header/components/header-wallet.tsx index 132f237cc..b3f51fc38 100644 --- a/shared/components/layout/header/components/header-wallet.tsx +++ b/shared/components/layout/header/components/header-wallet.tsx @@ -6,8 +6,8 @@ import { CHAINS, getChainColor } from '@lido-sdk/constants'; import { ThemeToggler } from '@lidofinance/lido-ui'; import NoSSRWrapper from '../../../no-ssr-wrapper'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box'; import { Button, Connect } from 'shared/wallet'; diff --git a/shared/components/layout/layout.tsx b/shared/components/layout/layout.tsx index 208a46d89..1fd5a6b11 100644 --- a/shared/components/layout/layout.tsx +++ b/shared/components/layout/layout.tsx @@ -2,8 +2,8 @@ import { ReactNode, FC, PropsWithChildren } from 'react'; import { ContainerProps } from '@lidofinance/lido-ui'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box'; diff --git a/shared/components/local-link/index.tsx b/shared/components/local-link/index.tsx index 565d3c85f..db91ff80c 100644 --- a/shared/components/local-link/index.tsx +++ b/shared/components/local-link/index.tsx @@ -2,8 +2,8 @@ import React, { FC, PropsWithChildren } from 'react'; import { useRouter } from 'next/router'; import Link, { LinkProps } from 'next/link'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { LinkIpfs } from 'shared/components/link-ipfs'; diff --git a/shared/formatters/format-date.tsx b/shared/formatters/format-date.tsx index 91a34a40d..8fb04c424 100644 --- a/shared/formatters/format-date.tsx +++ b/shared/formatters/format-date.tsx @@ -1,7 +1,9 @@ -import { LOCALE } from 'config'; import { memo } from 'react'; import { Component } from 'types'; +import { getConfig } from 'config'; +const { LOCALE } = getConfig(); + export type FormatDateComponent = Component<'time', { timeStamp: number }>; export const FormatDate: FormatDateComponent = memo((props) => { const { timeStamp, ...rest } = props; diff --git a/shared/formatters/format-percent.tsx b/shared/formatters/format-percent.tsx index 6d5091ccf..61d468661 100644 --- a/shared/formatters/format-percent.tsx +++ b/shared/formatters/format-percent.tsx @@ -1,6 +1,8 @@ -import { LOCALE } from 'config'; import { Component } from 'types'; +import { getConfig } from 'config'; +const { LOCALE } = getConfig(); + export type FormatPercentComponent = Component< 'span', { amount: number | null } diff --git a/shared/formatters/format-price.tsx b/shared/formatters/format-price.tsx index f415384f2..4df473cec 100644 --- a/shared/formatters/format-price.tsx +++ b/shared/formatters/format-price.tsx @@ -1,6 +1,9 @@ import { Tooltip } from '@lidofinance/lido-ui'; -import { LOCALE } from 'config'; import { DATA_UNAVAILABLE } from 'consts/text'; + +import { getConfig } from 'config'; +const { LOCALE } = getConfig(); + import { Component } from 'types'; export type FormatPriceComponent = Component< diff --git a/shared/hooks/use-compare-with-router-path.ts b/shared/hooks/use-compare-with-router-path.ts index 71ec136d8..49c9c4c21 100644 --- a/shared/hooks/use-compare-with-router-path.ts +++ b/shared/hooks/use-compare-with-router-path.ts @@ -1,8 +1,8 @@ import { useMemo } from 'react'; import { useRouter } from 'next/router'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { compareWithRouterPathInIPFS, diff --git a/shared/hooks/use-router-path.ts b/shared/hooks/use-router-path.ts index f79544e83..2a472f3b5 100644 --- a/shared/hooks/use-router-path.ts +++ b/shared/hooks/use-router-path.ts @@ -1,7 +1,7 @@ import { useRouter } from 'next/router'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode, isClientSide } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode, isClientSide } = getConfig(); import { HOME_PATH } from 'consts/urls'; diff --git a/shared/hooks/useLidoApr.ts b/shared/hooks/useLidoApr.ts index 229add157..cfca17a5f 100644 --- a/shared/hooks/useLidoApr.ts +++ b/shared/hooks/useLidoApr.ts @@ -1,8 +1,8 @@ import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; import { CHAINS } from '@lido-sdk/constants'; -import { getOneConfig } from 'config/one-config/utils'; -const { ethAPIBasePath } = getOneConfig(); +import { getConfig } from 'config'; +const { ethAPIBasePath } = getConfig(); import { standardFetcher } from 'utils/standardFetcher'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; diff --git a/shared/hooks/useLidoStats.ts b/shared/hooks/useLidoStats.ts index 2593e4ede..1a926b94d 100644 --- a/shared/hooks/useLidoStats.ts +++ b/shared/hooks/useLidoStats.ts @@ -1,8 +1,8 @@ import { useMemo } from 'react'; import { useSDK, useLidoSWR } from '@lido-sdk/react'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode, widgetApiBasePathForIpfs } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); import { DATA_UNAVAILABLE } from 'consts/text'; import { prependBasePath } from 'utils'; diff --git a/shared/hooks/useLidoSwr.ts b/shared/hooks/useLidoSwr.ts index 10ec01fc7..da22e82b6 100644 --- a/shared/hooks/useLidoSwr.ts +++ b/shared/hooks/useLidoSwr.ts @@ -2,8 +2,8 @@ import { SWRConfiguration } from 'swr'; import { useLidoSWR as useLidoSWRDefault, SWRResponse } from '@lido-sdk/react'; import { standardFetcher } from 'utils/standardFetcher'; -import { getOneConfig } from 'config/one-config/utils'; -const { basePath = '' } = getOneConfig(); +import { getConfig } from 'config'; +const { basePath = '' } = getConfig(); export const useLidoSWR = function ( path: string | null, diff --git a/shared/hooks/useStakingLimitInfo.ts b/shared/hooks/useStakingLimitInfo.ts index a2b384ea0..bdb9cad0f 100644 --- a/shared/hooks/useStakingLimitInfo.ts +++ b/shared/hooks/useStakingLimitInfo.ts @@ -6,8 +6,8 @@ import { CHAINS } from '@lido-sdk/constants'; import { StethAbi } from '@lido-sdk/contracts'; import { useSDK, useSTETHContractRPC } from '@lido-sdk/react'; -import { getOneConfig } from 'config/one-config/utils'; -export const { enableQaHelpers } = getOneConfig(); +import { getConfig } from 'config'; +const { enableQaHelpers } = getConfig(); import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { LIMIT_LEVEL } from 'types'; diff --git a/shared/hooks/useWeb3Key.ts b/shared/hooks/useWeb3Key.ts index 466f39d73..30b09a6d6 100644 --- a/shared/hooks/useWeb3Key.ts +++ b/shared/hooks/useWeb3Key.ts @@ -1,7 +1,7 @@ import { useWeb3 } from 'reef-knot/web3-react'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain } = getConfig(); // In order to simplify side effects of switching wallets/chains // we can remount by this key, resetting all internal states diff --git a/utils/get-ipfs-base-path.ts b/utils/get-ipfs-base-path.ts index 68d661e82..f2ca3db04 100644 --- a/utils/get-ipfs-base-path.ts +++ b/utils/get-ipfs-base-path.ts @@ -1,7 +1,7 @@ import memoize from 'lodash/memoize'; -import { getOneConfig } from 'config/one-config/utils'; -const { ipfsMode } = getOneConfig(); +import { getConfig } from 'config'; +const { ipfsMode } = getConfig(); import { encodeURLQuery } from './encodeURLQuery'; diff --git a/utils/prependBasePath.ts b/utils/prependBasePath.ts index f08d8afda..e2ddb1115 100644 --- a/utils/prependBasePath.ts +++ b/utils/prependBasePath.ts @@ -1,5 +1,5 @@ -import { getOneConfig } from 'config/one-config/utils'; -const { basePath } = getOneConfig(); +import { getConfig } from 'config'; +const { basePath } = getConfig(); export const prependBasePath = (route: string): string => { return `${basePath ?? ''}/${route}`; diff --git a/utilsApi/contractAddressesMetricsMap.ts b/utilsApi/contractAddressesMetricsMap.ts index e9a236c94..6ba474d1f 100644 --- a/utilsApi/contractAddressesMetricsMap.ts +++ b/utilsApi/contractAddressesMetricsMap.ts @@ -14,8 +14,8 @@ import { WstethAbiFactory, } from '@lido-sdk/contracts'; -import { getOneConfig } from 'config/one-config/utils'; -const { supportedChains } = getOneConfig(); +import { getConfig } from 'config'; +const { supportedChains } = getConfig(); import { getAggregatorStEthUsdPriceFeedAddress } from 'consts/aggregator'; import { diff --git a/utilsApi/getLdoStats.ts b/utilsApi/getLdoStats.ts index 64955ce30..f94fd42eb 100644 --- a/utilsApi/getLdoStats.ts +++ b/utilsApi/getLdoStats.ts @@ -4,8 +4,8 @@ import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -import { getOneConfig } from 'config/one-config/utils'; -const { ethplorerApiKey } = getOneConfig(); +import { getConfig } from 'config'; +const { ethplorerApiKey } = getConfig(); type GetLdoStats = () => Promise; diff --git a/utilsApi/getLidoHoldersViaSubgraphs.ts b/utilsApi/getLidoHoldersViaSubgraphs.ts index a499c3ac7..83737d33d 100644 --- a/utilsApi/getLidoHoldersViaSubgraphs.ts +++ b/utilsApi/getLidoHoldersViaSubgraphs.ts @@ -1,15 +1,18 @@ import ms from 'ms'; import { Cache } from 'memory-cache'; -import Metrics from 'utilsApi/metrics'; -import { standardFetcher } from 'utils/standardFetcher'; + import { SubgraphChains } from 'types'; -import { getSubgraphUrl } from './getSubgraphUrl'; -import { +import { getConfig } from 'config'; +const { + subgraphRequestTimeout, CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY, CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL, -} from 'config'; -import { getOneConfig } from 'config/one-config/utils'; -const { subgraphRequestTimeout } = getOneConfig(); +} = getConfig(); + +import Metrics from 'utilsApi/metrics'; +import { standardFetcher } from 'utils/standardFetcher'; + +import { getSubgraphUrl } from './getSubgraphUrl'; const SUBGRAPH_ERROR_MESSAGE = '[getLidoHoldersViaSubgraphs] Subgraph request failed.'; diff --git a/utilsApi/getLidoStats.ts b/utilsApi/getLidoStats.ts index 293182864..6f55c4ba2 100644 --- a/utilsApi/getLidoStats.ts +++ b/utilsApi/getLidoStats.ts @@ -4,8 +4,8 @@ import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -import { getOneConfig } from 'config/one-config/utils'; -const { ethplorerApiKey } = getOneConfig(); +import { getConfig } from 'config'; +const { ethplorerApiKey } = getConfig(); type GetLidoStats = () => Promise; diff --git a/utilsApi/getSmaStethApr.ts b/utilsApi/getSmaStethApr.ts index d589e9c08..4736aa553 100644 --- a/utilsApi/getSmaStethApr.ts +++ b/utilsApi/getSmaStethApr.ts @@ -2,8 +2,8 @@ import { CHAINS } from 'utils/chains'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -import { getOneConfig } from 'config/one-config/utils'; -const { ethAPIBasePath } = getOneConfig(); +import { getConfig } from 'config'; +const { ethAPIBasePath } = getConfig(); type SMA_APR_RESPONSE = { data: { diff --git a/utilsApi/getSubgraphUrl.ts b/utilsApi/getSubgraphUrl.ts index e73925b0a..e3b1d9567 100644 --- a/utilsApi/getSubgraphUrl.ts +++ b/utilsApi/getSubgraphUrl.ts @@ -1,8 +1,8 @@ import { CHAINS } from 'utils/chains'; import { SubgraphChains } from 'types'; -import { getOneConfig } from 'config/one-config/utils'; -const { subgraphMainnet, subgraphGoerli, subgraphHolesky } = getOneConfig(); +import { getConfig } from 'config'; +const { subgraphMainnet, subgraphGoerli, subgraphHolesky } = getConfig(); export const SUBGRAPH_URL = { [CHAINS.Mainnet]: subgraphMainnet, diff --git a/utilsApi/metrics/metrics.ts b/utilsApi/metrics/metrics.ts index 9fd790598..c06386e93 100644 --- a/utilsApi/metrics/metrics.ts +++ b/utilsApi/metrics/metrics.ts @@ -1,8 +1,8 @@ import { collectDefaultMetrics, Registry } from 'prom-client'; import { collectStartupMetrics } from '@lidofinance/api-metrics'; -import { getOneConfig } from 'config/one-config/utils'; -const { defaultChain, supportedChains } = getOneConfig(); +import { getConfig } from 'config'; +const { defaultChain, supportedChains } = getConfig(); import { METRICS_PREFIX } from 'consts/metrics'; import buildInfoJson from 'build-info.json'; diff --git a/utilsApi/nextApiWrappers.ts b/utilsApi/nextApiWrappers.ts index ace9c4bd4..9a1065e76 100644 --- a/utilsApi/nextApiWrappers.ts +++ b/utilsApi/nextApiWrappers.ts @@ -9,11 +9,14 @@ import { DEFAULT_API_ERROR_MESSAGE, } from '@lidofinance/next-api-wrapper'; import { rateLimitWrapper } from '@lidofinance/next-ip-rate-limit'; -import { + +import { getConfig } from 'config'; +const { CACHE_DEFAULT_HEADERS, - RATE_LIMIT, - RATE_LIMIT_TIME_FRAME, -} from 'config'; + rateLimit: RATE_LIMIT, + rateLimitTimeFrame = '', +} = getConfig(); + import { getMetricContractInterface, METRIC_CONTRACT_ADDRESSES, @@ -178,7 +181,7 @@ export const requestAddressMetric = export const rateLimit = rateLimitWrapper({ rateLimit: RATE_LIMIT, - rateLimitTimeFrame: RATE_LIMIT_TIME_FRAME, + rateLimitTimeFrame, }); export const nextDefaultErrorHandler = diff --git a/utilsApi/rpcUrls.ts b/utilsApi/rpcUrls.ts index 868f824ce..a7c85ab54 100644 --- a/utilsApi/rpcUrls.ts +++ b/utilsApi/rpcUrls.ts @@ -1,7 +1,7 @@ import { CHAINS } from 'utils/chains'; -import { getOneConfig } from 'config/one-config/utils'; -const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = getOneConfig(); +import { getConfig } from 'config'; +const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = getConfig(); export const rpcUrls: Record = { [CHAINS.Mainnet]: rpcUrls_1, diff --git a/utilsApi/withCSP.ts b/utilsApi/withCSP.ts index 4e06b7ab1..f7d8e6d79 100644 --- a/utilsApi/withCSP.ts +++ b/utilsApi/withCSP.ts @@ -3,19 +3,21 @@ import { AppProps } from 'next/app'; import { withSecureHeaders } from 'next-secure-headers'; import type { ContentSecurityPolicyOption } from 'next-secure-headers/lib/rules'; -import { getOneConfig } from 'config/one-config/utils'; +import { getConfig } from 'config'; const { cspTrustedHosts, cspReportOnly, cspReportUri, developmentMode, ipfsMode, -} = getOneConfig(); +} = getConfig(); const trustedHosts = cspTrustedHosts ? cspTrustedHosts.split(',') : []; const reportOnly = cspReportOnly == 'true'; +// TODO: move to config/csp + export const contentSecurityPolicy: ContentSecurityPolicyOption = { directives: { 'default-src': ["'self'"], From f3af549e87d95c51beb910a4659baaab91fc96f5 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 09:13:17 +0300 Subject: [PATCH 10/48] refactor: using 'getConfig' from 'config' --- config/get-config.ts | 3 +++ config/groups/ipfs.ts | 5 ----- config/groups/stake.ts | 4 ---- features/settings/settings-form/settings-form.tsx | 1 + 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/config/get-config.ts b/config/get-config.ts index f814496f2..fcdeb2fea 100644 --- a/config/get-config.ts +++ b/config/get-config.ts @@ -27,9 +27,12 @@ export const getConfig = (): any => { const isClientSide = typeof window !== 'undefined'; const isServerSide = typeof window === 'undefined'; + // TODO: another place const STAKE_FALLBACK_REFERRAL_ADDRESS = dynamics.ipfsMode ? ipfs.IPFS_REFERRAL_ADDRESS : AddressZero; + + // TODO: another place const BASE_PATH_ASSET = dynamics.ipfsMode ? '.' : serverRuntimeConfig.basePath || publicRuntimeConfig.basePath; diff --git a/config/groups/ipfs.ts b/config/groups/ipfs.ts index b2f657265..2d6c5b460 100644 --- a/config/groups/ipfs.ts +++ b/config/groups/ipfs.ts @@ -1,7 +1,2 @@ -// import { getConfig } from '../get-config'; -// const { ipfsMode, basePath = '' } = getConfig(); -// -// export const BASE_PATH_ASSET = ipfsMode ? '.' : basePath; - export const IPFS_REFERRAL_ADDRESS = '0x74d6e4Fd83A0b5623BDE3B2dF9a9A7F31fE02325'; diff --git a/config/groups/stake.ts b/config/groups/stake.ts index 57ba7c013..d12f936b0 100644 --- a/config/groups/stake.ts +++ b/config/groups/stake.ts @@ -15,7 +15,3 @@ export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( STETH_SUBMIT_GAS_LIMIT_DEFAULT * SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, ), ); - -// export const STAKE_FALLBACK_REFERRAL_ADDRESS = ipfsMode -// ? IPFS_REFERRAL_ADDRESS -// : AddressZero; diff --git a/features/settings/settings-form/settings-form.tsx b/features/settings/settings-form/settings-form.tsx index f87e1d40e..0370bae96 100644 --- a/features/settings/settings-form/settings-form.tsx +++ b/features/settings/settings-form/settings-form.tsx @@ -4,6 +4,7 @@ import { useForm } from 'react-hook-form'; import { useSDK } from '@lido-sdk/react'; import { Button, ToastSuccess, Block, Input } from '@lidofinance/lido-ui'; +// TODO import { useClientConfig } from 'config/client-config/hooks'; import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; import { RPCErrorType, checkRpcUrl } from 'utils/check-rpc-url'; From 44d57ae2cbd2e75878ab87a2c7f4dd92aa2a9ec2 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 09:13:35 +0300 Subject: [PATCH 11/48] refactor: using 'getConfig' from 'config' --- .../wsteth/wrap/hooks/use-wrap-form-network-data.ts | 10 +++++++--- pages/api/lidostats.ts | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts b/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts index 0a24a3baf..807e2e858 100644 --- a/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts +++ b/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts @@ -4,13 +4,17 @@ import { useSTETHBalance, useEthereumBalance, } from '@lido-sdk/react'; -import { useWrapGasLimit } from './use-wrap-gas-limit'; + +import { getConfig } from 'config'; +const { BALANCE_PADDING } = getConfig(); + import { useIsMultisig } from 'shared/hooks/useIsMultisig'; import { useTokenMaxAmount } from 'shared/hooks/use-token-max-amount'; +import { useMaxGasPrice, useStakingLimitInfo } from 'shared/hooks'; import { STRATEGY_LAZY } from 'utils/swrStrategies'; -import { useMaxGasPrice, useStakingLimitInfo } from 'shared/hooks'; -import { BALANCE_PADDING } from 'config'; + +import { useWrapGasLimit } from './use-wrap-gas-limit'; // Provides all data fetching for form to function export const useWrapFormNetworkData = () => { diff --git a/pages/api/lidostats.ts b/pages/api/lidostats.ts index 777a9427c..77c6db20f 100644 --- a/pages/api/lidostats.ts +++ b/pages/api/lidostats.ts @@ -1,6 +1,9 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } from 'config'; + +import { getConfig } from 'config'; +const { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } = getConfig(); + import { API_ROUTES } from 'consts/api'; import { getLidoStats, From e933f0ac0ce2ed62336cbceb58e4296260d83ee5 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 09:46:23 +0300 Subject: [PATCH 12/48] refactor: using 'getConfig' from 'config' --- pages/api/totalsupply.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pages/api/totalsupply.ts b/pages/api/totalsupply.ts index 5acad8bd0..9a8b66976 100644 --- a/pages/api/totalsupply.ts +++ b/pages/api/totalsupply.ts @@ -3,11 +3,14 @@ import { wrapRequest as wrapNextRequest, cacheControl, } from '@lidofinance/next-api-wrapper'; -import { + +import { getConfig } from 'config'; +const { CACHE_TOTAL_SUPPLY_KEY, CACHE_TOTAL_SUPPLY_TTL, CACHE_TOTAL_SUPPLY_HEADERS, -} from 'config'; +} = getConfig(); + import { API_ROUTES } from 'consts/api'; import { getTotalStaked, From e6521c72327f8857f2e3d365dd76f4f9f02dc81d Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 09:47:40 +0300 Subject: [PATCH 13/48] refactor: imports config/rpc --- config/index.ts | 3 ++- config/user-config/index.ts | 4 ++++ providers/ipfs-info-box-statuses.tsx | 3 ++- providers/web3.tsx | 11 ++++------- 4 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 config/user-config/index.ts diff --git a/config/index.ts b/config/index.ts index 098e6adb2..aacfcbf8c 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,4 +1,5 @@ export * from './get-config'; export * from './provider'; -export * from './rpc'; export * from './use-config'; +export * from './rpc/index'; +export * from './user-config/index'; diff --git a/config/user-config/index.ts b/config/user-config/index.ts new file mode 100644 index 000000000..bb01ff006 --- /dev/null +++ b/config/user-config/index.ts @@ -0,0 +1,4 @@ +export * from './hooks'; +export * from './provider'; +export * from './types'; +export * from './utils'; diff --git a/providers/ipfs-info-box-statuses.tsx b/providers/ipfs-info-box-statuses.tsx index 23dd21f6d..174baea9f 100644 --- a/providers/ipfs-info-box-statuses.tsx +++ b/providers/ipfs-info-box-statuses.tsx @@ -9,7 +9,8 @@ import { import { useLidoSWR, useLocalStorage, useSDK } from '@lido-sdk/react'; import invariant from 'tiny-invariant'; -import { useRpcUrl } from 'config/rpc'; +// import { useRpcUrl } from 'config/rpc'; // TODO: or better use 'config/rpc'? +import { useRpcUrl } from 'config'; import { STORAGE_IPFS_INFO_DISMISS } from 'consts/storage'; import { SETTINGS_PATH } from 'consts/urls'; diff --git a/providers/web3.tsx b/providers/web3.tsx index 37fae2d21..339d774d3 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -7,12 +7,9 @@ import * as wagmiChains from 'wagmi/chains'; import { CHAINS } from 'utils/chains'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; -import { useClientConfig } from 'config/client-config/hooks'; - -// TODO -import { useGetRpcUrlByChainId } from 'config/rpc'; - -import { getConfig } from 'config'; +// import { useUserConfig } from 'config/user-config/hooks'; // TODO: or better use 'config/user-config/hooks'? +// import { useGetRpcUrlByChainId } from 'config/rpc'; // TODO: or better 'config/rpc' +import { getConfig, useGetRpcUrlByChainId, useUserConfig } from 'config'; const { defaultChain: defaultChainFromConfig, supportedChains: supportedChainsFromConfig, @@ -20,7 +17,7 @@ const { const Web3Provider: FC = ({ children }) => { const { defaultChain, supportedChainIds, walletconnectProjectId } = - useClientConfig(); + useUserConfig(); const getRpcUrlByChainId = useGetRpcUrlByChainId(); From 2f5d454480fedcc78e77f848acfbb145fd9ee32b Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 09:48:18 +0300 Subject: [PATCH 14/48] refactor: rename ClientConfigProvider to UserConfigProvider --- config/client-config/hooks.ts | 11 --- config/client-config/provider.tsx | 69 ------------------- config/{rpc.ts => rpc/index.ts} | 17 ++--- config/user-config/hooks.ts | 10 +++ config/user-config/provider.tsx | 64 +++++++++++++++++ .../{client-config => user-config}/types.ts | 0 .../{client-config => user-config}/utils.ts | 8 +-- consts/storage.ts | 2 +- .../settings/settings-form/settings-form.tsx | 12 ++-- providers/index.tsx | 8 +-- 10 files changed, 98 insertions(+), 103 deletions(-) delete mode 100644 config/client-config/hooks.ts delete mode 100644 config/client-config/provider.tsx rename config/{rpc.ts => rpc/index.ts} (77%) create mode 100644 config/user-config/hooks.ts create mode 100644 config/user-config/provider.tsx rename config/{client-config => user-config}/types.ts (100%) rename config/{client-config => user-config}/utils.ts (77%) diff --git a/config/client-config/hooks.ts b/config/client-config/hooks.ts deleted file mode 100644 index d19305a4e..000000000 --- a/config/client-config/hooks.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { useContext } from 'react'; -import invariant from 'tiny-invariant'; - -import { ClientConfigContext } from './provider'; - -// TODO: 'useClientConfig' --> 'useUserConfig' -export const useClientConfig = () => { - const context = useContext(ClientConfigContext); - invariant(context, 'Attempt to use `client config` outside of provider'); - return context; -}; diff --git a/config/client-config/provider.tsx b/config/client-config/provider.tsx deleted file mode 100644 index ba4c26fe9..000000000 --- a/config/client-config/provider.tsx +++ /dev/null @@ -1,69 +0,0 @@ -import { - PropsWithChildren, - useMemo, - useState, - useCallback, - createContext, -} from 'react'; - -import { useLocalStorage } from '@lido-sdk/react'; - -import { STORAGE_CLIENT_CONFIG } from 'consts/storage'; -import { CHAINS } from 'utils/chains'; - -import { getUserConfigDefault } from './utils'; -import { UserConfigDefaultType } from './types'; - -// TODO whole file: '*Сlient*' --> '*User*', 'client' --> 'user' - -type SavedClientConfig = { - rpcUrls: Partial>; -}; - -type ClientConfigContext = UserConfigDefaultType & { - savedClientConfig: SavedClientConfig; - setSavedClientConfig: (config: SavedClientConfig) => void; -}; - -export const ClientConfigContext = createContext( - null, -); - -const DEFAULT_STATE: SavedClientConfig = { - rpcUrls: {}, -}; - -// TODO: 'ClientConfigProvider' --> 'UserConfigProvider' -export const ClientConfigProvider = ({ children }: PropsWithChildren) => { - const [restoredSettings, setLocalStorage] = useLocalStorage( - STORAGE_CLIENT_CONFIG, - DEFAULT_STATE, - ); - - const [savedClientConfig, setSavedClientConfig] = - useState(restoredSettings); - - const setSavedConfigAndRemember = useCallback( - (config: SavedClientConfig) => { - setLocalStorage(config); - setSavedClientConfig(config); - }, - [setLocalStorage], - ); - - const contextValue = useMemo(() => { - const userConfigDefault = getUserConfigDefault(); - - return { - ...userConfigDefault, - savedClientConfig, - setSavedClientConfig: setSavedConfigAndRemember, - }; - }, [savedClientConfig, setSavedConfigAndRemember]); - - return ( - - {children} - - ); -}; diff --git a/config/rpc.ts b/config/rpc/index.ts similarity index 77% rename from config/rpc.ts rename to config/rpc/index.ts index ccfecf503..f7ac840b0 100644 --- a/config/rpc.ts +++ b/config/rpc/index.ts @@ -2,19 +2,20 @@ import { useCallback } from 'react'; import invariant from 'tiny-invariant'; import { useSDK } from '@lido-sdk/react'; -import { useClientConfig } from './client-config/hooks'; import { CHAINS } from 'utils/chains'; -import { getConfig } from './get-config'; +import { getConfig } from '../get-config'; const { ipfsMode } = getConfig(); +import { useUserConfig } from '../user-config'; + export const getBackendRPCPath = (chainId: string | number): string => { const BASE_URL = typeof window === 'undefined' ? '' : window.location.origin; return `${BASE_URL}/api/rpc?chainId=${chainId}`; }; export const useGetRpcUrlByChainId = () => { - const clientConfig = useClientConfig(); + const userConfig = useUserConfig(); return useCallback( (chainId: CHAINS) => { @@ -23,7 +24,7 @@ export const useGetRpcUrlByChainId = () => { // chainId = 1 we need anytime! if ( chainId !== CHAINS.Mainnet && - !clientConfig.supportedChainIds.includes(chainId) + !userConfig.supportedChainIds.includes(chainId) ) { // Has no effect on functionality. Just a fix. // Return empty string as stub @@ -33,19 +34,19 @@ export const useGetRpcUrlByChainId = () => { if (ipfsMode) { const rpc = - clientConfig.savedClientConfig.rpcUrls[chainId] || - clientConfig.prefillUnsafeElRpcUrls[chainId]?.[0]; + userConfig.savedUserConfig.rpcUrls[chainId] || + userConfig.prefillUnsafeElRpcUrls[chainId]?.[0]; invariant(rpc, '[useGetRpcUrlByChainId] RPC is required!'); return rpc; } else { return ( - clientConfig.savedClientConfig.rpcUrls[chainId] || + userConfig.savedUserConfig.rpcUrls[chainId] || getBackendRPCPath(chainId) ); } }, - [clientConfig], + [userConfig], ); }; diff --git a/config/user-config/hooks.ts b/config/user-config/hooks.ts new file mode 100644 index 000000000..cf0fc1be1 --- /dev/null +++ b/config/user-config/hooks.ts @@ -0,0 +1,10 @@ +import { useContext } from 'react'; +import invariant from 'tiny-invariant'; + +import { UserConfigContext } from './provider'; + +export const useUserConfig = () => { + const context = useContext(UserConfigContext); + invariant(context, 'Attempt to use `client config` outside of provider'); + return context; +}; diff --git a/config/user-config/provider.tsx b/config/user-config/provider.tsx new file mode 100644 index 000000000..edf97eaf2 --- /dev/null +++ b/config/user-config/provider.tsx @@ -0,0 +1,64 @@ +import { + PropsWithChildren, + useMemo, + useState, + useCallback, + createContext, +} from 'react'; + +import { useLocalStorage } from '@lido-sdk/react'; + +import { STORAGE_USER_CONFIG } from 'consts/storage'; +import { CHAINS } from 'utils/chains'; + +import { getUserConfigDefault } from './utils'; +import { UserConfigDefaultType } from './types'; + +type SavedUserConfig = { + rpcUrls: Partial>; +}; + +type UserConfigContext = UserConfigDefaultType & { + savedUserConfig: SavedUserConfig; + setSavedUserConfig: (config: SavedUserConfig) => void; +}; + +export const UserConfigContext = createContext(null); + +const DEFAULT_STATE: SavedUserConfig = { + rpcUrls: {}, +}; + +export const UserConfigProvider = ({ children }: PropsWithChildren) => { + const [restoredSettings, setLocalStorage] = useLocalStorage( + STORAGE_USER_CONFIG, + DEFAULT_STATE, + ); + + const [savedUserConfig, setSavedUserConfig] = + useState(restoredSettings); + + const setSavedConfigAndRemember = useCallback( + (config: SavedUserConfig) => { + setLocalStorage(config); + setSavedUserConfig(config); + }, + [setLocalStorage], + ); + + const contextValue = useMemo(() => { + const userConfigDefault = getUserConfigDefault(); + + return { + ...userConfigDefault, + savedUserConfig, + setSavedUserConfig: setSavedConfigAndRemember, + }; + }, [savedUserConfig, setSavedConfigAndRemember]); + + return ( + + {children} + + ); +}; diff --git a/config/client-config/types.ts b/config/user-config/types.ts similarity index 100% rename from config/client-config/types.ts rename to config/user-config/types.ts diff --git a/config/client-config/utils.ts b/config/user-config/utils.ts similarity index 77% rename from config/client-config/utils.ts rename to config/user-config/utils.ts index 63e2ac57f..dcf26d12b 100644 --- a/config/client-config/utils.ts +++ b/config/user-config/utils.ts @@ -1,7 +1,5 @@ -import { UserConfigDefaultType } from 'config/client-config/types'; -import { CHAINS } from 'utils/chains'; - -import { getConfig } from 'config'; +// import { UserConfigDefaultType } from 'config/user-config/types'; // TODO: or better use 'config/user-config/types'? +import { getConfig, UserConfigDefaultType } from 'config'; const { defaultChain, supportedChains, @@ -11,6 +9,8 @@ const { walletconnectProjectId, } = getConfig(); +import { CHAINS } from 'utils/chains'; + export const getUserConfigDefault = (): UserConfigDefaultType => { return { defaultChain: Number(defaultChain), diff --git a/consts/storage.ts b/consts/storage.ts index dca7f5bd5..1cf6a4805 100644 --- a/consts/storage.ts +++ b/consts/storage.ts @@ -1,4 +1,4 @@ // TODO: or move to OneConfig??? export const STORAGE_CURRENCY_KEY = 'lido-currency'; -export const STORAGE_CLIENT_CONFIG = 'lido-client-config'; +export const STORAGE_USER_CONFIG = 'lido-user-config'; export const STORAGE_IPFS_INFO_DISMISS = 'lido-ipfs-info-dismiss'; diff --git a/features/settings/settings-form/settings-form.tsx b/features/settings/settings-form/settings-form.tsx index 0370bae96..7991e4094 100644 --- a/features/settings/settings-form/settings-form.tsx +++ b/features/settings/settings-form/settings-form.tsx @@ -4,8 +4,8 @@ import { useForm } from 'react-hook-form'; import { useSDK } from '@lido-sdk/react'; import { Button, ToastSuccess, Block, Input } from '@lidofinance/lido-ui'; -// TODO -import { useClientConfig } from 'config/client-config/hooks'; +// import { useUserConfig } from 'config/user-config/hooks'; // TODO: or better use 'config/user-config/hooks'? +import { useUserConfig } from 'config'; import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; import { RPCErrorType, checkRpcUrl } from 'utils/check-rpc-url'; import { CHAINS } from 'utils/chains'; @@ -22,14 +22,14 @@ type FormValues = { }; export const SettingsForm = () => { - const { savedClientConfig, setSavedClientConfig } = useClientConfig(); + const { savedUserConfig, setSavedUserConfig } = useUserConfig(); const { chainId } = useSDK(); const formMethods = useForm({ mode: 'onChange', reValidateMode: 'onChange', defaultValues: { - rpcUrl: savedClientConfig.rpcUrls[chainId as unknown as CHAINS], + rpcUrl: savedUserConfig.rpcUrls[chainId as unknown as CHAINS], }, }); @@ -43,13 +43,13 @@ export const SettingsForm = () => { const saveSettings = useCallback( (formValues: FormValues) => { - setSavedClientConfig({ + setSavedUserConfig({ rpcUrls: { [chainId]: formValues.rpcUrl, }, }); }, - [chainId, setSavedClientConfig], + [chainId, setSavedUserConfig], ); const handleSubmit = useCallback( diff --git a/providers/index.tsx b/providers/index.tsx index dec32657e..50258ab34 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -2,8 +2,8 @@ import { FC, PropsWithChildren } from 'react'; import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; -import { ClientConfigProvider } from 'config/client-config/provider'; -import { ConfigProvider } from 'config'; +// import { UserConfigProvider } from 'config/user-config'; // TODO: or better 'config/user-config' +import { ConfigProvider, UserConfigProvider } from 'config'; import { AppFlagProvider } from './app-flag'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; @@ -15,7 +15,7 @@ export { MODAL, ModalContext } from './modals'; export const Providers: FC = ({ children }) => ( - + @@ -28,6 +28,6 @@ export const Providers: FC = ({ children }) => ( - + ); From f1f1a49989e2ac82888a4c3510126146b6a50d38 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 09:58:40 +0300 Subject: [PATCH 15/48] refactor: moved CSP to config dir --- utilsApi/withCSP.ts => config/csp/index.ts | 2 -- config/index.ts | 2 ++ pages/_app.tsx | 2 +- pages/_document.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename utilsApi/withCSP.ts => config/csp/index.ts (98%) diff --git a/utilsApi/withCSP.ts b/config/csp/index.ts similarity index 98% rename from utilsApi/withCSP.ts rename to config/csp/index.ts index f7d8e6d79..903f538a0 100644 --- a/utilsApi/withCSP.ts +++ b/config/csp/index.ts @@ -16,8 +16,6 @@ const trustedHosts = cspTrustedHosts ? cspTrustedHosts.split(',') : []; const reportOnly = cspReportOnly == 'true'; -// TODO: move to config/csp - export const contentSecurityPolicy: ContentSecurityPolicyOption = { directives: { 'default-src': ["'self'"], diff --git a/config/index.ts b/config/index.ts index aacfcbf8c..35d66daae 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,5 +1,7 @@ export * from './get-config'; export * from './provider'; export * from './use-config'; + +export * from './csp/index'; export * from './rpc/index'; export * from './user-config/index'; diff --git a/pages/_app.tsx b/pages/_app.tsx index a925d6e1a..41d65994f 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -11,11 +11,11 @@ import { import { getConfig } from 'config'; const { ipfsMode } = getConfig(); +import { withCsp } from 'config/csp'; import { Providers } from 'providers'; import { BackgroundGradient } from 'shared/components/background-gradient/background-gradient'; import { nprogress, COOKIES_ALLOWED_FULL_KEY } from 'utils'; -import { withCsp } from 'utilsApi/withCSP'; // Migrations old theme cookies to new cross domain cookies migrationThemeCookiesToCrossDomainCookiesClientSide(); diff --git a/pages/_document.tsx b/pages/_document.tsx index e7ceb23fe..ea9602801 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -12,9 +12,9 @@ import { Fonts, LidoUIHead } from '@lidofinance/lido-ui'; import { getConfig } from 'config'; const { BASE_PATH_ASSET, defaultChain, ipfsMode } = getConfig(); +import { contentSecurityPolicy } from 'config/csp'; import { InsertIpfsBaseScript } from 'features/ipfs/ipfs-base-script'; -import { contentSecurityPolicy } from 'utilsApi/withCSP'; let host = 'https://stake.lido.fi'; From 218bed685fd09207d0453faa517cc46d86fbcf4a Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 10:18:17 +0300 Subject: [PATCH 16/48] refactor: moved CHAINS to consts/chains --- config/rpc/index.ts | 2 +- config/user-config/provider.tsx | 2 +- config/user-config/types.ts | 2 +- config/user-config/utils.ts | 2 +- {utils => consts}/chains.ts | 1 - features/settings/settings-form/settings-form.tsx | 2 +- providers/web3.tsx | 4 ++-- shared/wallet/fallback/useErrorMessage.ts | 2 +- types/subgraph.ts | 2 +- utils/index.ts | 1 - utilsApi/getEthApr.ts | 4 ++-- utilsApi/getEthPrice.ts | 5 +++-- utilsApi/getLdoStats.ts | 2 +- utilsApi/getSmaStethApr.ts | 8 ++++---- utilsApi/getSubgraphUrl.ts | 3 +-- utilsApi/getTotalStaked.ts | 2 +- utilsApi/rpcUrls.ts | 3 +-- 17 files changed, 22 insertions(+), 25 deletions(-) rename {utils => consts}/chains.ts (76%) diff --git a/config/rpc/index.ts b/config/rpc/index.ts index f7ac840b0..3fd455460 100644 --- a/config/rpc/index.ts +++ b/config/rpc/index.ts @@ -2,7 +2,7 @@ import { useCallback } from 'react'; import invariant from 'tiny-invariant'; import { useSDK } from '@lido-sdk/react'; -import { CHAINS } from 'utils/chains'; +import { CHAINS } from 'consts/chains'; import { getConfig } from '../get-config'; const { ipfsMode } = getConfig(); diff --git a/config/user-config/provider.tsx b/config/user-config/provider.tsx index edf97eaf2..29172f236 100644 --- a/config/user-config/provider.tsx +++ b/config/user-config/provider.tsx @@ -8,8 +8,8 @@ import { import { useLocalStorage } from '@lido-sdk/react'; +import { CHAINS } from 'consts/chains'; import { STORAGE_USER_CONFIG } from 'consts/storage'; -import { CHAINS } from 'utils/chains'; import { getUserConfigDefault } from './utils'; import { UserConfigDefaultType } from './types'; diff --git a/config/user-config/types.ts b/config/user-config/types.ts index 4df670173..7c8690b20 100644 --- a/config/user-config/types.ts +++ b/config/user-config/types.ts @@ -1,4 +1,4 @@ -import { CHAINS } from 'utils/chains'; +import { CHAINS } from 'consts/chains'; export type UserConfigDefaultType = { defaultChain: number; diff --git a/config/user-config/utils.ts b/config/user-config/utils.ts index dcf26d12b..51eaefa43 100644 --- a/config/user-config/utils.ts +++ b/config/user-config/utils.ts @@ -9,7 +9,7 @@ const { walletconnectProjectId, } = getConfig(); -import { CHAINS } from 'utils/chains'; +import { CHAINS } from 'consts/chains'; export const getUserConfigDefault = (): UserConfigDefaultType => { return { diff --git a/utils/chains.ts b/consts/chains.ts similarity index 76% rename from utils/chains.ts rename to consts/chains.ts index 98249eb96..2b2a5f95c 100644 --- a/utils/chains.ts +++ b/consts/chains.ts @@ -1,4 +1,3 @@ -// TODO: move to consts export const enum CHAINS { Mainnet = 1, Goerli = 5, diff --git a/features/settings/settings-form/settings-form.tsx b/features/settings/settings-form/settings-form.tsx index 7991e4094..e8e49cd02 100644 --- a/features/settings/settings-form/settings-form.tsx +++ b/features/settings/settings-form/settings-form.tsx @@ -6,9 +6,9 @@ import { Button, ToastSuccess, Block, Input } from '@lidofinance/lido-ui'; // import { useUserConfig } from 'config/user-config/hooks'; // TODO: or better use 'config/user-config/hooks'? import { useUserConfig } from 'config'; +import { CHAINS } from 'consts/chains'; import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; import { RPCErrorType, checkRpcUrl } from 'utils/check-rpc-url'; -import { CHAINS } from 'utils/chains'; import { Actions, diff --git a/providers/web3.tsx b/providers/web3.tsx index 339d774d3..763de1433 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -3,10 +3,10 @@ import { ProviderWeb3 } from 'reef-knot/web3-react'; import { getConnectors, holesky } from 'reef-knot/core-react'; import { WagmiConfig, createClient, configureChains, Chain } from 'wagmi'; import * as wagmiChains from 'wagmi/chains'; - -import { CHAINS } from 'utils/chains'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; +import { CHAINS } from 'consts/chains'; + // import { useUserConfig } from 'config/user-config/hooks'; // TODO: or better use 'config/user-config/hooks'? // import { useGetRpcUrlByChainId } from 'config/rpc'; // TODO: or better 'config/rpc' import { getConfig, useGetRpcUrlByChainId, useUserConfig } from 'config'; diff --git a/shared/wallet/fallback/useErrorMessage.ts b/shared/wallet/fallback/useErrorMessage.ts index 163a183b3..f989933fc 100644 --- a/shared/wallet/fallback/useErrorMessage.ts +++ b/shared/wallet/fallback/useErrorMessage.ts @@ -1,6 +1,6 @@ +import { useMemo } from 'react'; import { useSupportedChains, useConnectorError } from 'reef-knot/web3-react'; import { CHAINS } from '@lido-sdk/constants'; -import { useMemo } from 'react'; export const useErrorMessage = (): string | undefined => { const error = useConnectorError(); diff --git a/types/subgraph.ts b/types/subgraph.ts index 75147928f..2aed7a1c9 100644 --- a/types/subgraph.ts +++ b/types/subgraph.ts @@ -1,3 +1,3 @@ -import { CHAINS } from 'utils/chains'; +import { CHAINS } from 'consts/chains'; export type SubgraphChains = CHAINS; diff --git a/utils/index.ts b/utils/index.ts index bb31f01e3..f05898ef4 100644 --- a/utils/index.ts +++ b/utils/index.ts @@ -1,4 +1,3 @@ -export * from './chains'; export * from './appCookies'; export * from './formatBalance'; export * from './formatBalanceString'; diff --git a/utilsApi/getEthApr.ts b/utilsApi/getEthApr.ts index 18f250db8..646b07816 100644 --- a/utilsApi/getEthApr.ts +++ b/utilsApi/getEthApr.ts @@ -1,7 +1,7 @@ -import { CHAINS } from 'utils/chains'; +import { iterateUrls } from '@lidofinance/rpc'; +import { CHAINS } from 'consts/chains'; import { getStaticRpcBatchProvider } from './rpcProviders'; import { rpcUrls } from './rpcUrls'; -import { iterateUrls } from '@lidofinance/rpc'; export const getEthApr = async (): Promise => { console.debug('Getting eth apr...'); diff --git a/utilsApi/getEthPrice.ts b/utilsApi/getEthPrice.ts index b9b222d65..ce47bc025 100644 --- a/utilsApi/getEthPrice.ts +++ b/utilsApi/getEthPrice.ts @@ -1,9 +1,10 @@ -import { getStaticRpcBatchProvider } from './rpcProviders'; -import { rpcUrls } from './rpcUrls'; import { iterateUrls } from '@lidofinance/rpc'; import { getAggregatorContract } from '@lido-sdk/contracts'; import { CHAINS, getAggregatorAddress } from '@lido-sdk/constants'; +import { getStaticRpcBatchProvider } from './rpcProviders'; +import { rpcUrls } from './rpcUrls'; + export const getEthPrice = async (): Promise => { const urls = rpcUrls[CHAINS.Mainnet]; return iterateUrls(urls, (url) => getEthPriceWithFallbacks(url)); diff --git a/utilsApi/getLdoStats.ts b/utilsApi/getLdoStats.ts index f94fd42eb..cff9f792e 100644 --- a/utilsApi/getLdoStats.ts +++ b/utilsApi/getLdoStats.ts @@ -1,6 +1,6 @@ -import { CHAINS } from 'utils/chains'; import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; +import { CHAINS } from 'consts/chains'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; diff --git a/utilsApi/getSmaStethApr.ts b/utilsApi/getSmaStethApr.ts index 4736aa553..a4f042a43 100644 --- a/utilsApi/getSmaStethApr.ts +++ b/utilsApi/getSmaStethApr.ts @@ -1,9 +1,9 @@ -import { CHAINS } from 'utils/chains'; -import { standardFetcher } from 'utils/standardFetcher'; -import { responseTimeExternalMetricWrapper } from 'utilsApi'; - import { getConfig } from 'config'; const { ethAPIBasePath } = getConfig(); +import { CHAINS } from 'consts/chains'; + +import { standardFetcher } from 'utils/standardFetcher'; +import { responseTimeExternalMetricWrapper } from 'utilsApi'; type SMA_APR_RESPONSE = { data: { diff --git a/utilsApi/getSubgraphUrl.ts b/utilsApi/getSubgraphUrl.ts index e3b1d9567..a784bd3b6 100644 --- a/utilsApi/getSubgraphUrl.ts +++ b/utilsApi/getSubgraphUrl.ts @@ -1,6 +1,5 @@ -import { CHAINS } from 'utils/chains'; import { SubgraphChains } from 'types'; - +import { CHAINS } from 'consts/chains'; import { getConfig } from 'config'; const { subgraphMainnet, subgraphGoerli, subgraphHolesky } = getConfig(); diff --git a/utilsApi/getTotalStaked.ts b/utilsApi/getTotalStaked.ts index ba1f19a9b..b924a9982 100644 --- a/utilsApi/getTotalStaked.ts +++ b/utilsApi/getTotalStaked.ts @@ -3,7 +3,7 @@ import { StethAbiFactory } from '@lido-sdk/contracts'; import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; import { HEALTHY_RPC_SERVICES_ARE_OVER } from 'consts/api'; -import { CHAINS } from 'utils/chains'; +import { CHAINS } from 'consts/chains'; import { getStaticRpcBatchProvider } from './rpcProviders'; import { rpcUrls } from './rpcUrls'; diff --git a/utilsApi/rpcUrls.ts b/utilsApi/rpcUrls.ts index a7c85ab54..a1d16a03a 100644 --- a/utilsApi/rpcUrls.ts +++ b/utilsApi/rpcUrls.ts @@ -1,5 +1,4 @@ -import { CHAINS } from 'utils/chains'; - +import { CHAINS } from 'consts/chains'; import { getConfig } from 'config'; const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = getConfig(); From a344724a83433e532e045eaf13a8737f369daef7 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 10:25:54 +0300 Subject: [PATCH 17/48] refactor: moved 'swr-strategies' to consts --- utils/swrStrategies.ts => consts/swr-strategies.ts | 2 -- features/rewards/components/stats/Stats.tsx | 2 +- features/stake/stake-form/hooks.ts | 2 +- .../stake-form/stake-form-context/stake-form-context.tsx | 2 +- features/stake/stake-form/stake-form-info.tsx | 2 +- features/stake/stake-form/wallet/wallet.tsx | 2 +- features/stake/swap-discount-banner/swap-discount-banner.tsx | 2 +- features/withdrawals/hooks/contract/useLidoShareRate.ts | 5 +++-- features/withdrawals/hooks/contract/useUnfinalizedSteth.ts | 2 +- .../withdrawals/hooks/contract/useWithdrawalsBaseData.ts | 5 +++-- features/withdrawals/hooks/contract/useWithdrawalsData.ts | 2 +- features/withdrawals/hooks/useEthAmountByStethWsteth.ts | 2 +- features/withdrawals/hooks/useWaitingTime.ts | 2 +- features/withdrawals/hooks/useWithdrawTxPrice.ts | 2 +- features/withdrawals/hooks/useWithdrawalRates.ts | 2 +- .../use-request-form-data-context-value.ts | 2 +- features/wsteth/shared/wallet/wallet.tsx | 2 +- features/wsteth/unwrap/hooks/use-unwrap-form-network-data.ts | 2 +- features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts | 2 +- features/wsteth/wrap/hooks/use-approve-gas-limit.tsx | 2 +- features/wsteth/wrap/hooks/use-wrap-form-network-data.ts | 2 +- providers/ipfs-info-box-statuses.tsx | 2 +- shared/hooks/use-eth-usd.ts | 2 +- shared/hooks/useApprove.ts | 2 +- shared/hooks/useIsContract.ts | 2 +- shared/hooks/useLidoApr.ts | 2 +- shared/hooks/useLidoStats.ts | 2 +- shared/hooks/useMaxGasPrice.ts | 2 +- shared/hooks/useStakingLimitInfo.ts | 3 +-- shared/hooks/useStethByWsteth.ts | 2 +- shared/hooks/useWstethBySteth.ts | 2 +- shared/wallet/button/button.tsx | 3 ++- 32 files changed, 36 insertions(+), 36 deletions(-) rename utils/swrStrategies.ts => consts/swr-strategies.ts (97%) diff --git a/utils/swrStrategies.ts b/consts/swr-strategies.ts similarity index 97% rename from utils/swrStrategies.ts rename to consts/swr-strategies.ts index 5c55eca63..13af19fba 100644 --- a/utils/swrStrategies.ts +++ b/consts/swr-strategies.ts @@ -1,7 +1,5 @@ import type { SWRConfiguration } from 'swr'; -// TODO: move to consts - const MINUTE_MS = 1000 * 60; type StrategyConfig = Pick< diff --git a/features/rewards/components/stats/Stats.tsx b/features/rewards/components/stats/Stats.tsx index 06fb8a046..356501863 100644 --- a/features/rewards/components/stats/Stats.tsx +++ b/features/rewards/components/stats/Stats.tsx @@ -14,7 +14,7 @@ import EthSymbol from 'features/rewards/components/EthSymbol'; import NumberFormat from 'features/rewards/components/NumberFormat'; import { Big, BigDecimal } from 'features/rewards/helpers'; import { ETHER } from 'features/rewards/constants'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useMainnetStaticRpcProvider } from 'shared/hooks/use-mainnet-static-rpc-provider'; import { Item } from './Item'; diff --git a/features/stake/stake-form/hooks.ts b/features/stake/stake-form/hooks.ts index 18ff4809a..17181446f 100644 --- a/features/stake/stake-form/hooks.ts +++ b/features/stake/stake-form/hooks.ts @@ -5,8 +5,8 @@ import { useLidoSWR, useSDK, useSTETHContractRPC } from '@lido-sdk/react'; import { getConfig } from 'config'; const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT, STAKE_GASLIMIT_FALLBACK } = getConfig(); +import { STRATEGY_CONSTANT } from 'consts/swr-strategies'; -import { STRATEGY_CONSTANT } from 'utils/swrStrategies'; import { applyGasLimitRatio } from './utils'; type UseStethSubmitGasLimit = () => BigNumber; diff --git a/features/stake/stake-form/stake-form-context/stake-form-context.tsx b/features/stake/stake-form/stake-form-context/stake-form-context.tsx index aa70c8180..a6f4fe632 100644 --- a/features/stake/stake-form/stake-form-context/stake-form-context.tsx +++ b/features/stake/stake-form/stake-form-context/stake-form-context.tsx @@ -20,7 +20,7 @@ import { import { useStakingLimitInfo } from 'shared/hooks/useStakingLimitInfo'; import { useMaxGasPrice } from 'shared/hooks'; import { useIsMultisig } from 'shared/hooks/useIsMultisig'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useStethSubmitGasLimit } from '../hooks'; import { diff --git a/features/stake/stake-form/stake-form-info.tsx b/features/stake/stake-form/stake-form-info.tsx index 588d3ebe3..995e5b7af 100644 --- a/features/stake/stake-form/stake-form-info.tsx +++ b/features/stake/stake-form/stake-form-info.tsx @@ -5,9 +5,9 @@ import { useContractSWR, useSTETHContractRPC } from '@lido-sdk/react'; import { Zero } from '@ethersproject/constants'; import { DATA_UNAVAILABLE } from 'consts/text'; +import { STRATEGY_CONSTANT } from 'consts/swr-strategies'; import { FormatPrice, FormatToken } from 'shared/formatters'; import { useEthUsd } from 'shared/hooks/use-eth-usd'; -import { STRATEGY_CONSTANT } from 'utils/swrStrategies'; import { StakeFormInput, useStakeFormData } from './stake-form-context'; diff --git a/features/stake/stake-form/wallet/wallet.tsx b/features/stake/stake-form/wallet/wallet.tsx index ed134f146..d4decbbd6 100644 --- a/features/stake/stake-form/wallet/wallet.tsx +++ b/features/stake/stake-form/wallet/wallet.tsx @@ -11,7 +11,7 @@ import { FormatToken } from 'shared/formatters'; import { useLidoApr } from 'shared/hooks'; import { CardAccount, CardBalance, CardRow, Fallback } from 'shared/wallet'; import type { WalletComponentType } from 'shared/wallet/types'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { LimitMeter } from './limit-meter'; import { FlexCenter, LidoAprStyled, StyledCard } from './styles'; diff --git a/features/stake/swap-discount-banner/swap-discount-banner.tsx b/features/stake/swap-discount-banner/swap-discount-banner.tsx index bfb47512c..b5b758553 100644 --- a/features/stake/swap-discount-banner/swap-discount-banner.tsx +++ b/features/stake/swap-discount-banner/swap-discount-banner.tsx @@ -10,7 +10,7 @@ import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'consts/external-links'; import { getConfig } from 'config'; const { enableQaHelpers } = getConfig(); -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { getOpenOceanRate } from 'utils/get-open-ocean-rate'; import { Wrap, TextWrap, OpenOceanIcon, OverlayLink } from './styles'; diff --git a/features/withdrawals/hooks/contract/useLidoShareRate.ts b/features/withdrawals/hooks/contract/useLidoShareRate.ts index 9daaec334..75d3bc2d9 100644 --- a/features/withdrawals/hooks/contract/useLidoShareRate.ts +++ b/features/withdrawals/hooks/contract/useLidoShareRate.ts @@ -1,12 +1,13 @@ +import { BigNumber } from 'ethers'; import { useSDK, useLidoSWR, SWRResponse, useSTETHContractRPC, } from '@lido-sdk/react'; -import { BigNumber } from 'ethers'; + +import { STRATEGY_CONSTANT } from 'consts/swr-strategies'; import { calcShareRate } from 'features/withdrawals/utils/calc-share-rate'; -import { STRATEGY_CONSTANT } from 'utils/swrStrategies'; export const useLidoShareRate = (): SWRResponse => { const { chainId } = useSDK(); diff --git a/features/withdrawals/hooks/contract/useUnfinalizedSteth.ts b/features/withdrawals/hooks/contract/useUnfinalizedSteth.ts index 444db5003..868d69b26 100644 --- a/features/withdrawals/hooks/contract/useUnfinalizedSteth.ts +++ b/features/withdrawals/hooks/contract/useUnfinalizedSteth.ts @@ -1,7 +1,7 @@ import { useContractSWR } from '@lido-sdk/react'; import { useWithdrawalsContract } from './useWithdrawalsContract'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export const useUnfinalizedStETH = () => { const { contractRpc } = useWithdrawalsContract(); diff --git a/features/withdrawals/hooks/contract/useWithdrawalsBaseData.ts b/features/withdrawals/hooks/contract/useWithdrawalsBaseData.ts index 9ba18575c..537959527 100644 --- a/features/withdrawals/hooks/contract/useWithdrawalsBaseData.ts +++ b/features/withdrawals/hooks/contract/useWithdrawalsBaseData.ts @@ -1,8 +1,9 @@ -import { useSDK, useLidoSWR, SWRResponse } from '@lido-sdk/react'; import { BigNumber } from 'ethers'; +import { useSDK, useLidoSWR, SWRResponse } from '@lido-sdk/react'; + +import { STRATEGY_CONSTANT } from 'consts/swr-strategies'; import { useWithdrawalsContract } from './useWithdrawalsContract'; -import { STRATEGY_CONSTANT } from 'utils/swrStrategies'; type useWithdrawalsBaseDataResult = { maxAmount: BigNumber; diff --git a/features/withdrawals/hooks/contract/useWithdrawalsData.ts b/features/withdrawals/hooks/contract/useWithdrawalsData.ts index ff1cd92d7..2a7cdbb75 100644 --- a/features/withdrawals/hooks/contract/useWithdrawalsData.ts +++ b/features/withdrawals/hooks/contract/useWithdrawalsData.ts @@ -12,7 +12,7 @@ import { RequestStatusPending, } from 'features/withdrawals/types/request-status'; import { MAX_SHOWN_REQUEST_PER_TYPE } from 'features/withdrawals/withdrawals-constants'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; // import { calcExpectedRequestEth } from 'features/withdrawals/utils/calc-expected-request-eth'; diff --git a/features/withdrawals/hooks/useEthAmountByStethWsteth.ts b/features/withdrawals/hooks/useEthAmountByStethWsteth.ts index c798d2b4e..0b24973c7 100644 --- a/features/withdrawals/hooks/useEthAmountByStethWsteth.ts +++ b/features/withdrawals/hooks/useEthAmountByStethWsteth.ts @@ -1,7 +1,7 @@ import { BigNumber } from 'ethers'; import { useContractSWR, useWSTETHContractRPC } from '@lido-sdk/react'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; type useEthAmountByInputProps = { isSteth: boolean; diff --git a/features/withdrawals/hooks/useWaitingTime.ts b/features/withdrawals/hooks/useWaitingTime.ts index 61a98bfd7..ddc4cc176 100644 --- a/features/withdrawals/hooks/useWaitingTime.ts +++ b/features/withdrawals/hooks/useWaitingTime.ts @@ -3,11 +3,11 @@ import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; import { getConfig } from 'config'; const { wqAPIBasePath } = getConfig(); +import { STRATEGY_EAGER } from 'consts/swr-strategies'; import { useDebouncedValue } from 'shared/hooks'; import { encodeURLQuery } from 'utils/encodeURLQuery'; import { standardFetcher } from 'utils/standardFetcher'; -import { STRATEGY_EAGER } from 'utils/swrStrategies'; import { FetcherError } from 'utils/fetcherError'; import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; diff --git a/features/withdrawals/hooks/useWithdrawTxPrice.ts b/features/withdrawals/hooks/useWithdrawTxPrice.ts index 60746cb5b..aa1be48a2 100644 --- a/features/withdrawals/hooks/useWithdrawTxPrice.ts +++ b/features/withdrawals/hooks/useWithdrawTxPrice.ts @@ -15,12 +15,12 @@ const { WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT, wqAPIBasePath, } = getConfig(); +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { MAX_REQUESTS_COUNT } from 'features/withdrawals/withdrawals-constants'; import { useTxCostInUsd } from 'shared/hooks/txCost'; import { useDebouncedValue } from 'shared/hooks/useDebouncedValue'; import { encodeURLQuery } from 'utils/encodeURLQuery'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; import { standardFetcher } from 'utils/standardFetcher'; import { useWithdrawalsContract } from './contract/useWithdrawalsContract'; diff --git a/features/withdrawals/hooks/useWithdrawalRates.ts b/features/withdrawals/hooks/useWithdrawalRates.ts index 000659c03..80fcb5efe 100644 --- a/features/withdrawals/hooks/useWithdrawalRates.ts +++ b/features/withdrawals/hooks/useWithdrawalRates.ts @@ -7,7 +7,7 @@ import { CHAINS, getTokenAddress, TOKENS } from '@lido-sdk/constants'; import { useLidoSWR } from '@lido-sdk/react'; import { useDebouncedValue } from 'shared/hooks/useDebouncedValue'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { RequestFormInputType } from '../request/request-form-context'; import { getOpenOceanRate } from 'utils/get-open-ocean-rate'; diff --git a/features/withdrawals/request/request-form-context/use-request-form-data-context-value.ts b/features/withdrawals/request/request-form-context/use-request-form-data-context-value.ts index 4ee36159d..91bac7608 100644 --- a/features/withdrawals/request/request-form-context/use-request-form-data-context-value.ts +++ b/features/withdrawals/request/request-form-context/use-request-form-data-context-value.ts @@ -9,7 +9,7 @@ import { useClaimData } from 'features/withdrawals/contexts/claim-data-context'; import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; import { useUnfinalizedStETH } from 'features/withdrawals/hooks'; import { useCallback, useMemo } from 'react'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; // Provides all data fetching for form to function export const useRequestFormDataContextValue = () => { diff --git a/features/wsteth/shared/wallet/wallet.tsx b/features/wsteth/shared/wallet/wallet.tsx index 832865e32..31591dd5b 100644 --- a/features/wsteth/shared/wallet/wallet.tsx +++ b/features/wsteth/shared/wallet/wallet.tsx @@ -15,7 +15,7 @@ import { useWstethBySteth, useStethByWsteth } from 'shared/hooks'; import type { WalletComponentType } from 'shared/wallet/types'; import { CardBalance, CardRow, CardAccount, Fallback } from 'shared/wallet'; import { StyledCard } from './styles'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; const WalletComponent: WalletComponentType = (props) => { const { account } = useSDK(); diff --git a/features/wsteth/unwrap/hooks/use-unwrap-form-network-data.ts b/features/wsteth/unwrap/hooks/use-unwrap-form-network-data.ts index 7b83084b1..284d80061 100644 --- a/features/wsteth/unwrap/hooks/use-unwrap-form-network-data.ts +++ b/features/wsteth/unwrap/hooks/use-unwrap-form-network-data.ts @@ -1,7 +1,7 @@ import { useCallback, useMemo } from 'react'; import { useIsMultisig } from 'shared/hooks/useIsMultisig'; import { useSTETHBalance, useWSTETHBalance } from '@lido-sdk/react'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export const useUnwrapFormNetworkData = () => { const { isMultisig } = useIsMultisig(); diff --git a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts index b62063121..e63170996 100644 --- a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts +++ b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts @@ -6,7 +6,7 @@ const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); import { UNWRAP_GAS_LIMIT } from 'consts/tx'; import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export const useUnwrapGasLimit = () => { const wsteth = useWSTETHContractRPC(); diff --git a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx index 3c3fefd54..c4a221b09 100644 --- a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx +++ b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx @@ -7,7 +7,7 @@ import { } from '@lido-sdk/react'; import { WSTETH_APPROVE_GAS_LIMIT } from 'consts/tx'; -import { STRATEGY_IMMUTABLE } from 'utils/swrStrategies'; +import { STRATEGY_IMMUTABLE } from 'consts/swr-strategies'; import { getConfig } from 'config'; const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); diff --git a/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts b/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts index 807e2e858..82478fdf9 100644 --- a/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts +++ b/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts @@ -12,7 +12,7 @@ import { useIsMultisig } from 'shared/hooks/useIsMultisig'; import { useTokenMaxAmount } from 'shared/hooks/use-token-max-amount'; import { useMaxGasPrice, useStakingLimitInfo } from 'shared/hooks'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useWrapGasLimit } from './use-wrap-gas-limit'; diff --git a/providers/ipfs-info-box-statuses.tsx b/providers/ipfs-info-box-statuses.tsx index 174baea9f..626bec8d1 100644 --- a/providers/ipfs-info-box-statuses.tsx +++ b/providers/ipfs-info-box-statuses.tsx @@ -16,7 +16,7 @@ import { SETTINGS_PATH } from 'consts/urls'; import { useCSPViolation } from 'features/ipfs/csp-violation-box/use-csp-violation'; import { useRouterPath } from 'shared/hooks/use-router-path'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { checkRpcUrl } from 'utils/check-rpc-url'; type IPFSInfoBoxStatusesContextValue = { diff --git a/shared/hooks/use-eth-usd.ts b/shared/hooks/use-eth-usd.ts index 9c2813427..853499488 100644 --- a/shared/hooks/use-eth-usd.ts +++ b/shared/hooks/use-eth-usd.ts @@ -3,7 +3,7 @@ import { useMemo } from 'react'; import { useEthPrice } from '@lido-sdk/react'; import { weiToEth } from 'utils/weiToEth'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export const useEthUsd = (amount?: BigNumber): number | undefined => { const { data: price } = useEthPrice(STRATEGY_LAZY); diff --git a/shared/hooks/useApprove.ts b/shared/hooks/useApprove.ts index 60e8603b4..fe2c6bf98 100644 --- a/shared/hooks/useApprove.ts +++ b/shared/hooks/useApprove.ts @@ -12,7 +12,7 @@ import { getFeeData } from 'utils/getFeeData'; import { runWithTransactionLogger } from 'utils'; import { useCurrentStaticRpcProvider } from './use-current-static-rpc-provider'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; type ApproveOptions = | { diff --git a/shared/hooks/useIsContract.ts b/shared/hooks/useIsContract.ts index 543d957d2..a6dfc8a2d 100644 --- a/shared/hooks/useIsContract.ts +++ b/shared/hooks/useIsContract.ts @@ -1,5 +1,5 @@ import { useEthereumSWR } from '@lido-sdk/react'; -import { STRATEGY_IMMUTABLE } from 'utils/swrStrategies'; +import { STRATEGY_IMMUTABLE } from 'consts/swr-strategies'; export const useIsContract = ( account?: string | null, diff --git a/shared/hooks/useLidoApr.ts b/shared/hooks/useLidoApr.ts index cfca17a5f..74e608a64 100644 --- a/shared/hooks/useLidoApr.ts +++ b/shared/hooks/useLidoApr.ts @@ -3,9 +3,9 @@ import { CHAINS } from '@lido-sdk/constants'; import { getConfig } from 'config'; const { ethAPIBasePath } = getConfig(); +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { standardFetcher } from 'utils/standardFetcher'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; type SMA_APR_RESPONSE = { data: { diff --git a/shared/hooks/useLidoStats.ts b/shared/hooks/useLidoStats.ts index 1a926b94d..79a6f4cb2 100644 --- a/shared/hooks/useLidoStats.ts +++ b/shared/hooks/useLidoStats.ts @@ -7,7 +7,7 @@ const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); import { DATA_UNAVAILABLE } from 'consts/text'; import { prependBasePath } from 'utils'; import { standardFetcher } from 'utils/standardFetcher'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export type ResponseData = { uniqueAnytimeHolders: string; diff --git a/shared/hooks/useMaxGasPrice.ts b/shared/hooks/useMaxGasPrice.ts index f67442cf0..1411e585f 100644 --- a/shared/hooks/useMaxGasPrice.ts +++ b/shared/hooks/useMaxGasPrice.ts @@ -3,7 +3,7 @@ import { useLidoSWR } from '@lido-sdk/react'; import { BigNumber } from 'ethers'; import { getFeeData } from 'utils/getFeeData'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useCurrentStaticRpcProvider } from './use-current-static-rpc-provider'; diff --git a/shared/hooks/useStakingLimitInfo.ts b/shared/hooks/useStakingLimitInfo.ts index bdb9cad0f..8723a5e65 100644 --- a/shared/hooks/useStakingLimitInfo.ts +++ b/shared/hooks/useStakingLimitInfo.ts @@ -8,8 +8,7 @@ import { useSDK, useSTETHContractRPC } from '@lido-sdk/react'; import { getConfig } from 'config'; const { enableQaHelpers } = getConfig(); - -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { LIMIT_LEVEL } from 'types'; export type StakeLimitFullInfo = { diff --git a/shared/hooks/useStethByWsteth.ts b/shared/hooks/useStethByWsteth.ts index df05c4531..c0479b871 100644 --- a/shared/hooks/useStethByWsteth.ts +++ b/shared/hooks/useStethByWsteth.ts @@ -1,6 +1,6 @@ import { useContractSWR, useWSTETHContractRPC } from '@lido-sdk/react'; import { BigNumber } from 'ethers'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export const useStethByWsteth = ( wsteth: BigNumber | undefined, diff --git a/shared/hooks/useWstethBySteth.ts b/shared/hooks/useWstethBySteth.ts index 295fd92bf..2cc7b9e4d 100644 --- a/shared/hooks/useWstethBySteth.ts +++ b/shared/hooks/useWstethBySteth.ts @@ -1,6 +1,6 @@ import { useContractSWR, useWSTETHContractRPC } from '@lido-sdk/react'; import { BigNumber } from 'ethers'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; export const useWstethBySteth = ( steth: BigNumber | undefined, diff --git a/shared/wallet/button/button.tsx b/shared/wallet/button/button.tsx index 350dd5da9..7192ae239 100644 --- a/shared/wallet/button/button.tsx +++ b/shared/wallet/button/button.tsx @@ -4,6 +4,8 @@ import { MODAL } from 'providers'; import { useModal } from 'shared/hooks'; import { useEthereumBalance, useSDK } from '@lido-sdk/react'; import { FormatToken } from 'shared/formatters'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; + import { AddressBadge } from '../components/address-badge/address-badge'; import { WalledButtonStyle, @@ -11,7 +13,6 @@ import { WalledButtonBalanceStyle, WalledButtonLoaderStyle, } from './styles'; -import { STRATEGY_LAZY } from 'utils/swrStrategies'; export const Button: FC = (props) => { const { onClick, ...rest } = props; From eb6310ffc19af27e1a3f7b9d4da3f923e9fedc80 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 15:22:03 +0300 Subject: [PATCH 18/48] feat(config): add publicRuntimeConfig --- config/get-config.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/config/get-config.ts b/config/get-config.ts index fcdeb2fea..8c2af0632 100644 --- a/config/get-config.ts +++ b/config/get-config.ts @@ -53,6 +53,7 @@ export const getConfig = (): any => { BASE_PATH_ASSET, // highest priority + ...publicRuntimeConfig, ...(typeof window !== 'undefined' ? window.__env__ : dynamics), ...serverRuntimeConfig, }; From 328f842d7daa78e3cf1fd439418e8655fabbff3a Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 26 Feb 2024 16:12:26 +0300 Subject: [PATCH 19/48] docs: todo --- config/get-config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/get-config.ts b/config/get-config.ts index 8c2af0632..81f8ad1bb 100644 --- a/config/get-config.ts +++ b/config/get-config.ts @@ -58,3 +58,5 @@ export const getConfig = (): any => { ...serverRuntimeConfig, }; }; + +// TODO getServerConfig for secret envs? From a2ef6a000e0e1e70eed01c22a8f2ee8a1e336e8e Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 09:23:24 +0300 Subject: [PATCH 20/48] feat: preConfig --- config/csp/index.ts | 6 +++++- config/get-config.ts | 31 ++++--------------------------- config/get-preconfig.ts | 26 ++++++++++++++++++++++++++ config/groups/estimate.ts | 1 + config/groups/stake.ts | 12 ++++++++++++ config/index.ts | 1 + config/rpc/index.ts | 4 ++++ config/user-config/utils.ts | 9 +++++++-- 8 files changed, 60 insertions(+), 30 deletions(-) create mode 100644 config/get-preconfig.ts diff --git a/config/csp/index.ts b/config/csp/index.ts index 903f538a0..ed7328b18 100644 --- a/config/csp/index.ts +++ b/config/csp/index.ts @@ -3,7 +3,11 @@ import { AppProps } from 'next/app'; import { withSecureHeaders } from 'next-secure-headers'; import type { ContentSecurityPolicyOption } from 'next-secure-headers/lib/rules'; -import { getConfig } from 'config'; +// Not use absolute import here! +// code''' +// import { getConfig } from 'config'; +// ''' +import { getConfig } from '../get-config'; const { cspTrustedHosts, cspReportOnly, diff --git a/config/get-config.ts b/config/get-config.ts index 81f8ad1bb..6f8caa171 100644 --- a/config/get-config.ts +++ b/config/get-config.ts @@ -1,9 +1,4 @@ -import { AddressZero } from '@ethersproject/constants'; - -import getConfigNext from 'next/config'; -const { serverRuntimeConfig, publicRuntimeConfig } = getConfigNext(); - -import { default as dynamics } from './dynamics'; +import { getPreConfig } from './get-preconfig'; import * as cache from './groups/cache'; import * as estimate from './groups/estimate'; import * as ipfs from './groups/ipfs'; @@ -11,7 +6,7 @@ import * as locale from './groups/locale'; import * as stake from './groups/stake'; import * as withdrawalQueueEstimate from './groups/withdrawal-queue-estimate'; -// TODO: type serverRuntimeConfig? +// TODO: type // type ConfigType = { isClientSide: boolean, isServerSide: boolean } // & typeof cache // & typeof estimate @@ -20,23 +15,12 @@ import * as withdrawalQueueEstimate from './groups/withdrawal-queue-estimate'; // & typeof rateLimit // & typeof rateLimit // & typeof stake -// & typeof withdrawalQueueEstimate -// & typeof dynamics; +// & typeof withdrawalQueueEstimate; export const getConfig = (): any => { const isClientSide = typeof window !== 'undefined'; const isServerSide = typeof window === 'undefined'; - // TODO: another place - const STAKE_FALLBACK_REFERRAL_ADDRESS = dynamics.ipfsMode - ? ipfs.IPFS_REFERRAL_ADDRESS - : AddressZero; - - // TODO: another place - const BASE_PATH_ASSET = dynamics.ipfsMode - ? '.' - : serverRuntimeConfig.basePath || publicRuntimeConfig.basePath; - return { isClientSide, isServerSide, @@ -49,14 +33,7 @@ export const getConfig = (): any => { ...stake, ...withdrawalQueueEstimate, - STAKE_FALLBACK_REFERRAL_ADDRESS, - BASE_PATH_ASSET, - // highest priority - ...publicRuntimeConfig, - ...(typeof window !== 'undefined' ? window.__env__ : dynamics), - ...serverRuntimeConfig, + ...getPreConfig(), }; }; - -// TODO getServerConfig for secret envs? diff --git a/config/get-preconfig.ts b/config/get-preconfig.ts new file mode 100644 index 000000000..21f096069 --- /dev/null +++ b/config/get-preconfig.ts @@ -0,0 +1,26 @@ +import getConfigNext from 'next/config'; +import { default as dynamics } from './dynamics'; + +const { serverRuntimeConfig, publicRuntimeConfig } = getConfigNext(); + +// TODO: type +// type PreConfigType = typeof publicRuntimeConfig & typeof serverRuntimeConfig & typeof dynamics; + +// getPreConfig() needs for external internal in 'config/groups/*' +// Not use getPreConfig() outside of 'config/groups/*' +export const getPreConfig = (): any => { + const BASE_PATH_ASSET = dynamics.ipfsMode + ? '.' + : serverRuntimeConfig.basePath || publicRuntimeConfig.basePath; + + return { + BASE_PATH_ASSET, + + ...publicRuntimeConfig, + + ...(typeof window !== 'undefined' ? window.__env__ : dynamics), + + // TODO getServerConfig for secret envs? + ...serverRuntimeConfig, + }; +}; diff --git a/config/groups/estimate.ts b/config/groups/estimate.ts index 5717db655..ca11d5981 100644 --- a/config/groups/estimate.ts +++ b/config/groups/estimate.ts @@ -1,4 +1,5 @@ import { parseEther } from '@ethersproject/units'; + // account for gas estimation // will always have >=0.001 ether, >=0.001 stETH, >=0.001 wstETH // on Mainnet, Goerli, Holesky diff --git a/config/groups/stake.ts b/config/groups/stake.ts index d12f936b0..06c7ed63e 100644 --- a/config/groups/stake.ts +++ b/config/groups/stake.ts @@ -1,6 +1,14 @@ import { BigNumber } from 'ethers'; +import { AddressZero } from '@ethersproject/constants'; import { parseEther } from '@ethersproject/units'; +import { IPFS_REFERRAL_ADDRESS } from './ipfs'; + +// Not use getConfig() here!!! +// Use getPreConfig() only here!!! +import { getPreConfig } from '../get-preconfig'; +const { ipfsMode } = getPreConfig(); + export const PRECISION = 10 ** 6; // how much to leave out on user balance when max is pressed @@ -15,3 +23,7 @@ export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( STETH_SUBMIT_GAS_LIMIT_DEFAULT * SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, ), ); + +export const STAKE_FALLBACK_REFERRAL_ADDRESS = ipfsMode + ? IPFS_REFERRAL_ADDRESS + : AddressZero; diff --git a/config/index.ts b/config/index.ts index 35d66daae..f7b82bb27 100644 --- a/config/index.ts +++ b/config/index.ts @@ -2,6 +2,7 @@ export * from './get-config'; export * from './provider'; export * from './use-config'; +// TODO: look likes this give more problems than benefits export * from './csp/index'; export * from './rpc/index'; export * from './user-config/index'; diff --git a/config/rpc/index.ts b/config/rpc/index.ts index 3fd455460..5e38dafd2 100644 --- a/config/rpc/index.ts +++ b/config/rpc/index.ts @@ -4,6 +4,10 @@ import { useSDK } from '@lido-sdk/react'; import { CHAINS } from 'consts/chains'; +// Not use absolute import here! +// code''' +// import { getConfig } from 'config'; +// ''' import { getConfig } from '../get-config'; const { ipfsMode } = getConfig(); diff --git a/config/user-config/utils.ts b/config/user-config/utils.ts index 51eaefa43..6cfd19a30 100644 --- a/config/user-config/utils.ts +++ b/config/user-config/utils.ts @@ -1,5 +1,10 @@ -// import { UserConfigDefaultType } from 'config/user-config/types'; // TODO: or better use 'config/user-config/types'? -import { getConfig, UserConfigDefaultType } from 'config'; +// Not use absolute import here! +// code''' +// import { getConfig } from 'config'; +// ''' +import { getConfig } from '../get-config'; +import { UserConfigDefaultType } from './types'; + const { defaultChain, supportedChains, From 3515009088c0063a86a5dc67bfa4b0c4d81ddee4 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 14:03:14 +0300 Subject: [PATCH 21/48] feat: typing 'getConfig', 'getPreConfig' --- config/get-config.ts | 32 ++++++++++++++------------------ config/get-preconfig.ts | 9 ++++++--- global.d.ts | 32 ++++++++++++++++++++++++++++++++ next.config.mjs | 2 ++ shared/hooks/use-router-path.ts | 2 +- utilsApi/nextApiWrappers.ts | 3 ++- 6 files changed, 57 insertions(+), 23 deletions(-) diff --git a/config/get-config.ts b/config/get-config.ts index 6f8caa171..d9a3fc16c 100644 --- a/config/get-config.ts +++ b/config/get-config.ts @@ -1,4 +1,4 @@ -import { getPreConfig } from './get-preconfig'; +import { getPreConfig, PreConfigType } from './get-preconfig'; import * as cache from './groups/cache'; import * as estimate from './groups/estimate'; import * as ipfs from './groups/ipfs'; @@ -6,28 +6,24 @@ import * as locale from './groups/locale'; import * as stake from './groups/stake'; import * as withdrawalQueueEstimate from './groups/withdrawal-queue-estimate'; -// TODO: type -// type ConfigType = { isClientSide: boolean, isServerSide: boolean } -// & typeof cache -// & typeof estimate -// & typeof ipfs -// & typeof locale -// & typeof rateLimit -// & typeof rateLimit -// & typeof stake -// & typeof withdrawalQueueEstimate; - -export const getConfig = (): any => { - const isClientSide = typeof window !== 'undefined'; - const isServerSide = typeof window === 'undefined'; +type ConfigType = { + isClientSide: boolean; + isServerSide: boolean; +} & typeof cache & + typeof estimate & + typeof ipfs & + typeof locale & + typeof stake & + typeof withdrawalQueueEstimate & + PreConfigType; +export const getConfig = (): ConfigType => { return { - isClientSide, - isServerSide, + isClientSide: typeof window !== 'undefined', + isServerSide: typeof window === 'undefined', ...cache, ...estimate, - ...ipfs, ...locale, ...stake, diff --git a/config/get-preconfig.ts b/config/get-preconfig.ts index 21f096069..7f31b9884 100644 --- a/config/get-preconfig.ts +++ b/config/get-preconfig.ts @@ -3,12 +3,15 @@ import { default as dynamics } from './dynamics'; const { serverRuntimeConfig, publicRuntimeConfig } = getConfigNext(); -// TODO: type -// type PreConfigType = typeof publicRuntimeConfig & typeof serverRuntimeConfig & typeof dynamics; +export type PreConfigType = { + BASE_PATH_ASSET: string; +} & typeof publicRuntimeConfig & + typeof dynamics & + typeof serverRuntimeConfig; // getPreConfig() needs for external internal in 'config/groups/*' // Not use getPreConfig() outside of 'config/groups/*' -export const getPreConfig = (): any => { +export const getPreConfig = (): PreConfigType => { const BASE_PATH_ASSET = dynamics.ipfsMode ? '.' : serverRuntimeConfig.basePath || publicRuntimeConfig.basePath; diff --git a/global.d.ts b/global.d.ts index 4d0af64fd..e941fa0e8 100644 --- a/global.d.ts +++ b/global.d.ts @@ -2,3 +2,35 @@ interface Window { // see _document.js for definition _paq: undefined | [string, ...unknown[]][]; } + +declare module 'next/config' { + type ConfigTypes = () => { + serverRuntimeConfig: { + basePath: string; + rpcUrls_1: [string, ...string[]]; + rpcUrls_5: [string, ...string[]]; + rpcUrls_17000: [string, ...string[]]; + ethplorerApiKey: string; + cspTrustedHosts: string; + cspReportOnly: string; + cspReportUri: string; + subgraphMainnet: string; + subgraphGoerli: string; + subgraphHolesky: string; + subgraphRequestTimeout: number; + rateLimit: number; + rateLimitTimeFrame: number; + ethAPIBasePath: string; + rewardsBackendAPI: string; + defaultChain: number; + developmentMode: boolean; + }; + publicRuntimeConfig: { + basePath: string; + }; + }; + + declare const getConfig: ConfigTypes; + + export default getConfig; +} diff --git a/next.config.mjs b/next.config.mjs index 1259062d8..515d03af4 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -163,6 +163,7 @@ export default withBundleAnalyzer({ }, ], serverRuntimeConfig: { + // ATTENTION: If you will add a new variable you should to declare it in `global.d.ts` basePath, rpcUrls_1, rpcUrls_5, @@ -183,6 +184,7 @@ export default withBundleAnalyzer({ developmentMode, }, publicRuntimeConfig: { + // ATTENTION: If you will add a new variable you should to declare it in `global.d.ts` basePath, }, }); diff --git a/shared/hooks/use-router-path.ts b/shared/hooks/use-router-path.ts index 2a472f3b5..71e63cf79 100644 --- a/shared/hooks/use-router-path.ts +++ b/shared/hooks/use-router-path.ts @@ -9,7 +9,7 @@ export const useRouterPath = () => { const router = useRouter(); if (ipfsMode) { - if (!isClientSide()) return HOME_PATH; + if (!isClientSide) return HOME_PATH; return location.hash.replace('#', '') || HOME_PATH; } diff --git a/utilsApi/nextApiWrappers.ts b/utilsApi/nextApiWrappers.ts index 9a1065e76..e50e4da40 100644 --- a/utilsApi/nextApiWrappers.ts +++ b/utilsApi/nextApiWrappers.ts @@ -14,7 +14,8 @@ import { getConfig } from 'config'; const { CACHE_DEFAULT_HEADERS, rateLimit: RATE_LIMIT, - rateLimitTimeFrame = '', + // TODO: check that 0 is valid + rateLimitTimeFrame = 0, } = getConfig(); import { From d42ee89a879e1dc71db48a7f33a1505d8af0c98e Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 14:22:26 +0300 Subject: [PATCH 22/48] docs: comment --- config/dynamics.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/config/dynamics.ts b/config/dynamics.ts index a15bcd00d..483cf2b26 100644 --- a/config/dynamics.ts +++ b/config/dynamics.ts @@ -13,6 +13,7 @@ declare global { // Only through: // code``` // import { getConfig } from 'config'; +// or import { getConfig } from './get-config'; // const { ... } = getConfig(); // ``` export default typeof window !== 'undefined' ? window.__env__ : dynamics; From f28ab55090fd69649235b68b06dbf509973c96d2 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 14:50:58 +0300 Subject: [PATCH 23/48] feat: add secretConfig as proxy serverRuntimeConfig --- config/csp/index.ts | 26 ++++++++++++------------ config/get-config.ts | 2 ++ config/get-preconfig.ts | 10 ++++----- config/get-secret-config.ts | 16 +++++++++++++++ config/index.ts | 1 + pages/api/rewards.ts | 28 ++++++++++++++------------ utilsApi/getLdoStats.ts | 7 +++---- utilsApi/getLidoHoldersViaSubgraphs.ts | 18 ++++++++--------- utilsApi/getLidoStats.ts | 6 ++---- utilsApi/getSmaStethApr.ts | 7 ++++--- utilsApi/getSubgraphUrl.ts | 11 +++++----- utilsApi/nextApiWrappers.ts | 13 ++++-------- utilsApi/rpcUrls.ts | 9 ++++----- 13 files changed, 81 insertions(+), 73 deletions(-) create mode 100644 config/get-secret-config.ts diff --git a/config/csp/index.ts b/config/csp/index.ts index ed7328b18..26c589f60 100644 --- a/config/csp/index.ts +++ b/config/csp/index.ts @@ -6,19 +6,19 @@ import type { ContentSecurityPolicyOption } from 'next-secure-headers/lib/rules' // Not use absolute import here! // code''' // import { getConfig } from 'config'; +// import { getSecretConfig } from 'config'; +// or +// import { config } from 'config'; +// import { secretConfig } from 'config'; // ''' -import { getConfig } from '../get-config'; -const { - cspTrustedHosts, - cspReportOnly, - cspReportUri, - developmentMode, - ipfsMode, -} = getConfig(); +import { config } from '../get-config'; +import { secretConfig } from '../get-secret-config'; -const trustedHosts = cspTrustedHosts ? cspTrustedHosts.split(',') : []; +const trustedHosts = secretConfig.cspTrustedHosts + ? secretConfig.cspTrustedHosts.split(',') + : []; -const reportOnly = cspReportOnly == 'true'; +const reportOnly = secretConfig.cspReportOnly == 'true'; export const contentSecurityPolicy: ContentSecurityPolicyOption = { directives: { @@ -39,14 +39,14 @@ export const contentSecurityPolicy: ContentSecurityPolicyOption = { 'https:', 'wss:', // for HMR - ...(developmentMode ? ['ws:'] : []), + ...(secretConfig.developmentMode ? ['ws:'] : []), ], - ...(!ipfsMode && { + ...(!config.ipfsMode && { // CSP directive 'frame-ancestors' is ignored when delivered via a element. // CSP directive 'report-uri' is ignored when delivered via a element. frameAncestors: ['*'], - reportURI: cspReportUri, + reportURI: secretConfig.cspReportUri, }), childSrc: [ "'self'", diff --git a/config/get-config.ts b/config/get-config.ts index d9a3fc16c..d1ff46dc4 100644 --- a/config/get-config.ts +++ b/config/get-config.ts @@ -33,3 +33,5 @@ export const getConfig = (): ConfigType => { ...getPreConfig(), }; }; + +export const config = getConfig(); diff --git a/config/get-preconfig.ts b/config/get-preconfig.ts index 7f31b9884..20da66acb 100644 --- a/config/get-preconfig.ts +++ b/config/get-preconfig.ts @@ -1,13 +1,12 @@ import getConfigNext from 'next/config'; import { default as dynamics } from './dynamics'; -const { serverRuntimeConfig, publicRuntimeConfig } = getConfigNext(); +const { publicRuntimeConfig, serverRuntimeConfig } = getConfigNext(); export type PreConfigType = { BASE_PATH_ASSET: string; } & typeof publicRuntimeConfig & - typeof dynamics & - typeof serverRuntimeConfig; + typeof dynamics; // getPreConfig() needs for external internal in 'config/groups/*' // Not use getPreConfig() outside of 'config/groups/*' @@ -22,8 +21,7 @@ export const getPreConfig = (): PreConfigType => { ...publicRuntimeConfig, ...(typeof window !== 'undefined' ? window.__env__ : dynamics), - - // TODO getServerConfig for secret envs? - ...serverRuntimeConfig, }; }; + +export const preConfig = getPreConfig(); diff --git a/config/get-secret-config.ts b/config/get-secret-config.ts new file mode 100644 index 000000000..dd12a14e0 --- /dev/null +++ b/config/get-secret-config.ts @@ -0,0 +1,16 @@ +import getConfigNext from 'next/config'; + +const { serverRuntimeConfig } = getConfigNext(); + +export type SecretConfigType = typeof serverRuntimeConfig; + +// 'getSecretConfig()' needs for backend side. +// We can't merge with 'getPreConfig()' because we want to split responsibility +// +// Also you can note that 'getSecretConfig' is just proxy for 'serverRuntimeConfig' +// because we want similar approach with 'getConfig' +export const getSecretConfig = (): SecretConfigType => { + return serverRuntimeConfig; +}; + +export const secretConfig = getSecretConfig(); diff --git a/config/index.ts b/config/index.ts index f7b82bb27..468b7e48e 100644 --- a/config/index.ts +++ b/config/index.ts @@ -1,4 +1,5 @@ export * from './get-config'; +export * from './get-secret-config'; export * from './provider'; export * from './use-config'; diff --git a/pages/api/rewards.ts b/pages/api/rewards.ts index 292ee96de..04cd3225c 100644 --- a/pages/api/rewards.ts +++ b/pages/api/rewards.ts @@ -2,6 +2,10 @@ import { wrapRequest as wrapNextRequest, cacheControl, } from '@lidofinance/next-api-wrapper'; + +import { config, secretConfig } from 'config'; +import { API_ROUTES } from 'consts/api'; +import { API } from 'types'; import { defaultErrorHandler, responseTimeMetric, @@ -12,13 +16,8 @@ import { cors, } from 'utilsApi'; import Metrics from 'utilsApi/metrics'; -import { API_ROUTES } from 'consts/api'; -import { API } from 'types'; import { standardFetcher } from 'utils/standardFetcher'; -import { getConfig } from 'config'; -const { rewardsBackendAPI, CACHE_REWARDS_HEADERS } = getConfig(); - const TIMEOUT = 10_000; const rewards: API = async (req, res) => { @@ -39,15 +38,18 @@ const rewards: API = async (req, res) => { ); const result = await responseTimeExternalMetricWrapper({ - payload: rewardsBackendAPI, + payload: secretConfig.rewardsBackendAPI, request: () => - standardFetcher(`${rewardsBackendAPI}/?${params.toString()}`, { - headers: { - Accept: 'application/json', - 'Content-Type': 'application/json', + standardFetcher( + `${secretConfig.rewardsBackendAPI}/?${params.toString()}`, + { + headers: { + Accept: 'application/json', + 'Content-Type': 'application/json', + }, + signal: controller.signal, }, - signal: controller.signal, - }), + ), }); res.status(200).json(result); @@ -60,6 +62,6 @@ export default wrapNextRequest([ cors({ origin: ['*'], methods: [HttpMethod.GET] }), rateLimit, responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.REWARDS), - cacheControl({ headers: CACHE_REWARDS_HEADERS }), + cacheControl({ headers: config.CACHE_REWARDS_HEADERS }), defaultErrorHandler, ])(rewards); diff --git a/utilsApi/getLdoStats.ts b/utilsApi/getLdoStats.ts index cff9f792e..933579c8c 100644 --- a/utilsApi/getLdoStats.ts +++ b/utilsApi/getLdoStats.ts @@ -1,12 +1,11 @@ import { getTokenAddress, TOKENS } from '@lido-sdk/constants'; + +import { secretConfig } from 'config'; import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import { CHAINS } from 'consts/chains'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -import { getConfig } from 'config'; -const { ethplorerApiKey } = getConfig(); - type GetLdoStats = () => Promise; // DEPRECATED: In future will be delete!!! Because we don't want to use https://api.ethplorer.io/ @@ -17,7 +16,7 @@ export const getLdoStats: GetLdoStats = async () => { CHAINS.Mainnet as number, TOKENS.LDO, )}`; - const query = new URLSearchParams({ apiKey: ethplorerApiKey }); + const query = new URLSearchParams({ apiKey: secretConfig.ethplorerApiKey }); const url = `${api}?${query.toString()}`; const ldoStats = await responseTimeExternalMetricWrapper({ diff --git a/utilsApi/getLidoHoldersViaSubgraphs.ts b/utilsApi/getLidoHoldersViaSubgraphs.ts index 83737d33d..8c122a7dc 100644 --- a/utilsApi/getLidoHoldersViaSubgraphs.ts +++ b/utilsApi/getLidoHoldersViaSubgraphs.ts @@ -1,14 +1,8 @@ import ms from 'ms'; import { Cache } from 'memory-cache'; +import { config, secretConfig } from 'config'; import { SubgraphChains } from 'types'; -import { getConfig } from 'config'; -const { - subgraphRequestTimeout, - CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY, - CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL, -} = getConfig(); - import Metrics from 'utilsApi/metrics'; import { standardFetcher } from 'utils/standardFetcher'; @@ -35,7 +29,7 @@ type GetLidoHoldersViaSubgraphs = ( export const getLidoHoldersViaSubgraphs: GetLidoHoldersViaSubgraphs = async ( chainId: SubgraphChains, ) => { - const cacheKey = `${CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY}_${chainId}`; + const cacheKey = `${config.CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_KEY}_${chainId}`; console.debug('[getLidoHoldersViaSubgraphs] Started fetching... '); const query = ` @@ -49,7 +43,7 @@ export const getLidoHoldersViaSubgraphs: GetLidoHoldersViaSubgraphs = async ( const controller = new AbortController(); - const TIMEOUT = +subgraphRequestTimeout || ms('5s'); + const TIMEOUT = +secretConfig.subgraphRequestTimeout || ms('5s'); const timeoutId = setTimeout(() => controller.abort(), TIMEOUT); const params = { @@ -74,7 +68,11 @@ export const getLidoHoldersViaSubgraphs: GetLidoHoldersViaSubgraphs = async ( console.debug('[getLidoHoldersViaSubgraphs] Lido holders:', responseJsoned); - cache.put(cacheKey, responseJsoned, CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL); + cache.put( + cacheKey, + responseJsoned, + config.CACHE_LIDO_HOLDERS_VIA_SUBGRAPHS_TTL, + ); return responseJsoned; } catch (error) { diff --git a/utilsApi/getLidoStats.ts b/utilsApi/getLidoStats.ts index 6f55c4ba2..27acd7c47 100644 --- a/utilsApi/getLidoStats.ts +++ b/utilsApi/getLidoStats.ts @@ -1,12 +1,10 @@ import { TOKENS, getTokenAddress, CHAINS } from '@lido-sdk/constants'; +import { secretConfig } from 'config'; import { ETHPLORER_TOKEN_ENDPOINT } from 'consts/api'; import { standardFetcher } from 'utils/standardFetcher'; import { responseTimeExternalMetricWrapper } from 'utilsApi'; -import { getConfig } from 'config'; -const { ethplorerApiKey } = getConfig(); - type GetLidoStats = () => Promise; // DEPRECATED: In future will be delete!!! Because we don't want to use https://api.ethplorer.io/ @@ -17,7 +15,7 @@ export const getLidoStats: GetLidoStats = async () => { CHAINS.Mainnet, TOKENS.STETH, )}`; - const query = new URLSearchParams({ apiKey: ethplorerApiKey }); + const query = new URLSearchParams({ apiKey: secretConfig.ethplorerApiKey }); const url = `${api}?${query.toString()}`; const lidoStats = await responseTimeExternalMetricWrapper({ diff --git a/utilsApi/getSmaStethApr.ts b/utilsApi/getSmaStethApr.ts index a4f042a43..902dbe5bb 100644 --- a/utilsApi/getSmaStethApr.ts +++ b/utilsApi/getSmaStethApr.ts @@ -1,5 +1,4 @@ -import { getConfig } from 'config'; -const { ethAPIBasePath } = getConfig(); +import { secretConfig } from 'config'; import { CHAINS } from 'consts/chains'; import { standardFetcher } from 'utils/standardFetcher'; @@ -52,7 +51,9 @@ type SMA_APR_RESPONSE = { export const getSmaStethApr = async (): Promise => { // TODO: remove after deploy env variables - const basePath = ethAPIBasePath ? ethAPIBasePath : 'https://eth-api.lido.fi'; + const basePath = secretConfig.ethAPIBasePath + ? secretConfig.ethAPIBasePath + : 'https://eth-api.lido.fi'; const url = `${basePath}/v1/protocol/steth/apr/sma`; const data = await responseTimeExternalMetricWrapper({ diff --git a/utilsApi/getSubgraphUrl.ts b/utilsApi/getSubgraphUrl.ts index a784bd3b6..e9d00dcaf 100644 --- a/utilsApi/getSubgraphUrl.ts +++ b/utilsApi/getSubgraphUrl.ts @@ -1,12 +1,11 @@ -import { SubgraphChains } from 'types'; +import { secretConfig } from 'config'; import { CHAINS } from 'consts/chains'; -import { getConfig } from 'config'; -const { subgraphMainnet, subgraphGoerli, subgraphHolesky } = getConfig(); +import { SubgraphChains } from 'types'; export const SUBGRAPH_URL = { - [CHAINS.Mainnet]: subgraphMainnet, - [CHAINS.Goerli]: subgraphGoerli, - [CHAINS.Holesky]: subgraphHolesky, + [CHAINS.Mainnet]: secretConfig.subgraphMainnet, + [CHAINS.Goerli]: secretConfig.subgraphGoerli, + [CHAINS.Holesky]: secretConfig.subgraphHolesky, } as const; export const getSubgraphUrl = (chainId: SubgraphChains): string | undefined => { diff --git a/utilsApi/nextApiWrappers.ts b/utilsApi/nextApiWrappers.ts index e50e4da40..ec3f4cd95 100644 --- a/utilsApi/nextApiWrappers.ts +++ b/utilsApi/nextApiWrappers.ts @@ -10,13 +10,8 @@ import { } from '@lidofinance/next-api-wrapper'; import { rateLimitWrapper } from '@lidofinance/next-ip-rate-limit'; -import { getConfig } from 'config'; -const { - CACHE_DEFAULT_HEADERS, - rateLimit: RATE_LIMIT, - // TODO: check that 0 is valid - rateLimitTimeFrame = 0, -} = getConfig(); +import { secretConfig, getConfig } from 'config'; +const { CACHE_DEFAULT_HEADERS } = getConfig(); import { getMetricContractInterface, @@ -181,8 +176,8 @@ export const requestAddressMetric = }; export const rateLimit = rateLimitWrapper({ - rateLimit: RATE_LIMIT, - rateLimitTimeFrame, + rateLimit: secretConfig.rateLimit, + rateLimitTimeFrame: secretConfig.rateLimitTimeFrame, }); export const nextDefaultErrorHandler = diff --git a/utilsApi/rpcUrls.ts b/utilsApi/rpcUrls.ts index a1d16a03a..e13f422a5 100644 --- a/utilsApi/rpcUrls.ts +++ b/utilsApi/rpcUrls.ts @@ -1,9 +1,8 @@ import { CHAINS } from 'consts/chains'; -import { getConfig } from 'config'; -const { rpcUrls_1, rpcUrls_5, rpcUrls_17000 } = getConfig(); +import { secretConfig } from 'config'; export const rpcUrls: Record = { - [CHAINS.Mainnet]: rpcUrls_1, - [CHAINS.Goerli]: rpcUrls_5, - [CHAINS.Holesky]: rpcUrls_17000, + [CHAINS.Mainnet]: secretConfig.rpcUrls_1, + [CHAINS.Goerli]: secretConfig.rpcUrls_5, + [CHAINS.Holesky]: secretConfig.rpcUrls_17000, }; From 0744c24f92dc70197560f4a215df10355648e82c Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 14:52:09 +0300 Subject: [PATCH 24/48] feat: add developmentMode to publicRuntimeConfig --- global.d.ts | 1 + next.config.mjs | 1 + 2 files changed, 2 insertions(+) diff --git a/global.d.ts b/global.d.ts index e941fa0e8..edaed6df2 100644 --- a/global.d.ts +++ b/global.d.ts @@ -27,6 +27,7 @@ declare module 'next/config' { }; publicRuntimeConfig: { basePath: string; + developmentMode: boolean; }; }; diff --git a/next.config.mjs b/next.config.mjs index 515d03af4..fdde1e007 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -186,5 +186,6 @@ export default withBundleAnalyzer({ publicRuntimeConfig: { // ATTENTION: If you will add a new variable you should to declare it in `global.d.ts` basePath, + developmentMode, }, }); From 511cf732ca30be1bd7c4995304102487f3578e14 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 19:12:09 +0300 Subject: [PATCH 25/48] refactor: import config --- config/index.ts | 5 ----- features/settings/settings-form/settings-form.tsx | 3 +-- providers/index.tsx | 4 ++-- providers/ipfs-info-box-statuses.tsx | 6 ++---- providers/web3.tsx | 6 +++--- shared/hooks/use-current-static-rpc-provider.ts | 2 +- shared/hooks/use-mainnet-static-rpc-provider.ts | 2 +- 7 files changed, 10 insertions(+), 18 deletions(-) diff --git a/config/index.ts b/config/index.ts index 468b7e48e..65983fd22 100644 --- a/config/index.ts +++ b/config/index.ts @@ -2,8 +2,3 @@ export * from './get-config'; export * from './get-secret-config'; export * from './provider'; export * from './use-config'; - -// TODO: look likes this give more problems than benefits -export * from './csp/index'; -export * from './rpc/index'; -export * from './user-config/index'; diff --git a/features/settings/settings-form/settings-form.tsx b/features/settings/settings-form/settings-form.tsx index e8e49cd02..a9cc22e49 100644 --- a/features/settings/settings-form/settings-form.tsx +++ b/features/settings/settings-form/settings-form.tsx @@ -4,8 +4,7 @@ import { useForm } from 'react-hook-form'; import { useSDK } from '@lido-sdk/react'; import { Button, ToastSuccess, Block, Input } from '@lidofinance/lido-ui'; -// import { useUserConfig } from 'config/user-config/hooks'; // TODO: or better use 'config/user-config/hooks'? -import { useUserConfig } from 'config'; +import { useUserConfig } from 'config/user-config'; import { CHAINS } from 'consts/chains'; import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; import { RPCErrorType, checkRpcUrl } from 'utils/check-rpc-url'; diff --git a/providers/index.tsx b/providers/index.tsx index 50258ab34..50f05ec9a 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -2,8 +2,8 @@ import { FC, PropsWithChildren } from 'react'; import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; -// import { UserConfigProvider } from 'config/user-config'; // TODO: or better 'config/user-config' -import { ConfigProvider, UserConfigProvider } from 'config'; +import { ConfigProvider } from 'config'; +import { UserConfigProvider } from 'config/user-config'; import { AppFlagProvider } from './app-flag'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; diff --git a/providers/ipfs-info-box-statuses.tsx b/providers/ipfs-info-box-statuses.tsx index 626bec8d1..b0e2c22b3 100644 --- a/providers/ipfs-info-box-statuses.tsx +++ b/providers/ipfs-info-box-statuses.tsx @@ -9,14 +9,12 @@ import { import { useLidoSWR, useLocalStorage, useSDK } from '@lido-sdk/react'; import invariant from 'tiny-invariant'; -// import { useRpcUrl } from 'config/rpc'; // TODO: or better use 'config/rpc'? -import { useRpcUrl } from 'config'; +import { useRpcUrl } from 'config/rpc'; import { STORAGE_IPFS_INFO_DISMISS } from 'consts/storage'; import { SETTINGS_PATH } from 'consts/urls'; - +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useCSPViolation } from 'features/ipfs/csp-violation-box/use-csp-violation'; import { useRouterPath } from 'shared/hooks/use-router-path'; -import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { checkRpcUrl } from 'utils/check-rpc-url'; type IPFSInfoBoxStatusesContextValue = { diff --git a/providers/web3.tsx b/providers/web3.tsx index 763de1433..c04859876 100644 --- a/providers/web3.tsx +++ b/providers/web3.tsx @@ -5,11 +5,11 @@ import { WagmiConfig, createClient, configureChains, Chain } from 'wagmi'; import * as wagmiChains from 'wagmi/chains'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; +import { getConfig } from 'config'; +import { useUserConfig } from 'config/user-config'; +import { useGetRpcUrlByChainId } from 'config/rpc'; import { CHAINS } from 'consts/chains'; -// import { useUserConfig } from 'config/user-config/hooks'; // TODO: or better use 'config/user-config/hooks'? -// import { useGetRpcUrlByChainId } from 'config/rpc'; // TODO: or better 'config/rpc' -import { getConfig, useGetRpcUrlByChainId, useUserConfig } from 'config'; const { defaultChain: defaultChainFromConfig, supportedChains: supportedChainsFromConfig, diff --git a/shared/hooks/use-current-static-rpc-provider.ts b/shared/hooks/use-current-static-rpc-provider.ts index 8cf504ea1..d426728c1 100644 --- a/shared/hooks/use-current-static-rpc-provider.ts +++ b/shared/hooks/use-current-static-rpc-provider.ts @@ -4,7 +4,7 @@ import { CHAINS } from '@lido-sdk/constants'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; import { StaticJsonRpcBatchProvider } from '@lidofinance/eth-providers'; -import { useRpcUrl } from 'config'; +import { useRpcUrl } from 'config/rpc'; export const useCurrentStaticRpcProvider = (): { staticRpcProvider: StaticJsonRpcBatchProvider; diff --git a/shared/hooks/use-mainnet-static-rpc-provider.ts b/shared/hooks/use-mainnet-static-rpc-provider.ts index 85841642d..4bddb089a 100644 --- a/shared/hooks/use-mainnet-static-rpc-provider.ts +++ b/shared/hooks/use-mainnet-static-rpc-provider.ts @@ -2,7 +2,7 @@ import { useMemo } from 'react'; import { getStaticRpcBatchProvider } from '@lido-sdk/providers'; import { StaticJsonRpcBatchProvider } from '@lidofinance/eth-providers'; -import { useRpcUrl } from 'config'; +import { useRpcUrl } from 'config/rpc'; export const useMainnetStaticRpcProvider = (): StaticJsonRpcBatchProvider => { const rpcUrl = useRpcUrl(); From e9febef98c0728b152b6ff30caf424c95ff7e505 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Wed, 28 Feb 2024 19:14:01 +0300 Subject: [PATCH 26/48] refactor: invariant msg --- config/use-config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/use-config.ts b/config/use-config.ts index 70eec2b85..a7f201dab 100644 --- a/config/use-config.ts +++ b/config/use-config.ts @@ -4,6 +4,6 @@ import { ConfigContext } from './provider'; export const useConfig = () => { const context = useContext(ConfigContext); - invariant(context, 'Attempt to use `one config` outside of provider'); + invariant(context, 'Attempt to use `useConfig` outside of provider'); return context; }; From c601d7f002d8217a2d5756ac5c0cbb9abccaa8da Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 3 Mar 2024 19:02:33 +0300 Subject: [PATCH 27/48] refactor: remove 'consts/storage' --- config/user-config/provider.tsx | 3 ++- consts/storage.ts | 4 ---- features/rewards/components/CurrencySelector.tsx | 3 ++- providers/ipfs-info-box-statuses.tsx | 3 ++- 4 files changed, 6 insertions(+), 7 deletions(-) delete mode 100644 consts/storage.ts diff --git a/config/user-config/provider.tsx b/config/user-config/provider.tsx index 29172f236..dee799293 100644 --- a/config/user-config/provider.tsx +++ b/config/user-config/provider.tsx @@ -9,11 +9,12 @@ import { import { useLocalStorage } from '@lido-sdk/react'; import { CHAINS } from 'consts/chains'; -import { STORAGE_USER_CONFIG } from 'consts/storage'; import { getUserConfigDefault } from './utils'; import { UserConfigDefaultType } from './types'; +const STORAGE_USER_CONFIG = 'lido-user-config'; + type SavedUserConfig = { rpcUrls: Partial>; }; diff --git a/consts/storage.ts b/consts/storage.ts deleted file mode 100644 index 1cf6a4805..000000000 --- a/consts/storage.ts +++ /dev/null @@ -1,4 +0,0 @@ -// TODO: or move to OneConfig??? -export const STORAGE_CURRENCY_KEY = 'lido-currency'; -export const STORAGE_USER_CONFIG = 'lido-user-config'; -export const STORAGE_IPFS_INFO_DISMISS = 'lido-ipfs-info-dismiss'; diff --git a/features/rewards/components/CurrencySelector.tsx b/features/rewards/components/CurrencySelector.tsx index 344e54031..0de84f3ed 100644 --- a/features/rewards/components/CurrencySelector.tsx +++ b/features/rewards/components/CurrencySelector.tsx @@ -3,9 +3,10 @@ import styled from 'styled-components'; import { Box, Select, Option } from '@lidofinance/lido-ui'; -import { STORAGE_CURRENCY_KEY } from 'consts/storage'; import { CURRENCIES, type CurrencyType } from 'features/rewards/constants'; +const STORAGE_CURRENCY_KEY = 'lido-currency'; + const StyledSelect = styled(Select)` height: 32px; width: 72px; diff --git a/providers/ipfs-info-box-statuses.tsx b/providers/ipfs-info-box-statuses.tsx index b0e2c22b3..76823e0d0 100644 --- a/providers/ipfs-info-box-statuses.tsx +++ b/providers/ipfs-info-box-statuses.tsx @@ -10,7 +10,6 @@ import { useLidoSWR, useLocalStorage, useSDK } from '@lido-sdk/react'; import invariant from 'tiny-invariant'; import { useRpcUrl } from 'config/rpc'; -import { STORAGE_IPFS_INFO_DISMISS } from 'consts/storage'; import { SETTINGS_PATH } from 'consts/urls'; import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useCSPViolation } from 'features/ipfs/csp-violation-box/use-csp-violation'; @@ -24,6 +23,8 @@ type IPFSInfoBoxStatusesContextValue = { handleClickDismiss: () => void; }; +const STORAGE_IPFS_INFO_DISMISS = 'lido-ipfs-info-dismiss'; + const IPFSInfoBoxStatusContext = createContext(null); From feb28e4b8232537de877226e22ba0a729203b4e0 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 3 Mar 2024 19:03:35 +0300 Subject: [PATCH 28/48] feat: feature flags --- .env.example | 2 + config/feature-flags/hooks.ts | 28 +++++++++ config/feature-flags/index.ts | 4 ++ config/feature-flags/provider.tsx | 59 +++++++++++++++++++ config/feature-flags/types.ts | 9 +++ config/feature-flags/utils.ts | 9 +++ env-dynamics.mjs | 3 + pages/feature-flags.tsx | 45 ++++++++++++++ pages/settings.tsx | 29 ++++++--- providers/index.tsx | 27 +++++---- .../header/components/header-wallet.tsx | 11 +++- 11 files changed, 204 insertions(+), 22 deletions(-) create mode 100644 config/feature-flags/hooks.ts create mode 100644 config/feature-flags/index.ts create mode 100644 config/feature-flags/provider.tsx create mode 100644 config/feature-flags/types.ts create mode 100644 config/feature-flags/utils.ts create mode 100644 pages/feature-flags.tsx diff --git a/.env.example b/.env.example index 35bde4ae2..00f856249 100644 --- a/.env.example +++ b/.env.example @@ -57,3 +57,5 @@ WALLETCONNECT_PROJECT_ID= # ETH Stake Widget API for IPFS mode WIDGET_API_BASE_PATH_FOR_IPFS= + +FEATURE_FLAGS_PAGE_IS_ENABLED=false diff --git a/config/feature-flags/hooks.ts b/config/feature-flags/hooks.ts new file mode 100644 index 000000000..f9b4eaf08 --- /dev/null +++ b/config/feature-flags/hooks.ts @@ -0,0 +1,28 @@ +import { useContext } from 'react'; +import invariant from 'tiny-invariant'; + +import { FeatureFlagsContext, FeatureFlagsContextType } from './provider'; +import { FeatureFlagsType } from './types'; + +type UseFeatureFlagReturnType = { + [key in keyof FeatureFlagsType]: boolean; +} & { + setFeatureFlag: (featureFlag: keyof FeatureFlagsType, value: boolean) => void; +}; + +export const useFeatureFlag = ( + flag: keyof FeatureFlagsType, +): UseFeatureFlagReturnType => { + const context = useContext(FeatureFlagsContext); + invariant(context, 'Attempt to use `feature flag` outside of provider'); + return { + [flag]: context[flag], + setFeatureFlag: context.setFeatureFlag, + }; +}; + +export const useFeatureFlags = (): FeatureFlagsContextType => { + const context = useContext(FeatureFlagsContext); + invariant(context, 'Attempt to use `feature flag` outside of provider'); + return context; +}; diff --git a/config/feature-flags/index.ts b/config/feature-flags/index.ts new file mode 100644 index 000000000..bb01ff006 --- /dev/null +++ b/config/feature-flags/index.ts @@ -0,0 +1,4 @@ +export * from './hooks'; +export * from './provider'; +export * from './types'; +export * from './utils'; diff --git a/config/feature-flags/provider.tsx b/config/feature-flags/provider.tsx new file mode 100644 index 000000000..3dc8d34ed --- /dev/null +++ b/config/feature-flags/provider.tsx @@ -0,0 +1,59 @@ +import { + PropsWithChildren, + useMemo, + useState, + useCallback, + createContext, +} from 'react'; +import { useLocalStorage } from '@lido-sdk/react'; + +import { getFeatureFlagsDefault } from './utils'; +import { FeatureFlagsType } from './types'; + +const STORAGE_FEATURE_FLAGS = 'lido-feature-flags'; + +const FEATURE_FLAGS_DEFAULT = getFeatureFlagsDefault(); + +export type FeatureFlagsContextType = FeatureFlagsType & { + setFeatureFlag: (featureFlag: keyof FeatureFlagsType, value: boolean) => void; +}; + +export const FeatureFlagsContext = + createContext(null); + +export const FeatureFlagsProvider = ({ children }: PropsWithChildren) => { + const [featureFlagsLocalStorage, setFeatureFlagsLocalStorage] = + useLocalStorage(STORAGE_FEATURE_FLAGS, FEATURE_FLAGS_DEFAULT); + + const [featureFlagsState, setFeatureFlagsState] = useState( + featureFlagsLocalStorage, + ); + + const setFeatureFlag = useCallback( + (featureFlag: keyof FeatureFlagsType, value: boolean) => { + setFeatureFlagsLocalStorage({ + ...featureFlagsState, + [featureFlag]: value, + }); + setFeatureFlagsState({ + ...featureFlagsState, + [featureFlag]: value, + }); + }, + [featureFlagsState, setFeatureFlagsLocalStorage], + ); + + const contextValue = useMemo(() => { + return { + ...FEATURE_FLAGS_DEFAULT, + ...featureFlagsState, + setFeatureFlag: setFeatureFlag, + }; + }, [featureFlagsState, setFeatureFlag]); + + return ( + + {children} + + ); +}; diff --git a/config/feature-flags/types.ts b/config/feature-flags/types.ts new file mode 100644 index 000000000..7ed6fa4fb --- /dev/null +++ b/config/feature-flags/types.ts @@ -0,0 +1,9 @@ +// TODO: maybe do we wants use 'feature flags' for this? +// export const FEATURE_FLAGS_PAGE_IS_ENABLED = 'featureFlagsPageIsEnabled'; +export const RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED = + 'rpcSettingsPageOnInfraIsEnabled'; + +export type FeatureFlagsType = { + // [FEATURE_FLAGS_PAGE_IS_ENABLED]: boolean; + [RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED]: boolean; +}; diff --git a/config/feature-flags/utils.ts b/config/feature-flags/utils.ts new file mode 100644 index 000000000..cfd5b6681 --- /dev/null +++ b/config/feature-flags/utils.ts @@ -0,0 +1,9 @@ +import { FeatureFlagsType } from './types'; + +export const getFeatureFlagsDefault = (): FeatureFlagsType => { + return { + // TODO: maybe do we wants use 'feature flags' for this? + // featureFlagsPageIsEnabled: true, + rpcSettingsPageOnInfraIsEnabled: false, + }; +}; diff --git a/env-dynamics.mjs b/env-dynamics.mjs index 60d85d5c3..e256418fc 100644 --- a/env-dynamics.mjs +++ b/env-dynamics.mjs @@ -47,3 +47,6 @@ export const prefillUnsafeElRpcUrls17000 = process.env.PREFILL_UNSAFE_EL_RPC_URL /** @type string */ export const widgetApiBasePathForIpfs = process.env.WIDGET_API_BASE_PATH_FOR_IPFS; + +/** @type boolean */ +export const featureFlagsPageIsEnabled = toBoolean(process.env.FEATURE_FLAGS_PAGE_IS_ENABLED); diff --git a/pages/feature-flags.tsx b/pages/feature-flags.tsx new file mode 100644 index 000000000..943b34461 --- /dev/null +++ b/pages/feature-flags.tsx @@ -0,0 +1,45 @@ +import { FC } from 'react'; +import { GetStaticProps } from 'next'; +import { Block, Checkbox } from '@lidofinance/lido-ui'; + +import { config } from 'config'; +import { + useFeatureFlag, + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, +} from 'config/feature-flags'; +import { Layout } from 'shared/components'; +import NoSSRWrapper from 'shared/components/no-ssr-wrapper'; + +const FeatureFlags: FC = () => { + const { rpcSettingsPageOnInfraIsEnabled, setFeatureFlag } = useFeatureFlag( + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, + ); + + return ( + + +
+ + + setFeatureFlag( + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, + !rpcSettingsPageOnInfraIsEnabled, + ) + } + label="RPC settings page on infra" + /> + +
+
+ ); +}; + +export default FeatureFlags; + +export const getStaticProps: GetStaticProps = async () => { + if (!config.featureFlagsPageIsEnabled) return { notFound: true }; + + return { props: {} }; +}; diff --git a/pages/settings.tsx b/pages/settings.tsx index 293a475dc..0eb5cfe63 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,23 +1,34 @@ import { FC } from 'react'; -import { GetStaticProps } from 'next'; +// import { GetStaticProps } from 'next'; -import { getConfig } from 'config'; +// import { config } from 'config'; +import { + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, + useFeatureFlag, +} from 'config/feature-flags'; import { Layout } from 'shared/components'; import { SettingsForm } from 'features/settings/settings-form'; +import NoSSRWrapper from 'shared/components/no-ssr-wrapper'; const Settings: FC = () => { + const { rpcSettingsPageOnInfraIsEnabled } = useFeatureFlag( + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, + ); + return ( - + + {rpcSettingsPageOnInfraIsEnabled && } + {!rpcSettingsPageOnInfraIsEnabled && <>Settings Not Available!} + ); }; export default Settings; -export const getStaticProps: GetStaticProps = async () => { - const { ipfsMode } = getConfig(); - if (!ipfsMode) return { notFound: true }; - - return { props: {} }; -}; +// export const getStaticProps: GetStaticProps = async () => { +// if (!config.ipfsMode) return { notFound: true }; +// +// return { props: {} }; +// }; diff --git a/providers/index.tsx b/providers/index.tsx index 50f05ec9a..d1e9b1ffa 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -4,6 +4,7 @@ import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; import { ConfigProvider } from 'config'; import { UserConfigProvider } from 'config/user-config'; +import { FeatureFlagsProvider } from 'config/feature-flags'; import { AppFlagProvider } from './app-flag'; import { IPFSInfoBoxStatusesProvider } from './ipfs-info-box-statuses'; @@ -16,18 +17,20 @@ export { MODAL, ModalContext } from './modals'; export const Providers: FC = ({ children }) => ( - - - - - - - {children} - - - - - + + + + + + + + {children} + + + + + + ); diff --git a/shared/components/layout/header/components/header-wallet.tsx b/shared/components/layout/header/components/header-wallet.tsx index b3f51fc38..4f4fd89f0 100644 --- a/shared/components/layout/header/components/header-wallet.tsx +++ b/shared/components/layout/header/components/header-wallet.tsx @@ -7,6 +7,10 @@ import { ThemeToggler } from '@lidofinance/lido-ui'; import NoSSRWrapper from '../../../no-ssr-wrapper'; import { getConfig } from 'config'; +import { + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, + useFeatureFlag, +} from 'config/feature-flags'; const { ipfsMode } = getConfig(); import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box'; @@ -23,6 +27,9 @@ const HeaderWallet: FC = () => { const router = useRouter(); const { active } = useWeb3(); const { chainId } = useSDK(); + const { rpcSettingsPageOnInfraIsEnabled } = useFeatureFlag( + RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, + ); const chainName = CHAINS[chainId]; const testNet = chainId !== CHAINS.Mainnet; @@ -44,7 +51,9 @@ const HeaderWallet: FC = () => { ) : ( )} - {ipfsMode && } + {(ipfsMode || rpcSettingsPageOnInfraIsEnabled) && ( + + )} {!queryTheme && } {ipfsMode && ( From 585bbb8984ec0b2713dcf9b3fb317d0bc0ef07b5 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Tue, 5 Mar 2024 13:13:01 +0300 Subject: [PATCH 29/48] refactor: use 'config' instead of 'getConfig()' --- config/csp/index.ts | 6 +--- config/dynamics.ts | 7 ++--- config/feature-flags/types.ts | 3 -- config/feature-flags/utils.ts | 2 -- config/get-preconfig.ts | 6 ++-- config/groups/stake.ts | 9 +++--- config/provider.tsx | 1 - config/rpc/index.ts | 7 ++--- config/use-config.ts | 1 + config/user-config/utils.ts | 25 ++++++----------- .../fetchers/requesters/json/backend.ts | 7 ++--- .../fetchers/requesters/rpc/stEthEth.ts | 6 ++-- features/rewards/hooks/useRewardsDataLoad.ts | 8 ++---- features/stake/stake-form/hooks.ts | 10 +++---- features/stake/stake-form/use-stake.ts | 18 ++++++------ features/stake/stake-form/utils.ts | 7 +++-- features/withdrawals/hooks/useWaitingTime.ts | 9 ++---- .../withdrawals/hooks/useWithdrawTxPrice.ts | 28 ++++++------------- .../unwrap/hooks/use-unwrap-gas-limit.ts | 16 +++++------ .../wrap/hooks/use-wrap-form-network-data.ts | 9 ++---- .../wsteth/wrap/hooks/use-wrap-gas-limit.ts | 15 ++++------ pages/api/eth-apr.ts | 12 ++++---- pages/api/eth-price.ts | 17 +++++------ pages/api/ldo-stats.ts | 13 +++++---- pages/api/lido-stats.ts | 13 +++++---- pages/api/lidostats.ts | 14 ++++++---- pages/api/oneinch-rate.ts | 8 ++---- pages/api/rpc.ts | 6 ++-- pages/api/short-lido-stats.ts | 13 ++++----- pages/api/sma-steth-apr.ts | 16 ++++++----- pages/api/totalsupply.ts | 20 ++++++------- shared/banners/curve/useCurve.ts | 5 ++-- shared/hooks/use-compare-with-router-path.ts | 6 ++-- shared/hooks/use-router-path.ts | 8 ++---- shared/hooks/useLidoApr.ts | 6 ++-- shared/hooks/useLidoStats.ts | 10 +++---- shared/hooks/useStakingLimitInfo.ts | 5 ++-- shared/hooks/useWeb3Key.ts | 5 ++-- utils/get-ipfs-base-path.ts | 5 ++-- utils/prependBasePath.ts | 5 ++-- utilsApi/contractAddressesMetricsMap.ts | 8 +++--- utilsApi/metrics/metrics.ts | 10 +++---- utilsApi/nextApiWrappers.ts | 7 ++--- 43 files changed, 177 insertions(+), 235 deletions(-) diff --git a/config/csp/index.ts b/config/csp/index.ts index 26c589f60..bfa4247b0 100644 --- a/config/csp/index.ts +++ b/config/csp/index.ts @@ -5,11 +5,7 @@ import type { ContentSecurityPolicyOption } from 'next-secure-headers/lib/rules' // Not use absolute import here! // code''' -// import { getConfig } from 'config'; -// import { getSecretConfig } from 'config'; -// or -// import { config } from 'config'; -// import { secretConfig } from 'config'; +// import { config, secretConfig } from 'config'; // ''' import { config } from '../get-config'; import { secretConfig } from '../get-secret-config'; diff --git a/config/dynamics.ts b/config/dynamics.ts index 483cf2b26..21e089878 100644 --- a/config/dynamics.ts +++ b/config/dynamics.ts @@ -9,11 +9,10 @@ declare global { } } -// Not use dynamics directly! +// Not use dynamics directly in project! // Only through: // code``` -// import { getConfig } from 'config'; -// or import { getConfig } from './get-config'; -// const { ... } = getConfig(); +// import { config } from 'config'; // or +// import { config } from './get-config'; // in config "namespace" // ``` export default typeof window !== 'undefined' ? window.__env__ : dynamics; diff --git a/config/feature-flags/types.ts b/config/feature-flags/types.ts index 7ed6fa4fb..ec8a110b3 100644 --- a/config/feature-flags/types.ts +++ b/config/feature-flags/types.ts @@ -1,9 +1,6 @@ -// TODO: maybe do we wants use 'feature flags' for this? -// export const FEATURE_FLAGS_PAGE_IS_ENABLED = 'featureFlagsPageIsEnabled'; export const RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED = 'rpcSettingsPageOnInfraIsEnabled'; export type FeatureFlagsType = { - // [FEATURE_FLAGS_PAGE_IS_ENABLED]: boolean; [RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED]: boolean; }; diff --git a/config/feature-flags/utils.ts b/config/feature-flags/utils.ts index cfd5b6681..d4d721b5f 100644 --- a/config/feature-flags/utils.ts +++ b/config/feature-flags/utils.ts @@ -2,8 +2,6 @@ import { FeatureFlagsType } from './types'; export const getFeatureFlagsDefault = (): FeatureFlagsType => { return { - // TODO: maybe do we wants use 'feature flags' for this? - // featureFlagsPageIsEnabled: true, rpcSettingsPageOnInfraIsEnabled: false, }; }; diff --git a/config/get-preconfig.ts b/config/get-preconfig.ts index 20da66acb..56bb048d4 100644 --- a/config/get-preconfig.ts +++ b/config/get-preconfig.ts @@ -8,8 +8,8 @@ export type PreConfigType = { } & typeof publicRuntimeConfig & typeof dynamics; -// getPreConfig() needs for external internal in 'config/groups/*' -// Not use getPreConfig() outside of 'config/groups/*' +// `getPreConfig()` needs for external internal in 'config/groups/*' +// Not use `getPreConfig()` outside of 'config/groups/*' export const getPreConfig = (): PreConfigType => { const BASE_PATH_ASSET = dynamics.ipfsMode ? '.' @@ -24,4 +24,6 @@ export const getPreConfig = (): PreConfigType => { }; }; +// `preConfig` needs for external internal in 'config/groups/*' +// Not use `preConfig` outside of 'config/groups/*' export const preConfig = getPreConfig(); diff --git a/config/groups/stake.ts b/config/groups/stake.ts index 06c7ed63e..dbacb8864 100644 --- a/config/groups/stake.ts +++ b/config/groups/stake.ts @@ -4,10 +4,9 @@ import { parseEther } from '@ethersproject/units'; import { IPFS_REFERRAL_ADDRESS } from './ipfs'; -// Not use getConfig() here!!! -// Use getPreConfig() only here!!! -import { getPreConfig } from '../get-preconfig'; -const { ipfsMode } = getPreConfig(); +// Not use here: +// import { config } from '../get-config'; +import { preConfig } from '../get-preconfig'; export const PRECISION = 10 ** 6; @@ -24,6 +23,6 @@ export const STAKE_GASLIMIT_FALLBACK = BigNumber.from( ), ); -export const STAKE_FALLBACK_REFERRAL_ADDRESS = ipfsMode +export const STAKE_FALLBACK_REFERRAL_ADDRESS = preConfig.ipfsMode ? IPFS_REFERRAL_ADDRESS : AddressZero; diff --git a/config/provider.tsx b/config/provider.tsx index 632951a4e..8ef1b63e2 100644 --- a/config/provider.tsx +++ b/config/provider.tsx @@ -5,7 +5,6 @@ import { getConfig } from './get-config'; export const ConfigContext = createContext(null); export const ConfigProvider = ({ children }: PropsWithChildren) => { - // TODO: check object destructuring is fast or use memo? const contextValue = getConfig(); return ( diff --git a/config/rpc/index.ts b/config/rpc/index.ts index 5e38dafd2..16d05d847 100644 --- a/config/rpc/index.ts +++ b/config/rpc/index.ts @@ -6,10 +6,9 @@ import { CHAINS } from 'consts/chains'; // Not use absolute import here! // code''' -// import { getConfig } from 'config'; +// import { config } from 'config'; // ''' -import { getConfig } from '../get-config'; -const { ipfsMode } = getConfig(); +import { config } from '../get-config'; import { useUserConfig } from '../user-config'; @@ -36,7 +35,7 @@ export const useGetRpcUrlByChainId = () => { return ''; } - if (ipfsMode) { + if (config.ipfsMode) { const rpc = userConfig.savedUserConfig.rpcUrls[chainId] || userConfig.prefillUnsafeElRpcUrls[chainId]?.[0]; diff --git a/config/use-config.ts b/config/use-config.ts index a7f201dab..025afe73c 100644 --- a/config/use-config.ts +++ b/config/use-config.ts @@ -1,5 +1,6 @@ import { useContext } from 'react'; import invariant from 'tiny-invariant'; + import { ConfigContext } from './provider'; export const useConfig = () => { diff --git a/config/user-config/utils.ts b/config/user-config/utils.ts index 6cfd19a30..6715d4247 100644 --- a/config/user-config/utils.ts +++ b/config/user-config/utils.ts @@ -1,30 +1,21 @@ // Not use absolute import here! // code''' -// import { getConfig } from 'config'; +// import { config } from 'config'; // ''' -import { getConfig } from '../get-config'; +import { config } from '../get-config'; import { UserConfigDefaultType } from './types'; -const { - defaultChain, - supportedChains, - prefillUnsafeElRpcUrls1, - prefillUnsafeElRpcUrls5, - prefillUnsafeElRpcUrls17000, - walletconnectProjectId, -} = getConfig(); - import { CHAINS } from 'consts/chains'; export const getUserConfigDefault = (): UserConfigDefaultType => { return { - defaultChain: Number(defaultChain), - supportedChainIds: supportedChains, + defaultChain: Number(config.defaultChain), + supportedChainIds: config.supportedChains, prefillUnsafeElRpcUrls: { - [CHAINS.Mainnet]: prefillUnsafeElRpcUrls1, - [CHAINS.Goerli]: prefillUnsafeElRpcUrls5, - [CHAINS.Holesky]: prefillUnsafeElRpcUrls17000, + [CHAINS.Mainnet]: config.prefillUnsafeElRpcUrls1, + [CHAINS.Goerli]: config.prefillUnsafeElRpcUrls5, + [CHAINS.Holesky]: config.prefillUnsafeElRpcUrls17000, }, - walletconnectProjectId: walletconnectProjectId, + walletconnectProjectId: config.walletconnectProjectId, }; }; diff --git a/features/rewards/fetchers/requesters/json/backend.ts b/features/rewards/fetchers/requesters/json/backend.ts index 5d5d03976..565dbd452 100644 --- a/features/rewards/fetchers/requesters/json/backend.ts +++ b/features/rewards/fetchers/requesters/json/backend.ts @@ -1,5 +1,4 @@ -import { getConfig } from 'config'; -const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); +import { config } from 'config'; export type BackendQuery = { address: string; @@ -16,8 +15,8 @@ export const backendRequest = async (query: BackendQuery) => { Object.entries(query).forEach(([k, v]) => params.append(k, v.toString())); const apiRewardsPath = `/api/rewards?${params.toString()}`; - const apiRewardsUrl = ipfsMode - ? `${widgetApiBasePathForIpfs}${apiRewardsPath}` + const apiRewardsUrl = config.ipfsMode + ? `${config.widgetApiBasePathForIpfs}${apiRewardsPath}` : apiRewardsPath; const requested = await fetch(apiRewardsUrl); diff --git a/features/rewards/fetchers/requesters/rpc/stEthEth.ts b/features/rewards/fetchers/requesters/rpc/stEthEth.ts index a3ed2a784..4882d7bea 100644 --- a/features/rewards/fetchers/requesters/rpc/stEthEth.ts +++ b/features/rewards/fetchers/requesters/rpc/stEthEth.ts @@ -2,9 +2,7 @@ import { constants } from 'ethers'; import type { BigNumber as EthersBigNumber } from 'ethers'; import { StaticJsonRpcBatchProvider } from '@lidofinance/eth-providers'; -import { getConfig } from 'config'; -const { defaultChain } = getConfig(); - +import { config } from 'config'; import rpcFetch from 'features/rewards/fetchers/rpcFetch'; const MAINNET_CURVE = '0xDC24316b9AE028F1497c275EB9192a3Ea0f67022'; @@ -15,7 +13,7 @@ For testnet simply provide 1-1 ratio for UI to work **/ export const stEthEthRequest = (mainnetProvider: StaticJsonRpcBatchProvider) => - defaultChain === 1 + config.defaultChain === 1 ? rpcFetch( mainnetProvider, MAINNET_CURVE, diff --git a/features/rewards/hooks/useRewardsDataLoad.ts b/features/rewards/hooks/useRewardsDataLoad.ts index 670f7e711..204bb6c62 100644 --- a/features/rewards/hooks/useRewardsDataLoad.ts +++ b/features/rewards/hooks/useRewardsDataLoad.ts @@ -1,8 +1,6 @@ import { useEffect, useRef } from 'react'; -import { getConfig } from 'config'; -const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); - +import { config } from 'config'; import { Backend } from 'features/rewards/types'; import { useLidoSWR } from 'shared/hooks'; import { swrAbortableMiddleware } from 'utils'; @@ -49,8 +47,8 @@ export const useRewardsDataLoad: UseRewardsDataLoad = (props) => { ); const apiRewardsPath = `/api/rewards?${params.toString()}`; - const apiRewardsUrl = ipfsMode - ? `${widgetApiBasePathForIpfs}${apiRewardsPath}` + const apiRewardsUrl = config.ipfsMode + ? `${config.widgetApiBasePathForIpfs}${apiRewardsPath}` : apiRewardsPath; const { data, ...rest } = useLidoSWR( diff --git a/features/stake/stake-form/hooks.ts b/features/stake/stake-form/hooks.ts index 17181446f..3414c044f 100644 --- a/features/stake/stake-form/hooks.ts +++ b/features/stake/stake-form/hooks.ts @@ -2,9 +2,7 @@ import { BigNumber } from 'ethers'; import { AddressZero } from '@ethersproject/constants'; import { useLidoSWR, useSDK, useSTETHContractRPC } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT, STAKE_GASLIMIT_FALLBACK } = - getConfig(); +import { config } from 'config'; import { STRATEGY_CONSTANT } from 'consts/swr-strategies'; import { applyGasLimitRatio } from './utils'; @@ -19,13 +17,13 @@ export const useStethSubmitGasLimit: UseStethSubmitGasLimit = () => { ['submit-gas-limit', chainId], async () => { const gasLimit = await stethContractRPC.estimateGas.submit(AddressZero, { - from: ESTIMATE_ACCOUNT, - value: ESTIMATE_AMOUNT, + from: config.ESTIMATE_ACCOUNT, + value: config.ESTIMATE_AMOUNT, }); return applyGasLimitRatio(gasLimit); }, STRATEGY_CONSTANT, ); - return data ?? STAKE_GASLIMIT_FALLBACK; + return data ?? config.STAKE_GASLIMIT_FALLBACK; }; diff --git a/features/stake/stake-form/use-stake.ts b/features/stake/stake-form/use-stake.ts index 0be437238..4bed5ce35 100644 --- a/features/stake/stake-form/use-stake.ts +++ b/features/stake/stake-form/use-stake.ts @@ -1,21 +1,19 @@ -import { useSDK, useSTETHContractWeb3 } from '@lido-sdk/react'; import { BigNumber } from 'ethers'; import { useCallback } from 'react'; import { useWeb3 } from 'reef-knot/web3-react'; import invariant from 'tiny-invariant'; +import { useSDK, useSTETHContractWeb3 } from '@lido-sdk/react'; -import { runWithTransactionLogger } from 'utils'; - -import { getConfig } from 'config'; -const { enableQaHelpers, STAKE_FALLBACK_REFERRAL_ADDRESS } = getConfig(); +import { config } from 'config'; +import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; +import { TX_OPERATION, useTransactionModal } from 'shared/transaction-modal'; +import { runWithTransactionLogger } from 'utils'; import { getErrorMessage } from 'utils/getErrorMessage'; import { isContract } from 'utils/isContract'; -import { TX_OPERATION, useTransactionModal } from 'shared/transaction-modal'; -import { MockLimitReachedError, getAddress, applyGasLimitRatio } from './utils'; import { getFeeData } from 'utils/getFeeData'; -import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; +import { MockLimitReachedError, getAddress, applyGasLimitRatio } from './utils'; type StakeArguments = { amount: BigNumber | null; @@ -49,7 +47,7 @@ export const useStake = ({ onConfirm }: StakeOptions) => { }); if ( - enableQaHelpers && + config.enableQaHelpers && window.localStorage.getItem('mockLimitReached') === 'true' ) { throw new MockLimitReachedError('Stake limit reached'); @@ -59,7 +57,7 @@ export const useStake = ({ onConfirm }: StakeOptions) => { isContract(account, providerRpc), referral ? getAddress(referral, providerRpc) - : STAKE_FALLBACK_REFERRAL_ADDRESS, + : config.STAKE_FALLBACK_REFERRAL_ADDRESS, ]); dispatchModalState({ diff --git a/features/stake/stake-form/utils.ts b/features/stake/stake-form/utils.ts index a83e9b200..a45596c25 100644 --- a/features/stake/stake-form/utils.ts +++ b/features/stake/stake-form/utils.ts @@ -2,11 +2,12 @@ import { BigNumber } from 'ethers'; import { isAddress } from 'ethers/lib/utils'; import type { BaseProvider } from '@ethersproject/providers'; -import { getConfig } from 'config'; -const { SUBMIT_EXTRA_GAS_TRANSACTION_RATIO, PRECISION } = getConfig(); +import { config } from 'config'; export const applyGasLimitRatio = (gasLimit: BigNumber): BigNumber => - gasLimit.mul(SUBMIT_EXTRA_GAS_TRANSACTION_RATIO * PRECISION).div(PRECISION); + gasLimit + .mul(config.SUBMIT_EXTRA_GAS_TRANSACTION_RATIO * config.PRECISION) + .div(config.PRECISION); export const getAddress = async ( input: string, diff --git a/features/withdrawals/hooks/useWaitingTime.ts b/features/withdrawals/hooks/useWaitingTime.ts index ddc4cc176..f6ef80f15 100644 --- a/features/withdrawals/hooks/useWaitingTime.ts +++ b/features/withdrawals/hooks/useWaitingTime.ts @@ -1,17 +1,14 @@ import { useMemo } from 'react'; import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { wqAPIBasePath } = getConfig(); +import { config } from 'config'; import { STRATEGY_EAGER } from 'consts/swr-strategies'; - +import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; import { useDebouncedValue } from 'shared/hooks'; import { encodeURLQuery } from 'utils/encodeURLQuery'; import { standardFetcher } from 'utils/standardFetcher'; import { FetcherError } from 'utils/fetcherError'; -import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; - const DEFAULT_DAYS_VALUE = 5; type RequestTimeResponse = { @@ -34,7 +31,7 @@ export const useWaitingTime = ( const { isApproximate } = options; const debouncedAmount = useDebouncedValue(amount, 1000); const url = useMemo(() => { - const basePath = wqAPIBasePath; + const basePath = config.wqAPIBasePath; const params = encodeURLQuery({ amount: debouncedAmount }); const queryString = params ? `?${params}` : ''; return `${basePath}/v1/request-time${queryString}`; diff --git a/features/withdrawals/hooks/useWithdrawTxPrice.ts b/features/withdrawals/hooks/useWithdrawTxPrice.ts index aa1be48a2..a4e39bd6f 100644 --- a/features/withdrawals/hooks/useWithdrawTxPrice.ts +++ b/features/withdrawals/hooks/useWithdrawTxPrice.ts @@ -5,18 +5,8 @@ import { useWeb3 } from 'reef-knot/web3-react'; import { TOKENS } from '@lido-sdk/constants'; import { useLidoSWR, useSDK } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { - ESTIMATE_ACCOUNT, - WITHDRAWAL_QUEUE_CLAIM_GAS_LIMIT_DEFAULT, - WITHDRAWAL_QUEUE_REQUEST_STETH_APPROVED_GAS_LIMIT_DEFAULT, - WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT, - WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT, - WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT, - wqAPIBasePath, -} = getConfig(); +import { config } from 'config'; import { STRATEGY_LAZY } from 'consts/swr-strategies'; - import { MAX_REQUESTS_COUNT } from 'features/withdrawals/withdrawals-constants'; import { useTxCostInUsd } from 'shared/hooks/txCost'; import { useDebouncedValue } from 'shared/hooks/useDebouncedValue'; @@ -42,17 +32,17 @@ export const useRequestTxPrice = ({ const fallback = token === 'STETH' ? isApprovalFlow - ? WITHDRAWAL_QUEUE_REQUEST_STETH_APPROVED_GAS_LIMIT_DEFAULT - : WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT + ? config.WITHDRAWAL_QUEUE_REQUEST_STETH_APPROVED_GAS_LIMIT_DEFAULT + : config.WITHDRAWAL_QUEUE_REQUEST_STETH_PERMIT_GAS_LIMIT_DEFAULT : isApprovalFlow - ? WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT - : WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT; + ? config.WITHDRAWAL_QUEUE_REQUEST_WSTETH_APPROVED_GAS_LIMIT_DEFAULT + : config.WITHDRAWAL_QUEUE_REQUEST_WSTETH_PERMIT_GAS_LIMIT_DEFAULT; const cappedRequestCount = Math.min(requestCount || 1, MAX_REQUESTS_COUNT); const debouncedRequestCount = useDebouncedValue(cappedRequestCount, 2000); const url = useMemo(() => { - const basePath = wqAPIBasePath; + const basePath = config.wqAPIBasePath; const params = encodeURLQuery({ token, requestCount: debouncedRequestCount, @@ -78,8 +68,8 @@ export const useRequestTxPrice = ({ Array.from({ length: debouncedRequestCount }).fill( BigNumber.from(100), ), - ESTIMATE_ACCOUNT, - { from: ESTIMATE_ACCOUNT }, + config.ESTIMATE_ACCOUNT, + { from: config.ESTIMATE_ACCOUNT }, ) ).toNumber(); return gasLimit; @@ -160,7 +150,7 @@ export const useClaimTxPrice = (requests: RequestStatusClaimable[]) => { const gasLimit = isEstimateLoading ? undefined : gasLimitResult?.toNumber() ?? - WITHDRAWAL_QUEUE_CLAIM_GAS_LIMIT_DEFAULT * requestCount; + config.WITHDRAWAL_QUEUE_CLAIM_GAS_LIMIT_DEFAULT * requestCount; const price = useTxCostInUsd(gasLimit); diff --git a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts index e63170996..00f3eafcb 100644 --- a/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts +++ b/features/wsteth/unwrap/hooks/use-unwrap-gas-limit.ts @@ -1,12 +1,9 @@ import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); - +import { config } from 'config'; import { UNWRAP_GAS_LIMIT } from 'consts/tx'; - -import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; import { STRATEGY_LAZY } from 'consts/swr-strategies'; +import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; export const useUnwrapGasLimit = () => { const wsteth = useWSTETHContractRPC(); @@ -17,9 +14,12 @@ export const useUnwrapGasLimit = () => { async (_key, chainId) => { if (!chainId) return; try { - const gasLimit = await wsteth.estimateGas.unwrap(ESTIMATE_AMOUNT, { - from: ESTIMATE_ACCOUNT, - }); + const gasLimit = await wsteth.estimateGas.unwrap( + config.ESTIMATE_AMOUNT, + { + from: config.ESTIMATE_ACCOUNT, + }, + ); return gasLimit; } catch (error) { console.warn(error); diff --git a/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts b/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts index 82478fdf9..8e6b8d61e 100644 --- a/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts +++ b/features/wsteth/wrap/hooks/use-wrap-form-network-data.ts @@ -5,15 +5,12 @@ import { useEthereumBalance, } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { BALANCE_PADDING } = getConfig(); - +import { config } from 'config'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { useIsMultisig } from 'shared/hooks/useIsMultisig'; import { useTokenMaxAmount } from 'shared/hooks/use-token-max-amount'; import { useMaxGasPrice, useStakingLimitInfo } from 'shared/hooks'; -import { STRATEGY_LAZY } from 'consts/swr-strategies'; - import { useWrapGasLimit } from './use-wrap-gas-limit'; // Provides all data fetching for form to function @@ -39,7 +36,7 @@ export const useWrapFormNetworkData = () => { limit: stakeLimitInfo?.currentStakeLimit, isPadded: !isMultisig, gasLimit: gasLimitETH, - padding: BALANCE_PADDING, + padding: config.BALANCE_PADDING, isLoading: isMultisigLoading, }); diff --git a/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts b/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts index 63f140cde..1a3573e68 100644 --- a/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts +++ b/features/wsteth/wrap/hooks/use-wrap-gas-limit.ts @@ -1,16 +1,13 @@ -import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; import { useWeb3 } from 'reef-knot/web3-react'; +import { useLidoSWR, useWSTETHContractRPC } from '@lido-sdk/react'; import { CHAINS } from '@lido-sdk/constants'; +import { config } from 'config'; import { WRAP_FROM_ETH_GAS_LIMIT, WRAP_GAS_LIMIT, WRAP_GAS_LIMIT_GOERLI, } from 'consts/tx'; - -import { getConfig } from 'config'; -const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); - import { useCurrentStaticRpcProvider } from 'shared/hooks/use-current-static-rpc-provider'; import { applyGasLimitRatio } from 'features/stake/stake-form/utils'; @@ -27,9 +24,9 @@ export const useWrapGasLimit = () => { const fetchGasLimitETH = async () => { try { return await staticRpcProvider.estimateGas({ - from: ESTIMATE_ACCOUNT, + from: config.ESTIMATE_ACCOUNT, to: wsteth.address, - value: ESTIMATE_AMOUNT, + value: config.ESTIMATE_AMOUNT, }); } catch (error) { console.warn(`${_key}::[eth]`, error); @@ -39,8 +36,8 @@ export const useWrapGasLimit = () => { const fetchGasLimitStETH = async () => { try { - return await wsteth.estimateGas.wrap(ESTIMATE_AMOUNT, { - from: ESTIMATE_ACCOUNT, + return await wsteth.estimateGas.wrap(config.ESTIMATE_AMOUNT, { + from: config.ESTIMATE_ACCOUNT, }); } catch (error) { console.warn(`${_key}::[steth]`, error); diff --git a/pages/api/eth-apr.ts b/pages/api/eth-apr.ts index 41a1988e0..82c80039d 100644 --- a/pages/api/eth-apr.ts +++ b/pages/api/eth-apr.ts @@ -1,9 +1,8 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { CACHE_ETH_APR_KEY, CACHE_ETH_APR_TTL } = getConfig(); - +import { API } from 'types'; +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { getEthApr, @@ -12,21 +11,20 @@ import { rateLimit, } from 'utilsApi'; import Metrics from 'utilsApi/metrics'; -import { API } from 'types'; -const cache = new Cache(); +const cache = new Cache(); // Proxy for third-party API. // Returns eth annual percentage rate // TODO: delete after viewing grafana const ethApr: API = async (_, res) => { - const cachedEthApr = cache.get(CACHE_ETH_APR_KEY); + const cachedEthApr = cache.get(config.CACHE_ETH_APR_KEY); if (cachedEthApr) { res.json(cachedEthApr); } else { const ethApr = await getEthApr(); - cache.put(CACHE_ETH_APR_KEY, ethApr, CACHE_ETH_APR_TTL); + cache.put(config.CACHE_ETH_APR_KEY, ethApr, config.CACHE_ETH_APR_TTL); res.json(ethApr); } diff --git a/pages/api/eth-price.ts b/pages/api/eth-price.ts index e196db6e8..413d1f84c 100644 --- a/pages/api/eth-price.ts +++ b/pages/api/eth-price.ts @@ -4,10 +4,7 @@ import { cacheControl, } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { CACHE_ETH_PRICE_KEY, CACHE_ETH_PRICE_TTL, CACHE_ETH_PRICE_HEADERS } = - getConfig(); - +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { getEthPrice, @@ -18,17 +15,21 @@ import { import Metrics from 'utilsApi/metrics'; import { API } from 'types'; -const cache = new Cache(); +const cache = new Cache(); // Proxy for third-party API. const ethPrice: API = async (req, res) => { - const cachedEthPrice = cache.get(CACHE_ETH_PRICE_KEY); + const cachedEthPrice = cache.get(config.CACHE_ETH_PRICE_KEY); if (cachedEthPrice) { res.json(cachedEthPrice); } else { const ethPrice = await getEthPrice(); - cache.put(CACHE_ETH_PRICE_KEY, { price: ethPrice }, CACHE_ETH_PRICE_TTL); + cache.put( + config.CACHE_ETH_PRICE_KEY, + { price: ethPrice }, + config.CACHE_ETH_PRICE_TTL, + ); res.json({ price: ethPrice }); } @@ -37,6 +38,6 @@ const ethPrice: API = async (req, res) => { export default wrapNextRequest([ rateLimit, responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.ETH_PRICE), - cacheControl({ headers: CACHE_ETH_PRICE_HEADERS }), + cacheControl({ headers: config.CACHE_ETH_PRICE_HEADERS }), defaultErrorHandler, ])(ethPrice); diff --git a/pages/api/ldo-stats.ts b/pages/api/ldo-stats.ts index 5e0da1382..1efdb4fc1 100644 --- a/pages/api/ldo-stats.ts +++ b/pages/api/ldo-stats.ts @@ -1,8 +1,7 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { CACHE_LDO_STATS_KEY, CACHE_LDO_STATS_TTL } = getConfig(); +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { @@ -14,20 +13,24 @@ import { import Metrics from 'utilsApi/metrics'; import { API } from 'types'; -const cache = new Cache(); +const cache = new Cache(); // Proxy for third-party API. // Returns LDO token information // DEPRECATED: In future will be delete!!! const ldoStats: API = async (req, res) => { - const cachedLidoStats = cache.get(CACHE_LDO_STATS_KEY); + const cachedLidoStats = cache.get(config.CACHE_LDO_STATS_KEY); if (cachedLidoStats) { res.status(200).json(cachedLidoStats); } else { const ldoStats = await getLdoStats(); - cache.put(CACHE_LDO_STATS_KEY, { data: ldoStats }, CACHE_LDO_STATS_TTL); + cache.put( + config.CACHE_LDO_STATS_KEY, + { data: ldoStats }, + config.CACHE_LDO_STATS_TTL, + ); res.status(200).json({ data: ldoStats }); } diff --git a/pages/api/lido-stats.ts b/pages/api/lido-stats.ts index 9b4feadf6..d1089efab 100644 --- a/pages/api/lido-stats.ts +++ b/pages/api/lido-stats.ts @@ -1,8 +1,7 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } = getConfig(); +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { getLidoStats, @@ -13,19 +12,23 @@ import { import Metrics from 'utilsApi/metrics'; import { API } from 'types'; -const cache = new Cache(); +const cache = new Cache(); // Proxy for third-party API. // Returns steth token information // DEPRECATED: In future will be delete!!! const lidoStats: API = async (req, res) => { - const cachedLidoStats = cache.get(CACHE_LIDO_STATS_KEY); + const cachedLidoStats = cache.get(config.CACHE_LIDO_STATS_KEY); if (cachedLidoStats) { res.status(200).json(cachedLidoStats); } else { const lidoStats = await getLidoStats(); - cache.put(CACHE_LIDO_STATS_KEY, { data: lidoStats }, CACHE_LIDO_STATS_TTL); + cache.put( + config.CACHE_LIDO_STATS_KEY, + { data: lidoStats }, + config.CACHE_LIDO_STATS_TTL, + ); res.status(200).json({ data: lidoStats }); } diff --git a/pages/api/lidostats.ts b/pages/api/lidostats.ts index 77c6db20f..d5b684707 100644 --- a/pages/api/lidostats.ts +++ b/pages/api/lidostats.ts @@ -1,9 +1,7 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { CACHE_LIDO_STATS_KEY, CACHE_LIDO_STATS_TTL } = getConfig(); - +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { getLidoStats, @@ -14,20 +12,24 @@ import { import Metrics from 'utilsApi/metrics'; import { API } from 'types'; -const cache = new Cache(); +const cache = new Cache(); // Proxy for third-party API. // Returns steth token information // Mirror of /api/lido-stats // DEPRECATED: In future will be delete!!! const lidoStats: API = async (req, res) => { - const cachedLidoStats = cache.get(CACHE_LIDO_STATS_KEY); + const cachedLidoStats = cache.get(config.CACHE_LIDO_STATS_KEY); if (cachedLidoStats) { res.status(200).json(cachedLidoStats); } else { const lidoStats = await getLidoStats(); - cache.put(CACHE_LIDO_STATS_KEY, { data: lidoStats }, CACHE_LIDO_STATS_TTL); + cache.put( + config.CACHE_LIDO_STATS_KEY, + { data: lidoStats }, + config.CACHE_LIDO_STATS_TTL, + ); res.status(200).json({ data: lidoStats }); } diff --git a/pages/api/oneinch-rate.ts b/pages/api/oneinch-rate.ts index 60a34e479..0fe5e7aeb 100644 --- a/pages/api/oneinch-rate.ts +++ b/pages/api/oneinch-rate.ts @@ -5,9 +5,7 @@ import { NextApiRequest, NextApiResponse } from 'next'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; import { CHAINS, TOKENS, getTokenAddress } from '@lido-sdk/constants'; -import { getConfig } from 'config'; -const { CACHE_ONE_INCH_RATE_KEY, CACHE_ONE_INCH_RATE_TTL } = getConfig(); - +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { getOneInchRate, @@ -57,7 +55,7 @@ const oneInchRate: API = async (req, res) => { return; // TODO: enable test in test/consts.ts const token = await validateAndGetQueryToken(req, res); - const cacheKey = `${CACHE_ONE_INCH_RATE_KEY}-${token}`; + const cacheKey = `${config.CACHE_ONE_INCH_RATE_KEY}-${token}`; const cachedOneInchRate = cache.get(cacheKey); if (cachedOneInchRate) { @@ -81,7 +79,7 @@ const oneInchRate: API = async (req, res) => { DEFAULT_AMOUNT, ); } - cache.put(cacheKey, { rate: oneInchRate }, CACHE_ONE_INCH_RATE_TTL); + cache.put(cacheKey, { rate: oneInchRate }, config.CACHE_ONE_INCH_RATE_TTL); res.status(200).json({ rate: oneInchRate }); }; diff --git a/pages/api/rpc.ts b/pages/api/rpc.ts index 5be35db28..5680da397 100644 --- a/pages/api/rpc.ts +++ b/pages/api/rpc.ts @@ -1,9 +1,7 @@ import { rpcFactory } from '@lidofinance/next-pages'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { defaultChain } = getConfig(); - +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { METRICS_PREFIX } from 'consts/metrics'; import { @@ -41,7 +39,7 @@ const rpc = rpcFactory({ 'eth_chainId', 'net_version', ], - defaultChain: `${defaultChain}`, + defaultChain: `${config.defaultChain}`, providers: rpcUrls, }); diff --git a/pages/api/short-lido-stats.ts b/pages/api/short-lido-stats.ts index 3f0c8a405..f114dc26a 100644 --- a/pages/api/short-lido-stats.ts +++ b/pages/api/short-lido-stats.ts @@ -1,7 +1,9 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; + import { API, SubgraphChains } from 'types'; import { cors, @@ -17,17 +19,14 @@ import { import Metrics from 'utilsApi/metrics'; import { parallelizePromises } from 'utils'; -import { getConfig } from 'config'; -const { defaultChain, CACHE_LIDO_SHORT_STATS_KEY, CACHE_LIDO_SHORT_STATS_TTL } = - getConfig(); - const cache = new Cache(); // Proxy for third-party API. // Returns stETH token information const shortLidoStats: API = async (req, res) => { - const chainId = (Number(req.query.chainId) as SubgraphChains) || defaultChain; - const cacheKey = `${CACHE_LIDO_SHORT_STATS_KEY}_${chainId}`; + const chainId = + (Number(req.query.chainId) as SubgraphChains) || config.defaultChain; + const cacheKey = `${config.CACHE_LIDO_SHORT_STATS_KEY}_${chainId}`; const cachedLidoStats = cache.get(cacheKey); if (cachedLidoStats) { @@ -49,7 +48,7 @@ const shortLidoStats: API = async (req, res) => { // set the cache if there is all the data // because right now there is no request error handling in parallelizePromises if (lidoHolders && totalStaked && stEthPrice) { - cache.put(cacheKey, shortLidoStats, CACHE_LIDO_SHORT_STATS_TTL); + cache.put(cacheKey, shortLidoStats, config.CACHE_LIDO_SHORT_STATS_TTL); } res.status(200).json(shortLidoStats); diff --git a/pages/api/sma-steth-apr.ts b/pages/api/sma-steth-apr.ts index 9d79da491..c13438d98 100644 --- a/pages/api/sma-steth-apr.ts +++ b/pages/api/sma-steth-apr.ts @@ -1,10 +1,8 @@ import { Cache } from 'memory-cache'; import { wrapRequest as wrapNextRequest } from '@lidofinance/next-api-wrapper'; -import { API } from 'types'; - -import { getConfig } from 'config'; -const { CACHE_SMA_STETH_APR_KEY, CACHE_SMA_STETH_APR_TTL } = getConfig(); +import { API } from 'types'; +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { responseTimeMetric, @@ -14,17 +12,21 @@ import { } from 'utilsApi'; import Metrics from 'utilsApi/metrics'; -const cache = new Cache(); +const cache = new Cache(); // TODO: deprecated, will be delete after check grafana dashboards const smaStethApr: API = async (_, res) => { - const cachedStethApr = cache.get(CACHE_SMA_STETH_APR_KEY); + const cachedStethApr = cache.get(config.CACHE_SMA_STETH_APR_KEY); if (cachedStethApr) { res.json(cachedStethApr); } else { const smaStethApr = await getSmaStethApr(); - cache.put(CACHE_SMA_STETH_APR_KEY, smaStethApr, CACHE_SMA_STETH_APR_TTL); + cache.put( + config.CACHE_SMA_STETH_APR_KEY, + smaStethApr, + config.CACHE_SMA_STETH_APR_TTL, + ); res.json(smaStethApr); } diff --git a/pages/api/totalsupply.ts b/pages/api/totalsupply.ts index 9a8b66976..7518e0385 100644 --- a/pages/api/totalsupply.ts +++ b/pages/api/totalsupply.ts @@ -4,13 +4,7 @@ import { cacheControl, } from '@lidofinance/next-api-wrapper'; -import { getConfig } from 'config'; -const { - CACHE_TOTAL_SUPPLY_KEY, - CACHE_TOTAL_SUPPLY_TTL, - CACHE_TOTAL_SUPPLY_HEADERS, -} = getConfig(); - +import { config } from 'config'; import { API_ROUTES } from 'consts/api'; import { getTotalStaked, @@ -21,17 +15,21 @@ import { import Metrics from 'utilsApi/metrics'; import { API } from 'types'; -const cache = new Cache(); +const cache = new Cache(); // Proxy for third-party API. const totalSupply: API = async (req, res) => { - const cachedTotalSupply = cache.get(CACHE_TOTAL_SUPPLY_KEY); + const cachedTotalSupply = cache.get(config.CACHE_TOTAL_SUPPLY_KEY); if (cachedTotalSupply) { res.json(cachedTotalSupply); } else { const totalSupply = await getTotalStaked(); - cache.put(CACHE_TOTAL_SUPPLY_KEY, totalSupply, CACHE_TOTAL_SUPPLY_TTL); + cache.put( + config.CACHE_TOTAL_SUPPLY_KEY, + totalSupply, + config.CACHE_TOTAL_SUPPLY_TTL, + ); res.json(totalSupply); } @@ -40,6 +38,6 @@ const totalSupply: API = async (req, res) => { export default wrapNextRequest([ rateLimit, responseTimeMetric(Metrics.request.apiTimings, API_ROUTES.TOTALSUPPLY), - cacheControl({ headers: CACHE_TOTAL_SUPPLY_HEADERS }), + cacheControl({ headers: config.CACHE_TOTAL_SUPPLY_HEADERS }), defaultErrorHandler, ])(totalSupply); diff --git a/shared/banners/curve/useCurve.ts b/shared/banners/curve/useCurve.ts index c26290fa1..cdc0bfccf 100644 --- a/shared/banners/curve/useCurve.ts +++ b/shared/banners/curve/useCurve.ts @@ -1,7 +1,6 @@ import { useLidoSWR } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { ethAPIBasePath } = getConfig(); +import { config } from 'config'; import { standardFetcher } from 'utils/standardFetcher'; @@ -9,7 +8,7 @@ import { CurveResponse } from './types'; export const useCurve = () => { return useLidoSWR( - `${ethAPIBasePath ?? ''}/v1/pool/curve/steth-eth/apr/last`, + `${config.ethAPIBasePath ?? ''}/v1/pool/curve/steth-eth/apr/last`, standardFetcher, ); }; diff --git a/shared/hooks/use-compare-with-router-path.ts b/shared/hooks/use-compare-with-router-path.ts index 49c9c4c21..7fd6586dc 100644 --- a/shared/hooks/use-compare-with-router-path.ts +++ b/shared/hooks/use-compare-with-router-path.ts @@ -1,9 +1,7 @@ import { useMemo } from 'react'; import { useRouter } from 'next/router'; -import { getConfig } from 'config'; -const { ipfsMode } = getConfig(); - +import { config } from 'config'; import { compareWithRouterPathInIPFS, compareWithRouterPathInInfra, @@ -14,7 +12,7 @@ export const useCompareWithRouterPath = (href: string) => { return useMemo( () => - ipfsMode + config.ipfsMode ? compareWithRouterPathInIPFS(router.asPath, href) : compareWithRouterPathInInfra(router.asPath, href), [router.asPath, href], diff --git a/shared/hooks/use-router-path.ts b/shared/hooks/use-router-path.ts index 71e63cf79..3466cad90 100644 --- a/shared/hooks/use-router-path.ts +++ b/shared/hooks/use-router-path.ts @@ -1,15 +1,13 @@ import { useRouter } from 'next/router'; -import { getConfig } from 'config'; -const { ipfsMode, isClientSide } = getConfig(); - +import { config } from 'config'; import { HOME_PATH } from 'consts/urls'; export const useRouterPath = () => { const router = useRouter(); - if (ipfsMode) { - if (!isClientSide) return HOME_PATH; + if (config.ipfsMode) { + if (!config.isClientSide) return HOME_PATH; return location.hash.replace('#', '') || HOME_PATH; } diff --git a/shared/hooks/useLidoApr.ts b/shared/hooks/useLidoApr.ts index 74e608a64..34d0a038d 100644 --- a/shared/hooks/useLidoApr.ts +++ b/shared/hooks/useLidoApr.ts @@ -1,10 +1,8 @@ import { SWRResponse, useLidoSWR } from '@lido-sdk/react'; import { CHAINS } from '@lido-sdk/constants'; -import { getConfig } from 'config'; -const { ethAPIBasePath } = getConfig(); +import { config } from 'config'; import { STRATEGY_LAZY } from 'consts/swr-strategies'; - import { standardFetcher } from 'utils/standardFetcher'; type SMA_APR_RESPONSE = { @@ -56,7 +54,7 @@ export const useLidoApr = (): SWRResponse & { apr?: string; } => { const { data, ...rest } = useLidoSWR( - `${ethAPIBasePath ?? ''}/v1/protocol/steth/apr/sma`, + `${config.ethAPIBasePath ?? ''}/v1/protocol/steth/apr/sma`, standardFetcher, STRATEGY_LAZY, ); diff --git a/shared/hooks/useLidoStats.ts b/shared/hooks/useLidoStats.ts index 79a6f4cb2..08105d736 100644 --- a/shared/hooks/useLidoStats.ts +++ b/shared/hooks/useLidoStats.ts @@ -1,13 +1,11 @@ import { useMemo } from 'react'; import { useSDK, useLidoSWR } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { ipfsMode, widgetApiBasePathForIpfs } = getConfig(); - +import { config } from 'config'; import { DATA_UNAVAILABLE } from 'consts/text'; +import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { prependBasePath } from 'utils'; import { standardFetcher } from 'utils/standardFetcher'; -import { STRATEGY_LAZY } from 'consts/swr-strategies'; export type ResponseData = { uniqueAnytimeHolders: string; @@ -27,8 +25,8 @@ export const useLidoStats = (): { const { chainId } = useSDK(); const apiShortLidoStatsPath = `api/short-lido-stats?chainId=${chainId}`; const lidoStats = useLidoSWR( - ipfsMode - ? `${widgetApiBasePathForIpfs}/${apiShortLidoStatsPath}` + config.ipfsMode + ? `${config.widgetApiBasePathForIpfs}/${apiShortLidoStatsPath}` : prependBasePath(apiShortLidoStatsPath), standardFetcher, STRATEGY_LAZY, diff --git a/shared/hooks/useStakingLimitInfo.ts b/shared/hooks/useStakingLimitInfo.ts index 8723a5e65..accf52118 100644 --- a/shared/hooks/useStakingLimitInfo.ts +++ b/shared/hooks/useStakingLimitInfo.ts @@ -6,8 +6,7 @@ import { CHAINS } from '@lido-sdk/constants'; import { StethAbi } from '@lido-sdk/contracts'; import { useSDK, useSTETHContractRPC } from '@lido-sdk/react'; -import { getConfig } from 'config'; -const { enableQaHelpers } = getConfig(); +import { config } from 'config'; import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { LIMIT_LEVEL } from 'types'; @@ -50,7 +49,7 @@ export const useStakingLimitInfo = () => { const steth = useSTETHContractRPC(); return useSwr( - ['swr:getStakeLimitFullInfo', chainId, steth, enableQaHelpers], + ['swr:getStakeLimitFullInfo', chainId, steth, config.enableQaHelpers], async ( _key: string, _chainId: CHAINS, diff --git a/shared/hooks/useWeb3Key.ts b/shared/hooks/useWeb3Key.ts index 30b09a6d6..074a47f67 100644 --- a/shared/hooks/useWeb3Key.ts +++ b/shared/hooks/useWeb3Key.ts @@ -1,11 +1,10 @@ import { useWeb3 } from 'reef-knot/web3-react'; -import { getConfig } from 'config'; -const { defaultChain } = getConfig(); +import { config } from 'config'; // In order to simplify side effects of switching wallets/chains // we can remount by this key, resetting all internal states export const useWeb3Key = () => { const { account, chainId } = useWeb3(); - return `${account ?? 'NO_ACCOUNT'}_${chainId ?? defaultChain}`; + return `${account ?? 'NO_ACCOUNT'}_${chainId ?? config.defaultChain}`; }; diff --git a/utils/get-ipfs-base-path.ts b/utils/get-ipfs-base-path.ts index f2ca3db04..19d09920f 100644 --- a/utils/get-ipfs-base-path.ts +++ b/utils/get-ipfs-base-path.ts @@ -1,7 +1,6 @@ import memoize from 'lodash/memoize'; -import { getConfig } from 'config'; -const { ipfsMode } = getConfig(); +import { config } from 'config'; import { encodeURLQuery } from './encodeURLQuery'; @@ -15,6 +14,6 @@ export const prefixUrl = (url: string, query?: Record) => { const queryString = query && Object.keys(query).length > 0 ? `?${encodeURLQuery(query)}` : ''; - if (ipfsMode) return `${getIpfsBasePath()}${queryString}#${url}`; + if (config.ipfsMode) return `${getIpfsBasePath()}${queryString}#${url}`; return url; }; diff --git a/utils/prependBasePath.ts b/utils/prependBasePath.ts index e2ddb1115..a08050e9b 100644 --- a/utils/prependBasePath.ts +++ b/utils/prependBasePath.ts @@ -1,6 +1,5 @@ -import { getConfig } from 'config'; -const { basePath } = getConfig(); +import { config } from 'config'; export const prependBasePath = (route: string): string => { - return `${basePath ?? ''}/${route}`; + return `${config.basePath ?? ''}/${route}`; }; diff --git a/utilsApi/contractAddressesMetricsMap.ts b/utilsApi/contractAddressesMetricsMap.ts index 6ba474d1f..aa45f512e 100644 --- a/utilsApi/contractAddressesMetricsMap.ts +++ b/utilsApi/contractAddressesMetricsMap.ts @@ -14,9 +14,7 @@ import { WstethAbiFactory, } from '@lido-sdk/contracts'; -import { getConfig } from 'config'; -const { supportedChains } = getConfig(); - +import { config } from 'config'; import { getAggregatorStEthUsdPriceFeedAddress } from 'consts/aggregator'; import { AggregatorAbi__factory, @@ -61,7 +59,9 @@ const getAddressOrNull = < } }; -export const METRIC_CONTRACT_ADDRESSES = (supportedChains as CHAINS[]).reduce( +export const METRIC_CONTRACT_ADDRESSES = ( + config.supportedChains as CHAINS[] +).reduce( (mapped, chainId) => { const map = { [CONTRACT_NAMES.stETH]: getAddressOrNull( diff --git a/utilsApi/metrics/metrics.ts b/utilsApi/metrics/metrics.ts index c06386e93..18d00cb51 100644 --- a/utilsApi/metrics/metrics.ts +++ b/utilsApi/metrics/metrics.ts @@ -1,9 +1,7 @@ import { collectDefaultMetrics, Registry } from 'prom-client'; import { collectStartupMetrics } from '@lidofinance/api-metrics'; -import { getConfig } from 'config'; -const { defaultChain, supportedChains } = getConfig(); - +import { config } from 'config'; import { METRICS_PREFIX } from 'consts/metrics'; import buildInfoJson from 'build-info.json'; @@ -26,8 +24,10 @@ class Metrics { collectStartupMetrics({ prefix: METRICS_PREFIX, registry: this.registry, - defaultChain: `${defaultChain}`, - supportedChains: supportedChains.map((chain: number) => `${chain}`), + defaultChain: `${config.defaultChain}`, + supportedChains: config.supportedChains.map( + (chain: number) => `${chain}`, + ), version: buildInfoJson.version, commit: buildInfoJson.commit, branch: buildInfoJson.branch, diff --git a/utilsApi/nextApiWrappers.ts b/utilsApi/nextApiWrappers.ts index ec3f4cd95..e46e13a18 100644 --- a/utilsApi/nextApiWrappers.ts +++ b/utilsApi/nextApiWrappers.ts @@ -9,15 +9,14 @@ import { DEFAULT_API_ERROR_MESSAGE, } from '@lidofinance/next-api-wrapper'; import { rateLimitWrapper } from '@lidofinance/next-ip-rate-limit'; +import { CHAINS } from '@lido-sdk/constants'; -import { secretConfig, getConfig } from 'config'; -const { CACHE_DEFAULT_HEADERS } = getConfig(); +import { config, secretConfig } from 'config'; import { getMetricContractInterface, METRIC_CONTRACT_ADDRESSES, } from './contractAddressesMetricsMap'; -import { CHAINS } from '@lido-sdk/constants'; export enum HttpMethod { GET = 'GET', @@ -211,7 +210,7 @@ export const defaultErrorHandler = nextDefaultErrorHandler({ export const errorAndCacheDefaultWrappers = [ cacheControl({ - headers: CACHE_DEFAULT_HEADERS, + headers: config.CACHE_DEFAULT_HEADERS, }), defaultErrorHandler, ]; From 96edd36fa7b6df7825442bb4c590806de56881f7 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Tue, 5 Mar 2024 13:18:41 +0300 Subject: [PATCH 30/48] revert: remove feature-flags demo page --- .env.example | 2 - env-dynamics.mjs | 3 -- pages/feature-flags.tsx | 45 ------------------- pages/settings.tsx | 28 ++++-------- .../header/components/header-wallet.tsx | 16 ++----- 5 files changed, 11 insertions(+), 83 deletions(-) delete mode 100644 pages/feature-flags.tsx diff --git a/.env.example b/.env.example index 00f856249..35bde4ae2 100644 --- a/.env.example +++ b/.env.example @@ -57,5 +57,3 @@ WALLETCONNECT_PROJECT_ID= # ETH Stake Widget API for IPFS mode WIDGET_API_BASE_PATH_FOR_IPFS= - -FEATURE_FLAGS_PAGE_IS_ENABLED=false diff --git a/env-dynamics.mjs b/env-dynamics.mjs index e256418fc..60d85d5c3 100644 --- a/env-dynamics.mjs +++ b/env-dynamics.mjs @@ -47,6 +47,3 @@ export const prefillUnsafeElRpcUrls17000 = process.env.PREFILL_UNSAFE_EL_RPC_URL /** @type string */ export const widgetApiBasePathForIpfs = process.env.WIDGET_API_BASE_PATH_FOR_IPFS; - -/** @type boolean */ -export const featureFlagsPageIsEnabled = toBoolean(process.env.FEATURE_FLAGS_PAGE_IS_ENABLED); diff --git a/pages/feature-flags.tsx b/pages/feature-flags.tsx deleted file mode 100644 index 943b34461..000000000 --- a/pages/feature-flags.tsx +++ /dev/null @@ -1,45 +0,0 @@ -import { FC } from 'react'; -import { GetStaticProps } from 'next'; -import { Block, Checkbox } from '@lidofinance/lido-ui'; - -import { config } from 'config'; -import { - useFeatureFlag, - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, -} from 'config/feature-flags'; -import { Layout } from 'shared/components'; -import NoSSRWrapper from 'shared/components/no-ssr-wrapper'; - -const FeatureFlags: FC = () => { - const { rpcSettingsPageOnInfraIsEnabled, setFeatureFlag } = useFeatureFlag( - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, - ); - - return ( - - -
- - - setFeatureFlag( - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, - !rpcSettingsPageOnInfraIsEnabled, - ) - } - label="RPC settings page on infra" - /> - -
-
- ); -}; - -export default FeatureFlags; - -export const getStaticProps: GetStaticProps = async () => { - if (!config.featureFlagsPageIsEnabled) return { notFound: true }; - - return { props: {} }; -}; diff --git a/pages/settings.tsx b/pages/settings.tsx index 0eb5cfe63..bd584333c 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -1,34 +1,22 @@ import { FC } from 'react'; -// import { GetStaticProps } from 'next'; +import { GetStaticProps } from 'next'; -// import { config } from 'config'; -import { - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, - useFeatureFlag, -} from 'config/feature-flags'; +import { config } from 'config'; import { Layout } from 'shared/components'; import { SettingsForm } from 'features/settings/settings-form'; -import NoSSRWrapper from 'shared/components/no-ssr-wrapper'; const Settings: FC = () => { - const { rpcSettingsPageOnInfraIsEnabled } = useFeatureFlag( - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, - ); - return ( - - {rpcSettingsPageOnInfraIsEnabled && } - {!rpcSettingsPageOnInfraIsEnabled && <>Settings Not Available!} - + ); }; export default Settings; -// export const getStaticProps: GetStaticProps = async () => { -// if (!config.ipfsMode) return { notFound: true }; -// -// return { props: {} }; -// }; +export const getStaticProps: GetStaticProps = async () => { + if (!config.ipfsMode) return { notFound: true }; + + return { props: {} }; +}; diff --git a/shared/components/layout/header/components/header-wallet.tsx b/shared/components/layout/header/components/header-wallet.tsx index 4f4fd89f0..2b646fae2 100644 --- a/shared/components/layout/header/components/header-wallet.tsx +++ b/shared/components/layout/header/components/header-wallet.tsx @@ -6,12 +6,7 @@ import { CHAINS, getChainColor } from '@lido-sdk/constants'; import { ThemeToggler } from '@lidofinance/lido-ui'; import NoSSRWrapper from '../../../no-ssr-wrapper'; -import { getConfig } from 'config'; -import { - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, - useFeatureFlag, -} from 'config/feature-flags'; -const { ipfsMode } = getConfig(); +import { config } from 'config'; import { IPFSInfoBox } from 'features/ipfs/ipfs-info-box'; import { Button, Connect } from 'shared/wallet'; @@ -27,9 +22,6 @@ const HeaderWallet: FC = () => { const router = useRouter(); const { active } = useWeb3(); const { chainId } = useSDK(); - const { rpcSettingsPageOnInfraIsEnabled } = useFeatureFlag( - RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED, - ); const chainName = CHAINS[chainId]; const testNet = chainId !== CHAINS.Mainnet; @@ -51,11 +43,9 @@ const HeaderWallet: FC = () => { ) : ( )} - {(ipfsMode || rpcSettingsPageOnInfraIsEnabled) && ( - - )} + {config.ipfsMode && } {!queryTheme && } - {ipfsMode && ( + {config.ipfsMode && ( From 54487a8e78d9a316ea7cc08d5281c50eb3ca2f27 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Tue, 5 Mar 2024 13:28:23 +0300 Subject: [PATCH 31/48] refactor: use 'config' instead of 'getConfig()' in *.tsx --- .../rewards/components/CopyAddressUrl.tsx | 5 ++-- features/rewards/components/IndexerLink.tsx | 5 ++-- features/rewards/components/stats/Stats.tsx | 6 ++--- features/stake/lido-stats/lido-stats.tsx | 12 ++++----- .../stake-form-context/stake-form-context.tsx | 5 ++-- .../swap-discount-banner.tsx | 9 +++---- .../list/unstake-amount-boundaries.tsx | 10 +++---- .../wrap/hooks/use-approve-gas-limit.tsx | 8 +++--- pages/_app.tsx | 5 ++-- pages/_document.tsx | 26 ++++++++++--------- pages/index.tsx | 5 ++-- providers/inpage-navigation.tsx | 9 +++---- providers/web3.tsx | 11 +++----- shared/components/layout/layout.tsx | 5 ++-- shared/components/local-link/index.tsx | 6 ++--- shared/formatters/format-date.tsx | 5 ++-- shared/formatters/format-percent.tsx | 5 ++-- shared/formatters/format-price.tsx | 8 +++--- 18 files changed, 61 insertions(+), 84 deletions(-) diff --git a/features/rewards/components/CopyAddressUrl.tsx b/features/rewards/components/CopyAddressUrl.tsx index 6f25a415e..719cbebe2 100644 --- a/features/rewards/components/CopyAddressUrl.tsx +++ b/features/rewards/components/CopyAddressUrl.tsx @@ -1,8 +1,7 @@ import { useMemo } from 'react'; import { ButtonIcon, Copy } from '@lidofinance/lido-ui'; -import { getConfig } from 'config'; -const { ipfsMode } = getConfig(); +import { config } from 'config'; import { useCopyToClipboard } from 'shared/hooks'; import { getBasedHashHref } from 'utils/get-based-hash-href'; @@ -12,7 +11,7 @@ const CopyAddressUrl = ({ address }: { address: string }) => { const url = useMemo(() => { const { href } = location; - if (ipfsMode) { + if (config.ipfsMode) { let withoutHashAndQuery = href.split('?')[0].split('#')[0]; if (withoutHashAndQuery[withoutHashAndQuery.length - 1] === '/') { // Remove first '/' diff --git a/features/rewards/components/IndexerLink.tsx b/features/rewards/components/IndexerLink.tsx index 1ec1ba0f6..2f05fd919 100644 --- a/features/rewards/components/IndexerLink.tsx +++ b/features/rewards/components/IndexerLink.tsx @@ -1,8 +1,7 @@ import { Box, External as ExternalLinkIcon } from '@lidofinance/lido-ui'; import { getEtherscanTxLink } from '@lido-sdk/helpers'; -import { getConfig } from 'config'; -const { defaultChain } = getConfig(); +import { config } from 'config'; // TODO: move to separate folders type Props = { @@ -12,7 +11,7 @@ type Props = { const IndexerLink = ({ transactionHash }: Props) => { if (!transactionHash) return null; - const link = getEtherscanTxLink(defaultChain, transactionHash); + const link = getEtherscanTxLink(config.defaultChain, transactionHash); return (
diff --git a/features/rewards/components/stats/Stats.tsx b/features/rewards/components/stats/Stats.tsx index 356501863..4be9385f1 100644 --- a/features/rewards/components/stats/Stats.tsx +++ b/features/rewards/components/stats/Stats.tsx @@ -6,9 +6,7 @@ import { Box, Link } from '@lidofinance/lido-ui'; import { useSDK, useTokenBalance } from '@lido-sdk/react'; import { TOKENS, getTokenAddress } from '@lido-sdk/constants'; -import { getConfig } from 'config'; -const { defaultChain } = getConfig(); - +import { config } from 'config'; import { stEthEthRequest } from 'features/rewards/fetchers/requesters'; import EthSymbol from 'features/rewards/components/EthSymbol'; import NumberFormat from 'features/rewards/components/NumberFormat'; @@ -37,7 +35,7 @@ export const Stats: FC = (props) => { const mainnetStaticRpcProvider = useMainnetStaticRpcProvider(); const getStEthEth = useCallback(async () => { - if (defaultChain !== 1) { + if (config.defaultChain !== 1) { setStEthEth(constants.WeiPerEther); } else { const stEthEth = await stEthEthRequest(mainnetStaticRpcProvider); diff --git a/features/stake/lido-stats/lido-stats.tsx b/features/stake/lido-stats/lido-stats.tsx index 5d1d4bb46..55f1649ba 100644 --- a/features/stake/lido-stats/lido-stats.tsx +++ b/features/stake/lido-stats/lido-stats.tsx @@ -8,8 +8,7 @@ import { Block, DataTable, Question, Tooltip } from '@lidofinance/lido-ui'; import { Section, MatomoLink } from 'shared/components'; import { useLidoApr, useLidoStats } from 'shared/hooks'; -import { getConfig } from 'config'; -const { ipfsMode } = getConfig(); +import { config } from 'config'; import { LIDO_APR_TOOLTIP_TEXT } from 'consts/text'; import { MATOMO_CLICK_EVENTS_TYPES } from 'consts/matomo-click-events'; @@ -33,12 +32,13 @@ export const LidoStats: FC = memo(() => { const lidoApr = useLidoApr(); const lidoStats = useLidoStats(); - const showApr = !ipfsMode || isStatItemAvailable(lidoApr.apr); + const showApr = !config.ipfsMode || isStatItemAvailable(lidoApr.apr); const showTotalStaked = - !ipfsMode || isStatItemAvailable(lidoStats.data.totalStaked); - const showStakers = !ipfsMode || isStatItemAvailable(lidoStats.data.stakers); + !config.ipfsMode || isStatItemAvailable(lidoStats.data.totalStaked); + const showStakers = + !config.ipfsMode || isStatItemAvailable(lidoStats.data.stakers); const showMarketCap = - !ipfsMode || isStatItemAvailable(lidoStats.data.marketCap); + !config.ipfsMode || isStatItemAvailable(lidoStats.data.marketCap); if (!showApr && !showTotalStaked && !showStakers && !showMarketCap) { return null; diff --git a/features/stake/stake-form/stake-form-context/stake-form-context.tsx b/features/stake/stake-form/stake-form-context/stake-form-context.tsx index a6f4fe632..c23b9bd53 100644 --- a/features/stake/stake-form/stake-form-context/stake-form-context.tsx +++ b/features/stake/stake-form/stake-form-context/stake-form-context.tsx @@ -35,8 +35,7 @@ import { } from './types'; import { useTokenMaxAmount } from 'shared/hooks/use-token-max-amount'; -import { getConfig } from 'config'; -const { BALANCE_PADDING } = getConfig(); +import { config } from 'config'; // // Data context @@ -91,7 +90,7 @@ const useStakeFormNetworkData = (): StakeFormNetworkData => { limit: stakingLimitInfo?.currentStakeLimit, isPadded: !isMultisig, gasLimit: gasLimit, - padding: BALANCE_PADDING, + padding: config.BALANCE_PADDING, isLoading: isMultisigLoading, }); diff --git a/features/stake/swap-discount-banner/swap-discount-banner.tsx b/features/stake/swap-discount-banner/swap-discount-banner.tsx index b5b758553..9659f3ec7 100644 --- a/features/stake/swap-discount-banner/swap-discount-banner.tsx +++ b/features/stake/swap-discount-banner/swap-discount-banner.tsx @@ -4,12 +4,9 @@ import { useLidoSWR } from '@lido-sdk/react'; import { Button } from '@lidofinance/lido-ui'; import { trackEvent } from '@lidofinance/analytics-matomo'; +import { config } from 'config'; import { MATOMO_CLICK_EVENTS } from 'consts/matomo-click-events'; import { OPEN_OCEAN_REFERRAL_ADDRESS } from 'consts/external-links'; - -import { getConfig } from 'config'; -const { enableQaHelpers } = getConfig(); - import { STRATEGY_LAZY } from 'consts/swr-strategies'; import { getOpenOceanRate } from 'utils/get-open-ocean-rate'; @@ -42,7 +39,7 @@ const fetchRate = async (): Promise => { const linkClickHandler = () => trackEvent(...MATOMO_CLICK_EVENTS.openOceanDiscount); -if (enableQaHelpers && typeof window !== 'undefined') { +if (config.enableQaHelpers && typeof window !== 'undefined') { (window as any).setMockDiscountRate = (rate?: number) => rate === undefined ? localStorage.removeItem(MOCK_LS_KEY) @@ -50,7 +47,7 @@ if (enableQaHelpers && typeof window !== 'undefined') { } const getData = (data: FetchRateResult | undefined) => { - if (!enableQaHelpers || typeof window == 'undefined') return data; + if (!config.enableQaHelpers || typeof window == 'undefined') return data; const mock = localStorage.getItem(MOCK_LS_KEY); if (mock) { return calculateDiscountState(parseFloat(mock)); diff --git a/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx b/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx index 3ce38ac93..2fae9a421 100644 --- a/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx +++ b/features/withdrawals/withdrawals-faq/list/unstake-amount-boundaries.tsx @@ -1,13 +1,13 @@ import { Accordion } from '@lidofinance/lido-ui'; -import { weiToEth } from 'utils'; +import { config } from 'config'; import { useWithdrawals } from 'features/withdrawals/contexts/withdrawals-context'; - -import { getConfig } from 'config'; -const { LOCALE } = getConfig(); +import { weiToEth } from 'utils'; const formatAmount = (value: number | undefined) => - value ? value.toLocaleString(LOCALE, { maximumFractionDigits: 18 }) : '...'; + value + ? value.toLocaleString(config.LOCALE, { maximumFractionDigits: 18 }) + : '...'; export const UnstakeAmountBoundaries: React.FC = () => { const { maxAmount, minAmount } = useWithdrawals(); diff --git a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx index c4a221b09..3a5dbec3f 100644 --- a/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx +++ b/features/wsteth/wrap/hooks/use-approve-gas-limit.tsx @@ -6,12 +6,10 @@ import { useWSTETHContractRPC, } from '@lido-sdk/react'; +import { config } from 'config'; import { WSTETH_APPROVE_GAS_LIMIT } from 'consts/tx'; import { STRATEGY_IMMUTABLE } from 'consts/swr-strategies'; -import { getConfig } from 'config'; -const { ESTIMATE_ACCOUNT, ESTIMATE_AMOUNT } = getConfig(); - export const useApproveGasLimit = () => { const steth = useSTETHContractRPC(); const wsteth = useWSTETHContractRPC(); @@ -25,8 +23,8 @@ export const useApproveGasLimit = () => { try { const gasLimit = await steth.estimateGas.approve( wsteth.address, - ESTIMATE_AMOUNT, - { from: ESTIMATE_ACCOUNT }, + config.ESTIMATE_AMOUNT, + { from: config.ESTIMATE_ACCOUNT }, ); return gasLimit; } catch (error) { diff --git a/pages/_app.tsx b/pages/_app.tsx index 41d65994f..8b9ae2262 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -9,8 +9,7 @@ import { migrationThemeCookiesToCrossDomainCookiesClientSide, } from '@lidofinance/lido-ui'; -import { getConfig } from 'config'; -const { ipfsMode } = getConfig(); +import { config } from 'config'; import { withCsp } from 'config/csp'; import { Providers } from 'providers'; @@ -53,6 +52,6 @@ const AppWrapper = (props: AppProps): JSX.Element => { ); }; -export default ipfsMode || process.env.NODE_ENV === 'development' +export default config.ipfsMode || process.env.NODE_ENV === 'development' ? AppWrapper : withCsp(AppWrapper); diff --git a/pages/_document.tsx b/pages/_document.tsx index ea9602801..a7a3bc85a 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -10,8 +10,7 @@ import { createHeadersObject } from 'next-secure-headers'; import { ServerStyleSheet } from 'styled-components'; import { Fonts, LidoUIHead } from '@lidofinance/lido-ui'; -import { getConfig } from 'config'; -const { BASE_PATH_ASSET, defaultChain, ipfsMode } = getConfig(); +import { config } from 'config'; import { contentSecurityPolicy } from 'config/csp'; import { InsertIpfsBaseScript } from 'features/ipfs/ipfs-base-script'; @@ -81,45 +80,48 @@ export default class MyDocument extends Document { name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" /> - {ipfsMode && ( + {config.ipfsMode && ( )} - + @@ -132,12 +134,12 @@ export default class MyDocument extends Document { - + {/* eslint-disable-next-line @next/next/no-sync-scripts */} -