@waiaas/daemon 2.10.0-rc.8 → 2.10.0
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.
- package/README.md +1 -1
- package/dist/api/routes/actions.d.ts.map +1 -1
- package/dist/api/routes/actions.js +69 -3
- package/dist/api/routes/actions.js.map +1 -1
- package/dist/api/routes/admin-actions.d.ts +46 -0
- package/dist/api/routes/admin-actions.d.ts.map +1 -0
- package/dist/api/routes/admin-actions.js +325 -0
- package/dist/api/routes/admin-actions.js.map +1 -0
- package/dist/api/routes/admin.d.ts.map +1 -1
- package/dist/api/routes/admin.js +21 -5
- package/dist/api/routes/admin.js.map +1 -1
- package/dist/api/routes/connect-info.d.ts +1 -0
- package/dist/api/routes/connect-info.d.ts.map +1 -1
- package/dist/api/routes/connect-info.js +66 -0
- package/dist/api/routes/connect-info.js.map +1 -1
- package/dist/api/routes/hyperliquid.d.ts +18 -0
- package/dist/api/routes/hyperliquid.d.ts.map +1 -0
- package/dist/api/routes/hyperliquid.js +131 -0
- package/dist/api/routes/hyperliquid.js.map +1 -0
- package/dist/api/routes/index.d.ts +2 -0
- package/dist/api/routes/index.d.ts.map +1 -1
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/index.js.map +1 -1
- package/dist/api/routes/openapi-schemas.d.ts +172 -33
- package/dist/api/routes/openapi-schemas.d.ts.map +1 -1
- package/dist/api/routes/openapi-schemas.js +9 -0
- package/dist/api/routes/openapi-schemas.js.map +1 -1
- package/dist/api/routes/polymarket.d.ts +34 -0
- package/dist/api/routes/polymarket.d.ts.map +1 -0
- package/dist/api/routes/polymarket.js +158 -0
- package/dist/api/routes/polymarket.js.map +1 -0
- package/dist/api/routes/staking.d.ts.map +1 -1
- package/dist/api/routes/staking.js +14 -2
- package/dist/api/routes/staking.js.map +1 -1
- package/dist/api/routes/userop.d.ts.map +1 -1
- package/dist/api/routes/userop.js +19 -17
- package/dist/api/routes/userop.js.map +1 -1
- package/dist/api/routes/wallet.d.ts.map +1 -1
- package/dist/api/routes/wallet.js +18 -0
- package/dist/api/routes/wallet.js.map +1 -1
- package/dist/api/routes/wallets.d.ts.map +1 -1
- package/dist/api/routes/wallets.js +106 -4
- package/dist/api/routes/wallets.js.map +1 -1
- package/dist/api/server.d.ts +6 -0
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +61 -1
- package/dist/api/server.js.map +1 -1
- package/dist/infrastructure/action/action-provider-registry.d.ts +6 -4
- package/dist/infrastructure/action/action-provider-registry.d.ts.map +1 -1
- package/dist/infrastructure/action/action-provider-registry.js +11 -5
- package/dist/infrastructure/action/action-provider-registry.js.map +1 -1
- package/dist/infrastructure/config/loader.d.ts +10 -0
- package/dist/infrastructure/config/loader.d.ts.map +1 -1
- package/dist/infrastructure/config/loader.js +3 -0
- package/dist/infrastructure/config/loader.js.map +1 -1
- package/dist/infrastructure/database/migrate.d.ts +1 -1
- package/dist/infrastructure/database/migrate.d.ts.map +1 -1
- package/dist/infrastructure/database/migrate.js +362 -4
- package/dist/infrastructure/database/migrate.js.map +1 -1
- package/dist/infrastructure/database/schema.d.ts +1532 -36
- package/dist/infrastructure/database/schema.d.ts.map +1 -1
- package/dist/infrastructure/database/schema.js +149 -1
- package/dist/infrastructure/database/schema.js.map +1 -1
- package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -1
- package/dist/infrastructure/settings/hot-reload.js +4 -0
- package/dist/infrastructure/settings/hot-reload.js.map +1 -1
- package/dist/infrastructure/settings/setting-keys.d.ts.map +1 -1
- package/dist/infrastructure/settings/setting-keys.js +44 -2
- package/dist/infrastructure/settings/setting-keys.js.map +1 -1
- package/dist/infrastructure/smart-account/index.d.ts +2 -2
- package/dist/infrastructure/smart-account/index.d.ts.map +1 -1
- package/dist/infrastructure/smart-account/index.js +2 -2
- package/dist/infrastructure/smart-account/index.js.map +1 -1
- package/dist/infrastructure/smart-account/smart-account-clients.d.ts +10 -2
- package/dist/infrastructure/smart-account/smart-account-clients.d.ts.map +1 -1
- package/dist/infrastructure/smart-account/smart-account-clients.js +36 -9
- package/dist/infrastructure/smart-account/smart-account-clients.js.map +1 -1
- package/dist/infrastructure/smart-account/smart-account-service.d.ts +36 -0
- package/dist/infrastructure/smart-account/smart-account-service.d.ts.map +1 -1
- package/dist/infrastructure/smart-account/smart-account-service.js +83 -4
- package/dist/infrastructure/smart-account/smart-account-service.js.map +1 -1
- package/dist/infrastructure/telegram/telegram-bot-service.js +1 -1
- package/dist/infrastructure/telegram/telegram-bot-service.js.map +1 -1
- package/dist/infrastructure/token-registry/builtin-tokens.d.ts.map +1 -1
- package/dist/infrastructure/token-registry/builtin-tokens.js +3 -0
- package/dist/infrastructure/token-registry/builtin-tokens.js.map +1 -1
- package/dist/lifecycle/daemon.d.ts +2 -0
- package/dist/lifecycle/daemon.d.ts.map +1 -1
- package/dist/lifecycle/daemon.js +188 -4
- package/dist/lifecycle/daemon.js.map +1 -1
- package/dist/pipeline/stages.d.ts +2 -0
- package/dist/pipeline/stages.d.ts.map +1 -1
- package/dist/pipeline/stages.js +75 -2
- package/dist/pipeline/stages.js.map +1 -1
- package/dist/services/admin-stats-service.js +1 -1
- package/dist/services/admin-stats-service.js.map +1 -1
- package/dist/services/incoming/__tests__/incoming-tx-monitor-service.test.js +3 -2
- package/dist/services/incoming/__tests__/incoming-tx-monitor-service.test.js.map +1 -1
- package/dist/services/incoming/__tests__/integration-wiring.test.js +2 -2
- package/dist/services/incoming/__tests__/integration-wiring.test.js.map +1 -1
- package/package.json +6 -5
- package/public/admin/assets/index--wQVT9Dz.js +3 -0
- package/public/admin/index.html +1 -1
- package/public/admin/assets/index-BmC6eyj4.js +0 -3
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
var da,ue,Hn,Kn,ct,tn,Vn,qn,Gn,$a,xa,Da,Mt={},jn=[],Ql=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,ua=Array.isArray;function Ue(t,a){for(var n in a)t[n]=a[n];return t}function Fa(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function ei(t,a,n){var l,i,r,s={};for(r in a)r=="key"?l=a[r]:r=="ref"?i=a[r]:s[r]=a[r];if(arguments.length>2&&(s.children=arguments.length>3?da.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(r in t.defaultProps)s[r]===void 0&&(s[r]=t.defaultProps[r]);return ta(t,s,l,i,null)}function ta(t,a,n,l,i){var r={type:t,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Hn,__i:-1,__u:0};return i==null&&ue.vnode!=null&&ue.vnode(r),r}function te(t){return t.children}function Dt(t,a){this.props=t,this.context=a}function gt(t,a){if(a==null)return t.__?gt(t.__,t.__i+1):null;for(var n;a<t.__k.length;a++)if((n=t.__k[a])!=null&&n.__e!=null)return n.__e;return typeof t.type=="function"?gt(t):null}function Yn(t){var a,n;if((t=t.__)!=null&&t.__c!=null){for(t.__e=t.__c.base=null,a=0;a<t.__k.length;a++)if((n=t.__k[a])!=null&&n.__e!=null){t.__e=t.__c.base=n.__e;break}return Yn(t)}}function an(t){(!t.__d&&(t.__d=!0)&&ct.push(t)&&!na.__r++||tn!=ue.debounceRendering)&&((tn=ue.debounceRendering)||Vn)(na)}function na(){for(var t,a,n,l,i,r,s,o=1;ct.length;)ct.length>o&&ct.sort(qn),t=ct.shift(),o=ct.length,t.__d&&(n=void 0,l=void 0,i=(l=(a=t).__v).__e,r=[],s=[],a.__P&&((n=Ue({},l)).__v=l.__v+1,ue.vnode&&ue.vnode(n),Ba(a.__P,n,l,a.__n,a.__P.namespaceURI,32&l.__u?[i]:null,r,i??gt(l),!!(32&l.__u),s),n.__v=l.__v,n.__.__k[n.__i]=n,Zn(r,n,s),l.__e=l.__=null,n.__e!=i&&Yn(n)));na.__r=0}function Xn(t,a,n,l,i,r,s,o,u,d,v){var h,_,A,$,W,f,N,E=l&&l.__k||jn,G=a.length;for(u=ti(n,a,E,u,G),h=0;h<G;h++)(A=n.__k[h])!=null&&(_=A.__i==-1?Mt:E[A.__i]||Mt,A.__i=h,f=Ba(t,A,_,i,r,s,o,u,d,v),$=A.__e,A.ref&&_.ref!=A.ref&&(_.ref&&za(_.ref,null,A),v.push(A.ref,A.__c||$,A)),W==null&&$!=null&&(W=$),(N=!!(4&A.__u))||_.__k===A.__k?u=Jn(A,u,t,N):typeof A.type=="function"&&f!==void 0?u=f:$&&(u=$.nextSibling),A.__u&=-7);return n.__e=W,u}function ti(t,a,n,l,i){var r,s,o,u,d,v=n.length,h=v,_=0;for(t.__k=new Array(i),r=0;r<i;r++)(s=a[r])!=null&&typeof s!="boolean"&&typeof s!="function"?(typeof s=="string"||typeof s=="number"||typeof s=="bigint"||s.constructor==String?s=t.__k[r]=ta(null,s,null,null,null):ua(s)?s=t.__k[r]=ta(te,{children:s},null,null,null):s.constructor===void 0&&s.__b>0?s=t.__k[r]=ta(s.type,s.props,s.key,s.ref?s.ref:null,s.__v):t.__k[r]=s,u=r+_,s.__=t,s.__b=t.__b+1,o=null,(d=s.__i=ai(s,n,u,h))!=-1&&(h--,(o=n[d])&&(o.__u|=2)),o==null||o.__v==null?(d==-1&&(i>v?_--:i<v&&_++),typeof s.type!="function"&&(s.__u|=4)):d!=u&&(d==u-1?_--:d==u+1?_++:(d>u?_--:_++,s.__u|=4))):t.__k[r]=null;if(h)for(r=0;r<v;r++)(o=n[r])!=null&&(2&o.__u)==0&&(o.__e==l&&(l=gt(o)),el(o,o));return l}function Jn(t,a,n,l){var i,r;if(typeof t.type=="function"){for(i=t.__k,r=0;i&&r<i.length;r++)i[r]&&(i[r].__=t,a=Jn(i[r],a,n,l));return a}t.__e!=a&&(l&&(a&&t.type&&!a.parentNode&&(a=gt(t)),n.insertBefore(t.__e,a||null)),a=t.__e);do a=a&&a.nextSibling;while(a!=null&&a.nodeType==8);return a}function ai(t,a,n,l){var i,r,s,o=t.key,u=t.type,d=a[n],v=d!=null&&(2&d.__u)==0;if(d===null&&o==null||v&&o==d.key&&u==d.type)return n;if(l>(v?1:0)){for(i=n-1,r=n+1;i>=0||r<a.length;)if((d=a[s=i>=0?i--:r++])!=null&&(2&d.__u)==0&&o==d.key&&u==d.type)return s}return-1}function nn(t,a,n){a[0]=="-"?t.setProperty(a,n??""):t[a]=n==null?"":typeof n!="number"||Ql.test(a)?n:n+"px"}function qt(t,a,n,l,i){var r,s;e:if(a=="style")if(typeof n=="string")t.style.cssText=n;else{if(typeof l=="string"&&(t.style.cssText=l=""),l)for(a in l)n&&a in n||nn(t.style,a,"");if(n)for(a in n)l&&n[a]==l[a]||nn(t.style,a,n[a])}else if(a[0]=="o"&&a[1]=="n")r=a!=(a=a.replace(Gn,"$1")),s=a.toLowerCase(),a=s in t||a=="onFocusOut"||a=="onFocusIn"?s.slice(2):a.slice(2),t.l||(t.l={}),t.l[a+r]=n,n?l?n.u=l.u:(n.u=$a,t.addEventListener(a,r?Da:xa,r)):t.removeEventListener(a,r?Da:xa,r);else{if(i=="http://www.w3.org/2000/svg")a=a.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(a!="width"&&a!="height"&&a!="href"&&a!="list"&&a!="form"&&a!="tabIndex"&&a!="download"&&a!="rowSpan"&&a!="colSpan"&&a!="role"&&a!="popover"&&a in t)try{t[a]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&a[4]!="-"?t.removeAttribute(a):t.setAttribute(a,a=="popover"&&n==1?"":n))}}function ln(t){return function(a){if(this.l){var n=this.l[a.type+t];if(a.t==null)a.t=$a++;else if(a.t<n.u)return;return n(ue.event?ue.event(a):a)}}}function Ba(t,a,n,l,i,r,s,o,u,d){var v,h,_,A,$,W,f,N,E,G,I,V,C,x,w,R,K,y=a.type;if(a.constructor!==void 0)return null;128&n.__u&&(u=!!(32&n.__u),r=[o=a.__e=n.__e]),(v=ue.__b)&&v(a);e:if(typeof y=="function")try{if(N=a.props,E="prototype"in y&&y.prototype.render,G=(v=y.contextType)&&l[v.__c],I=v?G?G.props.value:v.__:l,n.__c?f=(h=a.__c=n.__c).__=h.__E:(E?a.__c=h=new y(N,I):(a.__c=h=new Dt(N,I),h.constructor=y,h.render=li),G&&G.sub(h),h.state||(h.state={}),h.__n=l,_=h.__d=!0,h.__h=[],h._sb=[]),E&&h.__s==null&&(h.__s=h.state),E&&y.getDerivedStateFromProps!=null&&(h.__s==h.state&&(h.__s=Ue({},h.__s)),Ue(h.__s,y.getDerivedStateFromProps(N,h.__s))),A=h.props,$=h.state,h.__v=a,_)E&&y.getDerivedStateFromProps==null&&h.componentWillMount!=null&&h.componentWillMount(),E&&h.componentDidMount!=null&&h.__h.push(h.componentDidMount);else{if(E&&y.getDerivedStateFromProps==null&&N!==A&&h.componentWillReceiveProps!=null&&h.componentWillReceiveProps(N,I),a.__v==n.__v||!h.__e&&h.shouldComponentUpdate!=null&&h.shouldComponentUpdate(N,h.__s,I)===!1){for(a.__v!=n.__v&&(h.props=N,h.state=h.__s,h.__d=!1),a.__e=n.__e,a.__k=n.__k,a.__k.some(function(p){p&&(p.__=a)}),V=0;V<h._sb.length;V++)h.__h.push(h._sb[V]);h._sb=[],h.__h.length&&s.push(h);break e}h.componentWillUpdate!=null&&h.componentWillUpdate(N,h.__s,I),E&&h.componentDidUpdate!=null&&h.__h.push(function(){h.componentDidUpdate(A,$,W)})}if(h.context=I,h.props=N,h.__P=t,h.__e=!1,C=ue.__r,x=0,E){for(h.state=h.__s,h.__d=!1,C&&C(a),v=h.render(h.props,h.state,h.context),w=0;w<h._sb.length;w++)h.__h.push(h._sb[w]);h._sb=[]}else do h.__d=!1,C&&C(a),v=h.render(h.props,h.state,h.context),h.state=h.__s;while(h.__d&&++x<25);h.state=h.__s,h.getChildContext!=null&&(l=Ue(Ue({},l),h.getChildContext())),E&&!_&&h.getSnapshotBeforeUpdate!=null&&(W=h.getSnapshotBeforeUpdate(A,$)),R=v,v!=null&&v.type===te&&v.key==null&&(R=Qn(v.props.children)),o=Xn(t,ua(R)?R:[R],a,n,l,i,r,s,o,u,d),h.base=a.__e,a.__u&=-161,h.__h.length&&s.push(h),f&&(h.__E=h.__=null)}catch(p){if(a.__v=null,u||r!=null)if(p.then){for(a.__u|=u?160:128;o&&o.nodeType==8&&o.nextSibling;)o=o.nextSibling;r[r.indexOf(o)]=null,a.__e=o}else{for(K=r.length;K--;)Fa(r[K]);La(a)}else a.__e=n.__e,a.__k=n.__k,p.then||La(a);ue.__e(p,a,n)}else r==null&&a.__v==n.__v?(a.__k=n.__k,a.__e=n.__e):o=a.__e=ni(n.__e,a,n,l,i,r,s,u,d);return(v=ue.diffed)&&v(a),128&a.__u?void 0:o}function La(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(La)}function Zn(t,a,n){for(var l=0;l<n.length;l++)za(n[l],n[++l],n[++l]);ue.__c&&ue.__c(a,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(r){r.call(i)})}catch(r){ue.__e(r,i.__v)}})}function Qn(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:ua(t)?t.map(Qn):Ue({},t)}function ni(t,a,n,l,i,r,s,o,u){var d,v,h,_,A,$,W,f=n.props||Mt,N=a.props,E=a.type;if(E=="svg"?i="http://www.w3.org/2000/svg":E=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),r!=null){for(d=0;d<r.length;d++)if((A=r[d])&&"setAttribute"in A==!!E&&(E?A.localName==E:A.nodeType==3)){t=A,r[d]=null;break}}if(t==null){if(E==null)return document.createTextNode(N);t=document.createElementNS(i,E,N.is&&N),o&&(ue.__m&&ue.__m(a,r),o=!1),r=null}if(E==null)f===N||o&&t.data==N||(t.data=N);else{if(r=r&&da.call(t.childNodes),!o&&r!=null)for(f={},d=0;d<t.attributes.length;d++)f[(A=t.attributes[d]).name]=A.value;for(d in f)if(A=f[d],d!="children"){if(d=="dangerouslySetInnerHTML")h=A;else if(!(d in N)){if(d=="value"&&"defaultValue"in N||d=="checked"&&"defaultChecked"in N)continue;qt(t,d,null,A,i)}}for(d in N)A=N[d],d=="children"?_=A:d=="dangerouslySetInnerHTML"?v=A:d=="value"?$=A:d=="checked"?W=A:o&&typeof A!="function"||f[d]===A||qt(t,d,A,f[d],i);if(v)o||h&&(v.__html==h.__html||v.__html==t.innerHTML)||(t.innerHTML=v.__html),a.__k=[];else if(h&&(t.innerHTML=""),Xn(a.type=="template"?t.content:t,ua(_)?_:[_],a,n,l,E=="foreignObject"?"http://www.w3.org/1999/xhtml":i,r,s,r?r[0]:n.__k&>(n,0),o,u),r!=null)for(d=r.length;d--;)Fa(r[d]);o||(d="value",E=="progress"&&$==null?t.removeAttribute("value"):$!=null&&($!==t[d]||E=="progress"&&!$||E=="option"&&$!=f[d])&&qt(t,d,$,f[d],i),d="checked",W!=null&&W!=t[d]&&qt(t,d,W,f[d],i))}return t}function za(t,a,n){try{if(typeof t=="function"){var l=typeof t.__u=="function";l&&t.__u(),l&&a==null||(t.__u=t(a))}else t.current=a}catch(i){ue.__e(i,n)}}function el(t,a,n){var l,i;if(ue.unmount&&ue.unmount(t),(l=t.ref)&&(l.current&&l.current!=t.__e||za(l,null,a)),(l=t.__c)!=null){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(r){ue.__e(r,a)}l.base=l.__P=null}if(l=t.__k)for(i=0;i<l.length;i++)l[i]&&el(l[i],a,n||typeof t.type!="function");n||Fa(t.__e),t.__c=t.__=t.__e=void 0}function li(t,a,n){return this.constructor(t,n)}function ii(t,a,n){var l,i,r,s;a==document&&(a=document.documentElement),ue.__&&ue.__(t,a),i=(l=!1)?null:a.__k,r=[],s=[],Ba(a,t=a.__k=ei(te,null,[t]),i||Mt,Mt,a.namespaceURI,i?null:a.firstChild?da.call(a.childNodes):null,r,i?i.__e:a.firstChild,l,s),Zn(r,t,s)}da=jn.slice,ue={__e:function(t,a,n,l){for(var i,r,s;a=a.__;)if((i=a.__c)&&!i.__)try{if((r=i.constructor)&&r.getDerivedStateFromError!=null&&(i.setState(r.getDerivedStateFromError(t)),s=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,l||{}),s=i.__d),s)return i.__E=i}catch(o){t=o}throw t}},Hn=0,Kn=function(t){return t!=null&&t.constructor===void 0},Dt.prototype.setState=function(t,a){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=Ue({},this.state),typeof t=="function"&&(t=t(Ue({},n),this.props)),t&&Ue(n,t),t!=null&&this.__v&&(a&&this._sb.push(a),an(this))},Dt.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),an(this))},Dt.prototype.render=te,ct=[],Vn=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,qn=function(t,a){return t.__v.__b-a.__v.__b},na.__r=0,Gn=/(PointerCapture)$|Capture$/i,$a=0,xa=ln(!1),Da=ln(!0);var ri=0;function e(t,a,n,l,i,r){a||(a={});var s,o,u=a;if("ref"in u)for(o in u={},a)o=="ref"?s=a[o]:u[o]=a[o];var d={type:t,props:u,key:n,ref:s,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--ri,__i:-1,__u:0,__source:i,__self:r};if(typeof t=="function"&&(s=t.defaultProps))for(o in s)u[o]===void 0&&(u[o]=s[o]);return ue.vnode&&ue.vnode(d),d}var la,Ee,_a,rn,Ra=0,tl=[],ye=ue,sn=ye.__b,on=ye.__r,cn=ye.diffed,dn=ye.__c,un=ye.unmount,vn=ye.__;function al(t,a){ye.__h&&ye.__h(Ee,t,Ra||a),Ra=0;var n=Ee.__H||(Ee.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function X(t,a){var n=al(la++,3);!ye.__s&&nl(n.__H,a)&&(n.__=t,n.u=a,Ee.__H.__h.push(n))}function Fe(t){return Ra=5,va(function(){return{current:t}},[])}function va(t,a){var n=al(la++,7);return nl(n.__H,a)&&(n.__=t(),n.__H=a,n.__h=t),n.__}function si(){for(var t;t=tl.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach(aa),t.__H.__h.forEach(Oa),t.__H.__h=[]}catch(a){t.__H.__h=[],ye.__e(a,t.__v)}}ye.__b=function(t){Ee=null,sn&&sn(t)},ye.__=function(t,a){t&&a.__k&&a.__k.__m&&(t.__m=a.__k.__m),vn&&vn(t,a)},ye.__r=function(t){on&&on(t),la=0;var a=(Ee=t.__c).__H;a&&(_a===Ee?(a.__h=[],Ee.__h=[],a.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(a.__h.forEach(aa),a.__h.forEach(Oa),a.__h=[],la=0)),_a=Ee},ye.diffed=function(t){cn&&cn(t);var a=t.__c;a&&a.__H&&(a.__H.__h.length&&(tl.push(a)!==1&&rn===ye.requestAnimationFrame||((rn=ye.requestAnimationFrame)||oi)(si)),a.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),_a=Ee=null},ye.__c=function(t,a){a.some(function(n){try{n.__h.forEach(aa),n.__h=n.__h.filter(function(l){return!l.__||Oa(l)})}catch(l){a.some(function(i){i.__h&&(i.__h=[])}),a=[],ye.__e(l,n.__v)}}),dn&&dn(t,a)},ye.unmount=function(t){un&&un(t);var a,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(l){try{aa(l)}catch(i){a=i}}),n.__H=void 0,a&&ye.__e(a,n.__v))};var hn=typeof requestAnimationFrame=="function";function oi(t){var a,n=function(){clearTimeout(l),hn&&cancelAnimationFrame(a),setTimeout(t)},l=setTimeout(n,35);hn&&(a=requestAnimationFrame(n))}function aa(t){var a=Ee,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),Ee=a}function Oa(t){var a=Ee;t.__c=t.__(),Ee=a}function nl(t,a){return!t||t.length!==a.length||a.some(function(n,l){return n!==t[l]})}var ci=Symbol.for("preact-signals");function ha(){if(et>1)et--;else{for(var t,a=!1;Lt!==void 0;){var n=Lt;for(Lt=void 0,Pa++;n!==void 0;){var l=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&rl(n))try{n.c()}catch(i){a||(t=i,a=!0)}n=l}}if(Pa=0,et--,a)throw t}}function di(t){if(et>0)return t();et++;try{return t()}finally{ha()}}var de=void 0;function ll(t){var a=de;de=void 0;try{return t()}finally{de=a}}var Lt=void 0,et=0,Pa=0,ia=0;function il(t){if(de!==void 0){var a=t.n;if(a===void 0||a.t!==de)return a={i:0,S:t,p:de.s,n:void 0,t:de,e:void 0,x:void 0,r:a},de.s!==void 0&&(de.s.n=a),de.s=a,t.n=a,32&de.f&&t.S(a),a;if(a.i===-1)return a.i=0,a.n!==void 0&&(a.n.p=a.p,a.p!==void 0&&(a.p.n=a.n),a.p=de.s,a.n=void 0,de.s.n=a,de.s=a),a}}function Te(t,a){this.v=t,this.i=0,this.n=void 0,this.t=void 0,this.W=a?.watched,this.Z=a?.unwatched,this.name=a?.name}Te.prototype.brand=ci;Te.prototype.h=function(){return!0};Te.prototype.S=function(t){var a=this,n=this.t;n!==t&&t.e===void 0&&(t.x=n,this.t=t,n!==void 0?n.e=t:ll(function(){var l;(l=a.W)==null||l.call(a)}))};Te.prototype.U=function(t){var a=this;if(this.t!==void 0){var n=t.e,l=t.x;n!==void 0&&(n.x=l,t.e=void 0),l!==void 0&&(l.e=n,t.x=void 0),t===this.t&&(this.t=l,l===void 0&&ll(function(){var i;(i=a.Z)==null||i.call(a)}))}};Te.prototype.subscribe=function(t){var a=this;return $t(function(){var n=a.value,l=de;de=void 0;try{t(n)}finally{de=l}},{name:"sub"})};Te.prototype.valueOf=function(){return this.value};Te.prototype.toString=function(){return this.value+""};Te.prototype.toJSON=function(){return this.value};Te.prototype.peek=function(){var t=de;de=void 0;try{return this.value}finally{de=t}};Object.defineProperty(Te.prototype,"value",{get:function(){var t=il(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(Pa>100)throw new Error("Cycle detected");this.v=t,this.i++,ia++,et++;try{for(var a=this.t;a!==void 0;a=a.x)a.t.N()}finally{ha()}}}});function Ne(t,a){return new Te(t,a)}function rl(t){for(var a=t.s;a!==void 0;a=a.n)if(a.S.i!==a.i||!a.S.h()||a.S.i!==a.i)return!0;return!1}function sl(t){for(var a=t.s;a!==void 0;a=a.n){var n=a.S.n;if(n!==void 0&&(a.r=n),a.S.n=a,a.i=-1,a.n===void 0){t.s=a;break}}}function ol(t){for(var a=t.s,n=void 0;a!==void 0;){var l=a.p;a.i===-1?(a.S.U(a),l!==void 0&&(l.n=a.n),a.n!==void 0&&(a.n.p=l)):n=a,a.S.n=a.r,a.r!==void 0&&(a.r=void 0),a=l}t.s=n}function ut(t,a){Te.call(this,void 0),this.x=t,this.s=void 0,this.g=ia-1,this.f=4,this.W=a?.watched,this.Z=a?.unwatched,this.name=a?.name}ut.prototype=new Te;ut.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ia))return!0;if(this.g=ia,this.f|=1,this.i>0&&!rl(this))return this.f&=-2,!0;var t=de;try{sl(this),de=this;var a=this.x();(16&this.f||this.v!==a||this.i===0)&&(this.v=a,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return de=t,ol(this),this.f&=-2,!0};ut.prototype.S=function(t){if(this.t===void 0){this.f|=36;for(var a=this.s;a!==void 0;a=a.n)a.S.S(a)}Te.prototype.S.call(this,t)};ut.prototype.U=function(t){if(this.t!==void 0&&(Te.prototype.U.call(this,t),this.t===void 0)){this.f&=-33;for(var a=this.s;a!==void 0;a=a.n)a.S.U(a)}};ut.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var t=this.t;t!==void 0;t=t.x)t.t.N()}};Object.defineProperty(ut.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=il(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function Wt(t,a){return new ut(t,a)}function cl(t){var a=t.u;if(t.u=void 0,typeof a=="function"){et++;var n=de;de=void 0;try{a()}catch(l){throw t.f&=-2,t.f|=8,Ha(t),l}finally{de=n,ha()}}}function Ha(t){for(var a=t.s;a!==void 0;a=a.n)a.S.U(a);t.x=void 0,t.s=void 0,cl(t)}function ui(t){if(de!==this)throw new Error("Out-of-order effect");ol(this),de=t,this.f&=-2,8&this.f&&Ha(this),ha()}function _t(t,a){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=a?.name}_t.prototype.c=function(){var t=this.S();try{if(8&this.f||this.x===void 0)return;var a=this.x();typeof a=="function"&&(this.u=a)}finally{t()}};_t.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,cl(this),sl(this),et++;var t=de;return de=this,ui.bind(this,t)};_t.prototype.N=function(){2&this.f||(this.f|=2,this.o=Lt,Lt=this)};_t.prototype.d=function(){this.f|=8,1&this.f||Ha(this)};_t.prototype.dispose=function(){this.d()};function $t(t,a){var n=new _t(t,a);try{n.c()}catch(i){throw n.d(),i}var l=n.d.bind(n);return l[Symbol.dispose]=l,l}var dl,pa,Gt,vi=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,ul=[];$t(function(){dl=this.N})();function bt(t,a){ue[t]=a.bind(null,ue[t]||function(){})}function ra(t){if(Gt){var a=Gt;Gt=void 0,a()}Gt=t&&t.S()}function vl(t){var a=this,n=t.data,l=c(n);l.value=n;var i=va(function(){for(var o=a,u=a.__v;u=u.__;)if(u.__c){u.__c.__$f|=4;break}var d=Wt(function(){var A=l.value.value;return A===0?0:A===!0?"":A||""}),v=Wt(function(){return!Array.isArray(d.value)&&!Kn(d.value)}),h=$t(function(){if(this.N=hl,v.value){var A=d.value;o.__v&&o.__v.__e&&o.__v.__e.nodeType===3&&(o.__v.__e.data=A)}}),_=a.__$u.d;return a.__$u.d=function(){h(),_.call(this)},[v,d]},[]),r=i[0],s=i[1];return r.value?s.peek():s.value}vl.displayName="ReactiveTextNode";Object.defineProperties(Te.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:vl},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});bt("__b",function(t,a){if(typeof a.type=="string"){var n,l=a.props;for(var i in l)if(i!=="children"){var r=l[i];r instanceof Te&&(n||(a.__np=n={}),n[i]=r,l[i]=r.peek())}}t(a)});bt("__r",function(t,a){if(t(a),a.type!==te){ra();var n,l=a.__c;l&&(l.__$f&=-2,(n=l.__$u)===void 0&&(l.__$u=n=(function(i,r){var s;return $t(function(){s=this},{name:r}),s.c=i,s})(function(){var i;vi&&((i=n.y)==null||i.call(n)),l.__$f|=1,l.setState({})},typeof a.type=="function"?a.type.displayName||a.type.name:""))),pa=l,ra(n)}});bt("__e",function(t,a,n,l){ra(),pa=void 0,t(a,n,l)});bt("diffed",function(t,a){ra(),pa=void 0;var n;if(typeof a.type=="string"&&(n=a.__e)){var l=a.__np,i=a.props;if(l){var r=n.U;if(r)for(var s in r){var o=r[s];o!==void 0&&!(s in l)&&(o.d(),r[s]=void 0)}else r={},n.U=r;for(var u in l){var d=r[u],v=l[u];d===void 0?(d=hi(n,u,v,i),r[u]=d):d.o(v,i)}}}t(a)});function hi(t,a,n,l){var i=a in t&&t.ownerSVGElement===void 0,r=Ne(n);return{o:function(s,o){r.value=s,l=o},d:$t(function(){this.N=hl;var s=r.value.value;l[a]!==s&&(l[a]=s,i?t[a]=s:s!=null&&(s!==!1||a[4]==="-")?t.setAttribute(a,s):t.removeAttribute(a))})}}bt("unmount",function(t,a){if(typeof a.type=="string"){var n=a.__e;if(n){var l=n.U;if(l){n.U=void 0;for(var i in l){var r=l[i];r&&r.d()}}}}else{var s=a.__c;if(s){var o=s.__$u;o&&(s.__$u=void 0,o.d())}}t(a)});bt("__h",function(t,a,n,l){(l<3||l===9)&&(a.__$f|=2),t(a,n,l)});Dt.prototype.shouldComponentUpdate=function(t,a){if(this.__R)return!0;var n=this.__$u,l=n&&n.s!==void 0;for(var i in a)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var r=2&this.__$f;if(!(l||r||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var s in t)if(s!=="__source"&&t[s]!==this.props[s])return!0;for(var o in this.props)if(!(o in t))return!0;return!1};function c(t,a){return va(function(){return Ne(t,a)},[])}function ma(t,a){var n=Fe(t);return n.current=t,pa.__$f|=4,va(function(){return Wt(function(){return n.current()},a)},[])}var pi=function(t){queueMicrotask(function(){queueMicrotask(t)})};function mi(){di(function(){for(var t;t=ul.shift();)dl.call(t)})}function hl(){ul.push(this)===1&&(ue.requestAnimationFrame||pi)(mi)}const Ut=Ne(null),fi=Wt(()=>Ut.value!==null),pl=Ne(900),gi=Ne(!1);let mt=null;const ft=()=>{Ka()};function yi(){document.addEventListener("mousemove",ft,{passive:!0}),document.addEventListener("keydown",ft,{passive:!0}),document.addEventListener("click",ft,{passive:!0}),Ka()}function _i(){document.removeEventListener("mousemove",ft),document.removeEventListener("keydown",ft),document.removeEventListener("click",ft),mt!==null&&(clearTimeout(mt),mt=null)}function Ka(){mt!==null&&clearTimeout(mt),mt=setTimeout(()=>{fa()},pl.value*1e3)}function bi(t,a){Ut.value=t,a!==void 0&&(pl.value=a),yi(),location.hash="#/dashboard"}function fa(){Ut.value=null,_i(),location.hash="#/login"}const D={ADMIN_STATUS:"/v1/admin/status",ADMIN_KILL_SWITCH:"/v1/admin/kill-switch",ADMIN_KILL_SWITCH_ESCALATE:"/v1/admin/kill-switch/escalate",ADMIN_RECOVER:"/v1/admin/recover",ADMIN_SHUTDOWN:"/v1/admin/shutdown",ADMIN_ROTATE_SECRET:"/v1/admin/rotate-secret",WALLETS:"/v1/wallets",WALLET:t=>`/v1/wallets/${t}`,SESSIONS:"/v1/sessions",SESSION:t=>`/v1/sessions/${t}`,POLICIES:"/v1/policies",POLICY:t=>`/v1/policies/${t}`,TOKENS:"/v1/tokens",ADMIN_NOTIFICATIONS_STATUS:"/v1/admin/notifications/status",ADMIN_NOTIFICATIONS_TEST:"/v1/admin/notifications/test",ADMIN_NOTIFICATIONS_LOG:"/v1/admin/notifications/log",MCP_TOKENS:"/v1/mcp/tokens",ADMIN_SETTINGS:"/v1/admin/settings",ADMIN_SETTINGS_TEST_RPC:"/v1/admin/settings/test-rpc",ADMIN_RPC_STATUS:"/v1/admin/rpc-status",WALLET_NETWORKS:t=>`/v1/wallets/${t}/networks`,ADMIN_WALLET_BALANCE:t=>`/v1/admin/wallets/${t}/balance`,ADMIN_WALLET_TRANSACTIONS:t=>`/v1/admin/wallets/${t}/transactions`,ADMIN_API_KEYS:"/v1/admin/api-keys",ADMIN_API_KEY:t=>`/v1/admin/api-keys/${t}`,ADMIN_FOREX_RATES:"/v1/admin/forex/rates",ADMIN_TELEGRAM_USERS:"/v1/admin/telegram-users",ADMIN_TELEGRAM_USER:t=>`/v1/admin/telegram-users/${t}`,WALLET_OWNER:t=>`/v1/wallets/${t}/owner`,WALLET_WITHDRAW:t=>`/v1/wallets/${t}/withdraw`,WALLET_WC_PAIR:t=>`/v1/wallets/${t}/wc/pair`,WALLET_WC_SESSION:t=>`/v1/wallets/${t}/wc/session`,WALLET_WC_PAIR_STATUS:t=>`/v1/wallets/${t}/wc/pair/status`,WALLET_OWNER_VERIFY:t=>`/v1/wallets/${t}/owner/verify`,WALLET_SUSPEND:t=>`/v1/wallets/${t}/suspend`,WALLET_RESUME:t=>`/v1/wallets/${t}/resume`,WALLET_PURGE:t=>`/v1/wallets/${t}/purge`,ADMIN_AGENT_PROMPT:"/v1/admin/agent-prompt",ADMIN_SESSION_REISSUE:t=>`/v1/admin/sessions/${t}/reissue`,ADMIN_TRANSACTIONS:"/v1/admin/transactions",ADMIN_TX_CANCEL:t=>`/v1/admin/transactions/${t}/cancel`,ADMIN_TX_REJECT:t=>`/v1/admin/transactions/${t}/reject`,ADMIN_INCOMING:"/v1/admin/incoming",WALLET_PATCH:t=>`/v1/wallets/${t}`,TOKENS_RESOLVE:"/v1/tokens/resolve",ACTIONS_PROVIDERS:"/v1/actions/providers",ADMIN_ACTIONS:"/v1/admin/actions",ADMIN_WALLET_STAKING:t=>`/v1/admin/wallets/${t}/staking`,ADMIN_DEFI_POSITIONS:"/v1/admin/defi/positions",ADMIN_MASTER_PASSWORD:"/v1/admin/master-password",ADMIN_WALLET_APPS:"/v1/admin/wallet-apps",ADMIN_WALLET_APP:t=>`/v1/admin/wallet-apps/${t}`,ADMIN_WALLET_APP_TEST_NOTIFICATION:t=>`/v1/admin/wallet-apps/${t}/test-notification`,ADMIN_AUDIT_LOGS:"/v1/audit-logs",ADMIN_STATS:"/v1/admin/stats",ADMIN_AUTOSTOP_RULES:"/v1/admin/autostop/rules",ERC8004_AGENT:t=>`/v1/erc8004/agent/${t}`,ERC8004_REPUTATION:t=>`/v1/erc8004/agent/${t}/reputation`,ERC8004_REGISTRATION_FILE:t=>`/v1/erc8004/registration-file/${t}`,ERC8004_VALIDATION:t=>`/v1/erc8004/validation/${t}`,WALLET_PROVIDER:t=>`/v1/wallets/${t}/provider`,ADMIN_WALLET_NFTS:t=>`/v1/wallets/${t}/nfts`,ADMIN_WALLET_NFT_METADATA:(t,a)=>`/v1/wallets/${t}/nfts/${a}`},Rt=Ne(""),pt=Ne(null),Ot=Ne(!1),Ve={wrapper:{display:"flex",alignItems:"center",justifyContent:"center",minHeight:"100vh",background:"var(--color-bg-secondary)"},card:{background:"var(--color-bg)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-lg)",padding:"var(--space-8)",width:"100%",maxWidth:"360px",boxShadow:"var(--shadow-md)"},title:{fontSize:"var(--font-size-2xl)",fontWeight:"var(--font-weight-bold)",textAlign:"center",marginBottom:"var(--space-1)"},subtitle:{fontSize:"var(--font-size-sm)",color:"var(--color-text-secondary)",textAlign:"center",marginBottom:"var(--space-6)"},input:{width:"100%",padding:"var(--space-2) var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",fontSize:"var(--font-size-base)",outline:"none"},button:{width:"100%",padding:"var(--space-2) var(--space-4)",background:"var(--color-primary)",color:"white",border:"none",borderRadius:"var(--radius-md)",fontSize:"var(--font-size-base)",fontWeight:"var(--font-weight-medium)",marginTop:"var(--space-4)"},buttonDisabled:{opacity:.6,cursor:"not-allowed"},error:{color:"var(--color-danger)",fontSize:"var(--font-size-sm)",textAlign:"center",marginTop:"var(--space-3)"}},wi=async t=>{if(t.preventDefault(),!!Rt.value.trim()){Ot.value=!0,pt.value=null;try{const a=await fetch(D.ADMIN_STATUS,{headers:{"X-Master-Password":Rt.value},signal:AbortSignal.timeout(1e4)});if(a.status===401){pt.value="Invalid master password";return}if(!a.ok){pt.value="Cannot connect to daemon";return}const n=await a.json();bi(Rt.value,n.adminTimeout)}catch{pt.value="Cannot connect to daemon"}finally{Ot.value=!1}}};function Si(){return e("div",{style:Ve.wrapper,children:e("form",{style:Ve.card,onSubmit:wi,children:[e("h1",{style:Ve.title,children:"WAIaaS Admin"}),e("p",{style:Ve.subtitle,children:"Enter master password to continue"}),e("input",{type:"password",placeholder:"Master password",autoFocus:!0,value:Rt.value,onInput:t=>{Rt.value=t.target.value},style:Ve.input}),e("button",{type:"submit",disabled:Ot.value,style:{...Ve.button,...Ot.value?Ve.buttonDisabled:{}},children:Ot.value?"Signing in...":"Sign in"}),pt.value&&e("p",{style:Ve.error,children:pt.value})]})})}const Ti=[{id:"wallets.rpc.solana_mainnet",label:"Solana Mainnet",description:"RPC endpoint URL for Solana mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_mainnet",keywords:["blockchain","rpc","solana","url","endpoint"]},{id:"wallets.rpc.solana_devnet",label:"Solana Devnet",description:"RPC endpoint URL for Solana devnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_devnet",keywords:["blockchain","rpc","solana","url","endpoint","test"]},{id:"wallets.rpc.solana_testnet",label:"Solana Testnet",description:"RPC endpoint URL for Solana testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.solana_testnet",keywords:["blockchain","rpc","solana","url","endpoint","test"]},{id:"wallets.rpc.evm_ethereum_mainnet",label:"Ethereum Mainnet",description:"RPC endpoint URL for Ethereum mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_ethereum_mainnet",keywords:["blockchain","rpc","evm","ethereum","url","endpoint"]},{id:"wallets.rpc.evm_ethereum_sepolia",label:"Ethereum Sepolia",description:"RPC endpoint URL for Ethereum Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_ethereum_sepolia",keywords:["blockchain","rpc","evm","ethereum","url","endpoint","test"]},{id:"wallets.rpc.evm_polygon_mainnet",label:"Polygon Mainnet",description:"RPC endpoint URL for Polygon mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_polygon_mainnet",keywords:["blockchain","rpc","evm","polygon","matic","url","endpoint"]},{id:"wallets.rpc.evm_polygon_amoy",label:"Polygon Amoy",description:"RPC endpoint URL for Polygon Amoy testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_polygon_amoy",keywords:["blockchain","rpc","evm","polygon","url","endpoint","test"]},{id:"wallets.rpc.evm_arbitrum_mainnet",label:"Arbitrum Mainnet",description:"RPC endpoint URL for Arbitrum mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_arbitrum_mainnet",keywords:["blockchain","rpc","evm","arbitrum","l2","url","endpoint"]},{id:"wallets.rpc.evm_arbitrum_sepolia",label:"Arbitrum Sepolia",description:"RPC endpoint URL for Arbitrum Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_arbitrum_sepolia",keywords:["blockchain","rpc","evm","arbitrum","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_optimism_mainnet",label:"Optimism Mainnet",description:"RPC endpoint URL for Optimism mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_optimism_mainnet",keywords:["blockchain","rpc","evm","optimism","l2","url","endpoint"]},{id:"wallets.rpc.evm_optimism_sepolia",label:"Optimism Sepolia",description:"RPC endpoint URL for Optimism Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_optimism_sepolia",keywords:["blockchain","rpc","evm","optimism","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_base_mainnet",label:"Base Mainnet",description:"RPC endpoint URL for Base mainnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_base_mainnet",keywords:["blockchain","rpc","evm","base","coinbase","l2","url","endpoint"]},{id:"wallets.rpc.evm_base_sepolia",label:"Base Sepolia",description:"RPC endpoint URL for Base Sepolia testnet",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_base_sepolia",keywords:["blockchain","rpc","evm","base","coinbase","l2","url","endpoint","test"]},{id:"wallets.rpc.evm_hyperevm_mainnet",label:"HyperEVM Mainnet",description:"RPC endpoint URL for HyperEVM mainnet (Hyperliquid)",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_hyperevm_mainnet",keywords:["blockchain","rpc","evm","hyperevm","hyperliquid","url","endpoint"]},{id:"wallets.rpc.evm_hyperevm_testnet",label:"HyperEVM Testnet",description:"RPC endpoint URL for HyperEVM testnet (Hyperliquid)",page:"/wallets",tab:"rpc",fieldName:"rpc.evm_hyperevm_testnet",keywords:["blockchain","rpc","evm","hyperevm","hyperliquid","url","endpoint","test"]},{id:"notifications.balance.enabled",label:"Enabled",description:"Enable or disable balance monitoring",page:"/notifications",tab:"balance",fieldName:"monitoring.enabled",keywords:["balance","monitoring","toggle","enable"]},{id:"notifications.balance.check_interval_sec",label:"Check Interval (seconds)",description:"How often to check wallet balances",page:"/notifications",tab:"balance",fieldName:"monitoring.check_interval_sec",keywords:["balance","monitoring","interval","frequency"]},{id:"notifications.balance.low_balance_threshold_sol",label:"Low Balance Threshold (SOL)",description:"Alert when SOL balance drops below this amount",page:"/notifications",tab:"balance",fieldName:"monitoring.low_balance_threshold_sol",keywords:["balance","monitoring","threshold","solana","alert","low"]},{id:"notifications.balance.low_balance_threshold_eth",label:"Low Balance Threshold (ETH)",description:"Alert when ETH balance drops below this amount",page:"/notifications",tab:"balance",fieldName:"monitoring.low_balance_threshold_eth",keywords:["balance","monitoring","threshold","ethereum","alert","low"]},{id:"notifications.balance.cooldown_hours",label:"Alert Cooldown (hours)",description:"Suppress duplicate alerts for this many hours",page:"/notifications",tab:"balance",fieldName:"monitoring.cooldown_hours",keywords:["balance","monitoring","cooldown","alert","suppress"]},{id:"wallets.walletconnect.project_id",label:"Project ID",description:"WalletConnect Cloud project identifier",page:"/wallets",tab:"walletconnect",fieldName:"walletconnect.project_id",keywords:["walletconnect","project","cloud","dapp"]},{id:"wallets.walletconnect.relay_url",label:"Relay URL",description:"WalletConnect relay server URL",page:"/wallets",tab:"walletconnect",fieldName:"walletconnect.relay_url",keywords:["walletconnect","relay","websocket","server"]},{id:"sessions.settings.max_sessions_per_wallet",label:"Max Sessions per Wallet",description:"Maximum concurrent sessions for a single wallet",page:"/sessions",tab:"settings",fieldName:"security.max_sessions_per_wallet",keywords:["session","limit","concurrent","wallet"]},{id:"sessions.settings.max_pending_tx",label:"Max Pending Transactions",description:"Maximum in-flight transactions per session",page:"/sessions",tab:"settings",fieldName:"security.max_pending_tx",keywords:["transaction","pending","limit","queue"]},{id:"sessions.settings.rate_limit_session_rpm",label:"Session Rate Limit (RPM)",description:"Max requests per minute per session",page:"/sessions",tab:"settings",fieldName:"security.rate_limit_session_rpm",keywords:["rate","limit","rpm","session","throttle"]},{id:"sessions.settings.rate_limit_tx_rpm",label:"Transaction Rate Limit (RPM)",description:"Max transaction requests per minute per session",page:"/sessions",tab:"settings",fieldName:"security.rate_limit_tx_rpm",keywords:["rate","limit","rpm","transaction","throttle"]},{id:"policies.defaults.policy_defaults_delay_seconds",label:"Policy Delay (seconds)",description:"Default delay before executing delayed-tier transactions",page:"/policies",tab:"defaults",fieldName:"security.policy_defaults_delay_seconds",keywords:["policy","delay","default","seconds","timer"]},{id:"policies.defaults.policy_defaults_approval_timeout",label:"Approval Timeout (seconds)",description:"How long to wait for owner approval before timeout",page:"/policies",tab:"defaults",fieldName:"security.policy_defaults_approval_timeout",keywords:["policy","approval","timeout","owner","default"]},{id:"policies.defaults.default_deny_tokens",label:"Default Deny: Token Transfers",description:"Deny token transfers unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_tokens",keywords:["policy","deny","token","transfer","default","security"]},{id:"policies.defaults.default_deny_contracts",label:"Default Deny: Contract Calls",description:"Deny contract calls unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_contracts",keywords:["policy","deny","contract","call","default","security"]},{id:"policies.defaults.default_deny_spenders",label:"Default Deny: Token Approvals",description:"Deny token approvals unless a matching whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_spenders",keywords:["policy","deny","spender","approval","default","security"]},{id:"policies.defaults.default_deny_erc8128_domains",label:"Default Deny: ERC-8128 Domains",description:"Deny ERC-8128 signing unless a matching domain whitelist policy exists",page:"/policies",tab:"defaults",fieldName:"policy.default_deny_erc8128_domains",keywords:["erc8128","deny","domain","whitelist","policy"]},{id:"notifications.settings.enabled",label:"Enabled",description:"Enable or disable notifications globally",page:"/notifications",tab:"settings",fieldName:"notifications.enabled",keywords:["notifications","enable","toggle","global"]},{id:"notifications.settings.telegram_bot_token",label:"Telegram Bot Token",description:"Bot token for Telegram notifications",page:"/notifications",tab:"settings",fieldName:"notifications.telegram_bot_token",keywords:["telegram","bot","token","notification","credential"]},{id:"notifications.settings.telegram_chat_id",label:"Telegram Chat ID",description:"Chat ID for Telegram notification delivery",page:"/notifications",tab:"settings",fieldName:"notifications.telegram_chat_id",keywords:["telegram","chat","notification"]},{id:"notifications.settings.locale",label:"Locale",description:"Language for notification messages",page:"/notifications",tab:"settings",fieldName:"notifications.locale",keywords:["locale","language","notification","i18n"]},{id:"notifications.settings.discord_webhook_url",label:"Discord Webhook URL",description:"Webhook URL for Discord notifications",page:"/notifications",tab:"settings",fieldName:"notifications.discord_webhook_url",keywords:["discord","webhook","notification","credential"]},{id:"notifications.settings.ntfy_server",label:"Ntfy Server",description:"Server URL for ntfy notifications",page:"/notifications",tab:"settings",fieldName:"notifications.ntfy_server",keywords:["ntfy","server","push","notification"]},{id:"notifications.settings.ntfy_topic",label:"Ntfy Topic",description:"Topic name for ntfy notifications",page:"/notifications",tab:"settings",fieldName:"notifications.ntfy_topic",keywords:["ntfy","topic","push","notification"]},{id:"notifications.settings.slack_webhook_url",label:"Slack Webhook URL",description:"Webhook URL for Slack notifications",page:"/notifications",tab:"settings",fieldName:"notifications.slack_webhook_url",keywords:["slack","webhook","notification","credential"]},{id:"notifications.settings.rate_limit_rpm",label:"Rate Limit (RPM)",description:"Max notifications per minute",page:"/notifications",tab:"settings",fieldName:"notifications.rate_limit_rpm",keywords:["rate","limit","rpm","notification","throttle"]},{id:"notifications.settings.notify_events",label:"Event Filter",description:"Per-event notification filter (choose which events are delivered)",page:"/notifications",tab:"settings",fieldName:"notifications.notify_events",keywords:["filter","event","category","notification","subscribe"]},{id:"notifications.settings.telegram_dedicated_bot_token",label:"Bot Token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)",page:"/notifications",tab:"settings",fieldName:"telegram.bot_token",keywords:["telegram","bot","token","credential"]},{id:"security.autostop.enabled",label:"Enabled",description:"Enable or disable AutoStop protection rules",page:"/security",tab:"autostop",fieldName:"autostop.enabled",keywords:["autostop","protection","enable","toggle","security"]},{id:"security.autostop.consecutive_failures_threshold",label:"Consecutive Failures Threshold",description:"Suspend wallet after this many consecutive failed transactions",page:"/security",tab:"autostop",fieldName:"autostop.consecutive_failures_threshold",keywords:["autostop","failure","threshold","suspend","security"]},{id:"security.autostop.unusual_activity_threshold",label:"Unusual Activity Threshold",description:"Max transactions within window before triggering unusual activity alert",page:"/security",tab:"autostop",fieldName:"autostop.unusual_activity_threshold",keywords:["autostop","unusual","activity","threshold","security"]},{id:"security.autostop.unusual_activity_window_sec",label:"Unusual Activity Window (seconds)",description:"Time window for unusual activity detection",page:"/security",tab:"autostop",fieldName:"autostop.unusual_activity_window_sec",keywords:["autostop","unusual","activity","window","time","security"]},{id:"security.autostop.idle_timeout_sec",label:"Idle Timeout (seconds)",description:"Revoke sessions with no activity for this duration",page:"/security",tab:"autostop",fieldName:"autostop.idle_timeout_sec",keywords:["autostop","idle","timeout","session","revoke","security"]},{id:"security.autostop.idle_check_interval_sec",label:"Idle Check Interval (seconds)",description:"How often to check for idle sessions",page:"/security",tab:"autostop",fieldName:"autostop.idle_check_interval_sec",keywords:["autostop","idle","check","interval","security"]},{id:"system..currency",label:"Display Currency",description:"Currency for USD amount conversion in dashboard and notifications",page:"/system",tab:"",fieldName:"display.currency",keywords:["currency","display","usd","conversion","fiat"]},{id:"system..rate_limit_global_ip_rpm",label:"Global IP Rate Limit (RPM)",description:"Maximum API requests per minute from a single IP address",page:"/system",tab:"",fieldName:"security.rate_limit_global_ip_rpm",keywords:["rate","limit","rpm","ip","global","throttle"]},{id:"system..log_level",label:"Log Level",description:"Daemon logging verbosity level",page:"/system",tab:"",fieldName:"daemon.log_level",keywords:["log","level","debug","info","warn","error","daemon"]},{id:"transactions.monitor.enabled",label:"Monitoring Enabled",description:"Enable or disable incoming transaction monitoring",page:"/transactions",tab:"monitor",fieldName:"incoming.enabled",keywords:["incoming","monitoring","enable","toggle"]},{id:"transactions.monitor.poll_interval",label:"Poll Interval (seconds)",description:"How often to poll for incoming transactions",page:"/transactions",tab:"monitor",fieldName:"incoming.poll_interval",keywords:["incoming","poll","interval","frequency"]},{id:"transactions.monitor.retention_days",label:"Retention Days",description:"How many days to retain incoming transaction records",page:"/transactions",tab:"monitor",fieldName:"incoming.retention_days",keywords:["incoming","retention","days","cleanup"]},{id:"transactions.monitor.suspicious_dust_usd",label:"Suspicious Dust USD Threshold",description:"USD threshold below which transactions are flagged as dust",page:"/transactions",tab:"monitor",fieldName:"incoming.suspicious_dust_usd",keywords:["incoming","suspicious","dust","threshold","usd"]},{id:"transactions.monitor.suspicious_amount_multiplier",label:"Suspicious Amount Multiplier",description:"Multiplier for detecting unusually large incoming amounts",page:"/transactions",tab:"monitor",fieldName:"incoming.suspicious_amount_multiplier",keywords:["incoming","suspicious","amount","multiplier","large"]},{id:"transactions.monitor.cooldown_minutes",label:"Notification Cooldown (minutes)",description:"Cooldown period between duplicate incoming TX notifications",page:"/transactions",tab:"monitor",fieldName:"incoming.cooldown_minutes",keywords:["incoming","cooldown","notification","minutes"]},{id:"transactions.monitor.wss_url",label:"WebSocket URL",description:"Custom WebSocket RPC URL for real-time incoming TX detection",page:"/transactions",tab:"monitor",fieldName:"incoming.wss_url",keywords:["incoming","websocket","wss","rpc","url"]},{id:"system..cross_validation_threshold",label:"Cross Validation Threshold (%)",description:"Maximum allowed deviation between price oracle sources",page:"/system",tab:"",fieldName:"oracle.cross_validation_threshold",keywords:["oracle","price","validation","threshold","deviation"]},{id:"system..signing_sdk_enabled",label:"SDK Enabled",description:"Enable Signing SDK for wallet app approval",page:"/system",tab:"",fieldName:"signing_sdk.enabled",keywords:["signing","sdk","wallet","app","enable"]},{id:"system..signing_sdk_request_expiry",label:"Request Expiry (min)",description:"Minutes before a sign request expires",page:"/system",tab:"",fieldName:"signing_sdk.request_expiry_min",keywords:["signing","sdk","expiry","timeout","request"]},{id:"system..signing_sdk_preferred_channel",label:"Preferred Channel",description:"Preferred signing channel for SDK requests",page:"/system",tab:"",fieldName:"signing_sdk.preferred_channel",keywords:["signing","sdk","channel","ntfy","telegram"]},{id:"wallet-apps..signing_sdk_notifications",label:"Notifications Enabled",description:"Push event notifications to wallet apps",page:"/wallet-apps",tab:"",fieldName:"signing_sdk.notifications_enabled",keywords:["signing","sdk","notification","wallet","push"]},{id:"system..erc8128_enabled",label:"ERC-8128 Enabled",description:"Enable ERC-8128 HTTP message signing",page:"/system",tab:"",fieldName:"erc8128.enabled",keywords:["erc8128","signing","http","rfc9421","enable"]},{id:"system..erc8128_default_preset",label:"Default Preset",description:"Default covered components preset for ERC-8128",page:"/system",tab:"",fieldName:"erc8128.default_preset",keywords:["erc8128","preset","minimal","standard","strict"]},{id:"system..erc8128_default_ttl_sec",label:"Default TTL",description:"Default signature TTL in seconds",page:"/system",tab:"",fieldName:"erc8128.default_ttl_sec",keywords:["erc8128","ttl","expiry","timeout"]},{id:"system..erc8128_default_nonce",label:"Include Nonce",description:"Include nonce in ERC-8128 signatures by default",page:"/system",tab:"",fieldName:"erc8128.default_nonce",keywords:["erc8128","nonce","replay"]},{id:"system..erc8128_default_algorithm",label:"Algorithm",description:"ERC-8128 signing algorithm",page:"/system",tab:"",fieldName:"erc8128.default_algorithm",keywords:["erc8128","algorithm","eip191"]},{id:"system..erc8128_default_rate_limit_rpm",label:"Rate Limit",description:"ERC-8128 rate limit per domain per minute",page:"/system",tab:"",fieldName:"erc8128.default_rate_limit_rpm",keywords:["erc8128","rate","limit","throttle"]}],xe=Ne(""),me=Ne(null),ki={"/wallets":"Wallets","/sessions":"Sessions","/transactions":"Transactions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"};function Ni(t){if(!t.trim())return[];const a=t.toLowerCase();return Ti.filter(n=>[n.label,n.description,n.keywords.join(" ")].join(" ").toLowerCase().includes(a)).slice(0,10)}function Ai(t){const a=ki[t.page]??t.page;return t.tab?`${a} > ${t.tab}`:a}function Ei({open:t}){const a=c(""),n=c(0),l=Fe(null),i=t.value?Ni(a.value):[];if(X(()=>{t.value&&(a.value="",n.value=0,requestAnimationFrame(()=>{l.current?.focus()}))},[t.value]),!t.value)return null;const r=()=>{t.value=!1,a.value="",n.value=0},s=d=>{d.target.classList.contains("search-overlay")&&r()},o=d=>{window.location.hash="#"+d.page,d.tab?me.value={tab:d.tab,fieldName:d.fieldName}:setTimeout(()=>{xe.value=d.fieldName},100),r()};return e("div",{class:"search-overlay",onClick:s,children:e("div",{class:"search-popover",onKeyDown:d=>{if(d.key==="Escape"){r();return}if(d.key==="ArrowDown"){d.preventDefault(),n.value=Math.min(n.value+1,i.length-1);return}if(d.key==="ArrowUp"){d.preventDefault(),n.value=Math.max(n.value-1,0);return}if(d.key==="Enter"&&i.length>0){d.preventDefault(),o(i[n.value]);return}},children:[e("div",{class:"search-input-wrapper",children:e("input",{ref:l,class:"search-input",type:"text",placeholder:"Search settings...",value:a.value,onInput:d=>{a.value=d.target.value,n.value=0}})}),e("div",{class:"search-results",children:[a.value.trim()&&i.length===0&&e("div",{class:"search-empty",children:"No settings found"}),i.map((d,v)=>e("button",{class:`search-result-item${v===n.value?" selected":""}`,onClick:()=>o(d),onMouseEnter:()=>{n.value=v},children:[e("div",{class:"search-result-label",children:d.label}),e("div",{class:"search-result-desc",children:d.description}),e("div",{class:"search-result-path",children:Ai(d)})]},d.id))]}),e("div",{class:"search-hint",children:[e("span",{children:[e("kbd",{children:"Esc"})," close"]}),e("span",{children:[e("kbd",{children:"↑"}),e("kbd",{children:"↓"})," navigate"]}),e("span",{children:[e("kbd",{children:"Enter"})," select"]})]})]})})}const dt=Ne([]),ml=Wt(()=>dt.value.some(t=>typeof t.isDirty=="function"&&t.isDirty()));function Be(t){dt.value=[...dt.value.filter(a=>a.id!==t.id),t]}function Re(t){dt.value=dt.value.filter(a=>a.id!==t)}async function Ci(){const t=dt.value.filter(a=>typeof a.isDirty=="function"&&a.isDirty());try{for(const a of t)await a.save();return!0}catch{return!1}}function Ii(){const t=dt.value.filter(a=>typeof a.isDirty=="function"&&a.isDirty());for(const a of t)a.discard()}function k({label:t,name:a,type:n="text",value:l,onChange:i,options:r,error:s,required:o,disabled:u,placeholder:d,min:v,max:h,description:_}){const A=xe.value===a;if(X(()=>{if(A){const W=document.querySelector(`[name="${a}"]`);W&&W.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const f=setTimeout(()=>{xe.value=""},2500);return()=>clearTimeout(f)}},[A,a]),n==="checkbox")return e("div",{class:`form-field${A?" form-field--highlight":""}`,children:[e("label",{children:[e("input",{type:"checkbox",name:a,checked:!!l,onChange:W=>i(W.target.checked),disabled:u}),t,o&&e("span",{children:" *"})]}),_&&e("span",{class:"form-description",children:_}),s&&e("span",{class:"form-error",children:s})]});const $=`field-${a}`;return e("div",{class:`form-field${A?" form-field--highlight":""}`,children:[e("label",{for:$,children:[t,o&&e("span",{children:" *"})]}),n==="select"?e("select",{id:$,name:a,value:l,onChange:W=>i(W.target.value),disabled:u,children:r?.map(W=>e("option",{value:W.value,children:W.label},W.value))}):n==="textarea"?e("textarea",{id:$,name:a,value:l,onInput:W=>i(W.target.value),disabled:u,placeholder:d}):e("input",{id:$,type:n,name:a,value:l,onInput:W=>{const f=W.target;i(n==="number"?Number(f.value):f.value)},disabled:u,placeholder:d,min:v,max:h,required:o}),_&&e("span",{class:"form-description",children:_}),s&&e("span",{class:"form-error",children:s})]})}function P({variant:t="primary",size:a="md",loading:n=!1,disabled:l=!1,onClick:i,children:r,type:s="button"}){const o=["btn",`btn-${t}`,a==="sm"?"btn-sm":""].filter(Boolean).join(" ");return e("button",{type:s,class:o,disabled:l||n,onClick:i,children:n?"...":r})}function j({variant:t,children:a}){return e("span",{class:`badge badge-${t}`,children:a})}const Ct=Ne(null),St=Ne(!1);function fl(t){Ct.value=t}function xi(){const t=Ct.value;if(!t)return null;const a=async()=>{St.value=!0;const i=await Ci();St.value=!1,i&&(Ct.value=null,t.execute())},n=()=>{Ii(),Ct.value=null,t.execute()},l=()=>{Ct.value=null};return e("div",{class:"modal-overlay",onClick:l,children:e("div",{class:"modal-card",onClick:i=>i.stopPropagation(),children:[e("div",{class:"modal-header",children:"Unsaved Changes"}),e("div",{class:"modal-body",children:e("p",{children:"You have unsaved changes. What would you like to do?"})}),e("div",{class:"modal-footer unsaved-dialog-footer",children:[e(P,{variant:"secondary",onClick:l,disabled:St.value,children:"Cancel"}),e(P,{variant:"ghost",onClick:n,disabled:St.value,children:"Discard & Navigate"}),e(P,{variant:"primary",onClick:a,loading:St.value,children:"Save & Navigate"})]})]})})}class b extends Error{constructor(a,n,l){super(`[${a}] ${n}: ${l}`),this.status=a,this.code=n,this.serverMessage=l,this.name="ApiError"}}async function Ft(t,a){const n={"Content-Type":"application/json",...a?.headers};Ut.value!==null&&(n["X-Master-Password"]=Ut.value);let l;try{l=await fetch(t,{...a,headers:n,signal:AbortSignal.timeout(1e4)})}catch(i){const r=i;throw r.name==="AbortError"||r.name==="TimeoutError"?new b(0,"TIMEOUT","Request timed out"):new b(0,"NETWORK_ERROR","Cannot connect to daemon")}if(l.status===401)throw t.startsWith("/v1/admin/")&&fa(),new b(401,"UNAUTHORIZED","Authentication failed");if(!l.ok){let i={};try{i=await l.json()}catch{}throw new b(l.status,i.code??"UNKNOWN",i.message??"Unknown error")}return Ka(),await l.json()}const q=t=>Ft(t,{method:"GET"}),he=(t,a)=>Ft(t,{method:"POST",body:a?JSON.stringify(a):void 0}),oe=(t,a)=>Ft(t,{method:"PUT",body:a?JSON.stringify(a):void 0}),Le=(t,a)=>Ft(t,{method:"DELETE",body:a?JSON.stringify(a):void 0}),Di=(t,a)=>Ft(t,{method:"PATCH",body:a?JSON.stringify(a):void 0});function Li(t){const a=Math.floor(t/86400),n=Math.floor(t%86400/3600),l=Math.floor(t%3600/60);return a>0?`${a}d ${n}h ${l}m`:n>0?`${n}h ${l}m`:`${l}m`}function _e(t){const a=new Date(t*1e3),n=l=>l.toString().padStart(2,"0");return`${a.getFullYear()}-${n(a.getMonth()+1)}-${n(a.getDate())} ${n(a.getHours())}:${n(a.getMinutes())}`}function Pt(t){return t?t.length<=10?t:`${t.slice(0,4)}..${t.slice(-4)}`:""}const Ri=new Set(["KRW","JPY","VND","CLP","HUF","PKR"]),Oi=new Set(["KWD","BHD"]);function Pi(t){return Ri.has(t)?0:Oi.has(t)?3:2}function Mi(t,a,n){const l=t*n,i=Pi(a),r=new Intl.NumberFormat("en-US",{style:"currency",currency:a,minimumFractionDigits:i,maximumFractionDigits:i}).format(l);return a==="USD"?r:`≈${r}`}let vt=null;const Wi=300*1e3;async function Va(){if(vt&&Date.now()-vt.fetchedAt<Wi)return{currency:vt.currency,rate:vt.rate};try{const a=(await q(D.ADMIN_SETTINGS)).display?.["display.currency"]??"USD";if(a==="USD")return vt={currency:"USD",rate:1,fetchedAt:Date.now()},{currency:"USD",rate:1};const i=(await q(`${D.ADMIN_FOREX_RATES}?currencies=${a}`)).rates[a]?.rate??null;return vt={currency:a,rate:i,fetchedAt:Date.now()},{currency:a,rate:i}}catch{return{currency:"USD",rate:1}}}function yt(t,a,n){return t==null?"":n==null?`$${t.toFixed(2)}`:Mi(t,a,n)}function De({columns:t,data:a,onRowClick:n,emptyMessage:l="No data",loading:i=!1}){return e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:t.map(r=>e("th",{style:r.width?{width:r.width}:void 0,children:r.header},r.key))})}),e("tbody",{children:i?e("tr",{children:e("td",{colSpan:t.length,class:"table-loading",children:"Loading..."})}):!a||a.length===0?e("tr",{children:e("td",{colSpan:t.length,class:"table-empty",children:l})}):a.map((r,s)=>e("tr",{class:n?"clickable":"",onClick:n?()=>n(r):void 0,children:t.map(o=>e("td",{children:o.render?o.render(r):r[o.key]},o.key))},s))})]})})}const Ui={INVALID_TOKEN:"Your authentication token is invalid. Please log in again.",TOKEN_EXPIRED:"Your session token has expired. Please log in again.",SESSION_REVOKED:"Your session has been revoked by an administrator.",INVALID_SIGNATURE:"The cryptographic signature is invalid.",INVALID_NONCE:"The authentication nonce is invalid or has expired.",INVALID_MASTER_PASSWORD:"Invalid master password. Please try again.",MASTER_PASSWORD_LOCKED:"Master password is locked due to too many failed attempts. Please wait.",SYSTEM_LOCKED:"The system is currently locked.",SESSION_NOT_FOUND:"Session not found.",SESSION_EXPIRED:"The session has expired.",SESSION_LIMIT_EXCEEDED:"Maximum number of sessions reached.",CONSTRAINT_VIOLATED:"A session constraint was violated.",RENEWAL_LIMIT_REACHED:"Session renewal limit has been reached. Create a new session.",SESSION_ABSOLUTE_LIFETIME_EXCEEDED:"Session has exceeded its maximum lifetime.",RENEWAL_TOO_EARLY:"Session renewal attempted too early. Please wait.",SESSION_RENEWAL_MISMATCH:"Session renewal count mismatch. The session may have been renewed elsewhere.",PIPELINE_HALTED:"Transaction is queued for delay or approval.",INSUFFICIENT_BALANCE:"Insufficient balance for this transaction.",INVALID_ADDRESS:"The blockchain address is invalid.",TX_NOT_FOUND:"Transaction not found.",TX_EXPIRED:"The transaction has expired.",TX_ALREADY_PROCESSED:"This transaction has already been processed.",CHAIN_ERROR:"A blockchain network error occurred. Please try again.",SIMULATION_FAILED:"Transaction simulation failed. The transaction may revert.",TOKEN_NOT_FOUND:"Token not found.",TOKEN_NOT_ALLOWED:"This token is not in the allowed list.",INSUFFICIENT_TOKEN_BALANCE:"Insufficient token balance.",CONTRACT_CALL_DISABLED:"Contract calls are disabled. Configure a CONTRACT_WHITELIST policy first.",CONTRACT_NOT_WHITELISTED:"This contract address is not whitelisted.",METHOD_NOT_WHITELISTED:"This contract method is not whitelisted.",APPROVE_DISABLED:"Token approvals are disabled. Configure an APPROVED_SPENDERS policy first.",SPENDER_NOT_APPROVED:"This spender address is not in the approved list.",APPROVE_AMOUNT_EXCEEDED:"The approve amount exceeds the configured limit.",UNLIMITED_APPROVE_BLOCKED:"Unlimited token approvals are blocked by policy.",BATCH_NOT_SUPPORTED:"Batch transactions are not supported on this chain.",BATCH_SIZE_EXCEEDED:"Batch contains too many instructions (maximum 20).",BATCH_POLICY_VIOLATION:"A policy violation occurred in the batch transaction.",POLICY_NOT_FOUND:"Policy not found.",POLICY_DENIED:"Transaction denied by policy.",SPENDING_LIMIT_EXCEEDED:"Spending limit has been exceeded.",RATE_LIMIT_EXCEEDED:"Rate limit exceeded. Please wait before retrying.",WHITELIST_DENIED:"The destination address is not in the whitelist.",OWNER_ALREADY_CONNECTED:"An owner wallet is already connected to this wallet.",OWNER_NOT_CONNECTED:"No owner wallet is connected to this wallet.",OWNER_NOT_FOUND:"Owner not found.",APPROVAL_TIMEOUT:"The approval request has timed out.",APPROVAL_NOT_FOUND:"Approval request not found.",OWNER_NOT_SET:"Owner address must be set before connecting WalletConnect.",OWNER_ADDRESS_MISMATCH:"Connected wallet address does not match registered owner.",KILL_SWITCH_ACTIVE:"Kill switch is active. All operations are suspended.",KILL_SWITCH_NOT_ACTIVE:"Kill switch is not currently active.",KEYSTORE_LOCKED:"The keystore is locked. Please try again.",CHAIN_NOT_SUPPORTED:"This blockchain is not supported.",SHUTTING_DOWN:"The daemon is shutting down.",ADAPTER_NOT_AVAILABLE:"Chain adapter is not available. Please try again.",WALLET_NOT_FOUND:"Wallet not found.",WALLET_SUSPENDED:"This wallet is currently suspended.",WALLET_TERMINATED:"This wallet has been terminated.",WALLET_NOT_TERMINATED:"Wallet must be terminated before purging.",WC_NOT_CONFIGURED:"WalletConnect is not configured. Set the Project ID in Settings first.",WC_SESSION_NOT_FOUND:"No active WalletConnect session.",WC_SESSION_EXISTS:"A WalletConnect session already exists. Disconnect first.",WC_SIGNING_FAILED:"WalletConnect signing request failed.",NO_OWNER:"No owner connected. Withdrawal requires an owner wallet.",WITHDRAW_LOCKED_ONLY:"Withdrawal is only available when the owner state is LOCKED.",SWEEP_TOTAL_FAILURE:"All sweep operations failed. Please try again.",INSUFFICIENT_FOR_FEE:"Insufficient balance to cover transaction fees.",ACTION_NOT_FOUND:"Action not found.",ACTION_VALIDATION_FAILED:"Action input validation failed.",ACTION_RESOLVE_FAILED:"Action failed due to an external API error. Please try again.",ACTION_RETURN_INVALID:"Action returned an invalid result.",ACTION_PLUGIN_LOAD_FAILED:"Failed to load the action plugin.",ACTION_NAME_CONFLICT:"An action with this name already exists.",ACTION_CHAIN_MISMATCH:"The request chain does not match the action provider.",ROTATION_TOO_RECENT:"Key rotation was attempted too recently. Please wait.",NETWORK_ERROR:"Cannot connect to the daemon. Check if it is running.",TIMEOUT:"Request timed out. The daemon may be busy."},$i=new Set(["ACTION_VALIDATION_FAILED","CONSTRAINT_VIOLATED","INVALID_ADDRESS","INVALID_SIGNATURE"]);function z(t,a){return a&&$i.has(t)?a:Ui[t]??`An error occurred (${t}).`}const Ze=Ne([]);let Fi=0;function m(t,a){const n=Fi++;Ze.value=[...Ze.value,{id:n,type:t,message:a}],setTimeout(()=>{Ze.value=Ze.value.filter(l=>l.id!==n)},5e3)}function Bi(t){Ze.value=Ze.value.filter(a=>a.id!==t)}function zi(){return Ze.value.length===0?null:e("div",{class:"toast-container",children:Ze.value.map(t=>e("div",{class:`toast toast-${t.type}`,onClick:()=>Bi(t.id),children:t.message},t.id))})}const Hi={"solana-mainnet":"https://solscan.io/tx/{txHash}","solana-devnet":"https://solscan.io/tx/{txHash}?cluster=devnet","solana-testnet":"https://solscan.io/tx/{txHash}?cluster=testnet","ethereum-mainnet":"https://etherscan.io/tx/{txHash}","ethereum-sepolia":"https://sepolia.etherscan.io/tx/{txHash}","polygon-mainnet":"https://polygonscan.com/tx/{txHash}","polygon-amoy":"https://amoy.polygonscan.com/tx/{txHash}","arbitrum-mainnet":"https://arbiscan.io/tx/{txHash}","arbitrum-sepolia":"https://sepolia.arbiscan.io/tx/{txHash}","optimism-mainnet":"https://optimistic.etherscan.io/tx/{txHash}","optimism-sepolia":"https://sepolia-optimism.etherscan.io/tx/{txHash}","base-mainnet":"https://basescan.org/tx/{txHash}","base-sepolia":"https://sepolia.basescan.org/tx/{txHash}"};function Ki(t,a){const n=Hi[t];return n?n.replace("{txHash}",a):null}function Vi(t){return t.length<=16?t:t.slice(0,8)+"..."+t.slice(-6)}function qa({network:t,txHash:a,label:n}){if(!a)return null;const l=Ki(t,a),i=n??Vi(a);return l?e("a",{href:l,target:"_blank",rel:"noopener noreferrer",class:"explorer-link",children:i}):e("span",{class:"explorer-link-text",children:i})}function qi(t){if(t===0)return"0 B";const a=["B","KB","MB","GB"],n=1024,l=Math.min(Math.floor(Math.log(t)/Math.log(n)),a.length-1);return`${(t/Math.pow(n,l)).toFixed(l===0?0:1)} ${a[l]}`}function we({label:t,value:a,loading:n,badge:l,href:i}){const r=e(te,{children:[e("div",{class:"stat-label",children:[t,i&&e("span",{class:"stat-link-arrow",children:" →"})]}),n?e("div",{class:"stat-skeleton"}):l?e(j,{variant:l,children:a}):e("div",{class:"stat-value",children:a})]});return i?e("a",{href:i,class:"stat-card stat-card-link",style:{textDecoration:"none",color:"inherit",cursor:"pointer"},children:r}):e("div",{class:"stat-card",children:r})}function Gi(t,a){return[{key:"createdAt",header:"Time",render:n=>n.createdAt?_e(n.createdAt):"—"},{key:"walletName",header:"Wallet",render:n=>n.walletName??n.walletId.slice(0,8)},{key:"type",header:"Type"},{key:"amount",header:"Amount",render:n=>{if(!n.amount)return"—";const l=n.formattedAmount??n.amount,i=yt(n.amountUsd,t,a);return i?`${l} (${i})`:l}},{key:"network",header:"Network",render:n=>n.network??"—"},{key:"status",header:"Status",render:n=>{const l=n.status==="CONFIRMED"?"success":n.status==="FAILED"?"danger":"warning";return e(j,{variant:l,children:n.status})}},{key:"txHash",header:"Tx Hash",render:n=>e(qa,{network:n.network??"",txHash:n.txHash})}]}function ji(t,a){return[{key:"provider",header:"Provider"},{key:"category",header:"Category",render:n=>e(j,{variant:"info",children:n.category})},{key:"chain",header:"Chain",render:n=>e(j,{variant:"info",children:n.chain})},{key:"amount",header:"Amount"},{key:"amountUsd",header:"USD Value",render:n=>n.amountUsd===null?"—":yt(n.amountUsd,t,a)??`$${n.amountUsd.toFixed(2)}`}]}async function Yi(t){try{await navigator.clipboard.writeText(t)}catch{const a=document.createElement("textarea");a.value=t,a.style.position="fixed",a.style.left="-9999px",document.body.appendChild(a),a.select(),document.execCommand("copy"),document.body.removeChild(a)}}function pn(){const t=c(null),a=c(!0),n=c(null),l=c("USD"),i=c(1),r=c(!1),s=c(null),o=c(null),u=c(null),d=c(!0),v=c(null),h=c(!0),_=async()=>{try{const E=await q(D.ADMIN_STATS);v.value=E}catch{}finally{h.value=!1}},A=async()=>{d.value=!0;try{const E=await q(D.ADMIN_DEFI_POSITIONS);u.value=E}catch{}finally{d.value=!1}},$=async()=>{a.value=!0,n.value=null;try{const E=await q(D.ADMIN_STATUS);t.value=E}catch(E){E instanceof b?n.value=z(E.code):n.value="An unexpected error occurred."}finally{a.value=!1}},W=async()=>{r.value=!0;try{const E=await he(D.ADMIN_AGENT_PROMPT,{});if(E.walletCount===0){m("warning","No active wallets found");return}s.value=E.prompt,m("success",`Prompt generated for ${E.walletCount} wallet(s)`)}catch(E){E instanceof b?m("error",z(E.code)):m("error","Failed to generate agent prompt")}finally{r.value=!1}},f=async()=>{s.value&&(await Yi(s.value),m("success","Copied to clipboard!"))};X(()=>{$(),A(),_(),Va().then(({currency:G,rate:I})=>{l.value=G,i.value=I}).catch(()=>{}),q(D.ADMIN_TRANSACTIONS+"?status=APPROVED&limit=1").then(G=>{o.value=G.total}).catch(()=>{});const E=setInterval(()=>{$(),A(),_()},3e4);return()=>clearInterval(E)},[]);const N=a.value&&!t.value;return e("div",{class:"page",children:[n.value&&e("div",{class:"dashboard-error",children:[e("span",{children:n.value}),e(P,{variant:"secondary",size:"sm",onClick:$,children:"Retry"})]}),t.value?.updateAvailable&&e("div",{class:"update-banner",role:"status",children:[e("span",{class:"update-banner-icon",children:"⬆"}),e("span",{children:[e("strong",{children:"Update available:"})," ",t.value.version," ","→"," ",t.value.latestVersion," — ","Run ",e("code",{children:"waiaas update"})," to update."]})]}),t.value?.autoProvisioned&&e("div",{class:"auto-provision-banner",role:"alert",children:[e("span",{class:"auto-provision-banner-icon",children:"⚠"}),e("span",{children:[e("strong",{children:"Auto-provision mode active."})," ","Change the master password for security."," ",e("a",{href:"#/security?tab=password",class:"auto-provision-link",children:"Go to Security"})]})]}),e("div",{class:"stat-grid",children:[e(we,{label:"Version",value:t.value?.version??"—",loading:N,badge:t.value&&t.value.updateAvailable?"warning":void 0}),e(we,{label:"Uptime",value:t.value?Li(t.value.uptime):"—",loading:N}),e(we,{label:"Wallets",value:t.value?.walletCount?.toString()??"—",loading:N,href:"#/wallets"}),e(we,{label:"Active Sessions",value:t.value?.activeSessionCount?.toString()??"—",loading:N,href:"#/sessions"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(we,{label:"Kill Switch",value:t.value?.killSwitchState==="ACTIVATED"?"ACTIVATED":"NORMAL",loading:N,badge:t.value?t.value.killSwitchState==="ACTIVATED"?"danger":"success":void 0}),e(we,{label:"Status",value:t.value?.status??"—",loading:N})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(we,{label:"Policies",value:t.value?.policyCount?.toString()??"—",loading:N,href:"#/policies"}),e(we,{label:"Recent Txns (24h)",value:t.value?.recentTxCount?.toString()??"—",loading:N,href:"#/transactions"}),e(we,{label:"Failed Txns (24h)",value:t.value?.failedTxCount?.toString()??"—",loading:N,badge:t.value?t.value.failedTxCount===0?"success":"danger":void 0,href:"#/transactions?status=FAILED"}),e(we,{label:"Approval Pending",value:o.value?.toString()??"—",loading:N,badge:o.value!=null&&o.value>0?"warning":void 0,href:"#/transactions?status=APPROVED"})]}),e("div",{class:"prompt-card",style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-2)"},children:"Agent Connection Prompt"}),e("p",{class:"prompt-card-desc",children:"Generate a connection prompt for AI agents. Creates sessions for all active wallets."}),s.value?e(te,{children:[e("pre",{class:"prompt-preview",children:s.value}),e("div",{style:{display:"flex",gap:"var(--space-2)",marginTop:"var(--space-3)"},children:[e(P,{variant:"primary",size:"sm",onClick:f,children:"Copy to Clipboard"}),e(P,{variant:"secondary",size:"sm",onClick:W,loading:r.value,children:"Regenerate"})]})]}):e(P,{variant:"primary",size:"sm",onClick:W,loading:r.value,style:{marginTop:"var(--space-2)"},children:"Generate"})]}),u.value&&u.value.activeCount>0&&e("div",{style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"DeFi Positions"}),e("div",{class:"stat-grid",children:[e(we,{label:"Total DeFi Value",value:u.value.totalValueUsd!==null?yt(u.value.totalValueUsd,l.value,i.value)??`$${u.value.totalValueUsd.toFixed(2)}`:"—",loading:d.value}),e(we,{label:"Health Factor",value:u.value.worstHealthFactor!==null?u.value.worstHealthFactor.toFixed(2):"N/A",loading:d.value,badge:u.value.worstHealthFactor!==null?u.value.worstHealthFactor<1.2?"danger":u.value.worstHealthFactor<1.5?"warning":"success":void 0}),e(we,{label:"Active Positions",value:u.value.activeCount.toString(),loading:d.value})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(De,{columns:ji(l.value,i.value),data:u.value.positions,loading:d.value,emptyMessage:"No active DeFi positions"})})]}),e("div",{style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Recent Activity"}),e(De,{columns:Gi(l.value,i.value),data:t.value?.recentTransactions??[],loading:N,emptyMessage:"No recent transactions"})]}),v.value&&e(te,{children:[v.value.rpc.byNetwork.length>0&&e("div",{style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"RPC Network Status"}),e(De,{columns:[{key:"network",header:"Network"},{key:"calls",header:"Total Calls"},{key:"errors",header:"Errors"},{key:"avgLatencyMs",header:"Avg Latency (ms)",render:E=>E.avgLatencyMs.toFixed(1)}],data:v.value.rpc.byNetwork,emptyMessage:"No RPC data available"})]}),e("div",{style:{marginTop:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"AutoStop Rules"}),e(De,{columns:[{key:"id",header:"Rule"},{key:"displayName",header:"Name"},{key:"enabled",header:"Status",render:E=>e(j,{variant:E.enabled?"success":"danger",children:E.enabled?"Enabled":"Disabled"})},{key:"trackedCount",header:"Tracked"}],data:v.value.autostop.rules,emptyMessage:"No rules configured"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(we,{label:"Notifications Sent (24h)",value:String(v.value.notifications.sentLast24h)}),e(we,{label:"Failed Notifications (24h)",value:String(v.value.notifications.failedLast24h),badge:v.value.notifications.failedLast24h>0?"danger":void 0})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(we,{label:"DB Size",value:qi(v.value.system.dbSizeBytes)}),e(we,{label:"Schema Version",value:`v${v.value.system.schemaVersion}`}),e(we,{label:"Node.js",value:v.value.system.nodeVersion}),e(we,{label:"Platform",value:v.value.system.platform})]})]})]})}function Se({open:t,title:a,children:n,onConfirm:l,onCancel:i,confirmText:r="Confirm",cancelText:s="Cancel",confirmVariant:o="primary",confirmDisabled:u=!1,loading:d=!1}){return X(()=>{if(!t)return;const v=h=>{h.key==="Escape"&&i()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[t,i]),t?e("div",{class:"modal-overlay",onClick:i,children:e("div",{class:"modal-card",onClick:v=>v.stopPropagation(),children:[e("div",{class:"modal-header",children:a}),e("div",{class:"modal-body",children:n}),e("div",{class:"modal-footer",children:[e(P,{variant:"secondary",onClick:i,disabled:d,children:s}),l&&e(P,{variant:o,onClick:l,loading:d,disabled:u,children:r})]})]})}):null}function tt({value:t,label:a}){const n=c(!1);return e("button",{class:"btn btn-ghost btn-sm",onClick:async()=>{try{await navigator.clipboard.writeText(t)}catch{const i=document.createElement("textarea");i.value=t,i.style.position="fixed",i.style.left="-9999px",document.body.appendChild(i),i.select(),document.execCommand("copy"),document.body.removeChild(i)}n.value=!0,setTimeout(()=>{n.value=!1},2e3)},children:n.value?"Copied!":a??"Copy"})}function ot({title:t,description:a,actionLabel:n,onAction:l}){return e("div",{class:"empty-state",children:[e("h3",{children:t}),a&&e("p",{children:a}),n&&l&&e("button",{class:"btn btn-primary",onClick:l,children:n})]})}function at({tabs:t,activeTab:a,onTabChange:n}){return e("div",{class:"tab-nav",children:t.map(l=>e("button",{class:`tab-btn ${a===l.key?"active":""}`,onClick:()=>{l.key!==a&&(ml.value?fl({type:"tab",execute:()=>n(l.key)}):n(l.key))},children:l.label},l.key))})}function wt({pageName:t,tabName:a,onPageClick:n}){return a?e("nav",{class:"breadcrumb","aria-label":"Breadcrumb",children:[e("button",{class:"breadcrumb-page",onClick:n,type:"button",children:t}),e("span",{class:"breadcrumb-separator","aria-hidden":"true",children:">"}),e("span",{class:"breadcrumb-current","aria-current":"page",children:a})]}):null}function gl({value:t,onSearch:a,placeholder:n="Search...",debounceMs:l=300}){const i=Fe(null);function r(o){const u=o.target.value;i.current!==null&&clearTimeout(i.current),i.current=setTimeout(()=>{a(u),i.current=null},l)}function s(){i.current!==null&&(clearTimeout(i.current),i.current=null),a("")}return e("div",{class:"search-input",children:[e("input",{type:"text",value:t,placeholder:n,onInput:r}),t&&e("button",{class:"search-clear",type:"button",onClick:s,children:"x"})]})}function Xi(){const t=window.location.hash,a=t.indexOf("?");if(a===-1)return{};const n=new URLSearchParams(t.slice(a+1)),l={};return n.forEach((i,r)=>{l[r]=i}),l}function mn(t){const a=window.location.hash,n=a.indexOf("?"),l=n===-1?a:a.slice(0,n),i=new URLSearchParams;for(const[o,u]of Object.entries(t))u&&i.set(o,u);const r=i.toString(),s=r?`${l}?${r}`:l;window.history.replaceState(null,"",s)}function Bt({fields:t,values:a,onChange:n,syncUrl:l=!0}){X(()=>{if(!l)return;const s=Xi(),o={...a};let u=!1;for(const d of t){const v=s[d.key];v!==void 0&&v!==o[d.key]&&(o[d.key]=v,u=!0)}u&&n(o)},[]);function i(s,o){const u={...a,[s]:o};n(u),l&&mn(u)}function r(){const s={};for(const o of t)s[o.key]="";n(s),l&&mn(s)}return e("div",{class:"filter-bar",children:[t.map(s=>e("div",{class:"filter-field",children:[e("label",{children:s.label}),s.type==="select"?e("select",{value:a[s.key]??"",onChange:o=>i(s.key,o.target.value),children:[e("option",{value:"",children:"All"}),s.options?.map(o=>e("option",{value:o.value,children:o.label},o.value))]}):e("input",{type:"date",value:a[s.key]??"",placeholder:s.placeholder,onChange:o=>i(s.key,o.target.value)})]},s.key)),e("button",{class:"btn btn-secondary filter-clear",type:"button",onClick:r,children:"Clear"})]})}const Ga=["solana-mainnet","solana-devnet","solana-testnet"],zt=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia","hyperevm-mainnet","hyperevm-testnet"],sa={"solana-mainnet":"Solana Mainnet","solana-devnet":"Solana Devnet","solana-testnet":"Solana Testnet","ethereum-mainnet":"Ethereum Mainnet","ethereum-sepolia":"Ethereum Sepolia","polygon-mainnet":"Polygon Mainnet","polygon-amoy":"Polygon Amoy","arbitrum-mainnet":"Arbitrum Mainnet","arbitrum-sepolia":"Arbitrum Sepolia","optimism-mainnet":"Optimism Mainnet","optimism-sepolia":"Optimism Sepolia","base-mainnet":"Base Mainnet","base-sepolia":"Base Sepolia","hyperevm-mainnet":"HyperEVM Mainnet","hyperevm-testnet":"HyperEVM Testnet"},Ji={"solana-mainnet":"SOL","solana-devnet":"SOL","solana-testnet":"SOL","ethereum-mainnet":"ETH","ethereum-sepolia":"ETH","polygon-mainnet":"POL","polygon-amoy":"POL","arbitrum-mainnet":"ETH","arbitrum-sepolia":"ETH","optimism-mainnet":"ETH","optimism-sepolia":"ETH","base-mainnet":"ETH","base-sepolia":"ETH","hyperevm-mainnet":"HYPE","hyperevm-testnet":"HYPE"};zt.map(t=>`evm_${t.replace(/-/g,"_")}`);Ga.map(t=>t.replace(/-/g,"_"));const Zi=Object.fromEntries([...Ga.map(t=>[t.replace(/-/g,"_"),sa[t]]),...zt.map(t=>[`evm_${t.replace(/-/g,"_")}`,sa[t]])]),Qi=new Set(["notifications.telegram_bot_token","notifications.discord_webhook_url","notifications.slack_webhook_url","telegram.bot_token"]);function er(t){return Qi.has(t)}function ie(t){return{enabled:"Enabled",telegram_bot_token:"Telegram Bot Token",telegram_chat_id:"Telegram Chat ID",discord_webhook_url:"Discord Webhook URL",ntfy_server:"Ntfy Server",ntfy_topic:"Ntfy Topic",locale:"Locale",rate_limit_rpm:"Rate Limit (RPM)",...Zi,max_sessions_per_wallet:"Max Sessions per Wallet",max_pending_tx:"Max Pending Transactions",rate_limit_global_ip_rpm:"Global IP Rate Limit (RPM)",rate_limit_session_rpm:"Session Rate Limit (RPM)",rate_limit_tx_rpm:"Transaction Rate Limit (RPM)",policy_defaults_delay_seconds:"Policy Delay (seconds)",policy_defaults_approval_timeout:"Approval Timeout (seconds)",default_deny_tokens:"Default Deny: Token Transfers",default_deny_contracts:"Default Deny: Contract Calls",default_deny_spenders:"Default Deny: Token Approvals",default_deny_x402_domains:"Default Deny: x402 Domains",default_deny_erc8128_domains:"Default Deny: ERC-8128 Domains",default_preset:"Default Preset",default_ttl:"Default TTL (seconds)",include_nonce:"Include Nonce",algorithm:"Algorithm",rate_limit_per_minute:"Rate Limit (per minute)",project_id:"Project ID",log_level:"Log Level",currency:"Display Currency",consecutive_failures_threshold:"Consecutive Failures Threshold",unusual_activity_threshold:"Unusual Activity Threshold",unusual_activity_window_sec:"Unusual Activity Window (seconds)",idle_timeout_sec:"Idle Timeout (seconds)",idle_check_interval_sec:"Idle Check Interval (seconds)",check_interval_sec:"Check Interval (seconds)",low_balance_threshold_sol:"Low Balance Threshold (SOL)",low_balance_threshold_eth:"Low Balance Threshold (ETH)",cooldown_hours:"Alert Cooldown (hours)",relay_url:"Relay URL",bot_token:"Bot Token",request_expiry_min:"Request Expiry (minutes)",preferred_channel:"Preferred Channel",preferred_wallet:"Preferred Wallet",ntfy_request_topic_prefix:"Ntfy Request Topic Prefix",ntfy_response_topic_prefix:"Ntfy Response Topic Prefix",wallets:"Registered Wallets (JSON)",aave_v3_enabled:"Aave V3 Enabled",aave_v3_health_factor_warning_threshold:"HF Warning Threshold",aave_v3_position_sync_interval_sec:"Position Sync Interval (seconds)",aave_v3_max_ltv_pct:"Max LTV Percentage",kamino_enabled:"Kamino Enabled",kamino_market:"Market",kamino_hf_threshold:"HF Warning Threshold",drift_enabled:"Drift Perp Enabled",drift_max_leverage:"Max Leverage",drift_max_position_usd:"Max Position Size (USD)",drift_margin_warning_threshold_pct:"Margin Warning Threshold (%)",drift_position_sync_interval_sec:"Position Sync Interval (seconds)",poll_interval_sec:"Poll Interval (seconds)",default_timeout_sec:"Default Timeout (seconds)",max_timeout_sec:"Max Timeout (seconds)",max_pending_count:"Max Pending Count",jupiter_swap_default_slippage_bps:"Default Slippage (%)",jupiter_swap_max_slippage_bps:"Max Slippage (%)",zerox_swap_default_slippage_bps:"Default Slippage (%)",zerox_swap_max_slippage_bps:"Max Slippage (%)",pendle_yield_default_slippage_bps:"Default Slippage (%)",pendle_yield_max_slippage_bps:"Max Slippage (%)",dcent_swap_default_slippage_bps:"Default Slippage (%)",dcent_swap_max_slippage_bps:"Max Slippage (%)",across_bridge_enabled:"Across Bridge Enabled",across_bridge_api_base_url:"API Base URL",across_bridge_integrator_id:"Integrator ID",across_bridge_fill_deadline_buffer_sec:"Fill Deadline Buffer (seconds)",across_bridge_default_slippage_pct:"Default Slippage (%)",across_bridge_max_slippage_pct:"Max Slippage (%)",across_bridge_request_timeout_ms:"Request Timeout (ms)"}[t]??t.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function pe(t,a,n,l){const i=`${n}.${l}`;if(a[i]!==void 0)return a[i];const r=t[n];if(!r)return"";const s=r[l];return typeof s=="boolean"?er(i)?"":String(s):s??""}function We(t,a,n,l){const i=`${n}.${l}`;if(a[i]!==void 0)return a[i]==="true";const r=t[n];if(!r)return!1;const s=r[l];return typeof s=="boolean"?s:s==="true"}const tr=new Set(["jupiter_swap_default_slippage_bps","jupiter_swap_max_slippage_bps","zerox_swap_default_slippage_bps","zerox_swap_max_slippage_bps","pendle_yield_default_slippage_bps","pendle_yield_max_slippage_bps","dcent_swap_default_slippage_bps","dcent_swap_max_slippage_bps"]);function fn(t){return tr.has(t)}function ar(t){const a=Number(t);return isNaN(a)||t===""?t:String(a/100)}function nr(t){const a=Number(t);return isNaN(a)||t===""?t:String(Math.round(a*100))}function It(t,a,n,l){const i=`${n}.${l}`;if(a[i]!==void 0)return!1;const r=t[n];return r?r[l]===!0:!1}const yl="0x5d82735936c6Cd5DE57cC3c1A799f6B2E6F933Df",Oe=[{value:"dcent",label:"D'CENT Wallet",description:"D'CENT hardware wallet with push notification signing"}],jt={dcent:"Wallet App (ntfy)"},lr={dcent:"sdk_ntfy"},oa=[{value:"none",label:"None (Lite mode)"},{value:"pimlico",label:"Pimlico"},{value:"alchemy",label:"Alchemy"},{value:"custom",label:"Custom"}],ca={pimlico:"https://dashboard.pimlico.io",alchemy:"https://dashboard.alchemy.com"};function _l(t){switch(t){case"NONE":return"neutral";case"GRACE":return"warning";case"LOCKED":return"success";default:return"neutral"}}function re({label:t,value:a,copy:n,children:l}){return e("div",{class:"detail-row",children:[e("div",{class:"detail-row-label",children:t}),e("div",{class:"detail-row-value",children:[l??a??"—",n&&a&&e(tt,{value:a})]})]})}const gn=[{value:null,label:"Auto (Global Fallback)",description:"System decides based on configured channels: Wallet App (ntfy) > Wallet App (Telegram) > WalletConnect > Telegram Bot > REST"},{value:"sdk_ntfy",label:"Wallet App (ntfy)",description:"Push sign request to wallet app via ntfy server",warning:"Signing SDK is not enabled. Go to Wallets > Human Wallet Apps settings.",warningCondition:t=>!t?.signingEnabled},{value:"sdk_telegram",label:"Wallet App (Telegram)",description:"Push sign request to wallet app via Telegram with universal link",warning:"Signing SDK or Telegram bot is not configured. Check Wallets > Human Wallet Apps and Notifications > Settings > Telegram.",warningCondition:t=>!t?.signingEnabled||!t?.telegramBotConfigured},{value:"walletconnect",label:"WalletConnect",description:"Approve via connected WalletConnect wallet (D'CENT, MetaMask, etc.)",warning:"WalletConnect project ID is not configured. Go to Wallets > WalletConnect tab.",warningCondition:t=>!t?.wcConfigured},{value:"telegram_bot",label:"Telegram Bot",description:"Approve/reject via Telegram bot /approve and /reject commands",warning:"Telegram bot token is not configured. Go to Notifications > Settings > Telegram.",warningCondition:t=>!t?.telegramBotConfigured},{value:"rest",label:"REST API",description:"Manual approval via REST API endpoints (POST /approve, /reject)"}],ir=[{key:"overview",label:"Overview"},{key:"transactions",label:"Transactions"},{key:"owner",label:"Owner"},{key:"staking",label:"Staking"},{key:"nfts",label:"NFTs"},{key:"mcp",label:"MCP"}],Tt=20,rr=[{value:"PENDING",label:"PENDING"},{value:"APPROVED",label:"APPROVED"},{value:"SUBMITTED",label:"SUBMITTED"},{value:"CONFIRMED",label:"CONFIRMED"},{value:"FAILED",label:"FAILED"}],sr=[{value:"TRANSFER",label:"TRANSFER"},{value:"TOKEN_TRANSFER",label:"TOKEN_TRANSFER"},{value:"CONTRACT_CALL",label:"CONTRACT_CALL"},{value:"APPROVE",label:"APPROVE"},{value:"BATCH",label:"BATCH"},{value:"NFT_TRANSFER",label:"NFT_TRANSFER"}],or=[{key:"status",label:"Status",type:"select",options:rr},{key:"type",label:"Type",type:"select",options:sr}],ba=["Time","Type","To","Amount","Network","Status","Tx Hash"];function cr(t){return t==="CONFIRMED"?"success":t==="FAILED"?"danger":"warning"}function dr({id:t}){const a=c(null),n=c(!0),l=c(!1),i=c(""),r=c(!1),s=c(!1),o=c(!1),u=c(!1),d=c(!1),v=c(!1),h=c(null),_=c([]),A=c(!0),$=c(null),W=c(!0),f=c([]),N=c(!0),E=c(0),G=c(0),I=c({status:"",type:""}),V=c(!1),C=c(null),x=c(!1),w=c(null),R=c(!0),K=c(!1),y=c(null),p=c(!1),T=c(""),H=c(!1),Y=c(""),ae=c(!1),ce=c(null),F=c(!1),O=c(!1),Q=c(""),J=c(!1),be=c("overview"),Ae=c("USD"),L=c(1),le=c([]),M=c(!0),ee=c([]),ve=c(!1),Ce=c(null),ke=c("grid"),S=c(null),U=c(!1),se=c(""),ge=c(null),nt=c(!1),ze=c(!1),ne=c("pimlico"),He=c(""),lt=c(""),Ht=c(""),Kt=c(""),ga=c(!1),it=async()=>{try{const g=await q(D.WALLET(t));a.value=g}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{n.value=!1}},Sl=async()=>{r.value=!0;try{const g=await oe(D.WALLET(t),{name:i.value});a.value=g,l.value=!1,m("success","Wallet name updated")}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{r.value=!1}},Tl=async()=>{o.value=!0;try{await Le(D.WALLET(t)),m("success","Wallet terminated"),window.location.hash="#/wallets"}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{o.value=!1}},kl=async()=>{d.value=!0;try{await Le(D.WALLET_PURGE(t)),m("success","Wallet permanently deleted"),window.location.hash="#/wallets"}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{d.value=!1}},Nl=async()=>{O.value=!0;try{await he(D.WALLET_SUSPEND(t),{reason:Q.value.trim()||void 0}),m("success","Wallet suspended"),F.value=!1,Q.value="",await it()}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{O.value=!1}},Al=async()=>{J.value=!0;try{await he(D.WALLET_RESUME(t)),m("success","Wallet resumed"),await it()}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{J.value=!1}},El=async()=>{ga.value=!0;try{const g=ne.value==="custom"?{provider:"custom",bundlerUrl:lt.value,paymasterUrl:Ht.value||void 0}:{provider:ne.value,apiKey:He.value||void 0,policyId:Kt.value||void 0};await oe(D.WALLET_PROVIDER(t),g),m("success","Provider updated"),ze.value=!1,He.value="",lt.value="",Ht.value="",Kt.value="",await it()}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{ga.value=!1}},Cl=()=>{a.value?.provider&&(ne.value=a.value.provider.name),ze.value=!0},Il=()=>{i.value=a.value.name,l.value=!0},xl=()=>{l.value=!1},ja=async()=>{v.value=!0;try{const g=await he(D.MCP_TOKENS,{walletId:t});h.value=g,m("success","MCP token provisioned successfully")}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{v.value=!1}},Dl=async()=>{A.value=!0;try{const g=await q(D.WALLET_NETWORKS(t));_.value=g.availableNetworks??[]}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code)),_.value=[]}finally{A.value=!1}},Ya=async()=>{W.value=!0;try{$.value=await q(D.ADMIN_WALLET_BALANCE(t))}catch{$.value=null}finally{W.value=!1}},Xa=async g=>{N.value=!0;try{const Z=(g??G.value)*Tt,fe=await q(`${D.ADMIN_WALLET_TRANSACTIONS(t)}?offset=${Z}&limit=${Tt}`);f.value=fe.items,E.value=fe.total}catch{f.value=[],E.value=0}finally{N.value=!1}},ya=ma(()=>{let g=f.value;const B=I.value;return B.status&&(g=g.filter(Z=>Z.status===B.status)),B.type&&(g=g.filter(Z=>Z.type===B.type)),g}),Ja=async()=>{M.value=!0;try{const g=await q(D.ADMIN_WALLET_STAKING(t));le.value=g.positions??[]}catch{le.value=[]}finally{M.value=!1}},Vt=async(g,B)=>{const Z=g??se.value;if(Z){ve.value=!0,Ce.value=null;try{const fe=new URLSearchParams({network:Z});B&&fe.set("cursor",B),fe.set("limit","20");const Ke=await q(`${D.ADMIN_WALLET_NFTS(t)}?${fe.toString()}`);B?ee.value=[...ee.value,...Ke.nfts]:ee.value=Ke.nfts,ge.value=Ke.cursor??null,nt.value=Ke.hasMore}catch(fe){fe instanceof b&&fe.code==="INDEXER_NOT_CONFIGURED"?Ce.value="INDEXER_NOT_CONFIGURED":Ce.value="FETCH_ERROR",ee.value=[]}finally{ve.value=!1}}},Za=async g=>{if(se.value){U.value=!0;try{const B=new URLSearchParams({network:se.value}),Z=await q(`${D.ADMIN_WALLET_NFT_METADATA(t,encodeURIComponent(g))}?${B.toString()}`);S.value=Z}catch{}finally{U.value=!1}}},Ll=async()=>{R.value=!0;try{w.value=await q(D.WALLET_WC_SESSION(t))}catch{w.value=null}finally{R.value=!1}},Rl=()=>{y.value&&clearInterval(y.value),y.value=setInterval(async()=>{try{const g=await q(D.WALLET_WC_PAIR_STATUS(t));g.status==="connected"?(y.value&&clearInterval(y.value),y.value=null,V.value=!1,C.value=null,w.value=g.session??null,m("success","Wallet connected via WalletConnect")):(g.status==="expired"||g.status==="none")&&(y.value&&clearInterval(y.value),y.value=null,V.value=!1,C.value=null,m("error","Pairing expired. Try again."))}catch{}},3e3)},Ol=async()=>{x.value=!0;try{const g=await he(D.WALLET_WC_PAIR(t));C.value=g,V.value=!0,Rl()}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");B.code==="WC_NOT_CONFIGURED"?(m("error","WalletConnect is not configured. Redirecting to settings..."),me.value={tab:"walletconnect",fieldName:"walletconnect.project_id"},window.location.hash="#/wallets"):m("error",z(B.code))}finally{x.value=!1}},Pl=async()=>{K.value=!0;try{await Le(D.WALLET_WC_SESSION(t)),w.value=null,m("success","WalletConnect session disconnected")}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code))}finally{K.value=!1}},Qa=()=>{T.value=a.value?.ownerAddress??"",Y.value=a.value?.walletType??"",p.value=!0},Ml=()=>{p.value=!1},Wl=async()=>{if(!T.value.trim()){m("error","Owner address is required");return}H.value=!0;try{const g={owner_address:T.value.trim()};Y.value&&(g.wallet_type=Y.value),await oe(D.WALLET_OWNER(t),g),await it(),p.value=!1;const B=Oe.find(Z=>Z.value===Y.value);B?m("success",`Owner set with ${B.label} auto-setup`):m("success","Owner address updated")}catch(g){const B=g instanceof b?g:new b(0,"UNKNOWN","Unknown error");m("error",z(B.code,B.serverMessage))}finally{H.value=!1}},Ul=async g=>{if(a.value?.ownerAddress){H.value=!0;try{const B={owner_address:a.value.ownerAddress};g&&(B.wallet_type=g),await oe(D.WALLET_OWNER(t),B),await it(),ae.value=!1;const Z=Oe.find(fe=>fe.value===g);Z?m("success",`Wallet Type changed to ${Z.label}`):m("success","Wallet Type cleared")}catch(B){const Z=B instanceof b?B:new b(0,"UNKNOWN","Unknown error");m("error",z(Z.code,Z.serverMessage))}finally{H.value=!1}}},$l=async()=>{try{const g=await q(D.ADMIN_SETTINGS),B=g.signing_sdk?.enabled==="true",Z=g.telegram?.bot_token===!0||g.notifications?.telegram_bot_token===!0,fe=!!g.walletconnect?.project_id&&g.walletconnect.project_id!=="";ce.value={signingEnabled:B,telegramBotConfigured:Z,wcConfigured:fe}}catch{}},Fl=async g=>{const B=a.value?.walletType;if(B){const Z=Oe.find(Ke=>Ke.value===B),fe=Z?lr[B]:void 0;if(fe&&g!==fe){const Ke=Z.label,Jl=gn.find(Zl=>Zl.value===fe)?.label??fe;if(!confirm(`${Ke} preset default is "${Jl}". Changing the approval method may prevent sign requests from being delivered correctly.
|
|
2
|
+
|
|
3
|
+
Proceed with change?`))return}}try{await oe(D.WALLET_OWNER(t),{owner_address:a.value.ownerAddress,approval_method:g??null}),await it(),m("success","Approval method updated")}catch(Z){const fe=Z instanceof b?Z:new b(0,"UNKNOWN","Unknown error");m("error",z(fe.code,fe.serverMessage))}};X(()=>{it(),Dl(),Ya(),Xa(),Ll(),Ja(),$l(),Va().then(({currency:g,rate:B})=>{Ae.value=g,L.value=B}).catch(()=>{})},[t]),X(()=>()=>{y.value&&clearInterval(y.value)},[]),X(()=>{Xa()},[G.value]);const en=G.value*Tt,Bl=E.value>0?en+1:0,zl=Math.min(en+Tt,E.value),Hl=G.value>0,Kl=(G.value+1)*Tt<E.value;function Vl(){return a.value?e(te,{children:[e("div",{class:"detail-grid",children:[e(re,{label:"ID",value:a.value.id,copy:!0}),e(re,{label:"Public Key",value:a.value.publicKey,copy:!0}),e(re,{label:"Chain",value:a.value.chain}),e(re,{label:"Environment",children:e(j,{variant:a.value.environment==="mainnet"?"warning":"info",children:a.value.environment})}),e(re,{label:"Status",children:e(j,{variant:a.value.status==="ACTIVE"?"success":a.value.status==="SUSPENDED"?"warning":"danger",children:a.value.status})}),e(re,{label:"Account Type",children:e(j,{variant:a.value.accountType==="smart"?"info":"default",children:a.value.accountType==="smart"?"Smart Account":"EOA"})}),a.value.accountType==="smart"&&a.value.factoryAddress?.toLowerCase()===yl.toLowerCase()&&e("div",{style:{background:"var(--color-danger-bg, #fef2f2)",border:"1px solid var(--color-danger, #ef4444)",borderRadius:"var(--radius)",padding:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("strong",{style:{color:"var(--color-danger, #ef4444)"},children:"Deprecated Smart Account"}),e("p",{style:{margin:"0.25rem 0 0",fontSize:"var(--font-size-sm)",color:"var(--text-secondary)"},children:"This Smart Account uses a deprecated factory (Solady). Transactions and UserOp operations will be rejected. Please create a new Smart Account wallet to continue."})]}),a.value.accountType==="smart"&&e(te,{children:[a.value.factoryAddress&&e(re,{label:"Factory Address",value:a.value.factoryAddress,copy:!0}),a.value.factorySupportedNetworks&&a.value.factorySupportedNetworks.length>0&&e(re,{label:"Factory Networks",children:e("div",{style:{display:"flex",flexWrap:"wrap",gap:"0.25rem"},children:a.value.factorySupportedNetworks.map(g=>e(j,{variant:"default",children:g},g))})}),a.value.factoryVerifiedOnNetwork!==null&&a.value.factoryVerifiedOnNetwork!==void 0&&e(re,{label:"Verified on Network",children:[e(j,{variant:a.value.factoryVerifiedOnNetwork?"success":"danger",children:a.value.factoryVerifiedOnNetwork?"Verified":"Not Verified"}),!a.value.factoryVerifiedOnNetwork&&e("span",{style:{marginLeft:"0.5rem",fontSize:"0.85rem",color:"var(--color-danger, #ef4444)"},children:"Factory may not be deployed on this network"})]}),e(re,{label:"Signer Key",value:a.value.signerKey??"--",copy:!0}),e(re,{label:"Deployed",children:e(j,{variant:a.value.deployed?"success":"warning",children:a.value.deployed?"Yes":"Not yet"})}),e(re,{label:"Mode",children:[e(j,{variant:a.value.provider?"success":"warning",children:a.value.provider?"Full":"Lite"}),!a.value.provider&&e("span",{style:{marginLeft:"0.5rem",fontSize:"0.85rem",color:"var(--color-text-secondary)"},children:"Use UserOp API for gas-sponsored transactions"})]}),a.value.provider?e(te,{children:[e(re,{label:"Provider",children:e(j,{variant:"info",children:a.value.provider.name})}),e(re,{label:"Supported Chains",value:a.value.provider.supportedChains.join(", ")||"--"}),e(re,{label:"Paymaster",children:e(j,{variant:a.value.provider.paymasterEnabled?"success":"neutral",children:a.value.provider.paymasterEnabled?"Enabled":"Disabled"})})]}):e(re,{label:"Provider",value:"Not configured"}),ze.value?e("div",{class:"inline-form",style:{marginTop:"var(--space-3)",padding:"var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)"},children:[e(k,{label:"Provider",name:"editProvider",type:"select",value:ne.value,onChange:g=>{ne.value=g},options:oa.map(g=>({label:g.label,value:g.value}))}),ne.value!=="custom"&&ne.value!=="none"?e(te,{children:[e(k,{label:"API Key",name:"editApiKey",value:He.value,onChange:g=>{He.value=g},placeholder:"Leave empty to use global default"}),e(k,{label:"Paymaster Policy ID",name:"editPolicyId",value:Kt.value,onChange:g=>{Kt.value=g},placeholder:"Leave empty to use global default"}),e("p",{style:{fontSize:"0.85rem",color:"var(--color-text-secondary)",margin:"0 0 0.5rem 0"},children:["Global defaults can be configured in"," ",e("a",{href:"/settings",style:{color:"var(--color-primary)"},children:"Settings > Smart Account"}),".",ca[ne.value]&&e(te,{children:[" ","Get API key at"," ",e("a",{href:ca[ne.value],target:"_blank",rel:"noopener noreferrer",children:[oa.find(g=>g.value===ne.value)?.label," Dashboard"]}),"."]})]})]}):ne.value==="custom"?e(te,{children:[e(k,{label:"Bundler URL",name:"editBundlerUrl",value:lt.value,onChange:g=>{lt.value=g},placeholder:"https://..."}),e(k,{label:"Paymaster URL (optional)",name:"editPaymasterUrl",value:Ht.value,onChange:g=>{Ht.value=g},placeholder:"https://..."})]}):null,e("div",{style:{display:"flex",gap:"var(--space-2)",marginTop:"var(--space-2)"},children:[e(P,{onClick:El,loading:ga.value,children:"Save"}),e(P,{variant:"secondary",onClick:()=>{ze.value=!1},children:"Cancel"})]})]}):e("div",{style:{marginTop:"var(--space-2)"},children:e(P,{variant:"secondary",size:"sm",onClick:Cl,children:"Change Provider"})})]}),a.value.status==="SUSPENDED"&&e(te,{children:[e(re,{label:"Suspended At",value:a.value.suspendedAt?_e(a.value.suspendedAt):"--"}),e(re,{label:"Suspension Reason",value:a.value.suspensionReason??"--"})]}),e(re,{label:"Created",value:_e(a.value.createdAt)}),e(re,{label:"Updated",value:a.value.updatedAt?_e(a.value.updatedAt):"Never"})]}),e("div",{class:"balance-section",style:{marginTop:"var(--space-6)"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("h3",{style:{margin:0},children:"Balances"}),e(P,{variant:"secondary",size:"sm",onClick:Ya,loading:W.value,children:"Refresh"})]}),W.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):$.value?.balances?.length?e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)"},children:$.value.balances.map(g=>e("div",{style:{padding:"var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"transparent"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:"var(--space-2)"},children:e("strong",{children:g.network})}),g.error?e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:g.error}):g.native?e("div",{children:[e(re,{label:"Native",children:e("span",{children:[g.native.balance," ",g.native.symbol,g.native.usd!=null&&e("span",{style:{color:"var(--color-text-secondary)",marginLeft:"var(--space-2)",fontSize:"0.85rem"},children:["(",yt(g.native.usd,Ae.value,L.value),")"]})]})}),g.tokens.length>0?g.tokens.map(B=>e(re,{label:B.symbol,value:B.balance},B.address)):null]}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Balance unavailable"})]},g.network))}):e("p",{style:{color:"var(--color-text-secondary)"},children:"No balance data available"})]}),e("div",{class:"networks-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Available Networks"}),A.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:(_.value??[]).map(g=>e("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"var(--space-2) var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)"},children:e("span",{children:g.name??g.network})},g.network))})]})]}):null}function ql(){return e(te,{children:[e(Bt,{fields:or,values:I.value,onChange:g=>{I.value=g},syncUrl:!1}),e("div",{class:"table-container",style:{marginTop:"var(--space-3)"},children:e("table",{children:[e("thead",{children:e("tr",{children:ba.map(g=>e("th",{children:g},g))})}),e("tbody",{children:N.value&&ya.value.length===0?e("tr",{children:e("td",{colSpan:ba.length,class:"table-loading",children:"Loading..."})}):ya.value.length===0?e("tr",{children:e("td",{colSpan:ba.length,class:"table-empty",children:"No transactions yet"})}):ya.value.map(g=>e("tr",{children:[e("td",{children:g.createdAt?_e(g.createdAt):"—"}),e("td",{children:e(j,{variant:"info",children:g.type})}),e("td",{children:g.toAddress?Pt(g.toAddress):"—"}),e("td",{children:g.amount?g.formattedAmount??g.amount:"—"}),e("td",{children:g.network??"—"}),e("td",{children:e(j,{variant:cr(g.status),children:g.status})}),e("td",{children:e(qa,{network:g.network??"",txHash:g.txHash})})]},g.id))})]})}),e("div",{class:"pagination",style:{marginTop:"var(--space-3)"},children:[e("span",{class:"pagination-info",children:["Showing ",Bl,"-",zl," of ",E.value]}),e("div",{class:"pagination-buttons",children:[e(P,{variant:"secondary",size:"sm",disabled:!Hl,onClick:()=>{G.value=G.value-1},children:"Previous"}),e(P,{variant:"secondary",size:"sm",disabled:!Kl,onClick:()=>{G.value=G.value+1},children:"Next"})]})]})]})}function Gl(){return a.value?e("div",{class:"owner-section",children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Owner Wallet"}),a.value.ownerState==="NONE"&&a.value.status!=="TERMINATED"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginBottom:"var(--space-4)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500},children:"What is an Owner Wallet?"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem",marginBottom:"var(--space-3)"},children:"Register an Owner wallet to enable transaction approval (APPROVAL policy) for high-value transfers. Connect D'CENT, MetaMask, or other WalletConnect-compatible wallets to approve transactions directly."}),e(P,{size:"sm",onClick:Qa,children:"Set Owner Address"})]}),p.value&&a.value.ownerState==="NONE"&&e("div",{style:{marginBottom:"var(--space-3)"},children:[e("label",{style:{display:"block",marginBottom:"var(--space-1)",fontSize:"0.85rem",fontWeight:500},children:"Wallet Type"}),e("select",{value:Y.value,onChange:g=>{Y.value=g.target.value},style:{width:"100%",padding:"var(--space-2) var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"var(--color-bg)",color:"var(--color-text)",fontSize:"0.9rem"},children:[e("option",{value:"",children:"Custom (manual setup)"}),Oe.map(g=>e("option",{value:g.value,children:g.label},g.value))]}),Y.value&&e("p",{style:{marginTop:"var(--space-1)",fontSize:"0.8rem",color:"var(--color-text-secondary)"},children:Oe.find(g=>g.value===Y.value)?.description}),Y.value&&jt[Y.value]&&e("p",{style:{marginTop:"var(--space-1)",fontSize:"0.8rem",color:"var(--color-primary)"},children:["Approval: ",jt[Y.value]]})]}),e(re,{label:"Address",children:p.value?e("div",{class:"inline-edit",children:[e("input",{value:T.value,onInput:g=>{T.value=g.target.value},class:"inline-edit-input",placeholder:"Enter owner wallet address"}),e(P,{size:"sm",onClick:Wl,loading:H.value,children:"Save"}),e(P,{size:"sm",variant:"secondary",onClick:Ml,children:"Cancel"})]}):e("span",{children:[a.value.ownerAddress?e(te,{children:[Pt(a.value.ownerAddress),e(tt,{value:a.value.ownerAddress})]}):"Not set",a.value.ownerState!=="LOCKED"&&a.value.status==="ACTIVE"&&e("button",{class:"btn btn-ghost btn-sm",onClick:Qa,title:"Set owner address",children:"✎"})]})}),e(re,{label:"State",children:[e(j,{variant:_l(a.value.ownerState),children:a.value.ownerState}),a.value.walletType&&e(j,{variant:"info",style:{marginLeft:"var(--space-2)"},children:Oe.find(g=>g.value===a.value.walletType)?.label??a.value.walletType})]}),a.value.ownerState==="GRACE"&&e("div",{style:{marginTop:"var(--space-3)"},children:[e(re,{label:"Wallet Type",children:ae.value?e("div",{class:"inline-edit",children:[e("select",{value:Y.value,onChange:g=>{Y.value=g.target.value},style:{padding:"var(--space-1) var(--space-2)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:"var(--color-bg)",color:"var(--color-text)",fontSize:"0.85rem"},children:[e("option",{value:"",children:"Custom (manual setup)"}),Oe.map(g=>e("option",{value:g.value,children:g.label},g.value))]}),e(P,{size:"sm",onClick:()=>Ul(Y.value),loading:H.value,children:"Save"}),e(P,{size:"sm",variant:"secondary",onClick:()=>{ae.value=!1},children:"Cancel"})]}):e("span",{children:[Oe.find(g=>g.value===a.value.walletType)?.label??a.value.walletType??"Custom",e("button",{class:"btn btn-ghost btn-sm",onClick:()=>{Y.value=a.value?.walletType??"",ae.value=!0},title:"Change wallet type",children:"✎"})]})}),ae.value&&Y.value&&jt[Y.value]&&e("p",{style:{fontSize:"0.8rem",color:"var(--color-primary)",marginTop:"var(--space-1)"},children:["Approval: ",jt[Y.value]]})]}),a.value.ownerState==="LOCKED"&&a.value.walletType&&e(re,{label:"Wallet Type",children:e("span",{children:Oe.find(g=>g.value===a.value.walletType)?.label??a.value.walletType})}),a.value.ownerState==="GRACE"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginTop:"var(--space-3)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500,fontSize:"0.85rem"},children:"Verify Owner"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Sign a verification message with the Owner wallet to transition from GRACE to LOCKED. Connect via WalletConnect first, then trigger an APPROVAL-tier transaction or use the CLI/SDK to call the verify endpoint."})]}),a.value.ownerState!=="NONE"&&e("div",{style:{marginTop:"var(--space-4)",paddingTop:"var(--space-3)",borderTop:"1px solid var(--color-border)"},children:[e("h4",{style:{marginBottom:"var(--space-2)",fontSize:"0.9rem"},children:"Approval Method"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem",marginBottom:"var(--space-3)"},children:'Choose how transaction approvals are delivered to the owner. Leave as "Auto (Global Fallback)" to use the system-wide priority.'}),e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:gn.map(g=>e("label",{style:{display:"flex",alignItems:"flex-start",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",background:a.value?.approvalMethod===g.value?"var(--color-bg-secondary)":"transparent",borderRadius:"var(--radius-md)",cursor:"pointer"},children:[e("input",{type:"radio",name:"approval_method",value:g.value??"",checked:a.value?.approvalMethod===g.value,onChange:()=>Fl(g.value),style:{marginTop:"2px"},disabled:a.value?.ownerState==="LOCKED"}),e("div",{children:[e("div",{style:{fontWeight:500,fontSize:"0.9rem"},children:g.label}),e("div",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:g.description}),g.warning&&g.warningCondition?.(ce.value)&&e("div",{style:{marginTop:"var(--space-1)",padding:"var(--space-1) var(--space-2)",background:"var(--color-warning-bg, #fff3cd)",border:"1px solid var(--color-warning-border, #ffc107)",borderRadius:"var(--radius-sm)",fontSize:"0.75rem",color:"var(--color-warning-text, #856404)"},children:g.warning})]})]},g.value??"auto"))})]}),a.value?.approvalMethod==="walletconnect"&&e("div",{style:{marginTop:"var(--space-4)",paddingTop:"var(--space-3)",borderTop:"1px solid var(--color-border)"},children:[e("h4",{style:{marginBottom:"var(--space-2)",fontSize:"0.9rem"},children:"WalletConnect"}),R.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):w.value?e("div",{children:[e(re,{label:"Status",children:e(j,{variant:"success",children:"Connected"})}),e(re,{label:"Peer",value:w.value.peerName??"Unknown"}),e(re,{label:"Chain ID",value:w.value.chainId}),e(re,{label:"Expires",value:_e(w.value.expiry)}),e("div",{style:{marginTop:"var(--space-3)"},children:e(P,{variant:"danger",onClick:Pl,loading:K.value,children:"Disconnect"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Connect an external wallet (D'CENT, MetaMask, Phantom) via WalletConnect for transaction approval."}),a.value?.ownerAddress?e(P,{onClick:Ol,loading:x.value,children:"Connect Wallet"}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Set an Owner address first to enable WalletConnect."})]})]})]}):null}function jl(){function g(Z){return Z==="lido"?"info":"neutral"}function B(Z){return Z==="COMPLETED"?"success":Z==="TIMEOUT"?"danger":"warning"}return e("div",{children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("h3",{style:{margin:0},children:"Staking Positions"}),e(P,{variant:"secondary",size:"sm",onClick:Ja,loading:M.value,children:"Refresh"})]}),M.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):le.value.length===0?e(ot,{title:"No staking positions",description:"Stake ETH (Lido) or SOL (Jito) to see positions here."}):e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{children:"Protocol"}),e("th",{children:"Asset"}),e("th",{children:"Balance"}),e("th",{children:"Balance (USD)"}),e("th",{children:"APY"}),e("th",{children:"Pending Unstake"})]})}),e("tbody",{children:le.value.map(Z=>e("tr",{children:[e("td",{children:e(j,{variant:g(Z.protocol),children:Z.protocol==="lido"?"Lido":"Jito"})}),e("td",{children:Z.asset}),e("td",{children:Z.chain==="ethereum"?`${(Number(Z.balance)/1e18).toFixed(6)} stETH`:`${(Number(Z.balance)/1e9).toFixed(6)} JitoSOL`}),e("td",{children:Z.balanceUsd?yt(Number(Z.balanceUsd),Ae.value,L.value):"—"}),e("td",{children:Z.apy??"—"}),e("td",{children:Z.pendingUnstake?e("span",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e(j,{variant:B(Z.pendingUnstake.status),children:Z.pendingUnstake.status}),e("span",{style:{fontSize:"0.85em",color:"var(--color-text-secondary)"},children:Z.chain==="ethereum"?`${(Number(Z.pendingUnstake.amount)/1e18).toFixed(4)} stETH`:`${(Number(Z.pendingUnstake.amount)/1e9).toFixed(4)} JitoSOL`})]}):"—"})]},`${Z.protocol}-${Z.chain}`))})]})})]})}function Yl(){const g=_.value.map(B=>B.network);return e("div",{children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("h3",{style:{margin:0},children:"NFTs"}),e(k,{label:"",name:"nft-network",type:"select",value:se.value,onChange:B=>{se.value=String(B),ge.value=null,Vt(String(B))},options:[{value:"",label:"Select network..."},...g.map(B=>({value:B,label:B}))]}),e(P,{variant:"ghost",size:"sm",onClick:()=>{ke.value=ke.value==="grid"?"list":"grid"},title:ke.value==="grid"?"Switch to list view":"Switch to grid view",children:ke.value==="grid"?"☰":"▦"}),se.value&&e(P,{variant:"secondary",size:"sm",onClick:()=>Vt(),loading:ve.value,children:"Refresh"})]}),se.value?ve.value&&ee.value.length===0?e("div",{class:"stat-skeleton",style:{height:"120px"}}):Ce.value==="INDEXER_NOT_CONFIGURED"?e(ot,{title:"NFT indexer not configured",description:"Set up an Alchemy (EVM) or Helius (Solana) API key in Settings > API Keys to view NFTs."}):Ce.value?e(ot,{title:"Failed to load NFTs",description:"An error occurred while fetching NFTs."}):ee.value.length===0?e(ot,{title:"No NFTs found",description:"This wallet has no NFTs on the selected network."}):ke.value==="grid"?e("div",{children:[e("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(180px, 1fr))",gap:"var(--space-3)"},children:ee.value.map(B=>e("div",{class:"nft-card",style:{border:"1px solid var(--color-border)",borderRadius:"var(--radius-lg)",padding:"var(--space-2)",cursor:"pointer",textAlign:"center"},onClick:()=>{S.value=B;const Z=B.contractAddress.includes(":")?B.contractAddress:`${B.contractAddress}:${B.tokenId}`;Za(Z)},children:[B.image?e("img",{src:B.image,alt:B.name??"NFT",style:{width:"96px",height:"96px",objectFit:"cover",borderRadius:"var(--radius-md)",margin:"0 auto var(--space-2)",display:"block"}}):e("div",{style:{width:"96px",height:"96px",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)",margin:"0 auto var(--space-2)",display:"flex",alignItems:"center",justifyContent:"center",color:"var(--color-text-secondary)",fontSize:"0.8em"},children:"No image"}),e("div",{style:{fontSize:"0.85em",fontWeight:600,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:B.name??`#${B.tokenId}`}),e(j,{variant:"neutral",children:B.standard.toUpperCase()})]},`${B.contractAddress}-${B.tokenId}`))}),nt.value&&e("div",{style:{textAlign:"center",marginTop:"var(--space-3)"},children:e(P,{variant:"secondary",onClick:()=>Vt(void 0,ge.value??void 0),loading:ve.value,children:"Load more"})})]}):e("div",{children:[e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{children:"Image"}),e("th",{children:"Name"}),e("th",{children:"Token ID"}),e("th",{children:"Standard"}),e("th",{children:"Collection"})]})}),e("tbody",{children:ee.value.map(B=>e("tr",{style:{cursor:"pointer"},onClick:()=>{S.value=B;const Z=B.contractAddress.includes(":")?B.contractAddress:`${B.contractAddress}:${B.tokenId}`;Za(Z)},children:[e("td",{children:B.image?e("img",{src:B.image,alt:B.name??"NFT",style:{width:"48px",height:"48px",objectFit:"cover",borderRadius:"var(--radius-sm)"}}):e("div",{style:{width:"48px",height:"48px",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-sm)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"0.7em",color:"var(--color-text-secondary)"},children:"-"})}),e("td",{children:B.name??"-"}),e("td",{style:{fontFamily:"monospace",fontSize:"0.85em"},children:B.tokenId}),e("td",{children:e(j,{variant:"neutral",children:B.standard.toUpperCase()})}),e("td",{children:B.collection?.name??"-"})]},`${B.contractAddress}-${B.tokenId}`))})]})}),nt.value&&e("div",{style:{textAlign:"center",marginTop:"var(--space-3)"},children:e(P,{variant:"secondary",onClick:()=>Vt(void 0,ge.value??void 0),loading:ve.value,children:"Load more"})})]}):e(ot,{title:"Select a network",description:"Choose a network to view NFTs."}),e(Se,{open:!!S.value,title:S.value?.name??"NFT Details",onCancel:()=>{S.value=null},onConfirm:()=>{S.value=null},confirmText:"Close",children:S.value&&e("div",{children:[S.value.image&&e("div",{style:{textAlign:"center",marginBottom:"var(--space-3)"},children:e("img",{src:S.value.image,alt:S.value.name??"NFT",style:{maxWidth:"300px",maxHeight:"300px",borderRadius:"var(--radius-lg)"}})}),S.value.description&&e("p",{style:{color:"var(--color-text-secondary)",marginBottom:"var(--space-3)"},children:S.value.description}),e("div",{class:"detail-grid",style:{marginBottom:"var(--space-3)"},children:[e(re,{label:"Token ID",value:S.value.tokenId}),e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e(re,{label:"Contract",value:Pt(S.value.contractAddress??"")}),e(tt,{value:S.value.contractAddress??""})]}),e(re,{label:"Standard",value:(S.value.standard??"").toUpperCase()}),S.value.collection?.name&&e(re,{label:"Collection",value:S.value.collection.name}),S.value.assetId&&e(re,{label:"CAIP-19",value:S.value.assetId})]}),S.value.attributes&&S.value.attributes.length>0&&e("div",{style:{marginBottom:"var(--space-3)"},children:[e("strong",{children:"Attributes"}),e("div",{style:{display:"flex",flexWrap:"wrap",gap:"var(--space-2)",marginTop:"var(--space-2)"},children:S.value.attributes.map((B,Z)=>e(j,{variant:"info",children:[B.traitType,": ",B.value]},Z))})]}),S.value.metadata&&e("details",{style:{marginTop:"var(--space-2)"},children:[e("summary",{style:{cursor:"pointer",fontWeight:600},children:"Raw Metadata"}),e("pre",{style:{background:"var(--color-bg-secondary)",padding:"var(--space-2)",borderRadius:"var(--radius-md)",overflow:"auto",maxHeight:"200px",fontSize:"0.8em",marginTop:"var(--space-2)"},children:JSON.stringify(S.value.metadata,null,2)})]})]})})]})}function Xl(){return e("div",{class:"mcp-setup-section",children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"MCP Setup"}),h.value?e("div",{children:[e("div",{class:"detail-grid",style:{marginBottom:"var(--space-4)"},children:[e(re,{label:"Token Path",value:h.value.tokenPath}),e(re,{label:"Expires At",value:_e(h.value.expiresAt)})]}),e("div",{style:{marginBottom:"var(--space-2)"},children:e("strong",{children:"Claude Desktop Config"})}),e("div",{style:{position:"relative"},children:[e("pre",{children:e("code",{style:{display:"block",whiteSpace:"pre-wrap",wordBreak:"break-all",background:"var(--color-bg-secondary)",padding:"var(--space-3)",borderRadius:"var(--radius-md)",fontSize:"0.85rem",maxHeight:"300px",overflow:"auto"},children:JSON.stringify({mcpServers:h.value.claudeDesktopConfig},null,2)})}),e("div",{style:{marginTop:"var(--space-2)"},children:e(tt,{value:JSON.stringify({mcpServers:h.value.claudeDesktopConfig},null,2),label:"Copy Config"})})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(P,{variant:"secondary",onClick:ja,loading:v.value,children:"Re-provision"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)"},children:"Provision an MCP token for Claude Desktop integration."}),e(P,{onClick:ja,loading:v.value,children:"Setup MCP"})]})]})}return e("div",{class:"page",children:[e("a",{href:"#/wallets",class:"back-link",children:"← Back to Wallets"}),n.value?e("div",{class:"stat-skeleton",style:{height:"200px",marginTop:"var(--space-4)"}}):a.value?e("div",{class:"wallet-detail",children:[e("div",{class:"detail-header",children:[e("div",{class:"detail-name",children:l.value?e("div",{class:"inline-edit",children:[e("input",{value:i.value,onInput:g=>{i.value=g.target.value},class:"inline-edit-input"}),e(P,{size:"sm",onClick:Sl,loading:r.value,children:"Save"}),e(P,{size:"sm",variant:"secondary",onClick:xl,children:"Cancel"})]}):e("span",{children:[a.value.name,e("button",{class:"btn btn-ghost btn-sm",onClick:Il,title:"Edit name",children:"✎"})]})}),e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[a.value.status==="ACTIVE"&&e(P,{variant:"secondary",onClick:()=>{F.value=!0},children:"Suspend Wallet"}),a.value.status==="SUSPENDED"&&e(P,{variant:"primary",onClick:Al,loading:J.value,children:"Resume Wallet"}),a.value.status!=="TERMINATED"&&e(P,{variant:"danger",onClick:()=>{s.value=!0},children:"Terminate Wallet"}),a.value.status==="TERMINATED"&&e(P,{variant:"danger",onClick:()=>{u.value=!0},children:"Permanently Delete"})]})]}),e(at,{tabs:ir,activeTab:be.value,onTabChange:g=>{be.value=g}}),be.value==="overview"&&e(Vl,{}),be.value==="transactions"&&e(ql,{}),be.value==="owner"&&e(Gl,{}),be.value==="staking"&&e(jl,{}),be.value==="nfts"&&e(Yl,{}),be.value==="mcp"&&e(Xl,{}),e(Se,{open:s.value,title:"Terminate Wallet",onCancel:()=>{s.value=!1},onConfirm:Tl,confirmText:"Terminate",confirmVariant:"danger",loading:o.value,children:e("p",{children:["Are you sure you want to terminate wallet ",e("strong",{children:a.value.name}),"? This action cannot be undone."]})}),e(Se,{open:u.value,title:"Permanently Delete Wallet",onCancel:()=>{u.value=!1},onConfirm:kl,confirmText:"Delete Forever",confirmVariant:"danger",loading:d.value,children:e("p",{children:["Are you sure you want to ",e("strong",{children:"permanently delete"})," wallet"," ",e("strong",{children:a.value.name}),"? All associated data (transactions, sessions, policies, keys, audit logs) will be irreversibly removed. This cannot be undone."]})}),e(Se,{open:V.value,title:"Scan QR Code",onCancel:()=>{V.value=!1,y.value&&clearInterval(y.value),y.value=null},children:C.value&&e("div",{style:{textAlign:"center"},children:[e("img",{src:C.value.qrCode,alt:"WalletConnect QR Code",style:{width:"280px",height:"280px",margin:"0 auto"}}),e("p",{style:{marginTop:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Scan with D'CENT, MetaMask, Phantom, or any WalletConnect-compatible wallet"}),e("p",{style:{marginTop:"var(--space-2)",color:"var(--color-text-secondary)",fontSize:"0.75rem"},children:"Waiting for connection..."})]})}),e(Se,{open:F.value,title:"Suspend Wallet",onCancel:()=>{F.value=!1,Q.value=""},onConfirm:Nl,confirmText:"Suspend",confirmVariant:"danger",loading:O.value,children:[e("p",{style:{marginBottom:"var(--space-3)"},children:["Are you sure you want to suspend wallet ",e("strong",{children:a.value.name}),"? Suspended wallets cannot process transactions until resumed."]}),e(k,{label:"Reason (optional)",name:"suspend-reason",value:Q.value,onChange:g=>{Q.value=g},placeholder:"e.g. suspicious activity"})]})]}):e(ot,{title:"Wallet not found",description:"The wallet may have been deleted."})]})}const ht=Ga,kt=zt;function ur(t){if(t<=0)return"";const a=Math.ceil(t/1e3);if(a<60)return`${a}s`;const n=Math.floor(a/60),l=a%60;return l>0?`${n}m ${l}s`:`${n}m`}function vr(t){return ht.includes(t)?"solana":"evm"}function hr(){const t=c({}),a=c({}),n=c({}),l=c(!1),i=c(!0),r=c({}),s=c({}),o=c({}),u=c({}),d=c({}),v=c({}),h=(w,R)=>{const K={},y=[...ht,...kt];for(const p of y){const T=[],H=w.rpc_pool;if(H){const F=H[p];if(typeof F=="string"&&F!=="[]")try{const O=JSON.parse(F);Array.isArray(O)&&T.push(...O.filter(Q=>typeof Q=="string"&&Q.length>0))}catch{}}const Y=R[p]??[],ae=new Set(T),ce=[];for(const F of T)ce.push({url:F,isBuiltin:Y.includes(F),enabled:!0});for(const F of Y)ae.has(F)||ce.push({url:F,isBuiltin:!0,enabled:!0});K[p]=ce}return K},_=async()=>{try{try{const K=await q(D.ADMIN_RPC_STATUS);K.builtinUrls&&(u.value=K.builtinUrls),o.value=K.networks??{}}catch{}const w=await q(D.ADMIN_SETTINGS);t.value=w;const R=h(w,u.value);n.value=R,a.value=JSON.parse(JSON.stringify(R))}catch(w){const R=w instanceof b?w:new b(0,"UNKNOWN","Unknown error");m("error",z(R.code))}finally{i.value=!1}};X(()=>{_()},[]),X(()=>{const w=async()=>{try{const K=await q(D.ADMIN_RPC_STATUS);o.value=K.networks??{},K.builtinUrls&&(u.value=K.builtinUrls)}catch{}};w();const R=setInterval(w,15e3);return()=>clearInterval(R)},[]);const A=async(w,R)=>{const K=`${w}:${R}`;d.value={...d.value,[K]:!0};try{const y=await he(D.ADMIN_SETTINGS_TEST_RPC,{url:R,chain:vr(w)});v.value={...v.value,[K]:y}}catch{v.value={...v.value,[K]:{success:!1,latencyMs:0,error:"Request failed"}}}finally{d.value={...d.value,[K]:!1}}},$=()=>{for(const w of[...ht,...kt]){const R=n.value[w]??[],K=a.value[w]??[];if(R.length!==K.length)return!0;for(let y=0;y<R.length;y++)if(R[y].url!==K[y].url||R[y].enabled!==K[y].enabled)return!0}return!1},W=ma(()=>{let w=0;for(const R of[...ht,...kt]){const K=n.value[R]??[],y=a.value[R]??[];if(K.length!==y.length){w++;continue}for(let p=0;p<K.length;p++)if(K[p].url!==y[p].url||K[p].enabled!==y[p].enabled){w++;break}}return w}),f=async()=>{l.value=!0;try{const w=[];for(const y of[...ht,...kt]){const T=(a.value[y]??[]).filter(H=>!H.isBuiltin&&H.enabled).map(H=>H.url);w.push({key:`rpc_pool.${y}`,value:JSON.stringify(T)})}const R=await oe(D.ADMIN_SETTINGS,{settings:w});t.value=R.settings;const K=h(R.settings);n.value=K,a.value=JSON.parse(JSON.stringify(K)),m("success","RPC settings saved and applied")}catch(w){const R=w instanceof b?w:new b(0,"UNKNOWN","Unknown error");m("error",z(R.code))}finally{l.value=!1}},N=()=>{a.value=JSON.parse(JSON.stringify(n.value))};X(()=>(Be({id:"wallets-rpc",isDirty:$,save:f,discard:N}),()=>Re("wallets-rpc")),[]);const E=w=>{r.value={...r.value,[w]:!r.value[w]}},G=w=>{const R=(s.value[w]??"").trim();if(!R)return;if(!R.startsWith("https://")){m("warning","URL must start with https://");return}const K=a.value[w]??[];if(K.some(T=>T.url===R)){m("warning","URL already exists in this network");return}const y=[...K];y.findIndex(T=>T.isBuiltin&&!K.slice(0,K.indexOf(T)).some(H=>!H.isBuiltin));const p=y.reduce((T,H,Y)=>H.isBuiltin?T:Y+1,0);y.splice(p,0,{url:R,isBuiltin:!1,enabled:!0}),a.value={...a.value,[w]:y},s.value={...s.value,[w]:""}},I=(w,R)=>{const K=[...a.value[w]??[]];K[R]?.isBuiltin||(K.splice(R,1),a.value={...a.value,[w]:K})},V=(w,R,K)=>{const y=[...a.value[w]??[]],p=K==="up"?R-1:R+1;if(p<0||p>=y.length)return;const T=y[R],H=y[p];!T||!H||([y[R],y[p]]=[y[p],y[R]],a.value={...a.value,[w]:y})},C=(w,R)=>{const K=[...a.value[w]??[]],y=K[R];y?.isBuiltin&&(K[R]={...y,enabled:!y.enabled},a.value={...a.value,[w]:K})};function x({network:w}){const R=a.value[w]??[],K=r.value[w]??!1,y=R.filter(H=>H.enabled).length,p=o.value[w]??[],T=H=>p.find(Y=>Y.url===H);return e("details",{class:"rpc-pool-network",open:K,"data-testid":`rpc-network-${w}`,children:[e("summary",{class:"rpc-pool-network-header",onClick:H=>{H.preventDefault(),E(w)},children:[e("span",{children:sa[w]??w}),e("span",{class:"rpc-pool-url-count",children:[y," URL",y!==1?"s":""]})]}),K&&e("div",{class:"rpc-url-list",children:[R.map((H,Y)=>{const ae=T(H.url),ce=`${w}:${H.url}`,F=d.value[ce]??!1,O=v.value[ce];return e("div",{class:`rpc-url-item${H.isBuiltin?" rpc-url-item--builtin":""}${H.enabled?"":" rpc-url-disabled"}`,"data-testid":`rpc-url-${w}-${Y}`,children:[e("span",{class:"rpc-url-priority",children:["#",Y+1]}),e("span",{class:"rpc-url-item-url",title:H.url,children:H.url}),H.isBuiltin&&e("span",{class:"badge-builtin",children:"(built-in)"}),e("span",{class:"rpc-url-status","data-testid":`rpc-status-${w}-${Y}`,children:ae?ae.status==="available"?e(te,{children:[e("span",{class:"rpc-url-status-dot rpc-url-status-dot--available"}),e("span",{children:"Available"})]}):e(te,{children:[e("span",{class:"rpc-url-status-dot rpc-url-status-dot--cooldown"}),e("span",{children:"Cooldown"}),e("span",{class:"rpc-url-cooldown-info",children:[ur(ae.cooldownRemainingMs)," remaining"]}),e(j,{variant:"warning",children:[ae.failureCount," fail",ae.failureCount!==1?"s":""]})]}):e(te,{children:[e("span",{class:"rpc-url-status-dot rpc-url-status-dot--unknown"}),e("span",{children:"Unknown"})]})}),e("span",{class:"rpc-url-test-inline",children:[e(P,{variant:"ghost",size:"sm",onClick:()=>A(w,H.url),loading:F,children:"Test"}),O&&e("span",{class:`rpc-test-result ${O.success?"rpc-test-result--success":"rpc-test-result--failure"}`,children:[e(j,{variant:O.success?"success":"danger",children:O.success?"OK":"FAIL"}),O.success&&e(te,{children:[" ",O.latencyMs,"ms",O.blockNumber!==void 0&&` (block #${O.blockNumber.toLocaleString()})`]}),O.error&&` - ${O.error}`]})]}),e("span",{class:"rpc-url-actions",children:[e("button",{class:"btn btn-ghost btn-sm rpc-action-btn",onClick:()=>V(w,Y,"up"),disabled:Y===0,title:"Move up","aria-label":"Move up",children:"↑"}),e("button",{class:"btn btn-ghost btn-sm rpc-action-btn",onClick:()=>V(w,Y,"down"),disabled:Y===R.length-1,title:"Move down","aria-label":"Move down",children:"↓"}),H.isBuiltin?e("button",{class:`btn btn-ghost btn-sm rpc-action-btn${H.enabled?"":" rpc-toggle-off"}`,onClick:()=>C(w,Y),title:H.enabled?"Disable":"Enable","aria-label":H.enabled?"Disable":"Enable",children:H.enabled?"On":"Off"}):e("button",{class:"btn btn-ghost btn-sm rpc-action-btn rpc-delete-btn",onClick:()=>I(w,Y),title:"Remove","aria-label":"Remove",children:"×"})]})]},`${w}-${Y}`)}),e("div",{class:"rpc-add-url",children:[e("input",{type:"text",class:"rpc-add-url-input",placeholder:"https://your-rpc-url.com",value:s.value[w]??"",onInput:H=>{s.value={...s.value,[w]:H.target.value}},onKeyDown:H=>{H.key==="Enter"&&G(w)}}),e(P,{variant:"secondary",size:"sm",onClick:()=>G(w),children:"Add"})]})]})]})}return i.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[W.value>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[W.value," unsaved change",W.value>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:N,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:f,loading:l.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"RPC Endpoints"}),e("p",{class:"settings-description",children:"Manage prioritized RPC URL lists per network. User URLs have highest priority; built-in defaults are appended automatically."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"Solana"}),ht.map(w=>e(x,{network:w},w))]}),e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"EVM"}),kt.map(w=>e(x,{network:w},w))]})]})]})]})}function pr(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const d=await q(D.ADMIN_SETTINGS);t.value=d}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{l.value=!1}};X(()=>{i()},[]);const r=(d,v)=>{const h=String(v);a.value={...a.value,[d]:h}},s=async()=>{n.value=!0;try{const d=Object.entries(a.value).filter(([h])=>h.startsWith("walletconnect.")).map(([h,_])=>({key:h,value:_})),v=await oe(D.ADMIN_SETTINGS,{settings:d});t.value=v.settings,a.value={},m("success","Settings saved and applied")}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{n.value=!1}},o=()=>{a.value={}};X(()=>(Be({id:"wallets-walletconnect",isDirty:()=>Object.keys(a.value).filter(d=>d.startsWith("walletconnect.")).length>0,save:s,discard:o}),()=>Re("wallets-walletconnect")),[]);const u=Object.keys(a.value).filter(d=>d.startsWith("walletconnect.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[u>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[u," unsaved change",u>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:s,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"WalletConnect"}),e("p",{class:"settings-description",children:"WalletConnect integration for dApp connections"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e("div",{class:"settings-field-full",children:e(k,{label:ie("project_id"),name:"walletconnect.project_id",type:"text",value:pe(t.value,a.value,"walletconnect","project_id"),onChange:d=>r("walletconnect.project_id",d),description:"WalletConnect Cloud project identifier"})}),e("div",{class:"settings-field-full",children:e(k,{label:ie("relay_url"),name:"walletconnect.relay_url",type:"text",value:pe(t.value,a.value,"walletconnect","relay_url"),onChange:d=>r("walletconnect.relay_url",d),placeholder:"wss://relay.walletconnect.com",description:"WalletConnect relay server URL"})})]}),e("div",{class:"settings-info-box",children:["Get your project ID from"," ",e("a",{href:"https://cloud.walletconnect.com",target:"_blank",rel:"noopener noreferrer",children:"https://cloud.walletconnect.com"})," ","— Create a free account and project to obtain your project ID."]}),e("div",{class:"settings-info-box",children:"Relay URL defaults to wss://relay.walletconnect.com if not set."})]})]})]})}const mr=[{key:"chain",label:"Chain",type:"select",options:[{value:"solana",label:"Solana"},{value:"ethereum",label:"Ethereum"}]},{key:"environment",label:"Environment",type:"select",options:[{value:"testnet",label:"Testnet"},{value:"mainnet",label:"Mainnet"}]},{key:"status",label:"Status",type:"select",options:[{value:"ACTIVE",label:"ACTIVE"},{value:"SUSPENDED",label:"SUSPENDED"},{value:"TERMINATED",label:"TERMINATED"}]}];function fr(){const t=c([]),a=c(!0),n=c(!1),l=c(""),i=c("solana"),r=c("testnet"),s=c("eoa"),o=c("none"),u=c(""),d=c(""),v=c(""),h=c(null),_=c(!1),A=c(null),$=c(""),W=c({chain:"",environment:"",status:""}),f=async()=>{try{const C=await q(D.WALLETS);t.value=C.items}catch(C){const x=C instanceof b?C:new b(0,"UNKNOWN","Unknown error");m("error",z(x.code))}finally{a.value=!1}},N=ma(()=>{let C=t.value;const x=$.value.toLowerCase();x&&(C=C.filter(R=>R.name.toLowerCase().includes(x)||R.publicKey.toLowerCase().includes(x)));const w=W.value;return w.chain&&(C=C.filter(R=>R.chain===w.chain)),w.environment&&(C=C.filter(R=>R.environment===w.environment)),w.status&&(C=C.filter(R=>R.status===w.status)),C}),E=[{key:"name",header:"Name"},{key:"chain",header:"Chain"},{key:"environment",header:"Environment",render:C=>e(j,{variant:C.environment==="mainnet"?"warning":"info",children:C.environment})},{key:"accountType",header:"Type",render:C=>C.accountType!=="smart"?e(j,{variant:"default",children:"EOA"}):C.factoryAddress?.toLowerCase()===yl.toLowerCase()?e(j,{variant:"danger",children:"Deprecated"}):e(j,{variant:C.provider?"info":"warning",children:C.provider?"Smart (Full)":"Smart (Lite)"})},{key:"publicKey",header:"Public Key",render:C=>e("span",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[Pt(C.publicKey)," ",e(tt,{value:C.publicKey})]})},{key:"status",header:"Status",render:C=>e(j,{variant:C.status==="ACTIVE"?"success":C.status==="SUSPENDED"?"warning":"danger",children:C.status})},{key:"ownerState",header:"Owner",render:C=>e(j,{variant:_l(C.ownerState),children:C.ownerState})},{key:"createdAt",header:"Created",render:C=>_e(C.createdAt)}],G=async()=>{if(!l.value.trim()){h.value="Name is required";return}h.value=null,_.value=!0;try{const C={name:l.value.trim(),chain:i.value,environment:r.value};s.value==="smart"&&(C.accountType="smart",o.value!=="none"&&(o.value==="custom"?(C.aaProvider="custom",C.aaBundlerUrl=d.value,v.value&&(C.aaPaymasterUrl=v.value)):(C.aaProvider=o.value,C.aaProviderApiKey=u.value)));const x=await he(D.WALLETS,C);x.session?.token?(A.value=x.session.token,m("success","Wallet created with session")):m("success","Wallet created"),l.value="",i.value="solana",r.value="testnet",s.value="eoa",o.value="none",u.value="",d.value="",v.value="",n.value=!1,a.value=!0,await f()}catch(C){const x=C instanceof b?C:new b(0,"UNKNOWN","Unknown error");h.value=z(x.code)}finally{_.value=!1}},I=C=>{window.location.hash="#/wallets/"+C.id},V=C=>{i.value=C,C==="solana"&&(s.value="eoa",o.value="none",u.value="",d.value="",v.value="")};return X(()=>{f()},[]),e(te,{children:[e("div",{class:"page-actions",children:!n.value&&e(P,{onClick:()=>{n.value=!0},children:"Create Wallet"})}),n.value&&e("div",{class:"inline-form",children:[e(k,{label:"Name",name:"name",value:l.value,onChange:C=>{l.value=C},required:!0,placeholder:"e.g. trading-bot",error:h.value??void 0}),e(k,{label:"Chain",name:"chain",type:"select",value:i.value,onChange:V,options:[{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}]}),i.value==="ethereum"&&e(k,{label:"Account Type",name:"accountType",type:"select",value:s.value,onChange:C=>{s.value=C},options:[{label:"EOA (Standard)",value:"eoa"},{label:"Smart Account (ERC-4337)",value:"smart"}]}),s.value==="smart"&&i.value==="ethereum"&&e(te,{children:[e(k,{label:"Provider",name:"provider",type:"select",value:o.value,onChange:C=>{o.value=C},options:oa.map(C=>({label:C.label,value:C.value}))}),o.value==="none"?null:o.value!=="custom"?e(te,{children:[e(k,{label:"API Key",name:"apiKey",value:u.value,onChange:C=>{u.value=C},placeholder:"Paste your provider API key"}),ca[o.value]&&e("p",{style:{fontSize:"0.85rem",color:"var(--color-text-secondary)",margin:"0 0 0.5rem 0"},children:["Get your API key at:"," ",e("a",{href:ca[o.value],target:"_blank",rel:"noopener noreferrer",children:[oa.find(C=>C.value===o.value)?.label," Dashboard"]})]})]}):e(te,{children:[e(k,{label:"Bundler URL",name:"bundlerUrl",value:d.value,onChange:C=>{d.value=C},placeholder:"https://..."}),e(k,{label:"Paymaster URL (optional)",name:"paymasterUrl",value:v.value,onChange:C=>{v.value=C},placeholder:"https://..."})]})]}),e(k,{label:"Environment",name:"environment",type:"select",value:r.value,onChange:C=>{r.value=C},options:[{label:"Testnet",value:"testnet"},{label:"Mainnet",value:"mainnet"}]}),e("div",{class:"inline-form-actions",children:[e(P,{onClick:G,loading:_.value,children:"Create"}),e(P,{variant:"secondary",onClick:()=>{n.value=!1,h.value=null},children:"Cancel"})]})]}),A.value&&e("div",{class:"inline-form",style:{marginBottom:"1rem"},children:[e("div",{style:{fontWeight:"bold",marginBottom:"0.5rem"},children:"Session Token (copy now — shown only once)"}),e("div",{style:{display:"flex",gap:"0.5rem",alignItems:"center"},children:[e("input",{type:"text",readOnly:!0,value:A.value,style:{flex:1,fontFamily:"monospace",fontSize:"0.85rem",padding:"0.5rem"},onClick:C=>C.target.select()}),e(P,{variant:"secondary",onClick:()=>{navigator.clipboard.writeText(A.value),m("success","Token copied")},children:"Copy"}),e(P,{variant:"secondary",onClick:()=>{A.value=null},children:"Dismiss"})]})]}),e(Bt,{fields:mr,values:W.value,onChange:C=>{W.value=C},syncUrl:!1}),e(gl,{value:$.value,onSearch:C=>{$.value=C},placeholder:"Search by name or public key..."}),e(De,{columns:E,data:N.value,loading:a.value,onRowClick:I,emptyMessage:"No wallets yet"})]})}const yn=[{key:"wallets",label:"Wallets"},{key:"rpc",label:"RPC Endpoints"},{key:"walletconnect",label:"WalletConnect"}];function gr(){const t=c("wallets");return X(()=>{const a=me.value;a&&a.tab&&(t.value=a.tab,setTimeout(()=>{xe.value=a.fieldName},100),me.value=null)},[me.value]),e("div",{class:"page",children:[e(wt,{pageName:"Wallets",tabName:yn.find(a=>a.key===t.value)?.label??"",onPageClick:()=>{t.value="wallets"}}),e(at,{tabs:yn,activeTab:t.value,onTabChange:a=>{t.value=a}}),t.value==="wallets"&&e(fr,{}),t.value==="rpc"&&e(hr,{}),t.value==="walletconnect"&&e(pr,{})]})}function _n(){const t=Je.value,a=t.startsWith("/wallets/")?t.slice(9):null;return a?e(dr,{id:a}):e(gr,{})}const bn=[{key:"transactions",label:"All Transactions"},{key:"monitor",label:"Monitor Settings"}],qe=20,yr=[{value:"all",label:"All"},{value:"outgoing",label:"Outgoing"},{value:"incoming",label:"Incoming"}],_r=[{value:"TRANSFER",label:"TRANSFER"},{value:"TOKEN_TRANSFER",label:"TOKEN_TRANSFER"},{value:"CONTRACT_CALL",label:"CONTRACT_CALL"},{value:"APPROVE",label:"APPROVE"},{value:"BATCH",label:"BATCH"}],br=[{value:"PENDING",label:"PENDING"},{value:"QUEUED",label:"QUEUED"},{value:"APPROVED",label:"APPROVED"},{value:"SUBMITTED",label:"SUBMITTED"},{value:"CONFIRMED",label:"CONFIRMED"},{value:"FAILED",label:"FAILED"},{value:"CANCELLED",label:"CANCELLED"}],wr=[{value:"DETECTED",label:"DETECTED"},{value:"CONFIRMED",label:"CONFIRMED"}],Sr=[{value:"solana",label:"Solana"},{value:"evm",label:"EVM"}],Tr=[{value:"true",label:"Yes"},{value:"false",label:"No"}],kr=[{value:"solana-mainnet",label:"solana-mainnet"},{value:"solana-devnet",label:"solana-devnet"},{value:"solana-testnet",label:"solana-testnet"},{value:"ethereum-mainnet",label:"ethereum-mainnet"},{value:"ethereum-sepolia",label:"ethereum-sepolia"},{value:"polygon-mainnet",label:"polygon-mainnet"},{value:"polygon-amoy",label:"polygon-amoy"},{value:"arbitrum-mainnet",label:"arbitrum-mainnet"},{value:"arbitrum-sepolia",label:"arbitrum-sepolia"},{value:"optimism-mainnet",label:"optimism-mainnet"},{value:"optimism-sepolia",label:"optimism-sepolia"},{value:"base-mainnet",label:"base-mainnet"},{value:"base-sepolia",label:"base-sepolia"}],Yt=["Time","Direction","Wallet","Counterparty","Amount","Network","Status","Tx Hash"];function Nr(t){return t==="CONFIRMED"?"success":t==="FAILED"?"danger":"warning"}function wn(t){return{id:`out-${t.id}`,direction:"outgoing",time:t.createdAt,walletId:t.walletId,walletName:t.walletName,counterparty:t.toAddress,amount:t.amount,formattedAmount:t.formattedAmount,amountUsd:t.amountUsd,network:t.network??t.chain,status:t.status,txHash:t.txHash,chain:t.chain,outgoing:t}}function Sn(t){return{id:`in-${t.id}`,direction:"incoming",time:t.detectedAt,walletId:t.walletId,walletName:t.walletName,counterparty:t.fromAddress,amount:t.amount,formattedAmount:t.formattedAmount,amountUsd:null,network:t.network,status:t.status,txHash:t.txHash,chain:t.chain,incoming:t}}function Tn(){const t=c("transactions"),a=c([]),n=c(0),l=c(0),i=c(!0),r=c(null),s=c("all"),o=c({wallet_id:"",type:"",status:"",network:"",chain:"",suspicious:"",since:"",until:""}),u=c(""),d=c(0),v=c(null),h=c("USD"),_=c(1),A=c([]),$=c({}),W=c({}),f=c(!1),N=c(!0),E=c([]),G=c(!0),I=c({}),V=c(null),C=(S,U)=>{W.value={...W.value,[S]:String(U)}},x=(S,U)=>pe($.value,W.value,S,U),w=async()=>{f.value=!0;try{const S=Object.entries(W.value).filter(([se])=>se.startsWith("incoming.")).map(([se,ge])=>({key:se,value:ge}));if(S.length===0){m("info","No changes to save"),f.value=!1;return}const U=await oe(D.ADMIN_SETTINGS,{settings:S});$.value=U.settings,W.value={},m("success","Settings saved and applied")}catch(S){const U=S instanceof b?S:new b(0,"UNKNOWN","Unknown error");m("error",z(U.code))}finally{f.value=!1}},R=()=>{W.value={}};X(()=>(Object.keys(W.value).filter(U=>U.startsWith("incoming.")).length>0?Be({id:"transactions-monitor",isDirty:()=>Object.keys(W.value).filter(U=>U.startsWith("incoming.")).length>0,save:w,discard:R}):Re("transactions-monitor"),()=>Re("transactions-monitor")),[W.value]);function K(){const S=s.value,U=[{key:"wallet_id",label:"Wallet",type:"select",options:A.value}];return(S==="outgoing"||S==="all")&&U.push({key:"type",label:"Type",type:"select",options:_r}),S==="outgoing"?U.push({key:"status",label:"Status",type:"select",options:br}):S==="incoming"&&U.push({key:"status",label:"Status",type:"select",options:wr}),U.push({key:"network",label:"Network",type:"select",options:kr}),(S==="incoming"||S==="all")&&(U.push({key:"chain",label:"Chain",type:"select",options:Sr}),U.push({key:"suspicious",label:"Suspicious",type:"select",options:Tr})),U.push({key:"since",label:"Since",type:"date"},{key:"until",label:"Until",type:"date"}),U}const y=async()=>{const S=new URLSearchParams,U=o.value;if(U.wallet_id&&S.set("wallet_id",U.wallet_id),U.type&&S.set("type",U.type),U.status&&s.value!=="all"&&S.set("status",U.status),U.network&&S.set("network",U.network),U.since){const se=new Date(U.since);isNaN(se.getTime())||S.set("since",String(Math.floor(se.getTime()/1e3)))}if(U.until){const se=new Date(U.until);isNaN(se.getTime())||(se.setHours(23,59,59,999),S.set("until",String(Math.floor(se.getTime()/1e3))))}return u.value&&S.set("search",u.value),S.set("offset",String(d.value*qe)),S.set("limit",String(qe)),q(`${D.ADMIN_TRANSACTIONS}?${S.toString()}`)},p=async()=>{const S=new URLSearchParams,U=o.value;return U.wallet_id&&S.set("wallet_id",U.wallet_id),U.chain&&S.set("chain",U.chain),U.status&&s.value!=="all"&&S.set("status",U.status),U.suspicious&&S.set("suspicious",U.suspicious),S.set("offset",String(d.value*qe)),S.set("limit",String(qe)),q(`${D.ADMIN_INCOMING}?${S.toString()}`)},T=async()=>{i.value=!0,r.value=null;try{const S=s.value;if(S==="outgoing"){const U=await y();a.value=U.items.map(wn),n.value=U.total,l.value=0}else if(S==="incoming"){const U=await p();a.value=U.items.map(Sn),n.value=0,l.value=U.total}else{const[U,se]=await Promise.all([y(),p()]),ge=[...U.items.map(wn),...se.items.map(Sn)];ge.sort((nt,ze)=>(ze.time??0)-(nt.time??0)),a.value=ge,n.value=U.total,l.value=se.total}}catch(S){S instanceof b?r.value=z(S.code):r.value="An unexpected error occurred."}finally{i.value=!1}},H=async()=>{try{const S=await q(D.WALLETS),U=Array.isArray(S)?S:S.items??[];A.value=U.map(ge=>({value:ge.id,label:ge.name||ge.id.slice(0,8)})),E.value=U;const se={};for(const ge of U)se[ge.id]=ge.monitorIncoming??!1;I.value=se}catch{}finally{G.value=!1}},Y=async()=>{try{const S=await q(D.ADMIN_SETTINGS);$.value=S}catch(S){const U=S instanceof b?S:new b(0,"UNKNOWN","Unknown error");m("error",z(U.code))}finally{N.value=!1}};X(()=>{T(),H(),Va().then(({currency:S,rate:U})=>{h.value=S,_.value=U}).catch(()=>{}),Y()},[]),X(()=>{T()},[o.value,u.value,d.value,s.value]),X(()=>{const S=me.value;S&&S.tab&&(t.value=S.tab,me.value=null,setTimeout(()=>{xe.value=S.fieldName},100))},[me.value]);function ae(S){t.value=S}function ce(S){o.value=S,d.value=0}function F(S){u.value=S,d.value=0}function O(S){s.value=S,d.value=0,o.value={...o.value,type:"",status:"",chain:"",suspicious:""}}function Q(S){v.value=v.value===S.id?null:S.id}function J(){d.value>0&&(d.value=d.value-1)}function be(){const S=n.value+l.value;(d.value+1)*qe<S&&(d.value=d.value+1)}async function Ae(S){if(window.confirm("Are you sure you want to cancel this transaction?"))try{await he(D.ADMIN_TX_CANCEL(S)),m("success","Transaction cancelled"),await T()}catch(U){const se=U instanceof b?U:new b(0,"UNKNOWN","Unknown error");m("error",z(se.code))}}async function L(S){if(window.confirm("Are you sure you want to reject this transaction?"))try{await he(D.ADMIN_TX_REJECT(S)),m("success","Transaction rejected"),await T()}catch(U){const se=U instanceof b?U:new b(0,"UNKNOWN","Unknown error");m("error",z(se.code))}}async function le(S){const U=I.value[S]??!1;V.value=S;try{const se=await Di(D.WALLET_PATCH(S),{monitorIncoming:!U});I.value={...I.value,[S]:se.monitorIncoming}}catch(se){const ge=se instanceof b?se:new b(0,"UNKNOWN","Unknown error");m("error",z(ge.code))}finally{V.value=null}}function M(){const S=n.value+l.value,U=d.value*qe,se=S>0?U+1:0,ge=Math.min(U+qe,S),nt=d.value>0,ze=(d.value+1)*qe<S;return e(te,{children:[r.value&&e("div",{class:"dashboard-error",children:[e("span",{children:r.value}),e(P,{variant:"secondary",size:"sm",onClick:T,children:"Retry"})]}),e("div",{class:"filter-bar",style:{marginBottom:0},children:e("div",{class:"filter-field",children:[e("label",{children:"Direction"}),e("select",{value:s.value,onChange:ne=>O(ne.target.value),children:yr.map(ne=>e("option",{value:ne.value,children:ne.label},ne.value))})]})}),e(Bt,{fields:K(),values:o.value,onChange:ce}),s.value!=="incoming"&&e(gl,{value:u.value,onSearch:F,placeholder:"Search by txHash or recipient address..."}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:Yt.map(ne=>e("th",{children:ne},ne))})}),e("tbody",{children:i.value&&a.value.length===0?e("tr",{children:e("td",{colSpan:Yt.length,class:"table-loading",children:"Loading..."})}):a.value.length===0?e("tr",{children:e("td",{colSpan:Yt.length,class:"table-empty",children:"No transactions found"})}):a.value.map(ne=>e(te,{children:[e("tr",{class:`clickable${v.value===ne.id?" row-expanded":""}`,style:{cursor:"pointer"},onClick:()=>Q(ne),children:[e("td",{children:ne.time?_e(ne.time):"—"}),e("td",{children:e(j,{variant:ne.direction==="outgoing"?"info":"success",children:ne.direction==="outgoing"?"Outgoing":"Incoming"})}),e("td",{children:ne.walletName??ne.walletId.slice(0,8)}),e("td",{children:ne.counterparty?Pt(ne.counterparty):"—"}),e("td",{children:ne.amount?(()=>{const He=ne.formattedAmount??ne.amount;if(ne.amountUsd!=null){const lt=yt(ne.amountUsd,h.value,_.value);return lt?`${He} (${lt})`:He}return He})():"—"}),e("td",{children:ne.network}),e("td",{children:e(j,{variant:Nr(ne.status),children:ne.status})}),e("td",{children:e(qa,{network:ne.network,txHash:ne.txHash})})]},ne.id),v.value===ne.id&&e("tr",{class:"row-expand",children:e("td",{colSpan:Yt.length,children:[ne.outgoing?ee(ne.outgoing):null,ne.incoming?ve(ne.incoming):null]})},`${ne.id}-expand`)]}))})]})}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Showing ",se,"-",ge," of ",S]}),e("div",{class:"pagination-buttons",children:[e(P,{variant:"secondary",size:"sm",disabled:!nt,onClick:J,children:"Previous"}),e(P,{variant:"secondary",size:"sm",disabled:!ze,onClick:be,children:"Next"})]})]})]})}function ee(S){return e("div",{class:"detail-grid",children:[e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"ID"}),e("span",{class:"detail-value",children:S.id})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet ID"}),e("span",{class:"detail-value",children:S.walletId})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet Name"}),e("span",{class:"detail-value",children:S.walletName??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Type"}),e("span",{class:"detail-value",children:S.type})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Status"}),e("span",{class:"detail-value",children:S.status})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Tier"}),e("span",{class:"detail-value",children:S.tier??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"To Address"}),e("span",{class:"detail-value",children:S.toAddress??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Amount"}),e("span",{class:"detail-value",children:S.amount??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Amount USD"}),e("span",{class:"detail-value",children:S.amountUsd!=null?`$${S.amountUsd.toFixed(2)}`:"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Network"}),e("span",{class:"detail-value",children:S.network??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Chain"}),e("span",{class:"detail-value",children:S.chain})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Tx Hash"}),e("span",{class:"detail-value",children:S.txHash??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Created At"}),e("span",{class:"detail-value",children:S.createdAt?_e(S.createdAt):"—"})]}),S.status==="QUEUED"&&e("div",{class:"detail-item",style:{gridColumn:"1 / -1",marginTop:"var(--space-2)"},children:e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[e(P,{variant:"danger",size:"sm",onClick:U=>{U.stopPropagation(),Ae(S.id)},children:"Cancel"}),e(P,{variant:"secondary",size:"sm",onClick:U=>{U.stopPropagation(),L(S.id)},children:"Reject"})]})})]})}function ve(S){return e("div",{class:"detail-grid",children:[e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"ID"}),e("span",{class:"detail-value",children:S.id})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Tx Hash"}),e("span",{class:"detail-value",children:S.txHash})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet ID"}),e("span",{class:"detail-value",children:S.walletId})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet Name"}),e("span",{class:"detail-value",children:S.walletName??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"From Address"}),e("span",{class:"detail-value",children:S.fromAddress})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Amount"}),e("span",{class:"detail-value",children:S.amount})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Token Address"}),e("span",{class:"detail-value",children:S.tokenAddress??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Chain"}),e("span",{class:"detail-value",children:S.chain})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Network"}),e("span",{class:"detail-value",children:S.network})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Status"}),e("span",{class:"detail-value",children:S.status})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Block Number"}),e("span",{class:"detail-value",children:S.blockNumber??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Detected At"}),e("span",{class:"detail-value",children:S.detectedAt?_e(S.detectedAt):"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Confirmed At"}),e("span",{class:"detail-value",children:S.confirmedAt?_e(S.confirmedAt):"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Suspicious"}),e("span",{class:"detail-value",children:S.suspicious?"Yes":"No"})]})]})}function Ce(){const S=Object.keys(W.value).filter(U=>U.startsWith("incoming.")).length;return e(te,{children:[S>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[S," unsaved change",S>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:R,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:w,loading:f.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Incoming TX Monitoring Settings"}),e("p",{class:"settings-description",children:"Monitor incoming transactions to wallets. Detects native and token transfers, flags suspicious activity (dust attacks, large amounts, unknown tokens)."})]}),e("div",{class:"settings-category-body",children:N.value?e("span",{children:"Loading settings..."}):e(te,{children:[e("div",{class:"settings-fields-grid",children:[e(k,{label:"Monitoring Enabled",name:"incoming.enabled",type:"select",value:x("incoming","enabled")||"false",onChange:U=>C("incoming.enabled",U),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}]}),e(k,{label:"Poll Interval (seconds)",name:"incoming.poll_interval",type:"number",value:Number(x("incoming","poll_interval"))||30,onChange:U=>C("incoming.poll_interval",U),min:5,max:3600}),e(k,{label:"Retention Days",name:"incoming.retention_days",type:"number",value:Number(x("incoming","retention_days"))||90,onChange:U=>C("incoming.retention_days",U),min:1,max:365}),e(k,{label:"Suspicious Dust USD Threshold",name:"incoming.suspicious_dust_usd",type:"number",value:Number(x("incoming","suspicious_dust_usd"))||.01,onChange:U=>C("incoming.suspicious_dust_usd",U),min:0,max:1e3}),e(k,{label:"Suspicious Amount Multiplier",name:"incoming.suspicious_amount_multiplier",type:"number",value:Number(x("incoming","suspicious_amount_multiplier"))||10,onChange:U=>C("incoming.suspicious_amount_multiplier",U),min:1,max:1e3}),e(k,{label:"Notification Cooldown (minutes)",name:"incoming.cooldown_minutes",type:"number",value:Number(x("incoming","cooldown_minutes"))||5,onChange:U=>C("incoming.cooldown_minutes",U),min:1,max:1440}),e(k,{label:"WebSocket URL (optional)",name:"incoming.wss_url",type:"text",value:x("incoming","wss_url"),onChange:U=>C("incoming.wss_url",U),placeholder:"wss://custom-rpc.example.com"})]}),e("div",{class:"settings-info-box",children:"Monitors wallets with incoming monitoring enabled for incoming transactions. Uses WebSocket subscription when available, falls back to polling. Suspicious transactions (dust attacks, unusually large amounts, unknown tokens) trigger broadcast alerts to all notification channels. Changes take effect immediately via hot-reload."})]})})]}),e("div",{class:"settings-category",style:{marginTop:"var(--space-4)"},children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Per-Wallet Monitoring"}),e("p",{class:"settings-description",children:"Enable or disable incoming transaction monitoring for individual wallets"})]}),e("div",{class:"settings-category-body",children:G.value?e("span",{children:"Loading wallets..."}):E.value.length===0?e("p",{class:"empty-text",children:"No wallets found"}):e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:[e("th",{children:"Wallet Name"}),e("th",{children:"Chain"}),e("th",{children:"Status"}),e("th",{children:"Monitor Incoming"})]})}),e("tbody",{children:E.value.map(U=>e("tr",{children:[e("td",{children:U.name||U.id.slice(0,8)}),e("td",{children:U.chain}),e("td",{children:e(j,{variant:(U.status??"ACTIVE")==="ACTIVE"?"success":"warning",children:U.status??"ACTIVE"})}),e("td",{children:e(P,{variant:I.value[U.id]?"primary":"secondary",size:"sm",onClick:()=>le(U.id),loading:V.value===U.id,children:I.value[U.id]?"ON":"OFF"})})]},U.id))})]})})})]})]})}const ke=bn.find(S=>S.key===t.value)?.label;return e("div",{class:"page",children:[e(wt,{pageName:"Transactions",tabName:ke,onPageClick:()=>{t.value="transactions"}}),e(at,{tabs:bn,activeTab:t.value,onTabChange:ae}),e("div",{style:{marginTop:"var(--space-4)"},children:t.value==="transactions"?M():Ce()})]})}const Ar=zt,wa=["Symbol","Name","Address","Decimals","Source","Actions"];function Er(t){return t.length<=10?t:`${t.slice(0,6)}...${t.slice(-4)}`}function Cr(){const t=c("ethereum-mainnet"),a=c([]),n=c(!0),l=c(null),i=c(!1),r=c(""),s=c(""),o=c(""),u=c("18"),d=c(!1),v=c(!1),h=c(null),_=Fe(null),A=async()=>{n.value=!0,l.value=null;try{const I=await q(`${D.TOKENS}?network=${encodeURIComponent(t.value)}`);a.value=I.tokens}catch(I){I instanceof b?l.value=z(I.code):l.value="An unexpected error occurred.",a.value=[]}finally{n.value=!1}};X(()=>{A()},[t.value]);function $(I){t.value=I.target.value}function W(){r.value="",s.value="",o.value="",u.value="18",v.value=!1,i.value=!1,_.current&&clearTimeout(_.current)}async function f(I){v.value=!0;try{const V=await q(`${D.TOKENS_RESOLVE}?network=${encodeURIComponent(t.value)}&address=${encodeURIComponent(I)}`);s.value=V.symbol,o.value=V.name,u.value=String(V.decimals),m("success",`Resolved: ${V.symbol} (${V.name})`)}catch{}finally{v.value=!1}}function N(I){const V=I.target.value;r.value=V,_.current&&clearTimeout(_.current),/^0x[a-fA-F0-9]{40}$/.test(V)&&(_.current=setTimeout(()=>f(V),500))}async function E(){if(!r.value||!s.value||!o.value){m("error","Please fill in all required fields.");return}d.value=!0;try{await he(D.TOKENS,{network:t.value,address:r.value,symbol:s.value,name:o.value,decimals:Number(u.value)}),m("success",`Token ${s.value} added successfully.`),W(),await A()}catch(I){I instanceof b?m("error",z(I.code)):m("error","Failed to add token.")}finally{d.value=!1}}async function G(I){h.value=I;try{await Le(D.TOKENS,{network:t.value,address:I}),m("success","Token removed successfully."),await A()}catch(V){V instanceof b?m("error",z(V.code)):m("error","Failed to remove token.")}finally{h.value=null}}return e("div",{class:"page",children:[l.value&&e("div",{class:"dashboard-error",children:[e("span",{children:l.value}),e(P,{variant:"secondary",size:"sm",onClick:A,children:"Retry"})]}),e("div",{class:"filter-bar",children:[e("div",{class:"filter-field",children:[e("label",{children:"Network"}),e("select",{value:t.value,onChange:$,children:Ar.map(I=>e("option",{value:I,children:sa[I]??I},I))})]}),e("div",{style:{marginLeft:"auto"},children:e(P,{variant:"primary",size:"sm",onClick:()=>{i.value=!i.value},children:i.value?"Cancel":"Add Token"})})]}),i.value&&e("div",{class:"card",style:{marginTop:"var(--space-3)",padding:"var(--space-4)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Add Custom Token"}),e("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"var(--space-3)"},children:[e("div",{class:"form-field",children:[e("label",{for:"token-address",children:["Contract Address ",v.value&&e("span",{style:{color:"var(--warning)",fontSize:"0.85em"},children:"(resolving...)"})]}),e("input",{id:"token-address",type:"text",value:r.value,onInput:N,placeholder:"0x... (metadata auto-fetched)"})]}),e("div",{class:"form-field",children:[e("label",{for:"token-symbol",children:"Symbol"}),e("input",{id:"token-symbol",type:"text",value:s.value,onInput:I=>{s.value=I.target.value},placeholder:"e.g. USDC"})]}),e("div",{class:"form-field",children:[e("label",{for:"token-name",children:"Name"}),e("input",{id:"token-name",type:"text",value:o.value,onInput:I=>{o.value=I.target.value},placeholder:"e.g. USD Coin"})]}),e("div",{class:"form-field",children:[e("label",{for:"token-decimals",children:"Decimals"}),e("input",{id:"token-decimals",type:"number",value:u.value,onInput:I=>{u.value=I.target.value},placeholder:"18"})]})]}),e("div",{style:{marginTop:"var(--space-3)",display:"flex",gap:"var(--space-2)"},children:[e(P,{variant:"primary",size:"sm",loading:d.value,onClick:E,children:"Submit"}),e(P,{variant:"secondary",size:"sm",onClick:W,children:"Cancel"})]})]}),e("div",{class:"table-container",style:{marginTop:"var(--space-3)"},children:e("table",{children:[e("thead",{children:e("tr",{children:wa.map(I=>e("th",{children:I},I))})}),e("tbody",{children:n.value&&a.value.length===0?e("tr",{children:e("td",{colSpan:wa.length,class:"table-loading",children:"Loading..."})}):a.value.length===0?e("tr",{children:e("td",{colSpan:wa.length,class:"table-empty",children:"No tokens found for this network"})}):a.value.map(I=>e("tr",{children:[e("td",{children:I.symbol}),e("td",{children:I.name}),e("td",{title:I.address,children:Er(I.address)}),e("td",{children:I.decimals}),e("td",{children:e(j,{variant:I.source==="builtin"?"neutral":"info",children:I.source==="builtin"?"Built-in":"Custom"})}),e("td",{children:I.source==="custom"?e(P,{variant:"danger",size:"sm",loading:h.value===I.address,onClick:()=>G(I.address),children:"Delete"}):"—"})]},I.address))})]})})]})}function Qe({legend:t,children:a,description:n}){return e("fieldset",{class:"field-group",children:[e("legend",{class:"field-group-legend",children:t}),n&&e("p",{class:"field-group-description",children:n}),e("div",{class:"field-group-body",children:a})]})}function Ir(t,a,n){a.value=t,n.value=!0}const kn=[{key:"sessions",label:"Sessions"},{key:"settings",label:"Settings"}],Sa=["security.max_sessions_per_wallet","security.max_pending_tx","security.rate_limit_session_rpm","security.rate_limit_tx_rpm"];function xr(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const d=await q(D.ADMIN_SETTINGS);t.value=d}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{l.value=!1}};X(()=>{i()},[]);const r=(d,v)=>{const h=String(v);a.value={...a.value,[d]:h}},s=async()=>{n.value=!0;try{const d=Object.entries(a.value).filter(([h])=>Sa.includes(h)).map(([h,_])=>({key:h,value:_})),v=await oe(D.ADMIN_SETTINGS,{settings:d});t.value=v.settings,a.value={},m("success","Session settings saved and applied")}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{n.value=!1}},o=()=>{a.value={}};X(()=>(Be({id:"sessions-settings",isDirty:()=>Object.keys(a.value).filter(d=>Sa.includes(d)).length>0,save:s,discard:o}),()=>Re("sessions-settings")),[]);const u=Object.keys(a.value).filter(d=>Sa.includes(d)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[u>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[u," unsaved change",u>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:s,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Session Configuration"}),e("p",{class:"settings-description",children:"Configure session lifetime, renewal limits, and request rate limiting. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e(Qe,{legend:"Limits",description:"Session concurrency limits",children:e("div",{class:"settings-fields-grid",children:e(k,{label:ie("max_sessions_per_wallet"),name:"security.max_sessions_per_wallet",type:"number",value:Number(pe(t.value,a.value,"security","max_sessions_per_wallet"))||0,onChange:d=>r("security.max_sessions_per_wallet",d),min:1,max:100,description:"Maximum concurrent sessions for a single wallet"})})}),e(Qe,{legend:"Rate Limits",description:"Request throttling per session and transaction",children:e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("max_pending_tx"),name:"security.max_pending_tx",type:"number",value:Number(pe(t.value,a.value,"security","max_pending_tx"))||0,onChange:d=>r("security.max_pending_tx",d),min:1,max:100,description:"Maximum in-flight transactions per session"}),e(k,{label:ie("rate_limit_session_rpm"),name:"security.rate_limit_session_rpm",type:"number",value:Number(pe(t.value,a.value,"security","rate_limit_session_rpm"))||0,onChange:d=>r("security.rate_limit_session_rpm",d),min:10,description:"Max requests per minute per session"}),e(k,{label:ie("rate_limit_tx_rpm"),name:"security.rate_limit_tx_rpm",type:"number",value:Number(pe(t.value,a.value,"security","rate_limit_tx_rpm"))||0,onChange:d=>r("security.rate_limit_tx_rpm",d),min:1,description:"Max transaction requests per minute per session"})]})})]})]})]})}function Dr(){const t=c("sessions");X(()=>{const y=me.value;y&&y.tab&&(t.value=y.tab,setTimeout(()=>{xe.value=y.fieldName},100),me.value=null)},[me.value]);const a=c([]),n=c(""),l=c(""),i=c([]),r=c(!1),s=c(!0),o=c(!1),u=c(!1),d=c(""),v=c(!1),h=c(""),_=c(!1),A=c(null),$=c(!1),W=c(new Set),f=c(!1),N=c(""),E=c(""),G=c(""),I=async()=>{try{const y=await q(D.WALLETS);a.value=y.items.filter(p=>p.status==="ACTIVE")}catch(y){const p=y instanceof b?y:new b(0,"UNKNOWN","Unknown error");m("error",z(p.code))}finally{s.value=!1}},V=async()=>{r.value=!0;try{const y=n.value?`${D.SESSIONS}?walletId=${n.value}`:D.SESSIONS,p=await q(y);i.value=p}catch(y){const p=y instanceof b?y:new b(0,"UNKNOWN","Unknown error");m("error",z(p.code))}finally{r.value=!1}},C=y=>{const p=new Set(W.value);p.has(y)?p.delete(y):p.add(y),W.value=p},x=async()=>{o.value=!0;try{const y=Array.from(W.value),p=y.length===1?{walletId:y[0]}:{walletIds:y},T=Number(N.value);T>0&&(p.ttl=T*86400);const H=Number(E.value);E.value!==""&&H>=0&&(p.maxRenewals=H);const Y=Number(G.value);Y>0&&(p.absoluteLifetime=Y*86400);const ae=await he(D.SESSIONS,p);d.value=ae.token,u.value=!0,$.value=!1,f.value=!1,N.value="",E.value="",G.value="",await V()}catch(y){const p=y instanceof b?y:new b(0,"UNKNOWN","Unknown error");m("error",z(p.code))}finally{o.value=!1}},w=async()=>{_.value=!0;try{await Le(D.SESSION(h.value)),m("success","Session revoked"),v.value=!1,await V()}catch(y){const p=y instanceof b?y:new b(0,"UNKNOWN","Unknown error");m("error",z(p.code))}finally{_.value=!1}},R=async y=>{A.value=y;try{const p=await he(D.ADMIN_SESSION_REISSUE(y),{});d.value=p.token,u.value=!0,await V()}catch(p){const T=p instanceof b?p:new b(0,"UNKNOWN","Unknown error");m("error",z(T.code))}finally{A.value=null}};X(()=>{I()},[]),X(()=>{i.value=[],V()},[n.value]);const K=[{key:"id",header:"ID",render:y=>y.id.slice(0,8)+"..."},{key:"walletName",header:"Wallet",render:y=>y.wallets&&y.wallets.length>0?e("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:y.wallets.map(p=>e("span",{children:p.name??p.id.slice(0,8)},p.id))}):y.walletName??y.walletId.slice(0,8)+"..."},{key:"source",header:"Source",render:y=>e(j,{variant:y.source==="mcp"?"info":"neutral",children:y.source==="mcp"?"MCP":"API"})},{key:"status",header:"Status",render:y=>e(j,{variant:y.status==="ACTIVE"?"success":y.status==="EXPIRED"?"warning":"danger",children:y.status})},{key:"expiresAt",header:"Expires At",render:y=>y.expiresAt===0?"Never":_e(y.expiresAt)},{key:"renewals",header:"Renewals",render:y=>`${y.renewalCount}/${y.maxRenewals}`},{key:"tokenIssuedCount",header:"Tokens",render:y=>String(y.tokenIssuedCount??1)},{key:"createdAt",header:"Created",render:y=>_e(y.createdAt)},{key:"actions",header:"Actions",render:y=>y.status==="ACTIVE"?e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[e(P,{size:"sm",variant:"secondary",onClick:()=>R(y.id),loading:A.value===y.id,children:"Reissue"}),e(P,{size:"sm",variant:"danger",onClick:()=>Ir(y.id,h,v),children:"Revoke"})]}):null}];return e("div",{class:"page",children:[e(wt,{pageName:"Sessions",tabName:kn.find(y=>y.key===t.value)?.label??"",onPageClick:()=>{t.value="sessions"}}),e(at,{tabs:kn,activeTab:t.value,onTabChange:y=>{t.value=y}}),t.value==="sessions"&&e(te,{children:[e("div",{class:"session-controls",children:[e("div",{class:"session-wallet-select",children:[e("label",{for:"wallet-select",children:"Wallet"}),e("select",{id:"wallet-select",value:n.value,onChange:y=>{n.value=y.target.value},disabled:s.value,children:[e("option",{value:"",children:"All Wallets"}),a.value.map(y=>e("option",{value:y.id,children:[y.name," (",y.chain,"/",y.network,")"]},y.id))]})]}),e("div",{class:"session-wallet-select",children:[e("label",{for:"source-select",children:"Source"}),e("select",{id:"source-select",value:l.value,onChange:y=>{l.value=y.target.value},children:[e("option",{value:"",children:"All"}),e("option",{value:"api",children:"API"}),e("option",{value:"mcp",children:"MCP"})]})]}),e(P,{onClick:()=>{W.value=new Set,$.value=!0},disabled:a.value.length===0,children:"Create Session"})]}),e(De,{columns:K,data:l.value?i.value.filter(y=>y.source===l.value):i.value,loading:r.value,emptyMessage:"No sessions"}),e(Se,{open:u.value,title:"Session Created",onCancel:()=>{u.value=!1},cancelText:"Close",children:[e("p",{class:"token-warning",children:"Copy this token now. It will not be shown again."}),e("div",{class:"token-display",children:[e("code",{class:"token-value",children:d.value}),e(tt,{value:d.value,label:"Copy Token"})]})]}),e(Se,{open:v.value,title:"Revoke Session",onCancel:()=>{v.value=!1},onConfirm:w,confirmText:"Revoke",confirmVariant:"danger",loading:_.value,children:e("p",{children:"Are you sure you want to revoke this session? The associated token will be immediately invalidated."})}),e(Se,{open:$.value,title:"Create Session",onCancel:()=>{$.value=!1},onConfirm:x,confirmText:`Create Session (${W.value.size} wallet${W.value.size!==1?"s":""})`,confirmDisabled:W.value.size===0,loading:o.value,children:[e("div",{children:[e("label",{style:{fontWeight:600,display:"block",marginBottom:"var(--space-2)"},children:"Select Wallets"}),e("div",{style:{maxHeight:"250px",overflow:"auto",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-2)"},children:a.value.map(y=>e("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"var(--space-1) 0",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:W.value.has(y.id),onChange:()=>C(y.id)}),e("span",{children:y.name}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:["(",y.chain,"/",y.network,")"]})]},y.id))})]}),e("div",{style:{marginTop:"var(--space-3)"},children:[e("button",{type:"button",onClick:()=>{f.value=!f.value},style:{background:"none",border:"none",color:"var(--color-primary)",cursor:"pointer",padding:0,fontSize:"0.85rem"},children:[f.value?"Hide":"Show"," Advanced Options"]}),f.value&&e("div",{style:{marginTop:"var(--space-2)",display:"grid",gap:"var(--space-2)"},children:[e(k,{label:"TTL (days)",name:"create-ttl",type:"number",value:N.value,onChange:y=>{N.value=String(y)},min:0,description:"Leave empty for unlimited session",placeholder:"Unlimited"}),e(k,{label:"Max Renewals",name:"create-max-renewals",type:"number",value:E.value,onChange:y=>{E.value=String(y)},min:0,description:"0 = unlimited renewals",placeholder:"Unlimited"}),e(k,{label:"Absolute Lifetime (days)",name:"create-lifetime",type:"number",value:G.value,onChange:y=>{G.value=String(y)},min:0,description:"Leave empty for unlimited lifetime",placeholder:"Unlimited"})]})]})]})]}),t.value==="settings"&&e(xr,{})]})}function Lr(t){return t&&Ji[t]||"Native"}const Nn=zt;function Rr({rules:t,onChange:a,errors:n,network:l}){const i=c([]),r=c(!1),s=f=>N=>{a({...t,[f]:N})},o=f=>N=>{const E=Number(N),G={...t};N===""||N===0||Number.isNaN(E)?delete G[f]:G[f]=E,a(G)},u=t.token_limits||{},d=f=>N=>{const E=String(N),I={...u.native||{instant_max:"",notify_max:"",delay_max:""},[f]:E};if(!I.instant_max&&!I.notify_max&&!I.delay_max){const V={...u};delete V.native,a({...t,token_limits:Object.keys(V).length>0?V:void 0})}else a({...t,token_limits:{...u,native:I}})},v=(f,N,E)=>{const I={...u[f]||{instant_max:"0",notify_max:"0",delay_max:"0"},[N]:E};a({...t,token_limits:{...u,[f]:I}})},h=f=>{const N={...u};delete N[f],a({...t,token_limits:Object.keys(N).length>0?N:void 0})},_=f=>{if(!f||u[f])return;const N={instant_max:"0",notify_max:"0",delay_max:"0"};a({...t,token_limits:{...u,[f]:N}})},A=()=>{const f=prompt("Enter CAIP-19 asset ID (e.g., eip155:1/erc20:0xa0b8...)");if(!f||u[f])return;const N={instant_max:"0",notify_max:"0",delay_max:"0"};a({...t,token_limits:{...u,[f]:N}})};X(()=>{if(!l){i.value=[];return}if(!Nn.includes(l)){i.value=[];return}r.value=!0,q(`${D.TOKENS}?network=${l}`).then(f=>{i.value=f.tokens}).catch(()=>{i.value=[]}).finally(()=>{r.value=!1})},[l]);const $=Object.entries(u).filter(([f])=>f!=="native").map(([f,N])=>({assetId:f,symbol:i.value.find(E=>E.assetId===f)?.symbol||f.split("/").pop()?.split(":").pop()||f,instant_max:N.instant_max,notify_max:N.notify_max,delay_max:N.delay_max})),W=Lr(l);return e("div",{class:"policy-form-fields",children:[e("h4",{children:"USD Amount Tiers"}),e("div",{class:"policy-form-grid",children:[e(k,{label:"Instant Max USD",name:"instant_max_usd",type:"number",value:t.instant_max_usd??"",onChange:o("instant_max_usd"),placeholder:"Optional"}),e(k,{label:"Notify Max USD",name:"notify_max_usd",type:"number",value:t.notify_max_usd??"",onChange:o("notify_max_usd"),placeholder:"Optional"}),e(k,{label:"Delay Max USD",name:"delay_max_usd",type:"number",value:t.delay_max_usd??"",onChange:o("delay_max_usd"),placeholder:"Optional"})]}),e("h4",{children:"Token-Specific Limits"}),e("h5",{children:["Native Token (",W,")"]}),e("div",{class:"policy-form-grid",children:[e(k,{label:`Instant Max (${W})`,name:"native_instant_max",value:u.native?.instant_max??"",onChange:d("instant_max"),placeholder:"e.g. 0.5",error:n["token_limits.native.instant_max"]}),e(k,{label:`Notify Max (${W})`,name:"native_notify_max",value:u.native?.notify_max??"",onChange:d("notify_max"),placeholder:"e.g. 0.5",error:n["token_limits.native.notify_max"]}),e(k,{label:`Delay Max (${W})`,name:"native_delay_max",value:u.native?.delay_max??"",onChange:d("delay_max"),placeholder:"e.g. 0.5",error:n["token_limits.native.delay_max"]})]}),e("p",{class:"form-description",children:"Human-readable amounts (e.g., 0.5 SOL, not lamports/wei)"}),e("h5",{style:{marginTop:"1rem"},children:"Custom Token Limits"}),$.map((f,N)=>e("div",{class:"token-limit-row",style:{border:"1px solid var(--border)",borderRadius:"0.5rem",padding:"0.75rem",marginBottom:"0.5rem"},children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.5rem"},children:[e("strong",{children:f.symbol}),e("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:1,marginLeft:"0.5rem",overflow:"hidden",textOverflow:"ellipsis"},children:f.assetId}),e("button",{class:"btn btn-ghost btn-sm",onClick:()=>h(f.assetId),title:"Remove",children:"x"})]}),e("div",{class:"policy-form-grid",children:[e(k,{label:"Instant Max",name:`token-${N}-instant`,value:f.instant_max,onChange:E=>v(f.assetId,"instant_max",String(E)),placeholder:"e.g. 100",error:n[`token_limits.${f.assetId}.instant_max`]}),e(k,{label:"Notify Max",name:`token-${N}-notify`,value:f.notify_max,onChange:E=>v(f.assetId,"notify_max",String(E)),placeholder:"e.g. 500",error:n[`token_limits.${f.assetId}.notify_max`]}),e(k,{label:"Delay Max",name:`token-${N}-delay`,value:f.delay_max,onChange:E=>v(f.assetId,"delay_max",String(E)),placeholder:"e.g. 1000",error:n[`token_limits.${f.assetId}.delay_max`]})]})]},f.assetId)),l&&Nn.includes(l)&&i.value.length>0&&e("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-end",marginTop:"0.5rem"},children:e(k,{label:"Select Token",name:"add-token-select",type:"select",value:"",onChange:f=>_(f),options:[{label:r.value?"Loading...":"-- Select a token --",value:""},...i.value.filter(f=>f.assetId&&!u[f.assetId]).map(f=>({label:`${f.symbol} (${f.name})`,value:f.assetId}))]})}),e("button",{class:"btn btn-secondary btn-sm",style:{marginTop:"0.5rem"},onClick:A,children:"+ Add Token Limit (manual CAIP-19)"}),e("h4",{children:"Cumulative USD Limits (Optional)"}),e("div",{class:"policy-form-grid",children:[e(k,{label:"Daily Limit USD (24h rolling)",name:"daily_limit_usd",type:"number",value:t.daily_limit_usd??"",onChange:o("daily_limit_usd"),placeholder:"e.g. 500",error:n.daily_limit_usd}),e(k,{label:"Monthly Limit USD (30d rolling)",name:"monthly_limit_usd",type:"number",value:t.monthly_limit_usd??"",onChange:o("monthly_limit_usd"),placeholder:"e.g. 5000",error:n.monthly_limit_usd})]}),e("h4",{children:["Legacy Raw Tiers ",e("span",{class:"badge badge-warning",children:"Deprecated"})]}),e("p",{class:"form-description",children:"Raw tiers use lamports/wei units and apply uniformly to all tokens. Use USD Tiers or Token-Specific Limits instead. These fields will be removed in a future version."}),e("div",{class:"policy-form-grid",children:[e(k,{label:"Instant Max (lamports/wei)",name:"instant_max",value:t.instant_max||"",onChange:s("instant_max"),error:n.instant_max}),e(k,{label:"Notify Max (lamports/wei)",name:"notify_max",value:t.notify_max||"",onChange:s("notify_max"),error:n.notify_max}),e(k,{label:"Delay Max (lamports/wei)",name:"delay_max",value:t.delay_max||"",onChange:s("delay_max"),error:n.delay_max})]}),e(k,{label:"Delay Duration (seconds, min 60)",name:"delay_seconds",type:"number",value:t.delay_seconds??900,onChange:s("delay_seconds"),error:n.delay_seconds,required:!0,min:60})]})}function $e({items:t,onAdd:a,onRemove:n,renderRow:l,onChange:i,addLabel:r="+ Add",minItems:s=0,error:o}){return e("div",{class:"dynamic-row-list",children:[t.map((u,d)=>e("div",{class:"dynamic-row",children:[e("div",{class:"dynamic-row-fields",children:l(u,d,i)}),e("button",{class:"btn btn-ghost btn-sm dynamic-row-remove",onClick:()=>n(d),disabled:t.length<=s,title:"Remove",children:"x"})]},d)),e("button",{class:"btn btn-secondary btn-sm",onClick:a,children:r}),o&&e("span",{class:"form-error",children:o})]})}function Or({rules:t,onChange:a,errors:n}){const l=t.allowed_addresses||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,allowed_addresses:[...l,""]}),onRemove:i=>a({...t,allowed_addresses:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,a({...t,allowed_addresses:s})},renderRow:(i,r,s)=>e(k,{label:`Address ${r+1}`,name:`address-${r}`,value:i,onChange:o=>s(r,o),placeholder:"Wallet address",error:n[`allowed_addresses.${r}`],required:!0}),addLabel:"+ Add Address",error:n.allowed_addresses})})}function Pr({rules:t,onChange:a,errors:n}){const l=i=>r=>{a({...t,[i]:r})};return e("div",{class:"policy-form-fields",children:[e(k,{label:"Max Requests",name:"max_requests",type:"number",value:t.max_requests??100,onChange:l("max_requests"),error:n.max_requests,required:!0,min:1}),e(k,{label:"Window (seconds)",name:"window_seconds",type:"number",value:t.window_seconds??3600,onChange:l("window_seconds"),error:n.window_seconds,required:!0,min:1})]})}function Mr({rules:t,onChange:a,errors:n}){const l=i=>{const r={...t};i===""||i===void 0?delete r.maxAmount:r.maxAmount=i,a(r)};return e("div",{class:"policy-form-fields",children:[e(k,{label:"Max Amount (lamports/wei, optional)",name:"maxAmount",value:t.maxAmount??"",onChange:l,error:n.maxAmount,placeholder:"Leave empty for no limit"}),e(k,{label:"Block Unlimited Approvals",name:"blockUnlimited",type:"checkbox",value:t.blockUnlimited??!0,onChange:i=>a({...t,blockUnlimited:i})})]})}const Wr=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function Ur({rules:t,onChange:a,errors:n}){return e("div",{class:"policy-form-fields",children:e(k,{label:"Override Tier",name:"tier",type:"select",value:t.tier??"DELAY",onChange:l=>a({...t,tier:l}),options:Wr,error:n.tier})})}const $r=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function Fr({rules:t,onChange:a,errors:n}){const l=t.tokens||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,tokens:[...l,{address:"",symbol:"",chain:""}]}),onRemove:i=>a({...t,tokens:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,a({...t,tokens:s})},renderRow:(i,r,s)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Address ${r+1}`,name:`token-addr-${r}`,value:i.address,onChange:o=>s(r,{...i,address:o}),placeholder:"Token mint/contract address",error:n[`tokens.${r}.address`],required:!0}),e(k,{label:"Symbol",name:`token-symbol-${r}`,value:i.symbol,onChange:o=>s(r,{...i,symbol:o}),placeholder:"e.g. USDC"}),e(k,{label:"Chain",name:`token-chain-${r}`,type:"select",value:i.chain,onChange:o=>{const u={...i,chain:o};o||delete u.chain,s(r,u)},options:$r})]}),addLabel:"+ Add Token",error:n.tokens})})}const Br=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function zr({rules:t,onChange:a,errors:n}){const l=t.contracts||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,contracts:[...l,{address:"",name:"",chain:""}]}),onRemove:i=>a({...t,contracts:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,a({...t,contracts:s})},renderRow:(i,r,s)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Address ${r+1}`,name:`contract-addr-${r}`,value:i.address,onChange:o=>s(r,{...i,address:o}),placeholder:"Contract address",error:n[`contracts.${r}.address`],required:!0}),e(k,{label:"Name",name:`contract-name-${r}`,value:i.name,onChange:o=>s(r,{...i,name:o}),placeholder:"e.g. Uniswap Router"}),e(k,{label:"Chain",name:`contract-chain-${r}`,type:"select",value:i.chain,onChange:o=>{const u={...i,chain:o};o||delete u.chain,s(r,u)},options:Br})]}),addLabel:"+ Add Contract",error:n.contracts})})}function Hr({rules:t,onChange:a,errors:n}){const l=t.methods||[],i=r=>{a({...t,methods:r})};return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>i([...l,{contractAddress:"",selectors:[""]}]),onRemove:r=>i(l.filter((s,o)=>o!==r)),onChange:(r,s)=>{const o=[...l];o[r]=s,i(o)},renderRow:(r,s,o)=>e("div",{style:{flex:1},children:[e(k,{label:`Contract Address ${s+1}`,name:`method-addr-${s}`,value:r.contractAddress,onChange:u=>o(s,{...r,contractAddress:u}),placeholder:"Contract address",error:n[`methods.${s}.contractAddress`],required:!0}),e("div",{style:{marginTop:"0.5rem",marginLeft:"1rem"},children:[e("label",{style:{fontSize:"0.85rem",fontWeight:500},children:"Selectors"}),e($e,{items:r.selectors,onAdd:()=>o(s,{...r,selectors:[...r.selectors,""]}),onRemove:u=>o(s,{...r,selectors:r.selectors.filter((d,v)=>v!==u)}),onChange:(u,d)=>{const v=[...r.selectors];v[u]=d,o(s,{...r,selectors:v})},renderRow:(u,d,v)=>e(k,{label:`Selector ${d+1}`,name:`method-sel-${s}-${d}`,value:u,onChange:h=>v(d,h),placeholder:"e.g. 0xa9059cbb or transfer(address,uint256)",error:n[`methods.${s}.selectors.${d}`],required:!0}),addLabel:"+ Add Selector",error:n[`methods.${s}.selectors`]})]})]}),addLabel:"+ Add Method Entry",error:n.methods})})}function Kr({rules:t,onChange:a,errors:n}){const l=t.spenders||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,spenders:[...l,{address:"",name:"",maxAmount:""}]}),onRemove:i=>a({...t,spenders:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,r.maxAmount||delete s[i].maxAmount,a({...t,spenders:s})},renderRow:(i,r,s)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Address ${r+1}`,name:`spender-addr-${r}`,value:i.address,onChange:o=>s(r,{...i,address:o}),placeholder:"Spender address",error:n[`spenders.${r}.address`],required:!0}),e(k,{label:"Name",name:`spender-name-${r}`,value:i.name,onChange:o=>s(r,{...i,name:o}),placeholder:"e.g. Uniswap"}),e(k,{label:"Max Amount",name:`spender-max-${r}`,value:i.maxAmount||"",onChange:o=>s(r,{...i,maxAmount:o}),placeholder:"Leave empty for unlimited",error:n[`spenders.${r}.maxAmount`]})]}),addLabel:"+ Add Spender",error:n.spenders})})}const Vr=Array.from({length:24},(t,a)=>({label:`${String(a).padStart(2,"0")}:00`,value:String(a)})),qr=Array.from({length:24},(t,a)=>({label:`${String(a+1).padStart(2,"0")}:00`,value:String(a+1)})),Gr=[{label:"Sun",value:0},{label:"Mon",value:1},{label:"Tue",value:2},{label:"Wed",value:3},{label:"Thu",value:4},{label:"Fri",value:5},{label:"Sat",value:6}];function jr({rules:t,onChange:a,errors:n}){const l=t.allowed_hours||{start:0,end:24},i=t.allowed_days||[],r=o=>u=>{const d={...l,[o]:Number(u)};a({...t,allowed_hours:d})},s=o=>{const u=i.includes(o)?i.filter(d=>d!==o):[...i,o].sort((d,v)=>d-v);a({...t,allowed_days:u})};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Allowed Hours"}),e("div",{class:"policy-form-grid",children:[e(k,{label:"Start Hour",name:"allowed_hours_start",type:"select",value:String(l.start),onChange:r("start"),options:Vr,error:n.allowed_hours}),e(k,{label:"End Hour",name:"allowed_hours_end",type:"select",value:String(l.end),onChange:r("end"),options:qr})]}),e("h4",{children:"Allowed Days"}),e("div",{style:{display:"flex",gap:"0.75rem",flexWrap:"wrap"},children:Gr.map(o=>e("label",{style:{display:"flex",alignItems:"center",gap:"0.25rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:i.includes(o.value),onChange:()=>s(o.value)}),o.label]},o.value))}),n.allowed_days&&e("span",{class:"form-error",children:n.allowed_days})]})}const Yr=[{label:"solana-mainnet",value:"solana-mainnet"},{label:"solana-devnet",value:"solana-devnet"},{label:"solana-testnet",value:"solana-testnet"},{label:"ethereum-mainnet",value:"ethereum-mainnet"},{label:"ethereum-sepolia",value:"ethereum-sepolia"},{label:"polygon-mainnet",value:"polygon-mainnet"},{label:"polygon-amoy",value:"polygon-amoy"},{label:"arbitrum-mainnet",value:"arbitrum-mainnet"},{label:"arbitrum-sepolia",value:"arbitrum-sepolia"},{label:"optimism-mainnet",value:"optimism-mainnet"},{label:"optimism-sepolia",value:"optimism-sepolia"},{label:"base-mainnet",value:"base-mainnet"},{label:"base-sepolia",value:"base-sepolia"}];function Xr({rules:t,onChange:a,errors:n}){const l=t.networks||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,networks:[...l,{network:"solana-mainnet",name:""}]}),onRemove:i=>a({...t,networks:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,a({...t,networks:s})},renderRow:(i,r,s)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Network ${r+1}`,name:`network-sel-${r}`,type:"select",value:i.network,onChange:o=>s(r,{...i,network:o}),options:Yr,error:n[`networks.${r}.network`],required:!0}),e(k,{label:"Label",name:`network-name-${r}`,value:i.name,onChange:o=>s(r,{...i,name:o}),placeholder:"Optional label"})]}),addLabel:"+ Add Network",error:n.networks})})}function Jr({rules:t,onChange:a,errors:n}){const l=t.domains||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,domains:[...l,""]}),onRemove:i=>a({...t,domains:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,a({...t,domains:s})},renderRow:(i,r,s)=>e(k,{label:`Domain ${r+1}`,name:`domain-${r}`,value:i,onChange:o=>s(r,o),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${r}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}function Zr({rules:t,onChange:a,errors:n}){const l=t.domains||[];return e("div",{class:"policy-form-fields",children:e($e,{items:l,onAdd:()=>a({...t,domains:[...l,""]}),onRemove:i=>a({...t,domains:l.filter((r,s)=>s!==i)}),onChange:(i,r)=>{const s=[...l];s[i]=r,a({...t,domains:s})},renderRow:(i,r,s)=>e(k,{label:`Domain ${r+1}`,name:`domain-${r}`,value:i,onChange:o=>s(r,o),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${r}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}const An=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function Qr({rules:t,onChange:a,errors:n}){return e("div",{class:"policy-form-fields",children:[e(k,{label:"Minimum Score",name:"min_score",type:"number",value:t.min_score??50,onChange:l=>a({...t,min_score:Number(l)}),error:n.min_score,min:0,max:100,description:"Minimum reputation score threshold (0-100)"}),e(k,{label:"Below Threshold Tier",name:"below_threshold_tier",type:"select",value:t.below_threshold_tier??"APPROVAL",onChange:l=>a({...t,below_threshold_tier:l}),options:An,error:n.below_threshold_tier,description:"Security tier when counterparty score is below minimum"}),e(k,{label:"Unrated Agent Tier",name:"unrated_tier",type:"select",value:t.unrated_tier??"APPROVAL",onChange:l=>a({...t,unrated_tier:l}),options:An,error:n.unrated_tier,description:"Security tier when counterparty has no reputation data"}),e(k,{label:"Tag1 Filter",name:"tag1",type:"text",value:t.tag1??"",onChange:l=>a({...t,tag1:l}),error:n.tag1,placeholder:"Optional (max 32 chars)"}),e(k,{label:"Tag2 Filter",name:"tag2",type:"text",value:t.tag2??"",onChange:l=>a({...t,tag2:l}),error:n.tag2,placeholder:"Optional (max 32 chars)"}),e(k,{label:"Check Counterparty",name:"check_counterparty",type:"checkbox",value:!!t.check_counterparty,onChange:l=>a({...t,check_counterparty:l}),error:n.check_counterparty,description:"Also evaluate the reputation of the transaction recipient"})]})}function En({type:t,rules:a,onChange:n,errors:l,network:i}){switch(t){case"SPENDING_LIMIT":return e(Rr,{rules:a,onChange:n,errors:l,network:i});case"WHITELIST":return e(Or,{rules:a,onChange:n,errors:l});case"RATE_LIMIT":return e(Pr,{rules:a,onChange:n,errors:l});case"APPROVE_AMOUNT_LIMIT":return e(Mr,{rules:a,onChange:n,errors:l});case"APPROVE_TIER_OVERRIDE":return e(Ur,{rules:a,onChange:n,errors:l});case"ALLOWED_TOKENS":return e(Fr,{rules:a,onChange:n,errors:l});case"CONTRACT_WHITELIST":return e(zr,{rules:a,onChange:n,errors:l});case"METHOD_WHITELIST":return e(Hr,{rules:a,onChange:n,errors:l});case"APPROVED_SPENDERS":return e(Kr,{rules:a,onChange:n,errors:l});case"TIME_RESTRICTION":return e(jr,{rules:a,onChange:n,errors:l});case"ALLOWED_NETWORKS":return e(Xr,{rules:a,onChange:n,errors:l});case"X402_ALLOWED_DOMAINS":return e(Jr,{rules:a,onChange:n,errors:l});case"ERC8128_ALLOWED_DOMAINS":return e(Zr,{rules:a,onChange:n,errors:l});case"REPUTATION_THRESHOLD":return e(Qr,{rules:a,onChange:n,errors:l});default:return e("p",{class:"policy-form-placeholder",children:"This policy type uses JSON editor. Toggle to JSON mode."})}}function Ma(t){const a=typeof t=="string"?Number(t):t;return Number.isNaN(a)?String(t):a.toLocaleString("en-US")}function es(t){return t===86400?"1d":t%86400===0?`${t/86400}d`:t===3600?"1h":t%3600===0?`${t/3600}h`:t===60?"1m":t%60===0?`${t/60}m`:`${t}s`}const Ta=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function ts(t){if(!t||t.length===0)return"";const a=[...t].sort((l,i)=>l-i);let n=!0;for(let l=1;l<a.length;l++)if(a[l]!==a[l-1]+1){n=!1;break}return n&&a.length>2?`${Ta[a[0]]}-${Ta[a[a.length-1]]}`:a.map(l=>Ta[l]??String(l)).join(", ")}function Cn(t){return String(t).padStart(2,"0")}function as({rules:t}){const a=Number(t.instant_max_usd??t.instant_max??0),n=Number(t.notify_max_usd??t.notify_max??0),l=Number(t.delay_max_usd??t.delay_max??0),i=!!(t.instant_max_usd||t.notify_max_usd||t.delay_max_usd),r=Math.max(a,n,l,1),s=[{label:"Instant",value:t.instant_max_usd??t.instant_max,width:a/r*100,cls:"instant"},{label:"Notify",value:t.notify_max_usd??t.notify_max,width:n/r*100,cls:"notify"},{label:"Delay",value:t.delay_max_usd??t.delay_max,width:l/r*100,cls:"delay"},{label:"Approval",value:"",width:100,cls:"approval"}];return e("div",{class:"tier-bars",children:s.map(o=>e("div",{class:"tier-bar",children:[e("span",{class:"tier-bar-label",children:o.label}),e("div",{class:"tier-bar-track",children:e("div",{class:`tier-bar-fill tier-bar-fill--${o.cls}`,style:{width:`${o.width}%`}})}),e("span",{class:"tier-bar-value",children:o.value?`${i?"$":""}${Ma(o.value)}`:""})]},o.cls))})}function In(t){return t.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:2})}function ns({rules:t}){const a=t.daily_limit_usd,n=t.monthly_limit_usd;return!a&&!n?null:e("div",{class:"cumulative-limits",children:[e("div",{class:"cumulative-limits-label",children:"Cumulative Limits"}),a&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Daily (24h)"}),e("span",{class:"cumulative-limit-value",children:["$",In(a)]})]}),n&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Monthly (30d)"}),e("span",{class:"cumulative-limit-value",children:["$",In(n)]})]})]})}const ls={INSTANT:"success",NOTIFY:"info",DELAY:"warning",APPROVAL:"danger"};function is({type:t,rules:a}){switch(t){case"SPENDING_LIMIT":return e("div",{class:"spending-limit-summary",children:[e(as,{rules:a}),e(ns,{rules:a})]});case"ALLOWED_TOKENS":{const n=a.tokens||[];return n.length===0?e("span",{class:"rules-vis-text",children:"No tokens"}):e("div",{class:"rules-vis-badges",children:n.map((l,i)=>e(j,{variant:"info",children:l.symbol||(l.address?l.address.slice(0,8)+"...":"?")},i))})}case"RATE_LIMIT":{const n=a.max_requests,l=a.window_seconds;return e("span",{class:"rules-vis-text",children:[n," req / ",es(l)]})}case"WHITELIST":{const n=a.allowed_addresses||[];return e(j,{variant:"neutral",children:[n.length," addresses"]})}case"TIME_RESTRICTION":{const n=a.allowed_days||[],l=a.allowed_hours,i=ts(n),r=l?`${Cn(l.start)}:00-${Cn(l.end)}:00`:"";return e("span",{class:"rules-vis-text",children:[i," ",r]})}case"CONTRACT_WHITELIST":{const n=a.contracts||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No contracts"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((r,s)=>e(j,{variant:"neutral",children:r.name||(r.address?r.address.slice(0,8)+"...":"?")},s)),i>0&&e(j,{variant:"neutral",children:["+",i," more"]})]})}case"METHOD_WHITELIST":{const n=a.methods||[],l=n.length,i=n.reduce((r,s)=>r+(s.selectors?.length||0),0);return e(j,{variant:"neutral",children:[l," contracts, ",i," methods"]})}case"APPROVED_SPENDERS":{const n=a.spenders||[];return e(j,{variant:"neutral",children:[n.length," spenders"]})}case"APPROVE_AMOUNT_LIMIT":{const n=a.maxAmount,l=a.blockUnlimited;return n&&l?e("span",{class:"rules-vis-text",children:["Max: ",Ma(n)," + Block unlimited"]}):n?e("span",{class:"rules-vis-text",children:["Max: ",Ma(n)]}):l?e("span",{class:"rules-vis-text",children:"Block unlimited only"}):e("span",{class:"rules-vis-text",children:"No limits"})}case"APPROVE_TIER_OVERRIDE":{const n=a.tier||"DELAY",l=ls[n]||"neutral";return e(j,{variant:l,children:n})}case"ALLOWED_NETWORKS":{const n=a.networks||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No networks"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((r,s)=>e(j,{variant:"info",children:r.network},s)),i>0&&e(j,{variant:"info",children:["+",i," more"]})]})}case"X402_ALLOWED_DOMAINS":{const n=a.domains||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No domains"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((r,s)=>e(j,{variant:"neutral",children:r},s)),i>0&&e(j,{variant:"neutral",children:["+",i," more"]})]})}default:{const n=JSON.stringify(a);return e("span",{class:"rules-summary",children:n.length>60?n.slice(0,60)+"...":n})}}}const bl=[{label:"Spending Limit",value:"SPENDING_LIMIT"},{label:"Whitelist",value:"WHITELIST"},{label:"Time Restriction",value:"TIME_RESTRICTION"},{label:"Rate Limit",value:"RATE_LIMIT"},{label:"Allowed Tokens",value:"ALLOWED_TOKENS"},{label:"Contract Whitelist",value:"CONTRACT_WHITELIST"},{label:"Method Whitelist",value:"METHOD_WHITELIST"},{label:"Approved Spenders",value:"APPROVED_SPENDERS"},{label:"Approve Amount Limit",value:"APPROVE_AMOUNT_LIMIT"},{label:"Approve Tier Override",value:"APPROVE_TIER_OVERRIDE"},{label:"Allowed Networks",value:"ALLOWED_NETWORKS"},{label:"x402 Allowed Domains",value:"X402_ALLOWED_DOMAINS"},{label:"ERC-8128 Allowed Domains",value:"ERC8128_ALLOWED_DOMAINS"},{label:"Reputation Threshold",value:"REPUTATION_THRESHOLD"}],ka={SPENDING_LIMIT:"Set per-transaction and cumulative spending limits by security tier (instant, notify, delay, approval).",WHITELIST:"Allow transfers only to pre-approved recipient addresses.",TIME_RESTRICTION:"Restrict transactions to specific time windows or days of the week.",RATE_LIMIT:"Limit the maximum number of transactions within a time window.",ALLOWED_TOKENS:"Allow only specified tokens for transfers; all others are denied.",CONTRACT_WHITELIST:"Allow contract calls only to pre-approved contract addresses.",METHOD_WHITELIST:"Allow only specific contract methods (function selectors) to be called.",APPROVED_SPENDERS:"Allow token approvals only for pre-approved spender addresses.",APPROVE_AMOUNT_LIMIT:"Set maximum token approval amounts and optionally block unlimited approvals.",APPROVE_TIER_OVERRIDE:"Force a specific security tier for all token approval transactions.",ALLOWED_NETWORKS:"Restrict transactions to specific blockchain networks only.",X402_ALLOWED_DOMAINS:"Allow x402 payments only to pre-approved domains.",ERC8128_ALLOWED_DOMAINS:"Allow ERC-8128 HTTP message signing only for pre-approved API domains.",REPUTATION_THRESHOLD:"Adjust security tier based on counterparty agent on-chain reputation score (ERC-8004)."},Nt={SPENDING_LIMIT:{instant_max_usd:"10",notify_max_usd:"100",delay_max_usd:"1000",delay_seconds:300,approval_timeout:3600},WHITELIST:{allowed_addresses:[]},TIME_RESTRICTION:{allowed_hours:{start:0,end:24},allowed_days:[0,1,2,3,4,5,6]},RATE_LIMIT:{max_requests:100,window_seconds:3600},ALLOWED_TOKENS:{tokens:[]},CONTRACT_WHITELIST:{contracts:[]},METHOD_WHITELIST:{methods:[]},APPROVED_SPENDERS:{spenders:[]},APPROVE_AMOUNT_LIMIT:{maxAmount:"1000000",blockUnlimited:!0},APPROVE_TIER_OVERRIDE:{tier:"DELAY"},ALLOWED_NETWORKS:{networks:[]},X402_ALLOWED_DOMAINS:{domains:[]},ERC8128_ALLOWED_DOMAINS:{domains:[]},REPUTATION_THRESHOLD:{min_score:50,below_threshold_tier:"APPROVAL",unrated_tier:"APPROVAL",check_counterparty:!1}};function Xt(t,a){const n={};if(t==="SPENDING_LIMIT"){a.instant_max&&!/^\d+$/.test(a.instant_max)&&(n.instant_max="Positive integer required"),a.notify_max&&!/^\d+$/.test(a.notify_max)&&(n.notify_max="Positive integer required"),a.delay_max&&!/^\d+$/.test(a.delay_max)&&(n.delay_max="Positive integer required");const l=!!(a.instant_max||a.notify_max||a.delay_max),i=!!(a.instant_max_usd||a.notify_max_usd||a.delay_max_usd),r=a.token_limits,s=r&&Object.keys(r).length>0;if(!l&&!i&&!s&&(n.__form="At least one of USD limits, token limits, or raw limits required"),r){const v=/^\d+(\.\d+)?$/;for(const[h,_]of Object.entries(r)){const A=_;if(!A||typeof A!="object")continue;A.instant_max&&!v.test(A.instant_max)&&(n[`token_limits.${h}.instant_max`]="Must be a non-negative decimal"),A.notify_max&&!v.test(A.notify_max)&&(n[`token_limits.${h}.notify_max`]="Must be a non-negative decimal"),A.delay_max&&!v.test(A.delay_max)&&(n[`token_limits.${h}.delay_max`]="Must be a non-negative decimal");const $=parseFloat(A.instant_max||"0"),W=parseFloat(A.notify_max||"0"),f=parseFloat(A.delay_max||"0");$>W&&(n[`token_limits.${h}.instant_max`]="Must be <= Notify Max"),W>f&&(n[`token_limits.${h}.notify_max`]="Must be <= Delay Max")}}const o=Number(a.delay_seconds);(a.delay_seconds===void 0||a.delay_seconds===""||Number.isNaN(o)||o<60)&&(n.delay_seconds="Minimum 60 seconds");const u=a.daily_limit_usd;if(u!==void 0&&u!==""){const v=Number(u);(Number.isNaN(v)||v<=0)&&(n.daily_limit_usd="Must be a positive number")}const d=a.monthly_limit_usd;if(d!==void 0&&d!==""){const v=Number(d);(Number.isNaN(v)||v<=0)&&(n.monthly_limit_usd="Must be a positive number")}}else if(t==="WHITELIST"){const l=a.allowed_addresses||[];l.length===0&&(n.allowed_addresses="At least one address required"),l.forEach((i,r)=>{(!i||i.trim()==="")&&(n[`allowed_addresses.${r}`]="Address required")})}else if(t==="RATE_LIMIT"){const l=Number(a.max_requests);(!a.max_requests||Number.isNaN(l)||l<1||!Number.isInteger(l))&&(n.max_requests="Positive integer required");const i=Number(a.window_seconds);(!a.window_seconds||Number.isNaN(i)||i<1||!Number.isInteger(i))&&(n.window_seconds="Positive integer required")}else if(t==="APPROVE_AMOUNT_LIMIT")a.maxAmount&&!/^\d+$/.test(a.maxAmount)&&(n.maxAmount="Must be a positive integer string");else if(t==="ALLOWED_TOKENS"){const l=a.tokens||[];l.length===0&&(n.tokens="At least one token required"),l.forEach((i,r)=>{(!i.address||i.address.trim()==="")&&(n[`tokens.${r}.address`]="Address required")})}else if(t==="CONTRACT_WHITELIST"){const l=a.contracts||[];l.length===0&&(n.contracts="At least one contract required"),l.forEach((i,r)=>{(!i.address||i.address.trim()==="")&&(n[`contracts.${r}.address`]="Address required")})}else if(t==="METHOD_WHITELIST"){const l=a.methods||[];l.length===0&&(n.methods="At least one method entry required"),l.forEach((i,r)=>{(!i.contractAddress||i.contractAddress.trim()==="")&&(n[`methods.${r}.contractAddress`]="Contract address required"),!i.selectors||i.selectors.length===0?n[`methods.${r}.selectors`]="At least one selector required":i.selectors.forEach((s,o)=>{(!s||s.trim()==="")&&(n[`methods.${r}.selectors.${o}`]="Selector required")})})}else if(t==="APPROVED_SPENDERS"){const l=a.spenders||[];l.length===0&&(n.spenders="At least one spender required"),l.forEach((i,r)=>{(!i.address||i.address.trim()==="")&&(n[`spenders.${r}.address`]="Address required"),i.maxAmount&&!/^\d+$/.test(i.maxAmount)&&(n[`spenders.${r}.maxAmount`]="Must be a positive integer")})}else if(t==="TIME_RESTRICTION"){(a.allowed_days||[]).length===0&&(n.allowed_days="At least one day required");const i=a.allowed_hours;i&&i.start>=i.end&&(n.allowed_hours="Start must be before end")}else if(t==="ALLOWED_NETWORKS"){const l=a.networks||[];l.length===0&&(n.networks="At least one network required"),l.forEach((i,r)=>{(!i.network||i.network.trim()==="")&&(n[`networks.${r}.network`]="Network required")})}else if(t==="X402_ALLOWED_DOMAINS"){const l=a.domains||[];l.length===0&&(n.domains="At least one domain required"),l.forEach((i,r)=>{(!i||i.trim()==="")&&(n[`domains.${r}`]="Domain required")})}return n}function rs(t,a){if(!t)return"Global";const n=a.find(l=>l.id===t);return n?n.name:t.slice(0,8)+"..."}function Na(t){const a=bl.find(n=>n.value===t);return a?a.label:t}const xn=[{key:"policies",label:"Policies"},{key:"defaults",label:"Defaults"}],Aa=["security.policy_defaults_delay_seconds","security.policy_defaults_approval_timeout","policy.default_deny_tokens","policy.default_deny_contracts","policy.default_deny_spenders","policy.default_deny_x402_domains","policy.default_deny_erc8128_domains"];function ss(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const d=await q(D.ADMIN_SETTINGS);t.value=d}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{l.value=!1}};X(()=>{i()},[]);const r=(d,v)=>{const h=String(v);a.value={...a.value,[d]:h}},s=async()=>{n.value=!0;try{const d=Object.entries(a.value).filter(([h])=>Aa.includes(h)).map(([h,_])=>({key:h,value:_})),v=await oe(D.ADMIN_SETTINGS,{settings:d});t.value=v.settings,a.value={},m("success","Policy defaults saved and applied")}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{n.value=!1}},o=()=>{a.value={}};X(()=>(Be({id:"policies-defaults",isDirty:()=>Object.keys(a.value).filter(d=>Aa.includes(d)).length>0,save:s,discard:o}),()=>Re("policies-defaults")),[]);const u=Object.keys(a.value).filter(d=>Aa.includes(d)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[u>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[u," unsaved change",u>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:s,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Policy Defaults"}),e("p",{class:"settings-description",children:"Configure default delay, approval timeout, and default-deny policies. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("policy_defaults_delay_seconds"),name:"security.policy_defaults_delay_seconds",type:"number",value:Number(pe(t.value,a.value,"security","policy_defaults_delay_seconds"))||0,onChange:d=>r("security.policy_defaults_delay_seconds",d),min:0,description:"Default delay before executing delayed-tier transactions"}),e(k,{label:ie("policy_defaults_approval_timeout"),name:"security.policy_defaults_approval_timeout",type:"number",value:Number(pe(t.value,a.value,"security","policy_defaults_approval_timeout"))||0,onChange:d=>r("security.policy_defaults_approval_timeout",d),min:60,description:"How long to wait for owner approval before timeout"})]}),e("div",{class:"settings-subgroup",style:{marginTop:"1rem",borderTop:"1px solid var(--border)",paddingTop:"1rem"},children:[e("h4",{style:{margin:"0 0 0.5rem 0",fontSize:"0.875rem",fontWeight:600,color:"var(--text-secondary)"},children:"Default Deny Policies"}),e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("default_deny_tokens"),name:"policy.default_deny_tokens",type:"checkbox",value:We(t.value,a.value,"policy","default_deny_tokens"),onChange:d=>r("policy.default_deny_tokens",d),description:"Deny token transfers unless a matching whitelist policy exists"}),e(k,{label:ie("default_deny_contracts"),name:"policy.default_deny_contracts",type:"checkbox",value:We(t.value,a.value,"policy","default_deny_contracts"),onChange:d=>r("policy.default_deny_contracts",d),description:"Deny contract calls unless a matching whitelist policy exists"}),e(k,{label:ie("default_deny_spenders"),name:"policy.default_deny_spenders",type:"checkbox",value:We(t.value,a.value,"policy","default_deny_spenders"),onChange:d=>r("policy.default_deny_spenders",d),description:"Deny token approvals unless a matching whitelist policy exists"}),e(k,{label:ie("default_deny_x402_domains"),name:"policy.default_deny_x402_domains",type:"checkbox",value:We(t.value,a.value,"policy","default_deny_x402_domains"),onChange:d=>r("policy.default_deny_x402_domains",d),description:"Deny x402 payments unless a matching domain whitelist policy exists"}),e(k,{label:ie("default_deny_erc8128_domains"),name:"policy.default_deny_erc8128_domains",type:"checkbox",value:We(t.value,a.value,"policy","default_deny_erc8128_domains"),onChange:d=>r("policy.default_deny_erc8128_domains",d),description:"Deny ERC-8128 signing unless a matching domain whitelist policy exists"})]})]}),e("div",{class:"settings-info-box",children:"When enabled, transactions are denied if no matching whitelist policy exists. Disable to allow all transactions of that type when no policy is configured."})]})]})]})}function os(){const t=c("policies");X(()=>{const M=me.value;M&&M.tab&&(t.value=M.tab,setTimeout(()=>{xe.value=M.fieldName},100),me.value=null)},[me.value]);const a=c([]),n=c([]),l=c("__all__"),i=c(!1),r=c(!0),s=c(!1),o=c("SPENDING_LIMIT"),u=c(""),d=c(JSON.stringify(Nt.SPENDING_LIMIT,null,2)),v=c(Nt.SPENDING_LIMIT),h=c({}),_=c(!1),A=c(0),$=c(!0),W=c(""),f=c(null),N=c(!1),E=c(!1),G=c(null),I=c(""),V=c({}),C=c(!1),x=c({}),w=c(0),R=c(!0),K=c(null),y=c(!1),p=c(!1),T=c(null),H=c(!1),Y=async()=>{try{const M=await q(D.WALLETS);a.value=M.items}catch(M){const ee=M instanceof b?M:new b(0,"UNKNOWN","Unknown error");m("error",z(ee.code))}finally{r.value=!1}},ae=async()=>{i.value=!0;try{let M=D.POLICIES;l.value!=="__all__"&&l.value!=="__global__"&&(M=`${D.POLICIES}?walletId=${l.value}`);const ee=await q(M);l.value==="__global__"?n.value=ee.filter(ve=>ve.walletId===null):n.value=ee}catch(M){const ee=M instanceof b?M:new b(0,"UNKNOWN","Unknown error");m("error",z(ee.code))}finally{i.value=!1}},ce=async()=>{f.value=null;let M;if(_.value)try{M=JSON.parse(d.value)}catch{f.value="Invalid JSON in rules field";return}else{const ee=Xt(o.value,v.value);if(Object.keys(ee).length>0){h.value=ee;return}h.value={},M=v.value}N.value=!0;try{await he(D.POLICIES,{walletId:u.value||void 0,type:o.value,rules:M,priority:A.value,enabled:$.value,network:W.value||void 0}),m("success","Policy created"),s.value=!1,o.value="SPENDING_LIMIT",u.value="",W.value="",d.value=JSON.stringify(Nt.SPENDING_LIMIT,null,2),v.value=Nt.SPENDING_LIMIT,h.value={},_.value=!1,A.value=0,$.value=!0,f.value=null,await ae()}catch(ee){const ve=ee instanceof b?ee:new b(0,"UNKNOWN","Unknown error");m("error",z(ve.code))}finally{N.value=!1}},F=M=>{G.value=M,I.value=JSON.stringify(M.rules,null,2),V.value={...M.rules},C.value=!1,x.value={},w.value=M.priority,R.value=M.enabled,K.value=null,E.value=!0},O=async()=>{K.value=null;let M;if(C.value)try{M=JSON.parse(I.value)}catch{K.value="Invalid JSON in rules field";return}else{const ee=Xt(G.value.type,V.value);if(Object.keys(ee).length>0){x.value=ee;return}x.value={},M=V.value}y.value=!0;try{await oe(D.POLICY(G.value.id),{rules:M,priority:w.value,enabled:R.value}),m("success","Policy updated"),E.value=!1,await ae()}catch(ee){const ve=ee instanceof b?ee:new b(0,"UNKNOWN","Unknown error");m("error",z(ve.code))}finally{y.value=!1}},Q=()=>{if(!C.value)I.value=JSON.stringify(V.value,null,2);else try{V.value=JSON.parse(I.value),K.value=null}catch{K.value="Invalid JSON — cannot switch to form mode";return}C.value=!C.value},J=M=>{T.value=M,p.value=!0},be=async()=>{H.value=!0;try{await Le(D.POLICY(T.value.id)),m("success","Policy deleted"),p.value=!1,await ae()}catch(M){const ee=M instanceof b?M:new b(0,"UNKNOWN","Unknown error");m("error",z(ee.code))}finally{H.value=!1}},Ae=M=>{const ee=M;o.value=ee;const ve=Nt[ee];ve&&(d.value=JSON.stringify(ve,null,2),v.value={...ve}),h.value={},_.value=!1},L=()=>{if(!_.value)d.value=JSON.stringify(v.value,null,2);else try{v.value=JSON.parse(d.value),f.value=null}catch{f.value="Invalid JSON — cannot switch to form mode";return}_.value=!_.value};X(()=>{Y()},[]),X(()=>{ae()},[l.value]);const le=[{key:"type",header:"Type",render:M=>e(j,{variant:M.type==="SPENDING_LIMIT"?"success":"info",children:Na(M.type)})},{key:"walletId",header:"Wallet",render:M=>rs(M.walletId,a.value)},{key:"network",header:"Network",render:M=>M.network??"All"},{key:"rules",header:"Rules",render:M=>e(is,{type:M.type,rules:M.rules})},{key:"priority",header:"Priority"},{key:"enabled",header:"Enabled",render:M=>e(j,{variant:M.enabled?"success":"danger",children:M.enabled?"ON":"OFF"})},{key:"actions",header:"Actions",render:M=>e("span",{style:{display:"flex",gap:"0.25rem"},children:[e("button",{class:"btn btn-ghost btn-sm",onClick:ee=>{ee.stopPropagation(),F(M)},children:"Edit"}),e(P,{size:"sm",variant:"danger",onClick:()=>J(M),children:"Delete"})]})}];return e("div",{class:"page",children:[e(wt,{pageName:"Policies",tabName:xn.find(M=>M.key===t.value)?.label??"",onPageClick:()=>{t.value="policies"}}),e(at,{tabs:xn,activeTab:t.value,onTabChange:M=>{t.value=M}}),t.value==="policies"&&e(te,{children:[e("div",{class:"policy-controls",children:[e("div",{class:"policy-filter-select",children:[e("label",{for:"policy-wallet-filter",children:"Filter by Wallet"}),e("select",{id:"policy-wallet-filter",value:l.value,onChange:M=>{l.value=M.target.value},disabled:r.value,children:[e("option",{value:"__all__",children:"All Policies"}),e("option",{value:"__global__",children:"Global Only"}),a.value.map(M=>e("option",{value:M.id,children:[M.name," (",M.chain,"/",M.network,")"]},M.id))]})]}),!s.value&&e(P,{onClick:()=>{s.value=!0},children:"Create Policy"})]}),s.value&&e("div",{class:"inline-form",children:[e(k,{label:"Type",name:"type",type:"select",value:o.value,onChange:Ae,options:bl,description:ka[o.value]??""}),e(k,{label:"Wallet",name:"walletId",type:"select",value:u.value,onChange:M=>{u.value=M},options:[{label:"Global (no wallet)",value:""},...a.value.map(M=>({label:`${M.name} (${M.chain}/${M.network})`,value:M.id}))]}),e(k,{label:"Network Scope",name:"network",value:W.value,onChange:M=>{W.value=M},placeholder:"e.g. polygon-mainnet (leave empty for all networks)"}),e("div",{class:"policy-form-section",children:[e("div",{class:"policy-form-header",children:[e("label",{children:"Rules"}),e("button",{class:"btn btn-ghost btn-sm json-toggle",onClick:L,children:_.value?"Switch to Form":"JSON Direct Edit"})]}),_.value?e(k,{label:"",name:"rules",type:"textarea",value:d.value,onChange:M=>{d.value=M},error:f.value??void 0}):e(En,{type:o.value,rules:v.value,onChange:M=>{v.value=M,Object.keys(h.value).length>0&&(h.value=Xt(o.value,M))},errors:h.value,network:W.value})]}),e(k,{label:"Priority",name:"priority",type:"number",value:A.value,onChange:M=>{A.value=M},min:0,max:999}),e(k,{label:"Enabled",name:"enabled",type:"checkbox",value:$.value,onChange:M=>{$.value=M}}),e("div",{class:"inline-form-actions",children:[e(P,{onClick:ce,loading:N.value,children:"Create"}),e(P,{variant:"secondary",onClick:()=>{s.value=!1,f.value=null},children:"Cancel"})]})]}),e(De,{columns:le,data:n.value,loading:i.value,emptyMessage:"No policies found"}),e(Se,{open:E.value,title:"Edit Policy",onCancel:()=>{E.value=!1},onConfirm:O,confirmText:"Save",loading:y.value,children:G.value&&e("div",{children:[e("div",{class:"policy-type-readonly",children:["Type: ",Na(G.value.type),ka[G.value.type]&&e("span",{class:"form-description",children:ka[G.value.type]})]}),e("div",{class:"policy-form-section",children:[e("div",{class:"policy-form-header",children:[e("label",{children:"Rules"}),e("button",{class:"btn btn-ghost btn-sm json-toggle",onClick:Q,children:C.value?"Switch to Form":"JSON Direct Edit"})]}),C.value?e("div",{class:"edit-rules-textarea",children:e(k,{label:"",name:"edit-rules",type:"textarea",value:I.value,onChange:M=>{I.value=M},error:K.value??void 0})}):e(En,{type:G.value.type,rules:V.value,onChange:M=>{V.value=M,Object.keys(x.value).length>0&&(x.value=Xt(G.value.type,M))},errors:x.value,network:G.value.network??""})]}),e(k,{label:"Priority",name:"edit-priority",type:"number",value:w.value,onChange:M=>{w.value=M},min:0,max:999}),e(k,{label:"Enabled",name:"edit-enabled",type:"checkbox",value:R.value,onChange:M=>{R.value=M}})]})}),e(Se,{open:p.value,title:"Delete Policy",onCancel:()=>{p.value=!1},onConfirm:be,confirmText:"Delete",confirmVariant:"danger",loading:H.value,children:T.value&&e("p",{children:["Are you sure you want to delete this"," ",e("strong",{children:Na(T.value.type)})," policy? This action cannot be undone."]})})]}),t.value==="defaults"&&e(ss,{})]})}function cs(){return e(ds,{})}function ds(){const t=c([]),a=c(!0),n=c(!1),l=c(null),i=c("ADMIN"),r=c(!1),s=c(!1),o=c(null),u=c(!1),d=async()=>{a.value=!0;try{const f=await q(D.ADMIN_TELEGRAM_USERS);t.value=f.users}catch(f){const N=f instanceof b?f:new b(0,"UNKNOWN","Unknown error");m("error",z(N.code))}finally{a.value=!1}};X(()=>{d()},[]);const v=f=>{l.value=f,i.value="ADMIN",n.value=!0},h=async()=>{if(l.value){r.value=!0;try{await oe(D.ADMIN_TELEGRAM_USER(l.value.chat_id),{role:i.value}),m("success",`User approved as ${i.value}`),n.value=!1,l.value=null,await d()}catch(f){const N=f instanceof b?f:new b(0,"UNKNOWN","Unknown error");m("error",z(N.code))}finally{r.value=!1}}},_=f=>{o.value=f,s.value=!0},A=async()=>{if(o.value){u.value=!0;try{await Le(D.ADMIN_TELEGRAM_USER(o.value.chat_id)),m("success","User deleted"),s.value=!1,o.value=null,await d()}catch(f){const N=f instanceof b?f:new b(0,"UNKNOWN","Unknown error");m("error",z(N.code))}finally{u.value=!1}}},$=f=>f==="PENDING"?"warning":f==="ADMIN"?"success":"info";return e("div",{class:"page",children:[e(De,{columns:[{key:"chat_id",header:"Chat ID",render:f=>String(f.chat_id)},{key:"username",header:"Username",render:f=>f.username??"-"},{key:"role",header:"Role",render:f=>e(j,{variant:$(f.role),children:f.role})},{key:"registered_at",header:"Registered",render:f=>_e(f.registered_at)},{key:"approved_at",header:"Approved",render:f=>f.approved_at?_e(f.approved_at):"-"},{key:"actions",header:"Actions",render:f=>e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[f.role==="PENDING"&&e(P,{size:"sm",variant:"primary",onClick:()=>v(f),children:"Approve"}),e(P,{size:"sm",variant:"danger",onClick:()=>_(f),children:"Delete"})]})}],data:t.value,loading:a.value,emptyMessage:"No Telegram users registered. Users appear here after sending /start to the bot."}),e(Se,{open:n.value,title:"Approve Telegram User",onCancel:()=>{n.value=!1,l.value=null},onConfirm:h,confirmText:"Approve",confirmVariant:"primary",loading:r.value,children:l.value&&e("div",{children:[e("p",{children:[e("strong",{children:"Chat ID:"})," ",l.value.chat_id,l.value.username&&e("span",{children:[" (",e("strong",{children:["@",l.value.username]}),")"]})]}),e("div",{class:"form-field",style:{marginTop:"var(--space-3)"},children:[e("label",{for:"approve-role",children:"Role"}),e("select",{id:"approve-role",value:i.value,onChange:f=>{i.value=f.target.value},children:[e("option",{value:"ADMIN",children:"ADMIN"}),e("option",{value:"READONLY",children:"READONLY"})]})]})]})}),e(Se,{open:s.value,title:"Delete Telegram User",onCancel:()=>{s.value=!1,o.value=null},onConfirm:A,confirmText:"Delete",confirmVariant:"danger",loading:u.value,children:e("p",{children:"Are you sure you want to remove this user? They will need to /start again to re-register."})})]})}const Ea=20,Dn=[{key:"channels",label:"Channels & Logs"},{key:"telegram",label:"Telegram Users"},{key:"settings",label:"Settings"},{key:"balance",label:"Balance Monitor"}],us=[{key:"eventType",label:"Event Type",type:"select",options:[{value:"tx.submitted",label:"tx.submitted"},{value:"tx.confirmed",label:"tx.confirmed"},{value:"tx.failed",label:"tx.failed"},{value:"policy.violation",label:"policy.violation"},{value:"security.kill_switch",label:"security.kill_switch"},{value:"security.auto_stop",label:"security.auto_stop"},{value:"security.suspicious_tx",label:"security.suspicious_tx"},{value:"session.created",label:"session.created"},{value:"session.expired",label:"session.expired"},{value:"owner.registered",label:"owner.registered"},{value:"owner.verified",label:"owner.verified"},{value:"incoming.detected",label:"incoming.detected"},{value:"incoming.suspicious",label:"incoming.suspicious"}]},{key:"channel",label:"Channel",type:"select",options:[{value:"telegram",label:"Telegram"},{value:"discord",label:"Discord"},{value:"ntfy",label:"ntfy"},{value:"slack",label:"Slack"},{value:"wallet_app",label:"Wallet App"}]},{key:"status",label:"Status",type:"select",options:[{value:"sent",label:"Sent"},{value:"failed",label:"Failed"}]},{key:"since",label:"Since",type:"date"},{key:"until",label:"Until",type:"date"}];function vs(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=c([]),r=c(!1),s=async()=>{try{const _=await q(D.ADMIN_SETTINGS);t.value=_}catch(_){const A=_ instanceof b?_:new b(0,"UNKNOWN","Unknown error");m("error",z(A.code))}finally{l.value=!1}};X(()=>{s()},[]);const o=(_,A)=>{const $=String(A);a.value={...a.value,[_]:$}},u=async()=>{n.value=!0;try{const _=Object.entries(a.value).filter(([$])=>$.startsWith("notifications.")||$.startsWith("telegram.")).map(([$,W])=>({key:$,value:W})),A=await oe(D.ADMIN_SETTINGS,{settings:_});t.value=A.settings,a.value={},m("success","Notification settings saved and applied")}catch(_){const A=_ instanceof b?_:new b(0,"UNKNOWN","Unknown error");m("error",z(A.code))}finally{n.value=!1}},d=()=>{a.value={}};X(()=>(Be({id:"notifications-settings",isDirty:()=>Object.keys(a.value).filter(_=>_.startsWith("notifications.")||_.startsWith("telegram.")).length>0,save:u,discard:d}),()=>Re("notifications-settings")),[]);const v=async()=>{r.value=!0,i.value=[];try{const _=await he(D.ADMIN_NOTIFICATIONS_TEST,{});if(i.value=_.results,_.results.length===0)m("info","No notification channels configured");else{const A=_.results.every($=>$.success);m(A?"success":"warning",A?"All test notifications sent":"Some channels failed")}}catch(_){const A=_ instanceof b?_:new b(0,"UNKNOWN","Unknown error");m("error",z(A.code))}finally{r.value=!1}},h=Object.keys(a.value).filter(_=>_.startsWith("notifications.")||_.startsWith("telegram.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[h>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[h," unsaved change",h>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:d,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:u,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Notification Configuration"}),e("p",{class:"settings-description",children:"Configure notification channels for transaction alerts. Changes apply immediately via hot-reload."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",style:{marginBottom:"var(--space-4)"},children:[e("div",{class:"settings-field-full",children:e(k,{label:"Enabled",name:"notifications.enabled",type:"checkbox",value:We(t.value,a.value,"notifications","enabled"),onChange:_=>o("notifications.enabled",_),description:"Enable or disable notifications globally"})}),e(k,{label:ie("locale"),name:"notifications.locale",type:"select",value:pe(t.value,a.value,"notifications","locale")||"en",onChange:_=>o("notifications.locale",_),options:[{label:"English",value:"en"},{label:"Korean",value:"ko"}],description:"Language for notification messages"})]}),e(Qe,{legend:"Telegram",description:"Telegram notification channel and bot configuration",children:[e("div",{class:"settings-info-box",style:{marginBottom:"0.75rem"},children:["Get your bot token from"," ",e("a",{href:"https://t.me/BotFather",target:"_blank",rel:"noopener noreferrer",children:"@BotFather"})," ","— send /newbot and follow the instructions. To get your Chat ID, send a message to your bot then visit"," ",e("a",{href:"https://api.telegram.org",target:"_blank",rel:"noopener noreferrer",children:"Telegram Bot API"}),"."]}),e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("telegram_bot_token"),name:"notifications.telegram_bot_token",type:"password",value:pe(t.value,a.value,"notifications","telegram_bot_token"),onChange:_=>o("notifications.telegram_bot_token",_),placeholder:It(t.value,a.value,"notifications","telegram_bot_token")?"(configured)":"",description:"Bot token for Telegram notifications"}),e(k,{label:ie("telegram_chat_id"),name:"notifications.telegram_chat_id",type:"text",value:pe(t.value,a.value,"notifications","telegram_chat_id"),onChange:_=>o("notifications.telegram_chat_id",_),description:"Chat ID for Telegram notification delivery"})]}),e("div",{class:"settings-subgroup",style:{marginTop:"0.75rem",borderTop:"1px solid var(--border)",paddingTop:"0.75rem"},children:[e("div",{class:"settings-subgroup-title",children:"Telegram Bot"}),e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("bot_token"),name:"telegram.bot_token",type:"password",value:pe(t.value,a.value,"telegram","bot_token"),onChange:_=>o("telegram.bot_token",_),placeholder:It(t.value,a.value,"telegram","bot_token")?"(configured)":"Leave empty to use notification token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)"}),e(k,{label:"Locale",name:"telegram.locale",type:"select",value:pe(t.value,a.value,"telegram","locale")||"en",onChange:_=>o("telegram.locale",_),options:[{label:"English",value:"en"},{label:"한국어",value:"ko"}],description:"Language for Telegram bot messages"})]})]})]}),e(Qe,{legend:"ntfy",description:"Push notification channel for Human Wallet Apps (signing requests and activity alerts)",children:[e("div",{class:"settings-info-box",style:{marginBottom:"0.75rem"},children:["ntfy is the push notification infrastructure used by Human Wallet Apps for signing requests and activity alerts. Per-wallet ntfy topics (sign topic, notify topic) are managed in"," ",e("a",{href:"#/wallet-apps",children:"Human Wallet Apps"}),". The server URL below is shared across all wallet apps."]}),e("div",{class:"settings-fields-grid",children:e(k,{label:ie("ntfy_server"),name:"notifications.ntfy_server",type:"text",value:pe(t.value,a.value,"notifications","ntfy_server"),onChange:_=>o("notifications.ntfy_server",_),description:"Server URL for ntfy push notifications"})})]}),e(Qe,{legend:"Other Channels",description:"Discord, Slack, and rate limiting",children:[e("div",{class:"settings-info-box",style:{marginBottom:"0.75rem"},children:[e("strong",{children:"Discord:"})," Create a webhook in Server Settings > Integrations >"," ",e("a",{href:"https://support.discord.com/hc/en-us/articles/228383668",target:"_blank",rel:"noopener noreferrer",children:"Webhooks"}),"."," ",e("strong",{children:"Slack:"})," Create an"," ",e("a",{href:"https://api.slack.com/messaging/webhooks",target:"_blank",rel:"noopener noreferrer",children:"Incoming Webhook"})," in your Slack workspace."]}),e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("discord_webhook_url"),name:"notifications.discord_webhook_url",type:"password",value:pe(t.value,a.value,"notifications","discord_webhook_url"),onChange:_=>o("notifications.discord_webhook_url",_),placeholder:It(t.value,a.value,"notifications","discord_webhook_url")?"(configured)":"",description:"Webhook URL for Discord notifications"}),e(k,{label:"Slack Webhook URL",name:"notifications.slack_webhook_url",type:"password",value:pe(t.value,a.value,"notifications","slack_webhook_url"),onChange:_=>o("notifications.slack_webhook_url",_),placeholder:It(t.value,a.value,"notifications","slack_webhook_url")?"(configured)":"",description:"Webhook URL for Slack notifications"}),e(k,{label:ie("rate_limit_rpm"),name:"notifications.rate_limit_rpm",type:"number",value:Number(pe(t.value,a.value,"notifications","rate_limit_rpm"))||20,onChange:_=>o("notifications.rate_limit_rpm",_),min:1,max:1e3,description:"Max notifications per minute"})]})]}),e(Qe,{legend:"Event Filter",description:"Choose which notification events are delivered. All checked = receive all.",children:[(()=>{const _=new Set(["KILL_SWITCH_ACTIVATED","KILL_SWITCH_RECOVERED","AUTO_STOP_TRIGGERED","TX_INCOMING_SUSPICIOUS"]),A=[{category:"transaction",label:"Transaction Events",events:[{event:"TX_REQUESTED",desc:"Transaction request received"},{event:"TX_QUEUED",desc:"Waiting in time-delay queue"},{event:"TX_SUBMITTED",desc:"Submitted to blockchain"},{event:"TX_CONFIRMED",desc:"Confirmed on-chain"},{event:"TX_FAILED",desc:"Transaction failed"},{event:"TX_CANCELLED",desc:"Cancelled by user or policy"},{event:"TX_DOWNGRADED_DELAY",desc:"Auto-approved demoted to time-delay"},{event:"TX_APPROVAL_REQUIRED",desc:"Owner approval required"},{event:"TX_APPROVAL_EXPIRED",desc:"Approval wait timed out"},{event:"TX_INCOMING",desc:"Incoming transaction detected"}]},{category:"policy",label:"Policy",events:[{event:"POLICY_VIOLATION",desc:"Blocked by policy rule"},{event:"CUMULATIVE_LIMIT_WARNING",desc:"Cumulative spend limit warning"}]},{category:"security_alert",label:"Security Alerts",events:[{event:"WALLET_SUSPENDED",desc:"Wallet suspended"},{event:"KILL_SWITCH_ACTIVATED",desc:"Emergency lock activated"},{event:"KILL_SWITCH_RECOVERED",desc:"Emergency lock released"},{event:"KILL_SWITCH_ESCALATED",desc:"Kill switch escalated"},{event:"AUTO_STOP_TRIGGERED",desc:"Auto-stop triggered"},{event:"TX_INCOMING_SUSPICIOUS",desc:"Suspicious incoming transaction"}]},{category:"session",label:"Session Events",events:[{event:"SESSION_EXPIRING_SOON",desc:"Session expiring soon"},{event:"SESSION_EXPIRED",desc:"Session expired"},{event:"SESSION_CREATED",desc:"Session created"},{event:"SESSION_WALLET_ADDED",desc:"Wallet added to session"},{event:"SESSION_WALLET_REMOVED",desc:"Wallet removed from session"}]},{category:"owner",label:"Owner Events",events:[{event:"OWNER_SET",desc:"Owner address registered"},{event:"OWNER_REMOVED",desc:"Owner address removed"},{event:"OWNER_VERIFIED",desc:"Owner address verified"}]},{category:"system",label:"System Notifications",events:[{event:"DAILY_SUMMARY",desc:"Daily summary report"},{event:"LOW_BALANCE",desc:"Low balance warning"},{event:"APPROVAL_CHANNEL_SWITCHED",desc:"Approval channel changed"},{event:"UPDATE_AVAILABLE",desc:"Daemon update available"}]}],$=A.flatMap(I=>I.events.map(V=>V.event)).filter(I=>!_.has(I)),W=pe(t.value,a.value,"notifications","notify_events")||"[]";let f=[];try{const I=JSON.parse(W);Array.isArray(I)&&(f=I)}catch{}const N=f.length===0?$:f,E=(I,V)=>{const C=V?[...N,I]:N.filter(w=>w!==I),x=C.length===$.length&&$.every(w=>C.includes(w))?[]:C;o("notifications.notify_events",JSON.stringify(x))},G=(I,V)=>{const C=I.events.filter(R=>!_.has(R.event)).map(R=>R.event);let x;if(V)x=[...new Set([...N,...C])];else{const R=new Set(C);x=N.filter(K=>!R.has(K))}const w=x.length===$.length&&$.every(R=>x.includes(R))?[]:x;o("notifications.notify_events",JSON.stringify(w))};return e("div",{class:"event-filter-groups",children:A.map(I=>{const V=I.events.filter(w=>!_.has(w.event)),C=V.every(w=>N.includes(w.event)),x=V.some(w=>N.includes(w.event));return e("details",{class:"event-filter-group",open:!0,children:[e("summary",{class:"event-filter-group-header",children:[e("span",{class:"event-filter-group-label",children:I.label}),e("label",{class:"event-filter-group-all",onClick:w=>w.stopPropagation(),children:[e("input",{type:"checkbox",checked:C,ref:w=>{w&&(w.indeterminate=x&&!C)},onChange:w=>G(I,w.target.checked)})," All"]})]}),e("div",{class:"event-filter-events",children:I.events.map(w=>{const R=_.has(w.event);return e("label",{class:`event-filter-event ${R?"event-broadcast":""}`,children:[e("input",{type:"checkbox",checked:R||N.includes(w.event),disabled:R,onChange:K=>E(w.event,K.target.checked)}),e("code",{children:w.event}),e("span",{class:"event-desc",children:w.desc}),R&&e("span",{class:"event-broadcast-badge",children:"Always sent"})]},w.event)})})]},I.category)})})})(),e("div",{class:"settings-info-box",style:{marginTop:"0.5rem"},children:"Applies to all notification channels (Telegram, Discord, ntfy, Slack) and wallet app side channel. Broadcast events (Kill Switch, Auto Stop, Suspicious TX) always bypass the filter."})]}),e("div",{class:"notif-test-section",children:[e(P,{variant:"secondary",size:"sm",onClick:v,loading:r.value,children:"Test Notification"}),i.value.length>0&&e("div",{class:"test-results",children:i.value.map(_=>e("div",{class:`test-result-item ${_.success?"test-result-success":"test-result-failure"}`,children:[e(j,{variant:_.success?"success":"danger",children:_.success?"OK":"FAIL"}),e("span",{children:_.channel}),_.error&&e("span",{style:"font-size: var(--font-size-xs); color: var(--color-danger);",children:[" - ",_.error]})]},_.channel))})]})]})]})]})}const Ln={enabled:"Enable or disable balance monitoring",check_interval_sec:"How often to check wallet balances",low_balance_threshold_sol:"Alert when SOL balance drops below this amount",low_balance_threshold_eth:"Alert when ETH balance drops below this amount",cooldown_hours:"Suppress duplicate alerts for this many hours"};function hs(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const v=await q(D.ADMIN_SETTINGS);t.value=v}catch(v){const h=v instanceof b?v:new b(0,"UNKNOWN","Unknown error");m("error",z(h.code))}finally{l.value=!1}};X(()=>{i()},[]);const r=(v,h)=>{const _=String(h);a.value={...a.value,[v]:_}},s=async()=>{n.value=!0;try{const v=Object.entries(a.value).filter(([_])=>_.startsWith("monitoring.")).map(([_,A])=>({key:_,value:A})),h=await oe(D.ADMIN_SETTINGS,{settings:v});t.value=h.settings,a.value={},m("success","Settings saved and applied")}catch(v){const h=v instanceof b?v:new b(0,"UNKNOWN","Unknown error");m("error",z(h.code))}finally{n.value=!1}},o=()=>{a.value={}};X(()=>(Be({id:"notifications-balance",isDirty:()=>Object.keys(a.value).filter(v=>v.startsWith("monitoring.")).length>0,save:s,discard:o}),()=>Re("notifications-balance")),[]);const u=[{key:"enabled",type:"checkbox"},{key:"check_interval_sec",type:"number",min:60,max:86400},{key:"low_balance_threshold_sol",type:"number",min:0},{key:"low_balance_threshold_eth",type:"number",min:0},{key:"cooldown_hours",type:"number",min:1,max:168}],d=Object.keys(a.value).filter(v=>v.startsWith("monitoring.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[d>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[d," unsaved change",d>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:s,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Balance Monitoring"}),e("p",{class:"settings-description",children:"Periodic balance checks for all active wallets. Sends LOW_BALANCE alerts when native token balance drops below thresholds. Changes apply immediately."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:u.map(v=>v.type==="checkbox"?e("div",{class:"settings-field-full",children:e(k,{label:ie(v.key),name:`monitoring.${v.key}`,type:"checkbox",value:We(t.value,a.value,"monitoring",v.key),onChange:h=>r(`monitoring.${v.key}`,h),description:Ln[v.key]})},v.key):e(k,{label:ie(v.key),name:`monitoring.${v.key}`,type:"number",value:Number(pe(t.value,a.value,"monitoring",v.key))||0,onChange:h=>r(`monitoring.${v.key}`,h),min:v.min,max:v.max,description:Ln[v.key]},v.key))}),e("div",{class:"settings-info-box",children:"Monitors all active wallet native token balances (SOL, ETH) at the configured interval. When balance drops below threshold, a LOW_BALANCE notification is sent. Duplicate alerts are suppressed for the cooldown period (per wallet)."})]})]})]})}function Rn(){const t=c("channels");X(()=>{const x=me.value;x&&x.tab&&(t.value=x.tab,setTimeout(()=>{xe.value=x.fieldName},100),me.value=null)},[me.value]);const a=c(null),n=c(!0),l=c(!1),i=c(null),r=c(null),s=c(null),o=c(!0),u=c(1),d=c(null),v=c({eventType:"",channel:"",status:"",since:"",until:""}),h=async()=>{try{const x=await q(D.ADMIN_NOTIFICATIONS_STATUS);a.value=x}catch(x){const w=x instanceof b?x:new b(0,"UNKNOWN","Unknown error");m("error",z(w.code))}finally{n.value=!1}},_=async x=>{o.value=!0;try{const w=new URLSearchParams;w.set("page",String(x)),w.set("pageSize",String(Ea));const R=v.value;if(R.eventType&&w.set("eventType",R.eventType),R.channel&&w.set("channel",R.channel),R.status&&w.set("status",R.status),R.since){const y=new Date(R.since);isNaN(y.getTime())||w.set("since",String(Math.floor(y.getTime()/1e3)))}if(R.until){const y=new Date(R.until);isNaN(y.getTime())||(y.setHours(23,59,59,999),w.set("until",String(Math.floor(y.getTime()/1e3))))}const K=await q(`${D.ADMIN_NOTIFICATIONS_LOG}?${w.toString()}`);s.value=K}catch(w){const R=w instanceof b?w:new b(0,"UNKNOWN","Unknown error");m("error",z(R.code))}finally{o.value=!1}},A=async()=>{l.value=!0,r.value=null;try{const w=(await he(D.ADMIN_NOTIFICATIONS_TEST,{})).results;r.value=w,w.every(K=>K.success)?m("success","Test sent successfully"):m("warning","Some channels failed")}catch(x){const w=x instanceof b?x:new b(0,"UNKNOWN","Unknown error");m("error",z(w.code))}finally{l.value=!1}},$=async x=>{i.value=x,r.value=null;try{const R=(await he(D.ADMIN_NOTIFICATIONS_TEST,{channel:x})).results;r.value=R,R.every(y=>y.success)?m("success",`Test sent to ${x}`):m("warning",`${x} test failed`)}catch(w){const R=w instanceof b?w:new b(0,"UNKNOWN","Unknown error");m("error",z(R.code))}finally{i.value=null}},W=()=>{u.value>1&&(u.value-=1,_(u.value))},f=()=>{const x=s.value?Math.ceil(s.value.total/Ea):1;u.value<x&&(u.value+=1,_(u.value))},N=x=>{d.value=d.value?.id===x.id?null:x},E=x=>{v.value=x,u.value=1,_(1)};X(()=>{h(),_(1);const x=setInterval(()=>_(u.value),3e4);return()=>clearInterval(x)},[]);const G=n.value&&!a.value,I=a.value?.channels.some(x=>x.enabled)??!1,V=s.value?Math.max(1,Math.ceil(s.value.total/Ea)):1,C=[{key:"eventType",header:"Event Type"},{key:"walletId",header:"Wallet ID",render:x=>x.walletId?e("a",{href:`#/wallets/${x.walletId}`,class:"wallet-link",onClick:w=>w.stopPropagation(),title:x.walletId,children:[x.walletId.slice(0,8),"..."]}):"—"},{key:"channel",header:"Channel",render:x=>e("span",{style:{textTransform:"capitalize"},children:x.channel})},{key:"status",header:"Status",render:x=>e(j,{variant:x.status==="sent"?"success":"danger",children:x.status})},{key:"createdAt",header:"Time",render:x=>_e(x.createdAt)}];return e("div",{class:"page",children:[e(wt,{pageName:"Notifications",tabName:Dn.find(x=>x.key===t.value)?.label??"",onPageClick:()=>{t.value="channels"}}),e(at,{tabs:Dn,activeTab:t.value,onTabChange:x=>{t.value=x}}),t.value==="telegram"?e(cs,{}):t.value==="settings"?e(vs,{}):t.value==="balance"?e(hs,{}):e(te,{children:[e("h2",{children:"Channel Status"}),a.value&&!a.value.enabled&&e("div",{class:"notif-disabled-banner",children:["Notifications are disabled."," ",e("a",{href:"#",onClick:x=>{x.preventDefault(),t.value="settings"},children:"Enable them in the Settings tab"})]}),G?e("div",{class:"channel-grid",children:[1,2,3].map(x=>e("div",{class:"channel-card",children:e("div",{class:"stat-skeleton"})},x))}):e("div",{class:"channel-grid",children:a.value?.channels.map(x=>e("div",{class:"channel-card",children:e("div",{class:"channel-card-header",children:[e("span",{class:"channel-card-name",children:x.name}),e("div",{class:"channel-card-actions",children:[e(j,{variant:x.enabled?"success":"neutral",children:x.enabled?x.configuredWallets!=null?`${x.configuredWallets} wallet${x.configuredWallets!==1?"s":""} configured`:"Connected":"Not Configured"}),x.enabled&&e(P,{variant:"secondary",size:"sm",onClick:()=>$(x.name),loading:i.value===x.name,children:"Test"})]})]})},x.name))}),e("div",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-6)"},children:[e(P,{onClick:A,loading:l.value,disabled:!I,children:"Test All Channels"}),r.value&&e("div",{class:"test-results",children:r.value.map(x=>e("div",{class:"test-result-item",children:[e("span",{class:x.success?"test-result-success":"test-result-failure",children:x.success?"✓":"✗"}),e("span",{style:{textTransform:"capitalize"},children:x.channel}),!x.success&&x.error&&e("span",{class:"test-result-failure",children:[" - ",x.error]})]},x.channel))})]}),e("h2",{children:"Delivery Log"}),e(Bt,{fields:us,values:v.value,onChange:E,syncUrl:!1}),e(De,{columns:C,data:s.value?.logs??[],loading:o.value,emptyMessage:"No notification logs",onRowClick:N}),d.value&&e("div",{class:"log-message-detail",children:[e("div",{class:"log-message-detail-header",children:[e("strong",{children:d.value.eventType})," via ",e("span",{style:{textTransform:"capitalize"},children:d.value.channel}),e(P,{variant:"ghost",size:"sm",onClick:()=>{d.value=null},children:"Close"})]}),e("div",{class:"log-message-detail-body",children:d.value.message?e("pre",{style:{whiteSpace:"pre-wrap",margin:0,fontSize:"var(--font-size-sm)"},children:d.value.message}):e("span",{class:"text-muted",children:"(No message recorded)"})})]}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Page ",u.value," of ",V,s.value?` (${s.value.total} total)`:""]}),e("div",{class:"pagination-buttons",children:[e(P,{variant:"secondary",size:"sm",onClick:W,disabled:u.value<=1,children:"Previous"}),e(P,{variant:"secondary",size:"sm",onClick:f,disabled:u.value>=V,children:"Next"})]})]}),e("div",{class:"config-guidance",children:e("p",{children:"Configure notification channels in the Settings tab above. Changes are applied immediately via hot-reload."})})]})]})}const Ca=[{key:"killswitch",label:"Kill Switch"},{key:"autostop",label:"AutoStop Rules"},{key:"jwt",label:"Invalidate Sessions"},{key:"password",label:"Master Password"}];function ps(){const t=c(null),a=c(!0),n=c(!1),l=async()=>{try{const h=await q(D.ADMIN_KILL_SWITCH);t.value=h}catch(h){const _=h instanceof b?h:new b(0,"UNKNOWN","Unknown error");m("error",z(_.code))}finally{a.value=!1}};X(()=>{l()},[]);const i=async()=>{n.value=!0;try{await he(D.ADMIN_KILL_SWITCH),m("success","Kill switch activated - all operations suspended"),await l()}catch(h){const _=h instanceof b?h:new b(0,"UNKNOWN","Unknown error");m("error",z(_.code))}finally{n.value=!1}},r=async()=>{n.value=!0;try{await he(D.ADMIN_KILL_SWITCH_ESCALATE),m("success","Kill switch escalated to LOCKED"),await l()}catch(h){const _=h instanceof b?h:new b(0,"UNKNOWN","Unknown error");m("error",z(_.code))}finally{n.value=!1}},s=async()=>{n.value=!0;try{await he(D.ADMIN_RECOVER),m("success","Kill switch recovered - operations resumed"),await l()}catch(h){const _=h instanceof b?h:new b(0,"UNKNOWN","Unknown error");m("error",z(_.code))}finally{n.value=!1}},o=t.value,u=o?.state==="ACTIVE",d=o?.state==="SUSPENDED",v=o?.state==="LOCKED";return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Kill Switch"}),e("p",{class:"settings-description",children:"Emergency stop - suspends all wallet operations immediately. 3-state: ACTIVE (normal) → SUSPENDED (paused) → LOCKED (permanent)."})]}),e("div",{class:"settings-category-body",children:a.value?e("span",{children:"Loading..."}):o?e(te,{children:[e("div",{class:"ks-state-card",style:{marginBottom:"var(--space-4)"},children:[e(j,{variant:u?"success":v?"danger":"warning",children:o.state}),!u&&o.activatedAt&&e("span",{class:"ks-state-info",children:["Since ",_e(o.activatedAt),o.activatedBy?` by ${o.activatedBy}`:""]})]}),e("div",{style:{display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},children:[u&&e(P,{variant:"danger",onClick:i,loading:n.value,children:"Activate Kill Switch"}),d&&e(te,{children:[e(P,{variant:"primary",onClick:s,loading:n.value,children:"Recover"}),e(P,{variant:"danger",onClick:r,loading:n.value,children:"Escalate to LOCKED"})]}),v&&e(P,{variant:"primary",onClick:s,loading:n.value,children:"Recover from LOCKED (5s wait)"})]}),d&&e("div",{class:"settings-info-box",style:{marginTop:"var(--space-3)"},children:"All wallet operations are suspended. Sessions revoked, transactions cancelled. You can Recover to resume operations, or Escalate to LOCKED for permanent lockdown."}),v&&e("div",{class:"settings-info-box",style:{marginTop:"var(--space-3)",borderColor:"var(--color-danger)"},children:"System is permanently locked. Recovery requires dual-auth (Owner signature + Master password) and has a mandatory 5-second wait period."})]}):null})]})}function ms(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const d=await q(D.ADMIN_SETTINGS);t.value=d}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{l.value=!1}};X(()=>{i()},[]);const r=(d,v)=>{const h=String(v);a.value={...a.value,[d]:h}},s=async()=>{n.value=!0;try{const d=Object.entries(a.value).filter(([h])=>h.startsWith("autostop.")).map(([h,_])=>({key:h,value:_})),v=await oe(D.ADMIN_SETTINGS,{settings:d});t.value=v.settings,a.value={},m("success","AutoStop settings saved and applied")}catch(d){const v=d instanceof b?d:new b(0,"UNKNOWN","Unknown error");m("error",z(v.code))}finally{n.value=!1}},o=()=>{a.value={}};X(()=>(Be({id:"security-autostop",isDirty:()=>Object.keys(a.value).filter(d=>d.startsWith("autostop.")).length>0,save:s,discard:o}),()=>Re("security-autostop")),[]);const u=Object.keys(a.value).filter(d=>d.startsWith("autostop.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[u>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[u," unsaved change",u>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:s,loading:n.value,children:"Save"})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"AutoStop Rules"}),e("p",{class:"settings-description",children:"Automatic protection rules that suspend wallets or trigger Kill Switch on anomalies. Changes apply immediately without daemon restart."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-field-full",style:{marginBottom:"var(--space-4)"},children:e(k,{label:ie("enabled"),name:"autostop.enabled",type:"checkbox",value:We(t.value,a.value,"autostop","enabled"),onChange:d=>r("autostop.enabled",d),description:"Enable or disable AutoStop protection rules"})}),e(Qe,{legend:"Activity Detection",description:"Detects failures and unusual transaction patterns",children:e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("consecutive_failures_threshold"),name:"autostop.consecutive_failures_threshold",type:"number",value:Number(pe(t.value,a.value,"autostop","consecutive_failures_threshold"))||0,onChange:d=>r("autostop.consecutive_failures_threshold",d),min:1,max:100,description:"Suspend wallet after this many consecutive failed transactions"}),e(k,{label:ie("unusual_activity_threshold"),name:"autostop.unusual_activity_threshold",type:"number",value:Number(pe(t.value,a.value,"autostop","unusual_activity_threshold"))||0,onChange:d=>r("autostop.unusual_activity_threshold",d),min:5,max:1e3,description:"Max transactions within window before triggering unusual activity alert"}),e(k,{label:ie("unusual_activity_window_sec"),name:"autostop.unusual_activity_window_sec",type:"number",value:Number(pe(t.value,a.value,"autostop","unusual_activity_window_sec"))||0,onChange:d=>r("autostop.unusual_activity_window_sec",d),min:60,max:86400,description:"Time window for unusual activity detection"})]})}),e(Qe,{legend:"Idle Detection",description:"Monitors inactivity and revokes idle sessions",children:e("div",{class:"settings-fields-grid",children:[e(k,{label:ie("idle_timeout_sec"),name:"autostop.idle_timeout_sec",type:"number",value:Number(pe(t.value,a.value,"autostop","idle_timeout_sec"))||0,onChange:d=>r("autostop.idle_timeout_sec",d),min:60,max:604800,description:"Revoke sessions with no activity for this duration"}),e(k,{label:ie("idle_check_interval_sec"),name:"autostop.idle_check_interval_sec",type:"number",value:Number(pe(t.value,a.value,"autostop","idle_check_interval_sec"))||0,onChange:d=>r("autostop.idle_check_interval_sec",d),min:10,max:3600,description:"How often to check for idle sessions"})]})}),e("div",{class:"settings-info-box",children:[e("strong",{children:"Consecutive Failures:"})," Suspends wallet after N consecutive failed transactions.",e("br",{}),e("strong",{children:"Unusual Activity:"})," Suspends wallet if transaction count exceeds threshold within the time window.",e("br",{}),e("strong",{children:"Idle Timeout:"})," Revokes sessions with no activity for the configured duration."]})]})]})]})}function fs(){const t=c(!1),a=c(!1),n=async()=>{a.value=!0;try{await he(D.ADMIN_ROTATE_SECRET),t.value=!1,m("success","All session tokens invalidated. Old tokens remain valid for 5 minutes.")}catch(l){const i=l instanceof b?l:new b(0,"UNKNOWN","Unknown error");m("error",z(i.code))}finally{a.value=!1}};return e(te,{children:[e("div",{class:"settings-section",children:[e("div",{class:"settings-section-header",children:[e("h3",{children:"Invalidate All Session Tokens"}),e("p",{class:"settings-description",children:"Revoke all active session tokens by rotating the signing key. Existing tokens remain valid for 5 minutes, then all wallets must create new sessions."})]}),e("div",{class:"settings-section-body",children:e(P,{variant:"secondary",onClick:()=>{t.value=!0},children:"Invalidate All Tokens"})})]}),e(Se,{open:t.value,title:"Invalidate All Session Tokens",onCancel:()=>{t.value=!1},onConfirm:n,confirmText:"Invalidate",confirmVariant:"primary",loading:a.value,children:e("p",{children:"This will rotate the signing key and invalidate all active session tokens after 5 minutes. Every wallet will need to create a new session to continue API access. Use this when a token may have been compromised."})})]})}function gs(){const t=c(""),a=c(""),n=c(""),l=c(!1),i=c(null),r=()=>a.value.length<8?(i.value="New password must be at least 8 characters.",!1):a.value!==n.value?(i.value="New password and confirmation do not match.",!1):(i.value=null,!0),s=async()=>{if(r()){l.value=!0;try{await oe(D.ADMIN_MASTER_PASSWORD,{newPassword:a.value}),m("success","Master password changed. Please log in again."),t.value="",a.value="",n.value="",setTimeout(()=>fa(),500)}catch(o){const u=o instanceof b?o:new b(0,"UNKNOWN","Unknown error");m("error",z(u.code))}finally{l.value=!1}}};return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Change Master Password"}),e("p",{class:"settings-description",children:"Update the master password used to authenticate with the Admin UI. You will be logged out after a successful change."})]}),e("div",{class:"settings-category-body",children:[i.value&&e("div",{class:"settings-info-box",style:{borderColor:"var(--color-danger)",color:"var(--color-danger)",marginBottom:"var(--space-3)"},children:i.value}),e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)",maxWidth:"400px"},children:[e(k,{label:"Current Password",name:"current-password",type:"password",value:t.value,onChange:o=>{t.value=String(o)}}),e(k,{label:"New Password",name:"new-password",type:"password",value:a.value,onChange:o=>{a.value=String(o)},description:"Minimum 8 characters"}),e(k,{label:"Confirm New Password",name:"confirm-password",type:"password",value:n.value,onChange:o=>{n.value=String(o)}}),e("div",{children:e(P,{variant:"primary",onClick:s,loading:l.value,disabled:!t.value||!a.value||!n.value,children:"Change Password"})})]})]})]})}function ys(){const t=(()=>{const l=location.hash,i=l.indexOf("?");if(i>=0){const s=new URLSearchParams(l.slice(i+1)).get("tab");if(s&&Ca.some(o=>o.key===s))return s}return"killswitch"})(),a=c(t);X(()=>{const l=me.value;l&&l.tab&&(a.value=l.tab,setTimeout(()=>{xe.value=l.fieldName},100),me.value=null)},[me.value]);const n=Ca.find(l=>l.key===a.value)?.label??"";return e("div",{class:"page",children:[e(wt,{pageName:"Security",tabName:n,onPageClick:()=>{a.value="killswitch"}}),e(at,{tabs:Ca,activeTab:a.value,onTabChange:l=>{a.value=l}}),a.value==="killswitch"&&e(ps,{}),a.value==="autostop"&&e(ms,{}),a.value==="jwt"&&e(fs,{}),a.value==="password"&&e(gs,{})]})}const Jt=[{code:"USD",name:"US Dollar",symbol:"$"},{code:"KRW",name:"Korean Won",symbol:"₩"},{code:"JPY",name:"Japanese Yen",symbol:"¥"},{code:"EUR",name:"Euro",symbol:"€"},{code:"GBP",name:"British Pound",symbol:"£"},{code:"CNY",name:"Chinese Yuan",symbol:"¥"},{code:"CAD",name:"Canadian Dollar",symbol:"CA$"},{code:"AUD",name:"Australian Dollar",symbol:"A$"},{code:"CHF",name:"Swiss Franc",symbol:"CHF"},{code:"SGD",name:"Singapore Dollar",symbol:"S$"},{code:"HKD",name:"Hong Kong Dollar",symbol:"HK$"},{code:"INR",name:"Indian Rupee",symbol:"₹"},{code:"TWD",name:"Taiwan Dollar",symbol:"NT$"},{code:"THB",name:"Thai Baht",symbol:"฿"},{code:"MYR",name:"Malaysian Ringgit",symbol:"RM"},{code:"IDR",name:"Indonesian Rupiah",symbol:"Rp"},{code:"PHP",name:"Philippine Peso",symbol:"₱"},{code:"VND",name:"Vietnamese Dong",symbol:"₫"},{code:"BRL",name:"Brazilian Real",symbol:"R$"},{code:"MXN",name:"Mexican Peso",symbol:"MX$"},{code:"CLP",name:"Chilean Peso",symbol:"CL$"},{code:"TRY",name:"Turkish Lira",symbol:"₺"},{code:"PLN",name:"Polish Zloty",symbol:"zł"},{code:"CZK",name:"Czech Koruna",symbol:"Kč"},{code:"HUF",name:"Hungarian Forint",symbol:"Ft"},{code:"SEK",name:"Swedish Krona",symbol:"kr"},{code:"NOK",name:"Norwegian Krone",symbol:"kr"},{code:"DKK",name:"Danish Krone",symbol:"kr"},{code:"NZD",name:"New Zealand Dollar",symbol:"NZ$"},{code:"ZAR",name:"South African Rand",symbol:"R"},{code:"ILS",name:"Israeli Shekel",symbol:"₪"},{code:"SAR",name:"Saudi Riyal",symbol:"SR"},{code:"AED",name:"UAE Dirham",symbol:"AED"},{code:"KWD",name:"Kuwaiti Dinar",symbol:"KD"},{code:"BHD",name:"Bahraini Dinar",symbol:"BD"},{code:"NGN",name:"Nigerian Naira",symbol:"₦"},{code:"RUB",name:"Russian Ruble",symbol:"₽"},{code:"UAH",name:"Ukrainian Hryvnia",symbol:"₴"},{code:"PKR",name:"Pakistani Rupee",symbol:"Rs"},{code:"BDT",name:"Bangladeshi Taka",symbol:"৳"},{code:"LKR",name:"Sri Lankan Rupee",symbol:"Rs"},{code:"MMK",name:"Myanmar Kyat",symbol:"K"},{code:"GEL",name:"Georgian Lari",symbol:"₾"}];function _s({value:t,onChange:a,name:n}){const l=c(""),i=c(!1),r=c(null),s=c(!1),o=Fe(null),u=ma(()=>{const v=l.value.toLowerCase();return v?Jt.filter(h=>h.code.toLowerCase().includes(v)||h.name.toLowerCase().includes(v)||h.symbol.includes(v)):Jt});X(()=>{if(t==="USD"){r.value="1 USD = $1.00";return}s.value=!0,q(`${D.ADMIN_FOREX_RATES}?currencies=${t}`).then(v=>{const h=v.rates[t];r.value=h?.preview??null}).catch(()=>{r.value=null}).finally(()=>{s.value=!1})},[t]),X(()=>{const v=h=>{o.current&&!o.current.contains(h.target)&&(i.value=!1,l.value="")};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const d=Jt.find(v=>v.code===t)??Jt[0];return e("div",{class:"currency-select",ref:o,children:[n&&e("input",{type:"hidden",name:n,value:t}),e("button",{type:"button",class:"currency-select-trigger",onClick:()=>{i.value=!i.value},children:[e("span",{class:"currency-select-value",children:[d.code," - ",d.name," (",d.symbol,")"]}),e("span",{class:"currency-select-chevron",children:i.value?"▲":"▼"})]}),r.value&&e("div",{class:"currency-rate-preview",children:s.value?"...":r.value}),i.value&&e("div",{class:"currency-select-dropdown",children:[e("input",{type:"text",class:"currency-select-search",placeholder:"Search currency...",value:l.value,onInput:v=>{l.value=v.target.value},autoFocus:!0}),e("div",{class:"currency-select-list",children:[u.value.map(v=>e("button",{type:"button",class:`currency-select-option ${v.code===t?"currency-select-option--active":""}`,onClick:()=>{a(v.code),i.value=!1,l.value=""},children:[e("span",{class:"currency-option-code",children:v.code}),e("span",{class:"currency-option-name",children:v.name}),e("span",{class:"currency-option-symbol",children:v.symbol})]},v.code)),u.value.length===0&&e("div",{class:"currency-select-empty",children:"No currencies found"})]})]})]})}const bs=["display.","daemon.","oracle.","gas_condition.","smart_account.","erc8128.","actions.nft_indexer_"],ws=new Set(["security.rate_limit_global_ip_rpm"]);function Ia(t){return bs.some(a=>t.startsWith(a))||ws.has(t)}function Ss(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=c([]),r=c(!0),s=c(null),o=c(""),u=c(!1),d=c(!1),v=c(!1),h=c(""),_=c(!1),A=async()=>{try{const F=await q(D.ADMIN_SETTINGS);t.value=F}catch(F){const O=F instanceof b?F:new b(0,"UNKNOWN","Unknown error");m("error",z(O.code))}finally{l.value=!1}},$=async()=>{try{const F=await q(D.ADMIN_API_KEYS);i.value=F.keys}catch{}finally{r.value=!1}};X(()=>{A(),$()},[]),X(()=>{const F=me.value;F&&(setTimeout(()=>{xe.value=F.fieldName},100),me.value=null)},[me.value]);const W=(F,O)=>pe(t.value,a.value,F,O),f=(F,O)=>We(t.value,a.value,F,O),N=(F,O)=>It(t.value,a.value,F,O),E=(F,O)=>{const Q=String(O);a.value={...a.value,[F]:Q}},G=async()=>{n.value=!0;try{const F=Object.entries(a.value).filter(([Q])=>Ia(Q)).map(([Q,J])=>({key:Q,value:J})),O=await oe(D.ADMIN_SETTINGS,{settings:F});t.value=O.settings,a.value={},m("success","Settings saved and applied")}catch(F){const O=F instanceof b?F:new b(0,"UNKNOWN","Unknown error");m("error",z(O.code))}finally{n.value=!1}},I=()=>{a.value={}};X(()=>(Be({id:"system-settings",isDirty:()=>Object.keys(a.value).filter(F=>Ia(F)).length>0,save:G,discard:I}),()=>Re("system-settings")),[]);const V=async F=>{u.value=!0;try{await oe(D.ADMIN_API_KEY(F),{apiKey:o.value}),m("success",`API key saved for ${F}`),s.value=null,o.value="",await $()}catch(O){const Q=O instanceof b?O:new b(0,"UNKNOWN","Unknown error");m("error",z(Q.code))}finally{u.value=!1}},C=async F=>{try{await Le(D.ADMIN_API_KEY(F)),m("success",`API key deleted for ${F}`),await $()}catch(O){const Q=O instanceof b?O:new b(0,"UNKNOWN","Unknown error");m("error",z(Q.code))}},x=async()=>{v.value=!0;try{await he(D.ADMIN_SHUTDOWN),d.value=!1,h.value="",m("info","Shutdown initiated"),_.value=!0}catch(F){const O=F instanceof b?F:new b(0,"UNKNOWN","Unknown error");m("error",z(O.code))}finally{v.value=!1}},w=Object.keys(a.value).filter(F=>Ia(F)).length,R={alchemy_nft:{label:"Alchemy NFT",description:"EVM NFT indexing (ERC-721, ERC-1155)"},helius:{label:"Helius",description:"Solana NFT indexing (Metaplex)"}};function K(){const F=i.value.filter(J=>J.providerName in R),Q=Object.keys(R).map(J=>F.find(Ae=>Ae.providerName===J)??{providerName:J,hasKey:!1,maskedKey:""});return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"NFT Indexer"}),e("p",{class:"settings-description",children:"Configure API keys for NFT indexing (required for NFT query operations)"})]}),e("div",{class:"settings-category-body",children:[Q.map(J=>{const be=R[J.providerName];return e("div",{class:"settings-field-row",children:[e("div",{class:"settings-field-label",children:[e("span",{children:be.label}),e("span",{style:{fontSize:"0.8em",color:"var(--color-text-secondary)"},children:be.description}),J.hasKey?e(j,{variant:"success",children:"Configured"}):e(j,{variant:"neutral",children:"Not configured"})]}),e("div",{class:"settings-field-value",children:s.value===J.providerName?e("div",{class:"api-key-edit-row",children:[e(k,{label:"API Key",type:"password",name:`nft-apikey-${J.providerName}`,value:o.value,onChange:Ae=>{o.value=String(Ae)},placeholder:"Enter API key"}),e(P,{onClick:()=>V(J.providerName),loading:u.value,size:"sm",children:"Save"}),e(P,{variant:"ghost",onClick:()=>{s.value=null,o.value=""},size:"sm",children:"Cancel"})]}):e("div",{class:"api-key-display-row",children:[e("span",{class:"api-key-masked",children:J.hasKey?J.maskedKey:"Not set"}),e(P,{variant:"ghost",onClick:()=>{s.value=J.providerName,o.value=""},size:"sm",children:J.hasKey?"Change":"Set"}),J.hasKey&&e(P,{variant:"danger",onClick:()=>C(J.providerName),size:"sm",children:"Delete"})]})})]},J.providerName)}),e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginTop:"var(--space-3)"},children:e(k,{label:"Cache TTL (seconds)",name:"actions.nft_indexer_cache_ttl_sec",type:"number",value:Number(W("actions","nft_indexer_cache_ttl_sec"))||300,onChange:J=>E("actions.nft_indexer_cache_ttl_sec",J),min:0,max:86400,description:"How long to cache NFT metadata and listings (seconds). Default: 300 (5 min)."})}),e("div",{class:"settings-info-box",children:"NFT indexer API keys enable NFT query operations. Alchemy is used for EVM chains (ERC-721, ERC-1155) and Helius for Solana (Metaplex). Without a configured key, NFT listing and metadata queries will fail for the respective chain family."})]})]})}function y(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Oracle"}),e("p",{class:"settings-description",children:"Price oracle configuration for cross-validation"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:e(k,{label:"Cross Validation Threshold (%)",name:"oracle.cross_validation_threshold",type:"number",value:Number(W("oracle","cross_validation_threshold"))||5,onChange:F=>E("oracle.cross_validation_threshold",F),min:0,max:100,description:"Maximum allowed deviation between price oracle sources"})}),e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginTop:"var(--space-3)"},children:e(k,{label:"CoinGecko API Key",name:"oracle.coingecko_api_key",type:"password",value:W("oracle","coingecko_api_key"),onChange:F=>E("oracle.coingecko_api_key",F),placeholder:N("oracle","coingecko_api_key")?"(configured)":"Enter CoinGecko Pro API key (optional)",description:"Pro API key for higher rate limits. Free tier: ~30 req/min."})}),e("div",{class:"settings-info-box",children:["Maximum allowed deviation between price sources before flagging a discrepancy. Default is 5%. CoinGecko Pro API key increases rate limits for reliable price data. Get your API key from"," ",e("a",{href:"https://www.coingecko.com/en/api",target:"_blank",rel:"noopener noreferrer",children:"CoinGecko API Dashboard"}),"."]})]})]})}function p(){const F=xe.value==="display.currency";return X(()=>{if(F){const O=document.querySelector('[name="display.currency"]');O&&O.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const Q=setTimeout(()=>{xe.value=""},2500);return()=>clearTimeout(Q)}},[F]),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Display Currency"}),e("p",{class:"settings-description",children:"Configure display currency for USD amount conversion"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:e("div",{class:`form-field${F?" form-field--highlight":""}`,children:[e("label",{children:ie("currency")}),e(_s,{name:"display.currency",value:W("display","currency")||"USD",onChange:O=>E("display.currency",O)})]})}),e("div",{class:"settings-info-box",children:"All USD amounts in the dashboard, notifications, and API responses will be converted to the selected currency. Policy evaluation always uses USD. The “≈” prefix indicates an approximate conversion."})]})]})}function T(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Global IP Rate Limit"}),e("p",{class:"settings-description",children:"Maximum API requests per minute from a single IP address"})]}),e("div",{class:"settings-category-body",children:e("div",{class:"settings-fields-grid",children:e(k,{label:ie("rate_limit_global_ip_rpm"),name:"security.rate_limit_global_ip_rpm",type:"number",value:Number(W("security","rate_limit_global_ip_rpm"))||0,onChange:F=>E("security.rate_limit_global_ip_rpm",F),min:10,description:"Maximum API requests per minute from a single IP address"})})})]})}function H(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Log Level"}),e("p",{class:"settings-description",children:"General daemon configuration"})]}),e("div",{class:"settings-category-body",children:e("div",{class:"settings-fields-grid",children:e(k,{label:ie("log_level"),name:"daemon.log_level",type:"select",value:W("daemon","log_level")||"info",onChange:F=>E("daemon.log_level",F),options:[{label:"debug",value:"debug"},{label:"info",value:"info"},{label:"warn",value:"warn"},{label:"error",value:"error"}],description:"Daemon logging verbosity level"})})})]})}function Y(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Gas Condition"}),e("p",{class:"settings-description",children:"Configure gas conditional execution for deferred transactions"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(k,{label:"Gas Condition Enabled",name:"gas_condition.enabled",type:"select",value:W("gas_condition","enabled")||"true",onChange:F=>E("gas_condition.enabled",F),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable gas conditional execution for agents"}),e(k,{label:ie("poll_interval_sec"),name:"gas_condition.poll_interval_sec",type:"number",value:Number(W("gas_condition","poll_interval_sec"))||30,onChange:F=>E("gas_condition.poll_interval_sec",F),min:10,max:300,description:"How often to check gas prices (seconds)"}),e(k,{label:ie("default_timeout_sec"),name:"gas_condition.default_timeout_sec",type:"number",value:Number(W("gas_condition","default_timeout_sec"))||3600,onChange:F=>E("gas_condition.default_timeout_sec",F),min:60,max:86400,description:"Default wait timeout when not specified in request (seconds)"}),e(k,{label:ie("max_timeout_sec"),name:"gas_condition.max_timeout_sec",type:"number",value:Number(W("gas_condition","max_timeout_sec"))||86400,onChange:F=>E("gas_condition.max_timeout_sec",F),min:60,max:86400,description:"Maximum allowed timeout for gas conditions (seconds)"}),e(k,{label:ie("max_pending_count"),name:"gas_condition.max_pending_count",type:"number",value:Number(W("gas_condition","max_pending_count"))||100,onChange:F=>E("gas_condition.max_pending_count",F),min:1,max:1e4,description:"Maximum number of concurrent GAS_WAITING transactions"})]}),e("div",{class:"settings-info-box",children:"Gas conditional execution allows agents to specify gas price conditions. Transactions wait until gas prices fall below the specified threshold before executing."})]})]})}function ae(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Smart Account (ERC-4337)"}),e("p",{class:"settings-description",children:"Global smart account feature toggle. Bundler and Paymaster are configured per-wallet."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(k,{label:"Enabled",name:"smart_account.enabled",type:"select",value:W("smart_account","enabled")||"false",onChange:F=>E("smart_account.enabled",F),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable smart account wallet creation. When disabled, only EOA wallets can be created.","data-field":"smart_account.enabled"}),e(k,{label:"EntryPoint Address",name:"smart_account.entry_point",value:W("smart_account","entry_point"),onChange:F=>E("smart_account.entry_point",F),placeholder:"0x0000000071727De22E5E9d8BAf0edAc6f37da032",description:"EntryPoint v0.7 contract address. Override only if using a custom deployment.","data-field":"smart_account.entry_point"})]}),e("div",{class:"settings-info-box",children:"Smart accounts enable gas-sponsored transactions via Paymaster, atomic batch execution, and lazy contract deployment. Bundler and Paymaster settings are configured individually on each wallet (Wallets → Edit → AA Provider)."})]})]})}function ce(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"ERC-8128 Signed HTTP Requests"}),e("p",{class:"settings-description",children:"Configure ERC-8128 HTTP message signing (RFC 9421 + EIP-191). Enables wallets to authenticate API requests with cryptographic signatures."})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(k,{label:"Enabled",name:"erc8128.enabled",type:"select",value:W("erc8128","enabled")||"false",onChange:F=>E("erc8128.enabled",F),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable ERC-8128 HTTP message signing. When disabled, sign/verify endpoints return 403.","data-field":"erc8128.enabled"}),e(k,{label:"Default Preset",name:"erc8128.default_preset",type:"select",value:W("erc8128","default_preset")||"standard",onChange:F=>E("erc8128.default_preset",F),options:[{label:"Minimal",value:"minimal"},{label:"Standard",value:"standard"},{label:"Strict",value:"strict"}],description:"Default covered components preset for signatures.","data-field":"erc8128.default_preset"}),e(k,{label:"Default TTL (seconds)",name:"erc8128.default_ttl_sec",value:W("erc8128","default_ttl_sec")||"300",onChange:F=>E("erc8128.default_ttl_sec",F),placeholder:"300",description:"Default signature TTL in seconds.","data-field":"erc8128.default_ttl_sec"}),e(k,{label:"Include Nonce",name:"erc8128.default_nonce",type:"checkbox",value:f("erc8128","default_nonce"),onChange:F=>E("erc8128.default_nonce",F),description:"Include a UUID v4 nonce in signatures by default for replay protection.","data-field":"erc8128.default_nonce"}),e(k,{label:"Algorithm",name:"erc8128.default_algorithm",value:W("erc8128","default_algorithm")||"ethereum-eip191",onChange:F=>E("erc8128.default_algorithm",F),placeholder:"ethereum-eip191",description:"Signing algorithm. Currently only ethereum-eip191 (personal_sign) is supported.","data-field":"erc8128.default_algorithm"}),e(k,{label:"Rate Limit (per minute)",name:"erc8128.default_rate_limit_rpm",value:W("erc8128","default_rate_limit_rpm")||"60",onChange:F=>E("erc8128.default_rate_limit_rpm",F),placeholder:"60",description:"Maximum signing requests per domain per minute.","data-field":"erc8128.default_rate_limit_rpm"})]}),e("div",{class:"settings-info-box",children:"ERC-8128 enables wallet-based HTTP API authentication using RFC 9421 message signatures signed with EIP-191 (personal_sign). Requires ERC8128_ALLOWED_DOMAINS policy for domain whitelisting."})]})]})}return e("div",{class:"page",children:[_.value&&e("div",{class:"shutdown-overlay",children:[e("h2",{children:"Daemon is shutting down..."}),e("p",{children:"You can close this tab."})]}),w>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[w," unsaved change",w>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(P,{variant:"ghost",size:"sm",onClick:I,children:"Discard"}),e(P,{variant:"primary",size:"sm",onClick:G,loading:n.value,children:"Save"})]})]}),l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(te,{children:[e(K,{}),e(y,{}),e(p,{}),e(T,{}),e(H,{}),e(Y,{}),e(ae,{}),e(ce,{})]}),e("div",{class:"settings-section settings-section--danger",children:[e("div",{class:"settings-section-header",children:[e("h3",{children:"Danger Zone"}),e("p",{class:"settings-description",children:"Irreversible actions. Proceed with caution."})]}),e("div",{class:"settings-section-body",children:e(P,{variant:"danger",onClick:()=>{d.value=!0},children:"Shutdown Daemon"})})]}),e(Se,{open:d.value,title:"Shutdown Daemon",onCancel:()=>{d.value=!1,h.value=""},onConfirm:x,confirmText:"Shutdown",confirmVariant:"danger",confirmDisabled:h.value!=="SHUTDOWN",loading:v.value,children:[e("p",{children:"This will gracefully stop the daemon process. All active connections will be terminated."}),e("div",{class:"shutdown-confirm-input",children:[e("label",{children:["Type ",e("strong",{children:"SHUTDOWN"})," to confirm"]}),e("input",{type:"text",value:h.value,onInput:F=>{h.value=F.target.value},placeholder:"SHUTDOWN"})]})]})]})}const On=[{key:"jupiter_swap",name:"Jupiter Swap",description:"Solana DEX aggregator",chain:"solana",category:"Swap",requiresApiKey:!0,docsUrl:"https://station.jup.ag/docs"},{key:"zerox_swap",name:"0x Swap",description:"EVM DEX aggregator (AllowanceHolder)",chain:"evm",category:"Swap",requiresApiKey:!0,docsUrl:"https://dashboard.0x.org"},{key:"dcent_swap",name:"D'CENT Swap Aggregator",description:"Multi-chain DEX swap aggregator with cross-chain support (6 EVM + Solana)",chain:"multi",category:"Swap",requiresApiKey:!1,docsUrl:"https://dcentwallet.com"},{key:"lifi",name:"LI.FI",description:"Multi-chain DEX/bridge aggregator",chain:"multi",category:"Bridge",requiresApiKey:!1,docsUrl:"https://docs.li.fi"},{key:"lido_staking",name:"Lido Staking",description:"ETH liquid staking (stETH/wstETH)",chain:"evm",category:"Staking",requiresApiKey:!1,docsUrl:"https://docs.lido.fi"},{key:"jito_staking",name:"Jito Staking",description:"SOL liquid staking (JitoSOL)",chain:"solana",category:"Staking",requiresApiKey:!1,docsUrl:"https://www.jito.network/docs"},{key:"aave_v3",name:"Aave V3 Lending",description:"EVM lending protocol (supply, borrow, repay, withdraw)",chain:"evm",category:"Lending",requiresApiKey:!1,docsUrl:"https://docs.aave.com/developers"},{key:"kamino",name:"Kamino Lending",description:"Solana lending protocol (supply, borrow, repay, withdraw)",chain:"solana",category:"Lending",requiresApiKey:!1,docsUrl:"https://docs.kamino.finance"},{key:"pendle_yield",name:"Pendle Yield",description:"EVM yield trading: buy/sell PT/YT, redeem at maturity, add/remove LP",chain:"evm",category:"Yield",requiresApiKey:!1,docsUrl:"https://docs.pendle.finance"},{key:"drift",name:"Drift Perp",description:"Solana perpetual futures trading (open, close, modify positions with leverage)",chain:"solana",category:"Perp",requiresApiKey:!1,docsUrl:"https://docs.drift.trade"},{key:"hyperliquid_perp",name:"Hyperliquid Perp",description:"Hyperliquid perpetual futures trading with EIP-712 signing",chain:"evm",category:"Perp",requiresApiKey:!1,docsUrl:"https://hyperliquid.gitbook.io/hyperliquid-docs"},{key:"hyperliquid_spot",name:"Hyperliquid Spot",description:"Hyperliquid spot market trading (buy, sell, cancel)",chain:"evm",category:"Swap",requiresApiKey:!1,docsUrl:"https://hyperliquid.gitbook.io/hyperliquid-docs"},{key:"hyperliquid_sub",name:"Hyperliquid Sub",description:"Hyperliquid sub-account management (create, transfer USDC)",chain:"evm",category:"DeFi",requiresApiKey:!1,docsUrl:"https://hyperliquid.gitbook.io/hyperliquid-docs"},{key:"across_bridge",name:"Across Bridge",description:"Intent-based cross-chain EVM bridge with fast relayer fills (2-10 sec)",chain:"evm",category:"Bridge",requiresApiKey:!1,docsUrl:"https://docs.across.to"}],Ts=["Swap","Bridge","Staking","Lending","Yield","Perp"];function Pn(){const t=c([]),a=c({}),n=c([]),l=c(!0),i=c(null),r=c(""),s=c(!1),o=c(null),u=c({}),d=async()=>{try{const p=await q(D.ADMIN_SETTINGS);a.value=p}catch(p){const T=p instanceof b?p:new b(0,"UNKNOWN","Unknown error");m("error",z(T.code))}},v=async()=>{try{const p=await q(D.ADMIN_API_KEYS);n.value=p.keys}catch{}},h=async()=>{try{const p=await q(D.ACTIONS_PROVIDERS);t.value=p.providers??[]}catch{}},_=async()=>{l.value=!0,await Promise.all([d(),v(),h()]),l.value=!1};X(()=>{_()},[]);const A=async(p,T)=>{const H=`actions.${p}_enabled`;o.value=p;try{const Y=await oe(D.ADMIN_SETTINGS,{settings:[{key:H,value:String(T)}]});a.value=Y.settings,m("success",`${T?"Enabled":"Disabled"} ${p.replace(/_/g," ")}`)}catch(Y){const ae=Y instanceof b?Y:new b(0,"UNKNOWN","Unknown error");m("error",z(ae.code))}finally{o.value=null}},$=async p=>{s.value=!0;try{await oe(D.ADMIN_API_KEY(p),{apiKey:r.value}),m("success",`API key saved for ${p}`),i.value=null,r.value="",await v()}catch(T){const H=T instanceof b?T:new b(0,"UNKNOWN","Unknown error");m("error",z(H.code))}finally{s.value=!1}},W=async p=>{try{await Le(D.ADMIN_API_KEY(p)),m("success",`API key deleted for ${p}`),await v()}catch(T){const H=T instanceof b?T:new b(0,"UNKNOWN","Unknown error");m("error",z(H.code))}},f=async(p,T)=>{const H=`actions.${p}`,Y=fn(p)?nr(T):T;try{const ae=await oe(D.ADMIN_SETTINGS,{settings:[{key:H,value:Y}]});a.value=ae.settings;const ce={...u.value};delete ce[p],u.value=ce,m("success","Setting updated")}catch(ae){const ce=ae instanceof b?ae:new b(0,"UNKNOWN","Unknown error");m("error",z(ce.code))}};function N(p){const T=a.value.actions;return T?T[`${p}_enabled`]==="true":!1}function E(p){return t.value.some(T=>T.name.toLowerCase().replace(/[\s-]/g,"_")===p||T.name.toLowerCase().includes(p.replace(/_/g," ")))}function G(p){return n.value.find(T=>T.providerName===p||T.providerName.toLowerCase().replace(/[\s-]/g,"_")===p)}function I(p){return t.value.find(T=>T.name.toLowerCase().replace(/[\s-]/g,"_")===p||T.name.toLowerCase().includes(p.replace(/_/g," ")))}function V(p,T){return a.value.actions?.[`${p}_${T}_tier`]||""}function C(p,T){const H=V(p,T);return H!==""&&H!==void 0}async function x(p,T,H){const Y=`actions.${p}_${T}_tier`;try{const ae=await oe(D.ADMIN_SETTINGS,{settings:[{key:Y,value:H}]});a.value=ae.settings,m("success",`Tier updated for ${p}/${T}`)}catch(ae){const ce=ae instanceof b?ae:new b(0,"UNKNOWN","Unknown error");m("error",z(ce.code))}}async function w(p,T){const H=`actions.${p}_${T}_tier`;try{const Y=await oe(D.ADMIN_SETTINGS,{settings:[{key:H,value:""}]});a.value=Y.settings,m("success",`Tier reset to default for ${p}/${T}`)}catch(Y){const ae=Y instanceof b?Y:new b(0,"UNKNOWN","Unknown error");m("error",z(ae.code))}}function R(p){const T=a.value.actions,H=u.value[p]??T?.[p]??"";return u.value[p]!==void 0?u.value[p]:fn(p)?ar(H):H}function K(p){const T=N(p.key),H=E(p.key);return T&&p.requiresApiKey&&!G(p.key)?.hasKey?{label:"Requires API Key",variant:"warning"}:T&&H?{label:"Active",variant:"success"}:{label:"Inactive",variant:"neutral"}}if(l.value)return e("div",{class:"page",children:e("div",{class:"empty-state",children:e("p",{children:"Loading action providers..."})})});const y=Ts.map(p=>({category:p,items:On.filter(T=>T.category===p)})).filter(p=>p.items.length>0);return e("div",{class:"page",children:[y.map(p=>e("div",{children:[e("h2",{style:{fontSize:"var(--font-size-lg)",fontWeight:600,margin:"var(--space-4) 0 var(--space-2)",borderBottom:"1px solid var(--border)",paddingBottom:"var(--space-2)"},children:p.category}),p.items.map(T=>{const H=K(T),Y=N(T.key),ae=I(T.key),ce=G(T.key),F=o.value===T.key;return e("div",{class:"settings-category",style:{marginBottom:"var(--space-4)"},children:[e("div",{class:"settings-category-header",style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e("div",{children:[e("h3",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",margin:0},children:[T.name,ae&&e(j,{variant:"info",children:ae.version}),e(j,{variant:(T.chain==="solana","info"),children:T.chain})]}),e("p",{class:"settings-description",style:{marginTop:"var(--space-1)"},children:[T.description,T.docsUrl&&e(te,{children:[" ","—"," ",e("a",{href:T.docsUrl,target:"_blank",rel:"noopener noreferrer",children:"Docs"})]})]})]}),e(j,{variant:H.variant,children:H.label})]}),e("div",{class:"settings-category-body",children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e(k,{label:"Enabled",name:`actions.${T.key}_enabled`,type:"checkbox",value:Y,onChange:O=>A(T.key,!!O),disabled:F}),F&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)"},children:"Saving..."})]}),T.requiresApiKey&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"API Key"}),i.value===T.key?e("div",{style:{display:"flex",alignItems:"flex-end",gap:"var(--space-2)"},children:[e(k,{label:"API Key",type:"password",name:`apikey-${T.key}`,value:r.value,onChange:O=>{r.value=String(O)},placeholder:"Enter API key"}),e(P,{onClick:()=>$(T.key),loading:s.value,size:"sm",children:"Save"}),e(P,{variant:"ghost",onClick:()=>{i.value=null,r.value=""},size:"sm",children:"Cancel"})]}):e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e("span",{style:{fontFamily:"monospace",fontSize:"var(--font-size-sm)",color:"var(--text-secondary)"},children:ce?.hasKey?ce.maskedKey:"Not set"}),e(P,{variant:"ghost",onClick:()=>{i.value=T.key,r.value=""},size:"sm",children:ce?.hasKey?"Update":"Set"}),ce?.hasKey&&e(P,{variant:"danger",onClick:()=>W(T.key),size:"sm",children:"Delete"})]})]}),T.key==="jupiter_swap"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["jupiter_swap_default_slippage_bps","jupiter_swap_max_slippage_bps"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),T.key==="zerox_swap"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["zerox_swap_default_slippage_bps","zerox_swap_max_slippage_bps"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),T.key==="aave_v3"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["aave_v3_health_factor_warning_threshold","aave_v3_position_sync_interval_sec","aave_v3_max_ltv_pct"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),T.key==="kamino"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["kamino_market","kamino_hf_threshold"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),T.key==="drift"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["drift_max_leverage","drift_max_position_usd","drift_margin_warning_threshold_pct","drift_position_sync_interval_sec"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),T.key==="pendle_yield"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["pendle_yield_default_slippage_bps","pendle_yield_max_slippage_bps"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),T.key==="dcent_swap"&&Y&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Advanced Settings"}),["dcent_swap_api_url","dcent_swap_default_slippage_bps","dcent_swap_max_slippage_bps"].map(O=>{const Q=R(O);return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=u.value[O];J!==void 0&&f(O,J)},children:e(k,{label:ie(O),name:`actions.${O}`,type:"text",value:Q,onChange:J=>{u.value={...u.value,[O]:String(J)}}})},O)})]}),Y&&ae&&ae.actions.length>0&&e("div",{style:{borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Registered Actions"}),e("table",{class:"table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Name"}),e("th",{children:"Description"}),e("th",{children:"Chain"}),e("th",{children:"Risk Level"}),e("th",{children:"Tier"})]})}),e("tbody",{children:ae.actions.map(O=>e("tr",{children:[e("td",{children:O.name}),e("td",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)",maxWidth:"300px"},children:O.description}),e("td",{children:ae.chains.length>1?ae.chains.map(Q=>e(j,{variant:"info",children:Q},Q)):e(j,{variant:"info",children:O.chain})}),e("td",{children:O.riskLevel}),e("td",{children:e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e("select",{value:V(T.key,O.name)||O.defaultTier,onChange:Q=>x(T.key,O.name,Q.target.value),style:{padding:"2px 4px",fontSize:"var(--font-size-sm)",borderRadius:"var(--radius-sm)"},children:["INSTANT","NOTIFY","DELAY","APPROVAL"].map(Q=>e("option",{value:Q,children:Q},Q))}),C(T.key,O.name)&&e(te,{children:[e(j,{variant:"warning",children:"customized"}),e("button",{onClick:()=>w(T.key,O.name),style:{background:"none",border:"none",cursor:"pointer",fontSize:"var(--font-size-xs)",color:"var(--text-secondary)",textDecoration:"underline"},title:"Reset to provider default",children:"reset"})]})]})})]},O.name))})]})]})]})]},T.key)})]},p.category)),On.length===0&&e("div",{class:"empty-state",children:e("p",{children:"No action providers available."})})]})}function ks(){const t=c([]),a=c(!0),n=c(!1),l=c(!1),i=c(!1),r=c(null),s=c(!1),o=c(""),u=c(""),d=c(""),v=c(!1),h=c({}),_=c(null),A=c(null),$=c({}),W=c(null),f=async()=>{try{const p=await q(D.ADMIN_WALLET_APPS);t.value=p.apps}catch{m("Failed to load wallet apps","error")}},N=async()=>{try{const T=(await q(D.ADMIN_SETTINGS)).signing_sdk;T&&(l.value=String(T.enabled)==="true",n.value=String(T.notifications_enabled)==="true")}catch{}};X(()=>{Promise.all([f(),N()]).finally(()=>{a.value=!1})},[]);const E=async()=>{i.value=!0;const p=!n.value;try{await oe(D.ADMIN_SETTINGS,{settings:[{key:"signing_sdk.notifications_enabled",value:String(p)}]}),n.value=p,m(`Wallet app notifications ${p?"enabled":"disabled"}`,"success")}catch{m("Failed to update notification setting","error")}finally{i.value=!1}},G=async(p,T)=>{A.value=`${p.id}-${T}`;try{await oe(D.ADMIN_WALLET_APP(p.id),{[T]:!p[T]}),await f(),m(`${T==="signing_enabled"?"Signing":"Alerts"} ${p[T]?"disabled":"enabled"} for ${p.display_name}`,"success")}catch{m("Failed to update toggle","error")}finally{A.value=null}},I=async p=>{r.value=p.id;try{const T=await he(D.ADMIN_WALLET_APP_TEST_NOTIFICATION(p.id));T.success?m(`Test notification sent to ${T.topic}`,"success"):m(T.error||"Test notification failed","error")}catch{m("Failed to send test notification","error")}finally{r.value=null}},V=async()=>{if(!o.value.trim()||!u.value.trim()){m("Name and display name are required","error");return}v.value=!0;try{const p={name:o.value.trim(),display_name:u.value.trim()};d.value.trim()&&(p.wallet_type=d.value.trim()),await he(D.ADMIN_WALLET_APPS,p),s.value=!1,o.value="",u.value="",d.value="",await f(),m("Wallet app registered","success")}catch(p){p instanceof b&&p.code==="WALLET_APP_DUPLICATE"?m("App already registered","error"):m("Failed to register app","error")}finally{v.value=!1}},C=async(p,T)=>{_.value=p.id;try{await oe(D.ADMIN_WALLET_APP(p.id),{subscription_token:T||""});const H={...h.value};delete H[p.id],h.value=H,await f(),m(T?"Subscription token set":"Subscription token cleared","success")}catch{m("Failed to update subscription token","error")}finally{_.value=null}},x=async p=>{if(confirm(`Remove "${p.display_name}"? Wallets using this app will no longer route signing requests to it.`))try{await Le(D.ADMIN_WALLET_APP(p.id)),await f(),m(`${p.display_name} removed`,"success")}catch{m("Failed to remove app","error")}},w=p=>{$.value={...$.value,[p.id]:{signTopic:p.sign_topic??"",notifyTopic:p.notify_topic??""}}},R=p=>{const T={...$.value};delete T[p],$.value=T},K=async p=>{const T=$.value[p.id];if(T){W.value=p.id;try{await oe(D.ADMIN_WALLET_APP(p.id),{sign_topic:T.signTopic||null,notify_topic:T.notifyTopic||null}),R(p.id),await f(),m("Topics updated","success")}catch{m("Failed to update topics","error")}finally{W.value=null}}},y=t.value.some(p=>p.alerts_enabled);return a.value?e("div",{class:"loading-container",children:"Loading..."}):e("div",{class:"human-wallet-apps-page",children:[e("div",{class:"settings-category",style:{marginBottom:"1.5rem"},children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Wallet App Notifications"}),e("p",{class:"settings-description",children:"Push event notifications (transaction alerts, balance changes) to registered wallet apps via ntfy"})]}),e("div",{class:"settings-category-body",children:[e("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[e("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:n.value,onChange:E,disabled:i.value,"data-testid":"notif-toggle"}),e("span",{children:"Notifications"}),e(j,{variant:n.value?"success":"muted",children:n.value?"ON":"OFF"})]}),i.value&&e("span",{style:{fontSize:"0.85rem",color:"var(--text-muted)"},children:"Saving..."})]}),!l.value&&e("div",{class:"settings-warning-box",style:{marginTop:"0.75rem",padding:"0.75rem",background:"var(--warning-bg, #fff3cd)",border:"1px solid var(--warning-border, #ffc107)",borderRadius:"4px",fontSize:"0.85rem"},children:"Signing SDK is disabled. Enable it in System > Signing SDK to use wallet app notifications."}),!n.value&&y&&e("div",{class:"settings-warning-box",style:{marginTop:"0.75rem",padding:"0.75rem",background:"var(--warning-bg, #fff3cd)",border:"1px solid var(--warning-border, #ffc107)",borderRadius:"4px",fontSize:"0.85rem"},children:"Notifications are disabled but some apps have alerts enabled. Enable notifications above for alerts to be delivered."})]})]}),e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",style:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e("div",{children:[e("h3",{children:"Registered Apps"}),e("p",{class:"settings-description",children:"Wallet apps registered for signing and notifications"})]}),e(P,{onClick:()=>{s.value=!0},children:"+ Register App"})]}),e("div",{class:"settings-category-body",children:t.value.length===0?e("div",{class:"settings-info-box",children:'No wallet apps registered. Use "+ Register App" to add one, or apply a wallet preset when setting up a wallet owner.'}):e("div",{style:{display:"grid",gap:"1rem"},children:t.value.map(p=>e("div",{class:"settings-category",style:{border:"1px solid var(--border)",padding:"1rem"},children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e("div",{children:[e("h4",{style:{margin:"0 0 0.25rem 0"},children:[p.display_name,p.wallet_type&&p.wallet_type!==p.name&&e(j,{variant:"info",style:{marginLeft:"0.5rem",fontSize:"0.7rem"},children:p.wallet_type})]}),e("code",{style:{fontSize:"0.8rem",color:"var(--text-muted)"},children:p.name})]}),e(P,{variant:"danger",size:"sm",onClick:()=>x(p),children:"Remove"})]}),e("div",{style:{display:"flex",gap:"2rem",marginTop:"1rem",flexWrap:"wrap",alignItems:"center"},children:[e("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:p.signing_enabled,onChange:()=>G(p,"signing_enabled"),disabled:A.value===`${p.id}-signing_enabled`}),e("span",{children:"Signing"}),e(j,{variant:p.signing_enabled?"success":"muted",children:p.signing_enabled?"ON":"OFF"})]}),e("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:p.alerts_enabled,onChange:()=>G(p,"alerts_enabled"),disabled:A.value===`${p.id}-alerts_enabled`}),e("span",{children:"Alerts"}),e(j,{variant:p.alerts_enabled?"success":"muted",children:p.alerts_enabled?"ON":"OFF"})]}),p.alerts_enabled&&e(P,{variant:"secondary",size:"sm",onClick:()=>I(p),disabled:r.value===p.id,children:r.value===p.id?"Sending...":"Test"})]}),e("div",{style:{marginTop:"0.75rem"},children:[e("span",{style:{fontSize:"0.85rem",fontWeight:500},children:"Used by: "}),p.used_by.length===0?e("span",{style:{fontSize:"0.85rem",color:"var(--text-muted)"},children:"No wallets"}):e("span",{style:{fontSize:"0.85rem"},children:p.used_by.map((T,H)=>e("span",{children:[H>0&&", ",e("a",{href:`#/wallets/${T.id}`,style:{color:"var(--primary)"},children:T.label})]},T.id))})]}),e("div",{style:{marginTop:"0.75rem"},children:[e("span",{style:{fontSize:"0.85rem",fontWeight:500},children:"Subscription Token: "}),h.value[p.id]!==void 0?e("span",{style:{display:"inline-flex",gap:"0.5rem",alignItems:"center"},children:[e("input",{type:"text",value:h.value[p.id],onInput:T=>{h.value={...h.value,[p.id]:T.target.value}},placeholder:"e.g., a1b2c3d4",style:{padding:"0.25rem 0.5rem",fontSize:"0.85rem",width:"140px"}}),e(P,{size:"sm",onClick:()=>C(p,h.value[p.id]),disabled:_.value===p.id,children:_.value===p.id?"Saving...":"Set"}),e(P,{variant:"secondary",size:"sm",onClick:()=>{const T={...h.value};delete T[p.id],h.value=T},children:"Cancel"})]}):p.subscription_token?e("span",{style:{fontSize:"0.85rem"},children:[e("code",{children:[p.subscription_token.slice(0,4),"****"]}),e(P,{variant:"secondary",size:"sm",onClick:()=>C(p,""),disabled:_.value===p.id,style:{marginLeft:"0.5rem"},children:"Clear"})]}):e("span",{style:{fontSize:"0.85rem"},children:[e("span",{style:{color:"var(--text-muted)"},children:"Not set"}),e(P,{variant:"secondary",size:"sm",onClick:()=>{h.value={...h.value,[p.id]:""}},style:{marginLeft:"0.5rem"},children:"Set"})]})]}),$.value[p.id]?e("div",{style:{marginTop:"0.75rem",borderTop:"1px solid var(--border)",paddingTop:"0.75rem"},children:[e("span",{style:{fontSize:"0.85rem",fontWeight:500,display:"block",marginBottom:"0.5rem"},children:"ntfy Topics"}),e("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.5rem"},children:[e(k,{label:"Sign Topic",name:`sign-topic-${p.id}`,type:"text",value:$.value[p.id].signTopic,onChange:T=>{$.value={...$.value,[p.id]:{...$.value[p.id],signTopic:String(T)}}},placeholder:`waiaas-sign-${p.name}`,description:"ntfy topic for signing requests"}),e(k,{label:"Notify Topic",name:`notify-topic-${p.id}`,type:"text",value:$.value[p.id].notifyTopic,onChange:T=>{$.value={...$.value,[p.id]:{...$.value[p.id],notifyTopic:String(T)}}},placeholder:`waiaas-notify-${p.name}`,description:"ntfy topic for activity alerts"})]}),e("div",{style:{display:"flex",gap:"0.5rem",justifyContent:"flex-end",marginTop:"0.5rem"},children:[e(P,{variant:"secondary",size:"sm",onClick:()=>R(p.id),children:"Cancel"}),e(P,{size:"sm",onClick:()=>K(p),disabled:W.value===p.id,children:W.value===p.id?"Saving...":"Save Topics"})]})]}):e("div",{style:{marginTop:"0.75rem",borderTop:"1px solid var(--border)",paddingTop:"0.75rem"},children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"0.5rem"},children:[e("span",{style:{fontSize:"0.85rem",fontWeight:500},children:"ntfy Topics"}),e(P,{variant:"secondary",size:"sm",onClick:()=>w(p),children:"Edit"})]}),e("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:"0.5rem",fontSize:"0.85rem"},children:[e("div",{children:[e("span",{style:{color:"var(--text-muted)"},children:"Sign Topic: "}),e("code",{children:p.sign_topic??"(default)"})]}),e("div",{children:[e("span",{style:{color:"var(--text-muted)"},children:"Notify Topic: "}),e("code",{children:p.notify_topic??"(default)"})]})]})]})]},p.id))})})]}),e(Se,{open:s.value,title:"Register Wallet App",onCancel:()=>{s.value=!1},children:e("div",{style:{display:"flex",flexDirection:"column",gap:"1rem"},children:[e(k,{label:"App Name",name:"register-app-name",type:"text",value:o.value,onChange:p=>{o.value=String(p)},placeholder:"my-custom-wallet",description:"Lowercase alphanumeric with hyphens (e.g., dcent, my-wallet)"}),e(k,{label:"Display Name",name:"register-app-display-name",type:"text",value:u.value,onChange:p=>{u.value=String(p)},placeholder:"My Custom Wallet",description:"Human-readable name shown in the UI"}),e(k,{label:"Wallet Type (optional)",name:"register-app-wallet-type",type:"text",value:d.value,onChange:p=>{d.value=String(p)},placeholder:"dcent, ledger, or custom",description:"Group multiple devices under the same wallet type. Defaults to app name."}),e("div",{style:{display:"flex",gap:"0.5rem",justifyContent:"flex-end"},children:[e(P,{variant:"secondary",onClick:()=>{s.value=!1},children:"Cancel"}),e(P,{onClick:V,disabled:v.value||!o.value.trim()||!u.value.trim(),children:v.value?"Registering...":"Register"})]})]})})]})}const Mn=[{key:"identity",label:"Identity"},{key:"registration",label:"Registration File"},{key:"reputation",label:"Reputation"}];function Wa({data:t,depth:a=0}){if(t==null)return e("span",{style:{color:"var(--color-text-muted)"},children:"null"});if(typeof t=="string")return e("span",{style:{color:"var(--color-success)"},children:['"',t,'"']});if(typeof t=="number"||typeof t=="boolean")return e("span",{style:{color:"var(--color-primary)"},children:String(t)});if(Array.isArray(t))return t.length===0?e("span",{children:"[]"}):e("div",{style:{paddingLeft:a>0?"var(--space-3)":"0"},children:["[",t.map((n,l)=>e("div",{style:{paddingLeft:"var(--space-3)"},children:[e(Wa,{data:n,depth:a+1}),l<t.length-1?",":""]},l)),"]"]});if(typeof t=="object"){const n=Object.entries(t);return n.length===0?e("span",{children:"{}"}):e("div",{style:{paddingLeft:a>0?"var(--space-3)":"0"},children:["{",n.map(([l,i],r)=>e("div",{style:{paddingLeft:"var(--space-3)"},children:[e("span",{style:{fontWeight:"bold"},children:['"',l,'"']}),": ",e(Wa,{data:i,depth:a+1}),r<n.length-1?",":""]},l)),"}"]})}return e("span",{children:String(t)})}function Wn(){const t=c("identity"),a=c(!0),n=c(!1),l=c([]),i=c([]),r=c([]),s=c({}),o=c(!1),u=c(!1),d=c(""),v=c(""),h=c(""),_=c(!1),A=c(""),$=c(null),W=c(!1),f=c(null),N=c(""),E=c(""),G=c(""),I=c(null),V=c(!1),C=c(null),x=c(""),w=c(!1);async function R(){a.value=!0;try{const L=await q(D.ADMIN_SETTINGS);s.value=L;const le=L.actions;n.value=le?.erc8004_agent_enabled==="true";try{const S=(await q(D.ACTIONS_PROVIDERS)).providers?.find(U=>U.name==="erc8004_agent");i.value=S?.actions??[]}catch{}const ee=(await q(D.WALLETS)).items??[];l.value=ee;const ve=ee.filter(ke=>ke.chain==="ethereum"),Ce=[];for(const ke of ve)try{const S=await q(D.ERC8004_REGISTRATION_FILE(ke.id)),U=S.agentId;Ce.push({walletId:ke.id,walletName:ke.name,agentId:U??null,status:U?"REGISTERED":"NOT_REGISTERED",registryAddress:S.registryAddress??""})}catch{Ce.push({walletId:ke.id,walletName:ke.name,agentId:null,status:"NOT_REGISTERED",registryAddress:""})}r.value=Ce}catch(L){L instanceof b&&m(z(L.code),"error")}finally{a.value=!1}}X(()=>{R()},[]);async function K(L){o.value=!0;try{await oe(D.ADMIN_SETTINGS,{settings:[{key:"actions.erc8004_agent_enabled",value:String(L)}]}),n.value=L,m(`Agent Identity ${L?"enabled":"disabled"}`,"success"),await R()}catch(le){le instanceof b&&m(z(le.code),"error")}finally{o.value=!1}}async function y(){if(!(!d.value||!v.value)){_.value=!0;try{await he(`${D.ADMIN_ACTIONS}/erc8004_agent/register_agent`,{params:{name:v.value,...h.value?{description:h.value}:{}},walletId:d.value}),m("Agent registration initiated","success"),u.value=!1,v.value="",h.value="",d.value="",await R()}catch(L){L instanceof b&&m(z(L.code),"error")}finally{_.value=!1}}}async function p(L,le){C.value=L,w.value=!1,x.value="";try{const M=await he(D.WALLET_WC_PAIR(L),{});x.value=M.uri;const ee=setInterval(async()=>{try{(await q(D.WALLET_WC_PAIR_STATUS(L))).connected&&(clearInterval(ee),w.value=!0,await he(`${D.ADMIN_ACTIONS}/erc8004_agent/set_agent_wallet`,{params:{agentId:le},walletId:L}),m("Wallet linking initiated via EIP-712","success"),C.value=null,await R())}catch{}},1e3);setTimeout(()=>{clearInterval(ee),!w.value&&C.value&&(m("WalletConnect pairing timed out","error"),C.value=null)},6e4)}catch(M){M instanceof b&&m(z(M.code),"error"),C.value=null}}async function T(L,le){try{await he(`${D.ADMIN_ACTIONS}/erc8004_agent/unset_agent_wallet`,{params:{agentId:le},walletId:L}),m("Wallet unlinking initiated","success"),await R()}catch(M){M instanceof b&&m(z(M.code),"error")}}async function H(L){if(L){W.value=!0;try{const le=await q(D.ERC8004_REGISTRATION_FILE(L));$.value=le}catch(le){le instanceof b&&m(z(le.code),"error"),$.value=null}finally{W.value=!1}}}async function Y(L,le,M){try{const ve=new URLSearchParams().toString(),Ce=await q(`${D.ERC8004_REPUTATION(L)}${ve?`?${ve}`:""}`);f.value=Ce}catch{f.value=null}}async function ae(){if(G.value){V.value=!0;try{const L=new URLSearchParams;N.value&&L.set("tag1",N.value),E.value&&L.set("tag2",E.value);const le=L.toString(),M=await q(`${D.ERC8004_REPUTATION(G.value)}${le?`?${le}`:""}`);I.value=M}catch(L){L instanceof b&&m(z(L.code),"error"),I.value=null}finally{V.value=!1}}}function ce(L){return L>=50?"success":L>=20?"warning":"danger"}function F(L,le){return s.value.actions?.[`${L}_${le}_tier`]||""}function O(L,le){const M=F(L,le);return M!==""&&M!==void 0}async function Q(L,le,M){const ee=`actions.${L}_${le}_tier`;try{const ve=await oe(D.ADMIN_SETTINGS,{settings:[{key:ee,value:M}]});s.value=ve.settings,m(`Tier updated for ${L}/${le}`,"success")}catch(ve){ve instanceof b&&m(z(ve.code),"error")}}async function J(L,le){const M=`actions.${L}_${le}_tier`;try{const ee=await oe(D.ADMIN_SETTINGS,{settings:[{key:M,value:""}]});s.value=ee.settings,m(`Tier reset to default for ${L}/${le}`,"success")}catch(ee){ee instanceof b&&m(z(ee.code),"error")}}const be=n.value?Mn:Mn.filter(L=>L.key==="identity");be.some(L=>L.key===t.value)||(t.value="identity");const Ae=l.value.filter(L=>L.chain==="ethereum");return e("div",{children:[e("div",{class:"settings-category",style:{marginBottom:"var(--space-4)"},children:[e("div",{class:"settings-category-header",children:e("h3",{style:{margin:0},children:"ERC-8004 Agent Identity"})}),e("div",{class:"settings-category-body",children:e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-3)"},children:[e(k,{label:"Enabled",name:"actions.erc8004_agent_enabled",type:"checkbox",value:n.value,onChange:L=>K(!!L),disabled:o.value}),o.value&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)"},children:"Saving..."})]})})]}),!a.value&&!n.value&&e("div",{class:"empty-state",style:{marginTop:"var(--space-3)"},children:e("p",{children:"Agent Identity features are disabled. Enable the toggle above to manage agent registrations, reputation, and wallet linking."})}),!a.value&&e(te,{children:[e(at,{tabs:be,activeTab:t.value,onTabChange:L=>{t.value=L}}),t.value==="identity"&&e("div",{children:[e("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"var(--space-3)"},children:[e("h3",{style:{margin:0},children:"Registered Agents"}),n.value&&e(P,{variant:"primary",onClick:()=>{u.value=!0},children:"Register Agent"})]}),r.value.length===0?e(ot,{title:"No EVM wallets found",description:"Create an EVM wallet first to register agents."}):e("table",{class:"data-table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Wallet Name"}),e("th",{children:"Wallet ID"}),e("th",{children:"Status"}),e("th",{children:"Agent ID"}),e("th",{children:"Registry Address"}),n.value&&e("th",{children:"Actions"})]})}),e("tbody",{children:r.value.map(L=>e("tr",{children:[e("td",{children:L.walletName}),e("td",{title:L.walletId,children:[L.walletId.slice(0,8),"..."]}),e("td",{children:e(j,{variant:L.status==="REGISTERED"?"success":L.status==="WALLET_LINKED"?"info":"default",children:L.status})}),e("td",{children:L.agentId??"-"}),e("td",{title:L.registryAddress,children:L.registryAddress?`${L.registryAddress.slice(0,10)}...`:"-"}),n.value&&e("td",{children:[L.agentId&&L.status==="REGISTERED"&&e(P,{variant:"secondary",onClick:()=>p(L.walletId,L.agentId),disabled:C.value===L.walletId,children:C.value===L.walletId?"Linking...":"Link Wallet"}),L.agentId&&L.status==="WALLET_LINKED"&&e(P,{variant:"danger",onClick:()=>T(L.walletId,L.agentId),children:"Unlink"})]})]},L.walletId))})]}),C.value&&x.value&&e("div",{style:{marginTop:"var(--space-3)",padding:"var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)"},children:[e("p",{style:{fontWeight:"bold"},children:"WalletConnect Pairing URI"}),e("code",{style:{wordBreak:"break-all",fontSize:"var(--font-sm)"},children:x.value}),e("div",{style:{marginTop:"var(--space-2)"},children:e(tt,{value:x.value,label:"Copy URI"})})]}),i.value.length>0&&e("div",{style:{marginTop:"var(--space-4)",borderTop:"1px solid var(--border)",paddingTop:"var(--space-3)"},children:[e("div",{style:{fontWeight:600,fontSize:"var(--font-size-sm)",marginBottom:"var(--space-2)",color:"var(--text-secondary)"},children:"Registered Actions"}),e("table",{class:"table",children:[e("thead",{children:e("tr",{children:[e("th",{children:"Name"}),e("th",{children:"Description"}),e("th",{children:"Risk Level"}),e("th",{children:"Tier"})]})}),e("tbody",{children:i.value.map(L=>e("tr",{children:[e("td",{children:L.name}),e("td",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)",maxWidth:"300px"},children:L.description}),e("td",{children:L.riskLevel}),e("td",{children:e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e("select",{value:F("erc8004_agent",L.name)||L.defaultTier,onChange:le=>Q("erc8004_agent",L.name,le.target.value),style:{padding:"2px 4px",fontSize:"var(--font-size-sm)",borderRadius:"var(--radius-sm)"},disabled:!n.value,children:["INSTANT","NOTIFY","DELAY","APPROVAL"].map(le=>e("option",{value:le,children:le},le))}),O("erc8004_agent",L.name)&&n.value&&e(te,{children:[e(j,{variant:"warning",children:"customized"}),e("button",{onClick:()=>J("erc8004_agent",L.name),style:{background:"none",border:"none",cursor:"pointer",fontSize:"var(--font-size-xs)",color:"var(--text-secondary)",textDecoration:"underline"},title:"Reset to provider default",children:"reset"})]})]})})]},L.name))})]})]})]}),n.value&&t.value==="registration"&&e("div",{children:[e("div",{class:"form-field",children:[e("label",{children:"Select Wallet"}),e("select",{value:A.value,onChange:L=>{const le=L.target.value;A.value=le,le&&H(le)},children:[e("option",{value:"",children:"-- Select wallet --"}),Ae.map(L=>e("option",{value:L.id,children:[L.name," (",L.id.slice(0,8),"...)"]},L.id))]})]}),A.value&&e("div",{style:{marginTop:"var(--space-3)"},children:[e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",marginBottom:"var(--space-2)"},children:[e("h4",{style:{margin:0},children:"Registration File"}),e(tt,{value:`${window.location.origin}/v1/erc8004/registration-file/${A.value}`,label:"Copy URL"})]}),W.value?e("p",{class:"loading-text",children:"Loading..."}):$.value?e("div",{style:{fontFamily:"monospace",fontSize:"var(--font-sm)",background:"var(--color-bg-secondary)",padding:"var(--space-3)",borderRadius:"var(--radius-md)",overflow:"auto"},children:e(Wa,{data:$.value})}):e("p",{children:"No registration file available for this wallet."})]})]}),n.value&&t.value==="reputation"&&e("div",{children:[e("h3",{children:"My Agent Score"}),r.value.filter(L=>L.agentId).length===0?e("p",{children:"No registered agents. Register an agent first."}):e("div",{children:r.value.filter(L=>L.agentId).map(L=>((!f.value||f.value.agentId!==L.agentId)&&Y(L.agentId),e("div",{style:{padding:"var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)",marginBottom:"var(--space-2)"},children:e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e("strong",{children:["Agent #",L.agentId]}),f.value&&f.value.agentId===L.agentId&&e(te,{children:[e("span",{style:{fontSize:"var(--font-xl)",fontWeight:"bold"},children:Number(f.value.score)/Math.pow(10,f.value.decimals)}),e(j,{variant:ce(Number(f.value.score)/Math.pow(10,f.value.decimals)),children:[f.value.count," feedback(s)"]})]})]})},L.agentId)))}),e("div",{style:{display:"flex",gap:"var(--space-2)",marginTop:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("div",{class:"form-field",children:[e("label",{children:"Tag1 Filter"}),e("input",{type:"text",value:N.value,onInput:L=>{N.value=L.target.value},placeholder:"e.g. reliability"})]}),e("div",{class:"form-field",children:[e("label",{children:"Tag2 Filter"}),e("input",{type:"text",value:E.value,onInput:L=>{E.value=L.target.value},placeholder:"e.g. speed"})]})]}),e("h3",{children:"External Agent Lookup"}),e("div",{style:{display:"flex",gap:"var(--space-2)",alignItems:"flex-end"},children:[e("div",{class:"form-field",children:[e("label",{children:"Agent ID"}),e("input",{type:"text",value:G.value,onInput:L=>{G.value=L.target.value},placeholder:"Enter agent ID"})]}),e(P,{variant:"primary",onClick:ae,loading:V.value,children:"Query"})]}),I.value&&e("div",{style:{marginTop:"var(--space-3)",padding:"var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)"},children:[e("p",{children:e("strong",{children:["Agent #",I.value.agentId]})}),e("p",{children:["Score: ",Number(I.value.score)/Math.pow(10,I.value.decimals)]}),e("p",{children:["Feedback count: ",I.value.count]}),I.value.tag1&&e("p",{children:["Tag1: ",I.value.tag1]}),I.value.tag2&&e("p",{children:["Tag2: ",I.value.tag2]}),e(j,{variant:ce(Number(I.value.score)/Math.pow(10,I.value.decimals)),children:Number(I.value.score)/Math.pow(10,I.value.decimals)>=50?"Good":Number(I.value.score)/Math.pow(10,I.value.decimals)>=20?"Fair":"Low"})]})]})]}),a.value&&e("p",{class:"loading-text",children:"Loading..."}),e(Se,{open:u.value,title:"Register Agent",onConfirm:y,onCancel:()=>{u.value=!1},confirmText:"Register",loading:_.value,confirmDisabled:!d.value||!v.value,children:[e("div",{class:"form-field",children:[e("label",{children:"EVM Wallet"}),e("select",{value:d.value,onChange:L=>{d.value=L.target.value},children:[e("option",{value:"",children:"-- Select wallet --"}),Ae.map(L=>e("option",{value:L.id,children:[L.name," (",L.id.slice(0,8),"...)"]},L.id))]})]}),e("div",{class:"form-field",children:[e("label",{children:"Name"}),e("input",{type:"text",value:v.value,onInput:L=>{v.value=L.target.value},placeholder:"Agent name"})]}),e("div",{class:"form-field",children:[e("label",{children:"Description (optional)"}),e("input",{type:"text",value:h.value,onInput:L=>{h.value=L.target.value},placeholder:"Description"})]})]})]})}const Ie={grid:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(180px, 1fr))",gap:"var(--space-3)",marginBottom:"var(--space-4)"},card:{padding:"var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius)",border:"1px solid var(--color-border)"},label:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)",marginBottom:"var(--space-1)"},value:{fontSize:"var(--font-size-lg)",fontWeight:"var(--font-weight-semibold)"}};function Ns(t){return t<=.1?{label:"Safe",color:"var(--color-success)"}:t<=.3?{label:"Warning",color:"var(--color-warning)"}:{label:"Danger",color:"var(--color-danger)"}}function As({walletId:t}){const a=c(null),n=c(!1),l=c(null);if(X(()=>{t&&(n.value=!0,l.value=null,q(`/v1/wallets/${t}/hyperliquid/account`).then(v=>{a.value=v.state}).catch(v=>{l.value=v instanceof Error?v.message:"Failed to load account state"}).finally(()=>{n.value=!1}))},[t]),!t)return e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view Hyperliquid account"});if(n.value)return e("p",{children:"Loading account state..."});if(l.value)return e("p",{style:{color:"var(--color-danger)"},children:l.value});const i=a.value?.marginSummary??a.value?.crossMarginSummary;if(!i)return e("p",{style:{color:"var(--color-text-muted)"},children:"No account data available"});const r=parseFloat(i.accountValue??"0"),s=parseFloat(i.totalMarginUsed??"0"),o=r-s,u=r>0?s/r:0,d=Ns(u);return e("div",{style:Ie.grid,children:[e("div",{style:Ie.card,children:[e("div",{style:Ie.label,children:"Perp Equity"}),e("div",{style:Ie.value,children:["$",r.toFixed(2)]})]}),e("div",{style:Ie.card,children:[e("div",{style:Ie.label,children:"Margin Used"}),e("div",{style:Ie.value,children:["$",s.toFixed(2)]})]}),e("div",{style:Ie.card,children:[e("div",{style:Ie.label,children:"Available Margin"}),e("div",{style:Ie.value,children:["$",o.toFixed(2)]})]}),e("div",{style:Ie.card,children:[e("div",{style:Ie.label,children:"Margin Ratio"}),e("div",{style:{...Ie.value,color:d.color},children:[(u*100).toFixed(1),"% (",d.label,")"]})]})]})}const Pe={padding:"var(--space-2) var(--space-3)",textAlign:"right",whiteSpace:"nowrap"},Ge={...Pe,fontWeight:"var(--font-weight-semibold)",color:"var(--color-text-muted)",fontSize:"var(--font-size-sm)",borderBottom:"2px solid var(--color-border)"};function Es({walletId:t}){const a=c([]),n=c(!1),l=c(null),i=Fe(null),r=()=>{t&&q(`/v1/wallets/${t}/hyperliquid/positions`).then(s=>{a.value=s.positions,l.value=null}).catch(s=>{l.value=s instanceof Error?s.message:"Failed to load positions"}).finally(()=>{n.value=!1})};return X(()=>{if(t)return n.value=!0,r(),i.current=setInterval(r,1e4),()=>{i.current&&clearInterval(i.current)}},[t]),t?n.value?e("p",{children:"Loading positions..."}):l.value?e("p",{style:{color:"var(--color-danger)"},children:l.value}):a.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No open positions"}):e("div",{style:{overflowX:"auto"},children:e("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e("thead",{children:e("tr",{children:[e("th",{style:{...Ge,textAlign:"left"},children:"Market"}),e("th",{style:Ge,children:"Side"}),e("th",{style:Ge,children:"Size"}),e("th",{style:Ge,children:"Entry Price"}),e("th",{style:Ge,children:"Position Value"}),e("th",{style:Ge,children:"PnL"}),e("th",{style:Ge,children:"Leverage"}),e("th",{style:Ge,children:"Liquidation"})]})}),e("tbody",{children:a.value.map(s=>{const o=parseFloat(s.szi),u=o>0?"LONG":"SHORT",d=o>0?"var(--color-success)":"var(--color-danger)",v=parseFloat(s.unrealizedPnl??"0"),h=v>=0?"var(--color-success)":"var(--color-danger)";return e("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e("td",{style:{...Pe,textAlign:"left",fontWeight:"var(--font-weight-semibold)"},children:s.coin}),e("td",{style:{...Pe,color:d},children:u}),e("td",{style:Pe,children:Math.abs(o).toFixed(4)}),e("td",{style:Pe,children:s.entryPx?parseFloat(s.entryPx).toFixed(2):"-"}),e("td",{style:Pe,children:["$",s.positionValue?parseFloat(s.positionValue).toFixed(2):"-"]}),e("td",{style:{...Pe,color:h},children:[v>=0?"+":"",v.toFixed(2)]}),e("td",{style:Pe,children:[s.leverage?.value??"-","x"]}),e("td",{style:Pe,children:s.liquidationPx?parseFloat(s.liquidationPx).toFixed(2):"-"})]},s.coin)})})]})}):e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view positions"})}const Me={padding:"var(--space-2) var(--space-3)",textAlign:"right",whiteSpace:"nowrap"},je={...Me,fontWeight:"var(--font-weight-semibold)",color:"var(--color-text-muted)",fontSize:"var(--font-size-sm)",borderBottom:"2px solid var(--color-border)"};function Cs({walletId:t}){const a=c([]),n=c(!1),l=c(null);return X(()=>{t&&(n.value=!0,l.value=null,q(`/v1/wallets/${t}/hyperliquid/orders`).then(i=>{a.value=i.orders}).catch(i=>{l.value=i instanceof Error?i.message:"Failed to load orders"}).finally(()=>{n.value=!1}))},[t]),t?n.value?e("p",{children:"Loading orders..."}):l.value?e("p",{style:{color:"var(--color-danger)"},children:l.value}):a.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No open orders"}):e("div",{style:{overflowX:"auto"},children:e("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e("thead",{children:e("tr",{children:[e("th",{style:{...je,textAlign:"left"},children:"Market"}),e("th",{style:je,children:"Side"}),e("th",{style:je,children:"Type"}),e("th",{style:je,children:"Size"}),e("th",{style:je,children:"Price"}),e("th",{style:je,children:"Trigger"}),e("th",{style:je,children:"TIF"}),e("th",{style:je,children:"Created"})]})}),e("tbody",{children:a.value.map(i=>{const r=i.side==="B"||i.side==="BUY"?"var(--color-success)":"var(--color-danger)",s=i.side==="B"||i.side==="BUY"?"BUY":"SELL";return e("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e("td",{style:{...Me,textAlign:"left",fontWeight:"var(--font-weight-semibold)"},children:i.coin}),e("td",{style:{...Me,color:r},children:s}),e("td",{style:Me,children:i.orderType??"LIMIT"}),e("td",{style:Me,children:parseFloat(i.sz).toFixed(4)}),e("td",{style:Me,children:parseFloat(i.limitPx).toFixed(2)}),e("td",{style:Me,children:i.triggerPx?parseFloat(i.triggerPx).toFixed(2):"-"}),e("td",{style:Me,children:i.tif??"GTC"}),e("td",{style:Me,children:i.timestamp?new Date(i.timestamp).toLocaleString():"-"})]},i.oid)})})]})}):e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view orders"})}const xt={padding:"var(--space-2) var(--space-3)",textAlign:"right",whiteSpace:"nowrap"},Zt={...xt,fontWeight:"var(--font-weight-semibold)",color:"var(--color-text-muted)",fontSize:"var(--font-size-sm)",borderBottom:"2px solid var(--color-border)"};function Is({walletId:t}){const a=c([]),n=c(!1),l=c(null),i=Fe(null),r=()=>{t&&q(`/v1/wallets/${t}/hyperliquid/spot/balances`).then(s=>{const o=s.balances;a.value=o.filter(u=>parseFloat(u.total)!==0),l.value=null}).catch(s=>{l.value=s instanceof Error?s.message:"Failed to load spot balances"}).finally(()=>{n.value=!1})};return X(()=>{if(t)return n.value=!0,r(),i.current=setInterval(r,1e4),()=>{i.current&&clearInterval(i.current)}},[t]),t?n.value?e("p",{children:"Loading spot balances..."}):l.value?e("p",{style:{color:"var(--color-danger)"},children:l.value}):a.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No spot balances"}):e("div",{style:{overflowX:"auto"},children:e("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e("thead",{children:e("tr",{children:[e("th",{style:{...Zt,textAlign:"left"},children:"Token"}),e("th",{style:Zt,children:"Total"}),e("th",{style:Zt,children:"Hold"}),e("th",{style:Zt,children:"Available"})]})}),e("tbody",{children:a.value.map(s=>{const o=parseFloat(s.total),u=parseFloat(s.hold),d=o-u;return e("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e("td",{style:{...xt,textAlign:"left",fontWeight:"var(--font-weight-semibold)"},children:s.coin}),e("td",{style:xt,children:o.toFixed(4)}),e("td",{style:xt,children:u>0?u.toFixed(4):"-"}),e("td",{style:xt,children:d.toFixed(4)})]},s.coin)})})]})}):e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view spot balances"})}const Ye={padding:"var(--space-2) var(--space-3)",textAlign:"right",whiteSpace:"nowrap"},rt={...Ye,fontWeight:"var(--font-weight-semibold)",color:"var(--color-text-muted)",fontSize:"var(--font-size-sm)",borderBottom:"2px solid var(--color-border)"};function xs({walletId:t}){const a=c([]),n=c(!1),l=c(null);return X(()=>{t&&(n.value=!0,l.value=null,q(`/v1/wallets/${t}/hyperliquid/orders`).then(i=>{const r=i.orders;a.value=r.filter(s=>s.coin.includes("/"))}).catch(i=>{l.value=i instanceof Error?i.message:"Failed to load spot orders"}).finally(()=>{n.value=!1}))},[t]),t?n.value?e("p",{children:"Loading spot orders..."}):l.value?e("p",{style:{color:"var(--color-danger)"},children:l.value}):a.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No spot orders"}):e("div",{style:{overflowX:"auto"},children:e("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e("thead",{children:e("tr",{children:[e("th",{style:{...rt,textAlign:"left"},children:"Market"}),e("th",{style:rt,children:"Side"}),e("th",{style:rt,children:"Type"}),e("th",{style:rt,children:"Size"}),e("th",{style:rt,children:"Price"}),e("th",{style:rt,children:"TIF"}),e("th",{style:rt,children:"Created"})]})}),e("tbody",{children:a.value.map(i=>{const r=i.side==="B"||i.side==="BUY"?"var(--color-success)":"var(--color-danger)",s=i.side==="B"||i.side==="BUY"?"BUY":"SELL";return e("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e("td",{style:{...Ye,textAlign:"left",fontWeight:"var(--font-weight-semibold)"},children:i.coin}),e("td",{style:{...Ye,color:r},children:s}),e("td",{style:Ye,children:i.orderType??"LIMIT"}),e("td",{style:Ye,children:parseFloat(i.sz).toFixed(4)}),e("td",{style:Ye,children:parseFloat(i.limitPx).toFixed(2)}),e("td",{style:Ye,children:i.tif??"GTC"}),e("td",{style:Ye,children:i.timestamp?new Date(i.timestamp).toLocaleString():"-"})]},i.oid)})})]})}):e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view spot orders"})}const Ua={padding:"var(--space-2) var(--space-3)",textAlign:"left",whiteSpace:"nowrap"},Un={...Ua,fontWeight:"var(--font-weight-semibold)",color:"var(--color-text-muted)",fontSize:"var(--font-size-sm)",borderBottom:"2px solid var(--color-border)"};function Ds({walletId:t,onSelect:a}){const n=c([]),l=c(!1),i=c(null),r=Fe(null),s=()=>{t&&q(`/v1/wallets/${t}/hyperliquid/sub-accounts`).then(o=>{n.value=o.subAccounts??[],i.value=null}).catch(o=>{i.value=o instanceof Error?o.message:"Failed to load sub-accounts"}).finally(()=>{l.value=!1})};return X(()=>{if(t)return l.value=!0,s(),r.current=setInterval(s,1e4),()=>{r.current&&clearInterval(r.current)}},[t]),t?l.value?e("p",{children:"Loading sub-accounts..."}):i.value?e("p",{style:{color:"var(--color-danger)"},children:i.value}):n.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No sub-accounts found"}):e("div",{style:{overflowX:"auto"},children:e("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e("thead",{children:e("tr",{children:[e("th",{style:Un,children:"Name"}),e("th",{style:Un,children:"Address"})]})}),e("tbody",{children:n.value.map(o=>e("tr",{style:{borderBottom:"1px solid var(--color-border)",cursor:a?"pointer":"default"},onClick:()=>a?.(o.subAccountUser),children:[e("td",{style:{...Ua,fontWeight:"var(--font-weight-semibold)"},children:o.name||"(unnamed)"}),e("td",{style:{...Ua,fontFamily:"var(--font-mono)",fontSize:"var(--font-size-sm)"},children:[o.subAccountUser.slice(0,6),"...",o.subAccountUser.slice(-4)]})]},o.subAccountUser))})]})}):e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view sub-accounts"})}const Xe={padding:"var(--space-2) var(--space-3)",textAlign:"right",whiteSpace:"nowrap"},st={...Xe,fontWeight:"var(--font-weight-semibold)",color:"var(--color-text-muted)",fontSize:"var(--font-size-sm)",borderBottom:"2px solid var(--color-border)"};function Ls({walletId:t,subAccountAddress:a}){const n=c([]),l=c(!1),i=c(null),r=Fe(null),s=()=>{!t||!a||q(`/v1/wallets/${t}/hyperliquid/sub-accounts/${a}/positions`).then(o=>{n.value=o.positions??[],i.value=null}).catch(o=>{i.value=o instanceof Error?o.message:"Failed to load positions"}).finally(()=>{l.value=!1})};return X(()=>{if(!(!t||!a))return l.value=!0,s(),r.current=setInterval(s,1e4),()=>{r.current&&clearInterval(r.current)}},[t,a]),l.value?e("p",{children:"Loading positions..."}):i.value?e("p",{style:{color:"var(--color-danger)"},children:i.value}):n.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No open positions for this sub-account"}):e("div",{style:{overflowX:"auto"},children:[e("h4",{style:{marginBottom:"var(--space-2)"},children:["Positions for ",a.slice(0,6),"...",a.slice(-4)]}),e("table",{style:{width:"100%",borderCollapse:"collapse"},children:[e("thead",{children:e("tr",{children:[e("th",{style:{...st,textAlign:"left"},children:"Market"}),e("th",{style:st,children:"Side"}),e("th",{style:st,children:"Size"}),e("th",{style:st,children:"Entry Price"}),e("th",{style:st,children:"PnL"}),e("th",{style:st,children:"Leverage"}),e("th",{style:st,children:"Liq. Price"})]})}),e("tbody",{children:n.value.map(o=>{const u=parseFloat(o.szi),d=u>0?"LONG":"SHORT",v=o.unrealizedPnl?parseFloat(o.unrealizedPnl):0;return e("tr",{style:{borderBottom:"1px solid var(--color-border)"},children:[e("td",{style:{...Xe,textAlign:"left",fontWeight:"var(--font-weight-semibold)"},children:o.coin}),e("td",{style:{...Xe,color:d==="LONG"?"var(--color-success)":"var(--color-danger)"},children:d}),e("td",{style:Xe,children:Math.abs(u).toFixed(4)}),e("td",{style:Xe,children:o.entryPx??"-"}),e("td",{style:{...Xe,color:v>=0?"var(--color-success)":"var(--color-danger)"},children:[v>=0?"+":"",v.toFixed(2)]}),e("td",{style:Xe,children:o.leverage?`${o.leverage.value}x`:"-"}),e("td",{style:Xe,children:o.liquidationPx??"-"})]},o.coin)})})]})]})}const $n=[{key:"actions.hyperliquid_enabled",label:"Enabled",type:"toggle"},{key:"actions.hyperliquid_network",label:"Network",type:"select",options:["mainnet","testnet"]},{key:"actions.hyperliquid_api_url",label:"API URL Override",type:"text",placeholder:"Leave empty for default"},{key:"actions.hyperliquid_rate_limit_weight_per_min",label:"Rate Limit (weight/min)",type:"number"},{key:"actions.hyperliquid_default_leverage",label:"Default Leverage",type:"number"},{key:"actions.hyperliquid_default_margin_mode",label:"Default Margin Mode",type:"select",options:["CROSS","ISOLATED"]},{key:"actions.hyperliquid_builder_address",label:"Builder Address",type:"text",placeholder:"0x..."},{key:"actions.hyperliquid_builder_fee",label:"Builder Fee (bps)",type:"number"},{key:"actions.hyperliquid_order_status_poll_interval_ms",label:"Order Poll Interval (ms)",type:"number"}];function Rs(){const t=c({}),a=c(!0),n=c(!1);X(()=>{q("/v1/admin/settings").then(r=>{const s=r;t.value=s.settings??{}}).catch(()=>{m("Failed to load settings","error")}).finally(()=>{a.value=!1})},[]);const l=(r,s)=>{t.value={...t.value,[r]:s}},i=async()=>{n.value=!0;try{const r={};for(const s of $n)t.value[s.key]!==void 0&&(r[s.key]=t.value[s.key]);await oe("/v1/admin/settings",{settings:r}),m("Hyperliquid settings saved","success")}catch{m("Failed to save settings","error")}finally{n.value=!1}};return a.value?e("p",{children:"Loading settings..."}):e("div",{children:[$n.map(r=>{const s=t.value[r.key]??"";return r.type==="toggle"?e(k,{label:r.label,children:e("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:s==="true",onChange:o=>l(r.key,o.target.checked?"true":"false")}),s==="true"?"Enabled":"Disabled"]})},r.key):r.type==="select"&&"options"in r?e(k,{label:r.label,children:e("select",{class:"form-input",value:s,onChange:o=>l(r.key,o.target.value),children:r.options.map(o=>e("option",{value:o,children:o},o))})},r.key):e(k,{label:r.label,children:e("input",{type:r.type==="number"?"number":"text",class:"form-input",value:s,placeholder:"placeholder"in r?r.placeholder:"",onInput:o=>l(r.key,o.target.value)})},r.key)}),e("div",{style:{marginTop:"var(--space-4)"},children:e(P,{onClick:i,disabled:n.value,children:n.value?"Saving...":"Save Settings"})})]})}const Os={display:"flex",gap:"var(--space-1)",marginBottom:"var(--space-4)",borderBottom:"1px solid var(--color-border)",paddingBottom:"var(--space-1)"},At=t=>({padding:"var(--space-2) var(--space-3)",border:"none",background:"none",cursor:"pointer",fontWeight:t?"var(--font-weight-semibold)":"var(--font-weight-normal)",color:t?"var(--color-primary)":"var(--color-text-muted)",borderBottom:t?"2px solid var(--color-primary)":"2px solid transparent",marginBottom:"-1px"});function Ps(){const t=c([]),a=c(null),n=c("overview"),l=c(null),i=c(!0);return X(()=>{q("/v1/wallets").then(r=>{const o=(r.wallets??[]).filter(u=>u.chain==="ethereum");t.value=o,o.length>0&&!a.value&&(a.value=o[0].id)}).catch(()=>{}).finally(()=>{i.value=!1})},[]),i.value?e("p",{children:"Loading..."}):e("div",{children:[e("div",{style:{marginBottom:"var(--space-4)"},children:[e("label",{style:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)",marginRight:"var(--space-2)"},children:"Wallet:"}),e("select",{class:"form-input",style:{width:"auto",display:"inline-block",minWidth:"200px"},value:a.value??"",onChange:r=>{a.value=r.target.value||null},children:[t.value.length===0&&e("option",{value:"",children:"No EVM wallets available"}),t.value.map(r=>e("option",{value:r.id,children:[r.name," (",r.network,")"]},r.id))]})]}),e("div",{style:Os,children:[e("button",{style:At(n.value==="overview"),onClick:()=>{n.value="overview"},children:"Overview"}),e("button",{style:At(n.value==="orders"),onClick:()=>{n.value="orders"},children:"Orders"}),e("button",{style:At(n.value==="spot"),onClick:()=>{n.value="spot"},children:"Spot"}),e("button",{style:At(n.value==="subaccounts"),onClick:()=>{n.value="subaccounts",l.value=null},children:"Sub-accounts"}),e("button",{style:At(n.value==="settings"),onClick:()=>{n.value="settings"},children:"Settings"})]}),n.value==="overview"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Account Summary"}),e(As,{walletId:a.value}),e("h3",{style:{marginBottom:"var(--space-3)"},children:"Positions"}),e(Es,{walletId:a.value})]}),n.value==="orders"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Open Orders"}),e(Cs,{walletId:a.value})]}),n.value==="spot"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Spot Balances"}),e(Is,{walletId:a.value}),e("h3",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-3)"},children:"Spot Orders"}),e(xs,{walletId:a.value})]}),n.value==="subaccounts"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Sub-accounts"}),e(Ds,{walletId:a.value,onSelect:r=>{l.value=r}}),l.value&&e("div",{style:{marginTop:"var(--space-4)"},children:e(Ls,{walletId:a.value,subAccountAddress:l.value})})]}),n.value==="settings"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Hyperliquid Settings"}),e(Rs,{})]})]})}function Ms({walletId:t}){const a=c(null),n=c(null),l=c([]),i=c(!0);if(X(()=>{if(!t){i.value=!1;return}i.value=!0,Promise.all([q(`/v1/wallets/${t}/polymarket/pnl`).catch(()=>null),q(`/v1/wallets/${t}/polymarket/balance`).catch(()=>null),q(`/v1/wallets/${t}/polymarket/orders`).catch(()=>({orders:[]}))]).then(([s,o,u])=>{a.value=s,n.value=o;const d=u;l.value=(d?.orders??[]).slice(0,5)}).finally(()=>{i.value=!1})},[t]),i.value)return e("p",{children:"Loading..."});if(!t)return e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view overview."});const r=a.value?.pnl;return e("div",{children:[e("div",{style:{display:"grid",gridTemplateColumns:"repeat(3, 1fr)",gap:"var(--space-3)",marginBottom:"var(--space-4)"},children:[e("div",{class:"card",style:{padding:"var(--space-3)"},children:[e("div",{style:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)"},children:"Active Positions"}),e("div",{style:{fontSize:"var(--font-size-xl)",fontWeight:"var(--font-weight-semibold)"},children:r?.positionCount??0})]}),e("div",{class:"card",style:{padding:"var(--space-3)"},children:[e("div",{style:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)"},children:"Unrealized PnL"}),e("div",{style:{fontSize:"var(--font-size-xl)",fontWeight:"var(--font-weight-semibold)"},children:r?.totalUnrealized??"0"})]}),e("div",{class:"card",style:{padding:"var(--space-3)"},children:[e("div",{style:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)"},children:"CTF Tokens"}),e("div",{style:{fontSize:"var(--font-size-xl)",fontWeight:"var(--font-weight-semibold)"},children:n.value?.tokenCount??0})]})]}),e("h4",{style:{marginBottom:"var(--space-2)"},children:"Recent Orders"}),l.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No Polymarket activity. Use pm_setup to create API keys."}):e("table",{class:"table",style:{width:"100%"},children:[e("thead",{children:e("tr",{children:[e("th",{children:"Side"}),e("th",{children:"Outcome"}),e("th",{children:"Price"}),e("th",{children:"Size"}),e("th",{children:"Status"})]})}),e("tbody",{children:l.value.map((s,o)=>{const u=s;return e("tr",{children:[e("td",{children:String(u.side??"")}),e("td",{children:String(u.outcome??"")}),e("td",{children:String(u.price??"")}),e("td",{children:String(u.size??"")}),e("td",{children:String(u.status??"")})]},o)})})]})]})}function Ws(){const t=c([]),a=c(!0),n=c(""),l=c(""),i=c(null),r=(u,d)=>{a.value=!0;const v=new URLSearchParams;u&&v.set("keyword",u),d&&v.set("category",d);const h=v.toString(),_=`/v1/polymarket/markets${h?`?${h}`:""}`;q(_).then(A=>{const $=A;t.value=$.markets??[]}).catch(()=>{t.value=[]}).finally(()=>{a.value=!1})};X(()=>{r()},[]);const s=u=>{n.value=u,i.value&&clearTimeout(i.value),i.value=setTimeout(()=>{r(u,l.value)},300)},o=u=>{l.value=u,r(n.value,u)};return a.value&&t.value.length===0?e("p",{children:"Loading markets..."}):e("div",{children:[e("div",{style:{display:"flex",gap:"var(--space-3)",marginBottom:"var(--space-3)"},children:[e("input",{type:"text",class:"form-input",placeholder:"Search markets...",value:n.value,onInput:u=>s(u.target.value),style:{flex:1}}),e("select",{class:"form-input",style:{width:"auto",minWidth:"150px"},value:l.value,onChange:u=>o(u.target.value),children:[e("option",{value:"",children:"All Categories"}),e("option",{value:"politics",children:"Politics"}),e("option",{value:"crypto",children:"Crypto"}),e("option",{value:"sports",children:"Sports"}),e("option",{value:"science",children:"Science"}),e("option",{value:"culture",children:"Culture"})]})]}),t.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No markets found."}):e("table",{class:"table",style:{width:"100%"},children:[e("thead",{children:e("tr",{children:[e("th",{children:"Question"}),e("th",{children:"Volume"}),e("th",{children:"Liquidity"}),e("th",{children:"End Date"})]})}),e("tbody",{children:t.value.map(u=>e("tr",{children:[e("td",{style:{maxWidth:"400px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:u.question}),e("td",{children:u.volume}),e("td",{children:u.liquidity}),e("td",{children:u.endDate})]},u.conditionId))})]})]})}function Us({walletId:t}){const a=c([]),n=c(!0),l=c("ALL"),i=s=>{if(!t){n.value=!1;return}n.value=!0;const o=s&&s!=="ALL"?`?status=${s}`:"";q(`/v1/wallets/${t}/polymarket/orders${o}`).then(u=>{const d=u;a.value=d.orders??[]}).catch(()=>{a.value=[]}).finally(()=>{n.value=!1})};X(()=>{i(l.value)},[t]);const r=s=>{l.value=s,i(s)};return t?n.value?e("p",{children:"Loading orders..."}):e("div",{children:[e("div",{style:{marginBottom:"var(--space-3)"},children:[e("label",{style:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)",marginRight:"var(--space-2)"},children:"Status:"}),e("select",{class:"form-input",style:{width:"auto",display:"inline-block",minWidth:"120px"},value:l.value,onChange:s=>r(s.target.value),children:[e("option",{value:"ALL",children:"All"}),e("option",{value:"LIVE",children:"Live"}),e("option",{value:"MATCHED",children:"Matched"}),e("option",{value:"CANCELLED",children:"Cancelled"})]})]}),a.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No orders found."}):e("table",{class:"table",style:{width:"100%"},children:[e("thead",{children:e("tr",{children:[e("th",{children:"Market"}),e("th",{children:"Side"}),e("th",{children:"Type"}),e("th",{children:"Price"}),e("th",{children:"Size"}),e("th",{children:"Status"}),e("th",{children:"Created"})]})}),e("tbody",{children:a.value.map(s=>e("tr",{children:[e("td",{style:{maxWidth:"250px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:s.market}),e("td",{children:s.side}),e("td",{children:s.type}),e("td",{children:s.price}),e("td",{children:s.size}),e("td",{children:s.status}),e("td",{children:s.createdAt})]},s.id))})]})]}):e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view orders."})}function $s({walletId:t}){const a=c([]),n=c(!0);if(X(()=>{if(!t){n.value=!1;return}n.value=!0,q(`/v1/wallets/${t}/polymarket/positions`).then(r=>{const s=r;a.value=s.positions??[]}).catch(()=>{a.value=[]}).finally(()=>{n.value=!1})},[t]),!t)return e("p",{style:{color:"var(--color-text-muted)"},children:"Select a wallet to view positions."});if(n.value)return e("p",{children:"Loading positions..."});const l=a.value.filter(r=>!r.resolved),i=a.value.filter(r=>r.resolved);return a.value.length===0?e("p",{style:{color:"var(--color-text-muted)"},children:"No positions."}):e("div",{children:[l.length>0&&e("div",{style:{marginBottom:"var(--space-4)"},children:[e("h4",{style:{marginBottom:"var(--space-2)"},children:"Active Positions"}),e("table",{class:"table",style:{width:"100%"},children:[e("thead",{children:e("tr",{children:[e("th",{children:"Market"}),e("th",{children:"Outcome"}),e("th",{children:"Size"}),e("th",{children:"Avg Price"}),e("th",{children:"Current"}),e("th",{children:"Unrealized PnL"})]})}),e("tbody",{children:l.map(r=>e("tr",{children:[e("td",{style:{maxWidth:"250px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.market}),e("td",{children:r.outcome}),e("td",{children:r.size}),e("td",{children:r.avgPrice}),e("td",{children:r.currentPrice}),e("td",{children:r.unrealizedPnl})]},`${r.conditionId}-${r.outcome}`))})]})]}),i.length>0&&e("div",{children:[e("h4",{style:{marginBottom:"var(--space-2)"},children:"Resolved Markets"}),e("table",{class:"table",style:{width:"100%"},children:[e("thead",{children:e("tr",{children:[e("th",{children:"Market"}),e("th",{children:"Outcome"}),e("th",{children:"Size"}),e("th",{children:"PnL"}),e("th",{children:"Redeemable"})]})}),e("tbody",{children:i.map(r=>e("tr",{children:[e("td",{style:{maxWidth:"250px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:r.market}),e("td",{children:r.outcome}),e("td",{children:r.size}),e("td",{children:r.unrealizedPnl}),e("td",{children:r.redeemable?"Yes":"No"})]},`${r.conditionId}-${r.outcome}`))})]})]})]})}const Fn=[{key:"actions.polymarket_enabled",label:"Enabled",type:"toggle"},{key:"actions.polymarket_default_fee_bps",label:"Default Fee (bps)",type:"number"},{key:"actions.polymarket_order_expiry_seconds",label:"Order Expiry (seconds)",type:"number"},{key:"actions.polymarket_max_position_usdc",label:"Max Position (USDC)",type:"number"},{key:"actions.polymarket_proxy_wallet",label:"Proxy Wallet",type:"toggle"},{key:"actions.polymarket_neg_risk_enabled",label:"Neg Risk Enabled",type:"toggle"},{key:"actions.polymarket_auto_approve_ctf",label:"Auto Approve CTF",type:"toggle"}];function Fs(){const t=c({}),a=c(!0),n=c(!1);X(()=>{q("/v1/admin/settings").then(r=>{const s=r;t.value=s.settings??{}}).catch(()=>{m("Failed to load settings","error")}).finally(()=>{a.value=!1})},[]);const l=(r,s)=>{t.value={...t.value,[r]:s}},i=async()=>{n.value=!0;try{const r={};for(const s of Fn)t.value[s.key]!==void 0&&(r[s.key]=t.value[s.key]);await oe("/v1/admin/settings",{settings:r}),m("Polymarket settings saved","success")}catch{m("Failed to save settings","error")}finally{n.value=!1}};return a.value?e("p",{children:"Loading settings..."}):e("div",{children:[Fn.map(r=>{const s=t.value[r.key]??"";return r.type==="toggle"?e(k,{label:r.label,children:e("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:s==="true",onChange:o=>l(r.key,o.target.checked?"true":"false")}),s==="true"?"Enabled":"Disabled"]})},r.key):e(k,{label:r.label,children:e("input",{type:"number",class:"form-input",value:s,onInput:o=>l(r.key,o.target.value)})},r.key)}),e("div",{style:{marginTop:"var(--space-4)"},children:e(P,{onClick:i,disabled:n.value,children:n.value?"Saving...":"Save Settings"})})]})}const Bs={display:"flex",gap:"var(--space-1)",marginBottom:"var(--space-4)",borderBottom:"1px solid var(--color-border)",paddingBottom:"var(--space-1)"},Et=t=>({padding:"var(--space-2) var(--space-3)",border:"none",background:"none",cursor:"pointer",fontWeight:t?"var(--font-weight-semibold)":"var(--font-weight-normal)",color:t?"var(--color-primary)":"var(--color-text-muted)",borderBottom:t?"2px solid var(--color-primary)":"2px solid transparent",marginBottom:"-1px"});function zs(){const t=c([]),a=c(null),n=c("overview"),l=c(!0);return X(()=>{q("/v1/wallets").then(i=>{const s=(i.wallets??[]).filter(o=>o.chain==="ethereum"&&o.network.includes("polygon"));t.value=s,s.length>0&&!a.value&&(a.value=s[0].id)}).catch(()=>{}).finally(()=>{l.value=!1})},[]),l.value?e("p",{children:"Loading..."}):e("div",{children:[e("div",{style:{marginBottom:"var(--space-4)"},children:[e("label",{style:{fontSize:"var(--font-size-sm)",color:"var(--color-text-muted)",marginRight:"var(--space-2)"},children:"Wallet:"}),e("select",{class:"form-input",style:{width:"auto",display:"inline-block",minWidth:"200px"},value:a.value??"",onChange:i=>{a.value=i.target.value||null},children:[t.value.length===0&&e("option",{value:"",children:"No Polygon wallets available"}),t.value.map(i=>e("option",{value:i.id,children:[i.name," (",i.network,")"]},i.id))]})]}),e("div",{style:Bs,children:[e("button",{style:Et(n.value==="overview"),onClick:()=>{n.value="overview"},children:"Overview"}),e("button",{style:Et(n.value==="markets"),onClick:()=>{n.value="markets"},children:"Markets"}),e("button",{style:Et(n.value==="orders"),onClick:()=>{n.value="orders"},children:"Orders"}),e("button",{style:Et(n.value==="positions"),onClick:()=>{n.value="positions"},children:"Positions"}),e("button",{style:Et(n.value==="settings"),onClick:()=>{n.value="settings"},children:"Settings"})]}),n.value==="overview"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Overview"}),e(Ms,{walletId:a.value})]}),n.value==="markets"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Markets"}),e(Ws,{})]}),n.value==="orders"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Orders"}),e(Us,{walletId:a.value})]}),n.value==="positions"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Positions"}),e($s,{walletId:a.value})]}),n.value==="settings"&&e("div",{children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Polymarket Settings"}),e(Fs,{})]})]})}const Hs=50,Ks=[{value:"WALLET_CREATED",label:"Wallet Created"},{value:"WALLET_SUSPENDED",label:"Wallet Suspended"},{value:"WALLET_PURGED",label:"Wallet Purged"},{value:"SESSION_CREATED",label:"Session Created"},{value:"SESSION_REVOKED",label:"Session Revoked"},{value:"SESSION_ISSUED_VIA_TELEGRAM",label:"Session Issued via Telegram"},{value:"TX_SUBMITTED",label:"TX Submitted"},{value:"TX_CONFIRMED",label:"TX Confirmed"},{value:"TX_FAILED",label:"TX Failed"},{value:"TX_APPROVED_VIA_TELEGRAM",label:"TX Approved via Telegram"},{value:"TX_REJECTED_VIA_TELEGRAM",label:"TX Rejected via Telegram"},{value:"TX_CANCELLED_VIA_TELEGRAM",label:"TX Cancelled via Telegram"},{value:"UNLISTED_TOKEN_TRANSFER",label:"Unlisted Token Transfer"},{value:"POLICY_DENIED",label:"Policy Denied"},{value:"KILL_SWITCH_ACTIVATED",label:"Kill Switch Activated"},{value:"KILL_SWITCH_ESCALATED",label:"Kill Switch Escalated"},{value:"KILL_SWITCH_RECOVERED",label:"Kill Switch Recovered"},{value:"AUTO_STOP_TRIGGERED",label:"Auto Stop Triggered"},{value:"MASTER_AUTH_FAILED",label:"Master Auth Failed"},{value:"OWNER_REGISTERED",label:"Owner Registered"},{value:"PROVIDER_UPDATED",label:"Provider Updated"},{value:"NOTIFICATION_TOTAL_FAILURE",label:"Notification Total Failure"},{value:"USEROP_BUILD",label:"UserOp Build"},{value:"USEROP_SIGNED",label:"UserOp Signed"}],Vs=[{value:"info",label:"Info"},{value:"warning",label:"Warning"},{value:"critical",label:"Critical"}],qs=[{key:"event_type",label:"Event Type",type:"select",options:Ks},{key:"severity",label:"Severity",type:"select",options:Vs},{key:"from",label:"From",type:"date"},{key:"to",label:"To",type:"date"}];function Bn(t){return t==="critical"?"danger":t==="warning"?"warning":"info"}function Gs(){const t=c([]),a=c(!0),n=c({event_type:"",severity:"",from:"",to:""}),l=c([]),i=c(void 0),r=c(null),s=c(!1),o=c(void 0),u=c(!1),d=c(null),v=async()=>{a.value=!0;try{const N=new URLSearchParams;N.set("limit",String(Hs)),N.set("include_total","true"),i.value!==void 0&&N.set("cursor",String(i.value));const E=n.value;if(E.event_type&&N.set("event_type",E.event_type),E.severity&&N.set("severity",E.severity),E.from){const V=new Date(E.from);N.set("from",String(Math.floor(V.getTime()/1e3)))}if(E.to){const V=new Date(E.to);N.set("to",String(Math.floor(V.getTime()/1e3)+86399))}const G=`${D.ADMIN_AUDIT_LOGS}?${N.toString()}`,I=await q(G);t.value=I.data,r.value=I.nextCursor,s.value=I.hasMore,I.total!==void 0&&(o.value=I.total)}catch(N){const E=N instanceof b?N:new b(0,"UNKNOWN","Unknown error");m("error",z(E.code))}finally{a.value=!1}};X(()=>{v()},[n.value,i.value]);const h=N=>{n.value=N,l.value=[],i.value=void 0,r.value=null},_=()=>{r.value!==null&&(l.value=[...l.value,i.value??0],i.value=r.value)},A=()=>{if(l.value.length===0)return;const N=[...l.value],E=N.pop();l.value=N,i.value=E===0?void 0:E},$=N=>{d.value=N,u.value=!0},W=l.value.length+1,f=[{key:"timestamp",header:"Time",render:N=>_e(N.timestamp)},{key:"eventType",header:"Event",render:N=>N.eventType.replace(/_/g," ")},{key:"severity",header:"Severity",render:N=>e(j,{variant:Bn(N.severity),children:N.severity.toUpperCase()})},{key:"actor",header:"Actor",render:N=>N.actor},{key:"walletId",header:"Wallet",render:N=>N.walletId?N.walletId.slice(0,8)+"...":"-"},{key:"txId",header:"TX",render:N=>N.txId?N.txId.slice(0,8)+"...":"-"},{key:"ipAddress",header:"IP",render:N=>N.ipAddress??"-"}];return e("div",{class:"page",children:[e(Bt,{fields:qs,values:n.value,onChange:h}),o.value!==void 0&&!a.value&&e("div",{style:{marginBottom:"var(--space-2)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:[o.value," total log",o.value!==1?"s":""]}),e(De,{columns:f,data:t.value,loading:a.value,emptyMessage:"No audit logs found",onRowClick:$}),!a.value&&t.value.length>0&&e("div",{class:"pagination-controls",style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginTop:"var(--space-3)"},children:[e(P,{variant:"secondary",size:"sm",disabled:l.value.length===0,onClick:A,children:"Previous"}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:["Page ",W]}),e(P,{variant:"secondary",size:"sm",disabled:!s.value,onClick:_,children:"Next"})]}),e(Se,{open:u.value,title:"Audit Log Detail",onCancel:()=>{u.value=!1},cancelText:"Close",children:d.value&&e("div",{class:"audit-detail",children:[e("div",{class:"audit-detail-fields",style:{display:"grid",gridTemplateColumns:"120px 1fr",gap:"var(--space-2)",marginBottom:"var(--space-3)"},children:[e("strong",{children:"Time"}),e("span",{children:_e(d.value.timestamp)}),e("strong",{children:"Event"}),e("span",{children:d.value.eventType}),e("strong",{children:"Severity"}),e("span",{children:e(j,{variant:Bn(d.value.severity),children:d.value.severity.toUpperCase()})}),e("strong",{children:"Actor"}),e("span",{children:d.value.actor}),e("strong",{children:"Wallet ID"}),e("span",{children:d.value.walletId??"-"}),e("strong",{children:"Session ID"}),e("span",{children:d.value.sessionId??"-"}),e("strong",{children:"TX ID"}),e("span",{children:d.value.txId??"-"}),e("strong",{children:"IP Address"}),e("span",{children:d.value.ipAddress??"-"})]}),e("div",{children:[e("strong",{style:{display:"block",marginBottom:"var(--space-1)"},children:"Details"}),e("pre",{style:{background:"var(--color-bg-secondary)",padding:"var(--space-2)",borderRadius:"var(--radius-md)",overflow:"auto",maxHeight:"300px",fontSize:"0.8rem"},children:JSON.stringify(d.value.details,null,2)})]})]})})]})}function wl(t){const a=t.slice(1)||"/dashboard",n=a.indexOf("?");return n>=0?a.slice(0,n):a}const Je=Ne(wl(window.location.hash)),Qt=Ne(!1);window.addEventListener("hashchange",()=>{Je.value=wl(window.location.hash)});const js={"/dashboard":"Dashboard","/wallets":"Wallets","/transactions":"Transactions","/sessions":"Sessions","/tokens":"Token Registry","/defi":"DeFi","/hyperliquid":"Hyperliquid","/polymarket":"Polymarket","/agent-identity":"Agent Identity","/policies":"Policies","/notifications":"Notifications","/security":"Security","/wallet-apps":"Human Wallet Apps","/audit-logs":"Audit Logs","/system":"System"},Ys={"/dashboard":"System overview and key metrics","/wallets":"Manage wallets, balances, and connections","/transactions":"View all transactions and configure incoming monitoring","/sessions":"View and manage active sessions","/tokens":"Manage EVM token registry per network","/defi":"Manage DeFi action providers and API keys","/hyperliquid":"Hyperliquid perpetual trading positions, orders, and settings","/polymarket":"Polymarket prediction market positions, orders, and settings","/agent-identity":"On-chain agent identity, reputation, and wallet linking","/policies":"Configure transaction policies and rules","/notifications":"Channel status, delivery logs, and settings","/security":"Emergency controls and automatic protection rules","/wallet-apps":"Manage wallet apps for signing and notifications","/audit-logs":"View security and operational audit events","/system":"API keys, display preferences, and daemon configuration"};function Xs(t){return t.startsWith("/wallets/")?"Wallet Detail":js[t]??"Dashboard"}function zn(t){return Ys[t]}const Js=[{path:"/dashboard",label:"Dashboard"},{path:"/wallets",label:"Wallets"},{path:"/transactions",label:"Transactions"},{path:"/sessions",label:"Sessions"},{path:"/tokens",label:"Tokens"},{path:"/defi",label:"DeFi"},{path:"/hyperliquid",label:"Hyperliquid"},{path:"/polymarket",label:"Polymarket"},{path:"/agent-identity",label:"Agent Identity"},{path:"/policies",label:"Policies"},{path:"/notifications",label:"Notifications"},{path:"/wallet-apps",label:"Human Wallet Apps"},{path:"/security",label:"Security"},{path:"/audit-logs",label:"Audit Logs"},{path:"/system",label:"System"}];function Zs(){const t=Je.value;return t==="/transactions"?e(Tn,{}):t==="/incoming"?(window.location.hash="#/transactions",e(Tn,{})):t==="/tokens"?e(Cr,{}):t==="/defi"?e(Pn,{}):t==="/actions"?(window.location.hash="#/defi",e(Pn,{})):t==="/hyperliquid"?e(Ps,{}):t==="/polymarket"?e(zs,{}):t==="/sessions"?e(Dr,{}):t==="/policies"?e(os,{}):t==="/notifications"?e(Rn,{}):t==="/telegram-users"?(window.location.hash="#/notifications",e(Rn,{})):t==="/settings"?(window.location.hash="#/dashboard",e(pn,{})):t==="/walletconnect"?(window.location.hash="#/wallets",e(_n,{})):t==="/security"?e(ys,{}):t==="/wallet-apps"?e(ks,{}):t==="/agent-identity"?e(Wn,{}):t==="/erc8004"?(window.location.hash="#/agent-identity",e(Wn,{})):t==="/audit-logs"?e(Gs,{}):t==="/system"?e(Ss,{}):t.startsWith("/wallets")?e(_n,{}):e(pn,{})}function Qs(){return X(()=>{const t=a=>{(a.metaKey||a.ctrlKey)&&a.key==="k"&&(a.preventDefault(),Qt.value=!Qt.value)};return document.addEventListener("keydown",t),()=>document.removeEventListener("keydown",t)},[]),e("div",{class:"layout",children:[e("aside",{class:"sidebar",children:[e("div",{class:"sidebar-brand",children:"WAIaaS"}),e("nav",{class:"sidebar-nav",children:Js.map(t=>{const a=t.path==="/wallets"?Je.value.startsWith("/wallets"):Je.value===t.path;return e("a",{href:`#${t.path}`,class:`sidebar-link ${a?"active":""}`,onClick:n=>{ml.value&&(n.preventDefault(),fl({type:"nav",execute:()=>{window.location.hash=`#${t.path}`}}))},children:t.label})})})]}),e("main",{class:"main",children:[e("header",{class:"header",children:[e("div",{class:"header-left",children:[e("h1",{class:"header-title",children:Xs(Je.value)}),zn(Je.value)&&e("p",{class:"header-subtitle",children:zn(Je.value)})]}),e("div",{class:"header-actions",children:[e("button",{class:"btn-search",onClick:()=>{Qt.value=!0},title:"Search settings (Ctrl+K)",children:"🔍"}),e("button",{class:"btn-logout",onClick:()=>fa(),children:"Logout"})]})]}),e("div",{class:"content",children:e(Zs,{})})]}),e(Ei,{open:Qt}),e(xi,{})]})}const ea={overlay:{position:"fixed",inset:0,display:"flex",alignItems:"center",justifyContent:"center",background:"rgba(0, 0, 0, 0.7)",color:"white",zIndex:9999},content:{textAlign:"center"},title:{fontSize:"var(--font-size-2xl)",fontWeight:"var(--font-weight-bold)",marginBottom:"var(--space-2)"},message:{fontSize:"var(--font-size-base)",color:"var(--color-text-muted)"}};function eo(){return e("div",{style:ea.overlay,children:e("div",{style:ea.content,children:[e("h1",{style:ea.title,children:"Daemon Shutting Down"}),e("p",{style:ea.message,children:"The daemon is shutting down. Please wait or restart."})]})})}function to(){return gi.value?e(eo,{}):fi.value?e(te,{children:[e(Qs,{}),e(zi,{})]}):e(Si,{})}ii(e(to,{}),document.getElementById("app"));
|