@origintrail-official/dkg-node-ui 10.0.18 → 10.0.19

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 (44) hide show
  1. package/dist/chain-cursor-stores.d.ts +17 -0
  2. package/dist/chain-cursor-stores.d.ts.map +1 -1
  3. package/dist/chain-cursor-stores.js +37 -0
  4. package/dist/chain-cursor-stores.js.map +1 -1
  5. package/dist/chain-event-log-store.d.ts +31 -0
  6. package/dist/chain-event-log-store.d.ts.map +1 -1
  7. package/dist/chain-event-log-store.js +87 -13
  8. package/dist/chain-event-log-store.js.map +1 -1
  9. package/dist/db.d.ts +1 -1
  10. package/dist/db.d.ts.map +1 -1
  11. package/dist/db.js +27 -1
  12. package/dist/db.js.map +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +1 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist-ui/assets/{3d-force-graph-DGF2sXeK.js → 3d-force-graph-CehOGxux.js} +1 -1
  18. package/dist-ui/assets/{ActivityFeed-DNatshHL.js → ActivityFeed-BE4MTD8M.js} +1 -1
  19. package/dist-ui/assets/{AgentHub-lOm96XuE.js → AgentHub-CT6UhLF2.js} +1 -1
  20. package/dist-ui/assets/{AgentProfilePage-BRtazufK.js → AgentProfilePage-ygi-GXKM.js} +1 -1
  21. package/dist-ui/assets/{ApproveWalletsModal-BMtRgndO.js → ApproveWalletsModal-YFfDrGth.js} +3 -3
  22. package/dist-ui/assets/{ContextGraphPrimitives-CBc6kvmp.js → ContextGraphPrimitives-Dh-w2D_i.js} +1 -1
  23. package/dist-ui/assets/{ConvictionDetailView-DOTYSm7p.js → ConvictionDetailView-CfRmqqDD.js} +2 -2
  24. package/dist-ui/assets/MemoryLayerView-DL0zLYAQ.js +2 -0
  25. package/dist-ui/assets/{MemoryStackView-Bol2eMyq.js → MemoryStackView-BsV_JnOe.js} +1 -1
  26. package/dist-ui/assets/{Network-B49IxpAj.js → Network-BkxRENe4.js} +1 -1
  27. package/dist-ui/assets/{OnChainProvenanceCard-BpUoHg4b.js → OnChainProvenanceCard-CnnkMMNI.js} +1 -1
  28. package/dist-ui/assets/{Operations-BCQ545Yk.js → Operations-BaWWLSUw.js} +1 -1
  29. package/dist-ui/assets/{ProjectView-BaQQSy8L.js → ProjectView-BJmZ5f62.js} +31 -31
  30. package/dist-ui/assets/{PublishingConviction-B5nWRsUP.js → PublishingConviction-CKB6JBYk.js} +2 -2
  31. package/dist-ui/assets/{Settings-DeZKX_Ry.js → Settings-DXGMPiJk.js} +1 -1
  32. package/dist-ui/assets/{browserWalletTransaction-B6wyaMOV.js → browserWalletTransaction-BdmrJpK1.js} +3 -3
  33. package/dist-ui/assets/{ccip-B_vQl40F.js → ccip-BNYiIkjs.js} +1 -1
  34. package/dist-ui/assets/{index-CT-LdpBE.js → index-DK8XzE3T.js} +92 -92
  35. package/dist-ui/assets/{index-DHd3qhAk.js → index-DOGXDQkQ.js} +3 -3
  36. package/dist-ui/assets/{jsonld-32FQRO67-BYu8pE-5.js → jsonld-32FQRO67-Ca-KnQfb.js} +2 -2
  37. package/dist-ui/assets/{jsonld-Crm5iwcE.js → jsonld-mRC9FbFR.js} +1 -1
  38. package/dist-ui/assets/{renderer-3d-2EVDZII7-C2z5aUgo.js → renderer-3d-2EVDZII7-AEMBPIY7.js} +2 -2
  39. package/dist-ui/assets/{shikiHighlighter-DW1fRfBU.js → shikiHighlighter-CUQ07vzt.js} +1 -1
  40. package/dist-ui/assets/{useEntityOnChainReceipt-0Ub24t6e.js → useEntityOnChainReceipt-C8NHlPPN.js} +1 -1
  41. package/dist-ui/assets/{useProjectActivity-CLza3psq.js → useProjectActivity-CVFCfbMj.js} +1 -1
  42. package/dist-ui/index.html +1 -1
  43. package/package.json +3 -3
  44. package/dist-ui/assets/MemoryLayerView-DDFI2ngR.js +0 -2
@@ -1,3 +1,3 @@
1
- import{aO as t,bc as g,aw as Ie,N as fe,b6 as st,bN as K,b8 as Ct,b5 as Nt,b3 as kt,z as jt,a7 as oe,ai as Fe,b4 as Tt,aH as Pt,aB as St,aS as Rt,bF as Et,bv as Ot,by as ke,aN as Ue,bJ as he,aq as We,H as Be,aI as It,B as ot}from"./index-CT-LdpBE.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-B6wyaMOV.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
- `);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 qt({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,J=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":J,"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:J,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 Gt(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}]}],Jt="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",Zt="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())===Jt&&f.length===4&&((i=f[1])==null?void 0:i.toLowerCase())===Zt&&!(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 qe(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 Ge 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 Ge(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(qe({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=qe({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,Je,Ze;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=(Je=(Qe=w==null?void 0:w.balances)==null?void 0:Qe.find(d=>d.address===N))==null?void 0:Je.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,J=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),[Z,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),q=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,G=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&&!G&&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&&Z?`${v}/tx/${Z}`: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:[Z&&t.jsxs("p",{children:["Broadcast tx"," ",d?t.jsxs("a",{href:d,target:"_blank",rel:"noreferrer",children:[Z," ↗"]}):t.jsx("code",{children:Z})]}),J?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=(Ze=$.snapshot)==null?void 0:Ze.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(Gt,{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)."}),q.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",q.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."]}),q.sponsorDead.length>0&&t.jsxs("div",{className:"v10-modal-warning",role:"alert","data-testid":"pca-b1-sponsor-dead",children:["Warning: ",q.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."]}),!q.zeroSelfCoverage&&q.sponsorBound.length>0&&t.jsxs("div",{className:"v10-modal-tip",role:"status","data-testid":"pca-b1-preview",children:["After creating, ",q.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)."]}),!q.zeroSelfCoverage&&q.ownBound.length>0&&t.jsxs("div",{className:"v10-modal-warning",role:"status","data-testid":"pca-b1-own-bound",children:["⚠ ",q.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",G&&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(qt,{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 qe({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 Ge)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 Ge||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),J=g.useRef(!1),m=g.useMemo(()=>{const C=new Set,S=[];let _=0;for(const M of ne.split(`
3
- `).map(G=>G.trim()).filter(Boolean)){if(!Ha.test(M)){_+=1;continue}const G=M.toLowerCase();C.has(G)||(C.add(G),S.push(M))}return{valid:S,invalid:_}},[ne]);g.useEffect(()=>{let C=!1;async function S(){const _=await Promise.all(A.map(async G=>{var te;try{const ae=await oe(e,G,{extended:!0});return[G,String(ae.accountId)===String(e)&&((te=ae.probedKey)==null?void 0:te.registered)===!0]}catch{return[G,!1]}}));if(C)return;const M=Object.fromEntries(_);Q(M),E(G=>{const te={...G};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),Z=async()=>{P.length!==0&&(J.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,()=>J.current))},{order:se,rows:ve,running:U,done:z,aborted:we,verificationDelayed:de,deviceSteps:q,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}),q.length>0&&t.jsx(ut,{steps:q,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:()=>{J.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:Z,children:"Retry to finish"}):null:t.jsxs("button",{type:"button",className:"v10-modal-btn primary","data-testid":"pca-approve-submit",onClick:Z,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,Gt as b,aa as c,ha as d,Na as e,na as o,Qt as p,qe as r,ja as u};
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-DK8XzE3T.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-BdmrJpK1.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
+ `);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
+ `).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-CT-LdpBE.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{aO as t}from"./index-DK8XzE3T.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,bN as $,bJ as R,bc as y,aW as G,b7 as J,aq as P,H as Q,B as E,by as S,aV as M,a7 as W,bL as X,ar as V,ai as Z,bv as I,N as O,aC as ee,aw as ae}from"./index-CT-LdpBE.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-BMtRgndO.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-B6wyaMOV.js";import{S as ve}from"./ContextGraphPrimitives-CBc6kvmp.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 L=(T=(await W(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"?_(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=>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)=>_(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{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-DK8XzE3T.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-YFfDrGth.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-BdmrJpK1.js";import{S as ve}from"./ContextGraphPrimitives-Dh-w2D_i.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};
@@ -0,0 +1,2 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DOGXDQkQ.js","assets/index-DK8XzE3T.js","assets/index-BLQUVvVz.css","assets/string-DtUow4KV.js","assets/OnChainProvenanceCard-CnnkMMNI.js","assets/useEntityOnChainReceipt-C8NHlPPN.js"])))=>i.map(i=>d[i]);
2
+ import{bd as i,$ as pe,aj as B,q as oe,bG as be,aO as e,R as K,bz as F,O as ge,bF as q,af as xe,aR as de,bc as fe,b2 as je,b3 as Ne,f as we,bb as ie,F as ye,E as re,_ as Y,aY as Se}from"./index-DK8XzE3T.js";import{t as he}from"./truncate-BaiMkAOo.js";const ke={"application/pdf":"pdf","application/json":"text","text/plain":"text","text/csv":"text","text/markdown":"markdown","image/png":"image","image/jpeg":"image","image/gif":"image","image/webp":"image"};function ne(s){const c=ke[s];return c?c==="markdown"?"text":c:"binary"}async function ce(s){const c=await fetch(s,{headers:oe()});if(!c.ok)throw new Error(`HTTP ${c.status}`);const l=await c.blob();return URL.createObjectURL(l)}function Ce({open:s,onClose:c,assertionName:l,contextGraphId:g,subGraphName:d}){const[r,v]=i.useState(null),[N,C]=i.useState(null),[h,w]=i.useState(null),[y,x]=i.useState(!0),[p,S]=i.useState(null);i.useEffect(()=>{if(s)return x(!0),S(null),v(null),C(null),w(null),pe(l,g,d).then(async b=>{v(b);const A=ne(b.detectedContentType),E=B(b.fileHash,b.detectedContentType);if(A==="text"){const t=await fetch(E,{headers:oe()});t.ok&&C(await t.text())}else if(A==="pdf"||A==="image"){const t=await ce(E);w(t)}}).catch(b=>S(b.message??"Failed to load file info")).finally(()=>x(!1)),()=>{h&&URL.revokeObjectURL(h)}},[s,l,g,d]),i.useEffect(()=>()=>{h&&URL.revokeObjectURL(h)},[h]);const{dialogRef:n,onBackdropClick:u}=be(s,c);if(!s)return null;const o=r?ne(r.detectedContentType):null,f=r?B(r.fileHash,r.detectedContentType):null,k=async(b,A)=>{try{const E=await ce(b),t=document.createElement("a");t.href=E,t.download=A,t.click(),URL.revokeObjectURL(E)}catch{window.open(b,"_blank")}};return e.jsx("div",{className:"v10-modal-overlay",onClick:u,role:"presentation",children:e.jsxs("div",{className:"v10-modal-box v10-file-preview-modal",ref:n,role:"dialog","aria-modal":"true","aria-labelledby":"dkg-file-preview-title",children:[e.jsxs("div",{className:"v10-modal-header",children:[e.jsx("div",{id:"dkg-file-preview-title",className:"v10-modal-title",children:l}),e.jsx("button",{type:"button",className:"v10-modal-close",onClick:c,"aria-label":"Close file preview",title:"Close (Esc)",children:"×"})]}),y&&e.jsx("div",{className:"v10-file-preview-loading",children:"Loading file preview..."}),p&&e.jsxs("div",{className:"v10-file-preview-error",children:[e.jsx("p",{children:p}),e.jsx("p",{style:{fontSize:11,marginTop:4},children:"File preview requires the extraction status to still be cached on the node. If the node was restarted, the preview metadata may be unavailable."})]}),r&&!y&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"v10-file-preview-meta",children:[e.jsx("span",{className:"v10-file-preview-meta-item",children:r.detectedContentType}),e.jsxs("span",{className:"v10-file-preview-meta-item",children:[r.tripleCount," triples extracted"]}),e.jsx("span",{className:"v10-file-preview-meta-item",children:r.pipelineUsed}),r.completedAt&&e.jsx("span",{className:"v10-file-preview-meta-item",children:new Date(r.completedAt).toLocaleString()})]}),e.jsxs("div",{className:"v10-file-preview-content",children:[o==="pdf"&&h&&e.jsx("iframe",{src:h,className:"v10-file-preview-iframe",title:`Preview: ${l}`}),o==="image"&&h&&e.jsx("img",{src:h,alt:l,className:"v10-file-preview-image"}),o==="text"&&N!=null&&e.jsx("pre",{className:"v10-file-preview-text",children:N}),o==="binary"&&e.jsxs("div",{className:"v10-file-preview-binary",children:[e.jsx("p",{children:"This file type cannot be previewed directly."}),f&&e.jsx("button",{className:"v10-file-preview-download",onClick:()=>k(f,l),children:"Download file"})]})]}),e.jsxs("div",{className:"v10-file-preview-footer",children:[f&&e.jsx("button",{className:"v10-file-preview-download",onClick:()=>k(f,l),children:"Download original"}),r.mdIntermediateHash&&e.jsx("button",{className:"v10-file-preview-download",onClick:()=>k(B(r.mdIntermediateHash,"text/markdown"),`${l}.md`),children:"Download markdown intermediate"})]})]})]})})}const Ee=i.lazy(()=>Y(()=>import("./index-DOGXDQkQ.js").then(s=>s.h),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.RdfGraph}))),Le=i.lazy(()=>Y(()=>import("./index-DOGXDQkQ.js").then(s=>s.h),__vite__mapDeps([0,1,2,3])).then(s=>({default:s.NodePanel}))),Pe=i.lazy(()=>Y(()=>import("./OnChainProvenanceCard-CnnkMMNI.js"),__vite__mapDeps([4,1,2,0,3,5])).then(s=>({default:s.OnChainProvenanceCard}))),Ae={wm:{label:"Working Memory",color:"var(--layer-working)",icon:"◇",description:"Private agent drafts. Fast local storage."},swm:{label:"Shared Working Memory",color:"var(--layer-shared)",icon:"◈",description:"Shared proposals with collaborators. TTL-bounded."},vm:{label:"Verifiable Memory",color:"var(--layer-verified)",icon:"◉",description:"Endorsed, published, on-chain knowledge."}},Re={labelMode:"humanized",renderer:"2d",labels:Se({extraPredicates:["http://schema.org/text"]}),style:{classColors:{"http://schema.org/Person":"#f472b6","http://schema.org/Organization":"#fb923c","http://schema.org/Place":"#34d399","http://schema.org/Product":"#c084fc","http://schema.org/Event":"#facc15","http://schema.org/CreativeWork":"#7dd3fc","http://schema.org/Thing":"#94a3b8"},defaultNodeColor:"#94a3b8",defaultEdgeColor:"#5f8598",edgeWidth:.9},hexagon:{baseSize:4,minSize:3,maxSize:6,scaleWithDegree:!0},focus:{maxNodes:3e3,hops:999}},Te=e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"3",y1:"9",x2:"21",y2:"9"}),e.jsx("line",{x1:"3",y1:"15",x2:"21",y2:"15"}),e.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]}),Me=e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"6",cy:"6",r:"3"}),e.jsx("circle",{cx:"18",cy:"6",r:"3"}),e.jsx("circle",{cx:"6",cy:"18",r:"3"}),e.jsx("circle",{cx:"18",cy:"18",r:"3"}),e.jsx("line",{x1:"8.5",y1:"7.5",x2:"15.5",y2:"16.5"}),e.jsx("line",{x1:"15.5",y1:"7.5",x2:"8.5",y2:"16.5"})]});function He({layer:s,contextGraphId:c,externalQuery:l,externalQueryKey:g,queryPresetOptions:d}){var le,te;const r=Ae[s],[v,N]=i.useState("graph"),[C,h]=i.useState(""),[w,y]=i.useState(""),[x,p]=i.useState(""),[S,n]=i.useState(""),[u,o]=i.useState("any"),[f,k]=i.useState(50),[b,A]=i.useState(""),[E,t]=i.useState("any"),[m,L]=i.useState(50),[U,P]=i.useState(s!=="vm"),j=K.useRef(s);K.useEffect(()=>{j.current!==s&&(j.current=s,h(""),P(s!=="vm"),y(""),p(""),n(""),o("any"),k(50),A(""),t("any"),L(50))},[s]),K.useEffect(()=>{l!==void 0&&(h(""),y(l),p(l))},[l,g]);const W=i.useMemo(()=>s==="wm"?`SELECT ?s ?p ?o WHERE { GRAPH <${`did:dkg:context-graph:${c}/_meta`}> { ?g <http://dkg.io/ontology/memoryLayer> "WM" } GRAPH ?g { ?s ?p ?o } FILTER(!CONTAINS(STR(?g), "/meta/assertion/")) } LIMIT 1000`:s==="vm"?Ue({query:b,field:E,limit:m}):"SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 500",[c,s,E,m,b]),R=x||W,O=s==="swm"?"_shared_memory":void 0,V=s==="swm",J=s==="vm"?"verifiable-memory":void 0,X=s==="wm"&&R===W,{data:M,loading:H,error:Z,refresh:T}=F(()=>ge(R,{contextGraphId:c,includeSharedMemory:V,graphSuffix:O,view:J,includeContextGraphPartitions:X}),[R,c,V,O,J,X],0);q(c,T,{layers:[s]});const{data:I}=F(xe,[],3e4),me=I==null?void 0:I.blockExplorerUrl,ee=i.useCallback(()=>{const a=w.trim();if(a===x){T();return}p(a)},[x,w,T]),se=i.useCallback(()=>{const a=S!==b||u!==E||f!==m;if(a&&(A(S),t(u),L(f)),x){p("");return}a||T()},[x,E,m,b,u,f,S,T]),_=((le=M==null?void 0:M.result)==null?void 0:le.bindings)??((te=M==null?void 0:M.results)==null?void 0:te.bindings)??[],z=i.useMemo(()=>_.map(a=>({subject:$(a.s)??"",predicate:$(a.p)??"",object:$(a.o)??""})).filter(a=>a.subject&&a.predicate&&a.object),[_]),ue=i.useCallback(a=>{a!=null&&a.id&&p(`SELECT (<${a.id}> AS ?s) ?p ?o WHERE { <${a.id}> ?p ?o } LIMIT 100`)},[]);return e.jsxs("div",{className:"v10-memory-layer-view",children:[e.jsxs("div",{className:"v10-mlv-header",children:[e.jsx("span",{className:"v10-mlv-icon",style:{color:r.color},children:r.icon}),e.jsxs("div",{children:[e.jsx("h2",{className:"v10-mlv-title",children:r.label}),e.jsx("p",{className:"v10-mlv-desc",children:r.description})]})]}),s==="wm"&&e.jsx(_e,{contextGraphId:c,onPromoted:T}),s==="swm"&&e.jsx($e,{contextGraphId:c,onPublished:T}),s==="vm"&&e.jsxs("div",{className:"v10-vm-search-panel",children:[e.jsxs("div",{className:"v10-vm-search-header",children:[e.jsxs("div",{children:[e.jsx("div",{className:"v10-vm-search-title",children:"Search Verifiable Memory"}),e.jsx("div",{className:"v10-vm-search-desc",children:"Search published triples by subject, predicate, object, or across all fields."})]}),e.jsx("button",{className:"v10-vm-search-toggle",type:"button",onClick:()=>P(a=>!a),children:U?"Hide SPARQL":"Advanced SPARQL"})]}),e.jsxs("div",{className:"v10-vm-search-controls",children:[e.jsx("input",{type:"text",className:"v10-mlv-query-input",placeholder:"Search verifiable memory...",value:S,onChange:a=>n(a.target.value),onKeyDown:a=>{a.key==="Enter"&&se()}}),e.jsxs("select",{className:"v10-vm-search-select",value:u,onChange:a=>o(a.target.value),children:[e.jsx("option",{value:"any",children:"Any field"}),e.jsx("option",{value:"subject",children:"Subject"}),e.jsx("option",{value:"predicate",children:"Predicate"}),e.jsx("option",{value:"object",children:"Object"})]}),e.jsxs("select",{className:"v10-vm-search-select",value:String(f),onChange:a=>k(Number.parseInt(a.target.value,10)||50),children:[e.jsx("option",{value:"25",children:"25 rows"}),e.jsx("option",{value:"50",children:"50 rows"}),e.jsx("option",{value:"100",children:"100 rows"}),e.jsx("option",{value:"200",children:"200 rows"})]}),e.jsx("button",{className:"v10-mlv-run-btn",onClick:se,children:"Search"})]})]}),(s!=="vm"||U)&&e.jsxs("div",{className:"v10-mlv-query-bar",children:[d!=null&&d.length?e.jsxs("select",{className:"v10-vm-search-select",value:C,onChange:a=>{const D=a.target.value;h(D);const G=d.find(ve=>ve.label===D),ae=(G==null?void 0:G.query)??"";y(ae),p(ae)},children:[e.jsx("option",{value:"",children:"Select common query..."}),d.map(a=>e.jsx("option",{value:a.label,children:a.label},a.label))]}):e.jsx("input",{type:"text",className:"v10-mlv-query-input",placeholder:"Custom SPARQL query...",value:w,onChange:a=>y(a.target.value),onKeyDown:a=>{a.key==="Enter"&&ee()}}),e.jsx("button",{className:"v10-mlv-run-btn",onClick:ee,children:"Run"}),x&&e.jsx("button",{className:"v10-mlv-clear-btn",onClick:()=>p(""),title:"Reset to full layer overview",children:"Reset"}),e.jsxs("div",{className:"v10-mlv-view-toggle",children:[e.jsx("button",{className:`v10-mlv-toggle-btn ${v==="table"?"active":""}`,onClick:()=>N("table"),title:"Table view",children:Te}),e.jsx("button",{className:`v10-mlv-toggle-btn ${v==="graph"?"active":""}`,onClick:()=>N("graph"),title:"Graph view",children:Me})]})]}),H&&e.jsx("p",{className:"v10-mlv-status",children:"Loading..."}),Z&&e.jsxs("p",{className:"v10-mlv-status",style:{color:"var(--accent-red)"},children:["Error: ",Z]}),!H&&_.length===0&&e.jsxs("div",{className:"v10-mlv-empty",children:[e.jsxs("p",{children:["No triples found in ",r.label.toLowerCase(),"."]}),e.jsxs("p",{style:{fontSize:11,marginTop:4},children:[s==="wm"&&"Import files or chat with your agent to generate working memory.",s==="swm"&&"Promote assertions from working memory to share with collaborators.",s==="vm"&&"Publish shared memory to create verified on-chain knowledge."]})]}),!H&&_.length>0&&v==="table"&&e.jsxs("div",{className:"v10-mlv-table-wrap",children:[e.jsxs("div",{className:"v10-mlv-result-count",children:[_.length," triples"]}),e.jsxs("table",{className:"v10-mlv-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"Subject"}),e.jsx("th",{children:"Predicate"}),e.jsx("th",{children:"Object"})]})}),e.jsx("tbody",{children:_.map((a,D)=>e.jsxs("tr",{children:[e.jsx("td",{className:"v10-mlv-cell",children:Q($(a.s))}),e.jsx("td",{className:"v10-mlv-cell",children:Q($(a.p))}),e.jsx("td",{className:"v10-mlv-cell",children:Q($(a.o))})]},D))})]})]}),!H&&z.length>0&&v==="graph"&&e.jsxs("div",{className:"v10-mlv-graph-container",children:[e.jsxs("div",{className:"v10-mlv-graph-info",children:[e.jsxs("span",{children:[z.length," triples"]}),x&&e.jsx("span",{className:"v10-mlv-graph-info-custom",children:"filtered"})]}),e.jsx(i.Suspense,{fallback:e.jsx("div",{className:"v10-mlv-graph-loading",children:"Loading graph renderer..."}),children:e.jsxs(Ee,{data:z,format:"triples",options:Re,style:{width:"100%",height:"100%"},onNodeClick:ue,initialFit:!0,children:[e.jsx(Le,{className:"v10-mlv-node-panel",showUri:!0,showTypes:!0,showProperties:!0,showMetadata:!1,maxValueLength:150}),e.jsx(Pe,{contextGraphId:c,layer:s,explorerUrl:me})]})})]})]})}function _e({contextGraphId:s,onPromoted:c}){const{data:l,loading:g,refresh:d}=F(()=>de(s,"wm"),[s],0);q(s,d,{layers:["wm"]});const[r,v]=i.useState(null),[N,C]=i.useState(null),[h,w]=i.useState(null),[y,x]=i.useState(null),p=i.useCallback(async n=>{v(n.graphUri),C(null),w(null);try{const u=await ie(s,n.name,n.subGraph?{subGraphName:n.subGraph}:{}),o=ye(n.name,u);C({message:o.message+(n.subGraph?` (in ${n.subGraph})`:""),kind:o.kind==="success"?"success":"noop",subGraph:n.subGraph}),d(),c()}catch(u){const o=re(n.name,u);w(o?{message:o.message,kind:"not-persisted"}:{message:(u==null?void 0:u.message)??"Promote failed",kind:"other"})}finally{v(null)}},[s,d,c]),S=i.useCallback(async()=>{if(!(l!=null&&l.length))return;v("__all__"),C(null),w(null);let n=0,u=null;try{for(const k of l)u=k.name,(await ie(s,k.name,k.subGraph?{subGraphName:k.subGraph}:{})).promotedCount===0&&(n+=1);const o=l.length-n,f=n>0?` (${n} already shared or still committing)`:"";C({message:o>0?`Shared ${o} complete Knowledge Asset${o===1?"":"s"} to Shared Working Memory${f}.`:"No Knowledge Assets were newly shared — all were already in Shared Working Memory or still committing.",kind:o>0?"success":"noop"}),d(),c()}catch(o){const f=re(u??"selected assertion",o);w(f?{message:f.message,kind:"not-persisted"}:{message:(o==null?void 0:o.message)??"Promote failed",kind:"other"})}finally{v(null)}},[l,s,d,c]);return g?e.jsx("div",{className:"v10-assertion-list-loading",children:"Loading assertions..."}):l!=null&&l.length?e.jsxs("div",{className:"v10-assertion-list",children:[e.jsxs("div",{className:"v10-assertion-list-header",children:[e.jsxs("span",{className:"v10-assertion-list-title",children:["Assertions in Working Memory (",l.length,")"]}),e.jsx("button",{className:"v10-btn-promote-all",disabled:r!==null,onClick:S,children:r==="__all__"?"Sharing...":"Share Complete KAs → SWM"})]}),e.jsx("div",{className:"v10-assertion-items",children:l.map(n=>e.jsxs("div",{className:"v10-assertion-item",children:[e.jsxs("div",{className:"v10-assertion-item-info",children:[e.jsx("button",{className:"v10-assertion-item-name clickable",title:n.graphUri,onClick:()=>x({name:n.name,subGraph:n.subGraph}),children:n.name}),n.tripleCount!=null&&e.jsxs("span",{className:"v10-assertion-item-count",children:[n.tripleCount," triples"]}),n.subGraph&&e.jsxs("span",{className:"v10-item-count v10-item-subgraph",title:`In sub-graph: ${n.subGraph}`,children:["› ",he(n.subGraph,18)]})]}),e.jsx("button",{className:"v10-btn-promote",disabled:r!==null,onClick:()=>p(n),title:"Share this complete Knowledge Asset to Shared Working Memory",children:r===n.graphUri?"Promoting...":"→ SWM"})]},n.graphUri))}),N&&e.jsx("div",{className:N.kind==="success"?"v10-promote-result success":"v10-promote-result info",children:N.message}),h&&e.jsx("div",{className:"v10-promote-result error",children:h.message}),y&&e.jsx(Ce,{open:!0,onClose:()=>x(null),assertionName:y.name,subGraphName:y.subGraph,contextGraphId:s})]}):null}function $e({contextGraphId:s,onPublished:c}){const{data:l,loading:g,refresh:d}=F(()=>de(s,"swm"),[s],0);q(s,d,{layers:["swm"]});const[r,v]=i.useState(new Set),[N,C]=i.useState(!1),[h,w]=i.useState(null),[y,x]=i.useState(null),p=(l==null?void 0:l.map(t=>t.graphUri))??[],S=p.length>0&&p.every(t=>r.has(t)),n=i.useCallback(t=>{v(m=>{const L=new Set(m);return L.has(t)?L.delete(t):L.add(t),L})},[]),u=i.useCallback(()=>{v(S?new Set:new Set(p))},[S,p]),o=i.useCallback(async t=>{if(t.length!==0){C(!0),w(null),x(null);try{w(await fe(s,t)),v(new Set),d(),c()}catch(m){x((m==null?void 0:m.message)??"Publish failed")}finally{C(!1)}}},[s,d,c]),f=i.useCallback(()=>{const t=(l??[]).filter(m=>r.has(m.graphUri));return o(t)},[l,r,o]),k=i.useCallback(()=>o(l??[]),[l,o]),b=(l==null?void 0:l.reduce((t,m)=>t+(m.tripleCount??0),0))??0,A=(l==null?void 0:l.filter(t=>r.has(t.graphUri)).reduce((t,m)=>t+(m.tripleCount??0),0))??0,E=!g&&(!l||l.length===0);return g?e.jsx("div",{className:"v10-assertion-list-loading",children:"Loading SWM contents..."}):E?e.jsxs("div",{className:"v10-publish-panel",children:[e.jsx("div",{className:"v10-publish-panel-header",children:e.jsx("span",{className:"v10-publish-panel-title",children:"Publish to Verifiable Memory"})}),e.jsx("div",{className:"v10-publish-panel-empty",children:"No data in Shared Working Memory yet. Promote assertions from Working Memory first."})]}):e.jsxs("div",{className:"v10-publish-panel",children:[e.jsxs("div",{className:"v10-publish-panel-header",children:[e.jsxs("span",{className:"v10-publish-panel-title",children:["Knowledge assets in Shared Working Memory (",l.length," asset",l.length===1?"":"s"," · ",b," triples)"]}),e.jsxs("div",{className:"v10-publish-panel-header-actions",children:[e.jsx("button",{className:"v10-publish-panel-refresh",onClick:d,title:"Refresh",children:"↻"}),e.jsx("button",{className:"v10-btn-promote-all",disabled:N,onClick:k,children:N&&r.size===0?"Publishing...":"Publish All → VM"})]})]}),e.jsxs("div",{className:"v10-publish-select-bar",children:[e.jsxs("label",{className:"v10-publish-select-all",children:[e.jsx("input",{type:"checkbox",checked:S,onChange:u}),e.jsx("span",{children:"Select all"})]}),r.size>0&&e.jsx("button",{className:"v10-btn-publish",disabled:N,onClick:f,children:N?"Publishing...":`Publish ${r.size} selected (${A} triples) → VM`})]}),e.jsx("div",{className:"v10-assertion-items",children:l.map(t=>e.jsxs("div",{className:`v10-assertion-item ${r.has(t.graphUri)?"selected":""}`,children:[e.jsx("label",{className:"v10-publish-entity-check",children:e.jsx("input",{type:"checkbox",checked:r.has(t.graphUri),onChange:()=>n(t.graphUri)})}),e.jsxs("div",{className:"v10-assertion-item-info",children:[e.jsx("span",{className:"v10-assertion-item-name",title:t.graphUri,children:t.name}),t.subGraph&&e.jsxs("span",{className:"v10-item-count v10-item-subgraph",title:`In sub-graph: ${t.subGraph}`,children:["› ",he(t.subGraph,18)]}),t.tripleCount!=null&&e.jsxs("span",{className:"v10-assertion-item-count",children:[t.tripleCount," triples"]})]})]},t.graphUri))}),h&&(()=>{const{published:t,total:m,partial:L,partialError:U,failures:P,sample:j,convictionCostCovered:W}=h,R=je(h),O=t===m&&t>0&&L===0,V=(j==null?void 0:j.status)==="confirmed"&&!!j.txHash;return e.jsxs("div",{className:`v10-publish-result-card ${O?"success":"error"}`,children:[e.jsx("div",{className:"v10-publish-result-title",children:t>0?`Published ${t} of ${m} knowledge asset${m===1?"":"s"} to Verifiable Memory`:R&&P.length===0?"Publish outcome unknown":"NOT published to Verifiable Memory"}),L>0&&e.jsxs("div",{className:"v10-publish-result-details",style:{marginBottom:6},children:["⚠ ",L," asset",L===1?"":"s",": ",Ne(U)]}),P.length>0&&e.jsxs("div",{className:"v10-publish-result-details",style:{marginBottom:6},children:[P.length," asset",P.length===1?"":"s"," could not be published — ",P[0].name,": ",P[0].error,P.length>1?` (+${P.length-1} more)`:""]}),R&&e.jsxs("div",{className:"v10-publish-result-details",style:{marginBottom:6},children:["⚠ ",R]}),e.jsxs("div",{className:"v10-publish-result-details",children:[(j==null?void 0:j.kaId)!=null&&e.jsxs("div",{children:[e.jsx("span",{className:"v10-publish-result-label",children:"Knowledge Asset:"})," ",j.kaId]}),V?e.jsxs("div",{className:"v10-publish-result-tx",children:[e.jsx("span",{className:"v10-publish-result-label",children:"Tx hash:"})," ",e.jsx("span",{className:"mono",title:j.txHash,children:j.txHash}),j.blockNumber!=null&&e.jsxs("span",{className:"v10-publish-result-block",children:[" (block ",j.blockNumber,")"]})]}):e.jsxs("div",{className:"v10-publish-result-details",children:["Verifiable Memory requires a confirmed ",e.jsx("code",{children:"KCCreated"})," event. If a publish did not land on-chain, check the node logs (typically a missing publisher wallet, an unfunded signer, or a chain adapter that isn't V10-ready)."]}),e.jsx(we,{convictionCostCovered:W})]})]})})(),y&&e.jsx("div",{className:"v10-publish-result-card error",children:y})]})}function $(s){if(s!=null)return typeof s=="string"?s:typeof s=="object"&&"value"in s?String(s.value):String(s)}function Q(s){if(!s)return"—";const c=s.lastIndexOf("#"),l=s.lastIndexOf("/"),g=Math.max(c,l);return g>=0?s.slice(g+1):s}function Ue(s){const c=Number.isFinite(s.limit)&&s.limit>0?Math.floor(s.limit):50,l=s.query.trim();if(!l)return`SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT ${c}`;const g=We(l.toLowerCase()),d={subject:`CONTAINS(LCASE(STR(?s)), "${g}")`,predicate:`CONTAINS(LCASE(STR(?p)), "${g}")`,object:`CONTAINS(LCASE(STR(?o)), "${g}")`};return`SELECT ?s ?p ?o WHERE { ?s ?p ?o . FILTER(${s.field==="any"?`(${d.subject} || ${d.predicate} || ${d.object})`:d[s.field]}) } LIMIT ${c}`}function We(s){return s.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r")}export{He as MemoryLayerView,$e as PublishPanel};