@origintrail-official/dkg-node-ui 10.0.23 → 10.0.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +4 -0
  2. package/dist-ui/assets/ActivityFeed-vyl2XdLo.js +99 -0
  3. package/dist-ui/assets/{AgentHub-DyF5Pa70.js → AgentHub-CYfAoOWF.js} +1 -1
  4. package/dist-ui/assets/AgentProfilePage-BjQm0je4.js +1 -0
  5. package/dist-ui/assets/{ApproveWalletsModal-Dd_tHLRP.js → ApproveWalletsModal-CzWJ4KyU.js} +1 -1
  6. package/dist-ui/assets/{ContextGraphPrimitives-BXormriD.js → ContextGraphPrimitives-ecppTns4.js} +1 -1
  7. package/dist-ui/assets/{ConvictionDetailView-BsPTd17P.js → ConvictionDetailView-CuLUhbzR.js} +2 -2
  8. package/dist-ui/assets/MemoryLayerView-Dymg_Zf_.js +2 -0
  9. package/dist-ui/assets/MemoryReadStatus-D4HXCImC.js +1 -0
  10. package/dist-ui/assets/MemoryStackView-Bq8Fbh5W.js +1 -0
  11. package/dist-ui/assets/{Network-BKvJttOu.js → Network-F76S9_1V.js} +1 -1
  12. package/dist-ui/assets/{OnChainProvenanceCard-BV9-G1cT.js → OnChainProvenanceCard-CCwK3sRG.js} +1 -1
  13. package/dist-ui/assets/{Operations-LAhUQsnj.js → Operations-aVCBUh8u.js} +1 -1
  14. package/dist-ui/assets/ProjectView-Cb1PQ-jm.js +290 -0
  15. package/dist-ui/assets/{PublishingConviction-CF6352oT.js → PublishingConviction-BnAJjHL8.js} +2 -2
  16. package/dist-ui/assets/{Settings-runaZqPv.js → Settings-rEyPw1oS.js} +1 -1
  17. package/dist-ui/assets/{browserWalletTransaction-CBgx0i4w.js → browserWalletTransaction-BJBFRjXx.js} +3 -3
  18. package/dist-ui/assets/{ccip-BM07w5uU.js → ccip-DYOqJfs7.js} +1 -1
  19. package/dist-ui/assets/index-CAdbSAQK.css +1 -0
  20. package/dist-ui/assets/index-HEpqHVfE.js +1143 -0
  21. package/dist-ui/assets/index-_vQ99L0s.js +192 -0
  22. package/dist-ui/assets/{jsonld-32FQRO67-DBZOBQji.js → jsonld-32FQRO67-DVqZhSL_.js} +2 -2
  23. package/dist-ui/assets/{jsonld-DOX7dKpf.js → jsonld-Dpm03cay.js} +1 -1
  24. package/dist-ui/assets/renderer-3d-IRPVRQWX-DjW_h88e.js +5126 -0
  25. package/dist-ui/assets/{shikiHighlighter-CzU2U2Tx.js → shikiHighlighter-DL7LOds2.js} +1 -1
  26. package/dist-ui/assets/truncate-BWdqLeqV.js +22 -0
  27. package/dist-ui/assets/{useEntityOnChainReceipt-BvWQ6qdT.js → useEntityOnChainReceipt-B_uLyqZc.js} +5 -5
  28. package/dist-ui/index.html +2 -2
  29. package/package.json +4 -4
  30. package/dist-ui/assets/3d-force-graph-DbVwxMKf.js +0 -1015
  31. package/dist-ui/assets/ActivityFeed-Bfg6fmQQ.js +0 -99
  32. package/dist-ui/assets/AgentProfilePage-BPrSuKjV.js +0 -1
  33. package/dist-ui/assets/MemoryLayerView-CloJeM33.js +0 -2
  34. package/dist-ui/assets/MemoryStackView-BbUJ2uiM.js +0 -1
  35. package/dist-ui/assets/ProjectView-0zCSblAV.js +0 -290
  36. package/dist-ui/assets/index-CfVUpsfM.js +0 -192
  37. package/dist-ui/assets/index-MQh8C4aJ.js +0 -1175
  38. package/dist-ui/assets/index-xKO-U_eV.css +0 -1
  39. package/dist-ui/assets/renderer-3d-2EVDZII7-CVCpAmwB.js +0 -2
  40. package/dist-ui/assets/three.module-BXIk8GZS.js +0 -4112
  41. package/dist-ui/assets/truncate-BaiMkAOo.js +0 -1
  42. package/dist-ui/assets/useProjectActivity-Cxr4QGX1.js +0 -1
package/README.md CHANGED
@@ -49,3 +49,7 @@ pnpm build
49
49
  - `@origintrail-official/dkg-core` - configuration types, event bus integration
50
50
  - `@origintrail-official/dkg-node-store` - the daemon's protocol persistence stores (outbox, sync checkpoints, changelog cursors, KA numbers, chain log and cursors). They used to live here; this package re-exports them unchanged (from its entry point, from `dist/db.js`, and from the former `dist/chain-event-log-store.js`, `dist/chain-cursor-stores.js` and `dist/protocol-outbox-store.js` paths, which are deprecated forwarding modules: first-party code imports node-store directly) and `DashboardDB` still opens `node-ui.db` and owns the schema and every migration
51
51
  - `@origintrail-official/dkg-graph-viz` - interactive RDF graph visualization component
52
+
53
+ ### Unavailable node
54
+
55
+ If both initial status probes fail or time out, the dashboard shows a connection recovery screen and hides operational panels, including node health, balances, graphs and integration readiness. Fallback fixtures are never shown as live state. Check the daemon and use **Retry connection** to reload; detection remains latched for the current page. A `401` response still opens the existing API token prompt rather than declaring the node unavailable.
@@ -0,0 +1,99 @@
1
+ var We=Object.defineProperty;var Ye=(e,t,r)=>t in e?We(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r;var w=(e,t,r)=>Ye(e,typeof t!="symbol"?t+"":t,r);import{aR as Xe,bt as Ce,bg as Ze,G as Ke,bW as Ne,z as Pe,bj as f,R as X,Y as Re,bk as Je,aU as d}from"./index-HEpqHVfE.js";import{u as et,b as tt,r as rt}from"./MemoryReadStatus-D4HXCImC.js";function at(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function ie(e,t,r=""){const o=at(e),a=e==null?void 0:e.length;if(!o||t!==void 0){const i=r&&`"${r}" `,s="",u=o?`length=${a}`:`type=${typeof e}`,p=i+"expected Uint8Array"+s+", got "+u;throw o?new RangeError(p):new TypeError(p)}return e}function me(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function nt(e,t){ie(e,void 0,"digestInto() output");const r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function oe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function ne(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function S(e,t){return e<<32-t|e>>>t}const st=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ot=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function it(e){if(ie(e),st)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=ot[e[r]];return t}function ct(e){if(typeof e!="string")throw new TypeError("string expected");return new Uint8Array(new TextEncoder().encode(e))}function lt(e,t={}){const r=(a,n)=>e(n).update(a).digest(),o=e(void 0);return r.outputLen=o.outputLen,r.blockLen=o.blockLen,r.canXOF=o.canXOF,r.create=a=>e(a),Object.assign(r,t),Object.freeze(r)}const ut=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function pt(e,t,r){return e&t^~e&r}function dt(e,t,r){return e&t^e&r^t&r}class ft{constructor(t,r,o,a){w(this,"blockLen");w(this,"outputLen");w(this,"canXOF",!1);w(this,"padOffset");w(this,"isLE");w(this,"buffer");w(this,"view");w(this,"finished",!1);w(this,"length",0);w(this,"pos",0);w(this,"destroyed",!1);this.blockLen=t,this.outputLen=r,this.padOffset=o,this.isLE=a,this.buffer=new Uint8Array(t),this.view=ne(this.buffer)}update(t){me(this),ie(t);const{view:r,buffer:o,blockLen:a}=this,n=t.length;for(let i=0;i<n;){const s=Math.min(a-this.pos,n-i);if(s===a){const u=ne(t);for(;a<=n-i;i+=a)this.process(u,i);continue}o.set(t.subarray(i,i+s),this.pos),this.pos+=s,i+=s,this.pos===a&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){me(this),nt(t,this),this.finished=!0;const{buffer:r,view:o,blockLen:a,isLE:n}=this;let{pos:i}=this;r[i++]=128,oe(this.buffer.subarray(i)),this.padOffset>a-i&&(this.process(o,0),i=0);for(let l=i;l<a;l++)r[l]=0;o.setBigUint64(a-8,BigInt(this.length*8),n),this.process(o,0);const s=ne(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen must be aligned to 32bit");const p=u/4,h=this.get();if(p>h.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<p;l++)s.setUint32(4*l,h[l],n)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const o=t.slice(0,r);return this.destroy(),o}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:o,length:a,finished:n,destroyed:i,pos:s}=this;return t.destroyed=i,t.finished=n,t.length=a,t.pos=s,a%r&&t.buffer.set(o),t}clone(){return this._cloneInto()}}const $=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ht=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),I=new Uint32Array(64);class mt extends ft{constructor(t){super(64,t,8,!1)}get(){const{A:t,B:r,C:o,D:a,E:n,F:i,G:s,H:u}=this;return[t,r,o,a,n,i,s,u]}set(t,r,o,a,n,i,s,u){this.A=t|0,this.B=r|0,this.C=o|0,this.D=a|0,this.E=n|0,this.F=i|0,this.G=s|0,this.H=u|0}process(t,r){for(let l=0;l<16;l++,r+=4)I[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){const b=I[l-15],g=I[l-2],A=S(b,7)^S(b,18)^b>>>3,v=S(g,17)^S(g,19)^g>>>10;I[l]=v+I[l-7]+A+I[l-16]|0}let{A:o,B:a,C:n,D:i,E:s,F:u,G:p,H:h}=this;for(let l=0;l<64;l++){const b=S(s,6)^S(s,11)^S(s,25),g=h+b+pt(s,u,p)+ht[l]+I[l]|0,v=(S(o,2)^S(o,13)^S(o,22))+dt(o,a,n)|0;h=p,p=u,u=s,s=i+g|0,i=n,n=a,a=o,o=g+v|0}o=o+this.A|0,a=a+this.B|0,n=n+this.C|0,i=i+this.D|0,s=s+this.E|0,u=u+this.F|0,p=p+this.G|0,h=h+this.H|0,this.set(o,a,n,i,s,u,p,h)}roundClean(){oe(I)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),oe(this.buffer)}}class gt extends mt{constructor(){super(32);w(this,"A",$[0]|0);w(this,"B",$[1]|0);w(this,"C",$[2]|0);w(this,"D",$[3]|0);w(this,"E",$[4]|0);w(this,"F",$[5]|0);w(this,"G",$[6]|0);w(this,"H",$[7]|0)}}const bt=lt(()=>new gt,ut(1)),yt=["string","integer","number","boolean","iri"],wt=/^[A-Za-z][A-Za-z0-9_]*$/,vt=/^[+-]?\d+$/,At=/^[+-]?(?:(?:\d+(?:\.\d*)?)|(?:\.\d+))(?:[eE][+-]?\d+)?$/;function F(e){if(e==null||e==="")return[];if(!Array.isArray(e))throw new Error("Query parameters must be an array.");const t=new Set;return e.map((r,o)=>{if(!r||typeof r!="object"||Array.isArray(r))throw new Error(`Query parameter at index ${o} must be an object.`);const a=r,n=typeof a.name=="string"?a.name.trim():"";if(!wt.test(n))throw new Error(`Query parameter at index ${o} has an invalid name: ${n||"<empty>"}.`);if(t.has(n))throw new Error(`Duplicate query parameter: ${n}.`);t.add(n);const i=a.type;if(typeof i!="string"||!yt.includes(i))throw new Error(`Query parameter ${n} has an unsupported type: ${String(i)}.`);const s={name:n,type:i};typeof a.label=="string"&&a.label.trim()&&(s.label=a.label.trim()),typeof a.description=="string"&&a.description.trim()&&(s.description=a.description.trim());let u;if(a.required!==void 0){if(typeof a.required!="boolean")throw new Error(`Query parameter ${n} required must be a boolean.`);u=a.required}const p=a.defaultValue!==void 0;if(p){if(!$e(a.defaultValue))throw new Error(`Query parameter ${n} has an invalid defaultValue.`);Oe(s,a.defaultValue),s.defaultValue=a.defaultValue}if(u===!0&&p)throw new Error(`Required query parameter ${n} cannot declare a defaultValue.`);if(u===!1&&!p)throw new Error(`Optional query parameter ${n} must declare a defaultValue.`);return s})}function lr(e){return e.defaultValue===void 0}function xt(e){return JSON.stringify(F(e))}function Et(e){const t=[];for(const r of Ie(e))t.includes(r.name)||t.push(r.name);return t}function Le(e,t){const r=F(t),o=new Set(r.map(n=>n.name)),a=new Set(Et(e));for(const n of a)if(!o.has(n))throw new Error(`SPARQL template uses undeclared query parameter: ${n}.`);for(const n of r)if(!a.has(n.name))throw new Error(`Query parameter ${n.name} is not used by the SPARQL template.`)}function St(e,t,r){const o=F(t);Le(e,o);const a=new Set(o.map(p=>p.name));for(const p of Object.keys(r))if(!a.has(p))throw new Error(`Unknown query parameter: ${p}.`);const n=new Map;for(const p of o){const h=r[p.name],l=ge(h)?p.defaultValue:h;if(ge(l))throw new Error(`Missing required query parameter: ${p.name}.`);if(!$e(l))throw new Error(`Query parameter ${p.name} must be a string, number, or boolean.`);n.set(p.name,Oe(p,l))}const i=Ie(e);let s="",u=0;for(const p of i)s+=e.slice(u,p.start),s+=n.get(p.name),u=p.end;return s+e.slice(u)}function Oe(e,t){switch(e.type){case"string":return Ce(String(t));case"integer":{const r=String(t).trim();if(!vt.test(r))throw new Error(`Query parameter ${e.name} must be an integer.`);return r}case"number":{const r=String(t).trim();if(!At.test(r))throw new Error(`Query parameter ${e.name} must be a number.`);return r}case"boolean":{if(t===!0||t==="true")return"true";if(t===!1||t==="false")return"false";throw new Error(`Query parameter ${e.name} must be true or false.`)}case"iri":{const r=String(t).trim();if(!Xe(r))throw new Error(`Query parameter ${e.name} must be a safe absolute IRI.`);return`<${r}>`}}}function $e(e){return typeof e=="string"||typeof e=="number"||typeof e=="boolean"}function ge(e){return e==null}function Ie(e){const t=[...e.matchAll(/\{\{([A-Za-z][A-Za-z0-9_]*)\}\}/g)],r=e.replace(/\{\{([A-Za-z][A-Za-z0-9_]*)\}\}/g,n=>"0".repeat(n.length)),o=Ze(r);if(o.status!=="valid")throw new Error("SPARQL template contains invalid lexical syntax.");const a=[];for(const n of t){const i=n.index;if(o.masked[i]===" ")continue;const s=i+n[0].length,u=e[i-1],p=e[s];if(u&&/[A-Za-z0-9_?:.%~-]/.test(u)||p&&/[A-Za-z0-9_?:.%~-]/.test(p))throw new Error(`Query parameter ${n[1]} must occupy a complete SPARQL term position.`);a.push({name:n[1],start:i,end:s})}return a}const Ct=2,ce="__context_graph",ur="ui-saved-queries",pr="Saved queries",x="http://dkg.io/ontology/profile/",be="http://schema.org/",ye="http://www.w3.org/1999/02/22-rdf-syntax-ns#type",Nt="http://www.w3.org/2001/XMLSchema#integer";class R extends Error{constructor(r="Incompatible query-catalog daemon contract. Upgrade the daemon and retry."){super(r);w(this,"code","QUERY_CATALOG_CONTRACT_INCOMPATIBLE");this.name="QueryCatalogContractError"}}function Pt(e,t){if(t===ce)return`did:dkg:context-graph:${e}`;const r=Ne(t);if(!r.valid)throw new Error(`Invalid query-catalog subgraph "${t}": ${r.reason}`);return Pe(e,t)}function Rt(e,t){const r=`did:dkg:context-graph:${e}`;if(t===r)return ce;const o=`${r}/`;if(!t.startsWith(o))throw new Error(`Query-catalog scope graph <${t}> is outside context graph "${e}".`);const a=t.slice(o.length),n=Ne(a);if(!n.valid)throw new Error(`Invalid query-catalog scope graph <${t}>: ${n.reason}`);if(Pe(e,a)!==t)throw new Error(`Query-catalog scope graph <${t}> is not a canonical subgraph IRI.`);return a}function dr(e,t={}){return{sparql:St(e.sparql,e.parameters,t),...e.view?{view:e.view}:{},...e.subGraph&&e.subGraph!==ce?{subGraphName:e.subGraph}:{}}}function Lt(e){return Ke.includes(e)?e:void 0}function Ot(e){if(!e||typeof e!="object"||Array.isArray(e))throw new R;const t=e,r=t.capabilities;if(t.schemaVersion!==Ct||(r==null?void 0:r.canonicalItems)!==!0||(r==null?void 0:r.queryParameters)!==!0||(r==null?void 0:r.executionView)!==!0||(r==null?void 0:r.graphScopeIri)!==!0||!Array.isArray(t.items))throw new R;return t.items.map((o,a)=>{if(!o||typeof o!="object"||Array.isArray(o))throw new R(`Invalid query-catalog item at index ${a}.`);const n=o,i=["queryIri","catalogIri","slug","name","sparql","catalogSlug","catalogName","subGraph","scopeGraph"];for(const l of i)if(typeof n[l]!="string")throw new R(`Invalid query-catalog item ${a}: ${l} must be a string.`);if(typeof n.rank!="number"||!Number.isFinite(n.rank)||typeof n.catalogRank!="number"||!Number.isFinite(n.catalogRank))throw new R(`Invalid query-catalog item ${a}: ranks must be finite numbers.`);const s=n.view===void 0?void 0:Lt(String(n.view));if(n.view!==void 0&&s===void 0)throw new R(`Invalid query-catalog item ${a}: unsupported execution view.`);const u=n.scopeGraph,p=typeof t.contextGraphId=="string"?t.contextGraphId:void 0;if(!p)throw new R("Invalid query-catalog response: contextGraphId must be a string.");let h;try{h=Rt(p,u)}catch(l){throw new R(`Invalid query-catalog item ${a}: ${l instanceof Error?l.message:String(l)}`)}if(h!==n.subGraph)throw new R(`Invalid query-catalog item ${a}: scopeGraph and subGraph do not match.`);return{queryIri:n.queryIri,catalogIri:n.catalogIri,slug:n.slug,name:n.name,...typeof n.description=="string"?{description:n.description}:{},sparql:n.sparql,...typeof n.resultColumn=="string"?{resultColumn:n.resultColumn}:{},rank:n.rank,catalogSlug:n.catalogSlug,catalogName:n.catalogName,...typeof n.catalogDescription=="string"?{catalogDescription:n.catalogDescription}:{},catalogRank:n.catalogRank,subGraph:n.subGraph,scopeGraph:u,parameters:F(n.parameters),...s?{view:s}:{}}})}function $t(e){const t=new Map;for(const r of e){const o=`${r.subGraph}|${r.catalogSlug}`,a=t.get(o);if(a){if(a.name!==r.catalogName||a.description!==r.catalogDescription||a.rank!==r.catalogRank)throw new Error(`Query catalog ${r.catalogSlug} has conflicting metadata.`);a.queries.push(r);continue}t.set(o,{slug:r.catalogSlug,subGraph:r.subGraph,name:r.catalogName,description:r.catalogDescription,rank:r.catalogRank,queries:[r]})}return[...t.values()].map(r=>({...r,queries:[...r.queries].sort((o,a)=>o.rank-a.rank||o.name.localeCompare(a.name))})).sort((r,o)=>r.subGraph.localeCompare(o.subGraph)||r.rank-o.rank||r.name.localeCompare(o.name))}function It(e){return e.trim().toLowerCase().normalize("NFKD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").slice(0,48)||"saved-query"}function we(e,t,r){return`urn:dkg:profile:${encodeURIComponent(e)}:${t}:${encodeURIComponent(r)}`}function Tt(e){return it(bt(ct(e)))}function C(e){return JSON.stringify(e)}function ve(e){return`"${e}"^^<${Nt}>`}function fr(e){const t=F(e.parameters),r=JSON.stringify({subGraph:e.subGraph,catalogSlug:e.catalogSlug,name:e.name,description:e.description,sparql:e.sparql,resultColumn:e.resultColumn,rank:e.rank,parameters:t,view:e.view}),o=`${It(e.name)}-${Tt(r)}`,a=we(e.contextGraphId,"catalog",e.catalogSlug),n=we(e.contextGraphId,"query",o),i=Pt(e.contextGraphId,e.subGraph);Le(e.sparql,t);const s=[{subject:a,predicate:ye,object:`${x}QueryCatalog`,graph:""},{subject:a,predicate:`${x}scopeGraph`,object:i,graph:""},{subject:a,predicate:`${x}forSubGraph`,object:C(e.subGraph),graph:""},{subject:a,predicate:`${x}displayName`,object:C(e.catalogName),graph:""},{subject:a,predicate:`${x}rank`,object:ve(e.catalogRank),graph:""},{subject:n,predicate:ye,object:`${x}SavedQuery`,graph:""},{subject:n,predicate:`${x}scopeGraph`,object:i,graph:""},{subject:n,predicate:`${x}forSubGraph`,object:C(e.subGraph),graph:""},{subject:n,predicate:`${x}inCatalog`,object:a,graph:""},{subject:n,predicate:`${x}displayName`,object:C(e.name),graph:""},{subject:n,predicate:`${x}sparqlQuery`,object:C(e.sparql),graph:""},{subject:n,predicate:`${x}rank`,object:ve(e.rank),graph:""}];return e.catalogDescription&&s.push({subject:a,predicate:`${be}description`,object:C(e.catalogDescription),graph:""}),e.description&&s.push({subject:n,predicate:`${be}description`,object:C(e.description),graph:""}),e.resultColumn&&s.push({subject:n,predicate:`${x}resultColumn`,object:C(e.resultColumn),graph:""}),t.length>0&&s.push({subject:n,predicate:`${x}queryParameters`,object:C(xt(t)),graph:""}),e.view&&s.push({subject:n,predicate:`${x}executionView`,object:C(e.view),graph:""}),{savedQuery:{queryIri:n,catalogIri:a,slug:o,name:e.name,description:e.description,sparql:e.sparql,resultColumn:e.resultColumn,rank:e.rank,catalogSlug:e.catalogSlug,catalogName:e.catalogName,catalogDescription:e.catalogDescription,catalogRank:e.catalogRank,subGraph:e.subGraph,scopeGraph:i,parameters:t,view:e.view,queryUri:n,catalogUri:a},quads:s}}const kt=new Set(["meta"]),Te="__root__";function hr(e){return!kt.has(e.name)}function G(e){const t=`did:dkg:context-graph:${e}/meta`;return`FILTER(strstarts(str(?g), ${Ce(t)}))`}async function H(e,t){var o;const r=await Re(e,{contextGraphId:t});return((o=r==null?void 0:r.result)==null?void 0:o.bindings)??[]}async function jt(e){const t=await Je(e);return Ot(t)}const N={displayName:"Project",primaryColor:"#a855f7",accentColor:"#22c55e"},Ae=e=>({slug:e,displayName:e,icon:"•",color:"#64748b",rank:99}),_t={slug:Te,displayName:"Root",description:"Entities not in any subgraph (Context Graph root)",icon:"⊘",rank:99},xe=e=>({typeIri:e,label:e.split(/[/#]/).pop()||e,color:"#64748b"}),M="http://dkg.io/ontology/profile/";function ke(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="object"&&"value"in e){const t=e.value;return t==null?"":String(t)}return String(e)}function m(e){const t=ke(e);if(!t)return"";const r=t.match(/^"((?:[^"\\]|\\.)*)"(?:@[\w-]+|\^\^<[^>]+>)?$/);return r?r[1].replace(/\\"/g,'"').replace(/\\n/g,`
2
+ `).replace(/\\\\/g,"\\"):t}function Gt(e){const t=m(e),r=parseInt(t,10);return Number.isFinite(r)?r:0}function Ut(e){return`PREFIX prof: <${M}>
3
+ PREFIX schema: <http://schema.org/>
4
+ SELECT ?profile ?name ?description ?primary ?accent
5
+ WHERE {
6
+ GRAPH ?g {
7
+ ?profile a prof:Profile .
8
+ OPTIONAL { ?profile prof:displayName ?name }
9
+ OPTIONAL { ?profile schema:description ?description }
10
+ OPTIONAL { ?profile prof:primaryColor ?primary }
11
+ OPTIONAL { ?profile prof:accentColor ?accent }
12
+ }
13
+ ${G(e)}
14
+ } LIMIT 1`}function Qt(e){return`PREFIX prof: <${M}>
15
+ PREFIX schema: <http://schema.org/>
16
+ SELECT ?slug ?displayName ?description ?icon ?color ?rank ?timelinePredicate ?sourceAssertion
17
+ WHERE {
18
+ GRAPH ?g {
19
+ ?b a prof:SubGraphBinding ;
20
+ prof:forSubGraph ?slug .
21
+ OPTIONAL { ?b prof:displayName ?displayName }
22
+ OPTIONAL { ?b schema:description ?description }
23
+ OPTIONAL { ?b prof:icon ?icon }
24
+ OPTIONAL { ?b prof:color ?color }
25
+ OPTIONAL { ?b prof:rank ?rank }
26
+ OPTIONAL { ?b prof:timelinePredicate ?timelinePredicate }
27
+ OPTIONAL { ?b prof:sourceAssertion ?sourceAssertion }
28
+ }
29
+ ${G(e)}
30
+ }`}function qt(e){return`PREFIX prof: <${M}>
31
+ SELECT ?chip ?subGraph ?type ?predicate ?label
32
+ (GROUP_CONCAT(DISTINCT ?v; separator="|") AS ?values)
33
+ WHERE {
34
+ GRAPH ?g {
35
+ ?chip a prof:FilterChip ;
36
+ prof:forSubGraph ?subGraph ;
37
+ prof:forType ?type ;
38
+ prof:onPredicate ?predicate ;
39
+ prof:chipValue ?v .
40
+ OPTIONAL { ?chip prof:label ?label }
41
+ }
42
+ ${G(e)}
43
+ }
44
+ GROUP BY ?chip ?subGraph ?type ?predicate ?label`}function Ht(e){const t=e.map(s=>s.catalogIri?s:{...s,catalogSlug:`default:${s.subGraph}`}),r=t.map(s=>({slug:s.slug,subGraph:s.subGraph,catalogSlug:s.catalogSlug,catalogName:s.catalogName,catalogDescription:s.catalogDescription,catalogRank:s.catalogRank,name:s.name,description:s.description,sparql:s.sparql,resultColumn:s.resultColumn??"",rank:s.rank,view:s.view,parameters:s.parameters})),o=new Map(t.map((s,u)=>[s.queryIri,r[u]])),a=$t(t).map(s=>({slug:s.slug,subGraph:s.subGraph,name:s.name,description:s.description,rank:s.rank,queries:s.queries.map(u=>o.get(u.queryIri)).filter(u=>!!u)})),n=new Map,i=new Map;for(const s of a){const u=n.get(s.subGraph)??[];u.push(s),n.set(s.subGraph,u);const p=i.get(s.subGraph)??[];p.push(...s.queries),i.set(s.subGraph,p)}return{queryCatalogs:a,savedQueries:r,catalogsBySubGraph:n,queriesBySubGraph:i}}function Ft(e){return`PREFIX prof: <${M}>
45
+ SELECT ?type ?label ?icon ?color ?detailHint
46
+ ?promoteLabel ?promoteHint ?publishLabel ?publishHint
47
+ WHERE {
48
+ GRAPH ?g {
49
+ ?b a prof:EntityTypeBinding ;
50
+ prof:forType ?type .
51
+ OPTIONAL { ?b prof:label ?label }
52
+ OPTIONAL { ?b prof:icon ?icon }
53
+ OPTIONAL { ?b prof:color ?color }
54
+ OPTIONAL { ?b prof:detailHint ?detailHint }
55
+ OPTIONAL { ?b prof:promoteLabel ?promoteLabel }
56
+ OPTIONAL { ?b prof:promoteHint ?promoteHint }
57
+ OPTIONAL { ?b prof:publishLabel ?publishLabel }
58
+ OPTIONAL { ?b prof:publishHint ?publishHint }
59
+ }
60
+ ${G(e)}
61
+ }`}function Mt(e){return`PREFIX prof: <${M}>
62
+ PREFIX schema: <http://schema.org/>
63
+ SELECT ?view ?name ?description ?nodeSize
64
+ (GROUP_CONCAT(DISTINCT ?incType; separator="|") AS ?includeTypes)
65
+ (GROUP_CONCAT(DISTINCT ?empPred; separator="|") AS ?emphasizePredicates)
66
+ WHERE {
67
+ GRAPH ?g {
68
+ ?view a prof:ViewConfig .
69
+ OPTIONAL { ?view prof:displayName ?name }
70
+ OPTIONAL { ?view schema:description ?description }
71
+ OPTIONAL { ?view prof:nodeSize ?nodeSize }
72
+ OPTIONAL { ?view prof:includeType ?incType }
73
+ OPTIONAL { ?view prof:emphasizePredicate ?empPred }
74
+ }
75
+ ${G(e)}
76
+ }
77
+ GROUP BY ?view ?name ?description ?nodeSize`}function T(e){const t=ke(e);if(!t)return"";const r=t.trim();return r.startsWith("<")&&r.endsWith(">")?r.slice(1,-1):r}function mr(e){const[t,r]=f.useState(!0),[o,a]=f.useState(),[n,i]=f.useState(N.displayName),[s,u]=f.useState(),[p,h]=f.useState(N.primaryColor),[l,b]=f.useState(N.accentColor),[g,A]=f.useState([]),[v,L]=f.useState([]),[U,B]=f.useState([]),[le,D]=f.useState([]),[V,Q]=f.useState([]),[z,k]=f.useState([]),_=f.useRef(new Map),Z=f.useRef(new Map),K=f.useRef(new Map),J=f.useRef(new Map),ee=f.useRef(new Map),te=f.useRef(new Map),O=f.useRef();f.useEffect(()=>{if(O.current=void 0,i(e??N.displayName),u(void 0),h(N.primaryColor),b(N.accentColor),A([]),L([]),B([]),D([]),Q([]),k([]),_.current=new Map,Z.current=new Map,K.current=new Map,J.current=new Map,ee.current=new Map,te.current=new Map,a(void 0),!e){r(!1);return}let y=!1;return(async()=>{r(!0);try{const[j,Me,Be,De,Ve,re]=await Promise.all([H(Ut(e),e).catch(()=>[]),H(Qt(e),e).catch(()=>[]),H(Ft(e),e).catch(()=>[]),H(Mt(e),e).catch(()=>[]),H(qt(e),e).catch(()=>[]),jt(e).then(c=>({rows:c,error:void 0})).catch(c=>({rows:[],error:c instanceof Error?c.message:String(c)}))]);if(y)return;const ue=e;if(j[0]){const c=j[0];i(m(c.name)||ue),u(m(c.description)||void 0),h(m(c.primary)||N.primaryColor),b(m(c.accent)||N.accentColor)}else i(ue),u(void 0),h(N.primaryColor),b(N.accentColor);const pe=Me.map(c=>({slug:m(c.slug),displayName:m(c.displayName)||m(c.slug),description:m(c.description)||void 0,icon:m(c.icon)||void 0,color:m(c.color)||void 0,rank:Gt(c.rank)||99,timelinePredicate:T(c.timelinePredicate)||void 0,sourceAssertion:m(c.sourceAssertion)||void 0})).filter(c=>c.slug).sort((c,E)=>c.rank-E.rank);A(pe),Z.current=new Map(pe.map(c=>[c.slug,c]));const de=Be.map(c=>({typeIri:T(c.type),label:m(c.label)||void 0,icon:m(c.icon)||void 0,color:m(c.color)||void 0,detailHint:m(c.detailHint)||void 0,promoteLabel:m(c.promoteLabel)||void 0,promoteHint:m(c.promoteHint)||void 0,publishLabel:m(c.publishLabel)||void 0,publishHint:m(c.publishHint)||void 0})).filter(c=>c.typeIri);L(de),_.current=new Map(de.map(c=>[c.typeIri,c]));const fe=De.map(c=>{const E=T(c.view),Y=E.split(":view:").pop()??E;return{slug:Y,name:m(c.name)||Y,description:m(c.description)||void 0,nodeSize:m(c.nodeSize)||void 0,includeTypes:m(c.includeTypes).split("|").map(q=>T(q.trim())).filter(Boolean),emphasizePredicates:m(c.emphasizePredicates).split("|").map(q=>T(q.trim())).filter(Boolean)}});B(fe),K.current=new Map(fe.map(c=>[c.slug,c]));const he=Ve.map(c=>{const E=T(c.chip),Y=E.split(":chip:").pop()??E,q=m(c.values).split("|").map(ze=>m(ze.trim())).filter(Boolean);return{slug:Y,subGraph:m(c.subGraph),typeIri:T(c.type),predicate:T(c.predicate),label:m(c.label)||"Filter",values:q}}).filter(c=>c.subGraph&&c.predicate&&c.values.length>0);D(he);const ae=new Map;for(const c of he){const E=ae.get(c.subGraph)??[];E.push(c),ae.set(c.subGraph,E)}J.current=ae;const W=Ht(re.rows);Q(W.queryCatalogs),k(W.savedQueries),ee.current=W.catalogsBySubGraph,te.current=W.queriesBySubGraph,O.current=e,re.error&&a(re.error)}catch(j){y||a((j==null?void 0:j.message)??String(j))}finally{y||r(!1)}})(),()=>{y=!0}},[e]);const Ge=f.useCallback(y=>y===Te?_t:O.current!==e?Ae(y):Z.current.get(y)??Ae(y),[e]),Ue=f.useCallback(y=>O.current===e?_.current.get(y)??xe(y):xe(y),[e]),Qe=f.useCallback(y=>O.current===e?K.current.get(y):void 0,[e]),qe=f.useCallback(y=>O.current===e?J.current.get(y)??[]:[],[e]),He=f.useCallback(y=>O.current===e?ee.current.get(y)??[]:[],[e]),Fe=f.useCallback(y=>O.current===e?te.current.get(y)??[]:[],[e]);return{contextGraphId:e??"",displayName:n,description:s,primaryColor:p,accentColor:l,subGraphs:g,typeBindings:v,views:U,filterChips:le,queryCatalogs:V,savedQueries:z,loading:t,error:o,forSubGraph:Ge,forType:Ue,view:Qe,chipsFor:qe,savedQueryCatalogsFor:He,savedQueriesFor:Fe}}const Bt=X.createContext(null);function Dt(){return f.useContext(Bt)}const Vt="http://dkg.io/ontology/agent/";function zt(e){return`PREFIX ag: <${Vt}>
78
+ PREFIX schema: <http://schema.org/>
79
+ PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
80
+ SELECT ?a ?kind ?name ?label ?fw ?op ?wallet ?peerId ?avatar ?reputation
81
+ WHERE {
82
+ GRAPH ?g {
83
+ ?a a ag:Agent .
84
+ OPTIONAL { ?a a ag:HumanAgent . BIND("human" AS ?kind) }
85
+ OPTIONAL { ?a a ag:AIAgent . BIND("ai" AS ?kindAi) }
86
+ OPTIONAL { ?a schema:name ?name }
87
+ OPTIONAL { ?a rdfs:label ?label }
88
+ OPTIONAL { ?a ag:framework ?fw }
89
+ OPTIONAL { ?a ag:operator ?op }
90
+ OPTIONAL { ?a ag:walletAddress ?wallet }
91
+ OPTIONAL { ?a ag:peerId ?peerId }
92
+ OPTIONAL { ?a ag:avatar ?avatar }
93
+ OPTIONAL { ?a ag:reputation ?reputation }
94
+ }
95
+ ${G(e)}
96
+ }`}function je(e){if(e==null)return"";if(typeof e=="string")return e;if(typeof e=="object"&&"value"in e){const t=e.value;return t==null?"":String(t)}return String(e)}function P(e){const t=je(e);if(!t)return"";const r=t.match(/^"((?:[^"\\]|\\.)*)"(?:@[\w-]+|\^\^<[^>]+>)?$/);return r?r[1].replace(/\\"/g,'"').replace(/\\n/g,`
97
+ `).replace(/\\\\/g,"\\"):t}function Ee(e){const t=je(e);if(!t)return"";const r=t.trim();return r.startsWith("<")&&r.endsWith(">")?r.slice(1,-1):r}function Wt(e){let t=0;for(let a=0;a<e.length;a++)t=t*31+e.charCodeAt(a)|0;return`hsl(${((t%360+360)%360+25)%360}, 55%, 58%)`}function Yt(e){const t=new Map;for(const r of e){const o=Ee(r.a);if(!o)continue;const a=t.get(o),n=P(r.kindAi)==="ai"||P(r.kind)==="ai"?"ai":P(r.kind)==="human"?"human":(a==null?void 0:a.kind)??"ai",i={uri:o,name:P(r.name)||P(r.label)||o.split(":").pop()||o,kind:n,framework:P(r.fw)||(a==null?void 0:a.framework),operatorUri:Ee(r.op)||(a==null?void 0:a.operatorUri),walletAddress:P(r.wallet)||(a==null?void 0:a.walletAddress),peerId:P(r.peerId)||(a==null?void 0:a.peerId),avatar:P(r.avatar)||(a==null?void 0:a.avatar),reputation:P(r.reputation)||(a==null?void 0:a.reputation),color:Wt(o)};i.kind==="human"&&!i.framework&&(i.framework="human"),t.set(o,i)}for(const r of t.values())if(r.operatorUri){const o=t.get(r.operatorUri);o&&(r.operatorName=o.name)}return t}function gr(e){const[t,r]=f.useState(()=>new Map),[o,a]=f.useState(!0),[n,i]=f.useState(),s=f.useRef(new Map);f.useEffect(()=>{if(!e){a(!1);return}let l=!1;return(async()=>{var b;a(!0),i(void 0);try{const g=await Re(zt(e),{contextGraphId:e});if(l)return;const A=((b=g==null?void 0:g.result)==null?void 0:b.bindings)??[],v=Yt(A);r(v),s.current=v}catch(g){l||i((g==null?void 0:g.message)??String(g))}finally{l||a(!1)}})(),()=>{l=!0}},[e]);const u=f.useCallback(l=>s.current.get(l),[]),p=X.useMemo(()=>[...t.values()].sort((l,b)=>l.name.localeCompare(b.name)),[t]),h=f.useCallback(l=>{},[]);return{agents:t,list:p,loading:o,error:n,get:u,openAgent:h}}const Xt=X.createContext(null);function _e(){return f.useContext(Xt)}const Se={"claude-code":"⦿",openclaw:"◈",hermes:"⬡",gemini:"✧",human:"👤"};function Zt(e,t){return e&&Se[e]?Se[e]:t==="human"?"👤":"◉"}function Kt(e){const t=e.trim();if(!t)return"?";const r=t.split(/[\s_-]+/).filter(Boolean);return r.length===1?r[0].slice(0,2).toUpperCase():(r[0][0]+(r[1][0]??"")).toUpperCase()}function Jt(e){const t=e.trim();return t.length<=11?t:`${t.slice(0,6)}…${t.slice(-4)}`}const er=({agent:e,fallbackUri:t,size:r="sm",showOperator:o=!1,onOpenAgent:a,className:n=""})=>{const i=_e();if(!e&&!t)return null;const s=a??(i==null?void 0:i.openAgent),u=(e==null?void 0:e.uri)??t,p=(e==null?void 0:e.name)??(t?Jt(t.split(":").pop()??t):"unknown"),h=(e==null?void 0:e.kind)??"ai",l=e==null?void 0:e.framework,b=Zt(l,h),g=(e==null?void 0:e.color)??"hsl(0, 0%, 55%)",A=[p,l?`framework: ${l}`:null,e!=null&&e.operatorName?`operator: ${e.operatorName}`:null,e!=null&&e.walletAddress?`wallet: ${e.walletAddress}`:null,e!=null&&e.peerId?`peer: ${e.peerId.slice(0,20)}…`:null,e!=null&&e.reputation?`— ${e.reputation}`:null,u].filter(Boolean).join(`
98
+ `),v=s?()=>s(u):void 0,L=!!v;return d.jsxs("span",{className:`v10-agent-chip v10-agent-chip-${r}${L?" interactive":""} ${n}`,style:{"--agent-color":g},onClick:v?U=>{U.stopPropagation(),v()}:void 0,title:A,role:L?"button":void 0,tabIndex:L?0:void 0,children:[d.jsxs("span",{className:"v10-agent-chip-avatar",style:{background:g},children:[d.jsx("span",{className:"v10-agent-chip-initials",children:Kt(p)}),d.jsx("span",{className:"v10-agent-chip-glyph",title:l??h,children:b})]}),d.jsxs("span",{className:"v10-agent-chip-body",children:[d.jsx("span",{className:"v10-agent-chip-name",children:p}),r==="lg"&&((e==null?void 0:e.operatorName)||l)&&d.jsxs("span",{className:"v10-agent-chip-sub",children:[l&&h==="ai"&&d.jsx("span",{className:"v10-agent-chip-fw",children:l}),(e==null?void 0:e.operatorName)&&h==="ai"&&d.jsxs(d.Fragment,{children:[l&&d.jsx("span",{className:"v10-agent-chip-sep",children:"·"}),d.jsxs("span",{className:"v10-agent-chip-op",children:["driven by ",e.operatorName]})]}),h==="human"&&d.jsx("span",{className:"v10-agent-chip-fw",children:"human"})]}),r==="md"&&o&&(e==null?void 0:e.operatorName)&&h==="ai"&&d.jsx("span",{className:"v10-agent-chip-sub",children:d.jsxs("span",{className:"v10-agent-chip-op",children:["· ",e.operatorName]})})]})]})},se={working:"#64748b",shared:"#f59e0b",verified:"#22c55e"},tr={working:"◇",shared:"◈",verified:"◉"},rr=200,br=({entities:e,agentUri:t,typeIri:r,subGraph:o,limit:a,includeUndated:n=!0,swmEvents:i,lifecycleEvents:s,lifecycleError:u,title:p,onSelectEntity:h,onOpenAgent:l,emptyHint:b,className:g=""})=>{const{items:A,hasMore:v}=et(e,{agentUri:t,typeIri:r,subGraph:o,limit:a,includeUndated:n,swmEvents:i,lifecycleEvents:s}),L=X.useMemo(()=>tt(A),[A]),U=_e(),B=Dt(),D=v?`${a??rr}+`:String(A.length),V=u!=null&&A.length===0,Q=p?d.jsxs("div",{className:"v10-activity-feed-title",children:[d.jsx("span",{className:"v10-activity-feed-title-label",children:p}),d.jsx("span",{className:"v10-activity-feed-title-count","data-state":V?"error":void 0,children:V?"—":D})]}):null,z=u?d.jsx("div",{className:"v10-activity-feed-error",role:"status","aria-live":"polite",title:u,children:"Couldn't load recent activity."}):null;return A.length===0?d.jsxs("div",{className:`v10-activity-feed v10-activity-feed-empty ${g}`,children:[Q,z??d.jsx("div",{className:"v10-activity-feed-empty-hint",children:b??"No activity with a timestamp yet."})]}):d.jsxs("div",{className:`v10-activity-feed ${g}`,children:[Q,z,L.map(k=>d.jsxs("div",{className:"v10-activity-feed-bucket",children:[d.jsxs("div",{className:"v10-activity-feed-bucket-head",children:[d.jsx("span",{className:"v10-activity-feed-bucket-label",children:k.label}),d.jsx("span",{className:"v10-activity-feed-bucket-count",children:k.items.length})]}),d.jsx("div",{className:"v10-activity-feed-items",children:k.items.map(_=>d.jsx(ar,{item:_,agents:U,profile:B,onSelectEntity:h,onOpenAgent:l},_.id))})]},k.key))]})};function ar({item:e,agents:t,profile:r,onSelectEntity:o,onOpenAgent:a}){const n=e.authorUri?t==null?void 0:t.get(e.authorUri):null,i=e.event==="typed",s=i&&e.kindUri?r==null?void 0:r.forType(e.kindUri):null,u=e.event==="added"?"Added":e.event==="promoted"?e.entityCount!=null&&e.entityCount>0?`Promoted to SWM · ${e.entityCount} ${e.entityCount===1?"entity":"entities"}`:"Promoted to SWM":e.event==="published"?"Published to VM":(s==null?void 0:s.label)??(e.kindUri?e.kindUri.split(/[#/]/).pop():null)??"Entity",p=e.event==="added"?"+":e.event==="promoted"?"⇡":e.event==="published"?"◉":(s==null?void 0:s.icon)??"◆",h=e.event==="promoted"?se.shared:e.event==="published"?se.verified:e.event==="added"?"#64748b":(s==null?void 0:s.color)??"#a855f7",l=se[e.layer],b=i?nr(e.entity):null,g=(()=>{const v=[];return e.event!=="typed"&&v.push(u),v.push(e.entity.label),e.at&&v.push(e.at.toISOString()),v.join(`
99
+ `)})(),A=d.jsxs(d.Fragment,{children:[d.jsx("span",{className:"v10-activity-feed-layer",style:{color:l},title:`${e.layer} memory`,children:tr[e.layer]}),d.jsxs("span",{className:"v10-activity-feed-type",style:{"--type-color":h},children:[d.jsx("span",{className:"v10-activity-feed-type-icon",children:p}),d.jsx("span",{className:"v10-activity-feed-type-label",children:u})]}),d.jsx("span",{className:"v10-activity-feed-title-text",children:e.entity.label}),b&&d.jsx("span",{className:`v10-activity-feed-status status-${sr(b)}`,children:b}),(n||e.authorUri)&&d.jsx("span",{className:"v10-activity-feed-author",children:d.jsx(er,{agent:n??void 0,fallbackUri:e.authorUri??void 0,size:"sm",onOpenAgent:a})}),d.jsx("span",{className:"v10-activity-feed-time",title:e.at?e.at.toLocaleString():"no timestamp",children:rt(e.at)})]});return e.clickable?d.jsx("button",{type:"button",className:"v10-activity-feed-row",onClick:()=>o(e.entity.uri),title:g,children:A}):d.jsx("div",{className:"v10-activity-feed-row v10-activity-feed-row-static",title:g,"aria-disabled":"true",children:A})}function nr(e){var r;const t=["http://dkg.io/ontology/decisions/status","http://dkg.io/ontology/tasks/status","http://dkg.io/ontology/github/state"];for(const o of t){const a=(r=e.properties.get(o))==null?void 0:r[0];if(a)return a}return null}function sr(e){switch(e){case"accepted":case"done":case"merged":return"good";case"proposed":case"in_progress":case"open":return"warn";case"rejected":case"superseded":case"blocked":case"cancelled":return"bad";default:return"neutral"}}export{br as A,ce as C,Bt as P,Te as R,pr as U,er as a,Xt as b,ur as c,fr as d,hr as e,_e as f,mr as g,Dt as h,lr as i,dr as p,It as q,gr as u};
@@ -1 +1 @@
1
- import{aO as e,j as t}from"./index-MQh8C4aJ.js";function n(){return e.jsxs("div",{className:"page-section",style:{display:"flex",flexDirection:"column",height:"100%",padding:0},children:[e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"Agent Hub"}),e.jsx("p",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4},children:"Bring your own agent into the node. OpenClaw chat, network peers, and integrated-agent session history live here."})]}),e.jsx("div",{style:{flex:1,minHeight:0,border:"1px solid var(--border)",borderRadius:12,overflow:"hidden",background:"var(--bg)"},children:e.jsx(t,{})})]})}export{n as AgentHubPage};
1
+ import{aU as e,j as t}from"./index-HEpqHVfE.js";function n(){return e.jsxs("div",{className:"page-section",style:{display:"flex",flexDirection:"column",height:"100%",padding:0},children:[e.jsxs("div",{style:{marginBottom:20},children:[e.jsx("h1",{className:"page-title",style:{marginBottom:0},children:"Agent Hub"}),e.jsx("p",{style:{fontSize:12,color:"var(--text-muted)",marginTop:4},children:"Bring your own agent into the node. OpenClaw chat, network peers, and integrated-agent session history live here."})]}),e.jsx("div",{style:{flex:1,minHeight:0,border:"1px solid var(--border)",borderRadius:12,overflow:"hidden",background:"var(--bg)"},children:e.jsx(t,{})})]})}export{n as AgentHubPage};
@@ -0,0 +1 @@
1
+ import{bj as x,aU as e,bL as P,bT as A,bS as C,R as y}from"./index-HEpqHVfE.js";import{f as T,h as R,a as k,A as E,g as M,u as S,P as $,b as D}from"./ActivityFeed-vyl2XdLo.js";import{M as B}from"./MemoryReadStatus-D4HXCImC.js";const F="http://www.w3.org/ns/prov#wasAttributedTo",w=[{iri:"http://dkg.io/ontology/decisions/Decision",label:"Decisions"},{iri:"http://dkg.io/ontology/tasks/Task",label:"Tasks"},{iri:"http://dkg.io/ontology/github/PullRequest",label:"Pull Requests"},{iri:"http://dkg.io/ontology/github/Issue",label:"Issues"},{iri:"http://dkg.io/ontology/github/Commit",label:"Commits"}],L=({agentUri:t,entityList:u,partial:n=!1,onSelectEntity:m,onOpenAgent:c,onBack:d})=>{const i=T(),p=R(),s=(i==null?void 0:i.get(t))??null,g=x.useMemo(()=>{const a=new Map;for(const l of u){if(!l.connections.some(j=>j.predicate===F&&j.targetUri===t))continue;const f=w.find(j=>l.types.includes(j.iri));if(!f)continue;const N=a.get(f.iri)??[];N.push(l),a.set(f.iri,N)}return a},[u,t]),v=x.useMemo(()=>{let a=0;for(const l of g.values())a+=l.length;return a},[g]),b=s!=null&&s.operatorUri?(i==null?void 0:i.get(s.operatorUri))??null:null,[h,r]=x.useState(null);return e.jsxs("div",{className:"v10-agent-profile",children:[e.jsxs("div",{className:"v10-agent-profile-header",children:[e.jsx("button",{type:"button",className:"v10-ka-back",onClick:d,children:"← Back"}),e.jsxs("div",{className:"v10-agent-profile-head",children:[e.jsx(k,{agent:s??void 0,fallbackUri:t,size:"lg",showOperator:!0}),(s==null?void 0:s.reputation)&&e.jsx("div",{className:"v10-agent-profile-reputation",children:s.reputation})]}),e.jsxs("div",{className:"v10-agent-profile-meta",children:[(s==null?void 0:s.walletAddress)&&e.jsxs("div",{className:"v10-agent-profile-meta-row",children:[e.jsx("span",{className:"v10-agent-profile-meta-lbl",children:"Wallet"}),e.jsxs("span",{className:"v10-agent-profile-meta-val mono v10-agent-profile-wallet",title:s.walletAddress,children:[s.walletAddress,e.jsx("button",{type:"button",className:"v10-agent-profile-copy",onClick:a=>{var l;a.stopPropagation(),(l=navigator.clipboard)==null||l.writeText(s.walletAddress).catch(()=>{})},title:"Copy wallet address",children:"⎘"})]})]}),e.jsxs("div",{className:"v10-agent-profile-meta-row",children:[e.jsx("span",{className:"v10-agent-profile-meta-lbl",children:"URI"}),e.jsx("span",{className:"v10-agent-profile-meta-val mono",children:t})]}),(s==null?void 0:s.peerId)&&e.jsxs("div",{className:"v10-agent-profile-meta-row",children:[e.jsx("span",{className:"v10-agent-profile-meta-lbl",children:"Peer ID"}),e.jsx("span",{className:"v10-agent-profile-meta-val mono",children:s.peerId})]}),b&&e.jsxs("div",{className:"v10-agent-profile-meta-row",children:[e.jsx("span",{className:"v10-agent-profile-meta-lbl",children:"Driven by"}),e.jsx("span",{className:"v10-agent-profile-meta-val",children:e.jsx(k,{agent:b,size:"sm",onOpenAgent:c})})]}),(s==null?void 0:s.framework)&&e.jsxs("div",{className:"v10-agent-profile-meta-row",children:[e.jsx("span",{className:"v10-agent-profile-meta-lbl",children:"Framework"}),e.jsx("span",{className:"v10-agent-profile-meta-val mono",children:s.framework})]})]})]}),e.jsxs("div",{className:"v10-agent-profile-stats",children:[e.jsxs("button",{type:"button",className:`v10-agent-profile-stat${h===null?" active":""}`,onClick:()=>r(null),children:[e.jsx("span",{className:"v10-agent-profile-stat-val",children:v}),e.jsx("span",{className:"v10-agent-profile-stat-lbl",children:n?"Loaded activity":"All activity"})]}),w.map(a=>{const l=g.get(a.iri)??[];if(l.length===0)return null;const o=p==null?void 0:p.forType(a.iri),f=(o==null?void 0:o.color)??"#a855f7";return e.jsxs("button",{type:"button",className:`v10-agent-profile-stat${h===a.iri?" active":""}`,style:{"--stat-color":f},onClick:()=>r(a.iri),children:[e.jsx("span",{className:"v10-agent-profile-stat-val",children:l.length}),e.jsx("span",{className:"v10-agent-profile-stat-lbl",children:o!=null&&o.label?o.label:a.label})]},a.iri)})]}),e.jsx(E,{entities:u,agentUri:t,typeIri:h??void 0,onSelectEntity:m,onOpenAgent:c,title:e.jsxs(e.Fragment,{children:[n?"Loaded activity":"All activity",s&&e.jsxs("span",{className:"v10-agent-profile-feed-sub",children:[" · authored by ",s.name]})]}),emptyHint:n?"No entries for this agent in the loaded preview. Load more memory to check later assets.":v===0?`${(s==null?void 0:s.name)??t} hasn't authored anything in this project yet.`:"No entries match the current filter."})]})},W=({contextGraphId:t,agentUri:u})=>{const n=M(t),m=S(t),c=P(t),{openTab:d,closeTab:i,activeTabId:p}=A(),{setActiveProject:s}=C(),g=y.useCallback(r=>{s(t),d({id:`project:${t}`,label:n.displayName||t.slice(0,16),closable:!0}),window.dispatchEvent(new CustomEvent("v10:open-entity",{detail:{contextGraphId:t,entityUri:r}}))},[t,d,n.displayName,s]),v=y.useCallback(r=>{var o;const a=r.startsWith("urn:dkg:agent:")?r.slice(14):r,l=((o=m.get(r))==null?void 0:o.name)??a;d({id:`agent:${t}|${a}`,label:`@ ${l}`,closable:!0})},[t,m,d]),b=y.useCallback(()=>{p&&i(p)},[p,i]),h=y.useMemo(()=>({...m,openAgent:v}),[m,v]);return e.jsx($.Provider,{value:n,children:e.jsxs(D.Provider,{value:h,children:[e.jsx(B,{memory:c}),e.jsx(L,{agentUri:u,entityList:c.entityList,partial:c.partial||c.loading,onSelectEntity:g,onOpenAgent:v,onBack:b})]})})};export{W as AgentProfilePage};
@@ -1,3 +1,3 @@
1
- import{aO as t,bd as g,aw as Ie,N as fe,b7 as st,bO as K,b9 as Ct,b6 as Nt,b4 as kt,z as jt,a7 as oe,ai as Fe,b5 as Tt,aH as Pt,aB as St,aS as Rt,bG as Et,bw as Ot,bz as ke,aN as Ue,bK as he,aq as We,H as Be,aI as It,B as ot}from"./index-MQh8C4aJ.js";import{Q as Wt,e as ge,C as it,W as $t,B as Ht,d as ce,E as Dt,O as ct,r as Lt,i as Bt,q as lt,o as Y,c as Ke,f as Ve}from"./browserWalletTransaction-CBgx0i4w.js";const _t={healthy:{glyph:"✓",label:"Healthy",toneClass:"badge-success",hint:"Active, solvent, and not expiring soon."},expiring:{glyph:"⏳",label:"Expiring soon",toneClass:"badge-warn",hint:"The lock period ends soon — top-up does NOT extend it; renew to keep the discount."},expired:{glyph:"✕",label:"Expired",toneClass:"badge-error",hint:"The lock period has ended — publishes no longer get this discount. Renew to continue."},insolvent:{glyph:"⚠",label:"Insolvent",toneClass:"badge-error",hint:"The spendable buffer is depleted — publishes will quietly pay the direct cost. Top up."},swept:{glyph:"⊘",label:"Fully swept",toneClass:"badge",hint:"Every epoch budget has been swept to the staker reward pool."},"cap-near":{glyph:"⚠",label:"Cap near 100",toneClass:"badge-warn",hint:"Approaching the 100 approved-publishing-wallet cap."}};function Ba({state:e,label:a,className:n=""}){const s=_t[e],r=a??s.label,o=[...new Set(["badge",s.toneClass,"v10-pca-health-chip",n])].filter(Boolean).join(" ");return t.jsxs("span",{className:o,"data-testid":"pca-health-chip","data-health":e,title:s.hint,children:[t.jsx("span",{className:"v10-pca-health-glyph","aria-hidden":"true",children:s.glyph}),t.jsx("span",{className:"v10-pca-health-label",children:r})]})}const Mt=t.jsxs(t.Fragment,{children:["Paste the ",t.jsx("strong",{children:"operational wallet address"})," — the address that signs its publish transactions (on-chain ",t.jsx("code",{children:"msg.sender"}),"). ",t.jsx("strong",{children:"NOT"})," its peerId."," ",t.jsx("strong",{children:"NOT"})," its admin wallet. ",t.jsx("strong",{children:"NOT"})," a content-author identity. The other operator gets these from ",t.jsx("code",{children:"dkg wallet"}),", or from their node's"," ",t.jsx("em",{children:"Get added to a PCA"})," panel."]});function Ft({value:e,onChange:a,mode:n="single",label:s="Operational wallet (the address that signs publishes)",cruxNote:r=Mt,placeholder:o,error:i,disabled:c=!1,rows:f=5,id:x,testId:v,className:w=""}){const A=g.useId(),N=x??`pca-addr-${A}`,R=`${N}-help`,H=`${N}-error`,h=[i?H:null,R].filter(Boolean).join(" ")||void 0,l=n==="bulk"?"0x… (one per line)":"0x…";return t.jsxs("div",{className:["v10-pca-address-crux",w].filter(Boolean).join(" "),children:[t.jsx("label",{className:"v10-form-label",htmlFor:N,children:s}),r!=null&&t.jsx("p",{className:"v10-pca-crux-note",children:r}),n==="bulk"?t.jsx("textarea",{id:N,"data-testid":v,className:"v10-form-textarea",value:e,onChange:k=>a(k.target.value),placeholder:o??l,disabled:c,rows:f,"aria-describedby":h,"aria-invalid":i?!0:void 0,spellCheck:!1}):t.jsx("input",{id:N,"data-testid":v,type:"text",className:"v10-form-input",value:e,onChange:k=>a(k.target.value),placeholder:o??l,disabled:c,"aria-describedby":h,"aria-invalid":i?!0:void 0,spellCheck:!1,autoComplete:"off"}),t.jsxs("p",{id:R,className:"v10-pca-crux-help",children:[t.jsx("abbr",{title:"On-chain authorization to publish under this account — unrelated to the ERC-20 token approve() that grants a spending allowance.",children:"“Approve”"})," ","is on-chain authorization to publish under this account — unrelated to ERC-20 token"," ",t.jsx("code",{children:"approve()"}),". The wallet owner doesn't sign anything."]}),i!=null&&t.jsx("p",{id:H,className:"v10-pca-crux-error",role:"alert",children:i})]})}const _e=[{minTrac:0,bps:0,tracLabel:"< 25,000 TRAC",pctLabel:"0%"},{minTrac:25e3,bps:1e3,tracLabel:"25,000 TRAC",pctLabel:"10%"},{minTrac:5e4,bps:2e3,tracLabel:"50,000 TRAC",pctLabel:"20%"},{minTrac:1e5,bps:3e3,tracLabel:"100,000 TRAC",pctLabel:"30%"},{minTrac:25e4,bps:4e3,tracLabel:"250,000 TRAC",pctLabel:"40%"},{minTrac:5e5,bps:5e3,tracLabel:"500,000 TRAC",pctLabel:"50%"},{minTrac:1e6,bps:7500,tracLabel:"1,000,000+ TRAC",pctLabel:"75%"}];function dt(e){const a=typeof e=="number"&&Number.isFinite(e)?e:0;let n=_e[0];for(const s of _e)a>=s.minTrac&&(n=s);return n}function Ut({committedTrac:e,caption:a="Discount tier for the entered commitment.",className:n=""}){const s=e==null?null:dt(e);return t.jsxs("div",{className:["v10-pca-tier-ladder",n].filter(Boolean).join(" "),"data-testid":"pca-tier-ladder",children:[t.jsx("ul",{className:"v10-pca-tier-list",role:"list",children:_e.map(r=>{const o=s!=null&&s.minTrac===r.minTrac;return t.jsxs("li",{className:["v10-pca-tier-row",o?"active":""].filter(Boolean).join(" "),"data-bps":r.bps,...o?{"aria-current":"true"}:{},children:[t.jsx("span",{className:"v10-pca-tier-trac",children:r.tracLabel}),t.jsx("span",{className:"v10-pca-tier-pct",children:r.pctLabel})]},r.minTrac)})}),a!=null&&t.jsx("p",{className:"v10-pca-tier-caption",children:a})]})}function Kt({wallets:e=[],accountId:a,role:n="edge",className:s=""}){const{copied:r,copy:o}=Wt(),i=e.join(`
1
+ import{aU as t,bj as g,aB as Ie,X as fe,bd as st,bV as K,bf as Ct,bc as Nt,ba as kt,B as jt,ac as oe,an as Fe,bb as Tt,aN as Pt,aG as St,aX as Rt,bN as Et,bD as Ot,bG as ke,aT as Ue,bR as he,av as We,H as Be,aO as It,F as ot}from"./index-HEpqHVfE.js";import{Q as Wt,e as ge,C as it,W as $t,B as Ht,d as ce,E as Dt,O as ct,r as Lt,i as Bt,q as lt,o as Y,c as Ke,f as Ve}from"./browserWalletTransaction-BJBFRjXx.js";const _t={healthy:{glyph:"✓",label:"Healthy",toneClass:"badge-success",hint:"Active, solvent, and not expiring soon."},expiring:{glyph:"⏳",label:"Expiring soon",toneClass:"badge-warn",hint:"The lock period ends soon — top-up does NOT extend it; renew to keep the discount."},expired:{glyph:"✕",label:"Expired",toneClass:"badge-error",hint:"The lock period has ended — publishes no longer get this discount. Renew to continue."},insolvent:{glyph:"⚠",label:"Insolvent",toneClass:"badge-error",hint:"The spendable buffer is depleted — publishes will quietly pay the direct cost. Top up."},swept:{glyph:"⊘",label:"Fully swept",toneClass:"badge",hint:"Every epoch budget has been swept to the staker reward pool."},"cap-near":{glyph:"⚠",label:"Cap near 100",toneClass:"badge-warn",hint:"Approaching the 100 approved-publishing-wallet cap."}};function Ba({state:e,label:a,className:n=""}){const s=_t[e],r=a??s.label,o=[...new Set(["badge",s.toneClass,"v10-pca-health-chip",n])].filter(Boolean).join(" ");return t.jsxs("span",{className:o,"data-testid":"pca-health-chip","data-health":e,title:s.hint,children:[t.jsx("span",{className:"v10-pca-health-glyph","aria-hidden":"true",children:s.glyph}),t.jsx("span",{className:"v10-pca-health-label",children:r})]})}const Mt=t.jsxs(t.Fragment,{children:["Paste the ",t.jsx("strong",{children:"operational wallet address"})," — the address that signs its publish transactions (on-chain ",t.jsx("code",{children:"msg.sender"}),"). ",t.jsx("strong",{children:"NOT"})," its peerId."," ",t.jsx("strong",{children:"NOT"})," its admin wallet. ",t.jsx("strong",{children:"NOT"})," a content-author identity. The other operator gets these from ",t.jsx("code",{children:"dkg wallet"}),", or from their node's"," ",t.jsx("em",{children:"Get added to a PCA"})," panel."]});function Ft({value:e,onChange:a,mode:n="single",label:s="Operational wallet (the address that signs publishes)",cruxNote:r=Mt,placeholder:o,error:i,disabled:c=!1,rows:f=5,id:x,testId:v,className:w=""}){const A=g.useId(),N=x??`pca-addr-${A}`,R=`${N}-help`,H=`${N}-error`,h=[i?H:null,R].filter(Boolean).join(" ")||void 0,l=n==="bulk"?"0x… (one per line)":"0x…";return t.jsxs("div",{className:["v10-pca-address-crux",w].filter(Boolean).join(" "),children:[t.jsx("label",{className:"v10-form-label",htmlFor:N,children:s}),r!=null&&t.jsx("p",{className:"v10-pca-crux-note",children:r}),n==="bulk"?t.jsx("textarea",{id:N,"data-testid":v,className:"v10-form-textarea",value:e,onChange:k=>a(k.target.value),placeholder:o??l,disabled:c,rows:f,"aria-describedby":h,"aria-invalid":i?!0:void 0,spellCheck:!1}):t.jsx("input",{id:N,"data-testid":v,type:"text",className:"v10-form-input",value:e,onChange:k=>a(k.target.value),placeholder:o??l,disabled:c,"aria-describedby":h,"aria-invalid":i?!0:void 0,spellCheck:!1,autoComplete:"off"}),t.jsxs("p",{id:R,className:"v10-pca-crux-help",children:[t.jsx("abbr",{title:"On-chain authorization to publish under this account — unrelated to the ERC-20 token approve() that grants a spending allowance.",children:"“Approve”"})," ","is on-chain authorization to publish under this account — unrelated to ERC-20 token"," ",t.jsx("code",{children:"approve()"}),". The wallet owner doesn't sign anything."]}),i!=null&&t.jsx("p",{id:H,className:"v10-pca-crux-error",role:"alert",children:i})]})}const _e=[{minTrac:0,bps:0,tracLabel:"< 25,000 TRAC",pctLabel:"0%"},{minTrac:25e3,bps:1e3,tracLabel:"25,000 TRAC",pctLabel:"10%"},{minTrac:5e4,bps:2e3,tracLabel:"50,000 TRAC",pctLabel:"20%"},{minTrac:1e5,bps:3e3,tracLabel:"100,000 TRAC",pctLabel:"30%"},{minTrac:25e4,bps:4e3,tracLabel:"250,000 TRAC",pctLabel:"40%"},{minTrac:5e5,bps:5e3,tracLabel:"500,000 TRAC",pctLabel:"50%"},{minTrac:1e6,bps:7500,tracLabel:"1,000,000+ TRAC",pctLabel:"75%"}];function dt(e){const a=typeof e=="number"&&Number.isFinite(e)?e:0;let n=_e[0];for(const s of _e)a>=s.minTrac&&(n=s);return n}function Ut({committedTrac:e,caption:a="Discount tier for the entered commitment.",className:n=""}){const s=e==null?null:dt(e);return t.jsxs("div",{className:["v10-pca-tier-ladder",n].filter(Boolean).join(" "),"data-testid":"pca-tier-ladder",children:[t.jsx("ul",{className:"v10-pca-tier-list",role:"list",children:_e.map(r=>{const o=s!=null&&s.minTrac===r.minTrac;return t.jsxs("li",{className:["v10-pca-tier-row",o?"active":""].filter(Boolean).join(" "),"data-bps":r.bps,...o?{"aria-current":"true"}:{},children:[t.jsx("span",{className:"v10-pca-tier-trac",children:r.tracLabel}),t.jsx("span",{className:"v10-pca-tier-pct",children:r.pctLabel})]},r.minTrac)})}),a!=null&&t.jsx("p",{className:"v10-pca-tier-caption",children:a})]})}function Kt({wallets:e=[],accountId:a,role:n="edge",className:s=""}){const{copied:r,copy:o}=Wt(),i=e.join(`
2
2
  `);return t.jsxs("div",{className:["v10-pca-handshake",s].filter(Boolean).join(" "),children:[t.jsxs("section",{className:"v10-pca-handshake-half","data-emphasis":n==="edge"?"true":"false",children:[t.jsxs("header",{className:"v10-pca-handshake-head",children:[t.jsx("span",{className:"v10-pca-handshake-title",children:"Operational wallets"}),t.jsx("span",{className:"v10-pca-handshake-sub",children:"The edge node shares these; the PCA owner approves them."})]}),e.length===0?t.jsx("p",{className:"v10-pca-handshake-empty",children:"No operational wallets detected on this node."}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"v10-pca-handshake-wallets",children:e.map(c=>t.jsx(ge,{address:c},c))}),t.jsx("button",{type:"button",className:"v10-pca-handshake-copyall",onClick:()=>o(i),"aria-label":r?"Copied all wallets":"Copy all wallet addresses",children:r?"Copied":"Copy all"})]})]}),t.jsxs("section",{className:"v10-pca-handshake-half","data-emphasis":n==="core"?"true":"false",children:[t.jsxs("header",{className:"v10-pca-handshake-head",children:[t.jsx("span",{className:"v10-pca-handshake-title",children:"PCA ID from owner"}),t.jsx("span",{className:"v10-pca-handshake-sub",children:"The PCA owner sends this back after approving the wallets."})]}),a?t.jsxs("div",{className:"v10-pca-handshake-account",children:[t.jsxs("span",{className:"v10-pca-handshake-account-id",children:["PCA #",a]}),t.jsx(it,{value:a,label:`Copy account id ${a}`})]}):t.jsx("p",{className:"v10-pca-handshake-empty",children:"Pending - enter it once the PCA owner confirms the approval."})]})]})}const Vt=50;function Gt({nodes:e,loading:a,error:n,onRetry:s,value:r,onChange:o,ownIdentityId:i,role:c,required:f=!1}){const[x,v]=g.useState(""),[w,A]=g.useState(!1),[N,R]=g.useState(-1),[H,h]=g.useState(""),[l,k]=g.useState(null),u=g.useId(),p=g.useMemo(()=>{const m=x.trim().toLowerCase();return m?e.filter(L=>L.nodeId.toLowerCase().includes(m)||L.identityId.toLowerCase().includes(m)):e},[e,x]),b=p.slice(0,Vt),y=p.length>b.length,j=m=>{o(m.identityId),v(""),A(!1),R(-1),k(null)},D=m=>{m.key==="ArrowDown"?(m.preventDefault(),A(!0),R(L=>Math.min(L+1,b.length-1))):m.key==="ArrowUp"?(m.preventDefault(),A(!0),R(L=>Math.max(L-1,0))):m.key==="Enter"?w&&N>=0&&b[N]&&(m.preventDefault(),j(b[N])):m.key==="Escape"&&w&&(m.stopPropagation(),A(!1),R(-1))},E=()=>{const m=H.trim().replace(/^#/,"");if(!m)return;const L=e.find(P=>P.identityId===m||P.nodeId.toLowerCase()===m.toLowerCase());if(!L){k("Not a staked sharding-table node.");return}j(L),h("")},I=r?e.find(m=>m.identityId===r):void 0,Q=r!==""&&i!=null&&r===i,ne=r!==""&&(i==null||r!==i),re=c==="edge"||i==null,W=I?Ie(I.stake):null,F=r!==""?`Selected node #${r}${W?` · ${W} TRAC staked`:""}${Q?" · this node":""}`:null,Z=F?`${u}-selected`:void 0;return t.jsxs("div",{className:"v10-pca-node-picker","data-testid":"pca-primary-node-picker",children:[t.jsx("p",{className:"v10-pca-create-hint",children:"Primary node = where reward weight goes. It’s separate from which wallets publish and from your discount."}),a?t.jsx("p",{className:"v10-pca-create-hint",role:"status",children:"Loading staked nodes…"}):n?t.jsxs("div",{className:"v10-modal-warning",role:"alert","data-testid":"pca-primary-node-error",children:["Couldn’t load the staked-node list — a primary node is required to create."," ",t.jsx("button",{type:"button",className:"v10-pca-card-btn","data-testid":"pca-primary-node-retry",onClick:s,children:"Retry"}),r!==""&&t.jsxs("p",{className:"v10-pca-create-hint","data-testid":"pca-primary-node-error-selected",children:["Using node #",r,Q?" (this node)":""," for now — Retry to pick another."]})]}):e.length===0?t.jsx("p",{className:"v10-pca-create-hint",role:"status",children:"No staked nodes found."}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:["v10-pca-node-picker-combo",F?"has-selection":""].filter(Boolean).join(" "),children:[t.jsx("input",{type:"text",role:"combobox","aria-expanded":w,"aria-controls":w?u:void 0,"aria-autocomplete":"list","aria-label":"Search staked nodes","aria-describedby":Z,"aria-required":f,"aria-invalid":f&&r==="","aria-activedescendant":w&&N>=0&&b[N]?`${u}-opt-${b[N].identityId}`:void 0,className:"v10-form-input","data-testid":"pca-primary-node-search",value:x,placeholder:F??"Search staked nodes by id…",autoComplete:"off",onFocus:()=>A(!0),onChange:m=>{v(m.target.value),A(!0),R(-1)},onKeyDown:D}),w&&t.jsxs("ul",{role:"listbox",id:u,"aria-label":"Staked sharding-table nodes",className:"v10-pca-node-picker-list",children:[b.map((m,L)=>{const P=m.identityId===r,B=i!=null&&m.identityId===i;return t.jsxs("li",{id:`${u}-opt-${m.identityId}`,role:"option","aria-selected":P,"data-testid":"pca-primary-node-option",className:["v10-pca-node-picker-option",L===N?"active":"",P?"selected":""].filter(Boolean).join(" "),"aria-label":`Node ${m.identityId}, peer ${m.nodeId}, stake ${Ie(m.stake)} TRAC${B?", this node":""}`,onMouseDown:$=>{$.preventDefault(),j(m)},children:[t.jsxs("span",{className:"v10-pca-node-picker-id",children:["#",m.identityId]}),t.jsx("span",{className:"v10-pca-node-picker-peer",title:m.nodeId,children:m.nodeId}),t.jsx("span",{className:"badge",title:"Node labels are not verified — match on id",children:"unverified"}),t.jsxs("span",{className:"v10-pca-node-picker-stake",children:[Ie(m.stake)," TRAC staked"]}),B&&t.jsx("span",{className:"v10-pca-node-picker-own",children:"✓ this node"})]},m.identityId)}),y&&t.jsxs("li",{role:"presentation",className:"v10-pca-node-picker-more",children:["showing ",b.length," of ",p.length," — refine your search"]})]})]}),F&&t.jsxs("div",{className:"v10-pca-node-picker-selected","data-testid":"pca-primary-node-selected",id:Z,role:"status",children:[t.jsx("span",{children:"Selected primary node"}),t.jsxs("strong",{children:["Node #",r,W?` · ${W} TRAC staked`:"",Q?" · this node":""]})]}),t.jsxs("div",{className:"v10-pca-node-picker-paste",children:[t.jsx("input",{type:"text",className:"v10-form-input","data-testid":"pca-primary-node-paste",value:H,placeholder:"…or paste a node id","aria-label":"Paste a node id",autoComplete:"off",onChange:m=>{h(m.target.value),k(null)},onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),E())}}),t.jsx("button",{type:"button",className:"v10-pca-card-btn","data-testid":"pca-primary-node-paste-use",onClick:E,children:"Use"}),l&&t.jsx("p",{className:"v10-pca-crux-error",role:"alert","data-testid":"pca-primary-node-paste-error",children:l})]}),re?t.jsx("p",{className:"v10-pca-create-hint","data-testid":"pca-primary-node-donation",children:"You get the discount; the reward weight from this account accrues to the node you pick — not to you."}):ne&&t.jsxs("p",{className:"v10-pca-create-warn",role:"status","data-testid":"pca-primary-node-heads-up",children:["Reward weight will go to node #",r," instead of this node."]})]})]})}function qt(e){return t.jsx($t,{...e,description:t.jsx(t.Fragment,{children:"Hardware wallet recommended. If your provider uses a device, verify the amount and contract on the device. Hot publishing wallets can publish without prompts; their spend is bounded by the per-epoch allowance, not the committed TRAC."})})}function zt(e){return e==="confirmed"?"OK":e==="submitted"?"TX":e==="failed"?"ERR":e==="aborted"?"STOP":e==="active"?"...":"-"}function ut({steps:e,currentLabel:a,blockExplorerUrl:n}){const s=e.some(r=>r.state==="failed"||r.state==="aborted");return t.jsxs("div",{className:"v10-pca-device-progress",role:s?"alert":"status","aria-live":s?"assertive":"polite",children:[t.jsx("p",{className:"v10-pca-device-progress-title",children:a??"Confirm on your device"}),t.jsx("p",{className:"v10-pca-device-progress-note",children:"Verify the amount and contract address on the device before approving."}),t.jsx("ol",{className:"v10-pca-device-progress-list",children:e.map(r=>{const o=r.txHash&&n?`${n.replace(/\/$/,"")}/tx/${r.txHash}`:null;return t.jsxs("li",{className:"v10-pca-device-progress-row","data-state":r.state,children:[t.jsx("span",{className:"v10-pca-device-progress-glyph",children:zt(r.state)}),t.jsx("span",{children:r.label}),r.txHash&&(o?t.jsx("a",{href:o,target:"_blank",rel:"noreferrer",className:"v10-pca-device-progress-tx",children:"tx"}):t.jsx("code",{className:"v10-pca-device-progress-tx",children:r.txHash})),r.error&&t.jsx("span",{className:"v10-pca-device-progress-error",children:r.error})]},r.id)})})]})}class Xt extends Ht{constructor({value:a}){super(`Number \`${a}\` is not a valid decimal number.`,{name:"InvalidDecimalNumberError"})}}function Yt(e,a){if(!/^(-?)([0-9]*)\.?([0-9]*)$/.test(e))throw new Xt({value:e});let[n,s="0"]=e.split(".");const r=n.startsWith("-");if(r&&(n=n.slice(1)),s=s.replace(/(0+)$/,""),s.length>a){const[o,i,c]=[s.slice(0,a-1),s.slice(a-1,a),s.slice(a)],f=Math.round(+`${i}.${c}`);f>9?s=`${BigInt(o)+BigInt(1)}0`.padStart(o.length+1,"0"):s=`${o}${f}`,s.length>a&&(s=s.slice(1),n=`${BigInt(n)+1n}`),s=s.slice(0,a)}else s=s.padEnd(a,"0");return BigInt(`${r?"-":""}${n}${s}`)}const Qt=[{type:"function",name:"createAccount",stateMutability:"nonpayable",inputs:[{name:"committedTRAC",type:"uint96"},{name:"primaryNode",type:"uint72"}],outputs:[{name:"accountId",type:"uint256"}]},{type:"function",name:"topUp",stateMutability:"nonpayable",inputs:[{name:"accountId",type:"uint256"},{name:"amount",type:"uint96"}],outputs:[]},{type:"function",name:"registerAgent",stateMutability:"nonpayable",inputs:[{name:"accountId",type:"uint256"},{name:"agent",type:"address"}],outputs:[]},{type:"function",name:"deregisterAgent",stateMutability:"nonpayable",inputs:[{name:"accountId",type:"uint256"},{name:"agent",type:"address"}],outputs:[]},{type:"function",name:"settle",stateMutability:"nonpayable",inputs:[{name:"accountId",type:"uint256"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"owner",type:"address"}],outputs:[{type:"uint256"}]},{type:"function",name:"tokenOfOwnerByIndex",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"index",type:"uint256"}],outputs:[{type:"uint256"}]},{type:"function",name:"ownerOf",stateMutability:"view",inputs:[{name:"tokenId",type:"uint256"}],outputs:[{type:"address"}]},{type:"function",name:"getDiscountBps",stateMutability:"view",inputs:[{name:"committedTRAC",type:"uint96"}],outputs:[{type:"uint256"}]},{type:"event",name:"Transfer",inputs:[{name:"from",type:"address",indexed:!0},{name:"to",type:"address",indexed:!0},{name:"tokenId",type:"uint256",indexed:!0}]}],Zt="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",Jt="0x0000000000000000000000000000000000000000000000000000000000000000";function ea(e){return`0x${e.slice(-40)}`.toLowerCase()}function ta(e,a,n){var o,i;const s=a.toLowerCase(),r=n==null?void 0:n.toLowerCase();for(const c of e.logs){if(c.address.toLowerCase()!==s)continue;const f=c.topics;if(((o=f[0])==null?void 0:o.toLowerCase())===Zt&&f.length===4&&((i=f[1])==null?void 0:i.toLowerCase())===Jt&&!(r&&ea(f[2])!==r))return BigInt(f[3])}throw new Error("No PCA mint Transfer found in the create receipt")}function aa(e,a){return e?"ready":a?"unreadable":"loading"}function na(e,a){return e==="daemon"||e==="wallet"&&!a}function ra(e,a,n){return e.mode==="wallet"&&e.writesEnabled?!0:e.mode==="unknown"?!!n&&(!a||fe(a,n)):!1}function Ge(e){const{owner:a,primaryWallet:n,connectedWallet:s,walletWrongNetwork:r=!1,primaryWalletState:o="ready"}=e;if(o==="loading")return{mode:"unknown",wrongNetwork:r,writesEnabled:!1,ownerUnknownCause:"wallets-loading"};if(o==="unreadable")return{mode:"unknown",wrongNetwork:r,writesEnabled:!1,ownerUnknownCause:"wallets-unreadable"};if(!a)return{mode:"unknown",wrongNetwork:r,writesEnabled:!1,ownerUnknownCause:"no-snapshot"};let i;fe(a,n)?i="daemon":s&&fe(a,s)&&!fe(a,n)?i="wallet":i="external";const c=r,f=na(i,c);return{mode:i,wrongNetwork:c,writesEnabled:f}}const sa=(1n<<72n)-1n,oa=(1n<<96n)-1n;class V extends Error{constructor(a){super(a),this.name="WalletOwnerActionSubmitterError"}}class qe extends V{constructor(a){super(a),this.name="WalletOwnerActionUnavailableError"}}class ze extends V{constructor(a){super(a),this.name="WalletOwnerActionAbortError"}}function je(e,a){return Bt(e,a,n=>new V(n))}function $e(e){const a=e.trim();if(!/^\d+$/.test(a))throw new V("accountId must be a non-negative integer string.");return BigInt(a)}function tt(e,a){const n=e.trim();if(!/^\d+(\.\d+)?$/.test(n))throw new V(`${a} must be a positive decimal number of TRAC tokens.`);let s;try{s=Yt(n,18)}catch(r){const o=r instanceof Error&&r.message?r.message:String(r);throw new V(`${a} parse error: ${o}`)}if(s<=0n)throw new V(`${a} must be > 0.`);if(s>oa)throw new V(`${a} exceeds the uint96 TRAC amount range.`);return s}function ia(e){if(typeof e!="string"&&typeof e!="number")throw new V("primaryNode must be a positive integer node identityId.");const a=String(e).trim();if(!/^\d+$/.test(a))throw new V("primaryNode must be a positive integer node identityId.");const n=BigInt(a);if(n<=0n)throw new V("primaryNode must be > 0 before signing; choose a staked node for this PCA.");if(n>sa)throw new V("primaryNode exceeds the uint72 node identityId range.");return n}function at(e){const a=Lt(e,18);return a.includes(".")?a:`${a}.0`}function ye(e){return e.blockNumber==null?void 0:Number(e.blockNumber)}const Te={error:e=>new V(e),unavailableError:e=>new qe(e),abortedError:e=>new ze(e),messages:{disconnected:"Connect the PCA owner wallet before signing.",wrongNetwork:"Switch the connected wallet to this node's PCA network.",providerChanged:"Wallet provider changed before the signature prompt. Reconnect and retry.",addressChanged:"Connected wallet changed before the signature prompt. Reconnect the owner wallet.",networkChanged:"Wallet network changed before the signature prompt. Switch back and retry.",accountChanged:"Wallet account changed before the signature prompt. Reconnect the owner wallet."}};function xe(e){const a=e.getWalletState??(()=>{const{provider:o,address:i,chainId:c}=K.getState();return{provider:o,address:i,chainId:c}}),n=e.bootstrap??K.getState().bootstrap;if(!n)throw Te.unavailableError("PCA contract addresses are not bootstrapped yet.");const s={bootstrap:n,getWalletState:a,...e.publicClientFor?{publicClientFor:e.publicClientFor}:{},...e.walletClientFromProvider?{walletClientFromProvider:e.walletClientFromProvider}:{}},r=Dt(s,Te);return{...r,runtimeDeps:s,owner:r.account,nft:je(r.bootstrap.nft,"PCA NFT contract"),token:je(r.bootstrap.token,"TRAC token contract")}}async function nt(e){return await e.publicClient.readContract({address:e.token,abi:lt,functionName:"allowance",args:[e.owner,e.nft]})}async function rt(e,a,n){var s;if(await nt(e)>=n){(s=a.onProgress)==null||s.call(a,{step:"approve",state:"skipped"});return}if(await ct(e,e.runtimeDeps,Te,r=>r.writeContract({account:e.account,chain:e.chain,address:e.token,abi:lt,functionName:"approve",args:[e.nft,n]}),"approve",{signing:()=>{var r;return(r=a.onProgress)==null?void 0:r.call(a,{step:"approve",state:"active"})},submitted:r=>{var o;return(o=a.onProgress)==null?void 0:o.call(a,{step:"approve",state:"submitted",txHash:r})},confirmed:r=>{var o;return(o=a.onProgress)==null?void 0:o.call(a,{step:"approve",state:"confirmed",txHash:r})},failed:(r,o)=>{var i;return(i=a.onProgress)==null?void 0:i.call(a,{step:"approve",state:"failed",txHash:o,error:r})}}),await nt(e)<n)throw new V("TRAC approval confirmed but allowance is still too low.")}async function Ae(e,a,n){return ct(e,e.runtimeDeps,Te,s=>s.writeContract({account:e.account,chain:e.chain,address:e.nft,abi:Qt,...n}),"action",{signing:()=>{var s;return(s=a.onProgress)==null?void 0:s.call(a,{step:"action",state:"active"})},submitted:s=>{var r;return(r=a.onProgress)==null?void 0:r.call(a,{step:"action",state:"submitted",txHash:s})},confirmed:s=>{var r;return(r=a.onProgress)==null?void 0:r.call(a,{step:"action",state:"confirmed",txHash:s})},failed:(s,r)=>{var o;return(o=a.onProgress)==null?void 0:o.call(a,{step:"action",state:"failed",txHash:r,error:s})}})}function pt(e={}){return{async create(a){const n=ia(a.primaryNode),s=tt(a.tokens,"tokens"),r=xe(e);await rt(r,e,s);const{hash:o,receipt:i}=await Ae(r,e,{functionName:"createAccount",args:[s,n]});let c;try{c=ta(i,r.nft,r.owner).toString()}catch(f){throw new ce(i.transactionHash??o,f,"action")}return{accountId:c,txHash:i.transactionHash??o,blockNumber:ye(i),committedTokens:at(s)}},async registerAgent(a,n){const s=$e(a),r=je(n,"Publishing wallet"),o=xe(e),{hash:i,receipt:c}=await Ae(o,e,{functionName:"registerAgent",args:[s,r]});return{accountId:a,agent:r,registered:!0,adapterSupported:!0,txHash:c.transactionHash??i,blockNumber:ye(c)}},async deregisterAgent(a,n){const s=$e(a),r=je(n,"Publishing wallet"),o=xe(e),{hash:i,receipt:c}=await Ae(o,e,{functionName:"deregisterAgent",args:[s,r]});return{accountId:a,agent:r,deregistered:!0,txHash:c.transactionHash??i,blockNumber:ye(c)}},async topUp(a,n){const s=$e(a),r=tt(n,"tokens"),o=xe(e);await rt(o,e,r);const{hash:i,receipt:c}=await Ae(o,e,{functionName:"topUp",args:[s,r]});return{accountId:a,addedTokens:at(r),txHash:c.transactionHash??i,blockNumber:ye(c)}},settle:st}}const le={create:jt,registerAgent:kt,deregisterAgent:Nt,topUp:Ct,settle:st};class ca extends Error{constructor(a="Connect the PCA owner wallet to manage this account."){super(a),this.name="ReadOnlyOwnerActionError"}}class ht extends Error{constructor(a,n){super(a),this.name="OwnerActionUnavailableError",this.cause=n==null?void 0:n.cause}}async function Ce(){throw new ca}function He(e,a){async function n(){throw new ht(e,{cause:a})}return{create:n,registerAgent:n,deregisterAgent:n,topUp:n,settle:le.settle}}const la={create:Ce,registerAgent:Ce,deregisterAgent:Ce,topUp:Ce,settle:le.settle};function mt(){const e=K.getState();return!e.provider||!e.address?"Connect the PCA owner wallet before signing.":!e.bootstrap||e.expectedChainId==null?"PCA contract addresses are not bootstrapped yet.":e.chainId!==e.expectedChainId?"Switch the connected wallet to this node's PCA network.":null}function Pe(e){return e==="daemon"?"daemon":e==="wallet"?"wallet":"read-only"}function da({owner:e,primaryWallet:a,connectedWallet:n}){return Pe(Ge({owner:e,primaryWallet:a,connectedWallet:n}).mode)}async function ua(e){const{accountId:a,primaryWallet:n,connectedWallet:s,walletWrongNetwork:r}=e;if(!a)return;const o=await oe(a).catch(()=>null);if(!(o!=null&&o.owner))return;const i=Ge({owner:o.owner,primaryWallet:n??null,connectedWallet:s,walletWrongNetwork:r}),c=Pe(i.mode);if(c==="daemon")return"daemon";if(c==="wallet"&&i.writesEnabled)return"wallet"}function ft(e,a={}){return e==="daemon"?le:e==="read-only"?la:pt(a)}async function De(e,a={}){let n;try{n=await oe(e)}catch(i){return He("Could not verify the PCA owner before signing.",i)}let s;try{s=(await Fe()).wallets??[]}catch(i){return He("Could not verify this node's primary wallet before signing.",i)}const r=K.getState().address,o=da({owner:n.owner,primaryWallet:s[0]??null,connectedWallet:r});if(o==="wallet"){const i=mt();if(i)return He(i)}return ft(o,a)}function gt(e){return async a=>{if(e.ownerKey!=="hardware")return le.create(a);const n=mt();if(n)throw new ht(n);return pt({onProgress:e.onWalletProgress}).create(a)}}function vt(e={}){return{create:gt(e),async registerAgent(a,n){return(await De(a,{onProgress:e.onWalletProgress})).registerAgent(a,n)},async deregisterAgent(a,n){return(await De(a,{onProgress:e.onWalletProgress})).deregisterAgent(a,n)},async topUp(a,n){return(await De(a,{onProgress:e.onWalletProgress})).topUp(a,n)},settle:le.settle}}function pa(e,a){if(e.mode==="unknown"||Pe(e.mode)==="wallet")return vt({onWalletProgress:a});const n=ft(Pe(e.mode),{onProgress:a});return{create:gt({onWalletProgress:a}),registerAgent:n.registerAgent,deregisterAgent:n.deregisterAgent,topUp:n.topUp,settle:le.settle}}function Me(e={}){return vt(e)}function ha(e){return pa(e.access,e.onWalletProgress)}function ma(e,a){return[{address:e,kind:"daemon"},{address:a,kind:"wallet"}]}function fa(e){return(Array.isArray(e)?e:e!=null?[e]:[]).flatMap(n=>typeof n=="string"?n?[{address:n,kind:"daemon"}]:[]:n.address?[{address:n.address,kind:n.kind??"daemon"}]:[])}async function wt(e,a){const n=fa(a),s=await Tt(e).catch(()=>{});if(s===void 0)return{wallet:e,boundTo:null,canOwn:!1,boundLive:!1,inconclusive:!0};const r=s.accountId;if(r==null)return{wallet:e,boundTo:null,canOwn:!1,boundLive:!1,inconclusive:!1};const o=await oe(r).catch(()=>null);if(o===null)return{wallet:e,boundTo:r,canOwn:!1,boundLive:!1,inconclusive:!0};const i=n.find(c=>fe(o.owner,c.address));return{wallet:e,boundTo:r,canOwn:!!i,signerKind:i==null?void 0:i.kind,boundLive:!Pt(o)&&St(o),inconclusive:!1}}async function ga(e,a){return Promise.all(e.map(n=>wt(n,a)))}function bt(e){return e.inconclusive||e.boundTo==null?{kind:"register"}:e.canOwn?{kind:"deregisterThenRegister",prevAccountId:e.boundTo}:e.boundLive?{kind:"skipSponsored",prevAccountId:e.boundTo}:{kind:"conflictSponsorDead",prevAccountId:e.boundTo}}function va(e){const a=e.map(w=>({binding:w,kind:bt(w).kind})),n=w=>a.filter(A=>A.kind===w).map(A=>A.binding),s=n("register"),r=s.filter(w=>w.inconclusive),o=s.filter(w=>!w.inconclusive),i=n("deregisterThenRegister"),c=n("skipSponsored"),f=n("conflictSponsorDead"),x=[...o,...i],v=e.length>0&&x.length===0&&r.length===0;return{selfCoverable:x,ownBound:i,sponsorBound:c,sponsorDead:f,inconclusive:r,zeroSelfCoverage:v}}const wa=(e,a)=>{try{const n=BigInt(e.stake),s=BigInt(a.stake);return n===s?0:n>s?-1:1}catch{return 0}};function ba(e=!0){const[a,n]=g.useState([]),[s,r]=g.useState(!0),[o,i]=g.useState(!1),c=g.useRef(!0),f=g.useRef(!1),x=g.useCallback(async w=>{r(!0),i(!1);try{const A=await Rt(w?{fresh:!0}:void 0);c.current&&n([...A.nodes].sort(wa))}catch{c.current&&(n([]),i(!0))}finally{c.current&&r(!1)}},[]);g.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),g.useEffect(()=>{e&&!f.current&&(f.current=!0,x(!1))},[e,x]);const v=g.useCallback(()=>{x(!0)},[x]);return{nodes:a,loading:s,error:o,refresh:v}}function ya(e){const{seedPrimaryNode:a,replacingAccountId:n,identityId:s,stakedNodes:r,nodesError:o,nodesLoading:i,enabled:c=!0}=e,[f,x]=g.useState(a??""),v=s&&s!=="0"?String(s):null,w=g.useMemo(()=>v&&r.some(N=>N.identityId===v)?v:null,[v,r]);g.useEffect(()=>{!c||f||!v||i||(w?x(w):o&&x(v))},[c,f,v,w,o,i]),g.useEffect(()=>{!c||n||o||i||v&&f===v&&!w&&x("")},[c,n,o,i,r.length,v,f,w]);const A=g.useCallback(()=>x(""),[]);return{primaryNode:f,setPrimaryNode:x,ownStaked:w,onRejected:A}}const xa="Approve exact TRAC allowance",Aa="Confirm on-chain receipt";function Ca(e){const a=[];return e.requiresApproval&&a.push({id:"approve",label:e.approveLabel??xa,state:"pending"}),a.push({id:"action",label:e.actionLabel,state:"pending"}),a.push({id:"confirm",label:e.confirmLabel??Aa,state:"pending"}),a}function Na({labels:e,flow:a,describeApproveError:n,describeActionError:s}){const r=g.useRef(void 0),[o,i]=g.useState([]),[c,f]=g.useState(e.idle),x=h=>Ca(a(h)),v=n??(h=>Y(h,"approve").message),w=s??(h=>Y(h,"action").message),A=h=>typeof e.actionActive=="function"?e.actionActive(h):e.actionActive;return{steps:o,currentLabel:c,onProgress:h=>{const l=r.current;f(()=>h.step==="approve"?h.state==="skipped"||h.state==="confirmed"?e.approveReady:h.state==="failed"?e.failed:e.approveActive:h.state==="active"?A(l):h.state==="submitted"?e.submitted:h.state==="confirmed"?e.confirmed:e.failed),i(k=>{const u=(k.length?k:x(l)).map(j=>({...j})),p=u.find(j=>j.id==="approve"),b=u.find(j=>j.id==="action"),y=u.find(j=>j.id==="confirm");return h.step==="approve"?(p&&(h.state==="skipped"?(p.state="confirmed",p.label="TRAC allowance already sufficient"):h.state==="active"||h.state==="submitted"?(p.state="active",p.txHash=h.txHash):h.state==="confirmed"?(p.state="confirmed",p.txHash=h.txHash):h.state==="failed"&&(p.state="failed",p.txHash=h.txHash,p.error=v(h.error))),u):(h.state==="active"?((p==null?void 0:p.state)==="pending"&&(p.state="confirmed"),b.state="active"):h.state==="submitted"?((p==null?void 0:p.state)==="pending"&&(p.state="confirmed"),b.state="confirmed",b.txHash=h.txHash,y.state="active"):h.state==="confirmed"?((p==null?void 0:p.state)==="pending"&&(p.state="confirmed"),b.state="confirmed",b.txHash=h.txHash,y.state="confirmed",y.txHash=h.txHash):h.state==="failed"&&(b.state="failed",b.txHash=h.txHash,b.error=w(h.error,l)),u)})},begin:h=>{r.current=h;const l=x(h);i(l);const k=l.some(u=>u.id==="approve");f(k?e.approveActive:A(h))},reset:()=>{r.current=void 0,i([]),f(e.idle)},initialSteps:x}}function me({onClose:e,title:a,subtitle:n,testId:s,children:r,dismissDisabled:o=!1}){const i=g.useCallback(()=>{o||e()},[o,e]),{dialogRef:c,onBackdropClick:f}=Et(!0,i),x=g.useRef(null);return g.useEffect(()=>{queueMicrotask(()=>{var v;return(v=x.current)==null?void 0:v.focus()})},[]),t.jsx("div",{className:"v10-modal-overlay",onClick:f,role:"presentation",children:t.jsxs("div",{className:"v10-modal-box v10-pca-modal-box","data-testid":s,ref:c,role:"dialog","aria-modal":"true","aria-labelledby":"pca-modal-title",children:[t.jsx("button",{type:"button",className:"v10-modal-close",onClick:i,"aria-label":o?"Close disabled while signing":"Close dialog",title:o?"Finish or reject the wallet prompt first":"Close (Esc)",disabled:o,style:{position:"absolute",top:12,right:12,background:"none",border:"none",color:"var(--text-tertiary)",cursor:o?"not-allowed":"pointer",fontSize:18,lineHeight:1,padding:4,zIndex:1,opacity:o?.45:1},children:"×"}),t.jsxs("div",{className:"v10-modal-header",children:[t.jsx("h2",{id:"pca-modal-title",className:"v10-modal-title",tabIndex:-1,ref:x,children:a}),n&&t.jsx("div",{className:"v10-modal-subtitle",children:n})]}),r]})})}function Ne(e){const a=e/100;return`${a%1===0?a.toFixed(0):a.toFixed(1)}%`}const ka=/^\d+(\.\d+)?$/;function _a({onClose:e,onApproveOwnWallets:a,onManage:n,onGetSponsored:s,seed:r,replacingAccountId:o,initialOwnerKey:i}){var Qe,Ze,Je;const c=Ot(d=>d.nodeStatus),f=(c==null?void 0:c.nodeRole)==="edge"||(c==null?void 0:c.hasIdentity)===!1,x=c==null,v=(c==null?void 0:c.blockExplorerUrl)??null,{data:w}=ke(Fe,[],0),A=(w==null?void 0:w.wallets)??[],N=A[0],R=(Ze=(Qe=w==null?void 0:w.balances)==null?void 0:Qe.find(d=>d.address===N))==null?void 0:Ze.trac,H=R!=null?Number(R):NaN,h=A.join(","),[l,k]=g.useState(i??"hardware"),u=K(d=>d.address),p=K(d=>d.provider),b=K(d=>d.bootstrap),y=K(d=>d.expectedChainId),j=K(d=>d.chainId),D=K(d=>Ue(d)),E=l==="hardware",I=Na({labels:{idle:"Confirm on your device",approveActive:"Confirm on your device (1 of 2): approve TRAC",approveReady:"Allowance ready — continue to Create PCA",actionActive:"Confirm on your device (2 of 2): Create PCA",submitted:"Waiting for on-chain confirmation",confirmed:"Create confirmed on-chain",failed:"Wallet transaction failed"},flow:()=>({requiresApproval:!0,actionLabel:"Sign Create PCA"})}),Q=Me({ownerKey:l,onWalletProgress:I.onProgress}),ne=he(d=>d.finishCreate),re=he(d=>d.setCreatePending),W=he(d=>d.clearCreatePending),F=he.getState().createPending,Z=he(d=>d.createPendingPersisted),[m,L]=g.useState((r==null?void 0:r.tokens)??""),[P,B]=g.useState(F?"reconcile":"form"),[$,Se]=g.useState(null),[J,se]=g.useState(F==null?void 0:F.txHash),[ve,U]=g.useState(null),z=P==="form"&&!x,we=g.useMemo(()=>[{address:N,kind:"daemon"},...E?[{address:u,kind:"wallet"}]:[]],[E,N,u]),{data:de}=ke(()=>z?ga(A,we):Promise.resolve([]),[h,N,u,E,z],0),G=g.useMemo(()=>va(de??[]),[de]),{nodes:ue,loading:pe,error:O,refresh:ie}=ba(z),{primaryNode:ee,setPrimaryNode:Re,ownStaked:C,onRejected:S}=ya({seedPrimaryNode:r==null?void 0:r.primaryNode,replacingAccountId:o,identityId:c==null?void 0:c.identityId,stakedNodes:ue,nodesError:O,nodesLoading:pe,enabled:z}),_=ka.test(m.trim())?Number(m.trim()):NaN,M=Number.isFinite(_)&&_>0,q=l!=="hardware"&&M&&Number.isFinite(H)&&_>H,te=M&&_<25e3,ae=g.useMemo(()=>dt(M?_:null),[_,M]),be=/^\d+$/.test(ee.trim())&&Number(ee.trim())>0,Xe=!!p&&!!u&&!!b&&y!=null&&j===y,Ye=!E||ue.some(d=>String(d.identityId)===ee.trim()),X=E?u??void 0:N,yt=M&&!q&&be&&!!X&&!x&&P==="form"&&(!E||Xe&&Ye),Ee=E&&P==="creating",Oe=u?D?"Switch the connected wallet to this node's PCA network before signing.":b?null:"PCA contract addresses are still loading for wallet signing.":"Connect the owner wallet before choosing the hardware path.",xt=async()=>{if(E){if(!Xe){U(Oe??"Connect the owner wallet before signing.");return}if(!Ye){S(),ie(),U("The selected primary node is no longer in the live staked-node list. Pick another staked node before signing.");return}}if(B("creating"),U(null),E?I.begin("create"):I.reset(),X&&!re({ownerEoa:X,submittedAt:Date.now()})){W(),U("Create is blocked because this browser cannot save the create-pending safety marker. Enable local storage or use a browser profile where site storage is available."),B("form");return}try{const d=await Q.create({tokens:m.trim(),primaryNode:ee.trim()});ne(d.accountId);const T=await oe(d.accountId).catch(()=>null);Se({...d,snapshot:T}),B("success")}catch(d){if(d instanceof Be&&(d.status===400||It(d))){W();const T=ot(d);(T==null?void 0:T.code)==="PrimaryNodeNotInShardingTable"&&(S(),ie()),U((T==null?void 0:T.message)??(d==null?void 0:d.message)??"Create failed."),B("form");return}if(d instanceof ce){if(d.txStep==="action"&&d.txHash){se(d.txHash),X&&re({ownerEoa:X,submittedAt:Date.now(),txHash:d.txHash}),B("reconcile");return}W();const T=Y(d,"approve");U(`${T.message} Retry will re-check the allowance before asking you to sign again.`),B("form");return}if(d instanceof Ke){W(),U(Y(d,"action").message),B("form");return}if(E){W();const T=Y(d,"action");T.kind==="revert"&&T.revertName==="PrimaryNodeNotInShardingTable"&&(S(),ie()),U(T.kind==="rejected"?"The TRAC allowance is set, but account not created because you rejected the Create PCA signature. Retry to finish (no new approval needed).":T.message),B("form");return}if(d instanceof Be&&d.status===504){const T=d.body??{};T.txHash&&(se(T.txHash),X&&re({ownerEoa:X,submittedAt:Date.now(),txHash:T.txHash}))}B("reconcile")}};if(P==="reconcile"){const d=v&&J?`${v}/tx/${J}`:void 0,T=(F==null?void 0:F.ownerEoa)??X??N;return t.jsxs(me,{onClose:e,testId:"pca-create-modal",title:"Confirm before retrying",children:[t.jsxs("div",{className:"v10-modal-body",children:[t.jsxs("div",{className:"v10-modal-warning",role:"alert",children:["⚠ Your create transaction was submitted but we lost confirmation. We’re checking the chain before letting you retry — creating again could lock a ",t.jsx("strong",{children:"second"})," commitment of TRAC."]}),t.jsxs("div",{className:"v10-pca-create-recon",children:[J&&t.jsxs("p",{children:["Broadcast tx"," ",d?t.jsxs("a",{href:d,target:"_blank",rel:"noreferrer",children:[J," ↗"]}):t.jsx("code",{children:J})]}),Z?t.jsxs("p",{children:["A “create-pending” marker is saved, so this guard survives a refresh. Verify on the explorer whether a PCA was minted to ",t.jsx("code",{children:T??"your owner wallet"}),":"]}):t.jsxs("p",{className:"v10-pca-create-warn",role:"alert",children:["⚠ This browser blocked saving the safety marker (storage disabled or full), so this guard will ",t.jsx("strong",{children:"NOT"})," survive a refresh. Do not create again until you’ve verified on the explorer whether a PCA was minted to"," ",t.jsx("code",{children:T??"your owner wallet"}),":"]}),t.jsxs("ul",{className:"v10-pca-create-recon-actions",children:[t.jsxs("li",{children:["If a PCA ",t.jsx("strong",{children:"was"})," minted → close this, then use “Track PCA by ID” on the overview."]}),t.jsxs("li",{children:["If ",t.jsx("strong",{children:"none"})," was minted → clear the marker below, then you can create again."]})]})]})]}),t.jsxs("div",{className:"v10-modal-footer",children:[d&&t.jsx("a",{className:"v10-modal-btn",href:d,target:"_blank",rel:"noreferrer",children:"Recheck on explorer ↗"}),t.jsx("button",{type:"button",className:"v10-modal-btn",onClick:()=>{W(),se(void 0),B("form")},children:"No PCA minted — clear & retry"}),t.jsx("button",{type:"button",className:"v10-modal-btn",onClick:e,children:"Close"})]})]})}if(x)return t.jsxs(me,{onClose:e,testId:"pca-create-modal",title:"Checking node eligibility…",children:[t.jsx("div",{className:"v10-modal-body",children:t.jsx("p",{className:"v10-pca-create-hint",role:"status",children:"Confirming this node can create a Publisher Conviction Account…"})}),t.jsx("div",{className:"v10-modal-footer",children:t.jsx("button",{type:"button",className:"v10-modal-btn",onClick:e,children:"Close"})})]});if(P==="success"&&$){const d=(Je=$.snapshot)==null?void 0:Je.discountBps,T=ae.bps,At=typeof d=="number"&&d!==T,et=v&&$.txHash?`${v}/tx/${$.txHash}`:void 0;return t.jsxs(me,{onClose:e,testId:"pca-create-modal",title:`PCA #${$.accountId} created`,children:[t.jsx("div",{className:"v10-modal-body",children:t.jsxs("div",{className:"v10-pca-create-success","data-testid":"pca-create-success",children:[t.jsxs("div",{className:"v10-pca-create-success-stats",children:[t.jsxs("span",{children:["Account ",t.jsxs("strong",{children:["#",$.accountId]})]}),typeof d=="number"&&t.jsxs("span",{children:["Discount tier ",t.jsx("strong",{children:Ne(d)})]}),t.jsxs("span",{children:["Committed ",t.jsxs("strong",{children:[We($.committedTokens)," TRAC"]})]})]}),At&&t.jsxs("p",{className:"v10-pca-create-warn",children:["Heads up: the created account returned a ",Ne(d)," discount tier instead of the previewed ",Ne(T)," tier."]}),$.txHash&&t.jsxs("p",{className:"v10-pca-create-tx",children:["Tx"," ",et?t.jsxs("a",{href:et,target:"_blank",rel:"noreferrer",children:[$.txHash," ↗"]}):t.jsx("code",{children:$.txHash})]}),t.jsx("div",{className:"v10-pca-create-warn",role:"alert",children:"⚠ 0/100 wallets approved — this PCA discounts nothing yet. It covers nothing until you approve this node’s operational (signing) wallets."})]})}),t.jsxs("div",{className:"v10-modal-footer",children:[t.jsx("button",{type:"button",className:"v10-modal-btn primary","data-testid":"pca-approve-own-wallets",onClick:()=>a($.accountId),children:o?`Re-approve PCA #${o}’s wallets`:"Approve this node’s operational wallets"}),t.jsxs("button",{type:"button",className:"v10-modal-btn",onClick:()=>n($.accountId),children:["Manage PCA #",$.accountId]})]})]})}return t.jsxs(me,{onClose:e,testId:"pca-create-modal",title:o?`Renew — new PCA to replace #${o}`:"Create a Publisher Conviction Account",subtitle:o?"Re-mint a fresh account seeded from the expiring one.":"Lock TRAC up front to publish at a discount.",dismissDisabled:Ee,children:[t.jsxs("div",{className:"v10-modal-body",children:[ve&&t.jsx("div",{className:"v10-modal-error",role:"alert",children:ve}),E&&P==="creating"&&t.jsx("div",{className:"v10-modal-warning",role:"status","data-testid":"pca-create-hw-lock",children:"Finish or reject the prompt in your wallet. Closing, backdrop click, and Esc are disabled while the approve-to-create sequence is in flight."}),E&&P==="creating"&&t.jsx(ut,{steps:I.steps.length?I.steps:I.initialSteps(),currentLabel:I.currentLabel,blockExplorerUrl:v}),t.jsxs("section",{className:"v10-pca-create-section","data-testid":"pca-create-owner-key",children:[t.jsx("h3",{className:"v10-pca-create-section-title",children:"1 · Owner key"}),t.jsxs("div",{className:"v10-pca-owner-key-grid",role:"radiogroup","aria-label":"PCA owner key",children:[t.jsxs("label",{className:`v10-pca-owner-key-card${l==="hardware"?" selected":""}`,children:[t.jsx("input",{type:"radio",name:"pca-owner-key",value:"hardware",checked:l==="hardware",onChange:()=>k("hardware"),disabled:P==="creating"}),t.jsxs("span",{children:[t.jsx("strong",{children:"Hardware wallet (recommended)"}),t.jsx("small",{children:"If your browser wallet is backed by a device, verify the amount and contract there. The app cannot verify hardware backing from provider metadata."})]})]}),t.jsxs("label",{className:`v10-pca-owner-key-card${l==="hot"?" selected":""}`,children:[t.jsx("input",{type:"radio",name:"pca-owner-key",value:"hot",checked:l==="hot",onChange:()=>k("hot"),disabled:P==="creating"}),t.jsxs("span",{children:[t.jsx("strong",{children:"This node's hot wallet"}),t.jsx("small",{children:"No connected browser wallet is required. The daemon signs with this node's primary operational wallet."})]})]})]}),E?t.jsxs("div",{className:"v10-pca-owner-key-readiness",children:[t.jsx(qt,{testId:"pca-wallet-connect"}),Oe&&t.jsx("p",{className:"v10-pca-create-warn",role:"status","data-testid":"pca-create-hw-readiness",children:Oe})]}):N?t.jsxs("div",{className:"v10-pca-create-owner",children:[t.jsx("span",{className:"v10-pca-card-owner-lbl",children:"Hot owner"}),t.jsx(ge,{address:N})]}):null]}),f&&!o&&t.jsx("div",{className:"v10-modal-tip",role:"status","data-testid":"pca-create-no-identity-note",children:"This node has no staked identity of its own — you can still create a PCA by choosing a staked node as its primary node below (you get the discount; the reward weight accrues to the node you pick)."}),G.zeroSelfCoverage&&t.jsxs("div",{className:"v10-modal-warning",role:"alert","data-testid":"pca-b1-zero-coverage",children:["⚠ All of this node’s operational wallets are already approved on other PCAs",G.sponsorBound.length>0?" (you already get the discount free where those are live)":"",". This new account will ",t.jsx("strong",{children:"NOT"})," discount your own publishes. Create it only if you intend to approve publishing wallets for other nodes; otherwise getting added to an existing PCA avoids locking TRAC."]}),G.sponsorDead.length>0&&t.jsxs("div",{className:"v10-modal-warning",role:"alert","data-testid":"pca-b1-sponsor-dead",children:["Warning: ",G.sponsorDead.length," of this node's wallet(s) are approved on another PCA that is",t.jsx("strong",{children:" expired or swept"})," - they are ",t.jsx("strong",{children:"not covered"}),", and this node cannot free them (it does not own that account). Ask that PCA owner to remove you, then re-approve them here; otherwise they stay uncovered."]}),!G.zeroSelfCoverage&&G.sponsorBound.length>0&&t.jsxs("div",{className:"v10-modal-tip",role:"status","data-testid":"pca-b1-preview",children:["After creating, ",G.sponsorBound.length," of your wallet(s) stay on another PCA (already discounted) and will not be moved; the rest are approved on the new account (any already on a PCA you own are deregistered from it first)."]}),!G.zeroSelfCoverage&&G.ownBound.length>0&&t.jsxs("div",{className:"v10-modal-warning",role:"status","data-testid":"pca-b1-own-bound",children:["⚠ ",G.ownBound.length," of this node’s wallet(s) are already approved on a PCA you own. Self-coverage will ",t.jsx("strong",{children:"move"})," them — deregister from that account, then approve on the new one. The old account’s committed TRAC stays locked until its own expiry and would then cover nothing, so only proceed if you’re replacing it."]}),o&&t.jsxs("div",{className:"v10-modal-warning",role:"status","data-testid":"pca-renew-note",children:["ⓘ This creates a ",t.jsx("strong",{children:"new, separate"})," account (a new id) — it does not extend or reclaim PCA #",o,". The old account’s committed TRAC stays locked until its own expiry (it can’t be withdrawn early), and the new account starts at ",t.jsx("strong",{children:"0/100"}),"approved wallets. The next step is pre-filled with the old account’s wallets for one-step re-approval."]}),t.jsxs("section",{className:"v10-pca-create-section",children:[t.jsx("h3",{className:"v10-pca-create-section-title",children:"2 · Commitment"}),t.jsxs("div",{className:"v10-form-group",children:[t.jsx("label",{className:"v10-form-label",htmlFor:"pca-create-tokens",children:"Commit amount (TRAC)"}),t.jsx("input",{id:"pca-create-tokens","data-testid":"pca-create-tokens",className:"v10-form-input",type:"text",inputMode:"decimal",value:m,onChange:d=>L(d.target.value),placeholder:"100000",autoComplete:"off"})]}),l!=="hardware"&&R!=null&&t.jsxs("p",{className:"v10-pca-create-balance",children:["Owner wallet balance: ",We(R)," TRAC",q&&t.jsx("span",{className:"v10-pca-create-err",children:" — exceeds balance"})]}),te&&t.jsx("div",{className:"v10-modal-warning",children:"⚠ Under 25,000 TRAC earns a 0% discount — you’d lock TRAC for no benefit."}),t.jsx(Ut,{committedTrac:M?_:null})]}),t.jsxs("section",{className:"v10-pca-create-section","data-testid":"pca-create-primary-node",children:[t.jsx("h3",{className:"v10-pca-create-section-title",children:"3 · Primary node"}),o&&(r==null?void 0:r.primaryNodeUnknown)&&t.jsxs("p",{className:"v10-pca-create-hint",role:"status","data-testid":"pca-renew-primary-unknown",children:["ⓘ Couldn’t read PCA #",o,"’s primary node — defaulting to this node. Pick a different staked node below if the replacement should point elsewhere."]}),t.jsx(Gt,{nodes:ue,loading:pe,error:O,onRetry:ie,value:ee,onChange:Re,ownIdentityId:C,role:(c==null?void 0:c.nodeRole)==="edge"?"edge":(c==null?void 0:c.nodeRole)==="core"?"core":void 0,required:!0})]}),t.jsxs("section",{className:"v10-pca-create-section",children:[t.jsx("h3",{className:"v10-pca-create-section-title",children:"4 · Review"}),t.jsxs("div",{className:"v10-pca-create-review",children:[t.jsxs("div",{children:[t.jsx("span",{children:"Commit"}),t.jsx("strong",{children:M?`${We(m)} TRAC`:"—"})]}),t.jsxs("div",{children:[t.jsx("span",{children:"Discount tier"}),t.jsx("strong",{children:Ne(ae.bps)})]}),t.jsxs("div",{children:[t.jsx("span",{children:"Primary node"}),t.jsx("strong",{children:be?`#${ee.trim()}`:"—"})]})]}),X&&t.jsxs("div",{className:"v10-pca-create-owner",children:[t.jsx("span",{className:"v10-pca-card-owner-lbl",children:"Owner"}),t.jsx(ge,{address:X,status:E?"connected wallet":"hot wallet"})]}),t.jsxs("p",{className:"v10-pca-create-owner-note",children:["Owner = the wallet that signs the create. ",t.jsx("strong",{children:"Being the owner does not discount your own publishes"})," — you approve your publishing wallets in the next step."]}),t.jsx("div",{className:"v10-modal-tip",children:"Committed TRAC is locked for the lock period (a global protocol parameter — there’s no lock-length input). The owner wallet still needs native gas to create the account."})]})]}),t.jsxs("div",{className:"v10-modal-footer",children:[t.jsx("button",{type:"button",className:"v10-modal-btn",onClick:()=>{Ee||e()},disabled:Ee,children:"Cancel"}),t.jsx("button",{type:"button",className:"v10-modal-btn primary","data-testid":"pca-create-submit",onClick:xt,disabled:!yt,children:P==="creating"?t.jsx("span",{role:"status",children:"Creating…"}):"Create PCA"})]})]})}function ja(e){const a=K(s=>s.address),n=K(s=>Ue(s));return Ge({owner:e.owner,primaryWallet:e.primaryWallet,connectedWallet:a,walletWrongNetwork:n,primaryWalletState:e.primaryWalletState})}const Ta={pending:"approving…",approved:"approved on-chain",submitted:"submitted — verify",skipped:"already approved here (skipped)",sponsored:"left on another PCA (already discounted)",stranded:"removed from the old PCA, not yet on the new one — retry to finish",conflict:"on another PCA",cap:"cap reached",error:"failed",aborted:"aborted",unverified:"already approved somewhere — couldn’t verify; retry"},Pa={pending:"neutral",approved:"success",submitted:"neutral",skipped:"neutral",sponsored:"neutral",stranded:"warn",conflict:"danger",cap:"warn",error:"danger",aborted:"neutral",unverified:"neutral"};function Sa(e){if(e instanceof ze||e instanceof qe)return e.message;if(e instanceof ce)return`${Y(e,e.txStep??"action").message} Stop here and verify before continuing.`;if(e instanceof Ke)return Y(e,"action").message;const a=Y(e,e instanceof Ve?e.txStep:"action");return a.kind==="rejected"||a.kind==="insufficient_funds"||a.kind==="rpc_timeout"||a.kind==="unknown"?a.message:null}function Le(e){return e instanceof ze||e instanceof qe||e instanceof ce||e instanceof Ke||e instanceof Ve?Sa(e):null}function Ra(e,a){const n=Y(e,e instanceof Ve?e.txStep:"action");if(n.kind!=="revert")return null;switch(n.revertName){case"AgentAlreadyRegistered":return{code:"AgentAlreadyRegistered",status:400,message:"This operational wallet is already approved on another PCA - deregister it there first."};case"AgentCapReached":return{code:"AgentCapReached",status:400,message:`PCA #${a} already has the maximum 100 approved publishing wallets.`};case"NotAccountOwner":return{code:"NotAccountOwner",status:403,message:`This wallet is not the owner of PCA #${a}, so it cannot manage it.`};default:return null}}const Ea={order:[],rows:{},running:!1,done:!1,aborted:null,verificationDelayed:null,deviceSteps:[],deviceLabel:void 0,walletBatchSigning:!1};function Oa(e,a){var n;switch(a.type){case"BATCH_START":return{...e,order:a.order,rows:Object.fromEntries(a.order.map(s=>[s,{address:s,status:"pending"}])),running:!0,done:!1,aborted:null,verificationDelayed:null,deviceSteps:[],deviceLabel:void 0,walletBatchSigning:!1};case"SET_WALLET_BATCH_SIGNING":return{...e,walletBatchSigning:a.signing};case"ROW_SET":return{...e,rows:{...e.rows,[a.address]:a.row}};case"MARK_REMAINING":{const s={...e.rows,[a.current.address]:a.current};for(const r of e.order)((n=s[r])==null?void 0:n.status)==="pending"&&(s[r]={address:r,status:a.status,message:a.message});return{...e,rows:s}}case"SET_ABORTED":return{...e,aborted:a.message};case"SET_VERIFICATION_DELAYED":return{...e,verificationDelayed:a.message};case"DEVICE_PROMPT_START":return{...e,deviceLabel:a.indexLabel,deviceSteps:[...e.deviceSteps,{id:a.id,label:a.label,state:"active"}]};case"DEVICE_PROMPT_CONFIRMED":return{...e,deviceSteps:e.deviceSteps.map(s=>s.id===a.id?{...s,state:"confirmed",txHash:a.txHash}:s)};case"DEVICE_PROMPT_SUBMITTED":return{...e,deviceSteps:e.deviceSteps.map(s=>s.id===a.id?{...s,state:"submitted",txHash:a.txHash,error:"confirmation delayed - recheck on-chain"}:s)};case"DEVICE_PROMPT_FAILED":return{...e,deviceSteps:e.deviceSteps.map(s=>s.id===a.id?{...s,state:"failed",error:a.error}:s)};case"BATCH_DONE":return{...e,running:!1,walletBatchSigning:!1,done:!0};default:return e}}function Ia(e){const a=e.order.map(n=>e.rows[n]).filter(Boolean);return{confirmed:a.filter(n=>n.status==="approved").length,submitted:a.filter(n=>n.status==="submitted").length,skipped:a.filter(n=>n.status==="skipped").length,sponsored:a.filter(n=>n.status==="sponsored").length,stranded:a.filter(n=>n.status==="stranded").length,conflict:a.filter(n=>n.status==="conflict").length,error:a.filter(n=>n.status==="error"||n.status==="cap").length,aborted:a.filter(n=>n.status==="aborted").length,unverified:a.filter(n=>n.status==="unverified").length}}function Wa(e){return e.order.filter(a=>{var s;const n=(s=e.rows[a])==null?void 0:s.status;return n==="approved"||n==="submitted"})}async function $a(e,a,n,s){var h;const{addresses:r,accountId:o,mode:i,selfCoverage:c,deregisterFrom:f,targetWalletManaged:x,signableOwners:v}=e;n({type:"BATCH_START",order:r});const w=new Map;if(c&&i==="self")for(const l of r){const k=await a.resolveWalletBinding(l,v);w.set(l,{action:a.planSelfCoverage(k),signerKind:k.signerKind})}const A=await a.signerKindForAccount(f),N=r.reduce((l,k)=>{if(f)return l+(A==="wallet"?1:0)+(x?1:0);if(c&&i==="self"){const u=w.get(k);if((u==null?void 0:u.action.kind)==="skipSponsored"||(u==null?void 0:u.action.kind)==="conflictSponsorDead")return l;const p=(u==null?void 0:u.action.kind)==="deregisterThenRegister"&&u.signerKind==="wallet"?1:0;return l+p+(x?1:0)}return l+(x?1:0)},0);n({type:"SET_WALLET_BATCH_SIGNING",signing:N>0});let R=0;const H=async(l,k,u=!1)=>{if(!u)return k();const p=R+1;R=p;const b=Math.max(N,p),y=`${p}-${l}`;n({type:"DEVICE_PROMPT_START",id:y,label:l,indexLabel:`Confirm on your device (${p} of ${b})`});try{const j=await k();return n({type:"DEVICE_PROMPT_CONFIRMED",id:y,txHash:j.txHash}),j}catch(j){throw j instanceof ce&&j.txHash?n({type:"DEVICE_PROMPT_SUBMITTED",id:y,txHash:j.txHash}):n({type:"DEVICE_PROMPT_FAILED",id:y,error:(j==null?void 0:j.message)??"Action failed."}),j}};for(const l of r){if(s()){n({type:"ROW_SET",address:l,row:{address:l,status:"error",message:"stopped"}});continue}let k=null;try{if(f)try{await H(`Deregister ${l} from PCA #${f}`,()=>a.deregisterRenew(f,l),A==="wallet"),k=f}catch(p){if(A==="wallet"&&Le(p))throw p}else if(c&&i==="self"){let p=w.get(l);if(!p){const y=await a.resolveWalletBinding(l,v);p={action:a.planSelfCoverage(y),signerKind:y.signerKind}}const b=p.action;if(b.kind==="skipSponsored"){n({type:"ROW_SET",address:l,row:{address:l,status:"sponsored",message:`Stays on PCA #${b.prevAccountId} - already discounted.`}});continue}if(b.kind==="conflictSponsorDead"){n({type:"ROW_SET",address:l,row:{address:l,status:"conflict",message:`Approved on PCA #${b.prevAccountId}, but it’s expired/swept (not covering) — ask its owner to deregister you; this node can’t free it.`}});continue}if(b.kind==="deregisterThenRegister")try{await H(`Deregister ${l} from PCA #${b.prevAccountId}`,()=>a.deregisterSelf(b.prevAccountId,l),p.signerKind==="wallet"),k=b.prevAccountId}catch(y){if(p.signerKind==="wallet"&&Le(y))throw y}}const u=await H(`Approve ${l} on PCA #${o}`,()=>a.registerAgent(o,l),x);n({type:"ROW_SET",address:l,row:{address:l,status:u.registered?"approved":"submitted",txHash:u.txHash}})}catch(u){const p=()=>({address:l,status:"stranded",message:`Removed from PCA #${k}, not yet on #${o} — retry to finish.`}),b=Le(u);if(u instanceof ce&&u.txHash&&(u.txStep??"action")==="action"){n({type:"SET_VERIFICATION_DELAYED",message:`Transaction ${u.txHash} was broadcast, but receipt verification failed. Recheck on-chain before retrying.`}),n({type:"MARK_REMAINING",current:{address:l,status:"submitted",txHash:u.txHash,message:"Broadcast; verify on-chain before retrying."},status:"aborted",message:"not run - verify the previous transaction first"});break}if(b){n({type:"SET_ABORTED",message:b}),n({type:"MARK_REMAINING",current:k?p():{address:l,status:"error",message:b},status:"aborted",message:"aborted"});break}if(u instanceof Be&&u.status===403){n({type:"SET_ABORTED",message:`This node isn’t the owner of PCA #${o} — approval aborted.`}),n({type:"MARK_REMAINING",current:k?p():{address:l,status:"error",message:"owner-only"},status:"error",message:"aborted"});break}const y=a.describePcaError(u,{accountId:o})??Ra(u,o);if((y==null?void 0:y.code)==="AgentCapReached"){n({type:"MARK_REMAINING",current:{address:l,status:"cap",message:y.message},status:"cap"});break}if((y==null?void 0:y.code)==="AgentAlreadyRegistered"){const j=await a.probePca(o,l).catch(()=>null),D=j==null?void 0:j.probedKey;(D==null?void 0:D.registered)===!0?n({type:"ROW_SET",address:l,row:{address:l,status:"skipped",message:"Already an approved publishing wallet here."}}):(D==null?void 0:D.registered)===!1&&D.adapterSupported!==!1?n({type:"ROW_SET",address:l,row:{address:l,status:"conflict",message:y.message}}):n({type:"ROW_SET",address:l,row:{address:l,status:"unverified"}})}else n({type:"ROW_SET",address:l,row:k?p():{address:l,status:"error",message:(y==null?void 0:y.message)??(u==null?void 0:u.message)}})}}n({type:"BATCH_DONE"}),(h=a.onApproved)==null||h.call(a)}const Ha=/^0x[0-9a-fA-F]{40}$/;function Ma({accountId:e,initialMode:a="sponsor",onClose:n,onApproved:s,seedBulk:r,deregisterFrom:o,seedAgentsResolved:i,selfCoverage:c}){const{data:f,error:x}=ke(Fe,[],0),{data:v}=ke(()=>oe(e),[e]),w=Me(),A=(f==null?void 0:f.wallets)??[],N=A[0],R=K(C=>C.address),H=K(C=>Ue(C)),h=aa(f,x),l=ja({owner:v==null?void 0:v.owner,primaryWallet:N,primaryWalletState:h}),k=ha({access:l}),u=Me(),p=(v==null?void 0:v.agentCount)??0,b=Math.max(0,100-p),[y,j]=g.useState(a),[D,E]=g.useState({}),[I,Q]=g.useState({}),[ne,re]=g.useState(r??""),[W,F]=g.useReducer(Oa,Ea),Z=g.useRef(!1),m=g.useMemo(()=>{const C=new Set,S=[];let _=0;for(const M of ne.split(`
3
3
  `).map(q=>q.trim()).filter(Boolean)){if(!Ha.test(M)){_+=1;continue}const q=M.toLowerCase();C.has(q)||(C.add(q),S.push(M))}return{valid:S,invalid:_}},[ne]);g.useEffect(()=>{let C=!1;async function S(){const _=await Promise.all(A.map(async q=>{var te;try{const ae=await oe(e,q,{extended:!0});return[q,String(ae.accountId)===String(e)&&((te=ae.probedKey)==null?void 0:te.registered)===!0]}catch{return[q,!1]}}));if(C)return;const M=Object.fromEntries(_);Q(M),E(q=>{const te={...q};for(const[ae,be]of _)be&&te[ae]===void 0&&(te[ae]=!0);return te})}return A.length===0?(Q({}),()=>{C=!0}):(S(),()=>{C=!0})},[e,A.join("|")]);const L=g.useMemo(()=>A.filter(C=>!I[C]&&!D[C]),[I,A,D]),P=y==="self"?L:m.valid,B=P.length>b,$=ra(l,v==null?void 0:v.owner,R),Se=ma(N,R),J=async()=>{P.length!==0&&(Z.current=!1,await $a({addresses:P,accountId:e,mode:y,selfCoverage:c,deregisterFrom:o,targetWalletManaged:$,signableOwners:Se},{registerAgent:k.registerAgent,deregisterRenew:w.deregisterAgent,deregisterSelf:u.deregisterAgent,resolveWalletBinding:wt,planSelfCoverage:bt,signerKindForAccount:C=>ua({accountId:C,primaryWallet:N,connectedWallet:R,walletWrongNetwork:H}),probePca:oe,describePcaError:ot,onApproved:s},F,()=>Z.current))},{order:se,rows:ve,running:U,done:z,aborted:we,verificationDelayed:de,deviceSteps:G,deviceLabel:ue,walletBatchSigning:pe}=W,O=g.useMemo(()=>Ia(W),[W.order,W.rows]),ie=Wa(W),ee=se.length>0,Re=A.filter(C=>I[C]).length;return t.jsxs(me,{onClose:n,testId:"pca-approve-modal",title:`Approve publishing wallets — PCA #${e}`,dismissDisabled:pe,children:[t.jsxs("div",{className:"v10-modal-body",children:[t.jsx("div",{className:"v10-form-group",children:t.jsxs("div",{className:"v10-form-radio-group",role:"radiogroup","aria-label":"Approval mode",children:[t.jsxs("label",{className:"v10-form-radio",children:[t.jsx("input",{type:"radio",checked:y==="self",onChange:()=>j("self"),disabled:U}),"Approve my own node’s wallets"]}),t.jsxs("label",{className:"v10-form-radio",children:[t.jsx("input",{type:"radio",checked:y==="sponsor",onChange:()=>j("sponsor"),disabled:U}),"Approve another node’s wallets"]})]})}),y==="self"?t.jsxs("section",{className:"v10-pca-approve-self",children:[t.jsxs("p",{className:"v10-pca-create-warn",children:[p," / 100 slots used — ",Re," of this node's wallets are already approved here. Unapproved wallets pay the direct cost until you approve them."]}),t.jsxs("div",{className:"v10-pca-approve-checklist",children:[A.map((C,S)=>t.jsxs("label",{className:"v10-pca-approve-self-row",children:[t.jsx("input",{type:"checkbox",checked:!I[C]&&!D[C],onChange:_=>E(M=>({...M,[C]:!_.target.checked})),disabled:U||I[C],"aria-label":`Approve ${C}`}),t.jsx(ge,{address:C,status:I[C]?"already approved here":S===0?"primary signer":void 0,statusTone:I[C]?"success":"neutral"})]},C)),A.length===0&&t.jsx("p",{className:"v10-pca-handshake-empty",children:"No operational wallets detected on this node."})]}),t.jsx("div",{className:"v10-modal-tip",children:"A new PCA covers NOTHING until you approve your own signing wallets. Each is a separate on-chain tx you sign (~30s, owner gas)."})]}):t.jsxs("section",{className:"v10-pca-approve-sponsor",children:[t.jsx(Ft,{mode:"bulk",testId:"pca-approve-address",value:ne,onChange:re,label:"Wallet address(es) — one per line",disabled:U}),t.jsxs("p",{className:"v10-pca-approve-counts",children:[m.valid.length," valid · ",m.invalid," invalid ·"," ",p," → ",p+m.valid.length," of 100 after this"]}),o?t.jsxs("div",{className:"v10-modal-warning","data-testid":"pca-renew-reapprove-note",children:["ⓘ Re-approving PCA #",o,"’s wallets on #",e,". Each wallet is MOVED — deregistered from #",o,", then approved on #",e," (two txs per wallet, owner gas). Account expiry alone doesn’t free a wallet, so this is required to re-use them.",i===!1&&t.jsxs(t.Fragment,{children:[" ",t.jsxs("strong",{children:["Couldn’t load PCA #",o,"’s wallets — add them manually below."]})]})]}):t.jsx("div",{className:"v10-modal-warning",children:"⚠ We can only check the address is well-formed — we can’t verify it’s the node’s real signing wallet. A typo / admin / author address still “approves” and burns a cap slot. Confirm it shows as approved in the other operator's Get added to a PCA panel."})]}),B&&t.jsxs("div",{className:"v10-modal-warning",role:"status",children:["⚠ Up to ",b," of these can be approved. Any already approved here are skipped (no slot used); any genuinely beyond the ",b,"-slot cap are marked “cap reached”."]}),we&&t.jsx("div",{className:"v10-modal-error",role:"alert",children:we}),de&&t.jsx("div",{className:"v10-modal-warning",role:"status",children:de}),G.length>0&&t.jsx(ut,{steps:G,currentLabel:ue??"Confirm on your device"}),ee&&t.jsxs("div",{className:"v10-pca-approve-results",role:"status","aria-live":"polite",children:[se.map(C=>{const S=ve[C];return S?t.jsx(ge,{address:C,status:S.message&&(S.status==="conflict"||S.status==="error"||S.status==="sponsored"||S.status==="stranded"||S.status==="submitted"||S.status==="aborted")?S.message:Ta[S.status],statusTone:Pa[S.status]},C):null}),z&&t.jsxs("p",{className:"v10-pca-approve-summary",children:["Approved ",O.confirmed," confirmed",O.submitted>0?` · ${O.submitted} submitted (verify)`:""," ","· ",O.skipped," already here · ",O.conflict," conflict",O.sponsored>0?` · ${O.sponsored} left on another PCA`:"",O.stranded>0?` · ${O.stranded} need a retry`:"",O.error>0?` · ${O.error} failed`:"",O.unverified>0?` · ${O.unverified} unverified`:""," (of ",se.length,")."]})]}),z&&O.stranded>0&&t.jsxs("div",{className:"v10-modal-warning",role:"alert","data-testid":"pca-approve-stranded",children:["⚠ ",O.stranded," wallet",O.stranded===1?" was":"s were"," removed from the old PCA but not yet re-approved on #",e," — temporarily UNCOVERED. Click “Retry to finish” to complete the move."]}),z&&y==="sponsor"&&!o&&t.jsxs("div",{className:"v10-pca-approve-handoff",children:[t.jsx("div",{className:"v10-modal-warning",children:"Remind the other operator: these wallets must hold NATIVE GAS to publish — the account covers TRAC, never gas."}),t.jsx(Kt,{wallets:ie,accountId:e,role:"core"}),t.jsxs("p",{className:"v10-pca-approve-counts",children:["Account id to share back: ",t.jsxs("strong",{children:["#",e]})," ",t.jsx(it,{value:e,label:`Copy account id ${e}`})]})]})]}),t.jsxs("div",{className:"v10-modal-footer",children:[t.jsx("button",{type:"button",className:"v10-modal-btn",onClick:n,disabled:pe,children:z?"Done":"Cancel"}),U?t.jsx("button",{type:"button",className:"v10-modal-btn",onClick:()=>{Z.current=!0},children:"Stop"}):z?O.stranded>0?t.jsx("button",{type:"button",className:"v10-modal-btn primary","data-testid":"pca-approve-retry-stranded",onClick:J,children:"Retry to finish"}):null:t.jsxs("button",{type:"button",className:"v10-modal-btn primary","data-testid":"pca-approve-submit",onClick:J,disabled:P.length===0,children:["Approve ",P.length," wallet",P.length===1?"":"s"]})]})]})}export{Ft as A,_a as C,ut as D,Ba as H,me as P,Ma as a,qt as b,aa as c,ha as d,Na as e,na as o,Qt as p,Ge as r,ja as u};
@@ -1 +1 @@
1
- import{aO as t}from"./index-MQh8C4aJ.js";const d={neutral:"var(--border-strong)",wm:"var(--layer-working, #64748b)",swm:"var(--layer-shared, #f59e0b)",vm:"var(--layer-verified, #22c55e)",danger:"var(--text-danger)",query:"#38bdf8",warning:"var(--text-warning)"};function m(e){return e}function h({icon:e,title:s,description:r,actions:n=[],tone:i="neutral",compact:a=!1,inline:c=!1,className:v=""}){const o={"--v10-empty-accent":d[i]};return t.jsxs("div",{className:["v10-empty-state",a?"compact":"",c?"inline":"",v].filter(Boolean).join(" "),"data-tone":i,style:o,children:[e&&t.jsx("div",{className:"v10-empty-state-icon","aria-hidden":"true",children:e}),t.jsxs("div",{className:"v10-empty-state-copy",children:[t.jsx("div",{className:"v10-empty-state-title",children:s}),r&&t.jsx("div",{className:"v10-empty-state-desc",children:r}),n.length>0&&t.jsx("div",{className:"v10-empty-state-actions",children:n.map(l=>t.jsx("button",{type:"button",className:`v10-empty-state-action ${l.variant??"secondary"}`,onClick:l.onClick,"data-testid":l.testId,children:l.label},l.label))})]})]})}function y({items:e,layer:s,compact:r=!1,className:n=""}){const i=s?{"--v10-stat-accent":d[s]}:void 0;return t.jsx("div",{className:["v10-stat-strip",r?"compact":"",n].filter(Boolean).join(" "),"data-layer":s,style:i,children:e.map((a,c)=>t.jsxs("div",{className:"v10-stat-strip-cell","data-stat-id":a.id,title:a.tooltip,children:[t.jsx("span",{className:"v10-stat-strip-label",children:a.label}),t.jsx("span",{className:"v10-stat-strip-value",children:a.value}),a.hint&&t.jsx("span",{className:"v10-stat-strip-hint",children:a.hint})]},a.id??c))})}export{h as E,y as S,m as t};
1
+ import{aU as t}from"./index-HEpqHVfE.js";const d={neutral:"var(--border-strong)",wm:"var(--layer-working, #64748b)",swm:"var(--layer-shared, #f59e0b)",vm:"var(--layer-verified, #22c55e)",danger:"var(--text-danger)",query:"#38bdf8",warning:"var(--text-warning)"};function m(e){return e}function h({icon:e,title:s,description:r,actions:n=[],tone:i="neutral",compact:a=!1,inline:c=!1,className:v=""}){const o={"--v10-empty-accent":d[i]};return t.jsxs("div",{className:["v10-empty-state",a?"compact":"",c?"inline":"",v].filter(Boolean).join(" "),"data-tone":i,style:o,children:[e&&t.jsx("div",{className:"v10-empty-state-icon","aria-hidden":"true",children:e}),t.jsxs("div",{className:"v10-empty-state-copy",children:[t.jsx("div",{className:"v10-empty-state-title",children:s}),r&&t.jsx("div",{className:"v10-empty-state-desc",children:r}),n.length>0&&t.jsx("div",{className:"v10-empty-state-actions",children:n.map(l=>t.jsx("button",{type:"button",className:`v10-empty-state-action ${l.variant??"secondary"}`,onClick:l.onClick,"data-testid":l.testId,children:l.label},l.label))})]})]})}function y({items:e,layer:s,compact:r=!1,className:n=""}){const i=s?{"--v10-stat-accent":d[s]}:void 0;return t.jsx("div",{className:["v10-stat-strip",r?"compact":"",n].filter(Boolean).join(" "),"data-layer":s,style:i,children:e.map((a,c)=>t.jsxs("div",{className:"v10-stat-strip-cell","data-stat-id":a.id,title:a.tooltip,children:[t.jsx("span",{className:"v10-stat-strip-label",children:a.label}),t.jsx("span",{className:"v10-stat-strip-value",children:a.value}),a.hint&&t.jsx("span",{className:"v10-stat-strip-hint",children:a.hint})]},a.id??c))})}export{h as E,y as S,m as t};
@@ -1,2 +1,2 @@
1
- import{aO as e,bO as $,bK as R,bd as y,aW as G,b8 as J,aq as P,H as Q,B as E,bz as S,aV as M,a7 as W,bM as X,ar as V,ai as Z,bw as I,N as L,aC as ee,aw as ae}from"./index-MQh8C4aJ.js";import{A as te,a as Y,C as ne,u as se,e as re,d as le,H as oe,b as ie,D as ce,c as de}from"./ApproveWalletsModal-Dd_tHLRP.js";import{e as U,o as q,L as pe,d as B,f as ue,c as me,b as he}from"./browserWalletTransaction-CBgx0i4w.js";import{S as ve}from"./ContextGraphPrimitives-BXormriD.js";const D=(a,t)=>!!a&&!!t&&a.toLowerCase()===t.toLowerCase();function we({agents:a,nodeWallets:t,ownerIsPrimary:r,ownerTitle:l,confirmRemove:s,onAskRemove:n,onCancelRemove:i,onConfirmRemove:v,removeBusy:u,explorer:p}){return e.jsx("div",{className:"v10-pca-detail-agentlist","data-testid":"pca-agent-list",children:a.map(c=>{const h=t.some(f=>D(f,c)),o=D(s??void 0,c);return e.jsx("div",{className:"v10-pca-agent-row","data-testid":"pca-agent-row",children:e.jsx(U,{address:c,status:h?"approved · this node":"approved",statusTone:"success",trailing:o?e.jsxs("span",{className:"v10-pca-agent-confirm",children:[e.jsx("span",{children:h?"This is one of this node’s own signing wallets — its publishes will pay the direct cost (and revert if it holds no TRAC). Remove?":"Publishes from this wallet will pay the direct cost (and revert if it holds no TRAC). Remove?"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","data-testid":"pca-deregister-btn","aria-label":`Confirm removing ${c}`,onClick:()=>v(c),disabled:u,children:u?"Removing…":"Yes, remove"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Cancel removing ${c}`,onClick:i,disabled:u,children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[p&&e.jsx("a",{className:"v10-pca-card-explorer",href:`${p}/address/${c}`,target:"_blank",rel:"noreferrer","aria-label":`View ${c} on explorer`,children:"↗"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Remove ${c}`,onClick:()=>n(c),disabled:!r,title:l,children:"Remove"})]})})},c)})})}function ge(){const a=$(l=>l.setBootstrap),t=$(l=>l.initWallet),r=R(l=>l.setScope);y.useEffect(()=>{let l=!1;return G().then(s=>{l||(r(J(s)),a(s))}).catch(()=>{}).finally(()=>{l||t()}),()=>{l=!0}},[t,r,a])}function be(a){return a==="topup"?{requiresApproval:!0,actionLabel:"Sign top-up"}:{requiresApproval:!1,actionLabel:"Sign remove wallet"}}function _(a,t){const r=q(a,"action");return t==="remove"&&r.kind==="rejected"?"You rejected the remove-wallet transaction. No wallet was removed.":r.message}const fe={busy:!1,error:null,result:null};function K(){return y.useState(fe)}function xe({accountId:a,setFund:t,refresh:r}){const l=R(i=>i.topUpPending[a]??null),s=R(i=>i.clearTopUpPending),n=$(i=>i.bootstrap);y.useEffect(()=>{var p;if(!l||!((p=n==null?void 0:n.rpcUrls)!=null&&p.length))return;let i=!1,v=null;const u=async()=>{try{const h=await pe(n.chainId,n.rpcUrls).getTransactionReceipt({hash:l.txHash});if(i)return;s(a),h.status==="success"?(t({busy:!1,error:null,warning:null,result:{txHash:l.txHash,message:"Top-up confirmed on-chain."}}),r()):t({busy:!1,error:"The pending top-up transaction reverted on-chain.",warning:null,result:null})}catch{i||(v=setTimeout(u,5e3))}};return u(),()=>{i=!0,v&&clearTimeout(v)}},[a,s,r,t,l,n])}function ye({accountId:a,snapshot:t,ownerTrac:r,explorer:l,access:s,ownerTitle:n,owner:i,deviceProgress:v,refresh:u}){const p=R(b=>b.topUpPending[a]??null),c=R(b=>b.setTopUpPending),h=R(b=>b.clearTopUpPending),[o,f]=y.useState(""),[m,w]=K();xe({accountId:a,setFund:w,refresh:u});const C=async()=>{var b,x;s.mode==="wallet"?v.begin("topup"):v.reset(),w({busy:!0,error:null,result:null,warning:null});try{const d=await i.topUp(a,o.trim());h(a),w({busy:!1,error:null,result:{txHash:d.txHash,message:`Added ${P(d.addedTokens)} TRAC.`}}),f(""),u()}catch(d){if(d instanceof Q&&d.status===504){const j=(b=d.body)==null?void 0:b.txHash;if(j){c({accountId:a,ownerEoa:t.owner,submittedAt:Date.now(),txHash:j,tokens:o.trim(),previousTopUpBufferTrac:t.topUpBufferTrac}),w({busy:!1,error:null,result:null,warning:{txHash:j,message:"Your top-up was submitted but we lost confirmation — it may already be on-chain. Verify on the explorer before adding again; a second top-up would lock additional TRAC."}});return}}if(d instanceof B&&d.txStep==="action"&&d.txHash){c({accountId:a,ownerEoa:t.owner,submittedAt:Date.now(),txHash:d.txHash,tokens:o.trim(),previousTopUpBufferTrac:t.topUpBufferTrac}),w({busy:!1,error:null,result:null,warning:{txHash:d.txHash,message:"Your top-up was submitted but we lost confirmation - it may already be on-chain. This exact transaction is being checked; do not add again until it resolves."}});return}if(s.mode==="wallet"){const j=q(d,d instanceof ue?d.txStep:d instanceof B?d.txStep??"action":"action");w({busy:!1,error:j.message,result:null,warning:d instanceof me?null:void 0});return}w({busy:!1,error:((x=E(d,{accountId:a}))==null?void 0:x.message)??(d==null?void 0:d.message)??"Top-up failed.",result:null})}};return e.jsxs("section",{className:"v10-pca-detail-section",children:[e.jsx("h3",{className:"v10-pca-detail-section-title",children:"Funding"}),e.jsxs("p",{className:"v10-pca-detail-hint",children:["Top-up raises the spendable buffer. It does ",e.jsx("strong",{children:"not"})," extend the lock period — when the account expires you create a new one."]}),r!=null&&e.jsxs("p",{className:"v10-pca-detail-hint",children:["Owner balance: ",P(r)," TRAC"]}),e.jsxs("div",{className:"v10-pca-detail-form",children:[e.jsx("input",{className:"v10-form-input",type:"text",inputMode:"decimal",value:o,onChange:b=>f(b.target.value),placeholder:"Top up (TRAC)",disabled:!s.writesEnabled||m.busy||!!p,"aria-label":"Top-up amount in TRAC"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn primary","data-testid":"pca-topup-btn",onClick:C,disabled:!s.writesEnabled||m.busy||!!p||!/^\d+(\.\d+)?$/.test(o.trim())||Number(o.trim())<=0,title:n,children:m.busy?"Adding…":"Add funds"})]}),e.jsx(Ce,{state:m,explorer:l,onRecheck:u}),p&&e.jsxs("p",{className:"v10-pca-create-warn","data-testid":"pca-topup-pending",role:"alert",children:["Top-up transaction ",e.jsx("code",{children:p.txHash})," is pending confirmation. The top-up button is disabled while this exact receipt is checked; adding again could lock more TRAC."," ",e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:u,children:"Recheck account"})]})]})}function Ce({state:a,explorer:t,onRecheck:r}){if(a.warning){const s=t&&a.warning.txHash?`${t}/tx/${a.warning.txHash}`:void 0;return e.jsxs("p",{className:"v10-pca-create-warn","data-testid":"pca-action-warning",role:"alert",children:[a.warning.message," ",a.warning.txHash&&(s?e.jsxs("a",{href:s,target:"_blank",rel:"noreferrer",children:[a.warning.txHash," ↗"]}):e.jsx("code",{children:a.warning.txHash}))," ",r&&e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:r,children:"Recheck"})]})}if(a.error)return e.jsx("p",{className:"v10-modal-error",role:"alert",children:a.error});if(!a.result)return null;const l=t&&a.result.txHash?`${t}/tx/${a.result.txHash}`:void 0;return e.jsxs("p",{className:"v10-pca-detail-result","data-testid":"pca-action-result",role:"status",children:[a.result.message," ",l&&e.jsx("a",{href:l,target:"_blank",rel:"noreferrer",children:"tx ↗"})," ","Still pending? You can close this and verify here."]})}const je=/^0x[0-9a-fA-F]{40}$/;function Ne({accountId:a,snapshot:t,wallets:r,explorer:l,access:s,ownerTitle:n,owner:i,deviceProgress:v,refresh:u}){const[p,c]=y.useState(""),[h,o]=y.useState(null),[f,m]=y.useState(null),[w,C]=K(),[b,x]=y.useState(!1),{data:d,loading:j,refresh:N}=S(()=>M(a),[a]),k=d&&d.accountId===a?d:null,z=async()=>{var T,A;o(null);const g=p.trim();if(!je.test(g)){o("Enter a valid 0x address.");return}try{const O=(T=(await W(a,g)).probedKey)==null?void 0:T.registered;o(O===!0?`✓ ${g} is an approved publishing wallet here.`:O===!1?`✗ ${g} is NOT approved here.`:`Couldn’t determine whether ${g} is approved here — retry.`)}catch(F){o(((A=E(F,{accountId:a}))==null?void 0:A.message)??"Probe failed.")}},H=async g=>{var T;s.mode==="wallet"?v.begin("remove"):v.reset(),C({busy:!0,error:null,result:null});try{await i.deregisterAgent(a,g),C({busy:!1,error:null,result:{message:`Removed ${g}.`}}),m(null),u(),N()}catch(A){C({busy:!1,error:s.mode==="wallet"?_(A,"remove"):((T=E(A,{accountId:a}))==null?void 0:T.message)??(A==null?void 0:A.message)??"Remove failed.",result:null})}};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"v10-pca-detail-section",children:[e.jsxs("h3",{className:"v10-pca-detail-section-title",children:["Publishing wallets — ",t.agentCount," / 100"]}),e.jsxs("div",{className:"v10-pca-detail-form",children:[e.jsx(te,{mode:"single",value:p,onChange:c,label:"Check a wallet",cruxNote:null}),e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:z,children:"Probe"})]}),h&&e.jsx("p",{className:"v10-pca-detail-hint",role:"status",children:h}),j&&!k?e.jsx("p",{className:"v10-pca-detail-hint",role:"status",children:"Loading approved wallets…"}):k?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"v10-pca-detail-subhead",children:"Approved publishing wallets:"}),k.agents.length>0?e.jsx(we,{agents:k.agents,nodeWallets:r,ownerIsPrimary:s.writesEnabled,ownerTitle:n,confirmRemove:f,onAskRemove:g=>m(g),onCancelRemove:()=>m(null),onConfirmRemove:g=>H(g),removeBusy:w.busy,explorer:l}):e.jsx("div",{className:"v10-pca-detail-agentlist","data-testid":"pca-agent-list",children:e.jsx("p",{className:"v10-pca-handshake-empty",children:"No approved publishing wallets yet."})})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"v10-pca-detail-subhead",children:"This node’s wallets:"}),e.jsxs("div",{className:"v10-pca-detail-agentlist","data-testid":"pca-agent-list",children:[r.map(g=>e.jsx(Ae,{accountId:a,wallet:g,ownerIsPrimary:s.writesEnabled,ownerTitle:n,confirming:f===g,onAskRemove:()=>m(g),onCancelRemove:()=>m(null),onConfirmRemove:()=>H(g),removeBusy:w.busy},g)),r.length===0&&e.jsx("p",{className:"v10-pca-handshake-empty",children:"No operational wallets on this node."})]}),e.jsx("p",{className:"v10-pca-overview-caveat",children:"ⓘ The chain exposes how many wallets are approved, not the full list — only this node’s wallets and any you probe are shown here."})]}),w.error&&e.jsx("p",{className:"v10-modal-error",role:"alert",children:w.error}),w.result&&e.jsx("p",{className:"v10-pca-detail-result",role:"status","data-testid":"pca-remove-result",children:w.result.message}),e.jsx("button",{type:"button",className:"v10-pca-card-btn primary",onClick:()=>x(!0),disabled:!s.writesEnabled,title:n,children:"+ Approve publishing wallet"})]}),b&&e.jsx(Y,{accountId:a,initialMode:"self",onClose:()=>{x(!1),u(),N()}})]})}function Ae({accountId:a,wallet:t,ownerIsPrimary:r,ownerTitle:l,confirming:s,onAskRemove:n,onCancelRemove:i,onConfirmRemove:v,removeBusy:u}){var m;const{data:p,loading:c,error:h}=S(()=>W(a,t),[a,t]),o=(m=p==null?void 0:p.probedKey)==null?void 0:m.registered,f=!c&&(h!=null||p!=null&&o==null);return e.jsx("div",{className:"v10-pca-agent-row","data-testid":"pca-agent-row",children:e.jsx(U,{address:t,status:o===!0?"approved":o===!1?"not approved":f?"couldn’t determine":"checking…",statusTone:o===!0?"success":o===!1?"danger":"neutral",trailing:o===!0?s?e.jsxs("span",{className:"v10-pca-agent-confirm",children:[e.jsx("span",{children:"This is one of this node’s own signing wallets — its publishes will pay the direct cost (and revert if it holds no TRAC). Remove?"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","data-testid":"pca-deregister-btn","aria-label":`Confirm removing ${t}`,onClick:v,disabled:u,children:u?"Removing…":"Yes, remove"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Cancel removing ${t}`,onClick:i,disabled:u,children:"Cancel"})]}):e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Remove ${t}`,onClick:n,disabled:!r,title:l,children:"Remove"}):void 0})})}function Re(a){const[t,r]=y.useState(!1),[l,s]=y.useState(!1),[n,i]=y.useState(null),v=X(c=>c.openTab);return{renewOpen:t,renewChaining:l,renewApprove:n,openRenew:()=>r(!0),closeRenew:()=>r(!1),onRenewSuccess:c=>{r(!1),s(!0),M(a).then(h=>({agents:h.agents,resolved:!0})).catch(()=>({agents:[],resolved:!1})).then(({agents:h,resolved:o})=>{s(!1),i({newAccountId:c,seedBulk:h.join(`
2
- `),agentsResolved:o})})},onManageNew:c=>{r(!1),v({id:`conviction:${c}`,label:`PCA #${c}`,closable:!0})},clearRenewApprove:()=>i(null)}}function Te({accountId:a,snapshot:t,access:r,ownerTitle:l,health:s}){const n=Re(a);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"v10-pca-detail-section",children:[e.jsx("h3",{className:"v10-pca-detail-section-title",children:"Lifecycle"}),(s==="expiring"||s==="expired")&&e.jsxs("p",{className:"v10-pca-card-warn",children:[V(t.expiresAtTimestamp),". The lock period can’t be extended — Renew creates a fresh replacement account seeded from this one (the old TRAC stays locked until its own expiry)."]}),e.jsx("button",{type:"button",className:`v10-pca-card-btn${s==="expiring"||s==="expired"?" primary":""}`,"data-testid":"pca-renew-btn",onClick:()=>n.openRenew(),disabled:!r.writesEnabled,title:l,children:"Renew — create a replacement PCA"})]}),n.renewOpen&&e.jsx(ne,{seed:{tokens:t.committedTRACTrac,primaryNode:t.primaryNode&&t.primaryNode!=="0"?String(t.primaryNode):void 0,primaryNodeUnknown:t.primaryNode==null},replacingAccountId:a,initialOwnerKey:r.mode==="wallet"?"hardware":"hot",onClose:()=>n.closeRenew(),onApproveOwnWallets:n.onRenewSuccess,onManage:n.onManageNew,onGetSponsored:()=>n.closeRenew()}),n.renewChaining&&e.jsx("div",{className:"lazy-spinner",role:"status","data-testid":"pca-renew-chaining",children:"Preparing re-approval…"}),n.renewApprove&&e.jsx(Y,{accountId:n.renewApprove.newAccountId,initialMode:"sponsor",seedBulk:n.renewApprove.seedBulk,deregisterFrom:a,seedAgentsResolved:n.renewApprove.agentsResolved,onClose:()=>n.clearRenewApprove()})]})}function Pe(a){return V(a).replace(/^Expires in /,"")}function Ue({accountId:a}){var d,j;const{data:t,loading:r,error:l,refresh:s}=S(()=>W(a,void 0,{extended:!0}),[a]),n=(t==null?void 0:t.accountId)===a?t:null,{data:i,error:v,refresh:u}=S(Z,[],0),p=I(N=>N.nodeStatus),c=(p==null?void 0:p.blockExplorerUrl)??null,h=$(N=>N.address),o=(i==null?void 0:i.wallets)??[],f=de(i,v),m=se({owner:n==null?void 0:n.owner,primaryWallet:o[0],primaryWalletState:f});if(ge(),r&&!n)return e.jsxs("div",{className:"lazy-spinner",children:["Loading PCA #",a,"…"]});if(l||!n)return e.jsx("div",{className:"v10-pca-detail",children:e.jsx("div",{className:"card",children:e.jsxs("div",{className:"card-body v10-pca-card-error",children:[e.jsxs("p",{children:["Couldn’t load PCA #",a,"."]}),e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:()=>s(),children:"Retry"})]})})});const w=o.some(N=>L(N,n.owner)),C=m.ownerUnknownCause==="wallets-loading",b=m.ownerUnknownCause==="wallets-unreadable",x=C?`Confirming ownership of PCA #${a}…`:b?`Couldn't load this node's wallets - can't confirm ownership of PCA #${a}.`:m.mode==="wallet"&&m.wrongNetwork?`Wrong network - switch the connected wallet to this node's PCA network to manage PCA #${a}.`:m.mode==="wallet"?`Connected wallet ${n.owner} owns PCA #${a}; device-signed owner actions are enabled.`:w?`Owner-only - PCA #${a} is owned by ${n.owner}, not this node's primary operational wallet, so node-UI can't sign for it.`:h?`Owner-only - connected as ${h}; switch to ${n.owner} to manage PCA #${a}.`:`Owner-only - connect ${n.owner} to manage PCA #${a}.`;return e.jsx(ke,{accountId:a,snapshot:n,wallets:o,ownerTrac:(j=(d=i==null?void 0:i.balances)==null?void 0:d.find(N=>L(N.address,n.owner)))==null?void 0:j.trac,explorer:c,access:m,connectedWallet:h,ownerOnlyReason:x,walletsLoading:C,walletsUnreadable:b,onRetryWallets:u,refresh:s})}function ke({accountId:a,snapshot:t,wallets:r,ownerTrac:l,explorer:s,access:n,connectedWallet:i,ownerOnlyReason:v,walletsLoading:u,walletsUnreadable:p,onRetryWallets:c,refresh:h}){const o=re({labels:{idle:"Confirm on your device",approveActive:"Confirm on your device (1 of 2): approve TRAC",approveReady:"Allowance ready — continue to the owner action",actionActive:x=>x==="remove"?"Confirm on your device: remove wallet":"Confirm on your device (2 of 2): top up",submitted:"Waiting for on-chain confirmation",confirmed:"Transaction confirmed on-chain",failed:"Wallet transaction failed"},flow:x=>be(x??"topup"),describeActionError:(x,d)=>_(x,d??"topup")}),f=le({access:n,onWalletProgress:n.mode==="wallet"?o.onProgress:void 0}),m=ee(t),w=n.writesEnabled?void 0:v,C=(t.discountBps/100).toFixed(t.discountBps%100===0?0:1),b=i?n.mode==="wallet"?n.wrongNetwork?"Owner wallet matches; switch network before signing owner actions.":"Connected owner wallet will sign top-up, approve, remove, and renewal actions.":n.mode==="daemon"?"Connected wallet is available for wallet-owned PCAs; this account uses the node daemon for owner actions.":`Connected as ${i}; switch to ${t.owner} to manage owner actions.`:n.mode==="external"?"Connect the PCA owner wallet to manage this account. Provider metadata is display-only.":"Connect a wallet to view and manage wallet-owned PCAs from this tab.";return e.jsxs("div",{className:"v10-pca-detail","data-testid":"pca-detail",children:[e.jsxs("div",{className:"v10-pca-detail-band",children:[e.jsxs("span",{className:"v10-pca-detail-id",children:["PCA #",a]}),e.jsxs("span",{className:"badge badge-info",children:["◉ ",C,"% discount"]}),e.jsxs("span",{className:"v10-pca-detail-committed",children:[P(t.committedTRACTrac)," TRAC committed"]}),e.jsx("span",{className:"v10-pca-card-spacer"}),e.jsx(oe,{state:m})]}),e.jsxs("div",{className:"v10-modal-tip",role:"status",children:[b,i?e.jsx(he,{}):e.jsx(ie,{testId:"pca-wallet-connect"})]}),o.steps.length>0&&e.jsx(ce,{steps:o.steps,currentLabel:o.currentLabel,blockExplorerUrl:s}),!n.writesEnabled&&(u?e.jsx("div",{className:"v10-modal-tip",role:"status",children:v}):e.jsxs("div",{className:"v10-modal-warning",role:"status",children:["ⓘ ",v," ",p?e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:c,children:"Retry"}):"Wallet probe stays available."]})),e.jsx(ve,{items:[{id:"buffer",label:"Top-up buffer",value:`${P(t.topUpBufferTrac)} TRAC`},{id:"per-epoch",label:"TRAC per epoch",value:`${ae(t.baseEpochAllowance)} TRAC`},...t.remainingAllowanceTrac!=null?[{id:"remaining",label:"Remaining this epoch",value:`${P(t.remainingAllowanceTrac)} TRAC`,tooltip:t.currentEpoch!=null?`Current epoch ${t.currentEpoch}`:void 0}]:[],{id:"wallets",label:"Publishing wallets",value:`${t.agentCount} / 100`},{id:"expires",label:"Expires in",value:Pe(t.expiresAtTimestamp),tooltip:`Expiry epoch ${t.expiresAtEpoch}`},...t.primaryNode!=null?[{id:"primary-node",label:"Primary node",value:t.primaryNode==="0"?"None set":`Node #${t.primaryNode}`,tooltip:t.lastPrimaryNodeChangeEpoch!=null?`Last changed epoch ${t.lastPrimaryNodeChangeEpoch}`:void 0}]:[]]}),e.jsxs("div",{className:"v10-pca-detail-owner",children:[e.jsx("span",{className:"v10-pca-card-owner-lbl",children:"Owner"}),e.jsx(U,{address:t.owner,trailing:s?e.jsx("a",{className:"v10-pca-card-explorer",href:`${s}/address/${t.owner}`,target:"_blank",rel:"noreferrer","aria-label":"View owner on explorer",children:"↗"}):void 0})]}),e.jsx(ye,{accountId:a,snapshot:t,ownerTrac:l,explorer:s,access:n,ownerTitle:w,owner:f,deviceProgress:o,refresh:h}),e.jsx(Ne,{accountId:a,snapshot:t,wallets:r,explorer:s,access:n,ownerTitle:w,owner:f,deviceProgress:o,refresh:h}),e.jsx(Te,{accountId:a,snapshot:t,access:n,ownerTitle:w,health:m})]})}export{Ue as ConvictionDetailView};
1
+ import{aU as e,bV as $,bR as R,bj as y,a$ as z,be as X,av as P,H as J,F as E,bG as S,a_ as M,ac as U,bT as Q,aw as V,an as Z,bD as I,X as O,aH as ee,aB as ae}from"./index-HEpqHVfE.js";import{A as te,a as Y,C as ne,u as se,e as re,d as le,H as oe,b as ie,D as ce,c as de}from"./ApproveWalletsModal-CzWJ4KyU.js";import{e as W,o as _,L as pe,d as B,f as ue,c as me,b as he}from"./browserWalletTransaction-BJBFRjXx.js";import{S as ve}from"./ContextGraphPrimitives-ecppTns4.js";const D=(a,t)=>!!a&&!!t&&a.toLowerCase()===t.toLowerCase();function we({agents:a,nodeWallets:t,ownerIsPrimary:r,ownerTitle:l,confirmRemove:s,onAskRemove:n,onCancelRemove:i,onConfirmRemove:v,removeBusy:u,explorer:p}){return e.jsx("div",{className:"v10-pca-detail-agentlist","data-testid":"pca-agent-list",children:a.map(c=>{const h=t.some(f=>D(f,c)),o=D(s??void 0,c);return e.jsx("div",{className:"v10-pca-agent-row","data-testid":"pca-agent-row",children:e.jsx(W,{address:c,status:h?"approved · this node":"approved",statusTone:"success",trailing:o?e.jsxs("span",{className:"v10-pca-agent-confirm",children:[e.jsx("span",{children:h?"This is one of this node’s own signing wallets — its publishes will pay the direct cost (and revert if it holds no TRAC). Remove?":"Publishes from this wallet will pay the direct cost (and revert if it holds no TRAC). Remove?"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","data-testid":"pca-deregister-btn","aria-label":`Confirm removing ${c}`,onClick:()=>v(c),disabled:u,children:u?"Removing…":"Yes, remove"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Cancel removing ${c}`,onClick:i,disabled:u,children:"Cancel"})]}):e.jsxs(e.Fragment,{children:[p&&e.jsx("a",{className:"v10-pca-card-explorer",href:`${p}/address/${c}`,target:"_blank",rel:"noreferrer","aria-label":`View ${c} on explorer`,children:"↗"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Remove ${c}`,onClick:()=>n(c),disabled:!r,title:l,children:"Remove"})]})})},c)})})}function ge(){const a=$(l=>l.setBootstrap),t=$(l=>l.initWallet),r=R(l=>l.setScope);y.useEffect(()=>{let l=!1;return z().then(s=>{l||(r(X(s)),a(s))}).catch(()=>{}).finally(()=>{l||t()}),()=>{l=!0}},[t,r,a])}function be(a){return a==="topup"?{requiresApproval:!0,actionLabel:"Sign top-up"}:{requiresApproval:!1,actionLabel:"Sign remove wallet"}}function q(a,t){const r=_(a,"action");return t==="remove"&&r.kind==="rejected"?"You rejected the remove-wallet transaction. No wallet was removed.":r.message}const fe={busy:!1,error:null,result:null};function G(){return y.useState(fe)}function xe({accountId:a,setFund:t,refresh:r}){const l=R(i=>i.topUpPending[a]??null),s=R(i=>i.clearTopUpPending),n=$(i=>i.bootstrap);y.useEffect(()=>{var p;if(!l||!((p=n==null?void 0:n.rpcUrls)!=null&&p.length))return;let i=!1,v=null;const u=async()=>{try{const h=await pe(n.chainId,n.rpcUrls).getTransactionReceipt({hash:l.txHash});if(i)return;s(a),h.status==="success"?(t({busy:!1,error:null,warning:null,result:{txHash:l.txHash,message:"Top-up confirmed on-chain."}}),r()):t({busy:!1,error:"The pending top-up transaction reverted on-chain.",warning:null,result:null})}catch{i||(v=setTimeout(u,5e3))}};return u(),()=>{i=!0,v&&clearTimeout(v)}},[a,s,r,t,l,n])}function ye({accountId:a,snapshot:t,ownerTrac:r,explorer:l,access:s,ownerTitle:n,owner:i,deviceProgress:v,refresh:u}){const p=R(b=>b.topUpPending[a]??null),c=R(b=>b.setTopUpPending),h=R(b=>b.clearTopUpPending),[o,f]=y.useState(""),[m,w]=G();xe({accountId:a,setFund:w,refresh:u});const C=async()=>{var b,x;s.mode==="wallet"?v.begin("topup"):v.reset(),w({busy:!0,error:null,result:null,warning:null});try{const d=await i.topUp(a,o.trim());h(a),w({busy:!1,error:null,result:{txHash:d.txHash,message:`Added ${P(d.addedTokens)} TRAC.`}}),f(""),u()}catch(d){if(d instanceof J&&d.status===504){const j=(b=d.body)==null?void 0:b.txHash;if(j){c({accountId:a,ownerEoa:t.owner,submittedAt:Date.now(),txHash:j,tokens:o.trim(),previousTopUpBufferTrac:t.topUpBufferTrac}),w({busy:!1,error:null,result:null,warning:{txHash:j,message:"Your top-up was submitted but we lost confirmation — it may already be on-chain. Verify on the explorer before adding again; a second top-up would lock additional TRAC."}});return}}if(d instanceof B&&d.txStep==="action"&&d.txHash){c({accountId:a,ownerEoa:t.owner,submittedAt:Date.now(),txHash:d.txHash,tokens:o.trim(),previousTopUpBufferTrac:t.topUpBufferTrac}),w({busy:!1,error:null,result:null,warning:{txHash:d.txHash,message:"Your top-up was submitted but we lost confirmation - it may already be on-chain. This exact transaction is being checked; do not add again until it resolves."}});return}if(s.mode==="wallet"){const j=_(d,d instanceof ue?d.txStep:d instanceof B?d.txStep??"action":"action");w({busy:!1,error:j.message,result:null,warning:d instanceof me?null:void 0});return}w({busy:!1,error:((x=E(d,{accountId:a}))==null?void 0:x.message)??(d==null?void 0:d.message)??"Top-up failed.",result:null})}};return e.jsxs("section",{className:"v10-pca-detail-section",children:[e.jsx("h3",{className:"v10-pca-detail-section-title",children:"Funding"}),e.jsxs("p",{className:"v10-pca-detail-hint",children:["Top-up raises the spendable buffer. It does ",e.jsx("strong",{children:"not"})," extend the lock period — when the account expires you create a new one."]}),r!=null&&e.jsxs("p",{className:"v10-pca-detail-hint",children:["Owner balance: ",P(r)," TRAC"]}),e.jsxs("div",{className:"v10-pca-detail-form",children:[e.jsx("input",{className:"v10-form-input",type:"text",inputMode:"decimal",value:o,onChange:b=>f(b.target.value),placeholder:"Top up (TRAC)",disabled:!s.writesEnabled||m.busy||!!p,"aria-label":"Top-up amount in TRAC"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn primary","data-testid":"pca-topup-btn",onClick:C,disabled:!s.writesEnabled||m.busy||!!p||!/^\d+(\.\d+)?$/.test(o.trim())||Number(o.trim())<=0,title:n,children:m.busy?"Adding…":"Add funds"})]}),e.jsx(Ce,{state:m,explorer:l,onRecheck:u}),p&&e.jsxs("p",{className:"v10-pca-create-warn","data-testid":"pca-topup-pending",role:"alert",children:["Top-up transaction ",e.jsx("code",{children:p.txHash})," is pending confirmation. The top-up button is disabled while this exact receipt is checked; adding again could lock more TRAC."," ",e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:u,children:"Recheck account"})]})]})}function Ce({state:a,explorer:t,onRecheck:r}){if(a.warning){const s=t&&a.warning.txHash?`${t}/tx/${a.warning.txHash}`:void 0;return e.jsxs("p",{className:"v10-pca-create-warn","data-testid":"pca-action-warning",role:"alert",children:[a.warning.message," ",a.warning.txHash&&(s?e.jsxs("a",{href:s,target:"_blank",rel:"noreferrer",children:[a.warning.txHash," ↗"]}):e.jsx("code",{children:a.warning.txHash}))," ",r&&e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:r,children:"Recheck"})]})}if(a.error)return e.jsx("p",{className:"v10-modal-error",role:"alert",children:a.error});if(!a.result)return null;const l=t&&a.result.txHash?`${t}/tx/${a.result.txHash}`:void 0;return e.jsxs("p",{className:"v10-pca-detail-result","data-testid":"pca-action-result",role:"status",children:[a.result.message," ",l&&e.jsx("a",{href:l,target:"_blank",rel:"noreferrer",children:"tx ↗"})," ","Still pending? You can close this and verify here."]})}const je=/^0x[0-9a-fA-F]{40}$/;function Ne({accountId:a,snapshot:t,wallets:r,explorer:l,access:s,ownerTitle:n,owner:i,deviceProgress:v,refresh:u}){const[p,c]=y.useState(""),[h,o]=y.useState(null),[f,m]=y.useState(null),[w,C]=G(),[b,x]=y.useState(!1),{data:d,loading:j,refresh:N}=S(()=>M(a),[a]),k=d&&d.accountId===a?d:null,K=async()=>{var T,A;o(null);const g=p.trim();if(!je.test(g)){o("Enter a valid 0x address.");return}try{const L=(T=(await U(a,g)).probedKey)==null?void 0:T.registered;o(L===!0?`✓ ${g} is an approved publishing wallet here.`:L===!1?`✗ ${g} is NOT approved here.`:`Couldn’t determine whether ${g} is approved here — retry.`)}catch(F){o(((A=E(F,{accountId:a}))==null?void 0:A.message)??"Probe failed.")}},H=async g=>{var T;s.mode==="wallet"?v.begin("remove"):v.reset(),C({busy:!0,error:null,result:null});try{await i.deregisterAgent(a,g),C({busy:!1,error:null,result:{message:`Removed ${g}.`}}),m(null),u(),N()}catch(A){C({busy:!1,error:s.mode==="wallet"?q(A,"remove"):((T=E(A,{accountId:a}))==null?void 0:T.message)??(A==null?void 0:A.message)??"Remove failed.",result:null})}};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"v10-pca-detail-section",children:[e.jsxs("h3",{className:"v10-pca-detail-section-title",children:["Publishing wallets — ",t.agentCount," / 100"]}),e.jsxs("div",{className:"v10-pca-detail-form",children:[e.jsx(te,{mode:"single",value:p,onChange:c,label:"Check a wallet",cruxNote:null}),e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:K,children:"Probe"})]}),h&&e.jsx("p",{className:"v10-pca-detail-hint",role:"status",children:h}),j&&!k?e.jsx("p",{className:"v10-pca-detail-hint",role:"status",children:"Loading approved wallets…"}):k?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"v10-pca-detail-subhead",children:"Approved publishing wallets:"}),k.agents.length>0?e.jsx(we,{agents:k.agents,nodeWallets:r,ownerIsPrimary:s.writesEnabled,ownerTitle:n,confirmRemove:f,onAskRemove:g=>m(g),onCancelRemove:()=>m(null),onConfirmRemove:g=>H(g),removeBusy:w.busy,explorer:l}):e.jsx("div",{className:"v10-pca-detail-agentlist","data-testid":"pca-agent-list",children:e.jsx("p",{className:"v10-pca-handshake-empty",children:"No approved publishing wallets yet."})})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"v10-pca-detail-subhead",children:"This node’s wallets:"}),e.jsxs("div",{className:"v10-pca-detail-agentlist","data-testid":"pca-agent-list",children:[r.map(g=>e.jsx(Ae,{accountId:a,wallet:g,ownerIsPrimary:s.writesEnabled,ownerTitle:n,confirming:f===g,onAskRemove:()=>m(g),onCancelRemove:()=>m(null),onConfirmRemove:()=>H(g),removeBusy:w.busy},g)),r.length===0&&e.jsx("p",{className:"v10-pca-handshake-empty",children:"No operational wallets on this node."})]}),e.jsx("p",{className:"v10-pca-overview-caveat",children:"ⓘ The chain exposes how many wallets are approved, not the full list — only this node’s wallets and any you probe are shown here."})]}),w.error&&e.jsx("p",{className:"v10-modal-error",role:"alert",children:w.error}),w.result&&e.jsx("p",{className:"v10-pca-detail-result",role:"status","data-testid":"pca-remove-result",children:w.result.message}),e.jsx("button",{type:"button",className:"v10-pca-card-btn primary",onClick:()=>x(!0),disabled:!s.writesEnabled,title:n,children:"+ Approve publishing wallet"})]}),b&&e.jsx(Y,{accountId:a,initialMode:"self",onClose:()=>{x(!1),u(),N()}})]})}function Ae({accountId:a,wallet:t,ownerIsPrimary:r,ownerTitle:l,confirming:s,onAskRemove:n,onCancelRemove:i,onConfirmRemove:v,removeBusy:u}){var m;const{data:p,loading:c,error:h}=S(()=>U(a,t),[a,t]),o=(m=p==null?void 0:p.probedKey)==null?void 0:m.registered,f=!c&&(h!=null||p!=null&&o==null);return e.jsx("div",{className:"v10-pca-agent-row","data-testid":"pca-agent-row",children:e.jsx(W,{address:t,status:o===!0?"approved":o===!1?"not approved":f?"couldn’t determine":"checking…",statusTone:o===!0?"success":o===!1?"danger":"neutral",trailing:o===!0?s?e.jsxs("span",{className:"v10-pca-agent-confirm",children:[e.jsx("span",{children:"This is one of this node’s own signing wallets — its publishes will pay the direct cost (and revert if it holds no TRAC). Remove?"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","data-testid":"pca-deregister-btn","aria-label":`Confirm removing ${t}`,onClick:v,disabled:u,children:u?"Removing…":"Yes, remove"}),e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Cancel removing ${t}`,onClick:i,disabled:u,children:"Cancel"})]}):e.jsx("button",{type:"button",className:"v10-pca-card-btn","aria-label":`Remove ${t}`,onClick:n,disabled:!r,title:l,children:"Remove"}):void 0})})}function Re(a){const[t,r]=y.useState(!1),[l,s]=y.useState(!1),[n,i]=y.useState(null),v=Q(c=>c.openTab);return{renewOpen:t,renewChaining:l,renewApprove:n,openRenew:()=>r(!0),closeRenew:()=>r(!1),onRenewSuccess:c=>{r(!1),s(!0),M(a).then(h=>({agents:h.agents,resolved:!0})).catch(()=>({agents:[],resolved:!1})).then(({agents:h,resolved:o})=>{s(!1),i({newAccountId:c,seedBulk:h.join(`
2
+ `),agentsResolved:o})})},onManageNew:c=>{r(!1),v({id:`conviction:${c}`,label:`PCA #${c}`,closable:!0})},clearRenewApprove:()=>i(null)}}function Te({accountId:a,snapshot:t,access:r,ownerTitle:l,health:s}){const n=Re(a);return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"v10-pca-detail-section",children:[e.jsx("h3",{className:"v10-pca-detail-section-title",children:"Lifecycle"}),(s==="expiring"||s==="expired")&&e.jsxs("p",{className:"v10-pca-card-warn",children:[V(t.expiresAtTimestamp),". The lock period can’t be extended — Renew creates a fresh replacement account seeded from this one (the old TRAC stays locked until its own expiry)."]}),e.jsx("button",{type:"button",className:`v10-pca-card-btn${s==="expiring"||s==="expired"?" primary":""}`,"data-testid":"pca-renew-btn",onClick:()=>n.openRenew(),disabled:!r.writesEnabled,title:l,children:"Renew — create a replacement PCA"})]}),n.renewOpen&&e.jsx(ne,{seed:{tokens:t.committedTRACTrac,primaryNode:t.primaryNode&&t.primaryNode!=="0"?String(t.primaryNode):void 0,primaryNodeUnknown:t.primaryNode==null},replacingAccountId:a,initialOwnerKey:r.mode==="wallet"?"hardware":"hot",onClose:()=>n.closeRenew(),onApproveOwnWallets:n.onRenewSuccess,onManage:n.onManageNew,onGetSponsored:()=>n.closeRenew()}),n.renewChaining&&e.jsx("div",{className:"lazy-spinner",role:"status","data-testid":"pca-renew-chaining",children:"Preparing re-approval…"}),n.renewApprove&&e.jsx(Y,{accountId:n.renewApprove.newAccountId,initialMode:"sponsor",seedBulk:n.renewApprove.seedBulk,deregisterFrom:a,seedAgentsResolved:n.renewApprove.agentsResolved,onClose:()=>n.clearRenewApprove()})]})}function Pe(a){return V(a).replace(/^Expires in /,"")}function We({accountId:a}){var d,j;const{data:t,loading:r,error:l,refresh:s}=S(()=>U(a,void 0,{extended:!0}),[a]),n=(t==null?void 0:t.accountId)===a?t:null,{data:i,error:v,refresh:u}=S(Z,[],0),p=I(N=>N.nodeStatus),c=(p==null?void 0:p.blockExplorerUrl)??null,h=$(N=>N.address),o=(i==null?void 0:i.wallets)??[],f=de(i,v),m=se({owner:n==null?void 0:n.owner,primaryWallet:o[0],primaryWalletState:f});if(ge(),r&&!n)return e.jsxs("div",{className:"lazy-spinner",children:["Loading PCA #",a,"…"]});if(l||!n)return e.jsx("div",{className:"v10-pca-detail",children:e.jsx("div",{className:"card",children:e.jsxs("div",{className:"card-body v10-pca-card-error",children:[e.jsxs("p",{children:["Couldn’t load PCA #",a,"."]}),e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:()=>s(),children:"Retry"})]})})});const w=o.some(N=>O(N,n.owner)),C=m.ownerUnknownCause==="wallets-loading",b=m.ownerUnknownCause==="wallets-unreadable",x=C?`Confirming ownership of PCA #${a}…`:b?`Couldn't load this node's wallets - can't confirm ownership of PCA #${a}.`:m.mode==="wallet"&&m.wrongNetwork?`Wrong network - switch the connected wallet to this node's PCA network to manage PCA #${a}.`:m.mode==="wallet"?`Connected wallet ${n.owner} owns PCA #${a}; device-signed owner actions are enabled.`:w?`Owner-only - PCA #${a} is owned by ${n.owner}, not this node's primary operational wallet, so node-UI can't sign for it.`:h?`Owner-only - connected as ${h}; switch to ${n.owner} to manage PCA #${a}.`:`Owner-only - connect ${n.owner} to manage PCA #${a}.`;return e.jsx(ke,{accountId:a,snapshot:n,wallets:o,ownerTrac:(j=(d=i==null?void 0:i.balances)==null?void 0:d.find(N=>O(N.address,n.owner)))==null?void 0:j.trac,explorer:c,access:m,connectedWallet:h,ownerOnlyReason:x,walletsLoading:C,walletsUnreadable:b,onRetryWallets:u,refresh:s})}function ke({accountId:a,snapshot:t,wallets:r,ownerTrac:l,explorer:s,access:n,connectedWallet:i,ownerOnlyReason:v,walletsLoading:u,walletsUnreadable:p,onRetryWallets:c,refresh:h}){const o=re({labels:{idle:"Confirm on your device",approveActive:"Confirm on your device (1 of 2): approve TRAC",approveReady:"Allowance ready — continue to the owner action",actionActive:x=>x==="remove"?"Confirm on your device: remove wallet":"Confirm on your device (2 of 2): top up",submitted:"Waiting for on-chain confirmation",confirmed:"Transaction confirmed on-chain",failed:"Wallet transaction failed"},flow:x=>be(x??"topup"),describeActionError:(x,d)=>q(x,d??"topup")}),f=le({access:n,onWalletProgress:n.mode==="wallet"?o.onProgress:void 0}),m=ee(t),w=n.writesEnabled?void 0:v,C=(t.discountBps/100).toFixed(t.discountBps%100===0?0:1),b=i?n.mode==="wallet"?n.wrongNetwork?"Owner wallet matches; switch network before signing owner actions.":"Connected owner wallet will sign top-up, approve, remove, and renewal actions.":n.mode==="daemon"?"Connected wallet is available for wallet-owned PCAs; this account uses the node daemon for owner actions.":`Connected as ${i}; switch to ${t.owner} to manage owner actions.`:n.mode==="external"?"Connect the PCA owner wallet to manage this account. Provider metadata is display-only.":"Connect a wallet to view and manage wallet-owned PCAs from this tab.";return e.jsxs("div",{className:"v10-pca-detail","data-testid":"pca-detail",children:[e.jsxs("div",{className:"v10-pca-detail-band",children:[e.jsxs("span",{className:"v10-pca-detail-id",children:["PCA #",a]}),e.jsxs("span",{className:"badge badge-info",children:["◉ ",C,"% discount"]}),e.jsxs("span",{className:"v10-pca-detail-committed",children:[P(t.committedTRACTrac)," TRAC committed"]}),e.jsx("span",{className:"v10-pca-card-spacer"}),e.jsx(oe,{state:m})]}),e.jsxs("div",{className:"v10-modal-tip",role:"status",children:[b,i?e.jsx(he,{}):e.jsx(ie,{testId:"pca-wallet-connect"})]}),o.steps.length>0&&e.jsx(ce,{steps:o.steps,currentLabel:o.currentLabel,blockExplorerUrl:s}),!n.writesEnabled&&(u?e.jsx("div",{className:"v10-modal-tip",role:"status",children:v}):e.jsxs("div",{className:"v10-modal-warning",role:"status",children:["ⓘ ",v," ",p?e.jsx("button",{type:"button",className:"v10-pca-card-btn",onClick:c,children:"Retry"}):"Wallet probe stays available."]})),e.jsx(ve,{items:[{id:"buffer",label:"Top-up buffer",value:`${P(t.topUpBufferTrac)} TRAC`},{id:"per-epoch",label:"TRAC per epoch",value:`${ae(t.baseEpochAllowance)} TRAC`},...t.remainingAllowanceTrac!=null?[{id:"remaining",label:"Remaining this epoch",value:`${P(t.remainingAllowanceTrac)} TRAC`,tooltip:t.currentEpoch!=null?`Current epoch ${t.currentEpoch}`:void 0}]:[],{id:"wallets",label:"Publishing wallets",value:`${t.agentCount} / 100`},{id:"expires",label:"Expires in",value:Pe(t.expiresAtTimestamp),tooltip:`Expiry epoch ${t.expiresAtEpoch}`},...t.primaryNode!=null?[{id:"primary-node",label:"Primary node",value:t.primaryNode==="0"?"None set":`Node #${t.primaryNode}`,tooltip:t.lastPrimaryNodeChangeEpoch!=null?`Last changed epoch ${t.lastPrimaryNodeChangeEpoch}`:void 0}]:[]]}),e.jsxs("div",{className:"v10-pca-detail-owner",children:[e.jsx("span",{className:"v10-pca-card-owner-lbl",children:"Owner"}),e.jsx(W,{address:t.owner,trailing:s?e.jsx("a",{className:"v10-pca-card-explorer",href:`${s}/address/${t.owner}`,target:"_blank",rel:"noreferrer","aria-label":"View owner on explorer",children:"↗"}):void 0})]}),e.jsx(ye,{accountId:a,snapshot:t,ownerTrac:l,explorer:s,access:n,ownerTitle:w,owner:f,deviceProgress:o,refresh:h}),e.jsx(Ne,{accountId:a,snapshot:t,wallets:r,explorer:s,access:n,ownerTitle:w,owner:f,deviceProgress:o,refresh:h}),e.jsx(Te,{accountId:a,snapshot:t,access:n,ownerTitle:w,health:m})]})}export{We as ConvictionDetailView};