-
Notifications
You must be signed in to change notification settings - Fork 404
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add capability for feed notices (#1440)
* Add feed notice capability --------- Co-authored-by: Yacine Benichou <[email protected]> * Fix typescript issues * Edits * More edits not included in previous commit * Updates * Fix typo in threshold variable name --------- Co-authored-by: Yacine Benichou <[email protected]>
- Loading branch information
Showing
8 changed files
with
277 additions
and
3 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
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
67 changes: 67 additions & 0 deletions
67
src/features/feeds/components/pause-notice/CheckHeartbeat.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,67 @@ | ||
/** @jsxImportSource preact */ | ||
import { useCallback, useEffect, useState } from "preact/hooks" | ||
import { aggregatorV3InterfaceABI } from "@abi" | ||
import { Contract } from "ethers" | ||
import { ROUND_DATA_RESPONSE } from "@features/feeds" | ||
import { PauseNotice } from "./PauseNotice" | ||
import { SupportedChain } from "@config" | ||
import { getWeb3Provider } from "~/features/utils" | ||
|
||
export const CheckHeartbeat = ({ | ||
feedAddress, | ||
supportedChain, | ||
feedName, | ||
list, | ||
currencyName, | ||
}: { | ||
feedAddress: string | ||
supportedChain: SupportedChain | ||
feedName: string | ||
list?: boolean | ||
currencyName: string | ||
}) => { | ||
const [latestUpdateTimestamp, setLatestUpdateTimestamp] = useState<number | undefined>(undefined) | ||
const getLatestTimestamp = useCallback(async () => { | ||
const rpcProvider = getWeb3Provider(supportedChain) | ||
if (!rpcProvider) { | ||
console.error(`web3 provider not found for chain ${supportedChain}`) | ||
return | ||
} | ||
const dataFeed = new Contract(feedAddress, aggregatorV3InterfaceABI, rpcProvider) | ||
const roundData: ROUND_DATA_RESPONSE = await dataFeed.latestRoundData() | ||
if (!roundData.updatedAt) { | ||
return | ||
} | ||
const updatedTimestamp = roundData.updatedAt.toNumber() | ||
setLatestUpdateTimestamp(updatedTimestamp) | ||
}, [feedAddress]) | ||
|
||
useEffect(() => { | ||
let timeout: NodeJS.Timeout | ||
const fetchData = async () => { | ||
await getLatestTimestamp() | ||
if (!latestUpdateTimestamp) { | ||
timeout = setInterval(getLatestTimestamp, 5000) | ||
} | ||
} | ||
fetchData() | ||
return () => { | ||
clearTimeout(timeout) | ||
} | ||
}, [getLatestTimestamp, latestUpdateTimestamp]) | ||
|
||
return latestUpdateTimestamp ? ( | ||
<div> | ||
<PauseNotice | ||
value={latestUpdateTimestamp} | ||
list={list} | ||
type="alert" | ||
feedName={feedName} | ||
feedAddress={feedAddress} | ||
heartbeat={86400} | ||
buffer={900} | ||
currencyName={currencyName} | ||
/> | ||
</div> | ||
) : null | ||
} |
75 changes: 75 additions & 0 deletions
75
src/features/feeds/components/pause-notice/PauseNotice.module.css
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 @@ | ||
.notice { | ||
color: black; | ||
padding: 0.5em; | ||
} | ||
|
||
.banner { | ||
display: inline-flex; | ||
border-color: black; | ||
border-style: solid; | ||
border-width: 0.1em; | ||
border-radius: 0.4em; | ||
} | ||
|
||
.alert { | ||
background-color: var(--yellow-100); | ||
} | ||
|
||
.danger { | ||
background-color: var(--red-200); | ||
} | ||
|
||
.alert:before { | ||
background-color: var(--yellow-100); | ||
} | ||
|
||
.danger:before { | ||
background-color: var(--red-200); | ||
} | ||
|
||
.icon { | ||
min-width: 2em; | ||
margin-left: 1em; | ||
vertical-align: middle; | ||
} | ||
|
||
.iconSmall { | ||
min-width: 1em; | ||
margin-left: 0.5em; | ||
vertical-align: middle; | ||
} | ||
|
||
.tooltip { | ||
position: relative; | ||
} | ||
|
||
.tooltip:hover { | ||
color: var(--black); | ||
cursor: default; | ||
} | ||
|
||
.tooltip:before { | ||
position: absolute; | ||
z-index: 50; | ||
bottom: 4em; | ||
left: 0; | ||
right: 0; | ||
content: attr(tooltip-text); | ||
visibility: hidden; | ||
opacity: 0; | ||
max-width: 50vw; | ||
min-width: 24em; | ||
color: black; | ||
text-align: left; | ||
border: solid; | ||
border-color: black; | ||
border-width: 0.1em; | ||
border-radius: 0.4em; | ||
padding: 0.4em; | ||
transition: opacity 0.2s ease-in-out; | ||
} | ||
|
||
.tooltip:hover:before { | ||
opacity: 1; | ||
visibility: visible; | ||
} |
83 changes: 83 additions & 0 deletions
83
src/features/feeds/components/pause-notice/PauseNotice.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,83 @@ | ||
/** @jsxImportSource preact */ | ||
import styles from "./PauseNotice.module.css" | ||
import dangerIcon from "../../../../components/Alert/Assets/danger-icon.svg" | ||
import alertIcon from "../../../../components/Alert/Assets/alert-icon.svg" | ||
import { useEffect, useState } from "preact/hooks" | ||
|
||
// SVG icon paths | ||
const icons = { | ||
alert: alertIcon, | ||
danger: dangerIcon, | ||
} | ||
|
||
export const PauseNotice = ({ | ||
list, | ||
type = "alert", | ||
feedName, | ||
feedAddress, | ||
value, | ||
heartbeat, | ||
buffer, | ||
currencyName, | ||
}: { | ||
value: number | ||
list?: boolean | ||
type: "alert" | "danger" | ||
feedName: string | ||
feedAddress: string | ||
heartbeat: number | ||
buffer: number | ||
currencyName: string | ||
}) => { | ||
const [ripCord, setRipCord] = useState<boolean>(false) | ||
const date = Math.floor(new Date().getTime() / 1000) | ||
const timeSinceUpdate = date - value | ||
const threshold = heartbeat + buffer | ||
|
||
useEffect(() => { | ||
const fetchRipCord = async () => { | ||
const res = await fetch( | ||
`https://api.real-time-reserves.ledgerlens.io/v1/chainlink/proof-of-reserves/${currencyName}`, | ||
{ | ||
method: "GET", | ||
} | ||
) | ||
const fecthedProofOfReserveData = await res.json() | ||
setRipCord(fecthedProofOfReserveData.ripCord ?? false) | ||
} | ||
fetchRipCord().catch((error) => { | ||
console.error(error) | ||
}) | ||
}, [ripCord]) | ||
// TODO: Add dynamic scanner URL paths from chain data. | ||
if (timeSinceUpdate > threshold && ripCord) { | ||
if (!list) { | ||
return ( | ||
<> | ||
<div class={styles.banner + " " + styles[type]}> | ||
<img class={styles.icon} src={icons[type]}></img> | ||
<p class={styles.notice}> | ||
The <a href={`https://etherscan.io/address/${feedAddress}`}>{feedName} feed</a> is paused due to lack of | ||
attestation data. Read the <a href="/data-feeds/proof-of-reserve">Proof of Reserves</a> page to learn more | ||
about data attestation types. | ||
</p> | ||
</div> | ||
</> | ||
) | ||
} else { | ||
return ( | ||
<> | ||
<span | ||
class={styles.banner + " " + styles.tooltip + " " + styles[type]} | ||
tooltip-text="This feed is paused due to lack of attestation data." | ||
> | ||
<img class={styles.iconSmall} src={icons[type]}></img> | ||
<p class={styles.notice}>Paused</p> | ||
</span> | ||
</> | ||
) | ||
} | ||
} else { | ||
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
f6cc730
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
documentation – ./
documentation-woad-five.vercel.app
documentation-chainlinklabs.vercel.app
documentation-git-main-chainlinklabs.vercel.app
docs.chain.link