Skip to content

Commit ec26ac4

Browse files
committed
more info
1 parent cc1e972 commit ec26ac4

File tree

3 files changed

+83
-11
lines changed

3 files changed

+83
-11
lines changed

src/components/TxNotificationCenter.tsx

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,31 @@ function PhaseTimelineBar({ phases }: { phases: PhaseTiming[] }) {
127127
<Typography variant="body2">
128128
{formatDurationLong(phase.duration)} ({percentage.toFixed(1)}%)
129129
</Typography>
130-
{phase.breakdown?.map((item, idx) => (
131-
<Typography key={idx} variant="caption" sx={{ display: 'block', pl: 1 }}>
132-
{item.label}: {formatDuration(item.duration)}
130+
{phase.breakdown?.map((item, idx) => {
131+
const isChild = item.label.startsWith(' ');
132+
return (
133+
<Typography
134+
key={idx}
135+
variant="caption"
136+
sx={{
137+
display: 'block',
138+
pl: isChild ? 2.5 : 1,
139+
fontWeight: isChild ? 400 : 600,
140+
fontSize: isChild ? '0.65rem' : '0.7rem',
141+
color: isChild ? 'text.secondary' : 'text.primary',
142+
}}
143+
>
144+
{item.label.trimStart()}: {formatDuration(item.duration)}
145+
</Typography>
146+
);
147+
})}
148+
{phase.details?.map((line, idx) => (
149+
<Typography
150+
key={`d-${idx}`}
151+
variant="caption"
152+
sx={{ display: 'block', pl: line.startsWith(' ') ? 2 : 0, mt: idx === 0 ? 0.5 : 0, fontFamily: 'monospace', fontSize: '0.65rem' }}
153+
>
154+
{line}
133155
</Typography>
134156
))}
135157
</Box>
@@ -177,21 +199,29 @@ interface TxToastProps {
177199
}
178200

179201
function TxToast({ event, onDismiss }: TxToastProps) {
180-
const [elapsed, setElapsed] = useState(Date.now() - event.startTime);
181-
const [expanded, setExpanded] = useState(true);
182-
const frozenElapsed = useRef<number | null>(null);
183202
const isActive = event.phase !== 'complete' && event.phase !== 'error';
184203

204+
// For completed events, compute total from recorded phase timings (stable across refreshes)
205+
const computeFinalElapsed = () => {
206+
const t = event.phaseTimings;
207+
const fromTimings = (t.simulation ?? 0) + (t.proving ?? 0) + (t.sending ?? 0) + (t.mining ?? 0);
208+
return fromTimings > 0 ? fromTimings : Date.now() - event.startTime;
209+
};
210+
211+
const [elapsed, setElapsed] = useState(() => isActive ? Date.now() - event.startTime : computeFinalElapsed());
212+
const [expanded, setExpanded] = useState(true);
213+
const frozen = useRef(!isActive);
214+
185215
// Tick elapsed time while active, freeze when done
186216
useEffect(() => {
187217
if (!isActive) {
188-
if (frozenElapsed.current === null) {
189-
frozenElapsed.current = Date.now() - event.startTime;
190-
setElapsed(frozenElapsed.current);
218+
if (!frozen.current) {
219+
frozen.current = true;
220+
setElapsed(computeFinalElapsed());
191221
}
192222
return;
193223
}
194-
frozenElapsed.current = null;
224+
frozen.current = false;
195225
const interval = setInterval(() => setElapsed(Date.now() - event.startTime), 200);
196226
return () => clearInterval(interval);
197227
}, [isActive, event.startTime]);

src/embedded_wallet.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,47 @@ export class EmbeddedWallet extends BaseWallet {
353353

354354
const simulationDuration = Date.now() - simulationStart;
355355
phaseTimings.simulation = simulationDuration;
356-
phases.push({ name: 'Simulation', duration: simulationDuration, color: '#ce93d8' });
356+
357+
// Build breakdown and details from simulation stats
358+
const simStats = simulationResult.stats;
359+
const breakdown: Array<{ label: string; duration: number }> = [];
360+
const details: string[] = [];
361+
362+
if (simStats?.timings) {
363+
const t = simStats.timings;
364+
if (t.sync > 0) breakdown.push({ label: 'Sync', duration: t.sync });
365+
if (t.perFunction.length > 0) {
366+
const witgenTotal = t.perFunction.reduce((sum, fn) => sum + fn.time, 0);
367+
breakdown.push({ label: 'Private execution', duration: witgenTotal });
368+
for (const fn of t.perFunction) {
369+
breakdown.push({ label: ` ${fn.functionName.split(':').pop() || fn.functionName}`, duration: fn.time });
370+
}
371+
}
372+
if (t.publicSimulation) breakdown.push({ label: 'Public simulation', duration: t.publicSimulation });
373+
if (t.unaccounted > 0) breakdown.push({ label: 'Other', duration: t.unaccounted });
374+
}
375+
376+
if (simStats?.nodeRPCCalls?.roundTrips) {
377+
const rt = simStats.nodeRPCCalls.roundTrips;
378+
const fmt = (ms: number) => (ms < 1000 ? `${Math.round(ms)}ms` : `${(ms / 1000).toFixed(1)}s`);
379+
details.push(`${rt.roundTrips} RPC round-trips (${fmt(rt.totalBlockingTime)} blocking)`);
380+
const MAX_METHODS_SHOWN = 3;
381+
for (let i = 0; i < rt.roundTripDurations.length; i++) {
382+
const allMethods = rt.roundTripMethods[i] ?? [];
383+
const count = allMethods.length;
384+
const shown = allMethods.slice(0, MAX_METHODS_SHOWN).join(', ');
385+
const suffix = count > MAX_METHODS_SHOWN ? `, ... +${count - MAX_METHODS_SHOWN} more` : '';
386+
details.push(` #${i + 1}: ${fmt(rt.roundTripDurations[i])}${shown}${suffix} (${count} calls)`);
387+
}
388+
}
389+
390+
phases.push({
391+
name: 'Simulation',
392+
duration: simulationDuration,
393+
color: '#ce93d8',
394+
...(breakdown.length > 0 && { breakdown }),
395+
...(details.length > 0 && { details }),
396+
});
357397
}
358398

359399
// --- PROVING ---

src/tx-progress.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface PhaseTiming {
1212
duration: number;
1313
color: string;
1414
breakdown?: Array<{ label: string; duration: number }>;
15+
/** Extra detail lines shown in the tooltip (e.g. RPC round-trip info) */
16+
details?: string[];
1517
}
1618

1719
export interface TxProgressEvent {

0 commit comments

Comments
 (0)