|
1 | 1 | import { Button } from '@/components/ui/button' |
| 2 | +import { Badge } from '@/components/ui/badge' |
2 | 3 | import { useTheme } from '@/components/theme-provider' |
3 | 4 | import { openInNewTab } from '@/lib/utils' |
4 | 5 | import { Moon, Sun } from 'lucide-react' |
5 | 6 | import { FaGithub } from 'react-icons/fa' |
| 7 | +import { useEffect, useState } from 'react' |
| 8 | +import { polkadotClient } from './clients' |
6 | 9 |
|
7 | 10 | export const Footer = () => { |
8 | 11 | const { theme, setTheme } = useTheme() |
| 12 | + const [latestBlockNumber, setLatestBlockNumber] = useState<number | null>( |
| 13 | + null, |
| 14 | + ) |
9 | 15 |
|
10 | 16 | const toggleTheme = () => setTheme(theme === 'light' ? 'dark' : 'light') |
11 | 17 |
|
| 18 | + useEffect(() => { |
| 19 | + const subscription = polkadotClient.finalizedBlock$.subscribe( |
| 20 | + (finalizedBlock) => { |
| 21 | + if (typeof finalizedBlock.number === 'number') { |
| 22 | + setLatestBlockNumber(finalizedBlock.number) |
| 23 | + } |
| 24 | + }, |
| 25 | + ) |
| 26 | + |
| 27 | + return () => subscription.unsubscribe() |
| 28 | + }, []) |
| 29 | + |
12 | 30 | return ( |
13 | 31 | <footer className="bg-background/80 w-fill supports-backdrop-filter:bg-background/60 fixed bottom-0 border-t backdrop-blur"> |
14 | | - <div className="text-muted-foreground flex flex-col justify-between gap-4 px-4 py-6 text-sm sm:flex-row sm:items-center sm:px-6"> |
| 32 | + <div className="text-muted-foreground mx-auto flex w-full max-w-7xl flex-col items-center justify-between gap-4 px-4 py-6 text-sm sm:flex-row sm:items-center sm:px-6"> |
15 | 33 | <div className="text-center sm:text-left"> |
16 | 34 | <p className="text-foreground text-base font-semibold"> |
17 | 35 | Polkadot Technical Fellowship |
@@ -41,6 +59,11 @@ export const Footer = () => { |
41 | 59 | <Moon className="h-[1.1rem] w-[1.1rem] scale-100 rotate-0 transition-all dark:scale-0 dark:-rotate-90" /> |
42 | 60 | <span className="sr-only">Toggle theme</span> |
43 | 61 | </Button> |
| 62 | + <Badge variant="secondary" className="p-3 text-nowrap"> |
| 63 | + {latestBlockNumber |
| 64 | + ? `#${latestBlockNumber.toLocaleString()}` |
| 65 | + : 'Syncing block...'} |
| 66 | + </Badge> |
44 | 67 | </div> |
45 | 68 | </div> |
46 | 69 | </footer> |
|
0 commit comments