Skip to content
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: 2 additions & 2 deletions frontend/src/context/BrandingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function readCache(): BrandingConfig | null {

function applyConfigState(cfg: BrandingConfig, setBranding: (v: typeof brandingDefaults) => void, setConfig: (v: BrandingConfig) => void) {
setConfig(cfg);
setBranding({ chainName: cfg.chain_name, logoUrl: cfg.logo_url || null, loaded: true });
setBranding({ chainName: cfg.chain_name, logoUrl: cfg.logo_url || null, accentHex: cfg.accent_color || null, loaded: true });
document.title = `${cfg.chain_name} - Block Explorer`;
if (cfg.logo_url) {
const link = document.querySelector<HTMLLinkElement>("link[rel='icon']");
Expand All @@ -29,7 +29,7 @@ export function BrandingProvider({ children }: { children: ReactNode }) {
const [branding, setBranding] = useState(() => {
const cached = readCache();
return cached
? { chainName: cached.chain_name, logoUrl: cached.logo_url || null, loaded: true }
? { chainName: cached.chain_name, logoUrl: cached.logo_url || null, accentHex: cached.accent_color || null, loaded: true }
: brandingDefaults;
});
const [config, setConfig] = useState<BrandingConfig | null>(readCache);
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/context/branding-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { createContext } from 'react';
export interface BrandingContextValue {
chainName: string;
logoUrl: string | null;
accentHex: string | null;
loaded: boolean;
}

export const brandingDefaults: BrandingContextValue = {
chainName: 'Unknown',
logoUrl: null,
accentHex: null,
loaded: false,
};

Expand Down
24 changes: 24 additions & 0 deletions frontend/src/hooks/useChartColors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useContext, useMemo } from 'react';
import { BrandingContext } from '../context/branding-context';
import { ThemeContext } from '../context/theme-context';

const DEFAULT_ACCENT = '#dc2626';

function cssVar(name: string): string {
return `rgb(${getComputedStyle(document.documentElement).getPropertyValue(name).trim()})`;
}

export function useChartColors() {
const { accentHex } = useContext(BrandingContext);
const themeCtx = useContext(ThemeContext);
const theme = themeCtx?.theme ?? 'dark';

return useMemo(() => ({
accent: accentHex ?? DEFAULT_ACCENT,
grid: cssVar('--color-surface-600'),
axisText: cssVar('--color-text-subtle'),
tooltipBg: cssVar('--color-surface-800'),
tooltipText: cssVar('--color-text-primary'),
// eslint-disable-next-line react-hooks/exhaustive-deps
}), [accentHex, theme]);
}
17 changes: 7 additions & 10 deletions frontend/src/pages/StatusPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ import { formatNumber } from '../utils';
import Loading from '../components/Loading';
import { BlockStatsContext } from '../context/BlockStatsContext';
import { useChartData } from '../hooks/useChartData';

// ─── theme constants for recharts (matches CSS vars) ──────────────────────────
const CHART_ACCENT = '#dc2626';
const CHART_GRID = '#22222e';
const CHART_AXIS_TEXT = '#94a3b8';
const CHART_TOOLTIP_BG = '#0c0c10';
import { useChartColors } from '../hooks/useChartColors';

const WINDOWS: { label: string; value: ChartWindow }[] = [
{ label: '1H', value: '1h' },
Expand All @@ -45,6 +40,8 @@ export default function StatusPage() {
dailyTxsError, blocksChartError, gasPriceError,
} = useChartData(window);

const { accent: CHART_ACCENT, grid: CHART_GRID, axisText: CHART_AXIS_TEXT, tooltipBg: CHART_TOOLTIP_BG, tooltipText: CHART_TOOLTIP_TEXT } = useChartColors();

useEffect(() => {
let mounted = true;
const fetchStatus = async () => {
Expand Down Expand Up @@ -137,7 +134,7 @@ export default function StatusPage() {
<Tooltip
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
itemStyle={{ color: CHART_TOOLTIP_TEXT }}
formatter={(v: unknown) => [formatCompact(v as number), 'Transactions']}
/>
<Bar dataKey="tx_count" fill={CHART_ACCENT} radius={[2, 2, 0, 0]} isAnimationActive={false} />
Expand Down Expand Up @@ -170,7 +167,7 @@ export default function StatusPage() {
<Tooltip
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
itemStyle={{ color: CHART_TOOLTIP_TEXT }}
formatter={(v: unknown) => [formatCompact(v as number), 'Avg Gas Used']}
labelFormatter={(v) => formatBucketTooltip(v, window)}
/>
Expand Down Expand Up @@ -206,7 +203,7 @@ export default function StatusPage() {
<Tooltip
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
itemStyle={{ color: CHART_TOOLTIP_TEXT }}
formatter={(v: unknown) => [formatCompact(v as number), 'Transactions']}
labelFormatter={(v) => formatBucketTooltip(v, window)}
/>
Expand Down Expand Up @@ -234,7 +231,7 @@ export default function StatusPage() {
<Tooltip
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
itemStyle={{ color: CHART_TOOLTIP_TEXT }}
formatter={(v: unknown) => [formatGwei(v as number), 'Avg Gas Price']}
labelFormatter={(v) => formatBucketTooltip(v, window)}
/>
Expand Down
11 changes: 4 additions & 7 deletions frontend/src/pages/TokenDetailPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ import {
} from 'recharts';
import { useToken, useTokenHolders, useTokenTransfers } from '../hooks';
import { useTokenChart } from '../hooks/useTokenChart';
import { useChartColors } from '../hooks/useChartColors';
import { Pagination, AddressLink, TxHashLink, CopyButton } from '../components';
import Loading from '../components/Loading';
import { formatNumber, formatTokenAmount, formatPercentage, formatTimeAgo, truncateHash } from '../utils';
import { type ChartWindow } from '../api/chartData';

const CHART_ACCENT = '#dc2626';
const CHART_GRID = '#22222e';
const CHART_AXIS_TEXT = '#94a3b8';
const CHART_TOOLTIP_BG = '#0c0c10';

const WINDOWS: { label: string; value: ChartWindow }[] = [
{ label: '1H', value: '1h' },
{ label: '6H', value: '6h' },
Expand Down Expand Up @@ -101,6 +97,7 @@ export default function TokenDetailPage() {
const { holders, pagination: holdersPagination } = useTokenHolders(address, { page: holdersPage, limit: 20 });
const { transfers, pagination: transfersPagination } = useTokenTransfers(address, { page: transfersPage, limit: 20 });
const { data: chartData, loading: chartLoading } = useTokenChart(address, chartWindow);
const { accent: CHART_ACCENT, grid: CHART_GRID, axisText: CHART_AXIS_TEXT, tooltipBg: CHART_TOOLTIP_BG, tooltipText: CHART_TOOLTIP_TEXT } = useChartColors();

const tabs: { id: TabType; label: string; count?: number }[] = [
{ id: 'holders', label: 'Holders', count: holdersPagination?.total },
Expand Down Expand Up @@ -195,7 +192,7 @@ export default function TokenDetailPage() {
<Tooltip
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
itemStyle={{ color: CHART_TOOLTIP_TEXT }}
formatter={(v: unknown) => [formatCompact(v as number), 'Transfers']}
labelFormatter={(v) => formatBucketTooltip(v, chartWindow)}
/>
Expand Down Expand Up @@ -224,7 +221,7 @@ export default function TokenDetailPage() {
<Tooltip
contentStyle={{ background: CHART_TOOLTIP_BG, border: `1px solid ${CHART_GRID}`, borderRadius: 8 }}
labelStyle={{ color: CHART_AXIS_TEXT }}
itemStyle={{ color: '#f8fafc' }}
itemStyle={{ color: CHART_TOOLTIP_TEXT }}
formatter={(v: unknown) => [formatCompact(v as number), `Volume (${token?.symbol || 'tokens'})`]}
labelFormatter={(v) => formatBucketTooltip(v, chartWindow)}
/>
Expand Down
Loading