código partido en src/: la app no cambia ni un byte
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01YA7U5k2DMU8ZdD6MztyVYS
This commit is contained in:
@@ -0,0 +1,702 @@
|
||||
// ── AUDITORÍA ──────────────────────────────────────────────────────────
|
||||
function Auditoria({base, initialQuery, abrirWallet}) {
|
||||
const {get, getStrict}=useApi(base);
|
||||
const consultaRef=useRef(0);
|
||||
const [query,setQuery]=useState(initialQuery||"");
|
||||
const [tx,setTx]=useState(null);
|
||||
const [analysis,setAnalysis]=useState(null);
|
||||
const [loading,setLoading]=useState(false);
|
||||
const [err,setErr]=useState(null);
|
||||
const [labels,setLabels]=useState(new Map()); // BIP-329: ref -> label
|
||||
const [showLabelModal,setShowLabelModal]=useState(false);
|
||||
const [labelInfo,setLabelInfo]=useState(null); // {count, file}
|
||||
const [walletAddrs,setWalletAddrs]=useState(null); // {receive:[], change:[]}
|
||||
// Con la wallet cargada, el análisis sabe si envías o recibes (v1.29).
|
||||
const ctxWallet = useMemo(() => walletAddrs ? { misDirecciones: new Set([...walletAddrs.receive, ...walletAddrs.change]) } : null, [walletAddrs]);
|
||||
const [xpubInput,setXpubInput]=useState("");
|
||||
const [xpubCount,setXpubCount]=useState(20);
|
||||
const [xpubLoading,setXpubLoading]=useState(false);
|
||||
const [xpubError,setXpubError]=useState(null);
|
||||
const [showWalletPanel,setShowWalletPanel]=useState(false);
|
||||
// Desde Inicio → «Revisar mi wallet» se llega con el panel ya abierto.
|
||||
const walletRef=useRef(null);
|
||||
useEffect(()=>{
|
||||
if(!abrirWallet) return;
|
||||
setShowWalletPanel(true); setShowLabelModal(false);
|
||||
},[abrirWallet]);
|
||||
|
||||
// Derivar direcciones usa la criptografía del navegador (crypto.subtle),
|
||||
// que solo existe en páginas seguras: https o el propio ordenador. Por
|
||||
// http fallaba con un error técnico; ahora se dice qué hacer.
|
||||
const paginaSegura = typeof window!=="undefined" && !!window.isSecureContext && !!(window.crypto&&window.crypto.subtle);
|
||||
// Generación de wallet: cada carga o borrado la incrementa, y un escaneo
|
||||
// que termine después de un cambio de wallet descarta su resultado. Sin
|
||||
// esto, el informe de una clave podía quedarse en pantalla con otra
|
||||
// cargada, o seguir visible (y descargable) tras «Borrar wallet» (W-06).
|
||||
const walletGen=useRef(0);
|
||||
const olvidarInforme = () => { walletGen.current++; setWalletReport(null); setWalletScanning(false); setWalletProgress(""); setVerifWallet(null); };
|
||||
// ¿Coincide la primera dirección con la de tu wallet? (v1.31) null | "si" | "no"
|
||||
const [verifWallet,setVerifWallet]=useState(null);
|
||||
const [verDondeClave,setVerDondeClave]=useState(false);
|
||||
const loadWallet = async (scriptElegido) => {
|
||||
const xpub = xpubInput.trim();
|
||||
if (!xpub) return;
|
||||
if (!paginaSegura) { setXpubError("Para cargar la wallet abre el dashboard por https (normalmente https://…:4081/dashboard). Por http el navegador no deja hacer la derivación."); return; }
|
||||
if (!/^[xyzuvt]pub[1-9A-HJ-NP-Za-km-z]{100,}$/.test(xpub)) {
|
||||
setXpubError("Introduce un xpub/zpub válido"); return;
|
||||
}
|
||||
setXpubLoading(true); setXpubError(null); olvidarInforme();
|
||||
const elegido = typeof scriptElegido === "string" ? scriptElegido : null;
|
||||
try {
|
||||
const addrs = await deriveAddresses(xpub, xpubCount, elegido);
|
||||
setWalletAddrs(addrs);
|
||||
// El panel se queda abierto: el paso siguiente («Analizar wallet»)
|
||||
// vive aquí, y antes desaparecía al cargar.
|
||||
} catch(e) {
|
||||
setXpubError("Error al derivar direcciones: " + e.message);
|
||||
}
|
||||
setXpubLoading(false);
|
||||
};
|
||||
|
||||
const clearWallet = () => { setWalletAddrs(null); setXpubInput(""); setXpubError(null); olvidarInforme(); };
|
||||
|
||||
// Determinar si una dirección es mía y de qué rama
|
||||
const myAddr = (addr) => {
|
||||
if (!walletAddrs) return null;
|
||||
if (walletAddrs.receive.includes(addr)) return "recepción";
|
||||
if (walletAddrs.change.includes(addr)) return "cambio";
|
||||
return null;
|
||||
};
|
||||
|
||||
// ── Análisis de wallet completo ──────────────────────────────────────
|
||||
const [walletReport,setWalletReport]=useState(null);
|
||||
const [walletScanning,setWalletScanning]=useState(false);
|
||||
const [walletProgress,setWalletProgress]=useState("");
|
||||
|
||||
// Trae datos del nodo por lotes, con pausa, para no saturar Fulcrum
|
||||
const scanWallet = async () => {
|
||||
if (!walletAddrs || !base) return;
|
||||
const gen = ++walletGen.current;
|
||||
setWalletScanning(true); setWalletReport(null);
|
||||
try {
|
||||
const all = [...walletAddrs.receive.map(a=>({addr:a,branch:"recepción"})),
|
||||
...walletAddrs.change.map(a=>({addr:a,branch:"cambio"}))];
|
||||
const BATCH = 5; // direcciones por lote
|
||||
const PAUSE = 120; // ms entre lotes
|
||||
const active = []; // direcciones con actividad
|
||||
// Consultas que el nodo no pudo servir. Se registran porque su
|
||||
// ausencia SESGA el informe hacia el optimismo: una dirección que no
|
||||
// se pudo leer parece una dirección sin actividad, y entonces su
|
||||
// reutilización, sus vinculaciones y sus transacciones desaparecen
|
||||
// del análisis. Decir "tu wallet está limpia" cuando en realidad
|
||||
// faltan datos es peor que no decir nada.
|
||||
const scanErrors = [];
|
||||
|
||||
// Fase 1: estado ligero de cada dirección
|
||||
for (let i = 0; i < all.length; i += BATCH) {
|
||||
const slice = all.slice(i, i + BATCH);
|
||||
setWalletProgress(`Explorando direcciones ${Math.min(i+BATCH,all.length)}/${all.length}`);
|
||||
const infos = await Promise.all(slice.map(async s => {
|
||||
try { return await getStrict(`/api/address/${s.addr}`); }
|
||||
catch (e) { scanErrors.push({ addr:s.addr, branch:s.branch, message:e.message, phase:"estado de la dirección" }); return null; }
|
||||
}));
|
||||
infos.forEach((info, j) => {
|
||||
const txc = info?.chain_stats?.tx_count || 0;
|
||||
if (txc > 0) active.push({ ...slice[j], info });
|
||||
});
|
||||
if (i + BATCH < all.length) await new Promise(r => setTimeout(r, PAUSE));
|
||||
}
|
||||
|
||||
// Fase 2: txs de las direcciones con actividad, con paginación
|
||||
// (paginaSiguiente: after_txid de Mempool o /txs/chain de Esplora;
|
||||
// 25 por página en Esplora, 10 sobre Electrum). Una página corta no
|
||||
// es el final: lo es una vacía o haber visto tx_count transacciones.
|
||||
const txMap = new Map();
|
||||
const myAddrSet = new Set(all.map(a => a.addr));
|
||||
for (let i = 0; i < active.length; i += BATCH) {
|
||||
const slice = active.slice(i, i + BATCH);
|
||||
setWalletProgress(`Trayendo transacciones ${Math.min(i+BATCH,active.length)}/${active.length}`);
|
||||
await Promise.all(slice.map(async s => {
|
||||
try {
|
||||
const raiz = `/api/address/${s.addr}`;
|
||||
const total = (s.info?.chain_stats?.tx_count || 0) + (s.info?.mempool_stats?.tx_count || 0);
|
||||
let page = await getStrict(`${raiz}/txs`);
|
||||
const primero = page?.[0]?.txid, vistas = new Set();
|
||||
let guard = 0;
|
||||
while (Array.isArray(page) && page.length > 0 && guard < 20) {
|
||||
const nuevas = page.filter(t => t && t.txid && !vistas.has(t.txid));
|
||||
if (!nuevas.length) break; // el servidor no avanzó
|
||||
nuevas.forEach(t => { vistas.add(t.txid); txMap.set(t.txid, t); });
|
||||
if (total && vistas.size >= total) break;
|
||||
page = await paginaSiguiente(getStrict, raiz, page[page.length-1].txid, primero);
|
||||
guard++;
|
||||
}
|
||||
if (total && vistas.size < total) scanErrors.push({ addr:s.addr, branch:s.branch, message:`historial incompleto: vistas ${vistas.size} de ${total} transacciones`, phase:"historial de transacciones", txCount:total });
|
||||
} catch (e) {
|
||||
// Perder el historial de una dirección con actividad conocida
|
||||
// es lo más grave: sabemos que tiene transacciones y no hemos
|
||||
// podido verlas. El informe queda incompleto por ahí.
|
||||
scanErrors.push({ addr:s.addr, branch:s.branch, message:e.message, phase:"historial de transacciones", txCount:s.info?.chain_stats?.tx_count ?? null });
|
||||
}
|
||||
}));
|
||||
if (i + BATCH < active.length) await new Promise(r => setTimeout(r, PAUSE));
|
||||
}
|
||||
|
||||
setWalletProgress("Analizando vinculación…");
|
||||
const report = buildWalletReport(active, [...txMap.values()], myAddrSet);
|
||||
report.scanErrors = scanErrors;
|
||||
report.scanComplete = scanErrors.length === 0;
|
||||
report.alcance = { porRama: walletAddrs.receive.length, script: walletAddrs.script, scriptSupuesto: walletAddrs.scriptSupuesto };
|
||||
if (gen !== walletGen.current) return; // la wallet cambió mientras se escaneaba
|
||||
setWalletReport(report);
|
||||
} catch(e) {
|
||||
if (gen !== walletGen.current) return;
|
||||
setWalletReport({ error: e.message });
|
||||
}
|
||||
setWalletScanning(false); setWalletProgress("");
|
||||
};
|
||||
|
||||
const loadLabels = (file) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => {
|
||||
const map = new Map();
|
||||
const lines = e.target.result.split("\n").filter(l => l.trim());
|
||||
for (const line of lines) {
|
||||
try {
|
||||
const obj = JSON.parse(line);
|
||||
if (obj.ref && obj.label) map.set(obj.ref, obj.label);
|
||||
} catch {}
|
||||
}
|
||||
setLabels(map);
|
||||
setLabelInfo({count: map.size, file: file.name});
|
||||
setTimeout(() => setShowLabelModal(false), 50);
|
||||
};
|
||||
reader.readAsText(file);
|
||||
};
|
||||
|
||||
const analyze=useCallback(async(q)=>{
|
||||
q=(q||query).trim(); if(!q)return;
|
||||
// Cada consulta lleva su número: si llega tarde la respuesta de una
|
||||
// anterior, se descarta en vez de pisar la nueva (revisión A-05).
|
||||
const gen = ++consultaRef.current;
|
||||
setTx(null);setAnalysis(null);setErr(null);
|
||||
if(!/^[0-9a-f]{64}$/i.test(q)){ setErr("Eso no es un txid: tiene que tener 64 caracteres (0-9 y a-f). Para direcciones o bloques usa «Explorar la cadena»."); return; }
|
||||
setLoading(true);
|
||||
if(!base){
|
||||
setTimeout(()=>{setTx(MOCK_TX);setAnalysis(analyzeTx(MOCK_TX));setLoading(false);},400); return;
|
||||
}
|
||||
try{
|
||||
if(!/^[0-9a-f]{64}$/i.test(q)) throw new Error("Introduce un txid válido (64 caracteres hex)");
|
||||
let txData;
|
||||
try { txData=await getStrict(`/api/tx/${q}`); }
|
||||
catch(e){ if(gen!==consultaRef.current) return; throw new Error(mensajeTxNoLlega(e)); }
|
||||
if(gen!==consultaRef.current) return;
|
||||
if(!txData) throw new Error("Transacción no encontrada: tu nodo responde, pero no la conoce.");
|
||||
setTx(txData); setAnalysis(analyzeTx(txData, ctxWallet));
|
||||
}catch(e){ if(gen===consultaRef.current) setErr(e.message); }
|
||||
if(gen===consultaRef.current) setLoading(false);
|
||||
},[query,base,get,getStrict,ctxWallet]);
|
||||
// Si se carga o se borra la wallet con una transacción ya analizada, se
|
||||
// vuelve a analizar: el papel (envías/recibes) puede cambiar la lectura.
|
||||
useEffect(()=>{ if(tx) setAnalysis(analyzeTx(tx, ctxWallet)); },[ctxWallet]);
|
||||
|
||||
// Si llegamos desde LAB con query pre-cargado, lanzar automáticamente
|
||||
useEffect(()=>{
|
||||
if(initialQuery){ setQuery(initialQuery); analyze(initialQuery); }
|
||||
},[initialQuery]);
|
||||
|
||||
return (
|
||||
<div style={{display:"flex",flexDirection:"column",gap:12}}>
|
||||
{!base&&<DemoBanner/>}
|
||||
<SectionTitle accent={C.purple} icon="⌖">Auditar privacidad</SectionTitle>
|
||||
{/* Antes eran dos botoncitos grises ("Wallet ↑") que casi no se veían. */}
|
||||
<div style={{display:"grid",gridTemplateColumns:"repeat(auto-fit,minmax(220px,1fr))",gap:8}}>
|
||||
<button onClick={()=>{setShowWalletPanel(!showWalletPanel);setShowLabelModal(false);}}
|
||||
style={{textAlign:"left",padding:"12px 14px",background:walletAddrs||showWalletPanel?C.greenMuted:C.bgCard,border:`1px solid ${C.green}${walletAddrs||showWalletPanel?"":"60"}`,borderRadius:8,cursor:"pointer"}}>
|
||||
<div style={{color:C.green,fontWeight:700,fontSize:"0.82rem",marginBottom:3}}>{walletAddrs?"✓ Wallet cargado":"Cargar mi wallet (xpub)"}</div>
|
||||
<div style={{color:C.t2,fontSize:"0.68rem",lineHeight:1.45}}>{walletAddrs?`${walletAddrs.receive.length+walletAddrs.change.length} direcciones tuyas. Pulsa para verlas o cambiar.`:"Para que la app sepa qué direcciones son tuyas. Solo la clave pública."}</div>
|
||||
</button>
|
||||
<button onClick={()=>{setShowLabelModal(!showLabelModal);setShowWalletPanel(false);}}
|
||||
style={{textAlign:"left",padding:"12px 14px",background:labels.size>0||showLabelModal?C.blueMuted:C.bgCard,border:`1px solid ${C.blue}${labels.size>0||showLabelModal?"":"60"}`,borderRadius:8,cursor:"pointer"}}>
|
||||
<div style={{color:C.blue,fontWeight:700,fontSize:"0.82rem",marginBottom:3}}>{labels.size>0?`✓ ${labels.size} etiquetas`:"Importar etiquetas (Sparrow)"}</div>
|
||||
<div style={{color:C.t2,fontSize:"0.68rem",lineHeight:1.45}}>{labels.size>0?"Pulsa para ver o cambiar el archivo.":"Archivo de etiquetas exportado de Sparrow: pone nombre a tus direcciones."}</div>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{showWalletPanel&&(
|
||||
<Card glow={C.green} innerRef={walletRef}>
|
||||
<div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10}}>
|
||||
<div style={{fontSize:"0.65rem",color:C.green,fontFamily:C.mono,fontWeight:700}}>WALLET WATCH-ONLY (xpub)</div>
|
||||
<button onClick={()=>setShowWalletPanel(false)} style={{background:"none",border:"none",color:C.t2,cursor:"pointer",fontSize:"1rem"}}>×</button>
|
||||
</div>
|
||||
{!paginaSegura&&<div style={{fontSize:"0.7rem",color:C.red,marginBottom:10,padding:"8px 10px",background:C.redMuted,border:`1px solid ${C.red}40`,borderRadius:6,lineHeight:1.55}}>
|
||||
<strong>Así no se puede cargar la wallet:</strong> esta página está abierta por http. Ábrela por https (normalmente <span style={{fontFamily:C.mono}}>https://…:4081/dashboard</span>) y pon también la dirección https en ⚙ Ajustes.
|
||||
</div>}
|
||||
<div style={{fontSize:"0.68rem",color:C.t2,marginBottom:8}}>
|
||||
Pega la clave pública de tu wallet (xpub, ypub o zpub). <strong style={{color:C.t1}}>Nunca las 12 o 24 palabras</strong>: con la clave pública se pueden ver tus direcciones, no gastar. La derivación ocurre en tu navegador: la clave no se envía a ninguna parte.
|
||||
<button onClick={()=>setVerDondeClave(!verDondeClave)} style={{marginLeft:6,background:"none",border:"none",color:C.green,fontFamily:C.mono,fontSize:"0.64rem",cursor:"pointer",padding:0,textDecoration:"underline"}}>{verDondeClave?"ocultar":"¿dónde la encuentro?"}</button>
|
||||
{verDondeClave&&(
|
||||
<div style={{marginTop:6,padding:"8px 10px",background:C.bgCard,border:`1px solid ${C.border}`,borderRadius:6,lineHeight:1.65}}>
|
||||
<div><strong style={{color:C.t1}}>Sparrow:</strong> abre la wallet → pestaña Settings → en Keystores, el campo xpub/zpub (Master Public Key).</div>
|
||||
<div><strong style={{color:C.t1}}>BlueWallet:</strong> entra en la wallet → ⋯ (detalles) → «Mostrar XPUB».</div>
|
||||
<div><strong style={{color:C.t1}}>Electrum:</strong> menú Monedero → Información → Clave pública maestra.</div>
|
||||
<div style={{marginTop:4,color:C.t3}}>Los nombres pueden cambiar un poco según la versión. Lo que buscas es un texto largo que empieza por xpub, ypub o zpub.</div>
|
||||
</div>)}
|
||||
</div>
|
||||
{/* Este aviso no es adorno. La versión anterior decía solo "el
|
||||
xpub no sale del navegador", que es cierto y a la vez
|
||||
engañoso: las DIRECCIONES derivadas sí salen, una consulta
|
||||
por cada una. Quien opere el nodo ve el wallet entero. En una
|
||||
herramienta que existe para no afirmar de más, esa media
|
||||
verdad era el peor sitio posible para tenerla. */}
|
||||
<div style={{fontSize:"0.66rem",color:C.t2,marginBottom:12,padding:"8px 10px",background:C.bgCard,border:`1px solid ${C.amber}40`,borderRadius:6,lineHeight:1.55}}>
|
||||
<span style={{color:C.amber,fontWeight:700}}>Antes de seguir:</span> el xpub se queda aquí, pero para saber qué ha pasado con tus direcciones hay que <strong>preguntarle al nodo por cada una</strong>. Quien opere ese nodo puede ver, en sus registros, el wallet completo que estás analizando: cuántas direcciones tienes, cuáles, su historial y su saldo.
|
||||
<div style={{marginTop:5}}>
|
||||
Si el nodo es <strong>tuyo</strong>, no hay problema: es tu propia información en tu propia máquina. Si es el nodo <strong>de otra persona</strong>, aunque sea alguien de confianza, le estás enseñando tus finanzas enteras. En ese caso usa un xpub de prueba o monta tu nodo.
|
||||
</div>
|
||||
</div>
|
||||
{walletAddrs?(
|
||||
<div>
|
||||
<div style={{fontSize:"0.65rem",color:C.green,fontFamily:C.mono,marginBottom:6}}>✓ {walletAddrs.receive.length} direcciones de recepción + {walletAddrs.change.length} de cambio derivadas</div>
|
||||
<div style={{fontSize:"0.64rem",color:C.t2,marginBottom:8,lineHeight:1.55}}>
|
||||
Tipo de dirección: <strong style={{color:C.t1}}>{TIPO_SCRIPT[walletAddrs.script]||walletAddrs.script}</strong>
|
||||
{walletAddrs.scriptSupuesto
|
||||
? <> · <span style={{color:C.amber}}>supuesto</span>. Una {walletAddrs.tipo} no indica el tipo de dirección: puede ser de una wallet SegWit nativa (bc1q…) o de una antigua (1…). Si las direcciones de abajo no coinciden con las de tu wallet, prueba otro tipo:</>
|
||||
: walletAddrs.tipo==="xpub"||walletAddrs.tipo==="tpub" ? <> · elegido por ti.</> : <> · lo indica el prefijo {walletAddrs.tipo}.</>}
|
||||
</div>
|
||||
{(walletAddrs.tipo==="xpub"||walletAddrs.tipo==="tpub")&&(
|
||||
<div style={{display:"flex",gap:6,flexWrap:"wrap",marginBottom:8}}>
|
||||
{["p2wpkh","p2sh-p2wpkh","p2pkh"].map(t=>(
|
||||
<button key={t} onClick={()=>loadWallet(t)} disabled={xpubLoading}
|
||||
style={{padding:"4px 10px",background:walletAddrs.script===t?C.greenMuted:"none",border:`1px solid ${walletAddrs.script===t?C.green:C.border}`,borderRadius:5,color:walletAddrs.script===t?C.green:C.t2,fontFamily:C.mono,fontSize:"0.62rem",cursor:"pointer"}}>
|
||||
{TIPO_SCRIPT[t]}
|
||||
</button>))}
|
||||
</div>)}
|
||||
{(walletAddrs.avisos||[]).map((a,i)=>(
|
||||
<div key={i} style={{fontSize:"0.64rem",color:C.amber,marginBottom:8,padding:"6px 9px",border:`1px solid ${C.amber}40`,borderRadius:6,lineHeight:1.5}}>⚠ {a}</div>))}
|
||||
<div style={{fontSize:"0.62rem",color:C.t2,marginBottom:8}}>Las direcciones de tus txs analizadas se marcan automáticamente como tuyas. Compara estas con las de tu wallet:</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:3,marginBottom:10}}>
|
||||
{walletAddrs.receive.slice(0,3).map((a,i)=>(
|
||||
<div key={i} style={{fontSize:"0.6rem",fontFamily:C.mono,color:C.t1}}>
|
||||
<span style={{color:C.t2}}>recep #{i}:</span> {a}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{/* Comprobación con un sí o un no (v1.31). Evita analizar
|
||||
direcciones que no son las tuyas sin darte cuenta. */}
|
||||
<div style={{marginBottom:10,padding:"9px 11px",border:`1px solid ${verifWallet==="si"?C.green:verifWallet==="no"?C.amber:C.borderBright}`,borderRadius:6,background:verifWallet==="si"?C.greenMuted:verifWallet==="no"?C.amberMuted:"none"}}>
|
||||
{verifWallet==="si" ? (
|
||||
<div style={{fontSize:"0.66rem",color:C.green,lineHeight:1.5}}>✓ Comprobado por ti: son las direcciones de tu wallet. <button onClick={()=>setVerifWallet(null)} style={{background:"none",border:"none",color:C.t2,fontSize:"0.6rem",cursor:"pointer",textDecoration:"underline",padding:0}}>deshacer</button></div>
|
||||
) : (<>
|
||||
<div style={{fontSize:"0.66rem",color:C.t1,marginBottom:6}}>¿La <strong>recep #0</strong> es la primera dirección de recepción de tu wallet?</div>
|
||||
<div style={{display:"flex",gap:6}}>
|
||||
<button onClick={()=>setVerifWallet("si")} style={{padding:"5px 14px",background:"none",border:`1px solid ${C.green}70`,borderRadius:5,color:C.green,fontFamily:C.mono,fontSize:"0.64rem",cursor:"pointer"}}>Sí</button>
|
||||
<button onClick={()=>setVerifWallet("no")} style={{padding:"5px 14px",background:"none",border:`1px solid ${C.amber}70`,borderRadius:5,color:C.amber,fontFamily:C.mono,fontSize:"0.64rem",cursor:"pointer"}}>No</button>
|
||||
</div>
|
||||
{verifWallet==="no"&&(
|
||||
<div style={{marginTop:8,fontSize:"0.64rem",color:C.t1,lineHeight:1.6}}>
|
||||
{(walletAddrs.tipo==="xpub"||walletAddrs.tipo==="tpub")
|
||||
? <>Una {walletAddrs.tipo} no dice qué tipo de direcciones usa tu wallet. Prueba los botones de tipo de arriba (SegWit anidada 3…, legacy 1…): el que dé la misma dirección es el bueno.</>
|
||||
: <>La app ha calculado direcciones {TIPO_SCRIPT[walletAddrs.script]} porque es lo que indica el prefijo {walletAddrs.tipo}. Si las de tu wallet empiezan por otra cosa, exporta la clave con el prefijo que corresponde: zpub para bc1q…, ypub para 3…, o una xpub y eliges el tipo aquí.</>}
|
||||
<div style={{marginTop:4}}>Comprueba también que es la clave de la misma cuenta y wallet, y que miras su primera dirección de <em>recepción</em>, no una de cambio.{walletAddrs.profundidad!==3?" Además, esta clave no es de una cuenta normal (mira el aviso de arriba).":""}</div>
|
||||
<div style={{marginTop:4,color:C.t2}}>Mientras no coincidan, el análisis de abajo sería sobre direcciones que no son las tuyas.</div>
|
||||
</div>)}
|
||||
</>)}
|
||||
</div>
|
||||
<div style={{display:"flex",gap:8,flexWrap:"wrap"}}>
|
||||
<button onClick={scanWallet} disabled={walletScanning||!base}
|
||||
style={{padding:"6px 14px",background:C.purpleMuted,border:`1px solid ${C.purple}60`,borderRadius:6,color:C.purple,fontFamily:C.mono,fontSize:"0.65rem",cursor:"pointer",fontWeight:700}}>
|
||||
{walletScanning?"···":"⊙ Analizar wallet"}
|
||||
</button>
|
||||
<button onClick={clearWallet} style={{padding:"6px 14px",background:"none",border:`1px solid ${C.red}40`,borderRadius:6,color:C.red,fontFamily:C.mono,fontSize:"0.65rem",cursor:"pointer"}}>
|
||||
Borrar wallet
|
||||
</button>
|
||||
</div>
|
||||
<div style={{marginTop:8,fontSize:"0.64rem",color:base?C.t2:C.amber,lineHeight:1.55}}>
|
||||
{base
|
||||
? "Siguiente paso: «Analizar wallet» pregunta a tu nodo por cada dirección derivada y arma el informe (reutilización, direcciones vinculadas, polvo, movimientos entre tus direcciones)."
|
||||
: "Siguiente paso: «Analizar wallet» necesita tu nodo para consultar el historial de cada dirección. Sin nodo configurado (⚙ Ajustes) no hay a quién preguntar; las direcciones derivadas de arriba sí son reales."}
|
||||
</div>
|
||||
{walletScanning&&walletProgress&&(
|
||||
<div style={{marginTop:8,fontSize:"0.62rem",color:C.t2,fontFamily:C.mono}}>{walletProgress}</div>
|
||||
)}
|
||||
</div>
|
||||
):(
|
||||
<div style={{display:"flex",gap:8}}>
|
||||
<input value={xpubInput} onChange={e=>setXpubInput(e.target.value)}
|
||||
onKeyDown={e=>e.key==="Enter"&&loadWallet()}
|
||||
placeholder="xpub... o zpub..."
|
||||
style={{flex:1,background:C.bg,border:`1px solid ${C.borderBright}`,borderRadius:6,padding:"8px 12px",color:C.t1,fontFamily:C.mono,fontSize:"0.7rem",outline:"none"}}
|
||||
/>
|
||||
<select value={xpubCount} onChange={e=>setXpubCount(Number(e.target.value))}
|
||||
title="Direcciones a derivar por rama"
|
||||
style={{background:C.bg,border:`1px solid ${C.borderBright}`,borderRadius:6,padding:"8px 8px",color:C.t1,fontFamily:C.mono,fontSize:"0.7rem",outline:"none",cursor:"pointer"}}>
|
||||
<option value={20}>20</option>
|
||||
<option value={50}>50</option>
|
||||
<option value={100}>100</option>
|
||||
</select>
|
||||
<button onClick={loadWallet} disabled={xpubLoading}
|
||||
style={{padding:"8px 16px",background:C.greenMuted,border:`1px solid ${C.green}40`,borderRadius:6,color:C.green,fontFamily:C.mono,fontSize:"0.72rem",cursor:"pointer",fontWeight:700}}>
|
||||
{xpubLoading?"···":"Cargar"}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{!walletAddrs&&<div style={{marginTop:8,fontSize:"0.6rem",color:C.t2,fontFamily:C.mono}}>Direcciones a derivar por rama (recepción y cambio). Más direcciones = más cobertura pero más tiempo de cálculo.</div>}
|
||||
{xpubError&&<div style={{marginTop:8,fontSize:"0.65rem",color:C.red,fontFamily:C.mono}}>{xpubError}</div>}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{walletReport&&!walletReport.error&&(
|
||||
<Card glow={C.purple}>
|
||||
{/* Cabecera del informe con exportación */}
|
||||
<div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:14}}>
|
||||
<div style={{fontSize:"0.65rem",color:C.purple,fontFamily:C.mono,fontWeight:700}}>INFORME DE WALLET</div>
|
||||
<div style={{display:"flex",gap:6}}>
|
||||
<button onClick={()=>{
|
||||
const {health,...rest}=walletReport;
|
||||
const exportData={...rest,health:{band:health.band,msg:health.msg}};
|
||||
const blob=new Blob([JSON.stringify(exportData,null,2)],{type:"application/json"});
|
||||
const a=document.createElement("a");a.href=URL.createObjectURL(blob);a.download="wallet-report.json";a.click();
|
||||
}} style={{padding:"3px 10px",background:"none",border:`1px solid ${C.border}`,borderRadius:4,color:C.t2,fontFamily:C.mono,fontSize:"0.6rem",cursor:"pointer"}}>↓ JSON</button>
|
||||
<button onClick={()=>{
|
||||
const {health,totalTxs,activeCount,reusedAddrs,clusters,history,scanErrors}=walletReport;
|
||||
const lines=[
|
||||
`# Informe de Wallet — Txoko`,``,
|
||||
...((scanErrors&&scanErrors.length>0)?[
|
||||
`> **AVISO — informe incompleto.** ${scanErrors.length} consulta(s) al nodo fallaron durante el escaneo.`,
|
||||
`> Las direcciones no leídas se comportan como si no tuvieran actividad, así que la valoración`,
|
||||
`> de abajo es **optimista**: puede faltar reutilización, vinculaciones o transacciones enteras.`,
|
||||
`> Repite el escaneo antes de darla por buena.`,``,
|
||||
...scanErrors.map(e=>`> - ${e.addr} (${e.branch}) — ${e.message} [${e.phase}]`),``,
|
||||
]:[]),
|
||||
`## Salud general: ${health.band}`,``,health.msg,``,
|
||||
`- Transacciones analizadas: ${totalTxs}`,
|
||||
`- Direcciones con actividad: ${activeCount}`,
|
||||
`- Direcciones reutilizadas: ${reusedAddrs.length}`,
|
||||
`- Clusters de vinculación: ${clusters.length}`,``,
|
||||
`## Clusters de vinculación`,``,
|
||||
...(clusters.length===0?[`No se detectan clusters.`]:clusters.flatMap((c,i)=>[
|
||||
`### Cluster ${i+1} — ${c.length} direcciones vinculadas`,
|
||||
...c.map(a=>`- ${a}`),``
|
||||
])),``,
|
||||
`## Historial (${history.length} transacciones)`,``,
|
||||
...history.slice(0,20).map(t=>`- ${t.txid.slice(0,16)}… | ${t.band} | ${t.time?new Date(t.time*1000).toLocaleDateString("es-ES"):"sin confirmar"}`),
|
||||
];
|
||||
const blob=new Blob([lines.join("\n")],{type:"text/markdown"});
|
||||
const a=document.createElement("a");a.href=URL.createObjectURL(blob);a.download="wallet-report.md";a.click();
|
||||
}} style={{padding:"3px 10px",background:"none",border:`1px solid ${C.border}`,borderRadius:4,color:C.t2,fontFamily:C.mono,fontSize:"0.6rem",cursor:"pointer"}}>↓ MD</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Aviso de escaneo incompleto — va ANTES de la banda a
|
||||
propósito: una valoración de salud leída sin saber que
|
||||
faltan datos es peor que no tener valoración. El sesgo
|
||||
siempre va hacia el optimismo, porque una dirección no
|
||||
leída parece una dirección sin actividad. */}
|
||||
{walletReport.scanErrors&&walletReport.scanErrors.length>0&&(
|
||||
<div style={{padding:"10px 14px",background:C.redMuted,border:`1px solid ${C.red}40`,borderRadius:8,marginBottom:14}}>
|
||||
<div style={{fontSize:"0.66rem",color:C.red,fontFamily:C.mono,fontWeight:700,marginBottom:6}}>
|
||||
⚠ Informe incompleto — {walletReport.scanErrors.length} consulta(s) al nodo fallaron
|
||||
</div>
|
||||
<div style={{fontSize:"0.64rem",color:C.t1,lineHeight:1.6,marginBottom:8}}>
|
||||
Las direcciones que no se pudieron leer se comportan aquí como si no tuvieran actividad. Eso hace que la valoración de abajo sea <strong>optimista</strong>: puede faltar reutilización, vinculaciones o transacciones enteras que sí existen. No la des por buena sin repetir el escaneo.
|
||||
</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:2}}>
|
||||
{walletReport.scanErrors.slice(0,6).map((e,i)=>(
|
||||
<div key={i} style={{fontSize:"0.56rem",color:C.t2,fontFamily:C.mono,wordBreak:"break-all"}}>
|
||||
{e.addr} ({e.branch}) — {e.message} · {e.phase}
|
||||
</div>
|
||||
))}
|
||||
{walletReport.scanErrors.length>6&&(
|
||||
<div style={{fontSize:"0.56rem",color:C.t2,fontFamily:C.mono}}>…y {walletReport.scanErrors.length-6} más</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Polvo recibido — va arriba porque es accionable AHORA: lo
|
||||
único que hay que hacer es no gastarlo, y para eso hay que
|
||||
saber que está ahí. */}
|
||||
{walletReport.polvoSinGastar&&walletReport.polvoSinGastar.length>0&&(
|
||||
<div style={{padding:"10px 14px",background:C.amberMuted,border:`1px solid ${C.amber}50`,borderRadius:8,marginBottom:14}}>
|
||||
<div style={{fontSize:"0.66rem",color:C.amber,fontFamily:C.mono,fontWeight:700,marginBottom:6}}>
|
||||
⚠ Has recibido {walletReport.polvoSinGastar.length} moneda(s) de polvo sin gastar
|
||||
</div>
|
||||
<div style={{fontSize:"0.64rem",color:C.t1,lineHeight:1.7,marginBottom:8}}>
|
||||
Son importes ridículos que alguien envió a tus direcciones. Por sí solos no hacen nada y no valen nada. <strong>El riesgo aparece si se gastan junto a otras monedas</strong>: en ese momento quedan todas enlazadas con quien mandó el polvo, que es justo lo que persigue quien lo hace.
|
||||
<br/>Mientras sigan quietas, no vinculan nada. Algunos monederos permiten marcar monedas como no gastables (en Sparrow, clic derecho → <em>Freeze UTXO</em>) para que no entren en una transacción por accidente.
|
||||
</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:3}}>
|
||||
{walletReport.polvoSinGastar.slice(0,6).map((p,i)=>(
|
||||
<div key={i} style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,wordBreak:"break-all"}}>
|
||||
{fmt.num(p.value)} sat · {p.address} · {p.txid.slice(0,16)}…:{p.vout}
|
||||
{p.tecnico&&<span style={{color:C.t3}}> · por debajo del mínimo económico</span>}
|
||||
</div>
|
||||
))}
|
||||
{walletReport.polvoSinGastar.length>6&&<div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono}}>…y {walletReport.polvoSinGastar.length-6} más</div>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{walletReport.polvoRecibido&&walletReport.polvoSinGastar&&walletReport.polvoRecibido.length>walletReport.polvoSinGastar.length&&(
|
||||
<div style={{padding:"9px 14px",background:C.bgCard,border:`1px solid ${C.border}`,borderRadius:8,marginBottom:14,fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,lineHeight:1.6}}>
|
||||
Además, {walletReport.polvoRecibido.length - walletReport.polvoSinGastar.length} moneda(s) de polvo que recibiste <strong>ya se gastaron</strong>. Si se mezclaron con otras monedas tuyas, esa vinculación ya está hecha y no se puede deshacer — figura en los clusters de abajo si es el caso. Se indica para que sepas de dónde viene, no para preocuparte por algo que ya pasó.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Autoenvíos que ataron direcciones. Solo se muestra cuando
|
||||
hubo daño real (más de una dirección de entrada): mover una
|
||||
dirección a otra no vincula nada nuevo y no merece alarma. */}
|
||||
{walletReport.autoenviosDaninos && walletReport.autoenviosDaninos.length > 0 && (
|
||||
<div style={{padding:"10px 14px",background:C.bgCard,border:`1px solid ${C.amber}40`,borderRadius:8,marginBottom:14}}>
|
||||
<div style={{fontSize:"0.64rem",color:C.amber,fontFamily:C.mono,fontWeight:700,marginBottom:5}}>
|
||||
{walletReport.autoenviosDaninos.length} autoenvío(s) que ataron direcciones tuyas
|
||||
</div>
|
||||
<div style={{fontSize:"0.62rem",color:C.t2,lineHeight:1.6,marginBottom:6}}>
|
||||
Estas transacciones movieron dinero de varias direcciones tuyas a otra dirección tuya, sin pagar a nadie. Al firmarse juntas, esas direcciones quedaron enlazadas en público para siempre.
|
||||
</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:3}}>
|
||||
{walletReport.autoenviosDaninos.slice(0,6).map(a=>(
|
||||
<div key={a.txid} style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono}}>
|
||||
<span style={{color:C.amber}}>{a.vinculadas} direcciones atadas</span>
|
||||
{" · "}{a.time ? new Date(a.time*1000).toLocaleDateString("es-ES") : "sin confirmar"}
|
||||
{" · "}<VerEnMempool base={base} tipo="tx" id={a.txid} texto={a.txid.slice(0,12)+"… ↗"}/>
|
||||
</div>
|
||||
))}
|
||||
{walletReport.autoenviosDaninos.length>6&&<div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono}}>…y {walletReport.autoenviosDaninos.length-6} más</div>}
|
||||
</div>
|
||||
<div style={{fontSize:"0.6rem",color:C.t2,fontFamily:C.mono,marginTop:6,lineHeight:1.5}}>
|
||||
Ya está hecho y no se deshace.
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Bloque 1: Salud general */}
|
||||
<div style={{display:"flex",alignItems:"center",gap:14,padding:"12px 14px",background:C.bgCard,borderRadius:8,marginBottom:14,border:`1px solid ${walletReport.health.color}30`}}>
|
||||
<div style={{width:48,height:48,borderRadius:"50%",border:`3px solid ${walletReport.health.color}`,display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0}}>
|
||||
<span style={{fontSize:walletReport.health.band==="SIN ACTIVIDAD"?"0.5rem":"0.6rem",fontFamily:C.mono,fontWeight:700,color:walletReport.health.color,textAlign:"center",lineHeight:1.1}}>{walletReport.health.band==="SIN ACTIVIDAD"?"—":walletReport.health.band}</span>
|
||||
</div>
|
||||
<div>
|
||||
<div style={{fontSize:"0.72rem",color:walletReport.health.color,fontWeight:700,marginBottom:4}}>
|
||||
{walletReport.health.band==="SIN ACTIVIDAD"?"Sin actividad detectada":walletReport.health.band==="ALTA"?"Monedas bien separadas":walletReport.health.band==="MEDIA"?"Algunas monedas vinculadas":"Muchas monedas vinculadas"}
|
||||
</div>
|
||||
<div style={{fontSize:"0.65rem",color:C.t2,lineHeight:1.5}}>{walletReport.health.msg}</div>
|
||||
{walletReport.alcance&&<div style={{fontSize:"0.6rem",color:C.t2,fontFamily:C.mono,marginTop:5}}>Alcance: {walletReport.alcance.porRama} direcciones de recepción + {walletReport.alcance.porRama} de cambio · {TIPO_SCRIPT[walletReport.alcance.script]||walletReport.alcance.script}{walletReport.alcance.scriptSupuesto?" (supuesto)":""}{verifWallet==="si"?" · comprobado por ti":verifWallet==="no"?" · NO coincide con tu wallet":" · sin comprobar"}</div>}
|
||||
<div style={{display:"flex",gap:16,marginTop:8}}>
|
||||
{[
|
||||
{label:"Txs",v:walletReport.totalTxs},
|
||||
{label:"Activas",v:walletReport.activeCount},
|
||||
{label:"Reutilizadas",v:walletReport.reusedAddrs.length,warn:walletReport.reusedAddrs.length>0},
|
||||
{label:"Clusters",v:walletReport.clusters.length,warn:walletReport.clusters.length>0},
|
||||
].map(({label,v,warn})=>(
|
||||
<div key={label}>
|
||||
<div style={{fontSize:"0.55rem",color:C.t2,fontFamily:C.mono}}>{label}</div>
|
||||
<div style={{fontSize:"0.8rem",fontFamily:C.mono,fontWeight:700,color:warn?C.amber:C.t1}}>{v}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Bloque 2: Clusters de vinculación */}
|
||||
{walletReport.clusters.length>0&&(
|
||||
<div style={{marginBottom:14}}>
|
||||
<div style={{fontSize:"0.6rem",color:C.amber,fontFamily:C.mono,fontWeight:700,marginBottom:8,letterSpacing:"0.15em"}}>CLUSTERS DE VINCULACIÓN</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:8}}>
|
||||
{walletReport.clusters.map((cluster,i)=>{
|
||||
const reasons=walletReport.linkReasons.filter(r=>r.addrs.some(a=>cluster.includes(a)));
|
||||
const barW=Math.min(100,Math.round((cluster.length/Math.max(...walletReport.clusters.map(c=>c.length)))*100));
|
||||
return (
|
||||
<div key={i} style={{padding:"10px 12px",background:C.bgCard,border:`1px solid ${C.amber}30`,borderRadius:6}}>
|
||||
<div style={{display:"flex",alignItems:"center",gap:10,marginBottom:6}}>
|
||||
<div style={{fontSize:"0.62rem",color:C.amber,fontFamily:C.mono,fontWeight:600}}>Cluster {i+1}</div>
|
||||
<div style={{flex:1,height:4,background:C.bg,borderRadius:2,overflow:"hidden"}}>
|
||||
<div style={{width:`${barW}%`,height:"100%",background:C.amber,borderRadius:2}}/>
|
||||
</div>
|
||||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono}}>{cluster.length} dirs.</div>
|
||||
</div>
|
||||
{reasons.length>0&&(
|
||||
<div style={{fontSize:"0.6rem",color:C.t2,marginBottom:6,lineHeight:1.4}}>
|
||||
Vinculadas porque {reasons[0].reason}
|
||||
{reasons.length>1&&<span> (+{reasons.length-1} más)</span>}
|
||||
</div>
|
||||
)}
|
||||
<div style={{display:"flex",flexDirection:"column",gap:2}}>
|
||||
{cluster.slice(0,4).map((a,j)=>(
|
||||
<div key={j} style={{fontSize:"0.58rem",color:C.t1,fontFamily:C.mono}}>
|
||||
{labels?.get(a)&&<span style={{color:C.purple,marginRight:6}}>🏷 {labels.get(a)}</span>}
|
||||
{a.slice(0,14)}…{a.slice(-8)}
|
||||
</div>
|
||||
))}
|
||||
{cluster.length>4&&<div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono}}>+{cluster.length-4} más</div>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{walletReport.clusters.length===0&&walletReport.health.band!=="SIN ACTIVIDAD"&&(
|
||||
<div style={{marginBottom:14,padding:"10px 12px",background:C.bgCard,border:`1px solid ${C.green}30`,borderRadius:6,fontSize:"0.65rem",color:C.green,fontFamily:C.mono}}>
|
||||
✓ No se detectan clusters de vinculación entre tus monedas.
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Bloque 3: Historial */}
|
||||
{walletReport.history.length>0&&(
|
||||
<div>
|
||||
<div style={{fontSize:"0.6rem",color:C.t2,fontFamily:C.mono,fontWeight:700,marginBottom:8,letterSpacing:"0.15em"}}>HISTORIAL — {walletReport.history.length} TRANSACCIONES</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:4,maxHeight:320,overflowY:"auto"}}>
|
||||
{walletReport.history.map((t,i)=>{
|
||||
const bandColor=t.band==="ALTA"?C.green:t.band==="MEDIA"?C.amber:t.band==="BAJA"?C.red:C.t2;
|
||||
return (
|
||||
<div key={i} onClick={()=>{setQuery(t.txid);setShowWalletPanel(false);setTimeout(()=>analyze(t.txid),50);}}
|
||||
style={{display:"flex",alignItems:"center",gap:10,padding:"7px 10px",background:C.bgCard,borderRadius:5,cursor:"pointer",border:`1px solid ${C.border}`,transition:"border-color 0.15s"}}
|
||||
onMouseEnter={e=>e.currentTarget.style.borderColor=bandColor}
|
||||
onMouseLeave={e=>e.currentTarget.style.borderColor=C.border}>
|
||||
<div style={{width:6,height:6,borderRadius:"50%",background:bandColor,flexShrink:0}}/>
|
||||
<div style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,minWidth:70}}>
|
||||
{t.time?new Date(t.time*1000).toLocaleDateString("es-ES",{day:"2-digit",month:"2-digit",year:"2-digit"}):"pendiente"}
|
||||
</div>
|
||||
<div style={{fontSize:"0.6rem",color:C.t1,fontFamily:C.mono,flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}>
|
||||
{labels?.get(t.txid)&&<span style={{color:C.purple,marginRight:6}}>🏷</span>}
|
||||
{t.txid.slice(0,20)}…
|
||||
</div>
|
||||
<div style={{fontSize:"0.58rem",color:bandColor,fontFamily:C.mono,fontWeight:600,flexShrink:0}}>{t.band||"—"}</div>
|
||||
{/* El clic en la fila abre el análisis interno; este
|
||||
enlace lleva al explorador, y por eso corta la
|
||||
propagación: son dos destinos distintos. */}
|
||||
<span onClick={e=>e.stopPropagation()} style={{flexShrink:0}}>
|
||||
<VerEnMempool base={base} tipo="tx" id={t.txid} texto="↗"/>
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
{walletReport?.error&&(
|
||||
<Card glow={C.red}>
|
||||
<div style={{fontSize:"0.65rem",color:C.red,fontFamily:C.mono}}>Error al analizar el wallet: {walletReport.error}</div>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{showLabelModal&&(
|
||||
<Card glow={C.purple}>
|
||||
<div style={{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:10}}>
|
||||
<div style={{fontSize:"0.65rem",color:C.purple,fontFamily:C.mono,fontWeight:700}}>IMPORTAR ETIQUETAS BIP-329</div>
|
||||
<button onClick={()=>setShowLabelModal(false)} style={{background:"none",border:"none",color:C.t2,cursor:"pointer",fontSize:"1rem",lineHeight:1}}>×</button>
|
||||
</div>
|
||||
<div style={{fontSize:"0.68rem",color:C.t2,marginBottom:12}}>
|
||||
Exporta tus etiquetas desde Sparrow: <span style={{color:C.t1,fontFamily:C.mono}}>File → Export → Export Labels</span>. El archivo <span style={{color:C.t1,fontFamily:C.mono}}>.jsonl</span> se carga en memoria — no sale del navegador.
|
||||
</div>
|
||||
{labelInfo&&(
|
||||
<div style={{marginBottom:10}}>
|
||||
<div style={{fontSize:"0.65rem",color:C.green,fontFamily:C.mono,marginBottom:8}}>✓ {labelInfo.file} — {labelInfo.count} etiquetas cargadas</div>
|
||||
<div style={{maxHeight:160,overflowY:"auto",display:"flex",flexDirection:"column",gap:3}}>
|
||||
{[...labels.entries()].map(([ref,lbl])=>(
|
||||
<div key={ref} style={{display:"flex",gap:8,padding:"3px 6px",background:C.bgCard,borderRadius:4,alignItems:"baseline"}}>
|
||||
<span style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,flexShrink:0,maxWidth:120,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"}}>{ref.length>20?ref.slice(0,10)+"…"+ref.slice(-8):ref}</span>
|
||||
<span style={{fontSize:"0.65rem",color:C.t1,fontFamily:C.mono}}>{lbl}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<label style={{display:"flex",alignItems:"center",gap:10,padding:"10px 14px",background:C.bgCard,border:`1px dashed ${C.purple}60`,borderRadius:6,cursor:"pointer"}}>
|
||||
<span style={{fontSize:"0.72rem",color:C.purple}}>↑</span>
|
||||
<span style={{fontSize:"0.7rem",color:C.t2}}>Seleccionar archivo .jsonl</span>
|
||||
<input type="file" accept=".jsonl,.json" style={{display:"none"}} onChange={e=>e.target.files[0]&&loadLabels(e.target.files[0])}/>
|
||||
</label>
|
||||
{labels.size>0&&(
|
||||
<button onClick={()=>{setLabels(new Map());setLabelInfo(null);setShowLabelModal(false);}}
|
||||
style={{marginTop:8,padding:"5px 12px",background:"none",border:`1px solid ${C.red}40`,borderRadius:6,color:C.red,fontFamily:C.mono,fontSize:"0.65rem",cursor:"pointer"}}>
|
||||
Borrar etiquetas
|
||||
</button>
|
||||
)}
|
||||
</Card>
|
||||
)}
|
||||
|
||||
<Card>
|
||||
<div style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono,marginBottom:10}}>ANALIZAR TRANSACCIÓN — introduce un txid</div>
|
||||
<div style={{display:"flex",gap:8}}>
|
||||
<input value={query} onChange={e=>setQuery(e.target.value)} onKeyDown={e=>e.key==="Enter"&&analyze()}
|
||||
placeholder="txid (64 caracteres hex)"
|
||||
style={{flex:1,background:C.bg,border:`1px solid ${C.borderBright}`,borderRadius:6,padding:"11px 14px",color:C.t1,fontFamily:C.mono,fontSize:"0.78rem",outline:"none"}}
|
||||
onFocus={e=>e.target.style.borderColor=C.purple} onBlur={e=>e.target.style.borderColor=C.borderBright}
|
||||
/>
|
||||
<button onClick={()=>analyze()} style={{padding:"11px 20px",background:C.purpleMuted,border:`1px solid ${C.purple}40`,borderRadius:6,color:C.purple,fontFamily:C.mono,fontSize:"0.75rem",cursor:"pointer",fontWeight:700}}>
|
||||
{loading?"···":"ANALIZAR"}
|
||||
</button>
|
||||
</div>
|
||||
{err&&<div style={{marginTop:10,padding:"8px 12px",background:C.redMuted,border:`1px solid ${C.red}30`,borderRadius:6,color:C.red,fontFamily:C.mono,fontSize:"0.72rem"}}>{err}</div>}
|
||||
{!base&&!tx&&!loading&&(
|
||||
<div style={{marginTop:10,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"}}>
|
||||
<button onClick={()=>{setQuery(MOCK_TX.txid);analyze(MOCK_TX.txid);}} style={{padding:"9px 14px",background:"none",border:`1px solid ${C.amber}70`,borderRadius:6,color:C.amber,fontFamily:C.mono,fontSize:"0.7rem",cursor:"pointer"}}>Probar con una transacción de ejemplo</button>
|
||||
<span style={{fontSize:"0.64rem",color:C.t2}}>Sin nodo no se puede consultar una transacción real.</span>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
|
||||
{loading&&<Spinner/>}
|
||||
{!base&&tx&&!loading&&<EjemploAviso texto="Sin nodo: esta es una transacción de ejemplo, no la que hayas escrito."/>}
|
||||
|
||||
{tx&&analysis&&(
|
||||
<div style={{display:"flex",flexDirection:"column",gap:10}}>
|
||||
<Card glow={C.purple}>
|
||||
<div style={{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:12}}>
|
||||
<div>
|
||||
<div style={{display:"flex",alignItems:"center",gap:8,marginBottom:4,flexWrap:"wrap"}}>
|
||||
<span style={{fontSize:"0.6rem",color:C.t2,fontFamily:C.mono}}>TRANSACCIÓN ANALIZADA</span>
|
||||
<VerEnMempool base={base} tipo="tx" id={tx.txid}/>
|
||||
</div>
|
||||
<div style={{fontSize:"0.68rem",fontFamily:C.mono,color:C.blue,wordBreak:"break-all"}}>{tx.txid}</div>
|
||||
{labels&&labels.get(tx.txid)&&(
|
||||
<div style={{marginTop:8,display:"flex",alignItems:"center",gap:8,padding:"6px 10px",background:C.purpleMuted,border:`1px solid ${C.purple}60`,borderRadius:6}}>
|
||||
<span style={{fontSize:"0.7rem"}}>🏷</span>
|
||||
<span style={{fontSize:"0.75rem",color:C.purple,fontFamily:C.mono,fontWeight:600}}>{labels.get(tx.txid)}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{tx.status?.confirmed?<Badge color={C.green}>#{fmt.num(tx.status.block_height)}</Badge>:<Badge color={C.amber}>MEMPOOL</Badge>}
|
||||
</div>
|
||||
<div style={{display:"grid",gridTemplateColumns:"repeat(auto-fill,minmax(120px,1fr))",gap:10,paddingTop:10,borderTop:`1px solid ${C.border}`}}>
|
||||
<Tag label="Comisión" value={fmtFee(comisionDe(tx))} color={C.amber}/>
|
||||
<Tag label="Tarifa" value={fmtTasa(comisionDe(tx))} color={C.amber}/>
|
||||
{comisionDe(tx).fee===0&&<div style={{gridColumn:"1 / -1",fontSize:"0.64rem",color:C.t2,lineHeight:1.5}}>Comisión 0: no es un dato que falte. Las primeras transacciones de Bitcoin solían no pagar comisión.</div>}
|
||||
<Tag label="vSize" value={tx.weight?`${Math.ceil(tx.weight/4)} vB`:"-"}/>
|
||||
<Tag label="Entradas" value={tx.vin?.length||0} color={C.t1}/>
|
||||
<Tag label="Salidas" value={tx.vout?.length||0} color={C.t1}/>
|
||||
<Tag label="Fecha" value={tx.status?.block_time?fmt.date(tx.status.block_time):"-"}/>
|
||||
</div>
|
||||
{walletAddrs&&tx.vout&&tx.vout.some(o=>myAddr(o.scriptpubkey_address))&&(
|
||||
<div style={{marginTop:10,paddingTop:10,borderTop:`1px solid ${C.border}`}}>
|
||||
<div style={{fontSize:"0.6rem",color:C.t2,fontFamily:C.mono,marginBottom:6}}>SALIDAS QUE SON DE TU WALLET</div>
|
||||
<div style={{display:"flex",flexDirection:"column",gap:4}}>
|
||||
{tx.vout.map((o,i)=>{
|
||||
const mine = myAddr(o.scriptpubkey_address);
|
||||
if (!mine) return null;
|
||||
const lbl = labels?.get(o.scriptpubkey_address);
|
||||
return (
|
||||
<div key={i} style={{display:"flex",alignItems:"center",gap:8,padding:"5px 8px",background:mine==="cambio"?C.amberMuted:C.greenMuted,border:`1px solid ${mine==="cambio"?C.amber:C.green}40`,borderRadius:5}}>
|
||||
<span style={{fontSize:"0.65rem",color:mine==="cambio"?C.amber:C.green,fontFamily:C.mono,fontWeight:600}}>{mine==="cambio"?"↺ cambio":"↓ recepción"}</span>
|
||||
<span style={{fontSize:"0.68rem",color:C.t1,fontFamily:C.mono}}>{fmt.sats(o.value)}</span>
|
||||
{lbl&&<span style={{fontSize:"0.62rem",color:C.t2,fontFamily:C.mono}}>· {lbl}</span>}
|
||||
<span style={{fontSize:"0.58rem",color:C.t2,fontFamily:C.mono,marginLeft:"auto"}}>{o.scriptpubkey_address?.slice(0,12)}…</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
<PrivacyLab analysis={analysis} tx={tx} labels={labels} myAddr={myAddr}/>
|
||||
<RastroProcedencia tx={tx} base={base} onAuditar={q=>{setQuery(q);analyze(q);try{window.scrollTo({top:0});}catch{}}}/>
|
||||
<TxVerifier base={base}/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user