Skip to content

Add real-time MEV refund metrics to navbar #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ module.exports = async function createConfigAsync() {
sidebarId: 'api',
position: 'left',
},
{
type: 'custom-mevMetrics',
position: 'right',
},
{
href: 'https://github.com/flashbots/docs',
label: 'GitHub',
Expand Down
39 changes: 39 additions & 0 deletions src/components/MevMetrics.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.container {
display: flex;
align-items: center;
gap: 0.75rem;
font-size: 0.875rem;
color: var(--ifm-navbar-link-color);
margin-right: 0.75rem;
}

.metric {
display: flex;
align-items: center;
gap: 0.25rem;
}

.label {
font-weight: 400;
}

.value {
font-family: monospace;
font-weight: 600;
transition: opacity 0.3s ease;
}

.loading {
opacity: 0.5;
}

.separator {
color: var(--ifm-navbar-link-color);
opacity: 0.3;
}

@media (max-width: 996px) {
.container {
display: none !important;
}
}
64 changes: 64 additions & 0 deletions src/components/MevMetrics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { useEffect, useState } from 'react';
import styles from './MevMetrics.module.css';

interface MetricsResponse {
totalMevRefund: number;
totalGasRefund: number;
fetchedAt: string;
stale: boolean;
}

export default function MevMetrics(): JSX.Element {
const [data, setData] = useState<MetricsResponse | null>(null);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchMetrics = async () => {
try {
const response = await fetch('https://refund-metrics-dune-api.vercel.app/api/metrics');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const metrics: MetricsResponse = await response.json();
setData(metrics);
} catch (error) {
console.error('Error fetching MEV metrics:', error);
// Mock data as fallback
setData({
totalMevRefund: 380.29,
totalGasRefund: 444.24,
fetchedAt: new Date().toISOString(),
stale: true
});
} finally {
setLoading(false);
}
};

fetchMetrics();
}, []);

const formatValue = (value: number): string => {
return `${value.toFixed(2)} ETH`;
};

return (
<div className={styles.container}>
<span className={styles.label}>Refund</span>
<span className={styles.separator}>|</span>
<div className={styles.metric}>
<span className={styles.label}>MEV:</span>
<span className={`${styles.value} ${loading ? styles.loading : ''}`}>
{loading ? '...' : data && formatValue(data.totalMevRefund)}
</span>
</div>
<span className={styles.separator}>|</span>
<div className={styles.metric}>
<span className={styles.label}>Gas:</span>
<span className={`${styles.value} ${loading ? styles.loading : ''}`}>
{loading ? '...' : data && formatValue(data.totalGasRefund)}
</span>
</div>
</div>
);
}
27 changes: 27 additions & 0 deletions src/theme/NavbarItem/ComponentTypes.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
import HtmlNavbarItem from '@theme/NavbarItem/HtmlNavbarItem';
import DocNavbarItem from '@theme/NavbarItem/DocNavbarItem';
import DocSidebarNavbarItem from '@theme/NavbarItem/DocSidebarNavbarItem';
import DocsVersionNavbarItem from '@theme/NavbarItem/DocsVersionNavbarItem';
import DocsVersionDropdownNavbarItem from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
import MevMetrics from '@site/src/components/MevMetrics';

import type {ComponentTypesObject} from '@theme/NavbarItem/ComponentTypes';

const ComponentTypes: ComponentTypesObject = {
default: DefaultNavbarItem,
localeDropdown: LocaleDropdownNavbarItem,
search: SearchNavbarItem,
dropdown: DropdownNavbarItem,
html: HtmlNavbarItem,
doc: DocNavbarItem,
docSidebar: DocSidebarNavbarItem,
docsVersion: DocsVersionNavbarItem,
docsVersionDropdown: DocsVersionDropdownNavbarItem,
'custom-mevMetrics': MevMetrics,
};

export default ComponentTypes;