From 4ef6eb980be05f6fac34dd45d9632651c205e243 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Thu, 23 Nov 2023 11:46:14 +0300 Subject: [PATCH 1/6] fix: rpc checker in ETH Widget IPFS in any chain --- utils/check-rpc-url.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/check-rpc-url.ts b/utils/check-rpc-url.ts index 07710982f..f2e7468b4 100644 --- a/utils/check-rpc-url.ts +++ b/utils/check-rpc-url.ts @@ -24,7 +24,7 @@ export const checkRpcUrl = async (rpcUrl: string, chainId: CHAINS) => { } // Doing a request to check rpc url is fetchable - const stethAddress = getTokenAddress(CHAINS.Mainnet, TOKENS.STETH); + const stethAddress = getTokenAddress(chainId, TOKENS.STETH); const stethContract = StethAbiFactory.connect(stethAddress, rpcProvider); await stethContract.name(); From 7bec54479303f97d5d1ff0cc4664467483d955f3 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sat, 25 Nov 2023 01:01:15 +0300 Subject: [PATCH 2/6] fix: disable getInitialProps in infra mode --- pages/_app.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pages/_app.tsx b/pages/_app.tsx index 74c5ce106..4b58354cc 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -38,7 +38,8 @@ const AppWrapper = (props: AppWrapperProps): JSX.Element => { const { envConfig, ...rest } = props; return ( - + // In infra version `envConfig` is undefined always + { ); }; +// #!if IPFS_MODE === "true" +// In IPFS mode we don't have server (IPFS version is SPA), +// therefore we inject env-dynamics in build time AppWrapper.getInitialProps = async (appContext: AppContext) => { const appProps = await NextApp.getInitialProps(appContext); return { ...appProps, - envConfig: parseEnvConfig(dynamics), + envConfig: parseEnvConfig(dynamics) ?? undefined, }; }; +// #!endif export default dynamics.ipfsMode || process.env.NODE_ENV === 'development' ? AppWrapper From 68a8d9c173088261817025b5f565f7fd4634c0b1 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Sun, 26 Nov 2023 14:54:24 +0300 Subject: [PATCH 3/6] feat(AppWrapper): remove getInitialProps --- pages/_app.tsx | 19 +++---------------- types/components.ts | 6 ++---- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/pages/_app.tsx b/pages/_app.tsx index 4b58354cc..e60722695 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,5 +1,5 @@ import { memo } from 'react'; -import NextApp, { AppProps, AppContext } from 'next/app'; +import { AppProps } from 'next/app'; import 'nprogress/nprogress.css'; import { @@ -35,11 +35,10 @@ const App = (props: AppProps) => { const MemoApp = memo(App); const AppWrapper = (props: AppWrapperProps): JSX.Element => { - const { envConfig, ...rest } = props; + const { ...rest } = props; return ( - // In infra version `envConfig` is undefined always - + { ); }; -// #!if IPFS_MODE === "true" -// In IPFS mode we don't have server (IPFS version is SPA), -// therefore we inject env-dynamics in build time -AppWrapper.getInitialProps = async (appContext: AppContext) => { - const appProps = await NextApp.getInitialProps(appContext); - return { - ...appProps, - envConfig: parseEnvConfig(dynamics) ?? undefined, - }; -}; -// #!endif - export default dynamics.ipfsMode || process.env.NODE_ENV === 'development' ? AppWrapper : withCsp(AppWrapper); diff --git a/types/components.ts b/types/components.ts index f493bbf45..d53ef685f 100644 --- a/types/components.ts +++ b/types/components.ts @@ -1,6 +1,5 @@ import { FC, ReactNode } from 'react'; import { AppProps } from 'next/app'; -import { EnvConfigParsed } from 'config'; export type ComponentProps< T extends keyof JSX.IntrinsicElements, @@ -17,8 +16,7 @@ export type Override< P extends Record, > = Omit & P; -export type AppWrapperProps = AppProps & { - envConfig: EnvConfigParsed; -}; +// Probably will come in handy later, id not - just delete and use `AppProps` +export type AppWrapperProps = AppProps; // & {}; export type AppWrapperType = FC; From db115ee70f60db7297c3c2ce382fd959a25de461 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 27 Nov 2023 11:57:06 +0300 Subject: [PATCH 4/6] feat: remove AppWrapperProps, remove passing envConfig to Providers --- pages/_app.tsx | 6 ++---- providers/client-config.tsx | 13 ++++++------- providers/index.tsx | 7 ++----- types/components.ts | 6 ------ utilsApi/withCSP.ts | 4 ++-- 5 files changed, 12 insertions(+), 24 deletions(-) diff --git a/pages/_app.tsx b/pages/_app.tsx index e60722695..4387ff2dd 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -13,9 +13,7 @@ import { dynamics } from 'config'; import { Providers } from 'providers'; import { BackgroundGradient } from 'shared/components/background-gradient/background-gradient'; import { nprogress, COOKIES_ALLOWED_FULL_KEY } from 'utils'; -import { parseEnvConfig } from 'utils/parse-env-config'; import { withCsp } from 'utilsApi/withCSP'; -import { AppWrapperProps } from 'types'; // Migrations old theme cookies to new cross domain cookies migrationThemeCookiesToCrossDomainCookiesClientSide(); @@ -34,11 +32,11 @@ const App = (props: AppProps) => { const MemoApp = memo(App); -const AppWrapper = (props: AppWrapperProps): JSX.Element => { +const AppWrapper = (props: AppProps): JSX.Element => { const { ...rest } = props; return ( - + >; @@ -33,16 +35,13 @@ export const useClientConfig = () => { return context; }; -type Props = { - envConfig: EnvConfigParsed; - children?: ReactNode; -}; - const DEFAULT_STATE: SavedClientConfig = { rpcUrls: {}, }; -export const ClientConfigProvider = ({ children, envConfig }: Props) => { +export const ClientConfigProvider = ({ children }: PropsWithChildren) => { + const envConfig = parseEnvConfig(dynamics); + const [restoredSettings, setLocalStorage] = useLocalStorage( STORAGE_CLIENT_CONFIG, DEFAULT_STATE, diff --git a/providers/index.tsx b/providers/index.tsx index d90ca0cbd..204a835d6 100644 --- a/providers/index.tsx +++ b/providers/index.tsx @@ -2,7 +2,6 @@ import { FC, PropsWithChildren } from 'react'; import { CookieThemeProvider } from '@lidofinance/lido-ui'; import { GlobalStyle } from 'styles'; -import { EnvConfigParsed } from '../config'; import { ClientConfigProvider } from './client-config'; import ModalProvider from './modals'; import Web3Provider from './web3'; @@ -10,10 +9,8 @@ import { AppFlagProvider } from './app-flag'; export { MODAL, ModalContext } from './modals'; -export const Providers: FC< - PropsWithChildren<{ envConfig: EnvConfigParsed }> -> = ({ envConfig, children }) => ( - +export const Providers: FC = ({ children }) => ( + diff --git a/types/components.ts b/types/components.ts index d53ef685f..30b5fde16 100644 --- a/types/components.ts +++ b/types/components.ts @@ -1,5 +1,4 @@ import { FC, ReactNode } from 'react'; -import { AppProps } from 'next/app'; export type ComponentProps< T extends keyof JSX.IntrinsicElements, @@ -15,8 +14,3 @@ export type Override< T extends Record, P extends Record, > = Omit & P; - -// Probably will come in handy later, id not - just delete and use `AppProps` -export type AppWrapperProps = AppProps; // & {}; - -export type AppWrapperType = FC; diff --git a/utilsApi/withCSP.ts b/utilsApi/withCSP.ts index 485f88cfe..519148840 100644 --- a/utilsApi/withCSP.ts +++ b/utilsApi/withCSP.ts @@ -1,9 +1,9 @@ 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 { AppWrapperType } from 'types'; const { serverRuntimeConfig } = getConfig(); const { cspTrustedHosts, cspReportOnly, cspReportUri, developmentMode } = @@ -76,7 +76,7 @@ export const contentSecurityPolicy = { reportOnly, }; -export const withCsp = (app: AppWrapperType): FC => +export const withCsp = (app: FC): FC => withSecureHeaders({ contentSecurityPolicy, frameGuard: false, From c02e453ad3b05b3e424ffe4e7f82ca53de2d9339 Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 27 Nov 2023 12:14:56 +0300 Subject: [PATCH 5/6] fix(providers): move envConfig parsing to contextValue memorized --- providers/client-config.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/providers/client-config.tsx b/providers/client-config.tsx index d84bc87a8..f5e40f737 100644 --- a/providers/client-config.tsx +++ b/providers/client-config.tsx @@ -40,8 +40,6 @@ const DEFAULT_STATE: SavedClientConfig = { }; export const ClientConfigProvider = ({ children }: PropsWithChildren) => { - const envConfig = parseEnvConfig(dynamics); - const [restoredSettings, setLocalStorage] = useLocalStorage( STORAGE_CLIENT_CONFIG, DEFAULT_STATE, @@ -59,12 +57,14 @@ export const ClientConfigProvider = ({ children }: PropsWithChildren) => { ); const contextValue = useMemo(() => { + const envConfig = parseEnvConfig(dynamics); + return { ...envConfig, savedClientConfig, setSavedClientConfig: setSavedConfigAndRemember, }; - }, [envConfig, savedClientConfig, setSavedConfigAndRemember]); + }, [savedClientConfig, setSavedConfigAndRemember]); return ( From 3d428094fd88afbc92cd69ecf2b4ae79f7e5d1ca Mon Sep 17 00:00:00 2001 From: Anton Shalimov Date: Mon, 27 Nov 2023 12:33:58 +0300 Subject: [PATCH 6/6] fix: remove resolutions duplicate --- package.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/package.json b/package.json index fb2ec0238..1836a081a 100644 --- a/package.json +++ b/package.json @@ -129,10 +129,6 @@ "postcss": "^8.4.31", "crypto-js": "^4.2.0" }, - "resolutions": { - "postcss": "^8.4.31", - "crypto-js": "^4.2.0" - }, "lint-staged": { "./**/*.{ts,tsx}": [ "eslint --ignore-path .gitignore --max-warnings=0"