-
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 #570 from lidofinance/develop
Merge develop to main
- Loading branch information
Showing
22 changed files
with
294 additions
and
71 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,54 @@ | ||
import { useMemo } from 'react'; | ||
import { | ||
Manifest, | ||
ManifestConfig, | ||
ManifestConfigPage, | ||
ManifestConfigPageList, | ||
ManifestEntry, | ||
isManifestValid, | ||
} from 'config/external-config'; | ||
import { getDexConfig } from 'features/withdrawals/request/withdrawal-rates'; | ||
|
||
import FallbackLocalManifest from 'IPFS.json' assert { type: 'json' }; | ||
|
||
export const getBackwardCompatibleConfig = ( | ||
config: ManifestEntry['config'], | ||
): ManifestEntry['config'] => { | ||
let pages: ManifestConfig['pages']; | ||
const configPages = config.pages; | ||
if (configPages) { | ||
pages = (Object.keys(configPages) as ManifestConfigPage[]) | ||
.filter((key) => ManifestConfigPageList.has(key)) | ||
.reduce( | ||
(acc, key) => { | ||
if (acc) { | ||
acc[key] = { ...configPages[key] }; | ||
} | ||
|
||
return acc; | ||
}, | ||
{} as ManifestConfig['pages'], | ||
); | ||
} | ||
|
||
return { | ||
enabledWithdrawalDexes: config.enabledWithdrawalDexes.filter( | ||
(dex) => !!getDexConfig(dex), | ||
), | ||
featureFlags: { ...(config.featureFlags ?? {}) }, | ||
multiChainBanner: config.multiChainBanner ?? [], | ||
pages, | ||
}; | ||
}; | ||
|
||
export const useFallbackManifestEntry = ( | ||
prefetchedManifest: unknown, | ||
chain: number, | ||
): ManifestEntry => { | ||
return useMemo(() => { | ||
const isValid = isManifestValid(prefetchedManifest, chain); | ||
return isValid | ||
? prefetchedManifest[chain] | ||
: (FallbackLocalManifest as unknown as Manifest)[chain]; | ||
}, [prefetchedManifest, chain]); | ||
}; |
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
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
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
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,47 @@ | ||
import { useState, useCallback, useMemo, ReactNode } from 'react'; | ||
import { useRouter } from 'next/router'; | ||
|
||
import { useRouterPath } from 'shared/hooks/use-router-path'; | ||
import { useConfig } from 'config'; | ||
import { | ||
ManifestConfigPage, | ||
ManifestConfigPageEnum, | ||
} from 'config/external-config'; | ||
import { HOME_PATH } from 'consts/urls'; | ||
|
||
import { LayoutEffectSsrDelayed } from 'shared/components/layout-effect-ssr-delayed'; | ||
|
||
export const ExternalForbiddenRouteProvider = ({ | ||
children, | ||
}: { | ||
children: ReactNode; | ||
}) => { | ||
const [showContent, setShowContent] = useState(true); | ||
const router = useRouter(); | ||
const path = useRouterPath(); | ||
const { pages } = useConfig().externalConfig; | ||
|
||
const checkPathEffect = useCallback(() => { | ||
if (pages) { | ||
const paths = Object.keys(pages) as ManifestConfigPage[]; | ||
const forbiddenPath = paths.find((pathKey) => path.includes(pathKey)); | ||
if ( | ||
forbiddenPath && | ||
forbiddenPath !== ManifestConfigPageEnum.Stake && | ||
pages[forbiddenPath]?.shouldDisable | ||
) { | ||
setShowContent(false); | ||
void router.push(HOME_PATH).finally(() => setShowContent(true)); | ||
} | ||
} | ||
}, [pages, path, router]); | ||
|
||
const effectDeps = useMemo(() => [pages, path], [pages, path]); | ||
|
||
return ( | ||
<> | ||
<LayoutEffectSsrDelayed effect={checkPathEffect} deps={effectDeps} /> | ||
{showContent && children} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.