-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #311 from lidofinance/develop
Develop to main
- Loading branch information
Showing
213 changed files
with
1,241 additions
and
898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useMemo, useState, useCallback } 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 useFeatureFlagsContext = () => { | ||
const [featureFlagsLocalStorage, setFeatureFlagsLocalStorage] = | ||
useLocalStorage(STORAGE_FEATURE_FLAGS, FEATURE_FLAGS_DEFAULT); | ||
|
||
const [featureFlagsState, setFeatureFlagsState] = useState<FeatureFlagsType>( | ||
featureFlagsLocalStorage, | ||
); | ||
|
||
const setFeatureFlag = useCallback( | ||
(featureFlag: keyof FeatureFlagsType, value: boolean) => { | ||
setFeatureFlagsLocalStorage({ | ||
...featureFlagsState, | ||
[featureFlag]: value, | ||
}); | ||
setFeatureFlagsState({ | ||
...featureFlagsState, | ||
[featureFlag]: value, | ||
}); | ||
}, | ||
[featureFlagsState, setFeatureFlagsLocalStorage], | ||
); | ||
|
||
return useMemo(() => { | ||
return { | ||
...FEATURE_FLAGS_DEFAULT, | ||
...featureFlagsState, | ||
setFeatureFlag: setFeatureFlag, | ||
}; | ||
}, [featureFlagsState, setFeatureFlag]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useContext, useMemo } from 'react'; | ||
import invariant from 'tiny-invariant'; | ||
|
||
import { ConfigContext } from '../provider'; | ||
import { FeatureFlagsContextType } from './context-hook'; | ||
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 | null => { | ||
const context = useContext(ConfigContext); | ||
invariant(context, 'Attempt to use `feature flag` outside of provider'); | ||
return useMemo(() => { | ||
return { | ||
[flag]: context.featureFlags[flag], | ||
setFeatureFlag: context.featureFlags?.setFeatureFlag, | ||
}; | ||
}, [context.featureFlags, flag]); | ||
}; | ||
|
||
export const useFeatureFlags = (): FeatureFlagsContextType | null => { | ||
const context = useContext(ConfigContext); | ||
invariant(context, 'Attempt to use `feature flag` outside of provider'); | ||
return useMemo(() => context.featureFlags, [context.featureFlags]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './hooks'; | ||
export * from './context-hook'; | ||
export * from './types'; | ||
export * from './utils'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED = | ||
'rpcSettingsPageOnInfraIsEnabled'; | ||
|
||
export type FeatureFlagsType = { | ||
[RPC_SETTINGS_PAGE_ON_INFRA_IS_ENABLED]: boolean; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { FeatureFlagsType } from './types'; | ||
|
||
export const getFeatureFlagsDefault = (): FeatureFlagsType => { | ||
return { | ||
rpcSettingsPageOnInfraIsEnabled: false, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { getPreConfig, PreConfigType } from './get-preconfig'; | ||
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'; | ||
|
||
export 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: typeof window !== 'undefined', | ||
isServerSide: typeof window === 'undefined', | ||
|
||
...cache, | ||
...estimate, | ||
...ipfs, | ||
...locale, | ||
...stake, | ||
...withdrawalQueueEstimate, | ||
|
||
// highest priority | ||
...getPreConfig(), | ||
}; | ||
}; | ||
|
||
export const config = getConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import getConfigNext from 'next/config'; | ||
import { default as dynamics } from './dynamics'; | ||
|
||
const { publicRuntimeConfig, serverRuntimeConfig } = getConfigNext(); | ||
|
||
export type PreConfigType = { | ||
BASE_PATH_ASSET: string; | ||
} & typeof publicRuntimeConfig & | ||
typeof dynamics; | ||
|
||
// `getPreConfig()` needs for internal using in 'config/groups/*' | ||
// Do not use `getPreConfig()` outside of 'config/groups/*' | ||
export const getPreConfig = (): PreConfigType => { | ||
const BASE_PATH_ASSET = dynamics.ipfsMode | ||
? '.' | ||
: (serverRuntimeConfig.basePath ?? '') || | ||
(publicRuntimeConfig.basePath ?? ''); | ||
|
||
return { | ||
BASE_PATH_ASSET, | ||
|
||
...publicRuntimeConfig, | ||
|
||
...(typeof window !== 'undefined' ? window.__env__ : dynamics), | ||
}; | ||
}; | ||
|
||
// `preConfig` needs for external internal in 'config/groups/*' | ||
// Not use `preConfig` outside of 'config/groups/*' | ||
export const preConfig = getPreConfig(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import getConfigNext from 'next/config'; | ||
import { type Modify, toBoolean } from './helpers'; | ||
|
||
const { serverRuntimeConfig } = getConfigNext(); | ||
|
||
export type SecretConfigType = Modify< | ||
typeof serverRuntimeConfig, | ||
{ | ||
defaultChain: number; | ||
|
||
rpcUrls_1: [string, ...string[]]; | ||
rpcUrls_5: [string, ...string[]]; | ||
rpcUrls_17000: [string, ...string[]]; | ||
|
||
cspReportOnly: boolean; | ||
|
||
subgraphRequestTimeout: number; | ||
|
||
rateLimit: number; | ||
rateLimitTimeFrame: number; | ||
} | ||
>; | ||
|
||
// 'getSecretConfig()' is required for the backend side. | ||
// We can't merge with 'getPreConfig()' because we want to split responsibility | ||
// | ||
// Also you can note that 'getSecretConfig' is just a proxy for 'serverRuntimeConfig' | ||
// because we want similar approach with 'getConfig' | ||
export const getSecretConfig = (): SecretConfigType => { | ||
return { | ||
...serverRuntimeConfig, | ||
|
||
// Keep fallback as in 'env-dynamics.mjs' | ||
defaultChain: Number(serverRuntimeConfig.defaultChain) || 17000, | ||
|
||
// Hack: in the current implementation we can treat an empty array as a "tuple" (conditionally) | ||
rpcUrls_1: (serverRuntimeConfig.rpcUrls_1?.split(',') ?? []) as [ | ||
string, | ||
...string[], | ||
], | ||
rpcUrls_5: (serverRuntimeConfig.rpcUrls_5?.split(',') ?? []) as [ | ||
string, | ||
...string[], | ||
], | ||
rpcUrls_17000: (serverRuntimeConfig.rpcUrls_17000?.split(',') ?? []) as [ | ||
string, | ||
...string[], | ||
], | ||
|
||
cspReportOnly: toBoolean(serverRuntimeConfig.cspReportOnly), | ||
|
||
subgraphRequestTimeout: | ||
Number(serverRuntimeConfig.subgraphRequestTimeout) || 5000, | ||
|
||
rateLimit: Number(serverRuntimeConfig.rateLimit) || 100, | ||
rateLimitTimeFrame: Number(serverRuntimeConfig.rateLimitTimeFrame) || 60, // 1 minute; | ||
}; | ||
}; | ||
|
||
export const secretConfig = getSecretConfig(); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const IPFS_REFERRAL_ADDRESS = | ||
'0x74d6e4Fd83A0b5623BDE3B2dF9a9A7F31fE02325'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 0 additions & 6 deletions
6
config/estimate.ts → config/groups/withdrawal-queue-estimate.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export type Modify<T, R> = Omit<T, keyof R> & R; | ||
|
||
export const toBoolean = (val: any) => { | ||
return ( | ||
val?.toLowerCase?.() === 'true' || | ||
val === true || | ||
Number.parseInt(val, 10) === 1 | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,4 @@ | ||
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'; | ||
export * from './get-config'; | ||
export * from './get-secret-config'; | ||
export * from './provider'; | ||
export * from './use-config'; |
Oops, something went wrong.