mango-v4-ui/components/StatusBar.tsx

115 lines
3.6 KiB
TypeScript
Raw Normal View History

2023-08-06 22:57:02 -07:00
import { useTranslation } from 'react-i18next'
import Tps from './Tps'
import DiscordIcon from './icons/DiscordIcon'
import { TwitterIcon } from './icons/TwitterIcon'
import { DocumentTextIcon } from '@heroicons/react/20/solid'
import { useEffect, useState } from 'react'
2023-08-07 04:07:34 -07:00
import { IDL } from '@blockworks-foundation/mango-v4'
2023-08-09 05:33:42 -07:00
import RpcPing from './RpcPing'
import Tooltip from './shared/Tooltip'
2023-08-06 22:57:02 -07:00
const DEFAULT_LATEST_COMMIT = { sha: '', url: '' }
const getLatestCommit = async () => {
try {
const response = await fetch(
2023-08-07 04:07:34 -07:00
`https://api.github.com/repos/blockworks-foundation/mango-v4-ui/commits`,
2023-08-06 22:57:02 -07:00
)
const data = await response.json()
if (data && data.length) {
const { sha, html_url } = data[0]
return {
sha: sha.slice(0, 7),
url: html_url,
}
}
return DEFAULT_LATEST_COMMIT
} catch (error) {
console.error('Error fetching latest commit:', error)
return DEFAULT_LATEST_COMMIT
}
}
2023-08-08 22:24:09 -07:00
const StatusBar = ({ collapsed }: { collapsed: boolean }) => {
2023-08-06 22:57:02 -07:00
const { t } = useTranslation('common')
const [latestCommit, setLatestCommit] = useState(DEFAULT_LATEST_COMMIT)
useEffect(() => {
const { sha } = latestCommit
if (!sha) {
getLatestCommit().then((commit) => setLatestCommit(commit))
}
}, [latestCommit])
return (
2023-08-08 22:24:09 -07:00
<div
className={`hidden fixed ${
collapsed ? 'w-[calc(100vw-64px)]' : 'w-[calc(100vw-200px)]'
2023-08-08 22:37:08 -07:00
} bottom-0 bg-th-input-bkg md:grid md:grid-cols-3 px-4 md:px-6 py-1`}
2023-08-08 22:24:09 -07:00
>
2023-08-09 05:33:42 -07:00
<div className="col-span-1 flex items-center space-x-2">
2023-08-06 22:57:02 -07:00
<Tps />
2023-08-09 05:33:42 -07:00
<span className="text-th-fgd-4">|</span>
<RpcPing />
2023-08-06 22:57:02 -07:00
</div>
2023-08-09 05:33:42 -07:00
<div className="col-span-1 flex items-center justify-center">
<Tooltip content={t('program-version')}>
2023-08-09 22:41:11 -07:00
<a
className="text-th-fgd-3 text-xs focus:outline-none md:hover:text-th-fgd-2"
href={`https://github.com/blockworks-foundation/mango-v4/releases`}
rel="noreferrer noopener"
target="_blank"
>
<span>v{IDL.version}</span>
2023-08-09 22:41:11 -07:00
</a>
2023-08-09 05:33:42 -07:00
</Tooltip>
2023-08-06 22:57:02 -07:00
{latestCommit.sha && latestCommit.url ? (
2023-08-09 05:33:42 -07:00
<Tooltip content={t('latest-ui-commit')}>
2023-08-07 04:07:34 -07:00
<span className="mx-1.5 text-th-fgd-4">|</span>
<a
className="text-th-fgd-3 text-xs focus:outline-none md:hover:text-th-fgd-2"
href={latestCommit.url}
rel="noreferrer noopener"
target="_blank"
>
{latestCommit.sha}
</a>
2023-08-09 05:33:42 -07:00
</Tooltip>
2023-08-06 22:57:02 -07:00
) : null}
</div>
<div className="col-span-1 flex items-center justify-end space-x-4 text-xs">
<a
className="text-th-fgd-3 focus:outline-none flex items-center md:hover:text-th-fgd-2"
href="https://docs.mango.markets"
rel="noreferrer noopener"
target="_blank"
>
<DocumentTextIcon className="h-3 w-3 mr-1" />
<span>{t('docs')}</span>
</a>
<a
className="text-th-fgd-3 focus:outline-none flex items-center md:hover:text-th-fgd-2"
href="https://discord.gg/2uwjsBc5yw"
rel="noreferrer noopener"
target="_blank"
>
<DiscordIcon className="h-3 w-3 mr-1" />
<span>{t('discord')}</span>
</a>
<a
className="text-th-fgd-3 focus:outline-none flex items-center md:hover:text-th-fgd-2"
href="https://twitter.com/mangomarkets"
rel="noreferrer noopener"
target="_blank"
>
<TwitterIcon className="h-3 w-3 mr-1" />
<span>{t('twitter')}</span>
</a>
</div>
</div>
)
}
export default StatusBar