@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
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
var Ga,ce,yn,_n,Ze,Pt,bn,wn,Tn,bt,vt,ht,Sa={},Sn=[],Al=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,qa=Array.isArray;function Oe(t,a){for(var n in a)t[n]=a[n];return t}function wt(t){t&&t.parentNode&&t.parentNode.removeChild(t)}function El(t,a,n){var l,i,s,r={};for(s in a)s=="key"?l=a[s]:s=="ref"?i=a[s]:r[s]=a[s];if(arguments.length>2&&(r.children=arguments.length>3?Ga.call(arguments,2):n),typeof t=="function"&&t.defaultProps!=null)for(s in t.defaultProps)r[s]===void 0&&(r[s]=t.defaultProps[s]);return Wa(t,r,l,i,null)}function Wa(t,a,n,l,i){var s={type:t,props:a,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++yn,__i:-1,__u:0};return i==null&&ce.vnode!=null&&ce.vnode(s),s}function J(t){return t.children}function ya(t,a){this.props=t,this.context=a}function ra(t,a){if(a==null)return t.__?ra(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"?ra(t):null}function kn(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 kn(t)}}function Mt(t){(!t.__d&&(t.__d=!0)&&Ze.push(t)&&!Fa.__r++||Pt!=ce.debounceRendering)&&((Pt=ce.debounceRendering)||bn)(Fa)}function Fa(){for(var t,a,n,l,i,s,r,d=1;Ze.length;)Ze.length>d&&Ze.sort(wn),t=Ze.shift(),d=Ze.length,t.__d&&(n=void 0,l=void 0,i=(l=(a=t).__v).__e,s=[],r=[],a.__P&&((n=Oe({},l)).__v=l.__v+1,ce.vnode&&ce.vnode(n),Tt(a.__P,n,l,a.__n,a.__P.namespaceURI,32&l.__u?[i]:null,s,i??ra(l),!!(32&l.__u),r),n.__v=l.__v,n.__.__k[n.__i]=n,En(s,n,r),l.__e=l.__=null,n.__e!=i&&kn(n)));Fa.__r=0}function Nn(t,a,n,l,i,s,r,d,p,o,v){var h,f,N,$,P,g,R,W=l&&l.__k||Sn,z=a.length;for(p=Cl(n,a,W,p,z),h=0;h<z;h++)(N=n.__k[h])!=null&&(f=N.__i==-1?Sa:W[N.__i]||Sa,N.__i=h,g=Tt(t,N,f,i,s,r,d,p,o,v),$=N.__e,N.ref&&f.ref!=N.ref&&(f.ref&&St(f.ref,null,N),v.push(N.ref,N.__c||$,N)),P==null&&$!=null&&(P=$),(R=!!(4&N.__u))||f.__k===N.__k?p=An(N,p,t,R):typeof N.type=="function"&&g!==void 0?p=g:$&&(p=$.nextSibling),N.__u&=-7);return n.__e=P,p}function Cl(t,a,n,l,i){var s,r,d,p,o,v=n.length,h=v,f=0;for(t.__k=new Array(i),s=0;s<i;s++)(r=a[s])!=null&&typeof r!="boolean"&&typeof r!="function"?(typeof r=="string"||typeof r=="number"||typeof r=="bigint"||r.constructor==String?r=t.__k[s]=Wa(null,r,null,null,null):qa(r)?r=t.__k[s]=Wa(J,{children:r},null,null,null):r.constructor===void 0&&r.__b>0?r=t.__k[s]=Wa(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):t.__k[s]=r,p=s+f,r.__=t,r.__b=t.__b+1,d=null,(o=r.__i=Il(r,n,p,h))!=-1&&(h--,(d=n[o])&&(d.__u|=2)),d==null||d.__v==null?(o==-1&&(i>v?f--:i<v&&f++),typeof r.type!="function"&&(r.__u|=4)):o!=p&&(o==p-1?f--:o==p+1?f++:(o>p?f--:f++,r.__u|=4))):t.__k[s]=null;if(h)for(s=0;s<v;s++)(d=n[s])!=null&&(2&d.__u)==0&&(d.__e==l&&(l=ra(d)),In(d,d));return l}function An(t,a,n,l){var i,s;if(typeof t.type=="function"){for(i=t.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=t,a=An(i[s],a,n,l));return a}t.__e!=a&&(l&&(a&&t.type&&!a.parentNode&&(a=ra(t)),n.insertBefore(t.__e,a||null)),a=t.__e);do a=a&&a.nextSibling;while(a!=null&&a.nodeType==8);return a}function Il(t,a,n,l){var i,s,r,d=t.key,p=t.type,o=a[n],v=o!=null&&(2&o.__u)==0;if(o===null&&d==null||v&&d==o.key&&p==o.type)return n;if(l>(v?1:0)){for(i=n-1,s=n+1;i>=0||s<a.length;)if((o=a[r=i>=0?i--:s++])!=null&&(2&o.__u)==0&&d==o.key&&p==o.type)return r}return-1}function Ut(t,a,n){a[0]=="-"?t.setProperty(a,n??""):t[a]=n==null?"":typeof n!="number"||Al.test(a)?n:n+"px"}function Da(t,a,n,l,i){var s,r;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||Ut(t.style,a,"");if(n)for(a in n)l&&n[a]==l[a]||Ut(t.style,a,n[a])}else if(a[0]=="o"&&a[1]=="n")s=a!=(a=a.replace(Tn,"$1")),r=a.toLowerCase(),a=r in t||a=="onFocusOut"||a=="onFocusIn"?r.slice(2):a.slice(2),t.l||(t.l={}),t.l[a+s]=n,n?l?n.u=l.u:(n.u=bt,t.addEventListener(a,s?ht:vt,s)):t.removeEventListener(a,s?ht:vt,s);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 Wt(t){return function(a){if(this.l){var n=this.l[a.type+t];if(a.t==null)a.t=bt++;else if(a.t<n.u)return;return n(ce.event?ce.event(a):a)}}}function Tt(t,a,n,l,i,s,r,d,p,o){var v,h,f,N,$,P,g,R,W,z,D,B,A,E,b,C,w,u=a.type;if(a.constructor!==void 0)return null;128&n.__u&&(p=!!(32&n.__u),s=[d=a.__e=n.__e]),(v=ce.__b)&&v(a);e:if(typeof u=="function")try{if(R=a.props,W="prototype"in u&&u.prototype.render,z=(v=u.contextType)&&l[v.__c],D=v?z?z.props.value:v.__:l,n.__c?g=(h=a.__c=n.__c).__=h.__E:(W?a.__c=h=new u(R,D):(a.__c=h=new ya(R,D),h.constructor=u,h.render=xl),z&&z.sub(h),h.state||(h.state={}),h.__n=l,f=h.__d=!0,h.__h=[],h._sb=[]),W&&h.__s==null&&(h.__s=h.state),W&&u.getDerivedStateFromProps!=null&&(h.__s==h.state&&(h.__s=Oe({},h.__s)),Oe(h.__s,u.getDerivedStateFromProps(R,h.__s))),N=h.props,$=h.state,h.__v=a,f)W&&u.getDerivedStateFromProps==null&&h.componentWillMount!=null&&h.componentWillMount(),W&&h.componentDidMount!=null&&h.__h.push(h.componentDidMount);else{if(W&&u.getDerivedStateFromProps==null&&R!==N&&h.componentWillReceiveProps!=null&&h.componentWillReceiveProps(R,D),a.__v==n.__v||!h.__e&&h.shouldComponentUpdate!=null&&h.shouldComponentUpdate(R,h.__s,D)===!1){for(a.__v!=n.__v&&(h.props=R,h.state=h.__s,h.__d=!1),a.__e=n.__e,a.__k=n.__k,a.__k.some(function(m){m&&(m.__=a)}),B=0;B<h._sb.length;B++)h.__h.push(h._sb[B]);h._sb=[],h.__h.length&&r.push(h);break e}h.componentWillUpdate!=null&&h.componentWillUpdate(R,h.__s,D),W&&h.componentDidUpdate!=null&&h.__h.push(function(){h.componentDidUpdate(N,$,P)})}if(h.context=D,h.props=R,h.__P=t,h.__e=!1,A=ce.__r,E=0,W){for(h.state=h.__s,h.__d=!1,A&&A(a),v=h.render(h.props,h.state,h.context),b=0;b<h._sb.length;b++)h.__h.push(h._sb[b]);h._sb=[]}else do h.__d=!1,A&&A(a),v=h.render(h.props,h.state,h.context),h.state=h.__s;while(h.__d&&++E<25);h.state=h.__s,h.getChildContext!=null&&(l=Oe(Oe({},l),h.getChildContext())),W&&!f&&h.getSnapshotBeforeUpdate!=null&&(P=h.getSnapshotBeforeUpdate(N,$)),C=v,v!=null&&v.type===J&&v.key==null&&(C=Cn(v.props.children)),d=Nn(t,qa(C)?C:[C],a,n,l,i,s,r,d,p,o),h.base=a.__e,a.__u&=-161,h.__h.length&&r.push(h),g&&(h.__E=h.__=null)}catch(m){if(a.__v=null,p||s!=null)if(m.then){for(a.__u|=p?160:128;d&&d.nodeType==8&&d.nextSibling;)d=d.nextSibling;s[s.indexOf(d)]=null,a.__e=d}else{for(w=s.length;w--;)wt(s[w]);pt(a)}else a.__e=n.__e,a.__k=n.__k,m.then||pt(a);ce.__e(m,a,n)}else s==null&&a.__v==n.__v?(a.__k=n.__k,a.__e=n.__e):d=a.__e=Dl(n.__e,a,n,l,i,s,r,p,o);return(v=ce.diffed)&&v(a),128&a.__u?void 0:d}function pt(t){t&&t.__c&&(t.__c.__e=!0),t&&t.__k&&t.__k.forEach(pt)}function En(t,a,n){for(var l=0;l<n.length;l++)St(n[l],n[++l],n[++l]);ce.__c&&ce.__c(a,t),t.some(function(i){try{t=i.__h,i.__h=[],t.some(function(s){s.call(i)})}catch(s){ce.__e(s,i.__v)}})}function Cn(t){return typeof t!="object"||t==null||t.__b&&t.__b>0?t:qa(t)?t.map(Cn):Oe({},t)}function Dl(t,a,n,l,i,s,r,d,p){var o,v,h,f,N,$,P,g=n.props||Sa,R=a.props,W=a.type;if(W=="svg"?i="http://www.w3.org/2000/svg":W=="math"?i="http://www.w3.org/1998/Math/MathML":i||(i="http://www.w3.org/1999/xhtml"),s!=null){for(o=0;o<s.length;o++)if((N=s[o])&&"setAttribute"in N==!!W&&(W?N.localName==W:N.nodeType==3)){t=N,s[o]=null;break}}if(t==null){if(W==null)return document.createTextNode(R);t=document.createElementNS(i,W,R.is&&R),d&&(ce.__m&&ce.__m(a,s),d=!1),s=null}if(W==null)g===R||d&&t.data==R||(t.data=R);else{if(s=s&&Ga.call(t.childNodes),!d&&s!=null)for(g={},o=0;o<t.attributes.length;o++)g[(N=t.attributes[o]).name]=N.value;for(o in g)if(N=g[o],o!="children"){if(o=="dangerouslySetInnerHTML")h=N;else if(!(o in R)){if(o=="value"&&"defaultValue"in R||o=="checked"&&"defaultChecked"in R)continue;Da(t,o,null,N,i)}}for(o in R)N=R[o],o=="children"?f=N:o=="dangerouslySetInnerHTML"?v=N:o=="value"?$=N:o=="checked"?P=N:d&&typeof N!="function"||g[o]===N||Da(t,o,N,g[o],i);if(v)d||h&&(v.__html==h.__html||v.__html==t.innerHTML)||(t.innerHTML=v.__html),a.__k=[];else if(h&&(t.innerHTML=""),Nn(a.type=="template"?t.content:t,qa(f)?f:[f],a,n,l,W=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,r,s?s[0]:n.__k&&ra(n,0),d,p),s!=null)for(o=s.length;o--;)wt(s[o]);d||(o="value",W=="progress"&&$==null?t.removeAttribute("value"):$!=null&&($!==t[o]||W=="progress"&&!$||W=="option"&&$!=g[o])&&Da(t,o,$,g[o],i),o="checked",P!=null&&P!=t[o]&&Da(t,o,P,g[o],i))}return t}function St(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){ce.__e(i,n)}}function In(t,a,n){var l,i;if(ce.unmount&&ce.unmount(t),(l=t.ref)&&(l.current&&l.current!=t.__e||St(l,null,a)),(l=t.__c)!=null){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(s){ce.__e(s,a)}l.base=l.__P=null}if(l=t.__k)for(i=0;i<l.length;i++)l[i]&&In(l[i],a,n||typeof t.type!="function");n||wt(t.__e),t.__c=t.__=t.__e=void 0}function xl(t,a,n){return this.constructor(t,n)}function Ll(t,a,n){var l,i,s,r;a==document&&(a=document.documentElement),ce.__&&ce.__(t,a),i=(l=!1)?null:a.__k,s=[],r=[],Tt(a,t=a.__k=El(J,null,[t]),i||Sa,Sa,a.namespaceURI,i?null:a.firstChild?Ga.call(a.childNodes):null,s,i?i.__e:a.firstChild,l,r),En(s,t,r)}Ga=Sn.slice,ce={__e:function(t,a,n,l){for(var i,s,r;a=a.__;)if((i=a.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(t)),r=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(t,l||{}),r=i.__d),r)return i.__E=i}catch(d){t=d}throw t}},yn=0,_n=function(t){return t!=null&&t.constructor===void 0},ya.prototype.setState=function(t,a){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=Oe({},this.state),typeof t=="function"&&(t=t(Oe({},n),this.props)),t&&Oe(n,t),t!=null&&this.__v&&(a&&this._sb.push(a),Mt(this))},ya.prototype.forceUpdate=function(t){this.__v&&(this.__e=!0,t&&this.__h.push(t),Mt(this))},ya.prototype.render=J,Ze=[],bn=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,wn=function(t,a){return t.__v.__b-a.__v.__b},Fa.__r=0,Tn=/(PointerCapture)$|Capture$/i,bt=0,vt=Wt(!1),ht=Wt(!0);var Rl=0;function e(t,a,n,l,i,s){a||(a={});var r,d,p=a;if("ref"in p)for(d in p={},a)d=="ref"?r=a[d]:p[d]=a[d];var o={type:t,props:p,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Rl,__i:-1,__u:0,__source:i,__self:s};if(typeof t=="function"&&(r=t.defaultProps))for(d in r)p[d]===void 0&&(p[d]=r[d]);return ce.vnode&&ce.vnode(o),o}var Ka,ke,at,$t,mt=0,Dn=[],ge=ce,Ft=ge.__b,Kt=ge.__r,Ht=ge.diffed,Bt=ge.__c,zt=ge.unmount,Vt=ge.__;function xn(t,a){ge.__h&&ge.__h(ke,t,mt||a),mt=0;var n=ke.__H||(ke.__H={__:[],__h:[]});return t>=n.__.length&&n.__.push({}),n.__[t]}function Y(t,a){var n=xn(Ka++,3);!ge.__s&&Ln(n.__H,a)&&(n.__=t,n.u=a,ke.__H.__h.push(n))}function Aa(t){return mt=5,ja(function(){return{current:t}},[])}function ja(t,a){var n=xn(Ka++,7);return Ln(n.__H,a)&&(n.__=t(),n.__H=a,n.__h=t),n.__}function Ol(){for(var t;t=Dn.shift();)if(t.__P&&t.__H)try{t.__H.__h.forEach($a),t.__H.__h.forEach(ft),t.__H.__h=[]}catch(a){t.__H.__h=[],ge.__e(a,t.__v)}}ge.__b=function(t){ke=null,Ft&&Ft(t)},ge.__=function(t,a){t&&a.__k&&a.__k.__m&&(t.__m=a.__k.__m),Vt&&Vt(t,a)},ge.__r=function(t){Kt&&Kt(t),Ka=0;var a=(ke=t.__c).__H;a&&(at===ke?(a.__h=[],ke.__h=[],a.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(a.__h.forEach($a),a.__h.forEach(ft),a.__h=[],Ka=0)),at=ke},ge.diffed=function(t){Ht&&Ht(t);var a=t.__c;a&&a.__H&&(a.__H.__h.length&&(Dn.push(a)!==1&&$t===ge.requestAnimationFrame||(($t=ge.requestAnimationFrame)||Pl)(Ol)),a.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),at=ke=null},ge.__c=function(t,a){a.some(function(n){try{n.__h.forEach($a),n.__h=n.__h.filter(function(l){return!l.__||ft(l)})}catch(l){a.some(function(i){i.__h&&(i.__h=[])}),a=[],ge.__e(l,n.__v)}}),Bt&&Bt(t,a)},ge.unmount=function(t){zt&&zt(t);var a,n=t.__c;n&&n.__H&&(n.__H.__.forEach(function(l){try{$a(l)}catch(i){a=i}}),n.__H=void 0,a&&ge.__e(a,n.__v))};var Gt=typeof requestAnimationFrame=="function";function Pl(t){var a,n=function(){clearTimeout(l),Gt&&cancelAnimationFrame(a),setTimeout(t)},l=setTimeout(n,35);Gt&&(a=requestAnimationFrame(n))}function $a(t){var a=ke,n=t.__c;typeof n=="function"&&(t.__c=void 0,n()),ke=a}function ft(t){var a=ke;t.__c=t.__(),ke=a}function Ln(t,a){return!t||t.length!==a.length||a.some(function(n,l){return n!==t[l]})}var Ml=Symbol.for("preact-signals");function Ya(){if(Ge>1)Ge--;else{for(var t,a=!1;_a!==void 0;){var n=_a;for(_a=void 0,gt++;n!==void 0;){var l=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Pn(n))try{n.c()}catch(i){a||(t=i,a=!0)}n=l}}if(gt=0,Ge--,a)throw t}}function Ul(t){if(Ge>0)return t();Ge++;try{return t()}finally{Ya()}}var oe=void 0;function Rn(t){var a=oe;oe=void 0;try{return t()}finally{oe=a}}var _a=void 0,Ge=0,gt=0,Ha=0;function On(t){if(oe!==void 0){var a=t.n;if(a===void 0||a.t!==oe)return a={i:0,S:t,p:oe.s,n:void 0,t:oe,e:void 0,x:void 0,r:a},oe.s!==void 0&&(oe.s.n=a),oe.s=a,t.n=a,32&oe.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=oe.s,a.n=void 0,oe.s.n=a,oe.s=a),a}}function we(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}we.prototype.brand=Ml;we.prototype.h=function(){return!0};we.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:Rn(function(){var l;(l=a.W)==null||l.call(a)}))};we.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&&Rn(function(){var i;(i=a.Z)==null||i.call(a)}))}};we.prototype.subscribe=function(t){var a=this;return Ea(function(){var n=a.value,l=oe;oe=void 0;try{t(n)}finally{oe=l}},{name:"sub"})};we.prototype.valueOf=function(){return this.value};we.prototype.toString=function(){return this.value+""};we.prototype.toJSON=function(){return this.value};we.prototype.peek=function(){var t=oe;oe=void 0;try{return this.value}finally{oe=t}};Object.defineProperty(we.prototype,"value",{get:function(){var t=On(this);return t!==void 0&&(t.i=this.i),this.v},set:function(t){if(t!==this.v){if(gt>100)throw new Error("Cycle detected");this.v=t,this.i++,Ha++,Ge++;try{for(var a=this.t;a!==void 0;a=a.x)a.t.N()}finally{Ya()}}}});function Te(t,a){return new we(t,a)}function Pn(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 Mn(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 Un(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 ea(t,a){we.call(this,void 0),this.x=t,this.s=void 0,this.g=Ha-1,this.f=4,this.W=a?.watched,this.Z=a?.unwatched,this.name=a?.name}ea.prototype=new we;ea.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Ha))return!0;if(this.g=Ha,this.f|=1,this.i>0&&!Pn(this))return this.f&=-2,!0;var t=oe;try{Mn(this),oe=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 oe=t,Un(this),this.f&=-2,!0};ea.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)}we.prototype.S.call(this,t)};ea.prototype.U=function(t){if(this.t!==void 0&&(we.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)}};ea.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(ea.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var t=On(this);if(this.h(),t!==void 0&&(t.i=this.i),16&this.f)throw this.v;return this.v}});function ka(t,a){return new ea(t,a)}function Wn(t){var a=t.u;if(t.u=void 0,typeof a=="function"){Ge++;var n=oe;oe=void 0;try{a()}catch(l){throw t.f&=-2,t.f|=8,kt(t),l}finally{oe=n,Ya()}}}function kt(t){for(var a=t.s;a!==void 0;a=a.n)a.S.U(a);t.x=void 0,t.s=void 0,Wn(t)}function Wl(t){if(oe!==this)throw new Error("Out-of-order effect");Un(this),oe=t,this.f&=-2,8&this.f&&kt(this),Ya()}function ca(t,a){this.x=t,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=a?.name}ca.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()}};ca.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Wn(this),Mn(this),Ge++;var t=oe;return oe=this,Wl.bind(this,t)};ca.prototype.N=function(){2&this.f||(this.f|=2,this.o=_a,_a=this)};ca.prototype.d=function(){this.f|=8,1&this.f||kt(this)};ca.prototype.dispose=function(){this.d()};function Ea(t,a){var n=new ca(t,a);try{n.c()}catch(i){throw n.d(),i}var l=n.d.bind(n);return l[Symbol.dispose]=l,l}var $n,Xa,xa,$l=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Fn=[];Ea(function(){$n=this.N})();function da(t,a){ce[t]=a.bind(null,ce[t]||function(){})}function Ba(t){if(xa){var a=xa;xa=void 0,a()}xa=t&&t.S()}function Kn(t){var a=this,n=t.data,l=c(n);l.value=n;var i=ja(function(){for(var d=a,p=a.__v;p=p.__;)if(p.__c){p.__c.__$f|=4;break}var o=ka(function(){var N=l.value.value;return N===0?0:N===!0?"":N||""}),v=ka(function(){return!Array.isArray(o.value)&&!_n(o.value)}),h=Ea(function(){if(this.N=Hn,v.value){var N=o.value;d.__v&&d.__v.__e&&d.__v.__e.nodeType===3&&(d.__v.__e.data=N)}}),f=a.__$u.d;return a.__$u.d=function(){h(),f.call(this)},[v,o]},[]),s=i[0],r=i[1];return s.value?r.peek():r.value}Kn.displayName="ReactiveTextNode";Object.defineProperties(we.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Kn},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});da("__b",function(t,a){if(typeof a.type=="string"){var n,l=a.props;for(var i in l)if(i!=="children"){var s=l[i];s instanceof we&&(n||(a.__np=n={}),n[i]=s,l[i]=s.peek())}}t(a)});da("__r",function(t,a){if(t(a),a.type!==J){Ba();var n,l=a.__c;l&&(l.__$f&=-2,(n=l.__$u)===void 0&&(l.__$u=n=(function(i,s){var r;return Ea(function(){r=this},{name:s}),r.c=i,r})(function(){var i;$l&&((i=n.y)==null||i.call(n)),l.__$f|=1,l.setState({})},typeof a.type=="function"?a.type.displayName||a.type.name:""))),Xa=l,Ba(n)}});da("__e",function(t,a,n,l){Ba(),Xa=void 0,t(a,n,l)});da("diffed",function(t,a){Ba(),Xa=void 0;var n;if(typeof a.type=="string"&&(n=a.__e)){var l=a.__np,i=a.props;if(l){var s=n.U;if(s)for(var r in s){var d=s[r];d!==void 0&&!(r in l)&&(d.d(),s[r]=void 0)}else s={},n.U=s;for(var p in l){var o=s[p],v=l[p];o===void 0?(o=Fl(n,p,v,i),s[p]=o):o.o(v,i)}}}t(a)});function Fl(t,a,n,l){var i=a in t&&t.ownerSVGElement===void 0,s=Te(n);return{o:function(r,d){s.value=r,l=d},d:Ea(function(){this.N=Hn;var r=s.value.value;l[a]!==r&&(l[a]=r,i?t[a]=r:r!=null&&(r!==!1||a[4]==="-")?t.setAttribute(a,r):t.removeAttribute(a))})}}da("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 s=l[i];s&&s.d()}}}}else{var r=a.__c;if(r){var d=r.__$u;d&&(r.__$u=void 0,d.d())}}t(a)});da("__h",function(t,a,n,l){(l<3||l===9)&&(a.__$f|=2),t(a,n,l)});ya.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 s=2&this.__$f;if(!(l||s||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var r in t)if(r!=="__source"&&t[r]!==this.props[r])return!0;for(var d in this.props)if(!(d in t))return!0;return!1};function c(t,a){return ja(function(){return Te(t,a)},[])}function Ja(t,a){var n=Aa(t);return n.current=t,Xa.__$f|=4,ja(function(){return ka(function(){return n.current()},a)},[])}var Kl=function(t){queueMicrotask(function(){queueMicrotask(t)})};function Hl(){Ul(function(){for(var t;t=Fn.shift();)$n.call(t)})}function Hn(){Fn.push(this)===1&&(ce.requestAnimationFrame||Kl)(Hl)}const Na=Te(null),Bl=ka(()=>Na.value!==null),Bn=Te(900),zl=Te(!1);let ia=null;const sa=()=>{Nt()};function Vl(){document.addEventListener("mousemove",sa,{passive:!0}),document.addEventListener("keydown",sa,{passive:!0}),document.addEventListener("click",sa,{passive:!0}),Nt()}function Gl(){document.removeEventListener("mousemove",sa),document.removeEventListener("keydown",sa),document.removeEventListener("click",sa),ia!==null&&(clearTimeout(ia),ia=null)}function Nt(){ia!==null&&clearTimeout(ia),ia=setTimeout(()=>{Za()},Bn.value*1e3)}function ql(t,a){Na.value=t,a!==void 0&&(Bn.value=a),Vl(),location.hash="#/dashboard"}function Za(){Na.value=null,Gl(),location.hash="#/login"}const x={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`,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_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_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}`},ba=Te(""),la=Te(null),wa=Te(!1),Ke={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)"}},jl=async t=>{if(t.preventDefault(),!!ba.value.trim()){wa.value=!0,la.value=null;try{const a=await fetch(x.ADMIN_STATUS,{headers:{"X-Master-Password":ba.value},signal:AbortSignal.timeout(1e4)});if(a.status===401){la.value="Invalid master password";return}if(!a.ok){la.value="Cannot connect to daemon";return}const n=await a.json();ql(ba.value,n.adminTimeout)}catch{la.value="Cannot connect to daemon"}finally{wa.value=!1}}};function Yl(){return e("div",{style:Ke.wrapper,children:e("form",{style:Ke.card,onSubmit:jl,children:[e("h1",{style:Ke.title,children:"WAIaaS Admin"}),e("p",{style:Ke.subtitle,children:"Enter master password to continue"}),e("input",{type:"password",placeholder:"Master password",autoFocus:!0,value:ba.value,onInput:t=>{ba.value=t.target.value},style:Ke.input}),e("button",{type:"submit",disabled:wa.value,style:{...Ke.button,...wa.value?Ke.buttonDisabled:{}},children:wa.value?"Signing in...":"Sign in"}),la.value&&e("p",{style:Ke.error,children:la.value})]})})}const Xl=[{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:"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"]}],Ae=Te(""),pe=Te(null),Jl={"/wallets":"Wallets","/sessions":"Sessions","/transactions":"Transactions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"};function Zl(t){if(!t.trim())return[];const a=t.toLowerCase();return Xl.filter(n=>[n.label,n.description,n.keywords.join(" ")].join(" ").toLowerCase().includes(a)).slice(0,10)}function Ql(t){const a=Jl[t.page]??t.page;return t.tab?`${a} > ${t.tab}`:a}function ei({open:t}){const a=c(""),n=c(0),l=Aa(null),i=t.value?Zl(a.value):[];if(Y(()=>{t.value&&(a.value="",n.value=0,requestAnimationFrame(()=>{l.current?.focus()}))},[t.value]),!t.value)return null;const s=()=>{t.value=!1,a.value="",n.value=0},r=o=>{o.target.classList.contains("search-overlay")&&s()},d=o=>{window.location.hash="#"+o.page,o.tab?pe.value={tab:o.tab,fieldName:o.fieldName}:setTimeout(()=>{Ae.value=o.fieldName},100),s()};return e("div",{class:"search-overlay",onClick:r,children:e("div",{class:"search-popover",onKeyDown:o=>{if(o.key==="Escape"){s();return}if(o.key==="ArrowDown"){o.preventDefault(),n.value=Math.min(n.value+1,i.length-1);return}if(o.key==="ArrowUp"){o.preventDefault(),n.value=Math.max(n.value-1,0);return}if(o.key==="Enter"&&i.length>0){o.preventDefault(),d(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:o=>{a.value=o.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((o,v)=>e("button",{class:`search-result-item${v===n.value?" selected":""}`,onClick:()=>d(o),onMouseEnter:()=>{n.value=v},children:[e("div",{class:"search-result-label",children:o.label}),e("div",{class:"search-result-desc",children:o.description}),e("div",{class:"search-result-path",children:Ql(o)})]},o.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 Qe=Te([]),zn=ka(()=>Qe.value.some(t=>typeof t.isDirty=="function"&&t.isDirty()));function Ue(t){Qe.value=[...Qe.value.filter(a=>a.id!==t.id),t]}function Ie(t){Qe.value=Qe.value.filter(a=>a.id!==t)}async function ai(){const t=Qe.value.filter(a=>typeof a.isDirty=="function"&&a.isDirty());try{for(const a of t)await a.save();return!0}catch{return!1}}function ti(){const t=Qe.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:s,error:r,required:d,disabled:p,placeholder:o,min:v,max:h,description:f}){const N=Ae.value===a;if(Y(()=>{if(N){const P=document.querySelector(`[name="${a}"]`);P&&P.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const g=setTimeout(()=>{Ae.value=""},2500);return()=>clearTimeout(g)}},[N,a]),n==="checkbox")return e("div",{class:`form-field${N?" form-field--highlight":""}`,children:[e("label",{children:[e("input",{type:"checkbox",name:a,checked:!!l,onChange:P=>i(P.target.checked),disabled:p}),t,d&&e("span",{children:" *"})]}),f&&e("span",{class:"form-description",children:f}),r&&e("span",{class:"form-error",children:r})]});const $=`field-${a}`;return e("div",{class:`form-field${N?" form-field--highlight":""}`,children:[e("label",{for:$,children:[t,d&&e("span",{children:" *"})]}),n==="select"?e("select",{id:$,name:a,value:l,onChange:P=>i(P.target.value),disabled:p,children:s?.map(P=>e("option",{value:P.value,children:P.label},P.value))}):n==="textarea"?e("textarea",{id:$,name:a,value:l,onInput:P=>i(P.target.value),disabled:p,placeholder:o}):e("input",{id:$,type:n,name:a,value:l,onInput:P=>{const g=P.target;i(n==="number"?Number(g.value):g.value)},disabled:p,placeholder:o,min:v,max:h,required:d}),f&&e("span",{class:"form-description",children:f}),r&&e("span",{class:"form-error",children:r})]})}function M({variant:t="primary",size:a="md",loading:n=!1,disabled:l=!1,onClick:i,children:s,type:r="button"}){const d=["btn",`btn-${t}`,a==="sm"?"btn-sm":""].filter(Boolean).join(" ");return e("button",{type:r,class:d,disabled:l||n,onClick:i,children:n?"...":s})}function V({variant:t,children:a}){return e("span",{class:`badge badge-${t}`,children:a})}const fa=Te(null),va=Te(!1);function Vn(t){fa.value=t}function ni(){const t=fa.value;if(!t)return null;const a=async()=>{va.value=!0;const i=await ai();va.value=!1,i&&(fa.value=null,t.execute())},n=()=>{ti(),fa.value=null,t.execute()},l=()=>{fa.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(M,{variant:"secondary",onClick:l,disabled:va.value,children:"Cancel"}),e(M,{variant:"ghost",onClick:n,disabled:va.value,children:"Discard & Navigate"}),e(M,{variant:"primary",onClick:a,loading:va.value,children:"Save & Navigate"})]})]})})}class T extends Error{constructor(a,n,l){super(`[${a}] ${n}: ${l}`),this.status=a,this.code=n,this.serverMessage=l,this.name="ApiError"}}async function Ca(t,a){const n={"Content-Type":"application/json",...a?.headers};Na.value!==null&&(n["X-Master-Password"]=Na.value);let l;try{l=await fetch(t,{...a,headers:n,signal:AbortSignal.timeout(1e4)})}catch(i){const s=i;throw s.name==="AbortError"||s.name==="TimeoutError"?new T(0,"TIMEOUT","Request timed out"):new T(0,"NETWORK_ERROR","Cannot connect to daemon")}if(l.status===401)throw t.startsWith("/v1/admin/")&&Za(),new T(401,"UNAUTHORIZED","Authentication failed");if(!l.ok){let i={};try{i=await l.json()}catch{}throw new T(l.status,i.code??"UNKNOWN",i.message??"Unknown error")}return Nt(),await l.json()}const q=t=>Ca(t,{method:"GET"}),ve=(t,a)=>Ca(t,{method:"POST",body:a?JSON.stringify(a):void 0}),ue=(t,a)=>Ca(t,{method:"PUT",body:a?JSON.stringify(a):void 0}),je=(t,a)=>Ca(t,{method:"DELETE",body:a?JSON.stringify(a):void 0}),li=(t,a)=>Ca(t,{method:"PATCH",body:a?JSON.stringify(a):void 0});function ii(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 Ta(t){return t?t.length<=10?t:`${t.slice(0,4)}..${t.slice(-4)}`:""}const si=new Set(["KRW","JPY","VND","CLP","HUF","PKR"]),ri=new Set(["KWD","BHD"]);function oi(t){return si.has(t)?0:ri.has(t)?3:2}function ci(t,a,n){const l=t*n,i=oi(a),s=new Intl.NumberFormat("en-US",{style:"currency",currency:a,minimumFractionDigits:i,maximumFractionDigits:i}).format(l);return a==="USD"?s:`≈${s}`}let ta=null;const di=300*1e3;async function At(){if(ta&&Date.now()-ta.fetchedAt<di)return{currency:ta.currency,rate:ta.rate};try{const a=(await q(x.ADMIN_SETTINGS)).display?.["display.currency"]??"USD";if(a==="USD")return ta={currency:"USD",rate:1,fetchedAt:Date.now()},{currency:"USD",rate:1};const i=(await q(`${x.ADMIN_FOREX_RATES}?currencies=${a}`)).rates[a]?.rate??null;return ta={currency:a,rate:i,fetchedAt:Date.now()},{currency:a,rate:i}}catch{return{currency:"USD",rate:1}}}function oa(t,a,n){return t==null?"":n==null?`$${t.toFixed(2)}`:ci(t,a,n)}function Pe({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(s=>e("th",{style:s.width?{width:s.width}:void 0,children:s.header},s.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((s,r)=>e("tr",{class:n?"clickable":"",onClick:n?()=>n(s):void 0,children:t.map(d=>e("td",{children:d.render?d.render(s):s[d.key]},d.key))},r))})]})})}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.",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."},vi=new Set(["ACTION_VALIDATION_FAILED","CONSTRAINT_VIOLATED","INVALID_ADDRESS","INVALID_SIGNATURE"]);function K(t,a){return a&&vi.has(t)?a:ui[t]??`An error occurred (${t}).`}const ze=Te([]);let hi=0;function _(t,a){const n=hi++;ze.value=[...ze.value,{id:n,type:t,message:a}],setTimeout(()=>{ze.value=ze.value.filter(l=>l.id!==n)},5e3)}function pi(t){ze.value=ze.value.filter(a=>a.id!==t)}function mi(){return ze.value.length===0?null:e("div",{class:"toast-container",children:ze.value.map(t=>e("div",{class:`toast toast-${t.type}`,onClick:()=>pi(t.id),children:t.message},t.id))})}const fi={"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 gi(t,a){const n=fi[t];return n?n.replace("{txHash}",a):null}function yi(t){return t.length<=16?t:t.slice(0,8)+"..."+t.slice(-6)}function Et({network:t,txHash:a,label:n}){if(!a)return null;const l=gi(t,a),i=n??yi(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 _i(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 ye({label:t,value:a,loading:n,badge:l,href:i}){const s=e(J,{children:[e("div",{class:"stat-label",children:[t,i&&e("span",{class:"stat-link-arrow",children:" →"})]}),n?e("div",{class:"stat-skeleton"}):l?e(V,{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:s}):e("div",{class:"stat-card",children:s})}function bi(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=oa(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(V,{variant:l,children:n.status})}},{key:"txHash",header:"Tx Hash",render:n=>e(Et,{network:n.network??"",txHash:n.txHash})}]}function wi(t,a){return[{key:"provider",header:"Provider"},{key:"category",header:"Category",render:n=>e(V,{variant:"info",children:n.category})},{key:"chain",header:"Chain",render:n=>e(V,{variant:"info",children:n.chain})},{key:"amount",header:"Amount"},{key:"amountUsd",header:"USD Value",render:n=>n.amountUsd===null?"—":oa(n.amountUsd,t,a)??`$${n.amountUsd.toFixed(2)}`}]}async function Ti(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 qt(){const t=c(null),a=c(!0),n=c(null),l=c("USD"),i=c(1),s=c(!1),r=c(null),d=c(null),p=c(null),o=c(!0),v=c(null),h=c(!0),f=async()=>{try{const W=await q(x.ADMIN_STATS);v.value=W}catch{}finally{h.value=!1}},N=async()=>{o.value=!0;try{const W=await q(x.ADMIN_DEFI_POSITIONS);p.value=W}catch{}finally{o.value=!1}},$=async()=>{a.value=!0,n.value=null;try{const W=await q(x.ADMIN_STATUS);t.value=W}catch(W){W instanceof T?n.value=K(W.code):n.value="An unexpected error occurred."}finally{a.value=!1}},P=async()=>{s.value=!0;try{const W=await ve(x.ADMIN_AGENT_PROMPT,{});if(W.walletCount===0){_("warning","No active wallets found");return}r.value=W.prompt,_("success",`Prompt generated for ${W.walletCount} wallet(s)`)}catch(W){W instanceof T?_("error",K(W.code)):_("error","Failed to generate agent prompt")}finally{s.value=!1}},g=async()=>{r.value&&(await Ti(r.value),_("success","Copied to clipboard!"))};Y(()=>{$(),N(),f(),At().then(({currency:z,rate:D})=>{l.value=z,i.value=D}).catch(()=>{}),q(x.ADMIN_TRANSACTIONS+"?status=APPROVED&limit=1").then(z=>{d.value=z.total}).catch(()=>{});const W=setInterval(()=>{$(),N(),f()},3e4);return()=>clearInterval(W)},[]);const R=a.value&&!t.value;return e("div",{class:"page",children:[n.value&&e("div",{class:"dashboard-error",children:[e("span",{children:n.value}),e(M,{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(ye,{label:"Version",value:t.value?.version??"—",loading:R,badge:t.value&&t.value.updateAvailable?"warning":void 0}),e(ye,{label:"Uptime",value:t.value?ii(t.value.uptime):"—",loading:R}),e(ye,{label:"Wallets",value:t.value?.walletCount?.toString()??"—",loading:R,href:"#/wallets"}),e(ye,{label:"Active Sessions",value:t.value?.activeSessionCount?.toString()??"—",loading:R,href:"#/sessions"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ye,{label:"Kill Switch",value:t.value?.killSwitchState==="ACTIVATED"?"ACTIVATED":"NORMAL",loading:R,badge:t.value?t.value.killSwitchState==="ACTIVATED"?"danger":"success":void 0}),e(ye,{label:"Status",value:t.value?.status??"—",loading:R})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ye,{label:"Policies",value:t.value?.policyCount?.toString()??"—",loading:R,href:"#/policies"}),e(ye,{label:"Recent Txns (24h)",value:t.value?.recentTxCount?.toString()??"—",loading:R,href:"#/transactions"}),e(ye,{label:"Failed Txns (24h)",value:t.value?.failedTxCount?.toString()??"—",loading:R,badge:t.value?t.value.failedTxCount===0?"success":"danger":void 0,href:"#/transactions?status=FAILED"}),e(ye,{label:"Approval Pending",value:d.value?.toString()??"—",loading:R,badge:d.value!=null&&d.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."}),r.value?e(J,{children:[e("pre",{class:"prompt-preview",children:r.value}),e("div",{style:{display:"flex",gap:"var(--space-2)",marginTop:"var(--space-3)"},children:[e(M,{variant:"primary",size:"sm",onClick:g,children:"Copy to Clipboard"}),e(M,{variant:"secondary",size:"sm",onClick:P,loading:s.value,children:"Regenerate"})]})]}):e(M,{variant:"primary",size:"sm",onClick:P,loading:s.value,style:{marginTop:"var(--space-2)"},children:"Generate"})]}),p.value&&p.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(ye,{label:"Total DeFi Value",value:p.value.totalValueUsd!==null?oa(p.value.totalValueUsd,l.value,i.value)??`$${p.value.totalValueUsd.toFixed(2)}`:"—",loading:o.value}),e(ye,{label:"Health Factor",value:p.value.worstHealthFactor!==null?p.value.worstHealthFactor.toFixed(2):"N/A",loading:o.value,badge:p.value.worstHealthFactor!==null?p.value.worstHealthFactor<1.2?"danger":p.value.worstHealthFactor<1.5?"warning":"success":void 0}),e(ye,{label:"Active Positions",value:p.value.activeCount.toString(),loading:o.value})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(Pe,{columns:wi(l.value,i.value),data:p.value.positions,loading:o.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(Pe,{columns:bi(l.value,i.value),data:t.value?.recentTransactions??[],loading:R,emptyMessage:"No recent transactions"})]}),v.value&&e(J,{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(Pe,{columns:[{key:"network",header:"Network"},{key:"calls",header:"Total Calls"},{key:"errors",header:"Errors"},{key:"avgLatencyMs",header:"Avg Latency (ms)",render:W=>W.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(Pe,{columns:[{key:"id",header:"Rule"},{key:"displayName",header:"Name"},{key:"enabled",header:"Status",render:W=>e(V,{variant:W.enabled?"success":"danger",children:W.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(ye,{label:"Notifications Sent (24h)",value:String(v.value.notifications.sentLast24h)}),e(ye,{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(ye,{label:"DB Size",value:_i(v.value.system.dbSizeBytes)}),e(ye,{label:"Schema Version",value:`v${v.value.system.schemaVersion}`}),e(ye,{label:"Node.js",value:v.value.system.nodeVersion}),e(ye,{label:"Platform",value:v.value.system.platform})]})]})]})}function Se({open:t,title:a,children:n,onConfirm:l,onCancel:i,confirmText:s="Confirm",cancelText:r="Cancel",confirmVariant:d="primary",confirmDisabled:p=!1,loading:o=!1}){return Y(()=>{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(M,{variant:"secondary",onClick:i,disabled:o,children:r}),l&&e(M,{variant:d,onClick:l,loading:o,disabled:p,children:s})]})]})}):null}function qe({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 Je({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 Ye({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&&(zn.value?Vn({type:"tab",execute:()=>n(l.key)}):n(l.key))},children:l.label},l.key))})}function ua({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 Gn({value:t,onSearch:a,placeholder:n="Search...",debounceMs:l=300}){const i=Aa(null);function s(d){const p=d.target.value;i.current!==null&&clearTimeout(i.current),i.current=setTimeout(()=>{a(p),i.current=null},l)}function r(){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:s}),t&&e("button",{class:"search-clear",type:"button",onClick:r,children:"x"})]})}function Si(){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,s)=>{l[s]=i}),l}function jt(t){const a=window.location.hash,n=a.indexOf("?"),l=n===-1?a:a.slice(0,n),i=new URLSearchParams;for(const[d,p]of Object.entries(t))p&&i.set(d,p);const s=i.toString(),r=s?`${l}?${s}`:l;window.history.replaceState(null,"",r)}function Qa({fields:t,values:a,onChange:n,syncUrl:l=!0}){Y(()=>{if(!l)return;const r=Si(),d={...a};let p=!1;for(const o of t){const v=r[o.key];v!==void 0&&v!==d[o.key]&&(d[o.key]=v,p=!0)}p&&n(d)},[]);function i(r,d){const p={...a,[r]:d};n(p),l&&jt(p)}function s(){const r={};for(const d of t)r[d.key]="";n(r),l&&jt(r)}return e("div",{class:"filter-bar",children:[t.map(r=>e("div",{class:"filter-field",children:[e("label",{children:r.label}),r.type==="select"?e("select",{value:a[r.key]??"",onChange:d=>i(r.key,d.target.value),children:[e("option",{value:"",children:"All"}),r.options?.map(d=>e("option",{value:d.value,children:d.label},d.value))]}):e("input",{type:"date",value:a[r.key]??"",placeholder:r.placeholder,onChange:d=>i(r.key,d.target.value)})]},r.key)),e("button",{class:"btn btn-secondary filter-clear",type:"button",onClick:s,children:"Clear"})]})}const ki=new Set(["notifications.telegram_bot_token","notifications.discord_webhook_url","notifications.slack_webhook_url","telegram.bot_token"]);function Ni(t){return ki.has(t)}function te(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)",solana_mainnet:"Solana Mainnet",solana_devnet:"Solana Devnet",solana_testnet:"Solana Testnet",evm_ethereum_mainnet:"Ethereum Mainnet",evm_ethereum_sepolia:"Ethereum Sepolia",evm_polygon_mainnet:"Polygon Mainnet",evm_polygon_amoy:"Polygon Amoy",evm_arbitrum_mainnet:"Arbitrum Mainnet",evm_arbitrum_sepolia:"Arbitrum Sepolia",evm_optimism_mainnet:"Optimism Mainnet",evm_optimism_sepolia:"Optimism Sepolia",evm_base_mainnet:"Base Mainnet",evm_base_sepolia:"Base Sepolia",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"}[t]??t.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function he(t,a,n,l){const i=`${n}.${l}`;if(a[i]!==void 0)return a[i];const s=t[n];if(!s)return"";const r=s[l];return typeof r=="boolean"?Ni(i)?"":String(r):r??""}function Re(t,a,n,l){const i=`${n}.${l}`;if(a[i]!==void 0)return a[i]==="true";const s=t[n];if(!s)return!1;const r=s[l];return typeof r=="boolean"?r:r==="true"}function ga(t,a,n,l){const i=`${n}.${l}`;if(a[i]!==void 0)return!1;const s=t[n];return s?s[l]===!0:!1}const Le=[{value:"dcent",label:"D'CENT Wallet",description:"D'CENT hardware wallet with push notification signing"}],La={dcent:"Wallet App (ntfy)"},Ai={dcent:"sdk_ntfy"},za=[{value:"none",label:"None (Lite mode)"},{value:"pimlico",label:"Pimlico"},{value:"alchemy",label:"Alchemy"},{value:"custom",label:"Custom"}],Va={pimlico:"https://dashboard.pimlico.io",alchemy:"https://dashboard.alchemy.com"};function qn(t){switch(t){case"NONE":return"neutral";case"GRACE":return"warning";case"LOCKED":return"success";default:return"neutral"}}function le({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(qe,{value:a})]})]})}const Yt=[{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)"}],Ei=[{key:"overview",label:"Overview"},{key:"transactions",label:"Transactions"},{key:"owner",label:"Owner"},{key:"staking",label:"Staking"},{key:"nfts",label:"NFTs"},{key:"mcp",label:"MCP"}],ha=20,Ci=[{value:"PENDING",label:"PENDING"},{value:"APPROVED",label:"APPROVED"},{value:"SUBMITTED",label:"SUBMITTED"},{value:"CONFIRMED",label:"CONFIRMED"},{value:"FAILED",label:"FAILED"}],Ii=[{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"}],Di=[{key:"status",label:"Status",type:"select",options:Ci},{key:"type",label:"Type",type:"select",options:Ii}],tt=["Time","Type","To","Amount","Network","Status","Tx Hash"];function xi(t){return t==="CONFIRMED"?"success":t==="FAILED"?"danger":"warning"}function Li({id:t}){const a=c(null),n=c(!0),l=c(!1),i=c(""),s=c(!1),r=c(!1),d=c(!1),p=c(!1),o=c(null),v=c([]),h=c(!0),f=c(null),N=c(!0),$=c([]),P=c(!0),g=c(0),R=c(0),W=c({status:"",type:""}),z=c(!1),D=c(null),B=c(!1),A=c(null),E=c(!0),b=c(!1),C=c(null),w=c(!1),u=c(""),m=c(!1),O=c(""),H=c(!1),ne=c(null),G=c(!1),de=c(!1),se=c(""),ae=c(!1),be=c("overview"),De=c("USD"),Ce=c(1),Ee=c([]),I=c(!0),X=c([]),L=c(!1),Z=c(null),re=c("grid"),ee=c(null),xe=c(!1),S=c(""),U=c(null),ie=c(!1),fe=c(!1),Ne=c("pimlico"),We=c(""),Q=c(""),$e=c(""),aa=c(!1),Xe=async()=>{try{const y=await q(x.WALLET(t));a.value=y}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{n.value=!1}},Xn=async()=>{s.value=!0;try{const y=await ue(x.WALLET(t),{name:i.value});a.value=y,l.value=!1,_("success","Wallet name updated")}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{s.value=!1}},Jn=async()=>{d.value=!0;try{await je(x.WALLET(t)),_("success","Wallet terminated"),window.location.hash="#/wallets"}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{d.value=!1}},Zn=async()=>{de.value=!0;try{await ve(x.WALLET_SUSPEND(t),{reason:se.value.trim()||void 0}),_("success","Wallet suspended"),G.value=!1,se.value="",await Xe()}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{de.value=!1}},Qn=async()=>{ae.value=!0;try{await ve(x.WALLET_RESUME(t)),_("success","Wallet resumed"),await Xe()}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{ae.value=!1}},el=async()=>{aa.value=!0;try{const y=Ne.value==="custom"?{provider:"custom",bundlerUrl:Q.value,paymasterUrl:$e.value||void 0}:{provider:Ne.value,apiKey:We.value};await ue(x.WALLET_PROVIDER(t),y),_("success","Provider updated"),fe.value=!1,We.value="",Q.value="",$e.value="",await Xe()}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{aa.value=!1}},al=()=>{a.value?.provider&&(Ne.value=a.value.provider.name),fe.value=!0},tl=()=>{i.value=a.value.name,l.value=!0},nl=()=>{l.value=!1},Ct=async()=>{p.value=!0;try{const y=await ve(x.MCP_TOKENS,{walletId:t});o.value=y,_("success","MCP token provisioned successfully")}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{p.value=!1}},ll=async()=>{h.value=!0;try{const y=await q(x.WALLET_NETWORKS(t));v.value=y.availableNetworks??[]}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code)),v.value=[]}finally{h.value=!1}},It=async()=>{N.value=!0;try{f.value=await q(x.ADMIN_WALLET_BALANCE(t))}catch{f.value=null}finally{N.value=!1}},Dt=async y=>{P.value=!0;try{const j=(y??R.value)*ha,me=await q(`${x.ADMIN_WALLET_TRANSACTIONS(t)}?offset=${j}&limit=${ha}`);$.value=me.items,g.value=me.total}catch{$.value=[],g.value=0}finally{P.value=!1}},et=Ja(()=>{let y=$.value;const F=W.value;return F.status&&(y=y.filter(j=>j.status===F.status)),F.type&&(y=y.filter(j=>j.type===F.type)),y}),xt=async()=>{I.value=!0;try{const y=await q(x.ADMIN_WALLET_STAKING(t));Ee.value=y.positions??[]}catch{Ee.value=[]}finally{I.value=!1}},Ia=async(y,F)=>{const j=y??S.value;if(j){L.value=!0,Z.value=null;try{const me=new URLSearchParams({network:j});F&&me.set("cursor",F),me.set("limit","20");const Fe=await q(`${x.ADMIN_WALLET_NFTS(t)}?${me.toString()}`);F?X.value=[...X.value,...Fe.nfts]:X.value=Fe.nfts,U.value=Fe.cursor??null,ie.value=Fe.hasMore}catch(me){me instanceof T&&me.code==="INDEXER_NOT_CONFIGURED"?Z.value="INDEXER_NOT_CONFIGURED":Z.value="FETCH_ERROR",X.value=[]}finally{L.value=!1}}},Lt=async y=>{if(S.value){xe.value=!0;try{const F=new URLSearchParams({network:S.value}),j=await q(`${x.ADMIN_WALLET_NFT_METADATA(t,encodeURIComponent(y))}?${F.toString()}`);ee.value=j}catch{}finally{xe.value=!1}}},il=async()=>{E.value=!0;try{A.value=await q(x.WALLET_WC_SESSION(t))}catch{A.value=null}finally{E.value=!1}},sl=()=>{C.value&&clearInterval(C.value),C.value=setInterval(async()=>{try{const y=await q(x.WALLET_WC_PAIR_STATUS(t));y.status==="connected"?(C.value&&clearInterval(C.value),C.value=null,z.value=!1,D.value=null,A.value=y.session??null,_("success","Wallet connected via WalletConnect")):(y.status==="expired"||y.status==="none")&&(C.value&&clearInterval(C.value),C.value=null,z.value=!1,D.value=null,_("error","Pairing expired. Try again."))}catch{}},3e3)},rl=async()=>{B.value=!0;try{const y=await ve(x.WALLET_WC_PAIR(t));D.value=y,z.value=!0,sl()}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");F.code==="WC_NOT_CONFIGURED"?(_("error","WalletConnect is not configured. Redirecting to settings..."),pe.value={tab:"walletconnect",fieldName:"walletconnect.project_id"},window.location.hash="#/wallets"):_("error",K(F.code))}finally{B.value=!1}},ol=async()=>{b.value=!0;try{await je(x.WALLET_WC_SESSION(t)),A.value=null,_("success","WalletConnect session disconnected")}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code))}finally{b.value=!1}},Rt=()=>{u.value=a.value?.ownerAddress??"",O.value=a.value?.walletType??"",w.value=!0},cl=()=>{w.value=!1},dl=async()=>{if(!u.value.trim()){_("error","Owner address is required");return}m.value=!0;try{const y={owner_address:u.value.trim()};O.value&&(y.wallet_type=O.value),await ue(x.WALLET_OWNER(t),y),await Xe(),w.value=!1;const F=Le.find(j=>j.value===O.value);F?_("success",`Owner set with ${F.label} auto-setup`):_("success","Owner address updated")}catch(y){const F=y instanceof T?y:new T(0,"UNKNOWN","Unknown error");_("error",K(F.code,F.serverMessage))}finally{m.value=!1}},ul=async y=>{if(a.value?.ownerAddress){m.value=!0;try{const F={owner_address:a.value.ownerAddress};y&&(F.wallet_type=y),await ue(x.WALLET_OWNER(t),F),await Xe(),H.value=!1;const j=Le.find(me=>me.value===y);j?_("success",`Wallet Type changed to ${j.label}`):_("success","Wallet Type cleared")}catch(F){const j=F instanceof T?F:new T(0,"UNKNOWN","Unknown error");_("error",K(j.code,j.serverMessage))}finally{m.value=!1}}},vl=async()=>{try{const y=await q(x.ADMIN_SETTINGS),F=y.signing_sdk?.enabled==="true",j=y.telegram?.bot_token===!0||y.notifications?.telegram_bot_token===!0,me=!!y.walletconnect?.project_id&&y.walletconnect.project_id!=="";ne.value={signingEnabled:F,telegramBotConfigured:j,wcConfigured:me}}catch{}},hl=async y=>{const F=a.value?.walletType;if(F){const j=Le.find(Fe=>Fe.value===F),me=j?Ai[F]:void 0;if(me&&y!==me){const Fe=j.label,kl=Yt.find(Nl=>Nl.value===me)?.label??me;if(!confirm(`${Fe} preset default is "${kl}". Changing the approval method may prevent sign requests from being delivered correctly.
|
|
2
|
-
|
|
3
|
-
Proceed with change?`))return}}try{await ue(x.WALLET_OWNER(t),{owner_address:a.value.ownerAddress,approval_method:y??null}),await Xe(),_("success","Approval method updated")}catch(j){const me=j instanceof T?j:new T(0,"UNKNOWN","Unknown error");_("error",K(me.code,me.serverMessage))}};Y(()=>{Xe(),ll(),It(),Dt(),il(),xt(),vl(),At().then(({currency:y,rate:F})=>{De.value=y,Ce.value=F}).catch(()=>{})},[t]),Y(()=>()=>{C.value&&clearInterval(C.value)},[]),Y(()=>{Dt()},[R.value]);const Ot=R.value*ha,pl=g.value>0?Ot+1:0,ml=Math.min(Ot+ha,g.value),fl=R.value>0,gl=(R.value+1)*ha<g.value;function yl(){return a.value?e(J,{children:[e("div",{class:"detail-grid",children:[e(le,{label:"ID",value:a.value.id,copy:!0}),e(le,{label:"Public Key",value:a.value.publicKey,copy:!0}),e(le,{label:"Chain",value:a.value.chain}),e(le,{label:"Environment",children:e(V,{variant:a.value.environment==="mainnet"?"warning":"info",children:a.value.environment})}),e(le,{label:"Status",children:e(V,{variant:a.value.status==="ACTIVE"?"success":a.value.status==="SUSPENDED"?"warning":"danger",children:a.value.status})}),e(le,{label:"Account Type",children:e(V,{variant:a.value.accountType==="smart"?"info":"default",children:a.value.accountType==="smart"?"Smart Account":"EOA"})}),a.value.accountType==="smart"&&e(J,{children:[e(le,{label:"Signer Key",value:a.value.signerKey??"--",copy:!0}),e(le,{label:"Deployed",children:e(V,{variant:a.value.deployed?"success":"warning",children:a.value.deployed?"Yes":"Not yet"})}),e(le,{label:"Mode",children:[e(V,{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(J,{children:[e(le,{label:"Provider",children:e(V,{variant:"info",children:a.value.provider.name})}),e(le,{label:"Supported Chains",value:a.value.provider.supportedChains.join(", ")||"--"}),e(le,{label:"Paymaster",children:e(V,{variant:a.value.provider.paymasterEnabled?"success":"neutral",children:a.value.provider.paymasterEnabled?"Enabled":"Disabled"})})]}):e(le,{label:"Provider",value:"Not configured"}),fe.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:y=>{Ne.value=y},options:za.map(y=>({label:y.label,value:y.value}))}),Ne.value!=="custom"?e(J,{children:[e(k,{label:"API Key",name:"editApiKey",value:We.value,onChange:y=>{We.value=y},placeholder:"Paste your provider API key"}),Va[Ne.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:Va[Ne.value],target:"_blank",rel:"noopener noreferrer",children:[za.find(y=>y.value===Ne.value)?.label," Dashboard"]})]})]}):e(J,{children:[e(k,{label:"Bundler URL",name:"editBundlerUrl",value:Q.value,onChange:y=>{Q.value=y},placeholder:"https://..."}),e(k,{label:"Paymaster URL (optional)",name:"editPaymasterUrl",value:$e.value,onChange:y=>{$e.value=y},placeholder:"https://..."})]}),e("div",{style:{display:"flex",gap:"var(--space-2)",marginTop:"var(--space-2)"},children:[e(M,{onClick:el,loading:aa.value,children:"Save"}),e(M,{variant:"secondary",onClick:()=>{fe.value=!1},children:"Cancel"})]})]}):e("div",{style:{marginTop:"var(--space-2)"},children:e(M,{variant:"secondary",size:"sm",onClick:al,children:"Change Provider"})})]}),a.value.status==="SUSPENDED"&&e(J,{children:[e(le,{label:"Suspended At",value:a.value.suspendedAt?_e(a.value.suspendedAt):"--"}),e(le,{label:"Suspension Reason",value:a.value.suspensionReason??"--"})]}),e(le,{label:"Created",value:_e(a.value.createdAt)}),e(le,{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(M,{variant:"secondary",size:"sm",onClick:It,loading:N.value,children:"Refresh"})]}),N.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):f.value?.balances?.length?e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)"},children:f.value.balances.map(y=>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:y.network})}),y.error?e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:y.error}):y.native?e("div",{children:[e(le,{label:"Native",children:e("span",{children:[y.native.balance," ",y.native.symbol,y.native.usd!=null&&e("span",{style:{color:"var(--color-text-secondary)",marginLeft:"var(--space-2)",fontSize:"0.85rem"},children:["(",oa(y.native.usd,De.value,Ce.value),")"]})]})}),y.tokens.length>0?y.tokens.map(F=>e(le,{label:F.symbol,value:F.balance},F.address)):null]}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Balance unavailable"})]},y.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"}),h.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:(v.value??[]).map(y=>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:y.name??y.network})},y.network))})]})]}):null}function _l(){return e(J,{children:[e(Qa,{fields:Di,values:W.value,onChange:y=>{W.value=y},syncUrl:!1}),e("div",{class:"table-container",style:{marginTop:"var(--space-3)"},children:e("table",{children:[e("thead",{children:e("tr",{children:tt.map(y=>e("th",{children:y},y))})}),e("tbody",{children:P.value&&et.value.length===0?e("tr",{children:e("td",{colSpan:tt.length,class:"table-loading",children:"Loading..."})}):et.value.length===0?e("tr",{children:e("td",{colSpan:tt.length,class:"table-empty",children:"No transactions yet"})}):et.value.map(y=>e("tr",{children:[e("td",{children:y.createdAt?_e(y.createdAt):"—"}),e("td",{children:e(V,{variant:"info",children:y.type})}),e("td",{children:y.toAddress?Ta(y.toAddress):"—"}),e("td",{children:y.amount?y.formattedAmount??y.amount:"—"}),e("td",{children:y.network??"—"}),e("td",{children:e(V,{variant:xi(y.status),children:y.status})}),e("td",{children:e(Et,{network:y.network??"",txHash:y.txHash})})]},y.id))})]})}),e("div",{class:"pagination",style:{marginTop:"var(--space-3)"},children:[e("span",{class:"pagination-info",children:["Showing ",pl,"-",ml," of ",g.value]}),e("div",{class:"pagination-buttons",children:[e(M,{variant:"secondary",size:"sm",disabled:!fl,onClick:()=>{R.value=R.value-1},children:"Previous"}),e(M,{variant:"secondary",size:"sm",disabled:!gl,onClick:()=>{R.value=R.value+1},children:"Next"})]})]})]})}function bl(){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(M,{size:"sm",onClick:Rt,children:"Set Owner Address"})]}),w.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:O.value,onChange:y=>{O.value=y.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)"}),Le.map(y=>e("option",{value:y.value,children:y.label},y.value))]}),O.value&&e("p",{style:{marginTop:"var(--space-1)",fontSize:"0.8rem",color:"var(--color-text-secondary)"},children:Le.find(y=>y.value===O.value)?.description}),O.value&&La[O.value]&&e("p",{style:{marginTop:"var(--space-1)",fontSize:"0.8rem",color:"var(--color-primary)"},children:["Approval: ",La[O.value]]})]}),e(le,{label:"Address",children:w.value?e("div",{class:"inline-edit",children:[e("input",{value:u.value,onInput:y=>{u.value=y.target.value},class:"inline-edit-input",placeholder:"Enter owner wallet address"}),e(M,{size:"sm",onClick:dl,loading:m.value,children:"Save"}),e(M,{size:"sm",variant:"secondary",onClick:cl,children:"Cancel"})]}):e("span",{children:[a.value.ownerAddress?e(J,{children:[Ta(a.value.ownerAddress),e(qe,{value:a.value.ownerAddress})]}):"Not set",a.value.ownerState!=="LOCKED"&&a.value.status==="ACTIVE"&&e("button",{class:"btn btn-ghost btn-sm",onClick:Rt,title:"Set owner address",children:"✎"})]})}),e(le,{label:"State",children:[e(V,{variant:qn(a.value.ownerState),children:a.value.ownerState}),a.value.walletType&&e(V,{variant:"info",style:{marginLeft:"var(--space-2)"},children:Le.find(y=>y.value===a.value.walletType)?.label??a.value.walletType})]}),a.value.ownerState==="GRACE"&&e("div",{style:{marginTop:"var(--space-3)"},children:[e(le,{label:"Wallet Type",children:H.value?e("div",{class:"inline-edit",children:[e("select",{value:O.value,onChange:y=>{O.value=y.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)"}),Le.map(y=>e("option",{value:y.value,children:y.label},y.value))]}),e(M,{size:"sm",onClick:()=>ul(O.value),loading:m.value,children:"Save"}),e(M,{size:"sm",variant:"secondary",onClick:()=>{H.value=!1},children:"Cancel"})]}):e("span",{children:[Le.find(y=>y.value===a.value.walletType)?.label??a.value.walletType??"Custom",e("button",{class:"btn btn-ghost btn-sm",onClick:()=>{O.value=a.value?.walletType??"",H.value=!0},title:"Change wallet type",children:"✎"})]})}),H.value&&O.value&&La[O.value]&&e("p",{style:{fontSize:"0.8rem",color:"var(--color-primary)",marginTop:"var(--space-1)"},children:["Approval: ",La[O.value]]})]}),a.value.ownerState==="LOCKED"&&a.value.walletType&&e(le,{label:"Wallet Type",children:e("span",{children:Le.find(y=>y.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:Yt.map(y=>e("label",{style:{display:"flex",alignItems:"flex-start",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",background:a.value?.approvalMethod===y.value?"var(--color-bg-secondary)":"transparent",borderRadius:"var(--radius-md)",cursor:"pointer"},children:[e("input",{type:"radio",name:"approval_method",value:y.value??"",checked:a.value?.approvalMethod===y.value,onChange:()=>hl(y.value),style:{marginTop:"2px"},disabled:a.value?.ownerState==="LOCKED"}),e("div",{children:[e("div",{style:{fontWeight:500,fontSize:"0.9rem"},children:y.label}),e("div",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:y.description}),y.warning&&y.warningCondition?.(ne.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:y.warning})]})]},y.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"}),E.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):A.value?e("div",{children:[e(le,{label:"Status",children:e(V,{variant:"success",children:"Connected"})}),e(le,{label:"Peer",value:A.value.peerName??"Unknown"}),e(le,{label:"Chain ID",value:A.value.chainId}),e(le,{label:"Expires",value:_e(A.value.expiry)}),e("div",{style:{marginTop:"var(--space-3)"},children:e(M,{variant:"danger",onClick:ol,loading:b.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(M,{onClick:rl,loading:B.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 wl(){function y(j){return j==="lido"?"info":"neutral"}function F(j){return j==="COMPLETED"?"success":j==="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(M,{variant:"secondary",size:"sm",onClick:xt,loading:I.value,children:"Refresh"})]}),I.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):Ee.value.length===0?e(Je,{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:Ee.value.map(j=>e("tr",{children:[e("td",{children:e(V,{variant:y(j.protocol),children:j.protocol==="lido"?"Lido":"Jito"})}),e("td",{children:j.asset}),e("td",{children:j.chain==="ethereum"?`${(Number(j.balance)/1e18).toFixed(6)} stETH`:`${(Number(j.balance)/1e9).toFixed(6)} JitoSOL`}),e("td",{children:j.balanceUsd?oa(Number(j.balanceUsd),De.value,Ce.value):"—"}),e("td",{children:j.apy??"—"}),e("td",{children:j.pendingUnstake?e("span",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e(V,{variant:F(j.pendingUnstake.status),children:j.pendingUnstake.status}),e("span",{style:{fontSize:"0.85em",color:"var(--color-text-secondary)"},children:j.chain==="ethereum"?`${(Number(j.pendingUnstake.amount)/1e18).toFixed(4)} stETH`:`${(Number(j.pendingUnstake.amount)/1e9).toFixed(4)} JitoSOL`})]}):"—"})]},`${j.protocol}-${j.chain}`))})]})})]})}function Tl(){const y=a.value?.networks?.map(F=>F.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:S.value,onChange:F=>{S.value=String(F),U.value=null,Ia(String(F))},options:[{value:"",label:"Select network..."},...y.map(F=>({value:F,label:F}))]}),e(M,{variant:"ghost",size:"sm",onClick:()=>{re.value=re.value==="grid"?"list":"grid"},title:re.value==="grid"?"Switch to list view":"Switch to grid view",children:re.value==="grid"?"☰":"▦"}),S.value&&e(M,{variant:"secondary",size:"sm",onClick:()=>Ia(),loading:L.value,children:"Refresh"})]}),S.value?L.value&&X.value.length===0?e("div",{class:"stat-skeleton",style:{height:"120px"}}):Z.value==="INDEXER_NOT_CONFIGURED"?e(Je,{title:"NFT indexer not configured",description:"Set up an Alchemy (EVM) or Helius (Solana) API key in Settings > API Keys to view NFTs."}):Z.value?e(Je,{title:"Failed to load NFTs",description:"An error occurred while fetching NFTs."}):X.value.length===0?e(Je,{title:"No NFTs found",description:"This wallet has no NFTs on the selected network."}):re.value==="grid"?e("div",{children:[e("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(180px, 1fr))",gap:"var(--space-3)"},children:X.value.map(F=>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:()=>{ee.value=F;const j=F.contractAddress.includes(":")?F.contractAddress:`${F.contractAddress}:${F.tokenId}`;Lt(j)},children:[F.image?e("img",{src:F.image,alt:F.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:F.name??`#${F.tokenId}`}),e(V,{variant:"neutral",children:F.standard.toUpperCase()})]},`${F.contractAddress}-${F.tokenId}`))}),ie.value&&e("div",{style:{textAlign:"center",marginTop:"var(--space-3)"},children:e(M,{variant:"secondary",onClick:()=>Ia(void 0,U.value??void 0),loading:L.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:X.value.map(F=>e("tr",{style:{cursor:"pointer"},onClick:()=>{ee.value=F;const j=F.contractAddress.includes(":")?F.contractAddress:`${F.contractAddress}:${F.tokenId}`;Lt(j)},children:[e("td",{children:F.image?e("img",{src:F.image,alt:F.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:F.name??"-"}),e("td",{style:{fontFamily:"monospace",fontSize:"0.85em"},children:F.tokenId}),e("td",{children:e(V,{variant:"neutral",children:F.standard.toUpperCase()})}),e("td",{children:F.collection?.name??"-"})]},`${F.contractAddress}-${F.tokenId}`))})]})}),ie.value&&e("div",{style:{textAlign:"center",marginTop:"var(--space-3)"},children:e(M,{variant:"secondary",onClick:()=>Ia(void 0,U.value??void 0),loading:L.value,children:"Load more"})})]}):e(Je,{title:"Select a network",description:"Choose a network to view NFTs."}),e(Se,{open:!!ee.value,title:ee.value?.name??"NFT Details",onCancel:()=>{ee.value=null},onConfirm:()=>{ee.value=null},confirmText:"Close",children:ee.value&&e("div",{children:[ee.value.image&&e("div",{style:{textAlign:"center",marginBottom:"var(--space-3)"},children:e("img",{src:ee.value.image,alt:ee.value.name??"NFT",style:{maxWidth:"300px",maxHeight:"300px",borderRadius:"var(--radius-lg)"}})}),ee.value.description&&e("p",{style:{color:"var(--color-text-secondary)",marginBottom:"var(--space-3)"},children:ee.value.description}),e("div",{class:"detail-grid",style:{marginBottom:"var(--space-3)"},children:[e(le,{label:"Token ID",value:ee.value.tokenId}),e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e(le,{label:"Contract",value:Ta(ee.value.contractAddress??"")}),e(qe,{value:ee.value.contractAddress??""})]}),e(le,{label:"Standard",value:(ee.value.standard??"").toUpperCase()}),ee.value.collection?.name&&e(le,{label:"Collection",value:ee.value.collection.name}),ee.value.assetId&&e(le,{label:"CAIP-19",value:ee.value.assetId})]}),ee.value.attributes&&ee.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:ee.value.attributes.map((F,j)=>e(V,{variant:"info",children:[F.traitType,": ",F.value]},j))})]}),ee.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(ee.value.metadata,null,2)})]})]})})]})}function Sl(){return e("div",{class:"mcp-setup-section",children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"MCP Setup"}),o.value?e("div",{children:[e("div",{class:"detail-grid",style:{marginBottom:"var(--space-4)"},children:[e(le,{label:"Token Path",value:o.value.tokenPath}),e(le,{label:"Expires At",value:_e(o.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:o.value.claudeDesktopConfig},null,2)})}),e("div",{style:{marginTop:"var(--space-2)"},children:e(qe,{value:JSON.stringify({mcpServers:o.value.claudeDesktopConfig},null,2),label:"Copy Config"})})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(M,{variant:"secondary",onClick:Ct,loading:p.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(M,{onClick:Ct,loading:p.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:y=>{i.value=y.target.value},class:"inline-edit-input"}),e(M,{size:"sm",onClick:Xn,loading:s.value,children:"Save"}),e(M,{size:"sm",variant:"secondary",onClick:nl,children:"Cancel"})]}):e("span",{children:[a.value.name,e("button",{class:"btn btn-ghost btn-sm",onClick:tl,title:"Edit name",children:"✎"})]})}),e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[a.value.status==="ACTIVE"&&e(M,{variant:"secondary",onClick:()=>{G.value=!0},children:"Suspend Wallet"}),a.value.status==="SUSPENDED"&&e(M,{variant:"primary",onClick:Qn,loading:ae.value,children:"Resume Wallet"}),a.value.status!=="TERMINATED"&&e(M,{variant:"danger",onClick:()=>{r.value=!0},children:"Terminate Wallet"})]})]}),e(Ye,{tabs:Ei,activeTab:be.value,onTabChange:y=>{be.value=y}}),be.value==="overview"&&e(yl,{}),be.value==="transactions"&&e(_l,{}),be.value==="owner"&&e(bl,{}),be.value==="staking"&&e(wl,{}),be.value==="nfts"&&e(Tl,{}),be.value==="mcp"&&e(Sl,{}),e(Se,{open:r.value,title:"Terminate Wallet",onCancel:()=>{r.value=!1},onConfirm:Jn,confirmText:"Terminate",confirmVariant:"danger",loading:d.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:z.value,title:"Scan QR Code",onCancel:()=>{z.value=!1,C.value&&clearInterval(C.value),C.value=null},children:D.value&&e("div",{style:{textAlign:"center"},children:[e("img",{src:D.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:G.value,title:"Suspend Wallet",onCancel:()=>{G.value=!1,se.value=""},onConfirm:Zn,confirmText:"Suspend",confirmVariant:"danger",loading:de.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:se.value,onChange:y=>{se.value=y},placeholder:"e.g. suspicious activity"})]})]}):e(Je,{title:"Wallet not found",description:"The wallet may have been deleted."})]})}const Ri={"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"},na=["solana-mainnet","solana-devnet","solana-testnet"],pa=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia"];function Oi(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 Pi(t){return na.includes(t)?"solana":"evm"}function Mi(){const t=c({}),a=c({}),n=c({}),l=c(!1),i=c(!0),s=c({}),r=c({}),d=c({}),p=c({}),o=c({}),v=c({}),h=(b,C)=>{const w={},u=[...na,...pa];for(const m of u){const O=[],H=b.rpc_pool;if(H){const se=H[m];if(typeof se=="string"&&se!=="[]")try{const ae=JSON.parse(se);Array.isArray(ae)&&O.push(...ae.filter(be=>typeof be=="string"&&be.length>0))}catch{}}const ne=C[m]??[],G=new Set(O),de=[];for(const se of O)de.push({url:se,isBuiltin:ne.includes(se),enabled:!0});for(const se of ne)G.has(se)||de.push({url:se,isBuiltin:!0,enabled:!0});w[m]=de}return w},f=async()=>{try{try{const w=await q(x.ADMIN_RPC_STATUS);w.builtinUrls&&(p.value=w.builtinUrls),d.value=w.networks??{}}catch{}const b=await q(x.ADMIN_SETTINGS);t.value=b;const C=h(b,p.value);n.value=C,a.value=JSON.parse(JSON.stringify(C))}catch(b){const C=b instanceof T?b:new T(0,"UNKNOWN","Unknown error");_("error",K(C.code))}finally{i.value=!1}};Y(()=>{f()},[]),Y(()=>{const b=async()=>{try{const w=await q(x.ADMIN_RPC_STATUS);d.value=w.networks??{},w.builtinUrls&&(p.value=w.builtinUrls)}catch{}};b();const C=setInterval(b,15e3);return()=>clearInterval(C)},[]);const N=async(b,C)=>{const w=`${b}:${C}`;o.value={...o.value,[w]:!0};try{const u=await ve(x.ADMIN_SETTINGS_TEST_RPC,{url:C,chain:Pi(b)});v.value={...v.value,[w]:u}}catch{v.value={...v.value,[w]:{success:!1,latencyMs:0,error:"Request failed"}}}finally{o.value={...o.value,[w]:!1}}},$=()=>{for(const b of[...na,...pa]){const C=n.value[b]??[],w=a.value[b]??[];if(C.length!==w.length)return!0;for(let u=0;u<C.length;u++)if(C[u].url!==w[u].url||C[u].enabled!==w[u].enabled)return!0}return!1},P=Ja(()=>{let b=0;for(const C of[...na,...pa]){const w=n.value[C]??[],u=a.value[C]??[];if(w.length!==u.length){b++;continue}for(let m=0;m<w.length;m++)if(w[m].url!==u[m].url||w[m].enabled!==u[m].enabled){b++;break}}return b}),g=async()=>{l.value=!0;try{const b=[];for(const u of[...na,...pa]){const O=(a.value[u]??[]).filter(H=>!H.isBuiltin&&H.enabled).map(H=>H.url);b.push({key:`rpc_pool.${u}`,value:JSON.stringify(O)})}const C=await ue(x.ADMIN_SETTINGS,{settings:b});t.value=C.settings;const w=h(C.settings);n.value=w,a.value=JSON.parse(JSON.stringify(w)),_("success","RPC settings saved and applied")}catch(b){const C=b instanceof T?b:new T(0,"UNKNOWN","Unknown error");_("error",K(C.code))}finally{l.value=!1}},R=()=>{a.value=JSON.parse(JSON.stringify(n.value))};Y(()=>(Ue({id:"wallets-rpc",isDirty:$,save:g,discard:R}),()=>Ie("wallets-rpc")),[]);const W=b=>{s.value={...s.value,[b]:!s.value[b]}},z=b=>{const C=(r.value[b]??"").trim();if(!C)return;if(!C.startsWith("https://")){_("warning","URL must start with https://");return}const w=a.value[b]??[];if(w.some(O=>O.url===C)){_("warning","URL already exists in this network");return}const u=[...w];u.findIndex(O=>O.isBuiltin&&!w.slice(0,w.indexOf(O)).some(H=>!H.isBuiltin));const m=u.reduce((O,H,ne)=>H.isBuiltin?O:ne+1,0);u.splice(m,0,{url:C,isBuiltin:!1,enabled:!0}),a.value={...a.value,[b]:u},r.value={...r.value,[b]:""}},D=(b,C)=>{const w=[...a.value[b]??[]];w[C]?.isBuiltin||(w.splice(C,1),a.value={...a.value,[b]:w})},B=(b,C,w)=>{const u=[...a.value[b]??[]],m=w==="up"?C-1:C+1;if(m<0||m>=u.length)return;const O=u[C],H=u[m];!O||!H||([u[C],u[m]]=[u[m],u[C]],a.value={...a.value,[b]:u})},A=(b,C)=>{const w=[...a.value[b]??[]],u=w[C];u?.isBuiltin&&(w[C]={...u,enabled:!u.enabled},a.value={...a.value,[b]:w})};function E({network:b}){const C=a.value[b]??[],w=s.value[b]??!1,u=C.filter(H=>H.enabled).length,m=d.value[b]??[],O=H=>m.find(ne=>ne.url===H);return e("details",{class:"rpc-pool-network",open:w,"data-testid":`rpc-network-${b}`,children:[e("summary",{class:"rpc-pool-network-header",onClick:H=>{H.preventDefault(),W(b)},children:[e("span",{children:Ri[b]??b}),e("span",{class:"rpc-pool-url-count",children:[u," URL",u!==1?"s":""]})]}),w&&e("div",{class:"rpc-url-list",children:[C.map((H,ne)=>{const G=O(H.url),de=`${b}:${H.url}`,se=o.value[de]??!1,ae=v.value[de];return e("div",{class:`rpc-url-item${H.isBuiltin?" rpc-url-item--builtin":""}${H.enabled?"":" rpc-url-disabled"}`,"data-testid":`rpc-url-${b}-${ne}`,children:[e("span",{class:"rpc-url-priority",children:["#",ne+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-${b}-${ne}`,children:G?G.status==="available"?e(J,{children:[e("span",{class:"rpc-url-status-dot rpc-url-status-dot--available"}),e("span",{children:"Available"})]}):e(J,{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:[Oi(G.cooldownRemainingMs)," remaining"]}),e(V,{variant:"warning",children:[G.failureCount," fail",G.failureCount!==1?"s":""]})]}):e(J,{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(M,{variant:"ghost",size:"sm",onClick:()=>N(b,H.url),loading:se,children:"Test"}),ae&&e("span",{class:`rpc-test-result ${ae.success?"rpc-test-result--success":"rpc-test-result--failure"}`,children:[e(V,{variant:ae.success?"success":"danger",children:ae.success?"OK":"FAIL"}),ae.success&&e(J,{children:[" ",ae.latencyMs,"ms",ae.blockNumber!==void 0&&` (block #${ae.blockNumber.toLocaleString()})`]}),ae.error&&` - ${ae.error}`]})]}),e("span",{class:"rpc-url-actions",children:[e("button",{class:"btn btn-ghost btn-sm rpc-action-btn",onClick:()=>B(b,ne,"up"),disabled:ne===0,title:"Move up","aria-label":"Move up",children:"↑"}),e("button",{class:"btn btn-ghost btn-sm rpc-action-btn",onClick:()=>B(b,ne,"down"),disabled:ne===C.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:()=>A(b,ne),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:()=>D(b,ne),title:"Remove","aria-label":"Remove",children:"×"})]})]},`${b}-${ne}`)}),e("div",{class:"rpc-add-url",children:[e("input",{type:"text",class:"rpc-add-url-input",placeholder:"https://your-rpc-url.com",value:r.value[b]??"",onInput:H=>{r.value={...r.value,[b]:H.target.value}},onKeyDown:H=>{H.key==="Enter"&&z(b)}}),e(M,{variant:"secondary",size:"sm",onClick:()=>z(b),children:"Add"})]})]})]})}return i.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(J,{children:[P.value>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[P.value," unsaved change",P.value>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:R,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:g,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"}),na.map(b=>e(E,{network:b},b))]}),e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"EVM"}),pa.map(b=>e(E,{network:b},b))]})]})]})]})}function Ui(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const o=await q(x.ADMIN_SETTINGS);t.value=o}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{l.value=!1}};Y(()=>{i()},[]);const s=(o,v)=>{const h=String(v);a.value={...a.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(a.value).filter(([h])=>h.startsWith("walletconnect.")).map(([h,f])=>({key:h,value:f})),v=await ue(x.ADMIN_SETTINGS,{settings:o});t.value=v.settings,a.value={},_("success","Settings saved and applied")}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{n.value=!1}},d=()=>{a.value={}};Y(()=>(Ue({id:"wallets-walletconnect",isDirty:()=>Object.keys(a.value).filter(o=>o.startsWith("walletconnect.")).length>0,save:r,discard:d}),()=>Ie("wallets-walletconnect")),[]);const p=Object.keys(a.value).filter(o=>o.startsWith("walletconnect.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(J,{children:[p>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[p," unsaved change",p>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:d,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:r,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:te("project_id"),name:"walletconnect.project_id",type:"text",value:he(t.value,a.value,"walletconnect","project_id"),onChange:o=>s("walletconnect.project_id",o),description:"WalletConnect Cloud project identifier"})}),e("div",{class:"settings-field-full",children:e(k,{label:te("relay_url"),name:"walletconnect.relay_url",type:"text",value:he(t.value,a.value,"walletconnect","relay_url"),onChange:o=>s("walletconnect.relay_url",o),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 Wi=[{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 $i(){const t=c([]),a=c(!0),n=c(!1),l=c(""),i=c("solana"),s=c("testnet"),r=c("eoa"),d=c("none"),p=c(""),o=c(""),v=c(""),h=c(null),f=c(!1),N=c(null),$=c(""),P=c({chain:"",environment:"",status:""}),g=async()=>{try{const A=await q(x.WALLETS);t.value=A.items}catch(A){const E=A instanceof T?A:new T(0,"UNKNOWN","Unknown error");_("error",K(E.code))}finally{a.value=!1}},R=Ja(()=>{let A=t.value;const E=$.value.toLowerCase();E&&(A=A.filter(C=>C.name.toLowerCase().includes(E)||C.publicKey.toLowerCase().includes(E)));const b=P.value;return b.chain&&(A=A.filter(C=>C.chain===b.chain)),b.environment&&(A=A.filter(C=>C.environment===b.environment)),b.status&&(A=A.filter(C=>C.status===b.status)),A}),W=[{key:"name",header:"Name"},{key:"chain",header:"Chain"},{key:"environment",header:"Environment",render:A=>e(V,{variant:A.environment==="mainnet"?"warning":"info",children:A.environment})},{key:"accountType",header:"Type",render:A=>A.accountType!=="smart"?e(V,{variant:"default",children:"EOA"}):e(V,{variant:A.provider?"info":"warning",children:A.provider?"Smart (Full)":"Smart (Lite)"})},{key:"publicKey",header:"Public Key",render:A=>e("span",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[Ta(A.publicKey)," ",e(qe,{value:A.publicKey})]})},{key:"status",header:"Status",render:A=>e(V,{variant:A.status==="ACTIVE"?"success":A.status==="SUSPENDED"?"warning":"danger",children:A.status})},{key:"ownerState",header:"Owner",render:A=>e(V,{variant:qn(A.ownerState),children:A.ownerState})},{key:"createdAt",header:"Created",render:A=>_e(A.createdAt)}],z=async()=>{if(!l.value.trim()){h.value="Name is required";return}h.value=null,f.value=!0;try{const A={name:l.value.trim(),chain:i.value,environment:s.value};r.value==="smart"&&(A.accountType="smart",d.value!=="none"&&(d.value==="custom"?(A.aaProvider="custom",A.aaBundlerUrl=o.value,v.value&&(A.aaPaymasterUrl=v.value)):(A.aaProvider=d.value,A.aaProviderApiKey=p.value)));const E=await ve(x.WALLETS,A);E.session?.token?(N.value=E.session.token,_("success","Wallet created with session")):_("success","Wallet created"),l.value="",i.value="solana",s.value="testnet",r.value="eoa",d.value="none",p.value="",o.value="",v.value="",n.value=!1,a.value=!0,await g()}catch(A){const E=A instanceof T?A:new T(0,"UNKNOWN","Unknown error");h.value=K(E.code)}finally{f.value=!1}},D=A=>{window.location.hash="#/wallets/"+A.id},B=A=>{i.value=A,A==="solana"&&(r.value="eoa",d.value="none",p.value="",o.value="",v.value="")};return Y(()=>{g()},[]),e(J,{children:[e("div",{class:"page-actions",children:!n.value&&e(M,{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:A=>{l.value=A},required:!0,placeholder:"e.g. trading-bot",error:h.value??void 0}),e(k,{label:"Chain",name:"chain",type:"select",value:i.value,onChange:B,options:[{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}]}),i.value==="ethereum"&&e(k,{label:"Account Type",name:"accountType",type:"select",value:r.value,onChange:A=>{r.value=A},options:[{label:"EOA (Standard)",value:"eoa"},{label:"Smart Account (ERC-4337)",value:"smart"}]}),r.value==="smart"&&i.value==="ethereum"&&e(J,{children:[e(k,{label:"Provider",name:"provider",type:"select",value:d.value,onChange:A=>{d.value=A},options:za.map(A=>({label:A.label,value:A.value}))}),d.value==="none"?null:d.value!=="custom"?e(J,{children:[e(k,{label:"API Key",name:"apiKey",value:p.value,onChange:A=>{p.value=A},placeholder:"Paste your provider API key"}),Va[d.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:Va[d.value],target:"_blank",rel:"noopener noreferrer",children:[za.find(A=>A.value===d.value)?.label," Dashboard"]})]})]}):e(J,{children:[e(k,{label:"Bundler URL",name:"bundlerUrl",value:o.value,onChange:A=>{o.value=A},placeholder:"https://..."}),e(k,{label:"Paymaster URL (optional)",name:"paymasterUrl",value:v.value,onChange:A=>{v.value=A},placeholder:"https://..."})]})]}),e(k,{label:"Environment",name:"environment",type:"select",value:s.value,onChange:A=>{s.value=A},options:[{label:"Testnet",value:"testnet"},{label:"Mainnet",value:"mainnet"}]}),e("div",{class:"inline-form-actions",children:[e(M,{onClick:z,loading:f.value,children:"Create"}),e(M,{variant:"secondary",onClick:()=>{n.value=!1,h.value=null},children:"Cancel"})]})]}),N.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:N.value,style:{flex:1,fontFamily:"monospace",fontSize:"0.85rem",padding:"0.5rem"},onClick:A=>A.target.select()}),e(M,{variant:"secondary",onClick:()=>{navigator.clipboard.writeText(N.value),_("success","Token copied")},children:"Copy"}),e(M,{variant:"secondary",onClick:()=>{N.value=null},children:"Dismiss"})]})]}),e(Qa,{fields:Wi,values:P.value,onChange:A=>{P.value=A},syncUrl:!1}),e(Gn,{value:$.value,onSearch:A=>{$.value=A},placeholder:"Search by name or public key..."}),e(Pe,{columns:W,data:R.value,loading:a.value,onRowClick:D,emptyMessage:"No wallets yet"})]})}const Xt=[{key:"wallets",label:"Wallets"},{key:"rpc",label:"RPC Endpoints"},{key:"walletconnect",label:"WalletConnect"}];function Fi(){const t=c("wallets");return Y(()=>{const a=pe.value;a&&a.tab&&(t.value=a.tab,setTimeout(()=>{Ae.value=a.fieldName},100),pe.value=null)},[pe.value]),e("div",{class:"page",children:[e(ua,{pageName:"Wallets",tabName:Xt.find(a=>a.key===t.value)?.label??"",onPageClick:()=>{t.value="wallets"}}),e(Ye,{tabs:Xt,activeTab:t.value,onTabChange:a=>{t.value=a}}),t.value==="wallets"&&e($i,{}),t.value==="rpc"&&e(Mi,{}),t.value==="walletconnect"&&e(Ui,{})]})}function Jt(){const t=Be.value,a=t.startsWith("/wallets/")?t.slice(9):null;return a?e(Li,{id:a}):e(Fi,{})}const Zt=[{key:"transactions",label:"All Transactions"},{key:"monitor",label:"Monitor Settings"}],He=20,Ki=[{value:"all",label:"All"},{value:"outgoing",label:"Outgoing"},{value:"incoming",label:"Incoming"}],Hi=[{value:"TRANSFER",label:"TRANSFER"},{value:"TOKEN_TRANSFER",label:"TOKEN_TRANSFER"},{value:"CONTRACT_CALL",label:"CONTRACT_CALL"},{value:"APPROVE",label:"APPROVE"},{value:"BATCH",label:"BATCH"}],Bi=[{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"}],zi=[{value:"DETECTED",label:"DETECTED"},{value:"CONFIRMED",label:"CONFIRMED"}],Vi=[{value:"solana",label:"Solana"},{value:"evm",label:"EVM"}],Gi=[{value:"true",label:"Yes"},{value:"false",label:"No"}],qi=[{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"}],Ra=["Time","Direction","Wallet","Counterparty","Amount","Network","Status","Tx Hash"];function ji(t){return t==="CONFIRMED"?"success":t==="FAILED"?"danger":"warning"}function Qt(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 en(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 an(){const t=c("transactions"),a=c([]),n=c(0),l=c(0),i=c(!0),s=c(null),r=c("all"),d=c({wallet_id:"",type:"",status:"",network:"",chain:"",suspicious:"",since:"",until:""}),p=c(""),o=c(0),v=c(null),h=c("USD"),f=c(1),N=c([]),$=c({}),P=c({}),g=c(!1),R=c(!0),W=c([]),z=c(!0),D=c({}),B=c(null),A=(S,U)=>{P.value={...P.value,[S]:String(U)}},E=(S,U)=>he($.value,P.value,S,U),b=async()=>{g.value=!0;try{const S=Object.entries(P.value).filter(([ie])=>ie.startsWith("incoming.")).map(([ie,fe])=>({key:ie,value:fe}));if(S.length===0){_("info","No changes to save"),g.value=!1;return}const U=await ue(x.ADMIN_SETTINGS,{settings:S});$.value=U.settings,P.value={},_("success","Settings saved and applied")}catch(S){const U=S instanceof T?S:new T(0,"UNKNOWN","Unknown error");_("error",K(U.code))}finally{g.value=!1}},C=()=>{P.value={}};Y(()=>(Object.keys(P.value).filter(U=>U.startsWith("incoming.")).length>0?Ue({id:"transactions-monitor",isDirty:()=>Object.keys(P.value).filter(U=>U.startsWith("incoming.")).length>0,save:b,discard:C}):Ie("transactions-monitor"),()=>Ie("transactions-monitor")),[P.value]);function w(){const S=r.value,U=[{key:"wallet_id",label:"Wallet",type:"select",options:N.value}];return(S==="outgoing"||S==="all")&&U.push({key:"type",label:"Type",type:"select",options:Hi}),S==="outgoing"?U.push({key:"status",label:"Status",type:"select",options:Bi}):S==="incoming"&&U.push({key:"status",label:"Status",type:"select",options:zi}),U.push({key:"network",label:"Network",type:"select",options:qi}),(S==="incoming"||S==="all")&&(U.push({key:"chain",label:"Chain",type:"select",options:Vi}),U.push({key:"suspicious",label:"Suspicious",type:"select",options:Gi})),U.push({key:"since",label:"Since",type:"date"},{key:"until",label:"Until",type:"date"}),U}const u=async()=>{const S=new URLSearchParams,U=d.value;if(U.wallet_id&&S.set("wallet_id",U.wallet_id),U.type&&S.set("type",U.type),U.status&&r.value!=="all"&&S.set("status",U.status),U.network&&S.set("network",U.network),U.since){const ie=new Date(U.since);isNaN(ie.getTime())||S.set("since",String(Math.floor(ie.getTime()/1e3)))}if(U.until){const ie=new Date(U.until);isNaN(ie.getTime())||(ie.setHours(23,59,59,999),S.set("until",String(Math.floor(ie.getTime()/1e3))))}return p.value&&S.set("search",p.value),S.set("offset",String(o.value*He)),S.set("limit",String(He)),q(`${x.ADMIN_TRANSACTIONS}?${S.toString()}`)},m=async()=>{const S=new URLSearchParams,U=d.value;return U.wallet_id&&S.set("wallet_id",U.wallet_id),U.chain&&S.set("chain",U.chain),U.status&&r.value!=="all"&&S.set("status",U.status),U.suspicious&&S.set("suspicious",U.suspicious),S.set("offset",String(o.value*He)),S.set("limit",String(He)),q(`${x.ADMIN_INCOMING}?${S.toString()}`)},O=async()=>{i.value=!0,s.value=null;try{const S=r.value;if(S==="outgoing"){const U=await u();a.value=U.items.map(Qt),n.value=U.total,l.value=0}else if(S==="incoming"){const U=await m();a.value=U.items.map(en),n.value=0,l.value=U.total}else{const[U,ie]=await Promise.all([u(),m()]),fe=[...U.items.map(Qt),...ie.items.map(en)];fe.sort((Ne,We)=>(We.time??0)-(Ne.time??0)),a.value=fe,n.value=U.total,l.value=ie.total}}catch(S){S instanceof T?s.value=K(S.code):s.value="An unexpected error occurred."}finally{i.value=!1}},H=async()=>{try{const S=await q(x.WALLETS),U=Array.isArray(S)?S:S.items??[];N.value=U.map(fe=>({value:fe.id,label:fe.name||fe.id.slice(0,8)})),W.value=U;const ie={};for(const fe of U)ie[fe.id]=fe.monitorIncoming??!1;D.value=ie}catch{}finally{z.value=!1}},ne=async()=>{try{const S=await q(x.ADMIN_SETTINGS);$.value=S}catch(S){const U=S instanceof T?S:new T(0,"UNKNOWN","Unknown error");_("error",K(U.code))}finally{R.value=!1}};Y(()=>{O(),H(),At().then(({currency:S,rate:U})=>{h.value=S,f.value=U}).catch(()=>{}),ne()},[]),Y(()=>{O()},[d.value,p.value,o.value,r.value]),Y(()=>{const S=pe.value;S&&S.tab&&(t.value=S.tab,pe.value=null,setTimeout(()=>{Ae.value=S.fieldName},100))},[pe.value]);function G(S){t.value=S}function de(S){d.value=S,o.value=0}function se(S){p.value=S,o.value=0}function ae(S){r.value=S,o.value=0,d.value={...d.value,type:"",status:"",chain:"",suspicious:""}}function be(S){v.value=v.value===S.id?null:S.id}function De(){o.value>0&&(o.value=o.value-1)}function Ce(){const S=n.value+l.value;(o.value+1)*He<S&&(o.value=o.value+1)}async function Ee(S){if(window.confirm("Are you sure you want to cancel this transaction?"))try{await ve(x.ADMIN_TX_CANCEL(S)),_("success","Transaction cancelled"),await O()}catch(U){const ie=U instanceof T?U:new T(0,"UNKNOWN","Unknown error");_("error",K(ie.code))}}async function I(S){if(window.confirm("Are you sure you want to reject this transaction?"))try{await ve(x.ADMIN_TX_REJECT(S)),_("success","Transaction rejected"),await O()}catch(U){const ie=U instanceof T?U:new T(0,"UNKNOWN","Unknown error");_("error",K(ie.code))}}async function X(S){const U=D.value[S]??!1;B.value=S;try{const ie=await li(x.WALLET_PATCH(S),{monitorIncoming:!U});D.value={...D.value,[S]:ie.monitorIncoming}}catch(ie){const fe=ie instanceof T?ie:new T(0,"UNKNOWN","Unknown error");_("error",K(fe.code))}finally{B.value=null}}function L(){const S=n.value+l.value,U=o.value*He,ie=S>0?U+1:0,fe=Math.min(U+He,S),Ne=o.value>0,We=(o.value+1)*He<S;return e(J,{children:[s.value&&e("div",{class:"dashboard-error",children:[e("span",{children:s.value}),e(M,{variant:"secondary",size:"sm",onClick:O,children:"Retry"})]}),e("div",{class:"filter-bar",style:{marginBottom:0},children:e("div",{class:"filter-field",children:[e("label",{children:"Direction"}),e("select",{value:r.value,onChange:Q=>ae(Q.target.value),children:Ki.map(Q=>e("option",{value:Q.value,children:Q.label},Q.value))})]})}),e(Qa,{fields:w(),values:d.value,onChange:de}),r.value!=="incoming"&&e(Gn,{value:p.value,onSearch:se,placeholder:"Search by txHash or recipient address..."}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:Ra.map(Q=>e("th",{children:Q},Q))})}),e("tbody",{children:i.value&&a.value.length===0?e("tr",{children:e("td",{colSpan:Ra.length,class:"table-loading",children:"Loading..."})}):a.value.length===0?e("tr",{children:e("td",{colSpan:Ra.length,class:"table-empty",children:"No transactions found"})}):a.value.map(Q=>e(J,{children:[e("tr",{class:`clickable${v.value===Q.id?" row-expanded":""}`,style:{cursor:"pointer"},onClick:()=>be(Q),children:[e("td",{children:Q.time?_e(Q.time):"—"}),e("td",{children:e(V,{variant:Q.direction==="outgoing"?"info":"success",children:Q.direction==="outgoing"?"Outgoing":"Incoming"})}),e("td",{children:Q.walletName??Q.walletId.slice(0,8)}),e("td",{children:Q.counterparty?Ta(Q.counterparty):"—"}),e("td",{children:Q.amount?(()=>{const $e=Q.formattedAmount??Q.amount;if(Q.amountUsd!=null){const aa=oa(Q.amountUsd,h.value,f.value);return aa?`${$e} (${aa})`:$e}return $e})():"—"}),e("td",{children:Q.network}),e("td",{children:e(V,{variant:ji(Q.status),children:Q.status})}),e("td",{children:e(Et,{network:Q.network,txHash:Q.txHash})})]},Q.id),v.value===Q.id&&e("tr",{class:"row-expand",children:e("td",{colSpan:Ra.length,children:[Q.outgoing?Z(Q.outgoing):null,Q.incoming?re(Q.incoming):null]})},`${Q.id}-expand`)]}))})]})}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Showing ",ie,"-",fe," of ",S]}),e("div",{class:"pagination-buttons",children:[e(M,{variant:"secondary",size:"sm",disabled:!Ne,onClick:De,children:"Previous"}),e(M,{variant:"secondary",size:"sm",disabled:!We,onClick:Ce,children:"Next"})]})]})]})}function Z(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(M,{variant:"danger",size:"sm",onClick:U=>{U.stopPropagation(),Ee(S.id)},children:"Cancel"}),e(M,{variant:"secondary",size:"sm",onClick:U=>{U.stopPropagation(),I(S.id)},children:"Reject"})]})})]})}function re(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 ee(){const S=Object.keys(P.value).filter(U=>U.startsWith("incoming.")).length;return e(J,{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(M,{variant:"ghost",size:"sm",onClick:C,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:b,loading:g.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:R.value?e("span",{children:"Loading settings..."}):e(J,{children:[e("div",{class:"settings-fields-grid",children:[e(k,{label:"Monitoring Enabled",name:"incoming.enabled",type:"select",value:E("incoming","enabled")||"false",onChange:U=>A("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(E("incoming","poll_interval"))||30,onChange:U=>A("incoming.poll_interval",U),min:5,max:3600}),e(k,{label:"Retention Days",name:"incoming.retention_days",type:"number",value:Number(E("incoming","retention_days"))||90,onChange:U=>A("incoming.retention_days",U),min:1,max:365}),e(k,{label:"Suspicious Dust USD Threshold",name:"incoming.suspicious_dust_usd",type:"number",value:Number(E("incoming","suspicious_dust_usd"))||.01,onChange:U=>A("incoming.suspicious_dust_usd",U),min:0,max:1e3}),e(k,{label:"Suspicious Amount Multiplier",name:"incoming.suspicious_amount_multiplier",type:"number",value:Number(E("incoming","suspicious_amount_multiplier"))||10,onChange:U=>A("incoming.suspicious_amount_multiplier",U),min:1,max:1e3}),e(k,{label:"Notification Cooldown (minutes)",name:"incoming.cooldown_minutes",type:"number",value:Number(E("incoming","cooldown_minutes"))||5,onChange:U=>A("incoming.cooldown_minutes",U),min:1,max:1440}),e(k,{label:"WebSocket URL (optional)",name:"incoming.wss_url",type:"text",value:E("incoming","wss_url"),onChange:U=>A("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:z.value?e("span",{children:"Loading wallets..."}):W.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:W.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(V,{variant:(U.status??"ACTIVE")==="ACTIVE"?"success":"warning",children:U.status??"ACTIVE"})}),e("td",{children:e(M,{variant:D.value[U.id]?"primary":"secondary",size:"sm",onClick:()=>X(U.id),loading:B.value===U.id,children:D.value[U.id]?"ON":"OFF"})})]},U.id))})]})})})]})]})}const xe=Zt.find(S=>S.key===t.value)?.label;return e("div",{class:"page",children:[e(ua,{pageName:"Transactions",tabName:xe,onPageClick:()=>{t.value="transactions"}}),e(Ye,{tabs:Zt,activeTab:t.value,onTabChange:G}),e("div",{style:{marginTop:"var(--space-4)"},children:t.value==="transactions"?L():ee()})]})}const Yi=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia"],nt=["Symbol","Name","Address","Decimals","Source","Actions"];function Xi(t){return t.length<=10?t:`${t.slice(0,6)}...${t.slice(-4)}`}function Ji(){const t=c("ethereum-mainnet"),a=c([]),n=c(!0),l=c(null),i=c(!1),s=c(""),r=c(""),d=c(""),p=c("18"),o=c(!1),v=c(!1),h=c(null),f=Aa(null),N=async()=>{n.value=!0,l.value=null;try{const D=await q(`${x.TOKENS}?network=${encodeURIComponent(t.value)}`);a.value=D.tokens}catch(D){D instanceof T?l.value=K(D.code):l.value="An unexpected error occurred.",a.value=[]}finally{n.value=!1}};Y(()=>{N()},[t.value]);function $(D){t.value=D.target.value}function P(){s.value="",r.value="",d.value="",p.value="18",v.value=!1,i.value=!1,f.current&&clearTimeout(f.current)}async function g(D){v.value=!0;try{const B=await q(`${x.TOKENS_RESOLVE}?network=${encodeURIComponent(t.value)}&address=${encodeURIComponent(D)}`);r.value=B.symbol,d.value=B.name,p.value=String(B.decimals),_("success",`Resolved: ${B.symbol} (${B.name})`)}catch{}finally{v.value=!1}}function R(D){const B=D.target.value;s.value=B,f.current&&clearTimeout(f.current),/^0x[a-fA-F0-9]{40}$/.test(B)&&(f.current=setTimeout(()=>g(B),500))}async function W(){if(!s.value||!r.value||!d.value){_("error","Please fill in all required fields.");return}o.value=!0;try{await ve(x.TOKENS,{network:t.value,address:s.value,symbol:r.value,name:d.value,decimals:Number(p.value)}),_("success",`Token ${r.value} added successfully.`),P(),await N()}catch(D){D instanceof T?_("error",K(D.code)):_("error","Failed to add token.")}finally{o.value=!1}}async function z(D){h.value=D;try{await je(x.TOKENS,{network:t.value,address:D}),_("success","Token removed successfully."),await N()}catch(B){B instanceof T?_("error",K(B.code)):_("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(M,{variant:"secondary",size:"sm",onClick:N,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:Yi.map(D=>e("option",{value:D,children:D},D))})]}),e("div",{style:{marginLeft:"auto"},children:e(M,{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:s.value,onInput:R,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:r.value,onInput:D=>{r.value=D.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:d.value,onInput:D=>{d.value=D.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:p.value,onInput:D=>{p.value=D.target.value},placeholder:"18"})]})]}),e("div",{style:{marginTop:"var(--space-3)",display:"flex",gap:"var(--space-2)"},children:[e(M,{variant:"primary",size:"sm",loading:o.value,onClick:W,children:"Submit"}),e(M,{variant:"secondary",size:"sm",onClick:P,children:"Cancel"})]})]}),e("div",{class:"table-container",style:{marginTop:"var(--space-3)"},children:e("table",{children:[e("thead",{children:e("tr",{children:nt.map(D=>e("th",{children:D},D))})}),e("tbody",{children:n.value&&a.value.length===0?e("tr",{children:e("td",{colSpan:nt.length,class:"table-loading",children:"Loading..."})}):a.value.length===0?e("tr",{children:e("td",{colSpan:nt.length,class:"table-empty",children:"No tokens found for this network"})}):a.value.map(D=>e("tr",{children:[e("td",{children:D.symbol}),e("td",{children:D.name}),e("td",{title:D.address,children:Xi(D.address)}),e("td",{children:D.decimals}),e("td",{children:e(V,{variant:D.source==="builtin"?"neutral":"info",children:D.source==="builtin"?"Built-in":"Custom"})}),e("td",{children:D.source==="custom"?e(M,{variant:"danger",size:"sm",loading:h.value===D.address,onClick:()=>z(D.address),children:"Delete"}):"—"})]},D.address))})]})})]})}function Ve({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 Zi(t,a,n){a.value=t,n.value=!0}const tn=[{key:"sessions",label:"Sessions"},{key:"settings",label:"Settings"}],lt=["security.max_sessions_per_wallet","security.max_pending_tx","security.rate_limit_session_rpm","security.rate_limit_tx_rpm"];function Qi(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const o=await q(x.ADMIN_SETTINGS);t.value=o}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{l.value=!1}};Y(()=>{i()},[]);const s=(o,v)=>{const h=String(v);a.value={...a.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(a.value).filter(([h])=>lt.includes(h)).map(([h,f])=>({key:h,value:f})),v=await ue(x.ADMIN_SETTINGS,{settings:o});t.value=v.settings,a.value={},_("success","Session settings saved and applied")}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{n.value=!1}},d=()=>{a.value={}};Y(()=>(Ue({id:"sessions-settings",isDirty:()=>Object.keys(a.value).filter(o=>lt.includes(o)).length>0,save:r,discard:d}),()=>Ie("sessions-settings")),[]);const p=Object.keys(a.value).filter(o=>lt.includes(o)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(J,{children:[p>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[p," unsaved change",p>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:d,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:r,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(Ve,{legend:"Limits",description:"Session concurrency limits",children:e("div",{class:"settings-fields-grid",children:e(k,{label:te("max_sessions_per_wallet"),name:"security.max_sessions_per_wallet",type:"number",value:Number(he(t.value,a.value,"security","max_sessions_per_wallet"))||0,onChange:o=>s("security.max_sessions_per_wallet",o),min:1,max:100,description:"Maximum concurrent sessions for a single wallet"})})}),e(Ve,{legend:"Rate Limits",description:"Request throttling per session and transaction",children:e("div",{class:"settings-fields-grid",children:[e(k,{label:te("max_pending_tx"),name:"security.max_pending_tx",type:"number",value:Number(he(t.value,a.value,"security","max_pending_tx"))||0,onChange:o=>s("security.max_pending_tx",o),min:1,max:100,description:"Maximum in-flight transactions per session"}),e(k,{label:te("rate_limit_session_rpm"),name:"security.rate_limit_session_rpm",type:"number",value:Number(he(t.value,a.value,"security","rate_limit_session_rpm"))||0,onChange:o=>s("security.rate_limit_session_rpm",o),min:10,description:"Max requests per minute per session"}),e(k,{label:te("rate_limit_tx_rpm"),name:"security.rate_limit_tx_rpm",type:"number",value:Number(he(t.value,a.value,"security","rate_limit_tx_rpm"))||0,onChange:o=>s("security.rate_limit_tx_rpm",o),min:1,description:"Max transaction requests per minute per session"})]})})]})]})]})}function es(){const t=c("sessions");Y(()=>{const u=pe.value;u&&u.tab&&(t.value=u.tab,setTimeout(()=>{Ae.value=u.fieldName},100),pe.value=null)},[pe.value]);const a=c([]),n=c(""),l=c(""),i=c([]),s=c(!1),r=c(!0),d=c(!1),p=c(!1),o=c(""),v=c(!1),h=c(""),f=c(!1),N=c(null),$=c(!1),P=c(new Set),g=c(!1),R=c(""),W=c(""),z=c(""),D=async()=>{try{const u=await q(x.WALLETS);a.value=u.items.filter(m=>m.status==="ACTIVE")}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{r.value=!1}},B=async()=>{s.value=!0;try{const u=n.value?`${x.SESSIONS}?walletId=${n.value}`:x.SESSIONS,m=await q(u);i.value=m}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{s.value=!1}},A=u=>{const m=new Set(P.value);m.has(u)?m.delete(u):m.add(u),P.value=m},E=async()=>{d.value=!0;try{const u=Array.from(P.value),m=u.length===1?{walletId:u[0]}:{walletIds:u},O=Number(R.value);O>0&&(m.ttl=O*86400);const H=Number(W.value);W.value!==""&&H>=0&&(m.maxRenewals=H);const ne=Number(z.value);ne>0&&(m.absoluteLifetime=ne*86400);const G=await ve(x.SESSIONS,m);o.value=G.token,p.value=!0,$.value=!1,g.value=!1,R.value="",W.value="",z.value="",await B()}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{d.value=!1}},b=async()=>{f.value=!0;try{await je(x.SESSION(h.value)),_("success","Session revoked"),v.value=!1,await B()}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{f.value=!1}},C=async u=>{N.value=u;try{const m=await ve(x.ADMIN_SESSION_REISSUE(u),{});o.value=m.token,p.value=!0,await B()}catch(m){const O=m instanceof T?m:new T(0,"UNKNOWN","Unknown error");_("error",K(O.code))}finally{N.value=null}};Y(()=>{D()},[]),Y(()=>{i.value=[],B()},[n.value]);const w=[{key:"id",header:"ID",render:u=>u.id.slice(0,8)+"..."},{key:"walletName",header:"Wallet",render:u=>u.wallets&&u.wallets.length>0?e("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:u.wallets.map(m=>e("span",{children:m.name??m.id.slice(0,8)},m.id))}):u.walletName??u.walletId.slice(0,8)+"..."},{key:"source",header:"Source",render:u=>e(V,{variant:u.source==="mcp"?"info":"neutral",children:u.source==="mcp"?"MCP":"API"})},{key:"status",header:"Status",render:u=>e(V,{variant:u.status==="ACTIVE"?"success":u.status==="EXPIRED"?"warning":"danger",children:u.status})},{key:"expiresAt",header:"Expires At",render:u=>u.expiresAt===0?"Never":_e(u.expiresAt)},{key:"renewals",header:"Renewals",render:u=>`${u.renewalCount}/${u.maxRenewals}`},{key:"tokenIssuedCount",header:"Tokens",render:u=>String(u.tokenIssuedCount??1)},{key:"createdAt",header:"Created",render:u=>_e(u.createdAt)},{key:"actions",header:"Actions",render:u=>u.status==="ACTIVE"?e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[e(M,{size:"sm",variant:"secondary",onClick:()=>C(u.id),loading:N.value===u.id,children:"Reissue"}),e(M,{size:"sm",variant:"danger",onClick:()=>Zi(u.id,h,v),children:"Revoke"})]}):null}];return e("div",{class:"page",children:[e(ua,{pageName:"Sessions",tabName:tn.find(u=>u.key===t.value)?.label??"",onPageClick:()=>{t.value="sessions"}}),e(Ye,{tabs:tn,activeTab:t.value,onTabChange:u=>{t.value=u}}),t.value==="sessions"&&e(J,{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:u=>{n.value=u.target.value},disabled:r.value,children:[e("option",{value:"",children:"All Wallets"}),a.value.map(u=>e("option",{value:u.id,children:[u.name," (",u.chain,"/",u.network,")"]},u.id))]})]}),e("div",{class:"session-wallet-select",children:[e("label",{for:"source-select",children:"Source"}),e("select",{id:"source-select",value:l.value,onChange:u=>{l.value=u.target.value},children:[e("option",{value:"",children:"All"}),e("option",{value:"api",children:"API"}),e("option",{value:"mcp",children:"MCP"})]})]}),e(M,{onClick:()=>{P.value=new Set,$.value=!0},disabled:a.value.length===0,children:"Create Session"})]}),e(Pe,{columns:w,data:l.value?i.value.filter(u=>u.source===l.value):i.value,loading:s.value,emptyMessage:"No sessions"}),e(Se,{open:p.value,title:"Session Created",onCancel:()=>{p.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:o.value}),e(qe,{value:o.value,label:"Copy Token"})]})]}),e(Se,{open:v.value,title:"Revoke Session",onCancel:()=>{v.value=!1},onConfirm:b,confirmText:"Revoke",confirmVariant:"danger",loading:f.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:E,confirmText:`Create Session (${P.value.size} wallet${P.value.size!==1?"s":""})`,confirmDisabled:P.value.size===0,loading:d.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(u=>e("label",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)",padding:"var(--space-1) 0",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:P.value.has(u.id),onChange:()=>A(u.id)}),e("span",{children:u.name}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:["(",u.chain,"/",u.network,")"]})]},u.id))})]}),e("div",{style:{marginTop:"var(--space-3)"},children:[e("button",{type:"button",onClick:()=>{g.value=!g.value},style:{background:"none",border:"none",color:"var(--color-primary)",cursor:"pointer",padding:0,fontSize:"0.85rem"},children:[g.value?"Hide":"Show"," Advanced Options"]}),g.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:R.value,onChange:u=>{R.value=String(u)},min:0,description:"Leave empty for unlimited session",placeholder:"Unlimited"}),e(k,{label:"Max Renewals",name:"create-max-renewals",type:"number",value:W.value,onChange:u=>{W.value=String(u)},min:0,description:"0 = unlimited renewals",placeholder:"Unlimited"}),e(k,{label:"Absolute Lifetime (days)",name:"create-lifetime",type:"number",value:z.value,onChange:u=>{z.value=String(u)},min:0,description:"Leave empty for unlimited lifetime",placeholder:"Unlimited"})]})]})]})]}),t.value==="settings"&&e(Qi,{})]})}const as={"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"};function ts(t){return t&&as[t]||"Native"}const nn=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia"];function ns({rules:t,onChange:a,errors:n,network:l}){const i=c([]),s=c(!1),r=g=>R=>{a({...t,[g]:R})},d=g=>R=>{const W=Number(R),z={...t};R===""||R===0||Number.isNaN(W)?delete z[g]:z[g]=W,a(z)},p=t.token_limits||{},o=g=>R=>{const W=String(R),D={...p.native||{instant_max:"",notify_max:"",delay_max:""},[g]:W};if(!D.instant_max&&!D.notify_max&&!D.delay_max){const B={...p};delete B.native,a({...t,token_limits:Object.keys(B).length>0?B:void 0})}else a({...t,token_limits:{...p,native:D}})},v=(g,R,W)=>{const D={...p[g]||{instant_max:"0",notify_max:"0",delay_max:"0"},[R]:W};a({...t,token_limits:{...p,[g]:D}})},h=g=>{const R={...p};delete R[g],a({...t,token_limits:Object.keys(R).length>0?R:void 0})},f=g=>{if(!g||p[g])return;const R={instant_max:"0",notify_max:"0",delay_max:"0"};a({...t,token_limits:{...p,[g]:R}})},N=()=>{const g=prompt("Enter CAIP-19 asset ID (e.g., eip155:1/erc20:0xa0b8...)");if(!g||p[g])return;const R={instant_max:"0",notify_max:"0",delay_max:"0"};a({...t,token_limits:{...p,[g]:R}})};Y(()=>{if(!l){i.value=[];return}if(!nn.includes(l)){i.value=[];return}s.value=!0,q(`${x.TOKENS}?network=${l}`).then(g=>{i.value=g.tokens}).catch(()=>{i.value=[]}).finally(()=>{s.value=!1})},[l]);const $=Object.entries(p).filter(([g])=>g!=="native").map(([g,R])=>({assetId:g,symbol:i.value.find(W=>W.assetId===g)?.symbol||g.split("/").pop()?.split(":").pop()||g,instant_max:R.instant_max,notify_max:R.notify_max,delay_max:R.delay_max})),P=ts(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:d("instant_max_usd"),placeholder:"Optional"}),e(k,{label:"Notify Max USD",name:"notify_max_usd",type:"number",value:t.notify_max_usd??"",onChange:d("notify_max_usd"),placeholder:"Optional"}),e(k,{label:"Delay Max USD",name:"delay_max_usd",type:"number",value:t.delay_max_usd??"",onChange:d("delay_max_usd"),placeholder:"Optional"})]}),e("h4",{children:"Token-Specific Limits"}),e("h5",{children:["Native Token (",P,")"]}),e("div",{class:"policy-form-grid",children:[e(k,{label:`Instant Max (${P})`,name:"native_instant_max",value:p.native?.instant_max??"",onChange:o("instant_max"),placeholder:"e.g. 0.5",error:n["token_limits.native.instant_max"]}),e(k,{label:`Notify Max (${P})`,name:"native_notify_max",value:p.native?.notify_max??"",onChange:o("notify_max"),placeholder:"e.g. 0.5",error:n["token_limits.native.notify_max"]}),e(k,{label:`Delay Max (${P})`,name:"native_delay_max",value:p.native?.delay_max??"",onChange:o("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((g,R)=>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:g.symbol}),e("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:1,marginLeft:"0.5rem",overflow:"hidden",textOverflow:"ellipsis"},children:g.assetId}),e("button",{class:"btn btn-ghost btn-sm",onClick:()=>h(g.assetId),title:"Remove",children:"x"})]}),e("div",{class:"policy-form-grid",children:[e(k,{label:"Instant Max",name:`token-${R}-instant`,value:g.instant_max,onChange:W=>v(g.assetId,"instant_max",String(W)),placeholder:"e.g. 100",error:n[`token_limits.${g.assetId}.instant_max`]}),e(k,{label:"Notify Max",name:`token-${R}-notify`,value:g.notify_max,onChange:W=>v(g.assetId,"notify_max",String(W)),placeholder:"e.g. 500",error:n[`token_limits.${g.assetId}.notify_max`]}),e(k,{label:"Delay Max",name:`token-${R}-delay`,value:g.delay_max,onChange:W=>v(g.assetId,"delay_max",String(W)),placeholder:"e.g. 1000",error:n[`token_limits.${g.assetId}.delay_max`]})]})]},g.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:g=>f(g),options:[{label:s.value?"Loading...":"-- Select a token --",value:""},...i.value.filter(g=>g.assetId&&!p[g.assetId]).map(g=>({label:`${g.symbol} (${g.name})`,value:g.assetId}))]})}),e("button",{class:"btn btn-secondary btn-sm",style:{marginTop:"0.5rem"},onClick:N,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:d("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:d("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:r("instant_max"),error:n.instant_max}),e(k,{label:"Notify Max (lamports/wei)",name:"notify_max",value:t.notify_max||"",onChange:r("notify_max"),error:n.notify_max}),e(k,{label:"Delay Max (lamports/wei)",name:"delay_max",value:t.delay_max||"",onChange:r("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:r("delay_seconds"),error:n.delay_seconds,required:!0,min:60})]})}function Me({items:t,onAdd:a,onRemove:n,renderRow:l,onChange:i,addLabel:s="+ Add",minItems:r=0,error:d}){return e("div",{class:"dynamic-row-list",children:[t.map((p,o)=>e("div",{class:"dynamic-row",children:[e("div",{class:"dynamic-row-fields",children:l(p,o,i)}),e("button",{class:"btn btn-ghost btn-sm dynamic-row-remove",onClick:()=>n(o),disabled:t.length<=r,title:"Remove",children:"x"})]},o)),e("button",{class:"btn btn-secondary btn-sm",onClick:a,children:s}),d&&e("span",{class:"form-error",children:d})]})}function ls({rules:t,onChange:a,errors:n}){const l=t.allowed_addresses||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,allowed_addresses:[...l,""]}),onRemove:i=>a({...t,allowed_addresses:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,a({...t,allowed_addresses:r})},renderRow:(i,s,r)=>e(k,{label:`Address ${s+1}`,name:`address-${s}`,value:i,onChange:d=>r(s,d),placeholder:"Wallet address",error:n[`allowed_addresses.${s}`],required:!0}),addLabel:"+ Add Address",error:n.allowed_addresses})})}function is({rules:t,onChange:a,errors:n}){const l=i=>s=>{a({...t,[i]:s})};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 ss({rules:t,onChange:a,errors:n}){const l=i=>{const s={...t};i===""||i===void 0?delete s.maxAmount:s.maxAmount=i,a(s)};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 rs=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function os({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:rs,error:n.tier})})}const cs=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function ds({rules:t,onChange:a,errors:n}){const l=t.tokens||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,tokens:[...l,{address:"",symbol:"",chain:""}]}),onRemove:i=>a({...t,tokens:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,a({...t,tokens:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Address ${s+1}`,name:`token-addr-${s}`,value:i.address,onChange:d=>r(s,{...i,address:d}),placeholder:"Token mint/contract address",error:n[`tokens.${s}.address`],required:!0}),e(k,{label:"Symbol",name:`token-symbol-${s}`,value:i.symbol,onChange:d=>r(s,{...i,symbol:d}),placeholder:"e.g. USDC"}),e(k,{label:"Chain",name:`token-chain-${s}`,type:"select",value:i.chain,onChange:d=>{const p={...i,chain:d};d||delete p.chain,r(s,p)},options:cs})]}),addLabel:"+ Add Token",error:n.tokens})})}const us=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function vs({rules:t,onChange:a,errors:n}){const l=t.contracts||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,contracts:[...l,{address:"",name:"",chain:""}]}),onRemove:i=>a({...t,contracts:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,a({...t,contracts:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Address ${s+1}`,name:`contract-addr-${s}`,value:i.address,onChange:d=>r(s,{...i,address:d}),placeholder:"Contract address",error:n[`contracts.${s}.address`],required:!0}),e(k,{label:"Name",name:`contract-name-${s}`,value:i.name,onChange:d=>r(s,{...i,name:d}),placeholder:"e.g. Uniswap Router"}),e(k,{label:"Chain",name:`contract-chain-${s}`,type:"select",value:i.chain,onChange:d=>{const p={...i,chain:d};d||delete p.chain,r(s,p)},options:us})]}),addLabel:"+ Add Contract",error:n.contracts})})}function hs({rules:t,onChange:a,errors:n}){const l=t.methods||[],i=s=>{a({...t,methods:s})};return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>i([...l,{contractAddress:"",selectors:[""]}]),onRemove:s=>i(l.filter((r,d)=>d!==s)),onChange:(s,r)=>{const d=[...l];d[s]=r,i(d)},renderRow:(s,r,d)=>e("div",{style:{flex:1},children:[e(k,{label:`Contract Address ${r+1}`,name:`method-addr-${r}`,value:s.contractAddress,onChange:p=>d(r,{...s,contractAddress:p}),placeholder:"Contract address",error:n[`methods.${r}.contractAddress`],required:!0}),e("div",{style:{marginTop:"0.5rem",marginLeft:"1rem"},children:[e("label",{style:{fontSize:"0.85rem",fontWeight:500},children:"Selectors"}),e(Me,{items:s.selectors,onAdd:()=>d(r,{...s,selectors:[...s.selectors,""]}),onRemove:p=>d(r,{...s,selectors:s.selectors.filter((o,v)=>v!==p)}),onChange:(p,o)=>{const v=[...s.selectors];v[p]=o,d(r,{...s,selectors:v})},renderRow:(p,o,v)=>e(k,{label:`Selector ${o+1}`,name:`method-sel-${r}-${o}`,value:p,onChange:h=>v(o,h),placeholder:"e.g. 0xa9059cbb or transfer(address,uint256)",error:n[`methods.${r}.selectors.${o}`],required:!0}),addLabel:"+ Add Selector",error:n[`methods.${r}.selectors`]})]})]}),addLabel:"+ Add Method Entry",error:n.methods})})}function ps({rules:t,onChange:a,errors:n}){const l=t.spenders||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,spenders:[...l,{address:"",name:"",maxAmount:""}]}),onRemove:i=>a({...t,spenders:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,s.maxAmount||delete r[i].maxAmount,a({...t,spenders:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Address ${s+1}`,name:`spender-addr-${s}`,value:i.address,onChange:d=>r(s,{...i,address:d}),placeholder:"Spender address",error:n[`spenders.${s}.address`],required:!0}),e(k,{label:"Name",name:`spender-name-${s}`,value:i.name,onChange:d=>r(s,{...i,name:d}),placeholder:"e.g. Uniswap"}),e(k,{label:"Max Amount",name:`spender-max-${s}`,value:i.maxAmount||"",onChange:d=>r(s,{...i,maxAmount:d}),placeholder:"Leave empty for unlimited",error:n[`spenders.${s}.maxAmount`]})]}),addLabel:"+ Add Spender",error:n.spenders})})}const ms=Array.from({length:24},(t,a)=>({label:`${String(a).padStart(2,"0")}:00`,value:String(a)})),fs=Array.from({length:24},(t,a)=>({label:`${String(a+1).padStart(2,"0")}:00`,value:String(a+1)})),gs=[{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 ys({rules:t,onChange:a,errors:n}){const l=t.allowed_hours||{start:0,end:24},i=t.allowed_days||[],s=d=>p=>{const o={...l,[d]:Number(p)};a({...t,allowed_hours:o})},r=d=>{const p=i.includes(d)?i.filter(o=>o!==d):[...i,d].sort((o,v)=>o-v);a({...t,allowed_days:p})};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:s("start"),options:ms,error:n.allowed_hours}),e(k,{label:"End Hour",name:"allowed_hours_end",type:"select",value:String(l.end),onChange:s("end"),options:fs})]}),e("h4",{children:"Allowed Days"}),e("div",{style:{display:"flex",gap:"0.75rem",flexWrap:"wrap"},children:gs.map(d=>e("label",{style:{display:"flex",alignItems:"center",gap:"0.25rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:i.includes(d.value),onChange:()=>r(d.value)}),d.label]},d.value))}),n.allowed_days&&e("span",{class:"form-error",children:n.allowed_days})]})}const _s=[{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 bs({rules:t,onChange:a,errors:n}){const l=t.networks||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,networks:[...l,{network:"solana-mainnet",name:""}]}),onRemove:i=>a({...t,networks:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,a({...t,networks:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(k,{label:`Network ${s+1}`,name:`network-sel-${s}`,type:"select",value:i.network,onChange:d=>r(s,{...i,network:d}),options:_s,error:n[`networks.${s}.network`],required:!0}),e(k,{label:"Label",name:`network-name-${s}`,value:i.name,onChange:d=>r(s,{...i,name:d}),placeholder:"Optional label"})]}),addLabel:"+ Add Network",error:n.networks})})}function ws({rules:t,onChange:a,errors:n}){const l=t.domains||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,domains:[...l,""]}),onRemove:i=>a({...t,domains:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,a({...t,domains:r})},renderRow:(i,s,r)=>e(k,{label:`Domain ${s+1}`,name:`domain-${s}`,value:i,onChange:d=>r(s,d),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${s}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}function Ts({rules:t,onChange:a,errors:n}){const l=t.domains||[];return e("div",{class:"policy-form-fields",children:e(Me,{items:l,onAdd:()=>a({...t,domains:[...l,""]}),onRemove:i=>a({...t,domains:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,a({...t,domains:r})},renderRow:(i,s,r)=>e(k,{label:`Domain ${s+1}`,name:`domain-${s}`,value:i,onChange:d=>r(s,d),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${s}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}const ln=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function Ss({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:ln,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:ln,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 sn({type:t,rules:a,onChange:n,errors:l,network:i}){switch(t){case"SPENDING_LIMIT":return e(ns,{rules:a,onChange:n,errors:l,network:i});case"WHITELIST":return e(ls,{rules:a,onChange:n,errors:l});case"RATE_LIMIT":return e(is,{rules:a,onChange:n,errors:l});case"APPROVE_AMOUNT_LIMIT":return e(ss,{rules:a,onChange:n,errors:l});case"APPROVE_TIER_OVERRIDE":return e(os,{rules:a,onChange:n,errors:l});case"ALLOWED_TOKENS":return e(ds,{rules:a,onChange:n,errors:l});case"CONTRACT_WHITELIST":return e(vs,{rules:a,onChange:n,errors:l});case"METHOD_WHITELIST":return e(hs,{rules:a,onChange:n,errors:l});case"APPROVED_SPENDERS":return e(ps,{rules:a,onChange:n,errors:l});case"TIME_RESTRICTION":return e(ys,{rules:a,onChange:n,errors:l});case"ALLOWED_NETWORKS":return e(bs,{rules:a,onChange:n,errors:l});case"X402_ALLOWED_DOMAINS":return e(ws,{rules:a,onChange:n,errors:l});case"ERC8128_ALLOWED_DOMAINS":return e(Ts,{rules:a,onChange:n,errors:l});case"REPUTATION_THRESHOLD":return e(Ss,{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 yt(t){const a=typeof t=="string"?Number(t):t;return Number.isNaN(a)?String(t):a.toLocaleString("en-US")}function ks(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 it=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Ns(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?`${it[a[0]]}-${it[a[a.length-1]]}`:a.map(l=>it[l]??String(l)).join(", ")}function rn(t){return String(t).padStart(2,"0")}function As({rules:t}){const a=Number(t.instant_max??0),n=Number(t.notify_max??0),l=Number(t.delay_max??0),i=Math.max(a,n,l,1),s=[{label:"Instant",value:t.instant_max,width:a/i*100,cls:"instant"},{label:"Notify",value:t.notify_max,width:n/i*100,cls:"notify"},{label:"Delay",value:t.delay_max,width:l/i*100,cls:"delay"},{label:"Approval",value:"",width:100,cls:"approval"}];return e("div",{class:"tier-bars",children:s.map(r=>e("div",{class:"tier-bar",children:[e("span",{class:"tier-bar-label",children:r.label}),e("div",{class:"tier-bar-track",children:e("div",{class:`tier-bar-fill tier-bar-fill--${r.cls}`,style:{width:`${r.width}%`}})}),e("span",{class:"tier-bar-value",children:r.value?yt(r.value):""})]},r.cls))})}function on(t){return t.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:2})}function Es({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:["$",on(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:["$",on(n)]})]})]})}const Cs={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(Es,{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(V,{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 / ",ks(l)]})}case"WHITELIST":{const n=a.allowed_addresses||[];return e(V,{variant:"neutral",children:[n.length," addresses"]})}case"TIME_RESTRICTION":{const n=a.allowed_days||[],l=a.allowed_hours,i=Ns(n),s=l?`${rn(l.start)}:00-${rn(l.end)}:00`:"";return e("span",{class:"rules-vis-text",children:[i," ",s]})}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((s,r)=>e(V,{variant:"neutral",children:s.name||(s.address?s.address.slice(0,8)+"...":"?")},r)),i>0&&e(V,{variant:"neutral",children:["+",i," more"]})]})}case"METHOD_WHITELIST":{const n=a.methods||[],l=n.length,i=n.reduce((s,r)=>s+(r.selectors?.length||0),0);return e(V,{variant:"neutral",children:[l," contracts, ",i," methods"]})}case"APPROVED_SPENDERS":{const n=a.spenders||[];return e(V,{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: ",yt(n)," + Block unlimited"]}):n?e("span",{class:"rules-vis-text",children:["Max: ",yt(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=Cs[n]||"neutral";return e(V,{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((s,r)=>e(V,{variant:"info",children:s.network},r)),i>0&&e(V,{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((s,r)=>e(V,{variant:"neutral",children:s},r)),i>0&&e(V,{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 jn=[{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"}],st={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)."},ma={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 Oa(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),s=a.token_limits,r=s&&Object.keys(s).length>0;if(!l&&!i&&!r&&(n.__form="At least one of USD limits, token limits, or raw limits required"),s){const v=/^\d+(\.\d+)?$/;for(const[h,f]of Object.entries(s)){const N=f;if(!N||typeof N!="object")continue;N.instant_max&&!v.test(N.instant_max)&&(n[`token_limits.${h}.instant_max`]="Must be a non-negative decimal"),N.notify_max&&!v.test(N.notify_max)&&(n[`token_limits.${h}.notify_max`]="Must be a non-negative decimal"),N.delay_max&&!v.test(N.delay_max)&&(n[`token_limits.${h}.delay_max`]="Must be a non-negative decimal");const $=parseFloat(N.instant_max||"0"),P=parseFloat(N.notify_max||"0"),g=parseFloat(N.delay_max||"0");$>P&&(n[`token_limits.${h}.instant_max`]="Must be <= Notify Max"),P>g&&(n[`token_limits.${h}.notify_max`]="Must be <= Delay Max")}}const d=Number(a.delay_seconds);(a.delay_seconds===void 0||a.delay_seconds===""||Number.isNaN(d)||d<60)&&(n.delay_seconds="Minimum 60 seconds");const p=a.daily_limit_usd;if(p!==void 0&&p!==""){const v=Number(p);(Number.isNaN(v)||v<=0)&&(n.daily_limit_usd="Must be a positive number")}const o=a.monthly_limit_usd;if(o!==void 0&&o!==""){const v=Number(o);(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,s)=>{(!i||i.trim()==="")&&(n[`allowed_addresses.${s}`]="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,s)=>{(!i.address||i.address.trim()==="")&&(n[`tokens.${s}.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,s)=>{(!i.address||i.address.trim()==="")&&(n[`contracts.${s}.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,s)=>{(!i.contractAddress||i.contractAddress.trim()==="")&&(n[`methods.${s}.contractAddress`]="Contract address required"),!i.selectors||i.selectors.length===0?n[`methods.${s}.selectors`]="At least one selector required":i.selectors.forEach((r,d)=>{(!r||r.trim()==="")&&(n[`methods.${s}.selectors.${d}`]="Selector required")})})}else if(t==="APPROVED_SPENDERS"){const l=a.spenders||[];l.length===0&&(n.spenders="At least one spender required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`spenders.${s}.address`]="Address required"),i.maxAmount&&!/^\d+$/.test(i.maxAmount)&&(n[`spenders.${s}.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,s)=>{(!i.network||i.network.trim()==="")&&(n[`networks.${s}.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,s)=>{(!i||i.trim()==="")&&(n[`domains.${s}`]="Domain required")})}return n}function Ds(t,a){if(!t)return"Global";const n=a.find(l=>l.id===t);return n?n.name:t.slice(0,8)+"..."}function rt(t){const a=jn.find(n=>n.value===t);return a?a.label:t}const cn=[{key:"policies",label:"Policies"},{key:"defaults",label:"Defaults"}],ot=["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 xs(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const o=await q(x.ADMIN_SETTINGS);t.value=o}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{l.value=!1}};Y(()=>{i()},[]);const s=(o,v)=>{const h=String(v);a.value={...a.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(a.value).filter(([h])=>ot.includes(h)).map(([h,f])=>({key:h,value:f})),v=await ue(x.ADMIN_SETTINGS,{settings:o});t.value=v.settings,a.value={},_("success","Policy defaults saved and applied")}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{n.value=!1}},d=()=>{a.value={}};Y(()=>(Ue({id:"policies-defaults",isDirty:()=>Object.keys(a.value).filter(o=>ot.includes(o)).length>0,save:r,discard:d}),()=>Ie("policies-defaults")),[]);const p=Object.keys(a.value).filter(o=>ot.includes(o)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(J,{children:[p>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[p," unsaved change",p>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:d,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:r,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:te("policy_defaults_delay_seconds"),name:"security.policy_defaults_delay_seconds",type:"number",value:Number(he(t.value,a.value,"security","policy_defaults_delay_seconds"))||0,onChange:o=>s("security.policy_defaults_delay_seconds",o),min:0,description:"Default delay before executing delayed-tier transactions"}),e(k,{label:te("policy_defaults_approval_timeout"),name:"security.policy_defaults_approval_timeout",type:"number",value:Number(he(t.value,a.value,"security","policy_defaults_approval_timeout"))||0,onChange:o=>s("security.policy_defaults_approval_timeout",o),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:te("default_deny_tokens"),name:"policy.default_deny_tokens",type:"checkbox",value:Re(t.value,a.value,"policy","default_deny_tokens"),onChange:o=>s("policy.default_deny_tokens",o),description:"Deny token transfers unless a matching whitelist policy exists"}),e(k,{label:te("default_deny_contracts"),name:"policy.default_deny_contracts",type:"checkbox",value:Re(t.value,a.value,"policy","default_deny_contracts"),onChange:o=>s("policy.default_deny_contracts",o),description:"Deny contract calls unless a matching whitelist policy exists"}),e(k,{label:te("default_deny_spenders"),name:"policy.default_deny_spenders",type:"checkbox",value:Re(t.value,a.value,"policy","default_deny_spenders"),onChange:o=>s("policy.default_deny_spenders",o),description:"Deny token approvals unless a matching whitelist policy exists"}),e(k,{label:te("default_deny_x402_domains"),name:"policy.default_deny_x402_domains",type:"checkbox",value:Re(t.value,a.value,"policy","default_deny_x402_domains"),onChange:o=>s("policy.default_deny_x402_domains",o),description:"Deny x402 payments unless a matching domain whitelist policy exists"}),e(k,{label:te("default_deny_erc8128_domains"),name:"policy.default_deny_erc8128_domains",type:"checkbox",value:Re(t.value,a.value,"policy","default_deny_erc8128_domains"),onChange:o=>s("policy.default_deny_erc8128_domains",o),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 Ls(){const t=c("policies");Y(()=>{const L=pe.value;L&&L.tab&&(t.value=L.tab,setTimeout(()=>{Ae.value=L.fieldName},100),pe.value=null)},[pe.value]);const a=c([]),n=c([]),l=c("__all__"),i=c(!1),s=c(!0),r=c(!1),d=c("SPENDING_LIMIT"),p=c(""),o=c(JSON.stringify(ma.SPENDING_LIMIT,null,2)),v=c(ma.SPENDING_LIMIT),h=c({}),f=c(!1),N=c(0),$=c(!0),P=c(""),g=c(null),R=c(!1),W=c(!1),z=c(null),D=c(""),B=c({}),A=c(!1),E=c({}),b=c(0),C=c(!0),w=c(null),u=c(!1),m=c(!1),O=c(null),H=c(!1),ne=async()=>{try{const L=await q(x.WALLETS);a.value=L.items}catch(L){const Z=L instanceof T?L:new T(0,"UNKNOWN","Unknown error");_("error",K(Z.code))}finally{s.value=!1}},G=async()=>{i.value=!0;try{let L=x.POLICIES;l.value!=="__all__"&&l.value!=="__global__"&&(L=`${x.POLICIES}?walletId=${l.value}`);const Z=await q(L);l.value==="__global__"?n.value=Z.filter(re=>re.walletId===null):n.value=Z}catch(L){const Z=L instanceof T?L:new T(0,"UNKNOWN","Unknown error");_("error",K(Z.code))}finally{i.value=!1}},de=async()=>{g.value=null;let L;if(f.value)try{L=JSON.parse(o.value)}catch{g.value="Invalid JSON in rules field";return}else{const Z=Oa(d.value,v.value);if(Object.keys(Z).length>0){h.value=Z;return}h.value={},L=v.value}R.value=!0;try{await ve(x.POLICIES,{walletId:p.value||void 0,type:d.value,rules:L,priority:N.value,enabled:$.value,network:P.value||void 0}),_("success","Policy created"),r.value=!1,d.value="SPENDING_LIMIT",p.value="",P.value="",o.value=JSON.stringify(ma.SPENDING_LIMIT,null,2),v.value=ma.SPENDING_LIMIT,h.value={},f.value=!1,N.value=0,$.value=!0,g.value=null,await G()}catch(Z){const re=Z instanceof T?Z:new T(0,"UNKNOWN","Unknown error");_("error",K(re.code))}finally{R.value=!1}},se=L=>{z.value=L,D.value=JSON.stringify(L.rules,null,2),B.value={...L.rules},A.value=!1,E.value={},b.value=L.priority,C.value=L.enabled,w.value=null,W.value=!0},ae=async()=>{w.value=null;let L;if(A.value)try{L=JSON.parse(D.value)}catch{w.value="Invalid JSON in rules field";return}else{const Z=Oa(z.value.type,B.value);if(Object.keys(Z).length>0){E.value=Z;return}E.value={},L=B.value}u.value=!0;try{await ue(x.POLICY(z.value.id),{rules:L,priority:b.value,enabled:C.value}),_("success","Policy updated"),W.value=!1,await G()}catch(Z){const re=Z instanceof T?Z:new T(0,"UNKNOWN","Unknown error");_("error",K(re.code))}finally{u.value=!1}},be=()=>{if(!A.value)D.value=JSON.stringify(B.value,null,2);else try{B.value=JSON.parse(D.value),w.value=null}catch{w.value="Invalid JSON — cannot switch to form mode";return}A.value=!A.value},De=L=>{O.value=L,m.value=!0},Ce=async()=>{H.value=!0;try{await je(x.POLICY(O.value.id)),_("success","Policy deleted"),m.value=!1,await G()}catch(L){const Z=L instanceof T?L:new T(0,"UNKNOWN","Unknown error");_("error",K(Z.code))}finally{H.value=!1}},Ee=L=>{const Z=L;d.value=Z;const re=ma[Z];re&&(o.value=JSON.stringify(re,null,2),v.value={...re}),h.value={},f.value=!1},I=()=>{if(!f.value)o.value=JSON.stringify(v.value,null,2);else try{v.value=JSON.parse(o.value),g.value=null}catch{g.value="Invalid JSON — cannot switch to form mode";return}f.value=!f.value};Y(()=>{ne()},[]),Y(()=>{G()},[l.value]);const X=[{key:"type",header:"Type",render:L=>e(V,{variant:L.type==="SPENDING_LIMIT"?"success":"info",children:rt(L.type)})},{key:"walletId",header:"Wallet",render:L=>Ds(L.walletId,a.value)},{key:"network",header:"Network",render:L=>L.network??"All"},{key:"rules",header:"Rules",render:L=>e(Is,{type:L.type,rules:L.rules})},{key:"priority",header:"Priority"},{key:"enabled",header:"Enabled",render:L=>e(V,{variant:L.enabled?"success":"danger",children:L.enabled?"ON":"OFF"})},{key:"actions",header:"Actions",render:L=>e("span",{style:{display:"flex",gap:"0.25rem"},children:[e("button",{class:"btn btn-ghost btn-sm",onClick:Z=>{Z.stopPropagation(),se(L)},children:"Edit"}),e(M,{size:"sm",variant:"danger",onClick:()=>De(L),children:"Delete"})]})}];return e("div",{class:"page",children:[e(ua,{pageName:"Policies",tabName:cn.find(L=>L.key===t.value)?.label??"",onPageClick:()=>{t.value="policies"}}),e(Ye,{tabs:cn,activeTab:t.value,onTabChange:L=>{t.value=L}}),t.value==="policies"&&e(J,{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:L=>{l.value=L.target.value},disabled:s.value,children:[e("option",{value:"__all__",children:"All Policies"}),e("option",{value:"__global__",children:"Global Only"}),a.value.map(L=>e("option",{value:L.id,children:[L.name," (",L.chain,"/",L.network,")"]},L.id))]})]}),!r.value&&e(M,{onClick:()=>{r.value=!0},children:"Create Policy"})]}),r.value&&e("div",{class:"inline-form",children:[e(k,{label:"Type",name:"type",type:"select",value:d.value,onChange:Ee,options:jn,description:st[d.value]??""}),e(k,{label:"Wallet",name:"walletId",type:"select",value:p.value,onChange:L=>{p.value=L},options:[{label:"Global (no wallet)",value:""},...a.value.map(L=>({label:`${L.name} (${L.chain}/${L.network})`,value:L.id}))]}),e(k,{label:"Network Scope",name:"network",value:P.value,onChange:L=>{P.value=L},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:I,children:f.value?"Switch to Form":"JSON Direct Edit"})]}),f.value?e(k,{label:"",name:"rules",type:"textarea",value:o.value,onChange:L=>{o.value=L},error:g.value??void 0}):e(sn,{type:d.value,rules:v.value,onChange:L=>{v.value=L,Object.keys(h.value).length>0&&(h.value=Oa(d.value,L))},errors:h.value,network:P.value})]}),e(k,{label:"Priority",name:"priority",type:"number",value:N.value,onChange:L=>{N.value=L},min:0,max:999}),e(k,{label:"Enabled",name:"enabled",type:"checkbox",value:$.value,onChange:L=>{$.value=L}}),e("div",{class:"inline-form-actions",children:[e(M,{onClick:de,loading:R.value,children:"Create"}),e(M,{variant:"secondary",onClick:()=>{r.value=!1,g.value=null},children:"Cancel"})]})]}),e(Pe,{columns:X,data:n.value,loading:i.value,emptyMessage:"No policies found"}),e(Se,{open:W.value,title:"Edit Policy",onCancel:()=>{W.value=!1},onConfirm:ae,confirmText:"Save",loading:u.value,children:z.value&&e("div",{children:[e("div",{class:"policy-type-readonly",children:["Type: ",rt(z.value.type),st[z.value.type]&&e("span",{class:"form-description",children:st[z.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:be,children:A.value?"Switch to Form":"JSON Direct Edit"})]}),A.value?e("div",{class:"edit-rules-textarea",children:e(k,{label:"",name:"edit-rules",type:"textarea",value:D.value,onChange:L=>{D.value=L},error:w.value??void 0})}):e(sn,{type:z.value.type,rules:B.value,onChange:L=>{B.value=L,Object.keys(E.value).length>0&&(E.value=Oa(z.value.type,L))},errors:E.value,network:z.value.network??""})]}),e(k,{label:"Priority",name:"edit-priority",type:"number",value:b.value,onChange:L=>{b.value=L},min:0,max:999}),e(k,{label:"Enabled",name:"edit-enabled",type:"checkbox",value:C.value,onChange:L=>{C.value=L}})]})}),e(Se,{open:m.value,title:"Delete Policy",onCancel:()=>{m.value=!1},onConfirm:Ce,confirmText:"Delete",confirmVariant:"danger",loading:H.value,children:O.value&&e("p",{children:["Are you sure you want to delete this"," ",e("strong",{children:rt(O.value.type)})," policy? This action cannot be undone."]})})]}),t.value==="defaults"&&e(xs,{})]})}function Rs(){return e(Os,{})}function Os(){const t=c([]),a=c(!0),n=c(!1),l=c(null),i=c("ADMIN"),s=c(!1),r=c(!1),d=c(null),p=c(!1),o=async()=>{a.value=!0;try{const g=await q(x.ADMIN_TELEGRAM_USERS);t.value=g.users}catch(g){const R=g instanceof T?g:new T(0,"UNKNOWN","Unknown error");_("error",K(R.code))}finally{a.value=!1}};Y(()=>{o()},[]);const v=g=>{l.value=g,i.value="ADMIN",n.value=!0},h=async()=>{if(l.value){s.value=!0;try{await ue(x.ADMIN_TELEGRAM_USER(l.value.chat_id),{role:i.value}),_("success",`User approved as ${i.value}`),n.value=!1,l.value=null,await o()}catch(g){const R=g instanceof T?g:new T(0,"UNKNOWN","Unknown error");_("error",K(R.code))}finally{s.value=!1}}},f=g=>{d.value=g,r.value=!0},N=async()=>{if(d.value){p.value=!0;try{await je(x.ADMIN_TELEGRAM_USER(d.value.chat_id)),_("success","User deleted"),r.value=!1,d.value=null,await o()}catch(g){const R=g instanceof T?g:new T(0,"UNKNOWN","Unknown error");_("error",K(R.code))}finally{p.value=!1}}},$=g=>g==="PENDING"?"warning":g==="ADMIN"?"success":"info";return e("div",{class:"page",children:[e(Pe,{columns:[{key:"chat_id",header:"Chat ID",render:g=>String(g.chat_id)},{key:"username",header:"Username",render:g=>g.username??"-"},{key:"role",header:"Role",render:g=>e(V,{variant:$(g.role),children:g.role})},{key:"registered_at",header:"Registered",render:g=>_e(g.registered_at)},{key:"approved_at",header:"Approved",render:g=>g.approved_at?_e(g.approved_at):"-"},{key:"actions",header:"Actions",render:g=>e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[g.role==="PENDING"&&e(M,{size:"sm",variant:"primary",onClick:()=>v(g),children:"Approve"}),e(M,{size:"sm",variant:"danger",onClick:()=>f(g),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:s.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:g=>{i.value=g.target.value},children:[e("option",{value:"ADMIN",children:"ADMIN"}),e("option",{value:"READONLY",children:"READONLY"})]})]})]})}),e(Se,{open:r.value,title:"Delete Telegram User",onCancel:()=>{r.value=!1,d.value=null},onConfirm:N,confirmText:"Delete",confirmVariant:"danger",loading:p.value,children:e("p",{children:"Are you sure you want to remove this user? They will need to /start again to re-register."})})]})}const ct=20,dn=[{key:"channels",label:"Channels & Logs"},{key:"telegram",label:"Telegram Users"},{key:"settings",label:"Settings"},{key:"balance",label:"Balance Monitor"}],Ps=[{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 Ms(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=c([]),s=c(!1),r=async()=>{try{const f=await q(x.ADMIN_SETTINGS);t.value=f}catch(f){const N=f instanceof T?f:new T(0,"UNKNOWN","Unknown error");_("error",K(N.code))}finally{l.value=!1}};Y(()=>{r()},[]);const d=(f,N)=>{const $=String(N);a.value={...a.value,[f]:$}},p=async()=>{n.value=!0;try{const f=Object.entries(a.value).filter(([$])=>$.startsWith("notifications.")||$.startsWith("telegram.")).map(([$,P])=>({key:$,value:P})),N=await ue(x.ADMIN_SETTINGS,{settings:f});t.value=N.settings,a.value={},_("success","Notification settings saved and applied")}catch(f){const N=f instanceof T?f:new T(0,"UNKNOWN","Unknown error");_("error",K(N.code))}finally{n.value=!1}},o=()=>{a.value={}};Y(()=>(Ue({id:"notifications-settings",isDirty:()=>Object.keys(a.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length>0,save:p,discard:o}),()=>Ie("notifications-settings")),[]);const v=async()=>{s.value=!0,i.value=[];try{const f=await ve(x.ADMIN_NOTIFICATIONS_TEST,{});if(i.value=f.results,f.results.length===0)_("info","No notification channels configured");else{const N=f.results.every($=>$.success);_(N?"success":"warning",N?"All test notifications sent":"Some channels failed")}}catch(f){const N=f instanceof T?f:new T(0,"UNKNOWN","Unknown error");_("error",K(N.code))}finally{s.value=!1}},h=Object.keys(a.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(J,{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(M,{variant:"ghost",size:"sm",onClick:o,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:p,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:Re(t.value,a.value,"notifications","enabled"),onChange:f=>d("notifications.enabled",f),description:"Enable or disable notifications globally"})}),e(k,{label:te("locale"),name:"notifications.locale",type:"select",value:he(t.value,a.value,"notifications","locale")||"en",onChange:f=>d("notifications.locale",f),options:[{label:"English",value:"en"},{label:"Korean",value:"ko"}],description:"Language for notification messages"})]}),e(Ve,{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:te("telegram_bot_token"),name:"notifications.telegram_bot_token",type:"password",value:he(t.value,a.value,"notifications","telegram_bot_token"),onChange:f=>d("notifications.telegram_bot_token",f),placeholder:ga(t.value,a.value,"notifications","telegram_bot_token")?"(configured)":"",description:"Bot token for Telegram notifications"}),e(k,{label:te("telegram_chat_id"),name:"notifications.telegram_chat_id",type:"text",value:he(t.value,a.value,"notifications","telegram_chat_id"),onChange:f=>d("notifications.telegram_chat_id",f),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:te("bot_token"),name:"telegram.bot_token",type:"password",value:he(t.value,a.value,"telegram","bot_token"),onChange:f=>d("telegram.bot_token",f),placeholder:ga(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:he(t.value,a.value,"telegram","locale")||"en",onChange:f=>d("telegram.locale",f),options:[{label:"English",value:"en"},{label:"한국어",value:"ko"}],description:"Language for Telegram bot messages"})]})]})]}),e(Ve,{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:te("ntfy_server"),name:"notifications.ntfy_server",type:"text",value:he(t.value,a.value,"notifications","ntfy_server"),onChange:f=>d("notifications.ntfy_server",f),description:"Server URL for ntfy push notifications"})})]}),e(Ve,{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:te("discord_webhook_url"),name:"notifications.discord_webhook_url",type:"password",value:he(t.value,a.value,"notifications","discord_webhook_url"),onChange:f=>d("notifications.discord_webhook_url",f),placeholder:ga(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:he(t.value,a.value,"notifications","slack_webhook_url"),onChange:f=>d("notifications.slack_webhook_url",f),placeholder:ga(t.value,a.value,"notifications","slack_webhook_url")?"(configured)":"",description:"Webhook URL for Slack notifications"}),e(k,{label:te("rate_limit_rpm"),name:"notifications.rate_limit_rpm",type:"number",value:Number(he(t.value,a.value,"notifications","rate_limit_rpm"))||20,onChange:f=>d("notifications.rate_limit_rpm",f),min:1,max:1e3,description:"Max notifications per minute"})]})]}),e(Ve,{legend:"Event Filter",description:"Choose which notification events are delivered. All checked = receive all.",children:[(()=>{const f=new Set(["KILL_SWITCH_ACTIVATED","KILL_SWITCH_RECOVERED","AUTO_STOP_TRIGGERED","TX_INCOMING_SUSPICIOUS"]),N=[{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"}]}],$=N.flatMap(D=>D.events.map(B=>B.event)).filter(D=>!f.has(D)),P=he(t.value,a.value,"notifications","notify_events")||"[]";let g=[];try{const D=JSON.parse(P);Array.isArray(D)&&(g=D)}catch{}const R=g.length===0?$:g,W=(D,B)=>{const A=B?[...R,D]:R.filter(b=>b!==D),E=A.length===$.length&&$.every(b=>A.includes(b))?[]:A;d("notifications.notify_events",JSON.stringify(E))},z=(D,B)=>{const A=D.events.filter(C=>!f.has(C.event)).map(C=>C.event);let E;if(B)E=[...new Set([...R,...A])];else{const C=new Set(A);E=R.filter(w=>!C.has(w))}const b=E.length===$.length&&$.every(C=>E.includes(C))?[]:E;d("notifications.notify_events",JSON.stringify(b))};return e("div",{class:"event-filter-groups",children:N.map(D=>{const B=D.events.filter(b=>!f.has(b.event)),A=B.every(b=>R.includes(b.event)),E=B.some(b=>R.includes(b.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:D.label}),e("label",{class:"event-filter-group-all",onClick:b=>b.stopPropagation(),children:[e("input",{type:"checkbox",checked:A,ref:b=>{b&&(b.indeterminate=E&&!A)},onChange:b=>z(D,b.target.checked)})," All"]})]}),e("div",{class:"event-filter-events",children:D.events.map(b=>{const C=f.has(b.event);return e("label",{class:`event-filter-event ${C?"event-broadcast":""}`,children:[e("input",{type:"checkbox",checked:C||R.includes(b.event),disabled:C,onChange:w=>W(b.event,w.target.checked)}),e("code",{children:b.event}),e("span",{class:"event-desc",children:b.desc}),C&&e("span",{class:"event-broadcast-badge",children:"Always sent"})]},b.event)})})]},D.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(M,{variant:"secondary",size:"sm",onClick:v,loading:s.value,children:"Test Notification"}),i.value.length>0&&e("div",{class:"test-results",children:i.value.map(f=>e("div",{class:`test-result-item ${f.success?"test-result-success":"test-result-failure"}`,children:[e(V,{variant:f.success?"success":"danger",children:f.success?"OK":"FAIL"}),e("span",{children:f.channel}),f.error&&e("span",{style:"font-size: var(--font-size-xs); color: var(--color-danger);",children:[" - ",f.error]})]},f.channel))})]})]})]})]})}const un={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 Us(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const v=await q(x.ADMIN_SETTINGS);t.value=v}catch(v){const h=v instanceof T?v:new T(0,"UNKNOWN","Unknown error");_("error",K(h.code))}finally{l.value=!1}};Y(()=>{i()},[]);const s=(v,h)=>{const f=String(h);a.value={...a.value,[v]:f}},r=async()=>{n.value=!0;try{const v=Object.entries(a.value).filter(([f])=>f.startsWith("monitoring.")).map(([f,N])=>({key:f,value:N})),h=await ue(x.ADMIN_SETTINGS,{settings:v});t.value=h.settings,a.value={},_("success","Settings saved and applied")}catch(v){const h=v instanceof T?v:new T(0,"UNKNOWN","Unknown error");_("error",K(h.code))}finally{n.value=!1}},d=()=>{a.value={}};Y(()=>(Ue({id:"notifications-balance",isDirty:()=>Object.keys(a.value).filter(v=>v.startsWith("monitoring.")).length>0,save:r,discard:d}),()=>Ie("notifications-balance")),[]);const p=[{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}],o=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(J,{children:[o>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[o," unsaved change",o>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:d,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:r,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:p.map(v=>v.type==="checkbox"?e("div",{class:"settings-field-full",children:e(k,{label:te(v.key),name:`monitoring.${v.key}`,type:"checkbox",value:Re(t.value,a.value,"monitoring",v.key),onChange:h=>s(`monitoring.${v.key}`,h),description:un[v.key]})},v.key):e(k,{label:te(v.key),name:`monitoring.${v.key}`,type:"number",value:Number(he(t.value,a.value,"monitoring",v.key))||0,onChange:h=>s(`monitoring.${v.key}`,h),min:v.min,max:v.max,description:un[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 vn(){const t=c("channels");Y(()=>{const E=pe.value;E&&E.tab&&(t.value=E.tab,setTimeout(()=>{Ae.value=E.fieldName},100),pe.value=null)},[pe.value]);const a=c(null),n=c(!0),l=c(!1),i=c(null),s=c(null),r=c(null),d=c(!0),p=c(1),o=c(null),v=c({eventType:"",channel:"",status:"",since:"",until:""}),h=async()=>{try{const E=await q(x.ADMIN_NOTIFICATIONS_STATUS);a.value=E}catch(E){const b=E instanceof T?E:new T(0,"UNKNOWN","Unknown error");_("error",K(b.code))}finally{n.value=!1}},f=async E=>{d.value=!0;try{const b=new URLSearchParams;b.set("page",String(E)),b.set("pageSize",String(ct));const C=v.value;if(C.eventType&&b.set("eventType",C.eventType),C.channel&&b.set("channel",C.channel),C.status&&b.set("status",C.status),C.since){const u=new Date(C.since);isNaN(u.getTime())||b.set("since",String(Math.floor(u.getTime()/1e3)))}if(C.until){const u=new Date(C.until);isNaN(u.getTime())||(u.setHours(23,59,59,999),b.set("until",String(Math.floor(u.getTime()/1e3))))}const w=await q(`${x.ADMIN_NOTIFICATIONS_LOG}?${b.toString()}`);r.value=w}catch(b){const C=b instanceof T?b:new T(0,"UNKNOWN","Unknown error");_("error",K(C.code))}finally{d.value=!1}},N=async()=>{l.value=!0,s.value=null;try{const b=(await ve(x.ADMIN_NOTIFICATIONS_TEST,{})).results;s.value=b,b.every(w=>w.success)?_("success","Test sent successfully"):_("warning","Some channels failed")}catch(E){const b=E instanceof T?E:new T(0,"UNKNOWN","Unknown error");_("error",K(b.code))}finally{l.value=!1}},$=async E=>{i.value=E,s.value=null;try{const C=(await ve(x.ADMIN_NOTIFICATIONS_TEST,{channel:E})).results;s.value=C,C.every(u=>u.success)?_("success",`Test sent to ${E}`):_("warning",`${E} test failed`)}catch(b){const C=b instanceof T?b:new T(0,"UNKNOWN","Unknown error");_("error",K(C.code))}finally{i.value=null}},P=()=>{p.value>1&&(p.value-=1,f(p.value))},g=()=>{const E=r.value?Math.ceil(r.value.total/ct):1;p.value<E&&(p.value+=1,f(p.value))},R=E=>{o.value=o.value?.id===E.id?null:E},W=E=>{v.value=E,p.value=1,f(1)};Y(()=>{h(),f(1);const E=setInterval(()=>f(p.value),3e4);return()=>clearInterval(E)},[]);const z=n.value&&!a.value,D=a.value?.channels.some(E=>E.enabled)??!1,B=r.value?Math.max(1,Math.ceil(r.value.total/ct)):1,A=[{key:"eventType",header:"Event Type"},{key:"walletId",header:"Wallet ID",render:E=>E.walletId?e("a",{href:`#/wallets/${E.walletId}`,class:"wallet-link",onClick:b=>b.stopPropagation(),title:E.walletId,children:[E.walletId.slice(0,8),"..."]}):"—"},{key:"channel",header:"Channel",render:E=>e("span",{style:{textTransform:"capitalize"},children:E.channel})},{key:"status",header:"Status",render:E=>e(V,{variant:E.status==="sent"?"success":"danger",children:E.status})},{key:"createdAt",header:"Time",render:E=>_e(E.createdAt)}];return e("div",{class:"page",children:[e(ua,{pageName:"Notifications",tabName:dn.find(E=>E.key===t.value)?.label??"",onPageClick:()=>{t.value="channels"}}),e(Ye,{tabs:dn,activeTab:t.value,onTabChange:E=>{t.value=E}}),t.value==="telegram"?e(Rs,{}):t.value==="settings"?e(Ms,{}):t.value==="balance"?e(Us,{}):e(J,{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:E=>{E.preventDefault(),t.value="settings"},children:"Enable them in the Settings tab"})]}),z?e("div",{class:"channel-grid",children:[1,2,3].map(E=>e("div",{class:"channel-card",children:e("div",{class:"stat-skeleton"})},E))}):e("div",{class:"channel-grid",children:a.value?.channels.map(E=>e("div",{class:"channel-card",children:e("div",{class:"channel-card-header",children:[e("span",{class:"channel-card-name",children:E.name}),e("div",{class:"channel-card-actions",children:[e(V,{variant:E.enabled?"success":"neutral",children:E.enabled?E.configuredWallets!=null?`${E.configuredWallets} wallet${E.configuredWallets!==1?"s":""} configured`:"Connected":"Not Configured"}),E.enabled&&e(M,{variant:"secondary",size:"sm",onClick:()=>$(E.name),loading:i.value===E.name,children:"Test"})]})]})},E.name))}),e("div",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-6)"},children:[e(M,{onClick:N,loading:l.value,disabled:!D,children:"Test All Channels"}),s.value&&e("div",{class:"test-results",children:s.value.map(E=>e("div",{class:"test-result-item",children:[e("span",{class:E.success?"test-result-success":"test-result-failure",children:E.success?"✓":"✗"}),e("span",{style:{textTransform:"capitalize"},children:E.channel}),!E.success&&E.error&&e("span",{class:"test-result-failure",children:[" - ",E.error]})]},E.channel))})]}),e("h2",{children:"Delivery Log"}),e(Qa,{fields:Ps,values:v.value,onChange:W,syncUrl:!1}),e(Pe,{columns:A,data:r.value?.logs??[],loading:d.value,emptyMessage:"No notification logs",onRowClick:R}),o.value&&e("div",{class:"log-message-detail",children:[e("div",{class:"log-message-detail-header",children:[e("strong",{children:o.value.eventType})," via ",e("span",{style:{textTransform:"capitalize"},children:o.value.channel}),e(M,{variant:"ghost",size:"sm",onClick:()=>{o.value=null},children:"Close"})]}),e("div",{class:"log-message-detail-body",children:o.value.message?e("pre",{style:{whiteSpace:"pre-wrap",margin:0,fontSize:"var(--font-size-sm)"},children:o.value.message}):e("span",{class:"text-muted",children:"(No message recorded)"})})]}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Page ",p.value," of ",B,r.value?` (${r.value.total} total)`:""]}),e("div",{class:"pagination-buttons",children:[e(M,{variant:"secondary",size:"sm",onClick:P,disabled:p.value<=1,children:"Previous"}),e(M,{variant:"secondary",size:"sm",onClick:g,disabled:p.value>=B,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 dt=[{key:"killswitch",label:"Kill Switch"},{key:"autostop",label:"AutoStop Rules"},{key:"jwt",label:"Invalidate Sessions"},{key:"password",label:"Master Password"}];function Ws(){const t=c(null),a=c(!0),n=c(!1),l=async()=>{try{const h=await q(x.ADMIN_KILL_SWITCH);t.value=h}catch(h){const f=h instanceof T?h:new T(0,"UNKNOWN","Unknown error");_("error",K(f.code))}finally{a.value=!1}};Y(()=>{l()},[]);const i=async()=>{n.value=!0;try{await ve(x.ADMIN_KILL_SWITCH),_("success","Kill switch activated - all operations suspended"),await l()}catch(h){const f=h instanceof T?h:new T(0,"UNKNOWN","Unknown error");_("error",K(f.code))}finally{n.value=!1}},s=async()=>{n.value=!0;try{await ve(x.ADMIN_KILL_SWITCH_ESCALATE),_("success","Kill switch escalated to LOCKED"),await l()}catch(h){const f=h instanceof T?h:new T(0,"UNKNOWN","Unknown error");_("error",K(f.code))}finally{n.value=!1}},r=async()=>{n.value=!0;try{await ve(x.ADMIN_RECOVER),_("success","Kill switch recovered - operations resumed"),await l()}catch(h){const f=h instanceof T?h:new T(0,"UNKNOWN","Unknown error");_("error",K(f.code))}finally{n.value=!1}},d=t.value,p=d?.state==="ACTIVE",o=d?.state==="SUSPENDED",v=d?.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..."}):d?e(J,{children:[e("div",{class:"ks-state-card",style:{marginBottom:"var(--space-4)"},children:[e(V,{variant:p?"success":v?"danger":"warning",children:d.state}),!p&&d.activatedAt&&e("span",{class:"ks-state-info",children:["Since ",_e(d.activatedAt),d.activatedBy?` by ${d.activatedBy}`:""]})]}),e("div",{style:{display:"flex",gap:"var(--space-2)",flexWrap:"wrap"},children:[p&&e(M,{variant:"danger",onClick:i,loading:n.value,children:"Activate Kill Switch"}),o&&e(J,{children:[e(M,{variant:"primary",onClick:r,loading:n.value,children:"Recover"}),e(M,{variant:"danger",onClick:s,loading:n.value,children:"Escalate to LOCKED"})]}),v&&e(M,{variant:"primary",onClick:r,loading:n.value,children:"Recover from LOCKED (5s wait)"})]}),o&&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 $s(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=async()=>{try{const o=await q(x.ADMIN_SETTINGS);t.value=o}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{l.value=!1}};Y(()=>{i()},[]);const s=(o,v)=>{const h=String(v);a.value={...a.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(a.value).filter(([h])=>h.startsWith("autostop.")).map(([h,f])=>({key:h,value:f})),v=await ue(x.ADMIN_SETTINGS,{settings:o});t.value=v.settings,a.value={},_("success","AutoStop settings saved and applied")}catch(o){const v=o instanceof T?o:new T(0,"UNKNOWN","Unknown error");_("error",K(v.code))}finally{n.value=!1}},d=()=>{a.value={}};Y(()=>(Ue({id:"security-autostop",isDirty:()=>Object.keys(a.value).filter(o=>o.startsWith("autostop.")).length>0,save:r,discard:d}),()=>Ie("security-autostop")),[]);const p=Object.keys(a.value).filter(o=>o.startsWith("autostop.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(J,{children:[p>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[p," unsaved change",p>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:d,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:r,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:te("enabled"),name:"autostop.enabled",type:"checkbox",value:Re(t.value,a.value,"autostop","enabled"),onChange:o=>s("autostop.enabled",o),description:"Enable or disable AutoStop protection rules"})}),e(Ve,{legend:"Activity Detection",description:"Detects failures and unusual transaction patterns",children:e("div",{class:"settings-fields-grid",children:[e(k,{label:te("consecutive_failures_threshold"),name:"autostop.consecutive_failures_threshold",type:"number",value:Number(he(t.value,a.value,"autostop","consecutive_failures_threshold"))||0,onChange:o=>s("autostop.consecutive_failures_threshold",o),min:1,max:100,description:"Suspend wallet after this many consecutive failed transactions"}),e(k,{label:te("unusual_activity_threshold"),name:"autostop.unusual_activity_threshold",type:"number",value:Number(he(t.value,a.value,"autostop","unusual_activity_threshold"))||0,onChange:o=>s("autostop.unusual_activity_threshold",o),min:5,max:1e3,description:"Max transactions within window before triggering unusual activity alert"}),e(k,{label:te("unusual_activity_window_sec"),name:"autostop.unusual_activity_window_sec",type:"number",value:Number(he(t.value,a.value,"autostop","unusual_activity_window_sec"))||0,onChange:o=>s("autostop.unusual_activity_window_sec",o),min:60,max:86400,description:"Time window for unusual activity detection"})]})}),e(Ve,{legend:"Idle Detection",description:"Monitors inactivity and revokes idle sessions",children:e("div",{class:"settings-fields-grid",children:[e(k,{label:te("idle_timeout_sec"),name:"autostop.idle_timeout_sec",type:"number",value:Number(he(t.value,a.value,"autostop","idle_timeout_sec"))||0,onChange:o=>s("autostop.idle_timeout_sec",o),min:60,max:604800,description:"Revoke sessions with no activity for this duration"}),e(k,{label:te("idle_check_interval_sec"),name:"autostop.idle_check_interval_sec",type:"number",value:Number(he(t.value,a.value,"autostop","idle_check_interval_sec"))||0,onChange:o=>s("autostop.idle_check_interval_sec",o),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 ve(x.ADMIN_ROTATE_SECRET),t.value=!1,_("success","All session tokens invalidated. Old tokens remain valid for 5 minutes.")}catch(l){const i=l instanceof T?l:new T(0,"UNKNOWN","Unknown error");_("error",K(i.code))}finally{a.value=!1}};return e(J,{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(M,{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 Ks(){const t=c(""),a=c(""),n=c(""),l=c(!1),i=c(null),s=()=>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),r=async()=>{if(s()){l.value=!0;try{await ue(x.ADMIN_MASTER_PASSWORD,{newPassword:a.value}),_("success","Master password changed. Please log in again."),t.value="",a.value="",n.value="",setTimeout(()=>Za(),500)}catch(d){const p=d instanceof T?d:new T(0,"UNKNOWN","Unknown error");_("error",K(p.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:d=>{t.value=String(d)}}),e(k,{label:"New Password",name:"new-password",type:"password",value:a.value,onChange:d=>{a.value=String(d)},description:"Minimum 8 characters"}),e(k,{label:"Confirm New Password",name:"confirm-password",type:"password",value:n.value,onChange:d=>{n.value=String(d)}}),e("div",{children:e(M,{variant:"primary",onClick:r,loading:l.value,disabled:!t.value||!a.value||!n.value,children:"Change Password"})})]})]})]})}function Hs(){const t=(()=>{const l=location.hash,i=l.indexOf("?");if(i>=0){const r=new URLSearchParams(l.slice(i+1)).get("tab");if(r&&dt.some(d=>d.key===r))return r}return"killswitch"})(),a=c(t);Y(()=>{const l=pe.value;l&&l.tab&&(a.value=l.tab,setTimeout(()=>{Ae.value=l.fieldName},100),pe.value=null)},[pe.value]);const n=dt.find(l=>l.key===a.value)?.label??"";return e("div",{class:"page",children:[e(ua,{pageName:"Security",tabName:n,onPageClick:()=>{a.value="killswitch"}}),e(Ye,{tabs:dt,activeTab:a.value,onTabChange:l=>{a.value=l}}),a.value==="killswitch"&&e(Ws,{}),a.value==="autostop"&&e($s,{}),a.value==="jwt"&&e(Fs,{}),a.value==="password"&&e(Ks,{})]})}const Pa=[{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 Bs({value:t,onChange:a,name:n}){const l=c(""),i=c(!1),s=c(null),r=c(!1),d=Aa(null),p=Ja(()=>{const v=l.value.toLowerCase();return v?Pa.filter(h=>h.code.toLowerCase().includes(v)||h.name.toLowerCase().includes(v)||h.symbol.includes(v)):Pa});Y(()=>{if(t==="USD"){s.value="1 USD = $1.00";return}r.value=!0,q(`${x.ADMIN_FOREX_RATES}?currencies=${t}`).then(v=>{const h=v.rates[t];s.value=h?.preview??null}).catch(()=>{s.value=null}).finally(()=>{r.value=!1})},[t]),Y(()=>{const v=h=>{d.current&&!d.current.contains(h.target)&&(i.value=!1,l.value="")};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const o=Pa.find(v=>v.code===t)??Pa[0];return e("div",{class:"currency-select",ref:d,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:[o.code," - ",o.name," (",o.symbol,")"]}),e("span",{class:"currency-select-chevron",children:i.value?"▲":"▼"})]}),s.value&&e("div",{class:"currency-rate-preview",children:r.value?"...":s.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:[p.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)),p.value.length===0&&e("div",{class:"currency-select-empty",children:"No currencies found"})]})]})]})}const zs=["display.","daemon.","oracle.","gas_condition.","smart_account.","erc8128."],Vs=new Set(["security.rate_limit_global_ip_rpm"]);function ut(t){return zs.some(a=>t.startsWith(a))||Vs.has(t)}function Gs(){const t=c({}),a=c({}),n=c(!1),l=c(!0),i=c([]),s=c(!0);c(null),c(""),c(!1);const r=c(!1),d=c(!1),p=c(""),o=c(!1),v=async()=>{try{const u=await q(x.ADMIN_SETTINGS);t.value=u}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{l.value=!1}},h=async()=>{try{const u=await q(x.ADMIN_API_KEYS);i.value=u.keys}catch{}finally{s.value=!1}};Y(()=>{v(),h()},[]),Y(()=>{const u=pe.value;u&&(setTimeout(()=>{Ae.value=u.fieldName},100),pe.value=null)},[pe.value]);const f=(u,m)=>he(t.value,a.value,u,m),N=(u,m)=>Re(t.value,a.value,u,m),$=(u,m)=>ga(t.value,a.value,u,m),P=(u,m)=>{const O=String(m);a.value={...a.value,[u]:O}},g=async()=>{n.value=!0;try{const u=Object.entries(a.value).filter(([O])=>ut(O)).map(([O,H])=>({key:O,value:H})),m=await ue(x.ADMIN_SETTINGS,{settings:u});t.value=m.settings,a.value={},_("success","Settings saved and applied")}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{n.value=!1}},R=()=>{a.value={}};Y(()=>(Ue({id:"system-settings",isDirty:()=>Object.keys(a.value).filter(u=>ut(u)).length>0,save:g,discard:R}),()=>Ie("system-settings")),[]);const W=async()=>{d.value=!0;try{await ve(x.ADMIN_SHUTDOWN),r.value=!1,p.value="",_("info","Shutdown initiated"),o.value=!0}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{d.value=!1}},z=Object.keys(a.value).filter(u=>ut(u)).length;function D(){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(f("oracle","cross_validation_threshold"))||5,onChange:u=>P("oracle.cross_validation_threshold",u),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:$("oracle","coingecko_api_key")?"••••••••":"",onChange:u=>P("oracle.coingecko_api_key",u),placeholder:"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 B(){const u=Ae.value==="display.currency";return Y(()=>{if(u){const m=document.querySelector('[name="display.currency"]');m&&m.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const O=setTimeout(()=>{Ae.value=""},2500);return()=>clearTimeout(O)}},[u]),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${u?" form-field--highlight":""}`,children:[e("label",{children:te("currency")}),e(Bs,{name:"display.currency",value:f("display","currency")||"USD",onChange:m=>P("display.currency",m)})]})}),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 A(){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:te("rate_limit_global_ip_rpm"),name:"security.rate_limit_global_ip_rpm",type:"number",value:Number(f("security","rate_limit_global_ip_rpm"))||0,onChange:u=>P("security.rate_limit_global_ip_rpm",u),min:10,description:"Maximum API requests per minute from a single IP address"})})})]})}function E(){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:te("log_level"),name:"daemon.log_level",type:"select",value:f("daemon","log_level")||"info",onChange:u=>P("daemon.log_level",u),options:[{label:"debug",value:"debug"},{label:"info",value:"info"},{label:"warn",value:"warn"},{label:"error",value:"error"}],description:"Daemon logging verbosity level"})})})]})}function b(){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:f("gas_condition","enabled")||"true",onChange:u=>P("gas_condition.enabled",u),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable gas conditional execution for agents"}),e(k,{label:te("poll_interval_sec"),name:"gas_condition.poll_interval_sec",type:"number",value:Number(f("gas_condition","poll_interval_sec"))||30,onChange:u=>P("gas_condition.poll_interval_sec",u),min:10,max:300,description:"How often to check gas prices (seconds)"}),e(k,{label:te("default_timeout_sec"),name:"gas_condition.default_timeout_sec",type:"number",value:Number(f("gas_condition","default_timeout_sec"))||3600,onChange:u=>P("gas_condition.default_timeout_sec",u),min:60,max:86400,description:"Default wait timeout when not specified in request (seconds)"}),e(k,{label:te("max_timeout_sec"),name:"gas_condition.max_timeout_sec",type:"number",value:Number(f("gas_condition","max_timeout_sec"))||86400,onChange:u=>P("gas_condition.max_timeout_sec",u),min:60,max:86400,description:"Maximum allowed timeout for gas conditions (seconds)"}),e(k,{label:te("max_pending_count"),name:"gas_condition.max_pending_count",type:"number",value:Number(f("gas_condition","max_pending_count"))||100,onChange:u=>P("gas_condition.max_pending_count",u),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 C(){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:f("smart_account","enabled")||"false",onChange:u=>P("smart_account.enabled",u),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:f("smart_account","entry_point"),onChange:u=>P("smart_account.entry_point",u),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 w(){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:f("erc8128","enabled")||"false",onChange:u=>P("erc8128.enabled",u),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:f("erc8128","default_preset")||"standard",onChange:u=>P("erc8128.default_preset",u),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:f("erc8128","default_ttl_sec")||"300",onChange:u=>P("erc8128.default_ttl_sec",u),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:N("erc8128","default_nonce"),onChange:u=>P("erc8128.default_nonce",u),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:f("erc8128","default_algorithm")||"ethereum-eip191",onChange:u=>P("erc8128.default_algorithm",u),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:f("erc8128","default_rate_limit_rpm")||"60",onChange:u=>P("erc8128.default_rate_limit_rpm",u),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:[o.value&&e("div",{class:"shutdown-overlay",children:[e("h2",{children:"Daemon is shutting down..."}),e("p",{children:"You can close this tab."})]}),z>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[z," unsaved change",z>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:R,children:"Discard"}),e(M,{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(J,{children:[e(D,{}),e(B,{}),e(A,{}),e(E,{}),e(b,{}),e(C,{}),e(w,{})]}),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(M,{variant:"danger",onClick:()=>{r.value=!0},children:"Shutdown Daemon"})})]}),e(Se,{open:r.value,title:"Shutdown Daemon",onCancel:()=>{r.value=!1,p.value=""},onConfirm:W,confirmText:"Shutdown",confirmVariant:"danger",confirmDisabled:p.value!=="SHUTDOWN",loading:d.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:p.value,onInput:u=>{p.value=u.target.value},placeholder:"SHUTDOWN"})]})]})]})}const hn=[{key:"jupiter_swap",name:"Jupiter Swap",description:"Solana DEX aggregator",chain:"solana",requiresApiKey:!1,docsUrl:"https://station.jup.ag/docs"},{key:"zerox_swap",name:"0x Swap",description:"EVM DEX aggregator (AllowanceHolder)",chain:"evm",requiresApiKey:!0,docsUrl:"https://dashboard.0x.org"},{key:"lifi",name:"LI.FI",description:"Multi-chain DEX/bridge aggregator",chain:"multi",requiresApiKey:!1,docsUrl:"https://docs.li.fi"},{key:"lido_staking",name:"Lido Staking",description:"ETH liquid staking (stETH/wstETH)",chain:"evm",requiresApiKey:!1,docsUrl:"https://docs.lido.fi"},{key:"jito_staking",name:"Jito Staking",description:"SOL liquid staking (JitoSOL)",chain:"solana",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",requiresApiKey:!1,docsUrl:"https://docs.aave.com/developers"},{key:"kamino",name:"Kamino Lending",description:"Solana lending protocol (supply, borrow, repay, withdraw)",chain:"solana",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",requiresApiKey:!1,docsUrl:"https://docs.pendle.finance"},{key:"drift_perp",name:"Drift Perp",description:"Solana perpetual futures trading (open, close, modify positions with leverage)",chain:"solana",requiresApiKey:!1,docsUrl:"https://docs.drift.trade"}];function pn(){const t=c([]),a=c({}),n=c([]),l=c(!0),i=c(null),s=c(""),r=c(!1),d=c(null),p=c({}),o=async()=>{try{const w=await q(x.ADMIN_SETTINGS);a.value=w}catch(w){const u=w instanceof T?w:new T(0,"UNKNOWN","Unknown error");_("error",K(u.code))}},v=async()=>{try{const w=await q(x.ADMIN_API_KEYS);n.value=w.keys}catch{}},h=async()=>{try{const w=await q(x.ACTIONS_PROVIDERS);t.value=w.providers??[]}catch{}},f=async()=>{l.value=!0,await Promise.all([o(),v(),h()]),l.value=!1};Y(()=>{f()},[]);const N=async(w,u)=>{const m=`actions.${w}_enabled`;d.value=w;try{const O=await ue(x.ADMIN_SETTINGS,{settings:[{key:m,value:String(u)}]});a.value=O.settings,_("success",`${u?"Enabled":"Disabled"} ${w.replace(/_/g," ")}`)}catch(O){const H=O instanceof T?O:new T(0,"UNKNOWN","Unknown error");_("error",K(H.code))}finally{d.value=null}},$=async w=>{r.value=!0;try{await ue(x.ADMIN_API_KEY(w),{apiKey:s.value}),_("success",`API key saved for ${w}`),i.value=null,s.value="",await v()}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}finally{r.value=!1}},P=async w=>{try{await je(x.ADMIN_API_KEY(w)),_("success",`API key deleted for ${w}`),await v()}catch(u){const m=u instanceof T?u:new T(0,"UNKNOWN","Unknown error");_("error",K(m.code))}},g=async(w,u)=>{const m=`actions.${w}`;try{const O=await ue(x.ADMIN_SETTINGS,{settings:[{key:m,value:u}]});a.value=O.settings;const H={...p.value};delete H[w],p.value=H,_("success","Setting updated")}catch(O){const H=O instanceof T?O:new T(0,"UNKNOWN","Unknown error");_("error",K(H.code))}};function R(w){const u=a.value.actions;return u?u[`${w}_enabled`]==="true":!1}function W(w){return t.value.some(u=>u.name.toLowerCase().replace(/[\s-]/g,"_")===w||u.name.toLowerCase().includes(w.replace(/_/g," ")))}function z(w){return n.value.find(u=>u.providerName===w||u.providerName.toLowerCase().replace(/[\s-]/g,"_")===w)}function D(w){return t.value.find(u=>u.name.toLowerCase().replace(/[\s-]/g,"_")===w||u.name.toLowerCase().includes(w.replace(/_/g," ")))}function B(w,u){return a.value.actions?.[`${w}_${u}_tier`]||""}function A(w,u){const m=B(w,u);return m!==""&&m!==void 0}async function E(w,u,m){const O=`actions.${w}_${u}_tier`;try{const H=await ue(x.ADMIN_SETTINGS,{settings:[{key:O,value:m}]});a.value=H.settings,_("success",`Tier updated for ${w}/${u}`)}catch(H){const ne=H instanceof T?H:new T(0,"UNKNOWN","Unknown error");_("error",K(ne.code))}}async function b(w,u){const m=`actions.${w}_${u}_tier`;try{const O=await ue(x.ADMIN_SETTINGS,{settings:[{key:m,value:""}]});a.value=O.settings,_("success",`Tier reset to default for ${w}/${u}`)}catch(O){const H=O instanceof T?O:new T(0,"UNKNOWN","Unknown error");_("error",K(H.code))}}function C(w){const u=R(w.key),m=W(w.key);return u&&w.requiresApiKey&&!z(w.key)?.hasKey?{label:"Requires API Key",variant:"warning"}:u&&m?{label:"Active",variant:"success"}:{label:"Inactive",variant:"neutral"}}return l.value?e("div",{class:"page",children:e("div",{class:"empty-state",children:e("p",{children:"Loading action providers..."})})}):e("div",{class:"page",children:[hn.map(w=>{const u=C(w),m=R(w.key),O=D(w.key),H=z(w.key),ne=d.value===w.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:[w.name,O&&e(V,{variant:"info",children:O.version}),e(V,{variant:(w.chain==="solana","info"),children:w.chain})]}),e("p",{class:"settings-description",style:{marginTop:"var(--space-1)"},children:[w.description,w.docsUrl&&e(J,{children:[" ","—"," ",e("a",{href:w.docsUrl,target:"_blank",rel:"noopener noreferrer",children:"Docs"})]})]})]}),e(V,{variant:u.variant,children:u.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.${w.key}_enabled`,type:"checkbox",value:m,onChange:G=>N(w.key,!!G),disabled:ne}),ne&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)"},children:"Saving..."})]}),w.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===w.key?e("div",{style:{display:"flex",alignItems:"flex-end",gap:"var(--space-2)"},children:[e(k,{label:"API Key",type:"password",name:`apikey-${w.key}`,value:s.value,onChange:G=>{s.value=String(G)},placeholder:"Enter API key"}),e(M,{onClick:()=>$(w.key),loading:r.value,size:"sm",children:"Save"}),e(M,{variant:"ghost",onClick:()=>{i.value=null,s.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:H?.hasKey?H.maskedKey:"Not set"}),e(M,{variant:"ghost",onClick:()=>{i.value=w.key,s.value=""},size:"sm",children:H?.hasKey?"Update":"Set"}),H?.hasKey&&e(M,{variant:"danger",onClick:()=>P(w.key),size:"sm",children:"Delete"})]})]}),w.key==="aave_v3"&&m&&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(G=>{const de=a.value.actions,se=p.value[G]??de?.[G]??"";return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const ae=p.value[G];ae!==void 0&&g(G,ae)},children:e(k,{label:te(G),name:`actions.${G}`,type:"text",value:se,onChange:ae=>{p.value={...p.value,[G]:String(ae)}}})},G)})]}),w.key==="kamino"&&m&&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(G=>{const de=a.value.actions,se=p.value[G]??de?.[G]??"";return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const ae=p.value[G];ae!==void 0&&g(G,ae)},children:e(k,{label:te(G),name:`actions.${G}`,type:"text",value:se,onChange:ae=>{p.value={...p.value,[G]:String(ae)}}})},G)})]}),w.key==="drift_perp"&&m&&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(G=>{const de=a.value.actions,se=p.value[G]??de?.[G]??"";return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const ae=p.value[G];ae!==void 0&&g(G,ae)},children:e(k,{label:te(G),name:`actions.${G}`,type:"text",value:se,onChange:ae=>{p.value={...p.value,[G]:String(ae)}}})},G)})]}),m&&O&&O.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:O.actions.map(G=>e("tr",{children:[e("td",{children:G.name}),e("td",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)",maxWidth:"300px"},children:G.description}),e("td",{children:e(V,{variant:"info",children:G.chain})}),e("td",{children:G.riskLevel}),e("td",{children:e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e("select",{value:B(w.key,G.name)||G.defaultTier,onChange:de=>E(w.key,G.name,de.target.value),style:{padding:"2px 4px",fontSize:"var(--font-size-sm)",borderRadius:"var(--radius-sm)"},children:["INSTANT","NOTIFY","DELAY","APPROVAL"].map(de=>e("option",{value:de,children:de},de))}),A(w.key,G.name)&&e(J,{children:[e(V,{variant:"warning",children:"customized"}),e("button",{onClick:()=>b(w.key,G.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"})]})]})})]},G.name))})]})]})]})]},w.key)}),hn.length===0&&e("div",{class:"empty-state",children:e("p",{children:"No action providers available."})})]})}function qs(){const t=c([]),a=c(!0),n=c(!1),l=c(!1),i=c(!1),s=c(null),r=c(!1),d=c(""),p=c(""),o=c(""),v=c(!1),h=c({}),f=c(null),N=c(null),$=c({}),P=c(null),g=async()=>{try{const m=await q(x.ADMIN_WALLET_APPS);t.value=m.apps}catch{_("Failed to load wallet apps","error")}},R=async()=>{try{const O=(await q(x.ADMIN_SETTINGS)).signing_sdk;O&&(l.value=String(O.enabled)==="true",n.value=String(O.notifications_enabled)==="true")}catch{}};Y(()=>{Promise.all([g(),R()]).finally(()=>{a.value=!1})},[]);const W=async()=>{i.value=!0;const m=!n.value;try{await ue(x.ADMIN_SETTINGS,{settings:[{key:"signing_sdk.notifications_enabled",value:String(m)}]}),n.value=m,_(`Wallet app notifications ${m?"enabled":"disabled"}`,"success")}catch{_("Failed to update notification setting","error")}finally{i.value=!1}},z=async(m,O)=>{N.value=`${m.id}-${O}`;try{await ue(x.ADMIN_WALLET_APP(m.id),{[O]:!m[O]}),await g(),_(`${O==="signing_enabled"?"Signing":"Alerts"} ${m[O]?"disabled":"enabled"} for ${m.display_name}`,"success")}catch{_("Failed to update toggle","error")}finally{N.value=null}},D=async m=>{s.value=m.id;try{const O=await ve(x.ADMIN_WALLET_APP_TEST_NOTIFICATION(m.id));O.success?_(`Test notification sent to ${O.topic}`,"success"):_(O.error||"Test notification failed","error")}catch{_("Failed to send test notification","error")}finally{s.value=null}},B=async()=>{if(!d.value.trim()||!p.value.trim()){_("Name and display name are required","error");return}v.value=!0;try{const m={name:d.value.trim(),display_name:p.value.trim()};o.value.trim()&&(m.wallet_type=o.value.trim()),await ve(x.ADMIN_WALLET_APPS,m),r.value=!1,d.value="",p.value="",o.value="",await g(),_("Wallet app registered","success")}catch(m){m instanceof T&&m.code==="WALLET_APP_DUPLICATE"?_("App already registered","error"):_("Failed to register app","error")}finally{v.value=!1}},A=async(m,O)=>{f.value=m.id;try{await ue(x.ADMIN_WALLET_APP(m.id),{subscription_token:O||""});const H={...h.value};delete H[m.id],h.value=H,await g(),_(O?"Subscription token set":"Subscription token cleared","success")}catch{_("Failed to update subscription token","error")}finally{f.value=null}},E=async m=>{if(confirm(`Remove "${m.display_name}"? Wallets using this app will no longer route signing requests to it.`))try{await je(x.ADMIN_WALLET_APP(m.id)),await g(),_(`${m.display_name} removed`,"success")}catch{_("Failed to remove app","error")}},b=m=>{$.value={...$.value,[m.id]:{signTopic:m.sign_topic??"",notifyTopic:m.notify_topic??""}}},C=m=>{const O={...$.value};delete O[m],$.value=O},w=async m=>{const O=$.value[m.id];if(O){P.value=m.id;try{await ue(x.ADMIN_WALLET_APP(m.id),{sign_topic:O.signTopic||null,notify_topic:O.notifyTopic||null}),C(m.id),await g(),_("Topics updated","success")}catch{_("Failed to update topics","error")}finally{P.value=null}}},u=t.value.some(m=>m.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:W,disabled:i.value,"data-testid":"notif-toggle"}),e("span",{children:"Notifications"}),e(V,{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&&u&&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(M,{onClick:()=>{r.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(m=>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:[m.display_name,m.wallet_type&&m.wallet_type!==m.name&&e(V,{variant:"info",style:{marginLeft:"0.5rem",fontSize:"0.7rem"},children:m.wallet_type})]}),e("code",{style:{fontSize:"0.8rem",color:"var(--text-muted)"},children:m.name})]}),e(M,{variant:"danger",size:"sm",onClick:()=>E(m),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:m.signing_enabled,onChange:()=>z(m,"signing_enabled"),disabled:N.value===`${m.id}-signing_enabled`}),e("span",{children:"Signing"}),e(V,{variant:m.signing_enabled?"success":"muted",children:m.signing_enabled?"ON":"OFF"})]}),e("label",{style:{display:"flex",alignItems:"center",gap:"0.5rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:m.alerts_enabled,onChange:()=>z(m,"alerts_enabled"),disabled:N.value===`${m.id}-alerts_enabled`}),e("span",{children:"Alerts"}),e(V,{variant:m.alerts_enabled?"success":"muted",children:m.alerts_enabled?"ON":"OFF"})]}),m.alerts_enabled&&e(M,{variant:"secondary",size:"sm",onClick:()=>D(m),disabled:s.value===m.id,children:s.value===m.id?"Sending...":"Test"})]}),e("div",{style:{marginTop:"0.75rem"},children:[e("span",{style:{fontSize:"0.85rem",fontWeight:500},children:"Used by: "}),m.used_by.length===0?e("span",{style:{fontSize:"0.85rem",color:"var(--text-muted)"},children:"No wallets"}):e("span",{style:{fontSize:"0.85rem"},children:m.used_by.map((O,H)=>e("span",{children:[H>0&&", ",e("a",{href:`#/wallets/${O.id}`,style:{color:"var(--primary)"},children:O.label})]},O.id))})]}),e("div",{style:{marginTop:"0.75rem"},children:[e("span",{style:{fontSize:"0.85rem",fontWeight:500},children:"Subscription Token: "}),h.value[m.id]!==void 0?e("span",{style:{display:"inline-flex",gap:"0.5rem",alignItems:"center"},children:[e("input",{type:"text",value:h.value[m.id],onInput:O=>{h.value={...h.value,[m.id]:O.target.value}},placeholder:"e.g., a1b2c3d4",style:{padding:"0.25rem 0.5rem",fontSize:"0.85rem",width:"140px"}}),e(M,{size:"sm",onClick:()=>A(m,h.value[m.id]),disabled:f.value===m.id,children:f.value===m.id?"Saving...":"Set"}),e(M,{variant:"secondary",size:"sm",onClick:()=>{const O={...h.value};delete O[m.id],h.value=O},children:"Cancel"})]}):m.subscription_token?e("span",{style:{fontSize:"0.85rem"},children:[e("code",{children:[m.subscription_token.slice(0,4),"****"]}),e(M,{variant:"secondary",size:"sm",onClick:()=>A(m,""),disabled:f.value===m.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(M,{variant:"secondary",size:"sm",onClick:()=>{h.value={...h.value,[m.id]:""}},style:{marginLeft:"0.5rem"},children:"Set"})]})]}),$.value[m.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-${m.id}`,type:"text",value:$.value[m.id].signTopic,onChange:O=>{$.value={...$.value,[m.id]:{...$.value[m.id],signTopic:String(O)}}},placeholder:`waiaas-sign-${m.name}`,description:"ntfy topic for signing requests"}),e(k,{label:"Notify Topic",name:`notify-topic-${m.id}`,type:"text",value:$.value[m.id].notifyTopic,onChange:O=>{$.value={...$.value,[m.id]:{...$.value[m.id],notifyTopic:String(O)}}},placeholder:`waiaas-notify-${m.name}`,description:"ntfy topic for activity alerts"})]}),e("div",{style:{display:"flex",gap:"0.5rem",justifyContent:"flex-end",marginTop:"0.5rem"},children:[e(M,{variant:"secondary",size:"sm",onClick:()=>C(m.id),children:"Cancel"}),e(M,{size:"sm",onClick:()=>w(m),disabled:P.value===m.id,children:P.value===m.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(M,{variant:"secondary",size:"sm",onClick:()=>b(m),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:m.sign_topic??"(default)"})]}),e("div",{children:[e("span",{style:{color:"var(--text-muted)"},children:"Notify Topic: "}),e("code",{children:m.notify_topic??"(default)"})]})]})]})]},m.id))})})]}),e(Se,{open:r.value,title:"Register Wallet App",onCancel:()=>{r.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:d.value,onChange:m=>{d.value=String(m)},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:p.value,onChange:m=>{p.value=String(m)},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:o.value,onChange:m=>{o.value=String(m)},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(M,{variant:"secondary",onClick:()=>{r.value=!1},children:"Cancel"}),e(M,{onClick:B,disabled:v.value||!d.value.trim()||!p.value.trim(),children:v.value?"Registering...":"Register"})]})]})})]})}const mn=[{key:"identity",label:"Identity"},{key:"registration",label:"Registration File"},{key:"reputation",label:"Reputation"}];function _t({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(_t,{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],s)=>e("div",{style:{paddingLeft:"var(--space-3)"},children:[e("span",{style:{fontWeight:"bold"},children:['"',l,'"']}),": ",e(_t,{data:i,depth:a+1}),s<n.length-1?",":""]},l)),"}"]})}return e("span",{children:String(t)})}function fn(){const t=c("identity"),a=c(!0),n=c(!1),l=c([]),i=c([]),s=c([]),r=c({}),d=c(!1),p=c(!1),o=c(""),v=c(""),h=c(""),f=c(!1),N=c(""),$=c(null),P=c(!1),g=c(null),R=c(""),W=c(""),z=c(""),D=c(null),B=c(!1),A=c(null),E=c(""),b=c(!1);async function C(){a.value=!0;try{const I=await q(x.ADMIN_SETTINGS);r.value=I;const X=I.actions;n.value=X?.erc8004_agent_enabled==="true";try{const xe=(await q(x.ACTIONS_PROVIDERS)).providers?.find(S=>S.name==="erc8004_agent");i.value=xe?.actions??[]}catch{}const L=await q(x.WALLETS);l.value=L;const Z=L.filter(ee=>ee.chain==="ethereum"),re=[];for(const ee of Z)try{const xe=await q(x.ERC8004_REGISTRATION_FILE(ee.id)),S=xe.agentId;re.push({walletId:ee.id,walletName:ee.name,agentId:S??null,status:S?"REGISTERED":"NOT_REGISTERED",registryAddress:xe.registryAddress??""})}catch{re.push({walletId:ee.id,walletName:ee.name,agentId:null,status:"NOT_REGISTERED",registryAddress:""})}s.value=re}catch(I){I instanceof T&&_(K(I.code),"error")}finally{a.value=!1}}Y(()=>{C()},[]);async function w(I){d.value=!0;try{await ue(x.ADMIN_SETTINGS,{settings:[{key:"actions.erc8004_agent_enabled",value:String(I)}]}),n.value=I,_(`Agent Identity ${I?"enabled":"disabled"}`,"success"),await C()}catch(X){X instanceof T&&_(K(X.code),"error")}finally{d.value=!1}}async function u(){if(!(!o.value||!v.value)){f.value=!0;try{await ve(`${x.ACTIONS_PROVIDERS}/erc8004_agent/register_agent`,{params:{name:v.value,...h.value?{description:h.value}:{}},walletId:o.value}),_("Agent registration initiated","success"),p.value=!1,v.value="",h.value="",o.value="",await C()}catch(I){I instanceof T&&_(K(I.code),"error")}finally{f.value=!1}}}async function m(I,X){A.value=I,b.value=!1,E.value="";try{const L=await ve(x.WALLET_WC_PAIR(I),{});E.value=L.uri;const Z=setInterval(async()=>{try{(await q(x.WALLET_WC_PAIR_STATUS(I))).connected&&(clearInterval(Z),b.value=!0,await ve(`${x.ACTIONS_PROVIDERS}/erc8004_agent/set_agent_wallet`,{params:{agentId:X},walletId:I}),_("Wallet linking initiated via EIP-712","success"),A.value=null,await C())}catch{}},1e3);setTimeout(()=>{clearInterval(Z),!b.value&&A.value&&(_("WalletConnect pairing timed out","error"),A.value=null)},6e4)}catch(L){L instanceof T&&_(K(L.code),"error"),A.value=null}}async function O(I,X){try{await ve(`${x.ACTIONS_PROVIDERS}/erc8004_agent/unset_agent_wallet`,{params:{agentId:X},walletId:I}),_("Wallet unlinking initiated","success"),await C()}catch(L){L instanceof T&&_(K(L.code),"error")}}async function H(I){if(I){P.value=!0;try{const X=await q(x.ERC8004_REGISTRATION_FILE(I));$.value=X}catch(X){X instanceof T&&_(K(X.code),"error"),$.value=null}finally{P.value=!1}}}async function ne(I,X,L){try{const re=new URLSearchParams().toString(),ee=await q(`${x.ERC8004_REPUTATION(I)}${re?`?${re}`:""}`);g.value=ee}catch{g.value=null}}async function G(){if(z.value){B.value=!0;try{const I=new URLSearchParams;R.value&&I.set("tag1",R.value),W.value&&I.set("tag2",W.value);const X=I.toString(),L=await q(`${x.ERC8004_REPUTATION(z.value)}${X?`?${X}`:""}`);D.value=L}catch(I){I instanceof T&&_(K(I.code),"error"),D.value=null}finally{B.value=!1}}}function de(I){return I>=50?"success":I>=20?"warning":"danger"}function se(I,X){return r.value.actions?.[`${I}_${X}_tier`]||""}function ae(I,X){const L=se(I,X);return L!==""&&L!==void 0}async function be(I,X,L){const Z=`actions.${I}_${X}_tier`;try{const re=await ue(x.ADMIN_SETTINGS,{settings:[{key:Z,value:L}]});r.value=re.settings,_(`Tier updated for ${I}/${X}`,"success")}catch(re){re instanceof T&&_(K(re.code),"error")}}async function De(I,X){const L=`actions.${I}_${X}_tier`;try{const Z=await ue(x.ADMIN_SETTINGS,{settings:[{key:L,value:""}]});r.value=Z.settings,_(`Tier reset to default for ${I}/${X}`,"success")}catch(Z){Z instanceof T&&_(K(Z.code),"error")}}const Ce=n.value?mn:mn.filter(I=>I.key==="identity");Ce.some(I=>I.key===t.value)||(t.value="identity");const Ee=l.value.filter(I=>I.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:I=>w(!!I),disabled:d.value}),d.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(J,{children:[e(Ye,{tabs:Ce,activeTab:t.value,onTabChange:I=>{t.value=I}}),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(M,{variant:"primary",onClick:()=>{p.value=!0},children:"Register Agent"})]}),s.value.length===0?e(Je,{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:s.value.map(I=>e("tr",{children:[e("td",{children:I.walletName}),e("td",{title:I.walletId,children:[I.walletId.slice(0,8),"..."]}),e("td",{children:e(V,{variant:I.status==="REGISTERED"?"success":I.status==="WALLET_LINKED"?"info":"default",children:I.status})}),e("td",{children:I.agentId??"-"}),e("td",{title:I.registryAddress,children:I.registryAddress?`${I.registryAddress.slice(0,10)}...`:"-"}),n.value&&e("td",{children:[I.agentId&&I.status==="REGISTERED"&&e(M,{variant:"secondary",onClick:()=>m(I.walletId,I.agentId),disabled:A.value===I.walletId,children:A.value===I.walletId?"Linking...":"Link Wallet"}),I.agentId&&I.status==="WALLET_LINKED"&&e(M,{variant:"danger",onClick:()=>O(I.walletId,I.agentId),children:"Unlink"})]})]},I.walletId))})]}),A.value&&E.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:E.value}),e("div",{style:{marginTop:"var(--space-2)"},children:e(qe,{value:E.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(I=>e("tr",{children:[e("td",{children:I.name}),e("td",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)",maxWidth:"300px"},children:I.description}),e("td",{children:I.riskLevel}),e("td",{children:e("div",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e("select",{value:se("erc8004_agent",I.name)||I.defaultTier,onChange:X=>be("erc8004_agent",I.name,X.target.value),style:{padding:"2px 4px",fontSize:"var(--font-size-sm)",borderRadius:"var(--radius-sm)"},disabled:!n.value,children:["INSTANT","NOTIFY","DELAY","APPROVAL"].map(X=>e("option",{value:X,children:X},X))}),ae("erc8004_agent",I.name)&&n.value&&e(J,{children:[e(V,{variant:"warning",children:"customized"}),e("button",{onClick:()=>De("erc8004_agent",I.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"})]})]})})]},I.name))})]})]})]}),n.value&&t.value==="registration"&&e("div",{children:[e("div",{class:"form-field",children:[e("label",{children:"Select Wallet"}),e("select",{value:N.value,onChange:I=>{const X=I.target.value;N.value=X,X&&H(X)},children:[e("option",{value:"",children:"-- Select wallet --"}),Ee.map(I=>e("option",{value:I.id,children:[I.name," (",I.id.slice(0,8),"...)"]},I.id))]})]}),N.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(qe,{value:`${window.location.origin}/v1/erc8004/registration-file/${N.value}`,label:"Copy URL"})]}),P.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(_t,{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"}),s.value.filter(I=>I.agentId).length===0?e("p",{children:"No registered agents. Register an agent first."}):e("div",{children:s.value.filter(I=>I.agentId).map(I=>((!g.value||g.value.agentId!==I.agentId)&&ne(I.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 #",I.agentId]}),g.value&&g.value.agentId===I.agentId&&e(J,{children:[e("span",{style:{fontSize:"var(--font-xl)",fontWeight:"bold"},children:Number(g.value.score)/Math.pow(10,g.value.decimals)}),e(V,{variant:de(Number(g.value.score)/Math.pow(10,g.value.decimals)),children:[g.value.count," feedback(s)"]})]})]})},I.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:R.value,onInput:I=>{R.value=I.target.value},placeholder:"e.g. reliability"})]}),e("div",{class:"form-field",children:[e("label",{children:"Tag2 Filter"}),e("input",{type:"text",value:W.value,onInput:I=>{W.value=I.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:z.value,onInput:I=>{z.value=I.target.value},placeholder:"Enter agent ID"})]}),e(M,{variant:"primary",onClick:G,loading:B.value,children:"Query"})]}),D.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 #",D.value.agentId]})}),e("p",{children:["Score: ",Number(D.value.score)/Math.pow(10,D.value.decimals)]}),e("p",{children:["Feedback count: ",D.value.count]}),D.value.tag1&&e("p",{children:["Tag1: ",D.value.tag1]}),D.value.tag2&&e("p",{children:["Tag2: ",D.value.tag2]}),e(V,{variant:de(Number(D.value.score)/Math.pow(10,D.value.decimals)),children:Number(D.value.score)/Math.pow(10,D.value.decimals)>=50?"Good":Number(D.value.score)/Math.pow(10,D.value.decimals)>=20?"Fair":"Low"})]})]})]}),a.value&&e("p",{class:"loading-text",children:"Loading..."}),e(Se,{open:p.value,title:"Register Agent",onConfirm:u,onCancel:()=>{p.value=!1},confirmText:"Register",loading:f.value,confirmDisabled:!o.value||!v.value,children:[e("div",{class:"form-field",children:[e("label",{children:"EVM Wallet"}),e("select",{value:o.value,onChange:I=>{o.value=I.target.value},children:[e("option",{value:"",children:"-- Select wallet --"}),Ee.map(I=>e("option",{value:I.id,children:[I.name," (",I.id.slice(0,8),"...)"]},I.id))]})]}),e("div",{class:"form-field",children:[e("label",{children:"Name"}),e("input",{type:"text",value:v.value,onInput:I=>{v.value=I.target.value},placeholder:"Agent name"})]}),e("div",{class:"form-field",children:[e("label",{children:"Description (optional)"}),e("input",{type:"text",value:h.value,onInput:I=>{h.value=I.target.value},placeholder:"Description"})]})]})]})}function Yn(t){const a=t.slice(1)||"/dashboard",n=a.indexOf("?");return n>=0?a.slice(0,n):a}const Be=Te(Yn(window.location.hash)),Ma=Te(!1);window.addEventListener("hashchange",()=>{Be.value=Yn(window.location.hash)});const js={"/dashboard":"Dashboard","/wallets":"Wallets","/transactions":"Transactions","/sessions":"Sessions","/tokens":"Token Registry","/defi":"DeFi","/agent-identity":"Agent Identity","/policies":"Policies","/notifications":"Notifications","/security":"Security","/wallet-apps":"Human Wallet Apps","/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","/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","/system":"API keys, display preferences, and daemon configuration"};function Xs(t){return t.startsWith("/wallets/")?"Wallet Detail":js[t]??"Dashboard"}function gn(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:"/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:"/system",label:"System"}];function Zs(){const t=Be.value;return t==="/transactions"?e(an,{}):t==="/incoming"?(window.location.hash="#/transactions",e(an,{})):t==="/tokens"?e(Ji,{}):t==="/defi"?e(pn,{}):t==="/actions"?(window.location.hash="#/defi",e(pn,{})):t==="/sessions"?e(es,{}):t==="/policies"?e(Ls,{}):t==="/notifications"?e(vn,{}):t==="/telegram-users"?(window.location.hash="#/notifications",e(vn,{})):t==="/settings"?(window.location.hash="#/dashboard",e(qt,{})):t==="/walletconnect"?(window.location.hash="#/wallets",e(Jt,{})):t==="/security"?e(Hs,{}):t==="/wallet-apps"?e(qs,{}):t==="/agent-identity"?e(fn,{}):t==="/erc8004"?(window.location.hash="#/agent-identity",e(fn,{})):t==="/system"?e(Gs,{}):t.startsWith("/wallets")?e(Jt,{}):e(qt,{})}function Qs(){return Y(()=>{const t=a=>{(a.metaKey||a.ctrlKey)&&a.key==="k"&&(a.preventDefault(),Ma.value=!Ma.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"?Be.value.startsWith("/wallets"):Be.value===t.path;return e("a",{href:`#${t.path}`,class:`sidebar-link ${a?"active":""}`,onClick:n=>{zn.value&&(n.preventDefault(),Vn({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(Be.value)}),gn(Be.value)&&e("p",{class:"header-subtitle",children:gn(Be.value)})]}),e("div",{class:"header-actions",children:[e("button",{class:"btn-search",onClick:()=>{Ma.value=!0},title:"Search settings (Ctrl+K)",children:"🔍"}),e("button",{class:"btn-logout",onClick:()=>Za(),children:"Logout"})]})]}),e("div",{class:"content",children:e(Zs,{})})]}),e(ei,{open:Ma}),e(ni,{})]})}const Ua={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 er(){return e("div",{style:Ua.overlay,children:e("div",{style:Ua.content,children:[e("h1",{style:Ua.title,children:"Daemon Shutting Down"}),e("p",{style:Ua.message,children:"The daemon is shutting down. Please wait or restart."})]})})}function ar(){return zl.value?e(er,{}):Bl.value?e(J,{children:[e(Qs,{}),e(mi,{})]}):e(Yl,{})}Ll(e(ar,{}),document.getElementById("app"));
|