-
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 #297 from lidofinance/feature/si-1299-add-link-to-…
…ipfs-version-to-footer feat: add link to ipfs
- Loading branch information
Showing
11 changed files
with
178 additions
and
88 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
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> | ||
); | ||
}; |
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
1 change: 0 additions & 1 deletion
1
shared/components/layout/header/components/header-settings-button.tsx
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