// The right ("Logs") column of the inspector's Programs & Logs row: the Simulation control sits above // its own results (Logs, then CU profiling), so the simulation lives TOGETHER with the logs it produces // — mirroring the transaction details page's ProgramLogSection + CUProfilingSection sticky panel. Each // block keeps its own anchor id (`simulation` / `logs` / `cu-profiling`) for tab navigation. Simulation // state is owned by the page (LoadedView) and passed in, so this panel and the Account List's "Change" // column react to the same run. import { CollapsibleSection } from '@components/shared/ui/collapsible-section'; import { cn } from '@components/shared/utils'; import { useCluster } from '@providers/cluster'; import type { VersionedMessage } from '@solana/web3.js'; import React from 'react'; import { ProgramLogsCardBody } from '@/app/components/ProgramLogsCardBody'; import { Badge } from '@/app/components/shared/ui/badge'; import { type SimulationState } from '@/app/features/instruction-simulation/model/use-simulation'; import { useSimulationInstructionNames } from '@/app/features/instruction-simulation/model/use-simulation-instruction-names'; import { BaseSimulatorCUProfilingCard } from '@/app/features/instruction-simulation/ui/BaseSimulatorCUProfilingCard'; import { LastSimulatedAt } from '@/app/features/instruction-simulation/ui/LastSimulatedAt'; import { SIM_ZONE_STYLE } from '@/app/features/instruction-simulation/ui/sim-zone-style'; import { SimulateButton } from '@/app/features/instruction-simulation/ui/SimulateButton'; function SimulatedTitle({ children }: { children: React.ReactNode }) { return ( {children} Simulated ); } const OUTLINE_ONLY_CARD = 'rounded-lg border border-solid border-outer-space-800'; // Empty state for a Logs / CU profiling card before a simulation has run: the card exists so its tab has // a scroll target. The Simulate button is revealed on hover/focus of the enclosing card (the `group`). function SimEmptyHint({ children, simulation }: { children: React.ReactNode; simulation: SimulationState }) { return (
{children}
); } export function InspectorSimulationPanel({ simulation, message, }: { simulation: SimulationState; message: VersionedMessage; }) { const { cluster, url } = useCluster(); const result = simulation.status === 'done' ? simulation.result : undefined; const logs = result?.logs; const hasLogs = !!logs?.length; // Lookup-table-resolved keys only exist once the simulation has run, so naming waits for them. const { instructions: namedInstructions, unresolvable } = useSimulationInstructionNames({ accountKeys: result?.accountKeys, message, }); return (
{/* Simulation — the heading sits OUTSIDE the card; the guidance + Simulate button live INSIDE a card carrying the green noise backing (SIM_ZONE_STYLE) and outer-space border. `overflow-hidden` keeps the tiled noise and the full-bleed failure band within the rounded corners. */}

Simulation

{/* Guidance stays between the heading and the button at all times — it is not cleared once a simulation has run. */}

Simulation is free and will run this transaction against the latest confirmed ledger state.

No state changes will be persisted and all signature checks will be disabled.

{simulation.status === 'error' && ( // Full-bleed to the card edges (negative margins cancel the card padding, incl. the // bottom so it reaches the rounded corner). A top border draws the full-width divider; // below it sits the failure text.
Simulation Failure: {simulation.error}
)}
{/* Logs and CU profiling are always present so their tabs have a scroll target; before a simulation runs they show an empty-state prompt instead of results. The "Simulated" badge is only added once real content is in the card. */}
Logs : 'Logs'} className={cn(OUTLINE_ONLY_CARD, !hasLogs && 'group')} > {hasLogs ? ( ) : ( Run the simulation to view the program logs. )}
{result && logs ? ( CU profiling} className={OUTLINE_ONLY_CARD} > {unresolvable ? ( // Logs exist, so this owes the user a card. Every CU figure would land on the wrong // instruction, so saying why beats drawing it.
Unavailable: an instruction referenced an account this message does not resolve.
) : ( )}
) : ( Run the simulation to view CU profiling. )}
); }