import { useEffect, useState } from 'react' import sumBy from 'lodash/sumBy' import { Connection } from '@solana/web3.js' import mangoStore, { CLUSTER } from '@store/mangoStore' import useInterval from './shared/useInterval' import { formatNumericValue } from 'utils/numbers' import Tooltip from './shared/Tooltip' import { useTranslation } from 'react-i18next' const tpsAlertThreshold = 1000 const tpsWarningThreshold = 1300 const getRecentPerformance = async ( connection: Connection, setTps: (x: number) => void, ) => { try { const samples = 2 const response = await connection.getRecentPerformanceSamples(samples) const totalSecs = sumBy(response, 'samplePeriodSecs') const totalTransactions = sumBy(response, 'numTransactions') const tps = totalTransactions / totalSecs setTps(tps) } catch { console.warn('Unable to fetch TPS') } } const Tps = () => { const { t } = useTranslation('common') const connection = mangoStore((s) => s.connection) const [tps, setTps] = useState(0) useEffect(() => { getRecentPerformance(connection, setTps) }, []) useInterval(() => { getRecentPerformance(connection, setTps) }, 60 * 1000) if (CLUSTER == 'mainnet-beta') { return (