-
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 #173 from lidofinance/develop
Merge develop to main
- Loading branch information
Showing
21 changed files
with
320 additions
and
112 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Wrap, InfoLink, Text } from './styles'; | ||
|
||
const GATEWAY_CHECKER_URL = 'https://ipfs.github.io/public-gateway-checker/'; | ||
const DESKTOP_APP_URL = 'https://github.com/ipfs/ipfs-desktop#ipfs-desktop'; | ||
|
||
export const CSPViolationBox = () => { | ||
return ( | ||
<Wrap> | ||
<Text weight={700} size="xs"> | ||
Insufficient Gateway CSP | ||
</Text> | ||
<Text weight={400} size="xxs"> | ||
RPC requests are blocked by Content Security Policy set by IPFS Gateway | ||
service you are using. | ||
</Text> | ||
<Text weight={700} size="xxs"> | ||
Possible actions: | ||
</Text> | ||
<Text weight={400} size="xxs"> | ||
Use another gateway service: | ||
<br /> | ||
<InfoLink href={GATEWAY_CHECKER_URL}>Public Gateway Checker</InfoLink> | ||
</Text> | ||
<Text weight={400} size="xxs"> | ||
Or install your IPFS Gateway: | ||
<br /> | ||
<InfoLink href={DESKTOP_APP_URL}>IPFS Desktop</InfoLink> | ||
</Text> | ||
</Wrap> | ||
); | ||
}; |
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 @@ | ||
export * from './csp-violation-box'; |
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,35 @@ | ||
import { ComponentProps, FC } from 'react'; | ||
import styled from 'styled-components'; | ||
import { Text as TextOriginal, themeDefault } from '@lidofinance/lido-ui'; | ||
import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; | ||
|
||
type TextProps = Omit<ComponentProps<typeof TextOriginal>, 'color'> & { | ||
color?: keyof typeof themeDefault.colors; | ||
}; | ||
export const Text: FC<TextProps> = styled(TextOriginal)<TextProps>` | ||
color: ${({ color }) => `var(--lido-color-${color})`}; | ||
`; | ||
|
||
export const Wrap = styled.div` | ||
position: relative; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 10px; | ||
border-radius: ${({ theme }) => theme.borderRadiusesMap.sm}px; | ||
padding: ${({ theme }) => theme.spaceMap.md}px | ||
${({ theme }) => theme.spaceMap.md}px; | ||
color: var(--lido-color-accentContrast); | ||
background-color: var(--lido-color-error); | ||
`; | ||
|
||
export const InfoLink = styled(LinkArrow)` | ||
font-weight: 700; | ||
&, | ||
&:visited, | ||
&:hover { | ||
color: var(--lido-color-accentContrast); | ||
} | ||
`; |
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,20 @@ | ||
import { useEffect, useState } from 'react'; | ||
|
||
export const useCSPViolation = () => { | ||
const [isCSPViolated, setCSPViolated] = useState(false); | ||
|
||
useEffect(() => { | ||
const handler = () => { | ||
setCSPViolated(true); | ||
}; | ||
document.addEventListener('securitypolicyviolation', handler); | ||
|
||
return () => { | ||
document.removeEventListener('securitypolicyviolation', handler); | ||
}; | ||
}, []); | ||
|
||
return { | ||
isCSPViolated, | ||
}; | ||
}; |
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,102 +1,15 @@ | ||
import { useCallback } from 'react'; | ||
import { useLidoSWR, useLocalStorage, useSDK } from '@lido-sdk/react'; | ||
import { useIPFSInfoBoxStatuses } from 'providers/ipfs-info-box-statuses'; | ||
|
||
import { useRpcUrl } from 'config/rpc'; | ||
import { SETTINGS_PATH } from 'config/urls'; | ||
import { usePrefixedPush } from 'shared/hooks/use-prefixed-history'; | ||
import { useRouterPath } from 'shared/hooks/use-router-path'; | ||
import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; | ||
|
||
import { Check, Close } from '@lidofinance/lido-ui'; | ||
import { Wrap, RpcStatusBox, Button, Text } from './styles'; | ||
|
||
import { checkRpcUrl } from 'utils/check-rpc-url'; | ||
import { STORAGE_IPFS_INFO_DISMISS } from 'config/storage'; | ||
|
||
const IPFS_INFO_URL = 'https://docs.ipfs.tech/concepts/what-is-ipfs/'; | ||
import { CSPViolationBox } from '../csp-violation-box'; | ||
import { RPCAvailabilityCheckResultBox } from '../rpc-availability-check-result-box'; | ||
|
||
export const IPFSInfoBox = () => { | ||
const { chainId } = useSDK(); | ||
const push = usePrefixedPush(); | ||
const [isDismissed, setDismissStorage] = useLocalStorage( | ||
STORAGE_IPFS_INFO_DISMISS, | ||
false, | ||
); | ||
|
||
const rpcUrl = useRpcUrl(); | ||
const { data: rpcCheckResult, initialLoading: isLoading } = useLidoSWR( | ||
`rpc-url-check-${rpcUrl}-${chainId}`, | ||
async () => { | ||
return await checkRpcUrl(rpcUrl, chainId); | ||
}, | ||
); | ||
|
||
const handleClickDismiss = useCallback(() => { | ||
setDismissStorage(true); | ||
}, [setDismissStorage]); | ||
|
||
const handleClickSettings = useCallback(() => { | ||
void push(SETTINGS_PATH); | ||
setDismissStorage(true); | ||
}, [push, setDismissStorage]); | ||
const { isCSPViolated, isShownTheRPCNotAvailableBox } = | ||
useIPFSInfoBoxStatuses(); | ||
|
||
const pathname = useRouterPath(); | ||
const isSettingsPage = pathname === SETTINGS_PATH; | ||
if (isCSPViolated) return <CSPViolationBox />; | ||
|
||
if ((isDismissed && rpcCheckResult === true) || isLoading || isSettingsPage) { | ||
return null; | ||
} | ||
if (isShownTheRPCNotAvailableBox) return <RPCAvailabilityCheckResultBox />; | ||
|
||
return ( | ||
<Wrap> | ||
<Text weight={700} size="xs" color="accentContrast"> | ||
You are currently using the IPFS widget's version. | ||
</Text> | ||
<LinkArrow href={IPFS_INFO_URL}>IPFS</LinkArrow> | ||
{rpcCheckResult === true && ( | ||
<> | ||
<RpcStatusBox status="success"> | ||
<Text | ||
weight={700} | ||
size="xxs" | ||
color="success" | ||
style={{ paddingRight: 10 }} | ||
> | ||
The pre-installed RPC node URL is now functioning correctly. | ||
</Text> | ||
<Check width={24} height={24} /> | ||
</RpcStatusBox> | ||
<Text weight={400} size="xxs" color="accentContrast"> | ||
However, you can visit the settings if you wish to customize your | ||
own RPC node URL. | ||
</Text> | ||
<Button size="xs" onClick={handleClickDismiss}> | ||
Dismiss | ||
</Button> | ||
</> | ||
)} | ||
{rpcCheckResult !== true && ( | ||
<> | ||
<RpcStatusBox status="error"> | ||
<Text | ||
weight={700} | ||
size="xxs" | ||
color="error" | ||
style={{ paddingRight: 10 }} | ||
> | ||
The pre-installed RPC node URL is not now functioning. | ||
</Text> | ||
<Close width={20} height={20} /> | ||
</RpcStatusBox> | ||
<Text weight={400} size="xxs" color="accentContrast"> | ||
You should visit the settings page and specify your own RPC node | ||
URL. | ||
</Text> | ||
<Button size="xs" onClick={handleClickSettings}> | ||
Open settings page | ||
</Button> | ||
</> | ||
)} | ||
</Wrap> | ||
); | ||
return null; | ||
}; |
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 @@ | ||
export * from './rpc-availability-check-result-box'; |
75 changes: 75 additions & 0 deletions
75
features/ipfs/rpc-availability-check-result-box/rpc-availability-check-result-box.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { useCallback } from 'react'; | ||
import { Check, Close } from '@lidofinance/lido-ui'; | ||
|
||
import { SETTINGS_PATH } from 'config/urls'; | ||
import { useIPFSInfoBoxStatuses } from 'providers/ipfs-info-box-statuses'; | ||
import { usePrefixedPush } from 'shared/hooks/use-prefixed-history'; | ||
import { LinkArrow } from 'shared/components/link-arrow/link-arrow'; | ||
|
||
import { Wrap, RpcStatusBox, Button, Text } from './styles'; | ||
|
||
const IPFS_INFO_URL = 'https://docs.ipfs.tech/concepts/what-is-ipfs/'; | ||
|
||
export const RPCAvailabilityCheckResultBox = () => { | ||
const { isRPCAvailable, handleClickDismiss } = useIPFSInfoBoxStatuses(); | ||
|
||
const push = usePrefixedPush(); | ||
|
||
const handleClickSettings = useCallback(() => { | ||
void push(SETTINGS_PATH); | ||
handleClickDismiss(); | ||
}, [push, handleClickDismiss]); | ||
|
||
return ( | ||
<Wrap> | ||
<Text weight={700} size="xs" color="accentContrast"> | ||
You are currently using the IPFS widget's version. | ||
</Text> | ||
<LinkArrow href={IPFS_INFO_URL}>IPFS</LinkArrow> | ||
{isRPCAvailable && ( | ||
<> | ||
<RpcStatusBox status="success"> | ||
<Text | ||
weight={700} | ||
size="xxs" | ||
color="success" | ||
style={{ paddingRight: 10 }} | ||
> | ||
The pre-installed RPC node URL is now functioning correctly. | ||
</Text> | ||
<Check width={24} height={24} /> | ||
</RpcStatusBox> | ||
<Text weight={400} size="xxs" color="accentContrast"> | ||
However, you can visit the settings if you wish to customize your | ||
own RPC node URL. | ||
</Text> | ||
<Button size="xs" onClick={handleClickDismiss}> | ||
Dismiss | ||
</Button> | ||
</> | ||
)} | ||
{!isRPCAvailable && ( | ||
<> | ||
<RpcStatusBox status="error"> | ||
<Text | ||
weight={700} | ||
size="xxs" | ||
color="error" | ||
style={{ paddingRight: 10 }} | ||
> | ||
The pre-installed RPC node URL is not now functioning. | ||
</Text> | ||
<Close width={20} height={20} /> | ||
</RpcStatusBox> | ||
<Text weight={400} size="xxs" color="accentContrast"> | ||
You should visit the settings page and specify your own RPC node | ||
URL. | ||
</Text> | ||
<Button size="xs" onClick={handleClickSettings}> | ||
Open settings page | ||
</Button> | ||
</> | ||
)} | ||
</Wrap> | ||
); | ||
}; |
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
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
Oops, something went wrong.