-
Notifications
You must be signed in to change notification settings - Fork 13
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 #298 from lidofinance/develop
Merge develop to main
- Loading branch information
Showing
18 changed files
with
187 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
export { HomePageIpfs } from './home-page-ipfs'; | ||
|
||
export { IPFS_INFO_URL } from './rpc-availability-check-result-box'; | ||
export { FaqPlaceholder } from './faq-placeholder'; | ||
export { SecurityStatusBanner } from './security-status-banner'; | ||
export { | ||
SecurityStatusBanner, | ||
useRemoteVersion, | ||
} from './security-status-banner'; | ||
export { InsertIpfsBaseScript } from './ipfs-base-script'; |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export { SecurityStatusBanner } from './security-status-banner'; | ||
export { useRemoteVersion } from './use-remote-version'; |
66 changes: 66 additions & 0 deletions
66
features/ipfs/security-status-banner/use-remote-version.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { useLidoSWR } from '@lido-sdk/react'; | ||
import { dynamics } from 'config'; | ||
import { useMainnetStaticRpcProvider } from 'shared/hooks/use-mainnet-static-rpc-provider'; | ||
import { standardFetcher } from 'utils/standardFetcher'; | ||
import { STRATEGY_LAZY } from 'utils/swrStrategies'; | ||
|
||
type EnsHashCheckReturn = { | ||
cid: string; | ||
ens?: string; | ||
leastSafeVersion?: string; | ||
link: string; | ||
} | null; | ||
|
||
type ReleaseInfoData = Record<string, ReleaseInfo>; | ||
|
||
type ReleaseInfo = { | ||
cid?: string; | ||
ens?: string; | ||
leastSafeVersion?: string; | ||
}; | ||
|
||
// for dev and local testing you can set to '/runtime/IPFS.json' and have file at /public/runtime/ | ||
const IPFS_RELEASE_URL = | ||
'https://raw.githubusercontent.com/lidofinance/ethereum-staking-widget/main/IPFS.json'; | ||
|
||
export const useRemoteVersion = () => { | ||
const provider = useMainnetStaticRpcProvider(); | ||
// ens cid extraction | ||
return useLidoSWR<EnsHashCheckReturn>( | ||
['swr:use-remote-version'], | ||
async (): Promise<EnsHashCheckReturn> => { | ||
const releaseInfoData = await standardFetcher<ReleaseInfoData>( | ||
IPFS_RELEASE_URL, | ||
{ | ||
headers: { Accept: 'application/json' }, | ||
}, | ||
); | ||
|
||
const releaseInfo = releaseInfoData[dynamics.defaultChain.toString()]; | ||
if (releaseInfo?.ens) { | ||
const resolver = await provider.getResolver(releaseInfo.ens); | ||
if (resolver) { | ||
const contentHash = await resolver.getContentHash(); | ||
if (contentHash) { | ||
return { | ||
cid: contentHash, | ||
ens: releaseInfo.ens, | ||
link: `https://${releaseInfo.ens}.limo`, | ||
leastSafeVersion: releaseInfo.leastSafeVersion, | ||
}; | ||
} | ||
} | ||
} | ||
if (releaseInfo?.cid) { | ||
return { | ||
cid: releaseInfo.cid, | ||
link: `https://${releaseInfo.cid}.ipfs.cf-ipfs.com`, | ||
leastSafeVersion: releaseInfo.leastSafeVersion, | ||
}; | ||
} | ||
|
||
throw new Error('invalid IPFS manifest content'); | ||
}, | ||
{ ...STRATEGY_LAZY }, | ||
); | ||
}; |
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,15 @@ | ||
import { IPFS_INFO_URL, useRemoteVersion } from 'features/ipfs'; | ||
|
||
import { OnlyInfraRender } from 'shared/components/only-infra-render'; | ||
import { ExternalLink } from './styles'; | ||
|
||
export const LinkToIpfs = () => { | ||
const { data } = useRemoteVersion(); | ||
return ( | ||
<OnlyInfraRender | ||
renderIPFS={<ExternalLink href={IPFS_INFO_URL}>IPFS Docs</ExternalLink>} | ||
> | ||
{data && <ExternalLink href={data?.link}>IPFS</ExternalLink>} | ||
</OnlyInfraRender> | ||
); | ||
}; |
Oops, something went wrong.