diff --git a/web/e.cash/components/navbar/getNavbarData.js b/web/e.cash/components/navbar/getNavbarData.js --- a/web/e.cash/components/navbar/getNavbarData.js +++ b/web/e.cash/components/navbar/getNavbarData.js @@ -7,6 +7,7 @@ export const ApiDataProvider = ({ children }) => { const [priceLinkText, setPriceLinkText] = useState('Buy XEC'); + const [blockHeight, setBlockHeight] = useState(0); const getPrice = () => { const api = @@ -19,12 +20,21 @@ .catch(err => console.log(err)); }; + const getBlockHeight = () => { + const api = 'https://api.blockchair.com/ecash/stats'; + fetch(api) + .then(response => response.json()) + .then(data => setBlockHeight(data.data.best_block_height)) + .catch(err => console.log(err)); + }; + useEffect(() => { getPrice(); + getBlockHeight(); }, []); return ( - + {children} ); diff --git a/web/e.cash/components/navbar/index.js b/web/e.cash/components/navbar/index.js --- a/web/e.cash/components/navbar/index.js +++ b/web/e.cash/components/navbar/index.js @@ -17,7 +17,7 @@ const [windowHeight, setWindowHeight] = useState(0); const [navBackground, setNavBackground] = useState(false); const mobileBreakPoint = 920; - const { priceLinkText } = useApiData(); + const { priceLinkText, blockHeight } = useApiData(); const handleResize = () => { setWindowWidth(window.innerWidth); @@ -50,8 +50,27 @@ } }, [windowHeight]); + const blocksBeforeHalving = 840000 - blockHeight; + return ( + {blocksBeforeHalving > 0 && ( + + + {blockHeight > 0 ? ( + + eCash halving in {blocksBeforeHalving} block + {blocksBeforeHalving > 1 ? 's' : ''}! + + ) : ( + eCash halving is imminent! + )} + + + )} Prepare for the eCash network upgrade! @@ -65,7 +84,7 @@ )} {!process.env.NEXT_PUBLIC_WEGLOT_API_KEY && ( - + Translations are disabled, set the env NEXT_PUBLIC_WEGLOT_API_KEY to fix