- Los enlaces ↗ ya no se montan sobre el sitio del dashboard (:4083): se derivan al 4081/4080 del mismo nodo, o a la «Web de Mempool» de Ajustes. - Botón de copiar en los txids y direcciones abreviados de Auditoría, Red, Explorar, rastro y peritaje. - tests/test25.js. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01L5npnUYgSPkAaHkdaeUqBr
262 lines
17 KiB
React
262 lines
17 KiB
React
// ── Vista de la cadena: mempool y bloques en una sola línea ─────────
|
||
// Antes esto eran dos pestañas, y era el mismo eje partido por la mitad:
|
||
// "bloques proyectados" (los que se van a minar) vivían en Mempool, y los
|
||
// confirmados en Bloques. Es una línea temporal con el ahora en el corte,
|
||
// así que se cuenta como una sola historia: lo que viene, el momento
|
||
// actual, y lo que ya pasó.
|
||
function RedView({base}) {
|
||
const {get}=useApi(base);
|
||
const isMobile=useIsMobile();
|
||
const [blocks,setBlocks]=useState([]);
|
||
const [selected,setSelected]=useState(null);
|
||
const [blockTxs,setBlockTxs]=useState(null);
|
||
const [mempool,setMempool]=useState(null);
|
||
const [fees,setFees]=useState(null);
|
||
const [proyectados,setProyectados]=useState(null);
|
||
const [feeHistory,setFeeHistory]=useState(null);
|
||
const [tarifa,setTarifa]=useState("");
|
||
const [loading,setLoading]=useState(true);
|
||
|
||
useEffect(()=>{
|
||
setLoading(true);
|
||
Promise.all([
|
||
get("/api/v1/blocks",MOCK_BLOCKS),
|
||
get("/api/mempool",MOCK_MEMPOOL),
|
||
get("/api/v1/fees/recommended",MOCK_FEES),
|
||
get("/api/v1/fees/mempool-blocks",MOCK_MEMPOOLBLOCKS),
|
||
]).then(([b,m,f,p])=>{ setBlocks(b||[]); setMempool(m); setFees(f); setProyectados(p); setLoading(false); });
|
||
get("/api/v1/mining/blocks/fee-rates/1w", MOCK_FEE_HISTORY).then(d=>setFeeHistory(d));
|
||
},[base]);
|
||
|
||
const selectBlock=async(b)=>{ setSelected(b); setBlockTxs(null); const txs=await get(`/api/block/${b.id}/txs/0`,[MOCK_TX]); setBlockTxs(Array.isArray(txs)?txs:[txs]); };
|
||
|
||
// El detalle se dibuja al final de la lista, así que al pinchar en un
|
||
// bloque de arriba se abría a quince filas de distancia y parecía que el
|
||
// clic no hacía nada. Se lleva la vista hasta él.
|
||
const detalleRef = useRef(null);
|
||
useEffect(()=>{
|
||
if (selected && detalleRef.current) {
|
||
detalleRef.current.scrollIntoView({ behavior:"smooth", block:"center" });
|
||
}
|
||
},[selected]);
|
||
|
||
// ¿En qué bloque entraría una transacción a esta tarifa? Es la pregunta
|
||
// que de verdad se hace quien mira las comisiones, y ni la vista de
|
||
// mempool ni la de bloques la respondían: daban los datos por separado
|
||
// y dejaban el cálculo al ojo.
|
||
const tarifaNum = parseFloat(String(tarifa).replace(",", "."));
|
||
const estimacion = (() => {
|
||
if (!Number.isFinite(tarifaNum) || tarifaNum <= 0 || !proyectados || !proyectados.length) return null;
|
||
const idx = proyectados.findIndex(b => {
|
||
const r = b.feeRange || [];
|
||
return r.length ? tarifaNum >= Math.min(...r) : false;
|
||
});
|
||
if (idx === -1) {
|
||
const ultimo = proyectados[proyectados.length-1];
|
||
const minUlt = (ultimo.feeRange||[]).length ? Math.min(...ultimo.feeRange) : null;
|
||
return { fuera:true, minUlt, bloques:proyectados.length };
|
||
}
|
||
return { fuera:false, posicion: idx+1, minutos: (idx+1)*10 };
|
||
})();
|
||
|
||
const feeStats = feeHistory ? (() => {
|
||
const fs = feeHistory.map(d=>d.avgFee_50||d.avgFee||0).filter(v=>v>0);
|
||
if (!fs.length) return null;
|
||
return { min:Math.min(...fs), max:Math.max(...fs), avg:Math.round(fs.reduce((a,b)=>a+b,0)/fs.length) };
|
||
})() : null;
|
||
|
||
if(loading)return<Spinner/>;
|
||
|
||
return (
|
||
<div style={{display:"flex",flexDirection:"column",gap:12}}>
|
||
{!base&&<DemoBanner/>}
|
||
|
||
{/* Comisiones — el contexto para decidir */}
|
||
{fees&&(
|
||
<Card>
|
||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,textTransform:"uppercase",letterSpacing:"0.1em",marginBottom:12}}>Comisiones ahora (según la mempool)</div>
|
||
<div style={{display:"grid",gridTemplateColumns:`repeat(auto-fill,minmax(${isMobile?"105px":"130px"},1fr))`,gap:10}}>
|
||
{[{label:"Próx. bloque",val:`${fees.fastestFee} sat/vB`,color:C.red},{label:"30 min",val:`${fees.halfHourFee} sat/vB`,color:C.amber},{label:"1 hora",val:`${fees.hourFee} sat/vB`,color:C.green},{label:"Económico",val:`${fees.economyFee} sat/vB`,color:C.t2},{label:"Mínimo",val:`${fees.minimumFee} sat/vB`,color:C.t3}].map(f=>(
|
||
<div key={f.label} style={{padding:"10px 12px",background:C.bg,borderRadius:6,border:`1px solid ${C.border}`}}><div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,textTransform:"uppercase",letterSpacing:"0.1em",marginBottom:4}}>{f.label}</div><div style={{fontSize:"0.88rem",color:f.color,fontFamily:C.mono,fontWeight:700}}>{f.val}</div></div>
|
||
))}
|
||
</div>
|
||
{/* La pregunta real */}
|
||
<div style={{marginTop:14,paddingTop:12,borderTop:`1px solid ${C.border}`}}>
|
||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,marginBottom:8}}>Si pagas… ¿cuándo entra?</div>
|
||
<div style={{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"}}>
|
||
<input value={tarifa} onChange={e=>setTarifa(e.target.value)} type="number" min="0" step="0.1" placeholder="sat/vB"
|
||
style={{width:110,background:C.bg,border:`1px solid ${C.borderBright}`,borderRadius:6,padding:"8px 10px",color:C.t1,fontFamily:C.mono,fontSize:"0.72rem",outline:"none"}}/>
|
||
{estimacion&&(
|
||
<span style={{fontSize:"0.68rem",fontFamily:C.mono,color:estimacion.fuera?C.amber:C.green}}>
|
||
{estimacion.fuera
|
||
? `No entra en los próximos ${estimacion.bloques} bloques${estimacion.minUlt!=null?` — el último proyectado admite desde ${estimacion.minUlt} sat/vB`:""}. Tendría que esperar a que baje la demanda.`
|
||
: `Entraría en el bloque +${estimacion.posicion} — unos ${estimacion.minutos} minutos de media.`}
|
||
</span>
|
||
)}
|
||
</div>
|
||
<div style={{fontSize:"0.58rem",color:C.t3,fontFamily:C.mono,marginTop:6,lineHeight:1.5}}>
|
||
Estimación sobre la mempool de ahora mismo: si llegan transacciones con más comisión, tu sitio se retrasa. Y diez minutos es la media entre bloques, no una promesa.
|
||
</div>
|
||
</div>
|
||
</Card>
|
||
)}
|
||
|
||
{/* Línea temporal: lo que viene ─ ahora ─ lo que pasó */}
|
||
<SectionTitle accent={C.amber} icon="◉">Por minar — mempool</SectionTitle>
|
||
{mempool&&(
|
||
<div style={{display:"grid",gridTemplateColumns:`repeat(auto-fill,minmax(${isMobile?"110px":"140px"},1fr))`,gap:8}}>
|
||
{[{label:"Transacciones",val:fmt.num(mempool.count),color:C.amber},{label:"vSize total",val:fmt.mb(mempool.vsize),color:C.blue},{label:"Comisiones",val:fmt.sbtc(mempool.total_fee),color:C.green}].map(s=>(
|
||
<Card key={s.label} style={{padding:"12px 14px"}}><div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,textTransform:"uppercase",letterSpacing:"0.1em",marginBottom:5}}>{s.label}</div><div style={{fontSize:"0.95rem",color:s.color,fontFamily:C.mono,fontWeight:700}}>{s.val}</div></Card>
|
||
))}
|
||
</div>
|
||
)}
|
||
|
||
{proyectados&&proyectados.length>0&&(
|
||
<Card>
|
||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,textTransform:"uppercase",letterSpacing:"0.1em",marginBottom:12}}>Bloques proyectados</div>
|
||
{proyectados.slice(0,4).map((block,i)=>{
|
||
const feeRange = block.feeRange || [];
|
||
const maxFee = Math.round(Math.max(...feeRange, 1));
|
||
const minFee = Math.round(Math.min(...feeRange, 1));
|
||
const esElTuyo = estimacion && !estimacion.fuera && estimacion.posicion === i+1;
|
||
return (
|
||
<div key={i} style={{display:"flex",justifyContent:"space-between",alignItems:"center",flexWrap:"wrap",gap:6,padding:"8px 10px",marginBottom:4,borderRadius:6,background:esElTuyo?C.greenMuted:"transparent",border:`1px solid ${esElTuyo?C.green+"40":"transparent"}`}}>
|
||
<div>
|
||
<span style={{fontSize:"0.7rem",color:C.purple,fontFamily:C.mono,fontWeight:700}}>+{i+1} bloque{i>0?"s":""}</span>
|
||
<span style={{fontSize:"0.62rem",color:C.t2,marginLeft:8,fontFamily:C.mono}}>{fmt.num(block.nTx)} txs</span>
|
||
{esElTuyo&&<span style={{fontSize:"0.6rem",color:C.green,marginLeft:8,fontFamily:C.mono,fontWeight:700}}>← tu transacción</span>}
|
||
</div>
|
||
<div style={{display:"flex",gap:6,flexWrap:"wrap"}}><Badge color={C.amber}>{minFee}–{maxFee} sat/vB</Badge><Badge color={C.t3}>{fmt.mb(block.blockVSize)}</Badge></div>
|
||
</div>
|
||
);
|
||
})}
|
||
</Card>
|
||
)}
|
||
|
||
{/* El corte: aquí acaba lo que se espera y empieza lo que ya está */}
|
||
<div style={{display:"flex",alignItems:"center",gap:10,margin:"2px 0"}}>
|
||
<div style={{flex:1,height:1,background:`linear-gradient(to right,transparent,${C.green}60)`}}/>
|
||
<span style={{fontSize:"0.58rem",color:C.green,fontFamily:C.mono,letterSpacing:"0.2em",textTransform:"uppercase"}}>ahora</span>
|
||
<div style={{flex:1,height:1,background:`linear-gradient(to left,transparent,${C.green}60)`}}/>
|
||
</div>
|
||
|
||
<SectionTitle accent={C.purple} icon="◈">Ya minado — últimos bloques</SectionTitle>
|
||
{blocks.map((b,i)=>(
|
||
<div key={b.id||i} onClick={()=>selectBlock(b)} style={{display:"grid",gridTemplateColumns:"90px 1fr auto",alignItems:"center",gap:12,padding:"10px 14px",borderRadius:6,cursor:"pointer",background:selected&&selected.id===b.id?C.purpleMuted:C.bgCard,border:`1px solid ${selected&&selected.id===b.id?C.purple+"50":C.border}`}}
|
||
onMouseEnter={e=>e.currentTarget.style.background=C.bgHover} onMouseLeave={e=>e.currentTarget.style.background=selected&&selected.id===b.id?C.purpleMuted:C.bgCard}>
|
||
<div><div style={{fontSize:"0.88rem",fontFamily:C.mono,color:C.purple,fontWeight:700}}>#{fmt.num(b.height)}</div><div style={{fontSize:"0.62rem",color:C.t2,marginTop:2}}>{fmt.ago(b.timestamp)}</div></div>
|
||
<div><div style={{fontSize:"0.68rem",fontFamily:C.mono,color:C.t2,marginBottom:4}}>{fmt.hash(b.id)}</div><div style={{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"}}><Badge color={C.blue}>{fmt.num(b.tx_count)} txs</Badge><Badge color={C.t3}>{fmt.mb(b.size)}</Badge>{b.extras&&b.extras.pool&&<span style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono}}>{b.extras.pool.name}</span>}</div></div>
|
||
<div style={{textAlign:"right"}}>{b.extras&&b.extras.totalFees!=null&&<><div style={{fontSize:"0.7rem",color:C.amber,fontFamily:C.mono}}>{fmt.sbtc(b.extras.totalFees)}</div><div style={{fontSize:"0.58rem",color:C.t2}}>fees</div></>}</div>
|
||
</div>
|
||
))}
|
||
{selected&&(
|
||
<Card style={{marginTop:8}} glow={C.purple} innerRef={detalleRef}>
|
||
<div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:12}}>
|
||
<div style={{display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"}}>
|
||
<span style={{fontFamily:C.mono,color:C.purple,fontWeight:700}}>Bloque #{fmt.num(selected.height)}</span>
|
||
<VerEnMempool base={base} tipo="bloque" id={selected.id}/>
|
||
</div>
|
||
<button onClick={()=>{setSelected(null);setBlockTxs(null);}} style={{background:"none",border:"none",color:C.t2,cursor:"pointer",fontSize:"1rem",fontFamily:C.mono}}>✕</button>
|
||
</div>
|
||
<div style={{fontSize:"0.68rem",fontFamily:C.mono,color:C.t2,wordBreak:"break-all",marginBottom:12}}>{selected.id}</div>
|
||
<div style={{display:"grid",gridTemplateColumns:"repeat(auto-fill,minmax(130px,1fr))",gap:12,paddingTop:12,borderTop:`1px solid ${C.border}`,marginBottom:16}}>
|
||
<Tag label="Transacciones" value={fmt.num(selected.tx_count)} color={C.blue}/>
|
||
<Tag label="Tamaño" value={fmt.mb(selected.size)} color={C.t1}/>
|
||
<Tag label="Fees totales" value={selected.extras&&selected.extras.totalFees!=null?fmt.sbtc(selected.extras.totalFees):"-"} color={C.amber}/>
|
||
<Tag label="Fee mediana" value={selected.extras&&selected.extras.medianFee!=null?`${(Math.round(selected.extras.medianFee*100)/100)} sat/vB`:"-"} color={C.amber}/>
|
||
<Tag label="Minero" value={selected.extras&&selected.extras.pool?selected.extras.pool.name:"-"} color={C.green}/>
|
||
<Tag label="Minado" value={fmt.date(selected.timestamp)} color={C.t1}/>
|
||
</div>
|
||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,textTransform:"uppercase",marginBottom:8}}>Primeras Transacciones</div>
|
||
{!blockTxs&&<Spinner/>}
|
||
{blockTxs&&blockTxs.slice(0,5).map((tx,i)=>(
|
||
<div key={i} style={{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"6px 0",borderBottom:`1px solid ${C.border}`}}>
|
||
<span style={{fontSize:"0.68rem",fontFamily:C.mono,color:C.blue}}><IdCopiable id={tx.txid} texto={fmt.hash(tx.txid)}/></span>
|
||
<div style={{display:"flex",gap:6,alignItems:"center"}}><Badge color={C.amber}>{tx.fee} sat</Badge><Badge color={C.t3}>{tx.size}B</Badge><VerEnMempool base={base} tipo="tx" id={tx.txid} texto="↗"/></div>
|
||
</div>
|
||
))}
|
||
</Card>
|
||
)}
|
||
|
||
{/* Histórico de comisiones — para saber si hoy es caro o barato */}
|
||
<Card>
|
||
<div style={{display:"flex",flexDirection:isMobile?"column":"row",alignItems:isMobile?"flex-start":"center",justifyContent:"space-between",gap:isMobile?8:0,marginBottom:12}}>
|
||
<div style={{fontSize:"0.62rem",color:C.amber,fontFamily:C.mono,textTransform:"uppercase",letterSpacing:isMobile?"0.1em":"0.2em",display:"flex",alignItems:"center",gap:8}}>
|
||
<span>◈</span> Comisiones de la última semana
|
||
</div>
|
||
{feeStats&&(
|
||
<div style={{display:"flex",gap:8,flexWrap:"wrap"}}>
|
||
<Badge color={C.green}>mín {feeStats.min} sat/vB</Badge>
|
||
<Badge color={C.amber}>media {feeStats.avg} sat/vB</Badge>
|
||
<Badge color={C.red}>máx {feeStats.max} sat/vB</Badge>
|
||
</div>
|
||
)}
|
||
</div>
|
||
{!feeHistory ? <Spinner/> : <FeeChart data={feeHistory} isMobile={isMobile}/>}
|
||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,marginTop:8}}>
|
||
sat/vB por hora · los fines de semana suelen ser más baratos
|
||
</div>
|
||
</Card>
|
||
</div>
|
||
);
|
||
}
|
||
|
||
const MOCK_FEE_HISTORY = Array.from({length:168}, (_,i) => ({
|
||
timestamp: Math.floor(Date.now()/1000) - (167-i)*3600,
|
||
avgFee_50: Math.max(1, Math.round(2 + Math.sin(i/8)*3 + Math.sin(i/24)*8 + Math.random()*2)),
|
||
}));
|
||
|
||
function FeeChart({data, isMobile}) {
|
||
if (!data || data.length === 0) return null;
|
||
const W = 600, H = 120, PAD = {top:10, right:10, bottom:24, left:32};
|
||
const plotW = W - PAD.left - PAD.right;
|
||
const plotH = H - PAD.top - PAD.bottom;
|
||
// Use avgFee_50 (median) as the fee value
|
||
const fees = data.map(d => d.avgFee_50 || d.avgFee || 0).filter(v => v > 0);
|
||
if (fees.length === 0) return null;
|
||
const maxFee = Math.max(...fees);
|
||
const minFee = Math.min(...fees);
|
||
const range = maxFee - minFee || 1;
|
||
|
||
const x = i => PAD.left + (i / (data.length-1)) * plotW;
|
||
const y = v => PAD.top + plotH - ((v - minFee) / range) * plotH;
|
||
|
||
const points = data.map((d,i) => `${x(i)},${y(d.avgFee_50||d.avgFee||minFee)}`);
|
||
const linePath = `M${points.join("L")}`;
|
||
const areaPath = `M${PAD.left},${PAD.top+plotH}L${points.join("L")}L${PAD.left+plotW},${PAD.top+plotH}Z`;
|
||
|
||
// X labels — menos etiquetas en móvil para que no se solapen
|
||
const labelCount = isMobile ? 4 : 7;
|
||
const step = Math.max(1, Math.floor(data.length/labelCount));
|
||
const xLabels = [];
|
||
for (let i=0; i<data.length; i+=step) {
|
||
const d = new Date(data[i].timestamp*1000);
|
||
xLabels.push({ i, label:`${d.getDate()}/${d.getMonth()+1}` });
|
||
}
|
||
const yLabels = [minFee, Math.round((minFee+maxFee)/2), maxFee];
|
||
|
||
return (
|
||
<svg viewBox={`0 0 ${W} ${H}`} style={{width:"100%",height:"auto",display:"block"}}>
|
||
<defs>
|
||
<linearGradient id="feeGrad" x1="0" y1="0" x2="0" y2="1">
|
||
<stop offset="0%" stopColor={C.amber} stopOpacity="0.3"/>
|
||
<stop offset="100%" stopColor={C.amber} stopOpacity="0"/>
|
||
</linearGradient>
|
||
</defs>
|
||
{yLabels.map((v,i) => (
|
||
<line key={i} x1={PAD.left} y1={y(v)} x2={PAD.left+plotW} y2={y(v)} stroke={C.border} strokeWidth="1"/>
|
||
))}
|
||
<path d={areaPath} fill="url(#feeGrad)"/>
|
||
<path d={linePath} fill="none" stroke={C.amber} strokeWidth="1.5" strokeLinejoin="round"/>
|
||
{yLabels.map((v,i) => (
|
||
<text key={i} x={PAD.left-4} y={y(v)+4} textAnchor="end" fill={C.t2} fontSize="9" fontFamily={C.mono}>{v}</text>
|
||
))}
|
||
{xLabels.map(({i,label}) => (
|
||
<text key={i} x={x(i)} y={H-4} textAnchor="middle" fill={C.t2} fontSize="9" fontFamily={C.mono}>{label}</text>
|
||
))}
|
||
</svg>
|
||
);
|
||
}
|
||
|
||
|