@waiaas/daemon 2.8.0 → 2.9.0-rc.1
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/dist/api/helpers/resolve-wallet-id.d.ts +10 -5
- package/dist/api/helpers/resolve-wallet-id.d.ts.map +1 -1
- package/dist/api/helpers/resolve-wallet-id.js +27 -12
- package/dist/api/helpers/resolve-wallet-id.js.map +1 -1
- package/dist/api/middleware/owner-auth.d.ts.map +1 -1
- package/dist/api/middleware/owner-auth.js +24 -8
- package/dist/api/middleware/owner-auth.js.map +1 -1
- package/dist/api/middleware/session-auth.d.ts +2 -2
- package/dist/api/middleware/session-auth.d.ts.map +1 -1
- package/dist/api/middleware/session-auth.js +3 -4
- package/dist/api/middleware/session-auth.js.map +1 -1
- package/dist/api/routes/actions.d.ts.map +1 -1
- package/dist/api/routes/actions.js +3 -4
- package/dist/api/routes/actions.js.map +1 -1
- package/dist/api/routes/admin.d.ts.map +1 -1
- package/dist/api/routes/admin.js +9 -24
- package/dist/api/routes/admin.js.map +1 -1
- package/dist/api/routes/connect-info.d.ts +0 -1
- package/dist/api/routes/connect-info.d.ts.map +1 -1
- package/dist/api/routes/connect-info.js +2 -9
- package/dist/api/routes/connect-info.js.map +1 -1
- package/dist/api/routes/mcp.d.ts.map +1 -1
- package/dist/api/routes/mcp.js +0 -2
- package/dist/api/routes/mcp.js.map +1 -1
- package/dist/api/routes/openapi-schemas.d.ts +0 -74
- package/dist/api/routes/openapi-schemas.d.ts.map +1 -1
- package/dist/api/routes/openapi-schemas.js +4 -31
- package/dist/api/routes/openapi-schemas.js.map +1 -1
- package/dist/api/routes/sessions.d.ts +1 -2
- package/dist/api/routes/sessions.d.ts.map +1 -1
- package/dist/api/routes/sessions.js +14 -84
- package/dist/api/routes/sessions.js.map +1 -1
- package/dist/api/routes/transactions.d.ts.map +1 -1
- package/dist/api/routes/transactions.js +4 -5
- package/dist/api/routes/transactions.js.map +1 -1
- package/dist/api/routes/wallet.d.ts +2 -3
- package/dist/api/routes/wallet.d.ts.map +1 -1
- package/dist/api/routes/wallet.js +23 -68
- 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 +18 -98
- package/dist/api/routes/wallets.js.map +1 -1
- package/dist/api/routes/wc.d.ts.map +1 -1
- package/dist/api/routes/wc.js +7 -5
- package/dist/api/routes/wc.js.map +1 -1
- package/dist/api/server.d.ts.map +1 -1
- package/dist/api/server.js +1 -2
- package/dist/api/server.js.map +1 -1
- package/dist/infrastructure/adapter-pool.d.ts +0 -1
- package/dist/infrastructure/adapter-pool.d.ts.map +1 -1
- package/dist/infrastructure/adapter-pool.js +0 -4
- package/dist/infrastructure/adapter-pool.js.map +1 -1
- package/dist/infrastructure/config/loader.d.ts +0 -5
- package/dist/infrastructure/config/loader.d.ts.map +1 -1
- package/dist/infrastructure/config/loader.js +0 -3
- 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 +76 -5
- package/dist/infrastructure/database/migrate.js.map +1 -1
- package/dist/infrastructure/database/schema.d.ts +2 -37
- package/dist/infrastructure/database/schema.d.ts.map +1 -1
- package/dist/infrastructure/database/schema.js +3 -5
- package/dist/infrastructure/database/schema.js.map +1 -1
- package/dist/infrastructure/jwt/jwt-secret-manager.d.ts +0 -1
- package/dist/infrastructure/jwt/jwt-secret-manager.d.ts.map +1 -1
- package/dist/infrastructure/jwt/jwt-secret-manager.js +0 -2
- package/dist/infrastructure/jwt/jwt-secret-manager.js.map +1 -1
- package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -1
- package/dist/infrastructure/settings/hot-reload.js +1 -3
- 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 +1 -2
- package/dist/infrastructure/settings/setting-keys.js.map +1 -1
- package/dist/infrastructure/telegram/telegram-bot-service.d.ts.map +1 -1
- package/dist/infrastructure/telegram/telegram-bot-service.js +2 -3
- package/dist/infrastructure/telegram/telegram-bot-service.js.map +1 -1
- package/dist/lifecycle/daemon.d.ts.map +1 -1
- package/dist/lifecycle/daemon.js +28 -19
- package/dist/lifecycle/daemon.js.map +1 -1
- package/dist/notifications/notification-service.d.ts.map +1 -1
- package/dist/notifications/notification-service.js +1 -2
- package/dist/notifications/notification-service.js.map +1 -1
- package/dist/pipeline/network-resolver.d.ts +13 -8
- package/dist/pipeline/network-resolver.d.ts.map +1 -1
- package/dist/pipeline/network-resolver.js +22 -13
- package/dist/pipeline/network-resolver.js.map +1 -1
- package/dist/pipeline/pipeline.d.ts.map +1 -1
- package/dist/pipeline/pipeline.js +2 -3
- package/dist/pipeline/pipeline.js.map +1 -1
- package/dist/pipeline/stages.d.ts +0 -1
- package/dist/pipeline/stages.d.ts.map +1 -1
- package/dist/pipeline/stages.js +4 -0
- package/dist/pipeline/stages.js.map +1 -1
- package/dist/services/monitoring/balance-monitor-service.d.ts.map +1 -1
- package/dist/services/monitoring/balance-monitor-service.js +34 -26
- package/dist/services/monitoring/balance-monitor-service.js.map +1 -1
- package/package.json +5 -5
- package/public/admin/assets/index-ClljeO4N.js +1 -0
- package/public/admin/index.html +1 -1
- package/public/admin/assets/index-CgtuiQGn.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var Ut,te,Qa,en,Ue,wa,tn,an,nn,va,ia,sa,ht={},ln=[],zn=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,Wt=Array.isArray;function ke(a,t){for(var n in t)a[n]=t[n];return a}function ha(a){a&&a.parentNode&&a.parentNode.removeChild(a)}function qn(a,t,n){var l,i,s,r={};for(s in t)s=="key"?l=t[s]:s=="ref"?i=t[s]:r[s]=t[s];if(arguments.length>2&&(r.children=arguments.length>3?Ut.call(arguments,2):n),typeof a=="function"&&a.defaultProps!=null)for(s in a.defaultProps)r[s]===void 0&&(r[s]=a.defaultProps[s]);return Dt(a,r,l,i,null)}function Dt(a,t,n,l,i){var s={type:a,props:t,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++Qa,__i:-1,__u:0};return i==null&&te.vnode!=null&&te.vnode(s),s}function Y(a){return a.children}function ct(a,t){this.props=a,this.context=t}function Je(a,t){if(t==null)return a.__?Je(a.__,a.__i+1):null;for(var n;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null)return n.__e;return typeof a.type=="function"?Je(a):null}function sn(a){var t,n;if((a=a.__)!=null&&a.__c!=null){for(a.__e=a.__c.base=null,t=0;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null){a.__e=a.__c.base=n.__e;break}return sn(a)}}function Sa(a){(!a.__d&&(a.__d=!0)&&Ue.push(a)&&!Ot.__r++||wa!=te.debounceRendering)&&((wa=te.debounceRendering)||tn)(Ot)}function Ot(){for(var a,t,n,l,i,s,r,c=1;Ue.length;)Ue.length>c&&Ue.sort(an),a=Ue.shift(),c=Ue.length,a.__d&&(n=void 0,l=void 0,i=(l=(t=a).__v).__e,s=[],r=[],t.__P&&((n=ke({},l)).__v=l.__v+1,te.vnode&&te.vnode(n),pa(t.__P,n,l,t.__n,t.__P.namespaceURI,32&l.__u?[i]:null,s,i??Je(l),!!(32&l.__u),r),n.__v=l.__v,n.__.__k[n.__i]=n,cn(s,n,r),l.__e=l.__=null,n.__e!=i&&sn(n)));Ot.__r=0}function rn(a,t,n,l,i,s,r,c,p,o,v){var h,f,N,P,E,y,D,U=l&&l.__k||ln,K=t.length;for(p=jn(n,t,U,p,K),h=0;h<K;h++)(N=n.__k[h])!=null&&(f=N.__i==-1?ht:U[N.__i]||ht,N.__i=h,y=pa(a,N,f,i,s,r,c,p,o,v),P=N.__e,N.ref&&f.ref!=N.ref&&(f.ref&&ma(f.ref,null,N),v.push(N.ref,N.__c||P,N)),E==null&&P!=null&&(E=P),(D=!!(4&N.__u))||f.__k===N.__k?p=on(N,p,a,D):typeof N.type=="function"&&y!==void 0?p=y:P&&(p=P.nextSibling),N.__u&=-7);return n.__e=E,p}function jn(a,t,n,l,i){var s,r,c,p,o,v=n.length,h=v,f=0;for(a.__k=new Array(i),s=0;s<i;s++)(r=t[s])!=null&&typeof r!="boolean"&&typeof r!="function"?(typeof r=="string"||typeof r=="number"||typeof r=="bigint"||r.constructor==String?r=a.__k[s]=Dt(null,r,null,null,null):Wt(r)?r=a.__k[s]=Dt(Y,{children:r},null,null,null):r.constructor===void 0&&r.__b>0?r=a.__k[s]=Dt(r.type,r.props,r.key,r.ref?r.ref:null,r.__v):a.__k[s]=r,p=s+f,r.__=a,r.__b=a.__b+1,c=null,(o=r.__i=Yn(r,n,p,h))!=-1&&(h--,(c=n[o])&&(c.__u|=2)),c==null||c.__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))):a.__k[s]=null;if(h)for(s=0;s<v;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==l&&(l=Je(c)),un(c,c));return l}function on(a,t,n,l){var i,s;if(typeof a.type=="function"){for(i=a.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=a,t=on(i[s],t,n,l));return t}a.__e!=t&&(l&&(t&&a.type&&!t.parentNode&&(t=Je(a)),n.insertBefore(a.__e,t||null)),t=a.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function Yn(a,t,n,l){var i,s,r,c=a.key,p=a.type,o=t[n],v=o!=null&&(2&o.__u)==0;if(o===null&&c==null||v&&c==o.key&&p==o.type)return n;if(l>(v?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((o=t[r=i>=0?i--:s++])!=null&&(2&o.__u)==0&&c==o.key&&p==o.type)return r}return-1}function Ta(a,t,n){t[0]=="-"?a.setProperty(t,n??""):a[t]=n==null?"":typeof n!="number"||zn.test(t)?n:n+"px"}function St(a,t,n,l,i){var s,r;e:if(t=="style")if(typeof n=="string")a.style.cssText=n;else{if(typeof l=="string"&&(a.style.cssText=l=""),l)for(t in l)n&&t in n||Ta(a.style,t,"");if(n)for(t in n)l&&n[t]==l[t]||Ta(a.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(nn,"$1")),r=t.toLowerCase(),t=r in a||t=="onFocusOut"||t=="onFocusIn"?r.slice(2):t.slice(2),a.l||(a.l={}),a.l[t+s]=n,n?l?n.u=l.u:(n.u=va,a.addEventListener(t,s?sa:ia,s)):a.removeEventListener(t,s?sa:ia,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in a)try{a[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?a.removeAttribute(t):a.setAttribute(t,t=="popover"&&n==1?"":n))}}function ka(a){return function(t){if(this.l){var n=this.l[t.type+a];if(t.t==null)t.t=va++;else if(t.t<n.u)return;return n(te.event?te.event(t):t)}}}function pa(a,t,n,l,i,s,r,c,p,o){var v,h,f,N,P,E,y,D,U,K,I,A,k,u,m,S,g,O=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(p=!!(32&n.__u),s=[c=t.__e=n.__e]),(v=te.__b)&&v(t);e:if(typeof O=="function")try{if(D=t.props,U="prototype"in O&&O.prototype.render,K=(v=O.contextType)&&l[v.__c],I=v?K?K.props.value:v.__:l,n.__c?y=(h=t.__c=n.__c).__=h.__E:(U?t.__c=h=new O(D,I):(t.__c=h=new ct(D,I),h.constructor=O,h.render=Jn),K&&K.sub(h),h.state||(h.state={}),h.__n=l,f=h.__d=!0,h.__h=[],h._sb=[]),U&&h.__s==null&&(h.__s=h.state),U&&O.getDerivedStateFromProps!=null&&(h.__s==h.state&&(h.__s=ke({},h.__s)),ke(h.__s,O.getDerivedStateFromProps(D,h.__s))),N=h.props,P=h.state,h.__v=t,f)U&&O.getDerivedStateFromProps==null&&h.componentWillMount!=null&&h.componentWillMount(),U&&h.componentDidMount!=null&&h.__h.push(h.componentDidMount);else{if(U&&O.getDerivedStateFromProps==null&&D!==N&&h.componentWillReceiveProps!=null&&h.componentWillReceiveProps(D,I),t.__v==n.__v||!h.__e&&h.shouldComponentUpdate!=null&&h.shouldComponentUpdate(D,h.__s,I)===!1){for(t.__v!=n.__v&&(h.props=D,h.state=h.__s,h.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function($){$&&($.__=t)}),A=0;A<h._sb.length;A++)h.__h.push(h._sb[A]);h._sb=[],h.__h.length&&r.push(h);break e}h.componentWillUpdate!=null&&h.componentWillUpdate(D,h.__s,I),U&&h.componentDidUpdate!=null&&h.__h.push(function(){h.componentDidUpdate(N,P,E)})}if(h.context=I,h.props=D,h.__P=a,h.__e=!1,k=te.__r,u=0,U){for(h.state=h.__s,h.__d=!1,k&&k(t),v=h.render(h.props,h.state,h.context),m=0;m<h._sb.length;m++)h.__h.push(h._sb[m]);h._sb=[]}else do h.__d=!1,k&&k(t),v=h.render(h.props,h.state,h.context),h.state=h.__s;while(h.__d&&++u<25);h.state=h.__s,h.getChildContext!=null&&(l=ke(ke({},l),h.getChildContext())),U&&!f&&h.getSnapshotBeforeUpdate!=null&&(E=h.getSnapshotBeforeUpdate(N,P)),S=v,v!=null&&v.type===Y&&v.key==null&&(S=dn(v.props.children)),c=rn(a,Wt(S)?S:[S],t,n,l,i,s,r,c,p,o),h.base=t.__e,t.__u&=-161,h.__h.length&&r.push(h),y&&(h.__E=h.__=null)}catch($){if(t.__v=null,p||s!=null)if($.then){for(t.__u|=p?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(g=s.length;g--;)ha(s[g]);ra(t)}else t.__e=n.__e,t.__k=n.__k,$.then||ra(t);te.__e($,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=Xn(n.__e,t,n,l,i,s,r,p,o);return(v=te.diffed)&&v(t),128&t.__u?void 0:c}function ra(a){a&&a.__c&&(a.__c.__e=!0),a&&a.__k&&a.__k.forEach(ra)}function cn(a,t,n){for(var l=0;l<n.length;l++)ma(n[l],n[++l],n[++l]);te.__c&&te.__c(t,a),a.some(function(i){try{a=i.__h,i.__h=[],a.some(function(s){s.call(i)})}catch(s){te.__e(s,i.__v)}})}function dn(a){return typeof a!="object"||a==null||a.__b&&a.__b>0?a:Wt(a)?a.map(dn):ke({},a)}function Xn(a,t,n,l,i,s,r,c,p){var o,v,h,f,N,P,E,y=n.props||ht,D=t.props,U=t.type;if(U=="svg"?i="http://www.w3.org/2000/svg":U=="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==!!U&&(U?N.localName==U:N.nodeType==3)){a=N,s[o]=null;break}}if(a==null){if(U==null)return document.createTextNode(D);a=document.createElementNS(i,U,D.is&&D),c&&(te.__m&&te.__m(t,s),c=!1),s=null}if(U==null)y===D||c&&a.data==D||(a.data=D);else{if(s=s&&Ut.call(a.childNodes),!c&&s!=null)for(y={},o=0;o<a.attributes.length;o++)y[(N=a.attributes[o]).name]=N.value;for(o in y)if(N=y[o],o!="children"){if(o=="dangerouslySetInnerHTML")h=N;else if(!(o in D)){if(o=="value"&&"defaultValue"in D||o=="checked"&&"defaultChecked"in D)continue;St(a,o,null,N,i)}}for(o in D)N=D[o],o=="children"?f=N:o=="dangerouslySetInnerHTML"?v=N:o=="value"?P=N:o=="checked"?E=N:c&&typeof N!="function"||y[o]===N||St(a,o,N,y[o],i);if(v)c||h&&(v.__html==h.__html||v.__html==a.innerHTML)||(a.innerHTML=v.__html),t.__k=[];else if(h&&(a.innerHTML=""),rn(t.type=="template"?a.content:a,Wt(f)?f:[f],t,n,l,U=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,r,s?s[0]:n.__k&&Je(n,0),c,p),s!=null)for(o=s.length;o--;)ha(s[o]);c||(o="value",U=="progress"&&P==null?a.removeAttribute("value"):P!=null&&(P!==a[o]||U=="progress"&&!P||U=="option"&&P!=y[o])&&St(a,o,P,y[o],i),o="checked",E!=null&&E!=a[o]&&St(a,o,E,y[o],i))}return a}function ma(a,t,n){try{if(typeof a=="function"){var l=typeof a.__u=="function";l&&a.__u(),l&&t==null||(a.__u=a(t))}else a.current=t}catch(i){te.__e(i,n)}}function un(a,t,n){var l,i;if(te.unmount&&te.unmount(a),(l=a.ref)&&(l.current&&l.current!=a.__e||ma(l,null,t)),(l=a.__c)!=null){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(s){te.__e(s,t)}l.base=l.__P=null}if(l=a.__k)for(i=0;i<l.length;i++)l[i]&&un(l[i],t,n||typeof a.type!="function");n||ha(a.__e),a.__c=a.__=a.__e=void 0}function Jn(a,t,n){return this.constructor(a,n)}function Zn(a,t,n){var l,i,s,r;t==document&&(t=document.documentElement),te.__&&te.__(a,t),i=(l=!1)?null:t.__k,s=[],r=[],pa(t,a=t.__k=qn(Y,null,[a]),i||ht,ht,t.namespaceURI,i?null:t.firstChild?Ut.call(t.childNodes):null,s,i?i.__e:t.firstChild,l,r),cn(s,a,r)}Ut=ln.slice,te={__e:function(a,t,n,l){for(var i,s,r;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(a)),r=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(a,l||{}),r=i.__d),r)return i.__E=i}catch(c){a=c}throw a}},Qa=0,en=function(a){return a!=null&&a.constructor===void 0},ct.prototype.setState=function(a,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=ke({},this.state),typeof a=="function"&&(a=a(ke({},n),this.props)),a&&ke(n,a),a!=null&&this.__v&&(t&&this._sb.push(t),Sa(this))},ct.prototype.forceUpdate=function(a){this.__v&&(this.__e=!0,a&&this.__h.push(a),Sa(this))},ct.prototype.render=Y,Ue=[],tn=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,an=function(a,t){return a.__v.__b-t.__v.__b},Ot.__r=0,nn=/(PointerCapture)$|Capture$/i,va=0,ia=ka(!1),sa=ka(!0);var Qn=0;function e(a,t,n,l,i,s){t||(t={});var r,c,p=t;if("ref"in p)for(c in p={},t)c=="ref"?r=t[c]:p[c]=t[c];var o={type:a,props:p,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--Qn,__i:-1,__u:0,__source:i,__self:s};if(typeof a=="function"&&(r=a.defaultProps))for(c in r)p[c]===void 0&&(p[c]=r[c]);return te.vnode&&te.vnode(o),o}var Lt,fe,jt,Na,oa=0,vn=[],se=te,Ea=se.__b,Aa=se.__r,Ca=se.diffed,Ia=se.__c,Da=se.unmount,xa=se.__;function hn(a,t){se.__h&&se.__h(fe,a,oa||t),oa=0;var n=fe.__H||(fe.__H={__:[],__h:[]});return a>=n.__.length&&n.__.push({}),n.__[a]}function F(a,t){var n=hn(Lt++,3);!se.__s&&pn(n.__H,t)&&(n.__=a,n.u=t,fe.__H.__h.push(n))}function gt(a){return oa=5,$t(function(){return{current:a}},[])}function $t(a,t){var n=hn(Lt++,7);return pn(n.__H,t)&&(n.__=a(),n.__H=t,n.__h=a),n.__}function el(){for(var a;a=vn.shift();)if(a.__P&&a.__H)try{a.__H.__h.forEach(xt),a.__H.__h.forEach(ca),a.__H.__h=[]}catch(t){a.__H.__h=[],se.__e(t,a.__v)}}se.__b=function(a){fe=null,Ea&&Ea(a)},se.__=function(a,t){a&&t.__k&&t.__k.__m&&(a.__m=t.__k.__m),xa&&xa(a,t)},se.__r=function(a){Aa&&Aa(a),Lt=0;var t=(fe=a.__c).__H;t&&(jt===fe?(t.__h=[],fe.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(xt),t.__h.forEach(ca),t.__h=[],Lt=0)),jt=fe},se.diffed=function(a){Ca&&Ca(a);var t=a.__c;t&&t.__H&&(t.__H.__h.length&&(vn.push(t)!==1&&Na===se.requestAnimationFrame||((Na=se.requestAnimationFrame)||tl)(el)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),jt=fe=null},se.__c=function(a,t){t.some(function(n){try{n.__h.forEach(xt),n.__h=n.__h.filter(function(l){return!l.__||ca(l)})}catch(l){t.some(function(i){i.__h&&(i.__h=[])}),t=[],se.__e(l,n.__v)}}),Ia&&Ia(a,t)},se.unmount=function(a){Da&&Da(a);var t,n=a.__c;n&&n.__H&&(n.__H.__.forEach(function(l){try{xt(l)}catch(i){t=i}}),n.__H=void 0,t&&se.__e(t,n.__v))};var Oa=typeof requestAnimationFrame=="function";function tl(a){var t,n=function(){clearTimeout(l),Oa&&cancelAnimationFrame(t),setTimeout(a)},l=setTimeout(n,35);Oa&&(t=requestAnimationFrame(n))}function xt(a){var t=fe,n=a.__c;typeof n=="function"&&(a.__c=void 0,n()),fe=t}function ca(a){var t=fe;a.__c=a.__(),fe=t}function pn(a,t){return!a||a.length!==t.length||t.some(function(n,l){return n!==a[l]})}var al=Symbol.for("preact-signals");function Kt(){if(Le>1)Le--;else{for(var a,t=!1;dt!==void 0;){var n=dt;for(dt=void 0,da++;n!==void 0;){var l=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&gn(n))try{n.c()}catch(i){t||(a=i,t=!0)}n=l}}if(da=0,Le--,t)throw a}}function nl(a){if(Le>0)return a();Le++;try{return a()}finally{Kt()}}var Q=void 0;function mn(a){var t=Q;Q=void 0;try{return a()}finally{Q=t}}var dt=void 0,Le=0,da=0,Rt=0;function fn(a){if(Q!==void 0){var t=a.n;if(t===void 0||t.t!==Q)return t={i:0,S:a,p:Q.s,n:void 0,t:Q,e:void 0,x:void 0,r:t},Q.s!==void 0&&(Q.s.n=t),Q.s=t,a.n=t,32&Q.f&&a.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=Q.s,t.n=void 0,Q.s.n=t,Q.s=t),t}}function he(a,t){this.v=a,this.i=0,this.n=void 0,this.t=void 0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}he.prototype.brand=al;he.prototype.h=function(){return!0};he.prototype.S=function(a){var t=this,n=this.t;n!==a&&a.e===void 0&&(a.x=n,this.t=a,n!==void 0?n.e=a:mn(function(){var l;(l=t.W)==null||l.call(t)}))};he.prototype.U=function(a){var t=this;if(this.t!==void 0){var n=a.e,l=a.x;n!==void 0&&(n.x=l,a.e=void 0),l!==void 0&&(l.e=n,a.x=void 0),a===this.t&&(this.t=l,l===void 0&&mn(function(){var i;(i=t.Z)==null||i.call(t)}))}};he.prototype.subscribe=function(a){var t=this;return yt(function(){var n=t.value,l=Q;Q=void 0;try{a(n)}finally{Q=l}},{name:"sub"})};he.prototype.valueOf=function(){return this.value};he.prototype.toString=function(){return this.value+""};he.prototype.toJSON=function(){return this.value};he.prototype.peek=function(){var a=Q;Q=void 0;try{return this.value}finally{Q=a}};Object.defineProperty(he.prototype,"value",{get:function(){var a=fn(this);return a!==void 0&&(a.i=this.i),this.v},set:function(a){if(a!==this.v){if(da>100)throw new Error("Cycle detected");this.v=a,this.i++,Rt++,Le++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{Kt()}}}});function me(a,t){return new he(a,t)}function gn(a){for(var t=a.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function yn(a){for(var t=a.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){a.s=t;break}}}function _n(a){for(var t=a.s,n=void 0;t!==void 0;){var l=t.p;t.i===-1?(t.S.U(t),l!==void 0&&(l.n=t.n),t.n!==void 0&&(t.n.p=l)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=l}a.s=n}function Be(a,t){he.call(this,void 0),this.x=a,this.s=void 0,this.g=Rt-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Be.prototype=new he;Be.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===Rt))return!0;if(this.g=Rt,this.f|=1,this.i>0&&!gn(this))return this.f&=-2,!0;var a=Q;try{yn(this),Q=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return Q=a,_n(this),this.f&=-2,!0};Be.prototype.S=function(a){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}he.prototype.S.call(this,a)};Be.prototype.U=function(a){if(this.t!==void 0&&(he.prototype.U.call(this,a),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Be.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var a=this.t;a!==void 0;a=a.x)a.t.N()}};Object.defineProperty(Be.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var a=fn(this);if(this.h(),a!==void 0&&(a.i=this.i),16&this.f)throw this.v;return this.v}});function pt(a,t){return new Be(a,t)}function bn(a){var t=a.u;if(a.u=void 0,typeof t=="function"){Le++;var n=Q;Q=void 0;try{t()}catch(l){throw a.f&=-2,a.f|=8,fa(a),l}finally{Q=n,Kt()}}}function fa(a){for(var t=a.s;t!==void 0;t=t.n)t.S.U(t);a.x=void 0,a.s=void 0,bn(a)}function ll(a){if(Q!==this)throw new Error("Out-of-order effect");_n(this),Q=a,this.f&=-2,8&this.f&&fa(this),Kt()}function Ze(a,t){this.x=a,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}Ze.prototype.c=function(){var a=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{a()}};Ze.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,bn(this),yn(this),Le++;var a=Q;return Q=this,ll.bind(this,a)};Ze.prototype.N=function(){2&this.f||(this.f|=2,this.o=dt,dt=this)};Ze.prototype.d=function(){this.f|=8,1&this.f||fa(this)};Ze.prototype.dispose=function(){this.d()};function yt(a,t){var n=new Ze(a,t);try{n.c()}catch(i){throw n.d(),i}var l=n.d.bind(n);return l[Symbol.dispose]=l,l}var wn,Ft,Tt,il=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Sn=[];yt(function(){wn=this.N})();function Qe(a,t){te[a]=t.bind(null,te[a]||function(){})}function Pt(a){if(Tt){var t=Tt;Tt=void 0,t()}Tt=a&&a.S()}function Tn(a){var t=this,n=a.data,l=d(n);l.value=n;var i=$t(function(){for(var c=t,p=t.__v;p=p.__;)if(p.__c){p.__c.__$f|=4;break}var o=pt(function(){var N=l.value.value;return N===0?0:N===!0?"":N||""}),v=pt(function(){return!Array.isArray(o.value)&&!en(o.value)}),h=yt(function(){if(this.N=kn,v.value){var N=o.value;c.__v&&c.__v.__e&&c.__v.__e.nodeType===3&&(c.__v.__e.data=N)}}),f=t.__$u.d;return t.__$u.d=function(){h(),f.call(this)},[v,o]},[]),s=i[0],r=i[1];return s.value?r.peek():r.value}Tn.displayName="ReactiveTextNode";Object.defineProperties(he.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Tn},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});Qe("__b",function(a,t){if(typeof t.type=="string"){var n,l=t.props;for(var i in l)if(i!=="children"){var s=l[i];s instanceof he&&(n||(t.__np=n={}),n[i]=s,l[i]=s.peek())}}a(t)});Qe("__r",function(a,t){if(a(t),t.type!==Y){Pt();var n,l=t.__c;l&&(l.__$f&=-2,(n=l.__$u)===void 0&&(l.__$u=n=(function(i,s){var r;return yt(function(){r=this},{name:s}),r.c=i,r})(function(){var i;il&&((i=n.y)==null||i.call(n)),l.__$f|=1,l.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),Ft=l,Pt(n)}});Qe("__e",function(a,t,n,l){Pt(),Ft=void 0,a(t,n,l)});Qe("diffed",function(a,t){Pt(),Ft=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var l=t.__np,i=t.props;if(l){var s=n.U;if(s)for(var r in s){var c=s[r];c!==void 0&&!(r in l)&&(c.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=sl(n,p,v,i),s[p]=o):o.o(v,i)}}}a(t)});function sl(a,t,n,l){var i=t in a&&a.ownerSVGElement===void 0,s=me(n);return{o:function(r,c){s.value=r,l=c},d:yt(function(){this.N=kn;var r=s.value.value;l[t]!==r&&(l[t]=r,i?a[t]=r:r!=null&&(r!==!1||t[4]==="-")?a.setAttribute(t,r):a.removeAttribute(t))})}}Qe("unmount",function(a,t){if(typeof t.type=="string"){var n=t.__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=t.__c;if(r){var c=r.__$u;c&&(r.__$u=void 0,c.d())}}a(t)});Qe("__h",function(a,t,n,l){(l<3||l===9)&&(t.__$f|=2),a(t,n,l)});ct.prototype.shouldComponentUpdate=function(a,t){if(this.__R)return!0;var n=this.__$u,l=n&&n.s!==void 0;for(var i in t)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 a)if(r!=="__source"&&a[r]!==this.props[r])return!0;for(var c in this.props)if(!(c in a))return!0;return!1};function d(a,t){return $t(function(){return me(a,t)},[])}function Ht(a,t){var n=gt(a);return n.current=a,Ft.__$f|=4,$t(function(){return pt(function(){return n.current()},t)},[])}var rl=function(a){queueMicrotask(function(){queueMicrotask(a)})};function ol(){nl(function(){for(var a;a=Sn.shift();)wn.call(a)})}function kn(){Sn.push(this)===1&&(te.requestAnimationFrame||rl)(ol)}const mt=me(null),cl=pt(()=>mt.value!==null),Nn=me(900),dl=me(!1);let Ye=null;const Xe=()=>{ga()};function ul(){document.addEventListener("mousemove",Xe,{passive:!0}),document.addEventListener("keydown",Xe,{passive:!0}),document.addEventListener("click",Xe,{passive:!0}),ga()}function vl(){document.removeEventListener("mousemove",Xe),document.removeEventListener("keydown",Xe),document.removeEventListener("click",Xe),Ye!==null&&(clearTimeout(Ye),Ye=null)}function ga(){Ye!==null&&clearTimeout(Ye),Ye=setTimeout(()=>{Bt()},Nn.value*1e3)}function hl(a,t){mt.value=a,t!==void 0&&(Nn.value=t),ul(),location.hash="#/dashboard"}function Bt(){mt.value=null,vl(),location.hash="#/login"}const R={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:a=>`/v1/wallets/${a}`,SESSIONS:"/v1/sessions",SESSION:a=>`/v1/sessions/${a}`,POLICIES:"/v1/policies",POLICY:a=>`/v1/policies/${a}`,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:a=>`/v1/wallets/${a}/networks`,ADMIN_WALLET_BALANCE:a=>`/v1/admin/wallets/${a}/balance`,ADMIN_WALLET_TRANSACTIONS:a=>`/v1/admin/wallets/${a}/transactions`,ADMIN_API_KEYS:"/v1/admin/api-keys",ADMIN_API_KEY:a=>`/v1/admin/api-keys/${a}`,ADMIN_FOREX_RATES:"/v1/admin/forex/rates",ADMIN_TELEGRAM_USERS:"/v1/admin/telegram-users",ADMIN_TELEGRAM_USER:a=>`/v1/admin/telegram-users/${a}`,WALLET_OWNER:a=>`/v1/wallets/${a}/owner`,WALLET_WITHDRAW:a=>`/v1/wallets/${a}/withdraw`,WALLET_WC_PAIR:a=>`/v1/wallets/${a}/wc/pair`,WALLET_WC_SESSION:a=>`/v1/wallets/${a}/wc/session`,WALLET_WC_PAIR_STATUS:a=>`/v1/wallets/${a}/wc/pair/status`,WALLET_OWNER_VERIFY:a=>`/v1/wallets/${a}/owner/verify`,WALLET_SUSPEND:a=>`/v1/wallets/${a}/suspend`,WALLET_RESUME:a=>`/v1/wallets/${a}/resume`,ADMIN_AGENT_PROMPT:"/v1/admin/agent-prompt",ADMIN_SESSION_REISSUE:a=>`/v1/admin/sessions/${a}/reissue`,ADMIN_TRANSACTIONS:"/v1/admin/transactions",ADMIN_TX_CANCEL:a=>`/v1/admin/transactions/${a}/cancel`,ADMIN_TX_REJECT:a=>`/v1/admin/transactions/${a}/reject`,ADMIN_INCOMING:"/v1/admin/incoming",WALLET_PATCH:a=>`/v1/wallets/${a}`,TOKENS_RESOLVE:"/v1/tokens/resolve",ACTIONS_PROVIDERS:"/v1/actions/providers",ADMIN_WALLET_STAKING:a=>`/v1/admin/wallets/${a}/staking`,ADMIN_DEFI_POSITIONS:"/v1/admin/defi/positions",ADMIN_MASTER_PASSWORD:"/v1/admin/master-password"},ut=me(""),je=me(null),vt=me(!1),Ce={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)"}},pl=async a=>{if(a.preventDefault(),!!ut.value.trim()){vt.value=!0,je.value=null;try{const t=await fetch(R.ADMIN_STATUS,{headers:{"X-Master-Password":ut.value},signal:AbortSignal.timeout(1e4)});if(t.status===401){je.value="Invalid master password";return}if(!t.ok){je.value="Cannot connect to daemon";return}const n=await t.json();hl(ut.value,n.adminTimeout)}catch{je.value="Cannot connect to daemon"}finally{vt.value=!1}}};function ml(){return e("div",{style:Ce.wrapper,children:e("form",{style:Ce.card,onSubmit:pl,children:[e("h1",{style:Ce.title,children:"WAIaaS Admin"}),e("p",{style:Ce.subtitle,children:"Enter master password to continue"}),e("input",{type:"password",placeholder:"Master password",autoFocus:!0,value:ut.value,onInput:a=>{ut.value=a.target.value},style:Ce.input}),e("button",{type:"submit",disabled:vt.value,style:{...Ce.button,...vt.value?Ce.buttonDisabled:{}},children:vt.value?"Signing in...":"Sign in"}),je.value&&e("p",{style:Ce.error,children:je.value})]})})}const fl=[{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.session_ttl",label:"Session TTL (seconds)",description:"How long a session token is valid before renewal",page:"/sessions",tab:"settings",fieldName:"security.session_ttl",keywords:["session","ttl","lifetime","expiry","timeout"]},{id:"sessions.settings.session_absolute_lifetime",label:"Absolute Lifetime (seconds)",description:"Maximum total session duration regardless of renewals",page:"/sessions",tab:"settings",fieldName:"security.session_absolute_lifetime",keywords:["session","lifetime","absolute","maximum"]},{id:"sessions.settings.session_max_renewals",label:"Max Renewals",description:"Maximum number of times a session can be renewed",page:"/sessions",tab:"settings",fieldName:"security.session_max_renewals",keywords:["session","renewal","limit","maximum"]},{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:"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:"system..signing_sdk_notifications",label:"Notifications Enabled",description:"Push event notifications to wallet apps",page:"/system",tab:"",fieldName:"signing_sdk.notifications_enabled",keywords:["signing","sdk","notification","wallet","push"]}],_e=me(""),le=me(null),gl={"/wallets":"Wallets","/sessions":"Sessions","/transactions":"Transactions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"};function yl(a){if(!a.trim())return[];const t=a.toLowerCase();return fl.filter(n=>[n.label,n.description,n.keywords.join(" ")].join(" ").toLowerCase().includes(t)).slice(0,10)}function _l(a){const t=gl[a.page]??a.page;return a.tab?`${t} > ${a.tab}`:t}function bl({open:a}){const t=d(""),n=d(0),l=gt(null),i=a.value?yl(t.value):[];if(F(()=>{a.value&&(t.value="",n.value=0,requestAnimationFrame(()=>{l.current?.focus()}))},[a.value]),!a.value)return null;const s=()=>{a.value=!1,t.value="",n.value=0},r=o=>{o.target.classList.contains("search-overlay")&&s()},c=o=>{window.location.hash="#"+o.page,o.tab?le.value={tab:o.tab,fieldName:o.fieldName}:setTimeout(()=>{_e.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(),c(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:t.value,onInput:o=>{t.value=o.target.value,n.value=0}})}),e("div",{class:"search-results",children:[t.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:()=>c(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:_l(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 $e=me([]),En=pt(()=>$e.value.some(a=>typeof a.isDirty=="function"&&a.isDirty()));function Ne(a){$e.value=[...$e.value.filter(t=>t.id!==a.id),a]}function Se(a){$e.value=$e.value.filter(t=>t.id!==a)}async function wl(){const a=$e.value.filter(t=>typeof t.isDirty=="function"&&t.isDirty());try{for(const t of a)await t.save();return!0}catch{return!1}}function Sl(){const a=$e.value.filter(t=>typeof t.isDirty=="function"&&t.isDirty());for(const t of a)t.discard()}function C({label:a,name:t,type:n="text",value:l,onChange:i,options:s,error:r,required:c,disabled:p,placeholder:o,min:v,max:h,description:f}){const N=_e.value===t;if(F(()=>{if(N){const E=document.querySelector(`[name="${t}"]`);E&&E.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const y=setTimeout(()=>{_e.value=""},2500);return()=>clearTimeout(y)}},[N,t]),n==="checkbox")return e("div",{class:`form-field${N?" form-field--highlight":""}`,children:[e("label",{children:[e("input",{type:"checkbox",name:t,checked:!!l,onChange:E=>i(E.target.checked),disabled:p}),a,c&&e("span",{children:" *"})]}),f&&e("span",{class:"form-description",children:f}),r&&e("span",{class:"form-error",children:r})]});const P=`field-${t}`;return e("div",{class:`form-field${N?" form-field--highlight":""}`,children:[e("label",{for:P,children:[a,c&&e("span",{children:" *"})]}),n==="select"?e("select",{id:P,name:t,value:l,onChange:E=>i(E.target.value),disabled:p,children:s?.map(E=>e("option",{value:E.value,children:E.label},E.value))}):n==="textarea"?e("textarea",{id:P,name:t,value:l,onInput:E=>i(E.target.value),disabled:p,placeholder:o}):e("input",{id:P,type:n,name:t,value:l,onInput:E=>{const y=E.target;i(n==="number"?Number(y.value):y.value)},disabled:p,placeholder:o,min:v,max:h,required:c}),f&&e("span",{class:"form-description",children:f}),r&&e("span",{class:"form-error",children:r})]})}function M({variant:a="primary",size:t="md",loading:n=!1,disabled:l=!1,onClick:i,children:s,type:r="button"}){const c=["btn",`btn-${a}`,t==="sm"?"btn-sm":""].filter(Boolean).join(" ");return e("button",{type:r,class:c,disabled:l||n,onClick:i,children:n?"...":s})}function B({variant:a,children:t}){return e("span",{class:`badge badge-${a}`,children:t})}const rt=me(null),nt=me(!1);function An(a){rt.value=a}function Tl(){const a=rt.value;if(!a)return null;const t=async()=>{nt.value=!0;const i=await wl();nt.value=!1,i&&(rt.value=null,a.execute())},n=()=>{Sl(),rt.value=null,a.execute()},l=()=>{rt.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:nt.value,children:"Cancel"}),e(M,{variant:"ghost",onClick:n,disabled:nt.value,children:"Discard & Navigate"}),e(M,{variant:"primary",onClick:t,loading:nt.value,children:"Save & Navigate"})]})]})})}class _ extends Error{constructor(t,n,l){super(`[${t}] ${n}: ${l}`),this.status=t,this.code=n,this.serverMessage=l,this.name="ApiError"}}async function _t(a,t){const n={"Content-Type":"application/json",...t?.headers};mt.value!==null&&(n["X-Master-Password"]=mt.value);let l;try{l=await fetch(a,{...t,headers:n,signal:AbortSignal.timeout(1e4)})}catch(i){const s=i;throw s.name==="AbortError"||s.name==="TimeoutError"?new _(0,"TIMEOUT","Request timed out"):new _(0,"NETWORK_ERROR","Cannot connect to daemon")}if(l.status===401)throw a.startsWith("/v1/admin/")&&Bt(),new _(401,"UNAUTHORIZED","Authentication failed");if(!l.ok){let i={};try{i=await l.json()}catch{}throw new _(l.status,i.code??"UNKNOWN",i.message??"Unknown error")}return ga(),await l.json()}const V=a=>_t(a,{method:"GET"}),ie=(a,t)=>_t(a,{method:"POST",body:t?JSON.stringify(t):void 0}),ve=(a,t)=>_t(a,{method:"PUT",body:t?JSON.stringify(t):void 0}),Ke=(a,t)=>_t(a,{method:"DELETE",body:t?JSON.stringify(t):void 0}),kl=(a,t)=>_t(a,{method:"PATCH",body:t?JSON.stringify(t):void 0});function Nl(a){const t=Math.floor(a/86400),n=Math.floor(a%86400/3600),l=Math.floor(a%3600/60);return t>0?`${t}d ${n}h ${l}m`:n>0?`${n}h ${l}m`:`${l}m`}function ue(a){const t=new Date(a*1e3),n=l=>l.toString().padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function Mt(a){return a.length<=10?a:`${a.slice(0,4)}..${a.slice(-4)}`}const El=new Set(["KRW","JPY","VND","CLP","HUF","PKR"]),Al=new Set(["KWD","BHD"]);function Cl(a){return El.has(a)?0:Al.has(a)?3:2}function Il(a,t,n){const l=a*n,i=Cl(t),s=new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:i,maximumFractionDigits:i}).format(l);return t==="USD"?s:`≈${s}`}let ze=null;const Dl=300*1e3;async function Vt(){if(ze&&Date.now()-ze.fetchedAt<Dl)return{currency:ze.currency,rate:ze.rate};try{const t=(await V(R.ADMIN_SETTINGS)).display?.["display.currency"]??"USD";if(t==="USD")return ze={currency:"USD",rate:1,fetchedAt:Date.now()},{currency:"USD",rate:1};const i=(await V(`${R.ADMIN_FOREX_RATES}?currencies=${t}`)).rates[t]?.rate??null;return ze={currency:t,rate:i,fetchedAt:Date.now()},{currency:t,rate:i}}catch{return{currency:"USD",rate:1}}}function Fe(a,t,n){return a==null?"":n==null?`$${a.toFixed(2)}`:Il(a,t,n)}function He({columns:a,data:t,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:a.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:a.length,class:"table-loading",children:"Loading..."})}):!t||t.length===0?e("tr",{children:e("td",{colSpan:a.length,class:"table-empty",children:l})}):t.map((s,r)=>e("tr",{class:n?"clickable":"",onClick:n?()=>n(s):void 0,children:a.map(c=>e("td",{children:c.render?c.render(s):s[c.key]},c.key))},r))})]})})}const xl={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."},Ol=new Set(["ACTION_VALIDATION_FAILED","CONSTRAINT_VIOLATED","INVALID_ADDRESS","INVALID_SIGNATURE"]);function W(a,t){return t&&Ol.has(a)?t:xl[a]??`An error occurred (${a}).`}const xe=me([]);let Ll=0;function T(a,t){const n=Ll++;xe.value=[...xe.value,{id:n,type:a,message:t}],setTimeout(()=>{xe.value=xe.value.filter(l=>l.id!==n)},5e3)}function Rl(a){xe.value=xe.value.filter(t=>t.id!==a)}function Pl(){return xe.value.length===0?null:e("div",{class:"toast-container",children:xe.value.map(a=>e("div",{class:`toast toast-${a.type}`,onClick:()=>Rl(a.id),children:a.message},a.id))})}const Ml={mainnet:"https://solscan.io/tx/{txHash}",devnet:"https://solscan.io/tx/{txHash}?cluster=devnet",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 Ul(a,t){const n=Ml[a];return n?n.replace("{txHash}",t):null}function Wl(a){return a.length<=16?a:a.slice(0,8)+"..."+a.slice(-6)}function ya({network:a,txHash:t,label:n}){if(!t)return null;const l=Ul(a,t),i=n??Wl(t);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 ye({label:a,value:t,loading:n,badge:l,href:i}){const s=e(Y,{children:[e("div",{class:"stat-label",children:[a,i&&e("span",{class:"stat-link-arrow",children:" →"})]}),n?e("div",{class:"stat-skeleton"}):l?e(B,{variant:l,children:t}):e("div",{class:"stat-value",children:t})]});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 $l(a,t){return[{key:"createdAt",header:"Time",render:n=>n.createdAt?ue(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=Fe(n.amountUsd,a,t);return l?`${n.amount} (${l})`:n.amount}},{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(B,{variant:l,children:n.status})}},{key:"txHash",header:"Tx Hash",render:n=>e(ya,{network:n.network??"",txHash:n.txHash})}]}function Kl(a,t){return[{key:"provider",header:"Provider"},{key:"category",header:"Category",render:n=>e(B,{variant:"info",children:n.category})},{key:"chain",header:"Chain",render:n=>e(B,{variant:"info",children:n.chain})},{key:"amount",header:"Amount"},{key:"amountUsd",header:"USD Value",render:n=>n.amountUsd===null?"—":Fe(n.amountUsd,a,t)??`$${n.amountUsd.toFixed(2)}`}]}async function Fl(a){try{await navigator.clipboard.writeText(a)}catch{const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}}function La(){const a=d(null),t=d(!0),n=d(null),l=d("USD"),i=d(1),s=d(!1),r=d(null),c=d(null),p=d(null),o=d(!0),v=async()=>{o.value=!0;try{const E=await V(R.ADMIN_DEFI_POSITIONS);p.value=E}catch{}finally{o.value=!1}},h=async()=>{t.value=!0,n.value=null;try{const E=await V(R.ADMIN_STATUS);a.value=E}catch(E){E instanceof _?n.value=W(E.code):n.value="An unexpected error occurred."}finally{t.value=!1}},f=async()=>{s.value=!0;try{const E=await ie(R.ADMIN_AGENT_PROMPT,{});if(E.walletCount===0){T("warning","No active wallets found");return}r.value=E.prompt,T("success",`Prompt generated for ${E.walletCount} wallet(s)`)}catch(E){E instanceof _?T("error",W(E.code)):T("error","Failed to generate agent prompt")}finally{s.value=!1}},N=async()=>{r.value&&(await Fl(r.value),T("success","Copied to clipboard!"))};F(()=>{h(),v(),Vt().then(({currency:y,rate:D})=>{l.value=y,i.value=D}).catch(()=>{}),V(R.ADMIN_TRANSACTIONS+"?status=APPROVED&limit=1").then(y=>{c.value=y.total}).catch(()=>{});const E=setInterval(()=>{h(),v()},3e4);return()=>clearInterval(E)},[]);const P=t.value&&!a.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:h,children:"Retry"})]}),a.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:"})," ",a.value.version," ","→"," ",a.value.latestVersion," — ","Run ",e("code",{children:"waiaas update"})," to update."]})]}),a.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:a.value?.version??"—",loading:P,badge:a.value&&a.value.updateAvailable?"warning":void 0}),e(ye,{label:"Uptime",value:a.value?Nl(a.value.uptime):"—",loading:P}),e(ye,{label:"Wallets",value:a.value?.walletCount?.toString()??"—",loading:P,href:"#/wallets"}),e(ye,{label:"Active Sessions",value:a.value?.activeSessionCount?.toString()??"—",loading:P,href:"#/sessions"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ye,{label:"Kill Switch",value:a.value?.killSwitchState==="ACTIVATED"?"ACTIVATED":"NORMAL",loading:P,badge:a.value?a.value.killSwitchState==="ACTIVATED"?"danger":"success":void 0}),e(ye,{label:"Status",value:a.value?.status??"—",loading:P})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ye,{label:"Policies",value:a.value?.policyCount?.toString()??"—",loading:P,href:"#/policies"}),e(ye,{label:"Recent Txns (24h)",value:a.value?.recentTxCount?.toString()??"—",loading:P,href:"#/transactions"}),e(ye,{label:"Failed Txns (24h)",value:a.value?.failedTxCount?.toString()??"—",loading:P,badge:a.value?a.value.failedTxCount===0?"success":"danger":void 0,href:"#/transactions?status=FAILED"}),e(ye,{label:"Approval Pending",value:c.value?.toString()??"—",loading:P,badge:c.value!=null&&c.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(Y,{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:N,children:"Copy to Clipboard"}),e(M,{variant:"secondary",size:"sm",onClick:f,loading:s.value,children:"Regenerate"})]})]}):e(M,{variant:"primary",size:"sm",onClick:f,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?Fe(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(He,{columns:Kl(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(He,{columns:$l(l.value,i.value),data:a.value?.recentTransactions??[],loading:P,emptyMessage:"No recent transactions"})]})]})}function be({open:a,title:t,children:n,onConfirm:l,onCancel:i,confirmText:s="Confirm",cancelText:r="Cancel",confirmVariant:c="primary",confirmDisabled:p=!1,loading:o=!1}){return F(()=>{if(!a)return;const v=h=>{h.key==="Escape"&&i()};return document.addEventListener("keydown",v),()=>document.removeEventListener("keydown",v)},[a,i]),a?e("div",{class:"modal-overlay",onClick:i,children:e("div",{class:"modal-card",onClick:v=>v.stopPropagation(),children:[e("div",{class:"modal-header",children:t}),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:c,onClick:l,loading:o,disabled:p,children:s})]})]})}):null}function ft({value:a,label:t}){const n=d(!1);return e("button",{class:"btn btn-ghost btn-sm",onClick:async()=>{try{await navigator.clipboard.writeText(a)}catch{const i=document.createElement("textarea");i.value=a,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!":t??"Copy"})}function Ra({title:a,description:t,actionLabel:n,onAction:l}){return e("div",{class:"empty-state",children:[e("h3",{children:a}),t&&e("p",{children:t}),n&&l&&e("button",{class:"btn btn-primary",onClick:l,children:n})]})}function Ve({tabs:a,activeTab:t,onTabChange:n}){return e("div",{class:"tab-nav",children:a.map(l=>e("button",{class:`tab-btn ${t===l.key?"active":""}`,onClick:()=>{l.key!==t&&(En.value?An({type:"tab",execute:()=>n(l.key)}):n(l.key))},children:l.label},l.key))})}function et({pageName:a,tabName:t,onPageClick:n}){return t?e("nav",{class:"breadcrumb","aria-label":"Breadcrumb",children:[e("button",{class:"breadcrumb-page",onClick:n,type:"button",children:a}),e("span",{class:"breadcrumb-separator","aria-hidden":"true",children:">"}),e("span",{class:"breadcrumb-current","aria-current":"page",children:t})]}):null}function Cn({value:a,onSearch:t,placeholder:n="Search...",debounceMs:l=300}){const i=gt(null);function s(c){const p=c.target.value;i.current!==null&&clearTimeout(i.current),i.current=setTimeout(()=>{t(p),i.current=null},l)}function r(){i.current!==null&&(clearTimeout(i.current),i.current=null),t("")}return e("div",{class:"search-input",children:[e("input",{type:"text",value:a,placeholder:n,onInput:s}),a&&e("button",{class:"search-clear",type:"button",onClick:r,children:"x"})]})}function Hl(){const a=window.location.hash,t=a.indexOf("?");if(t===-1)return{};const n=new URLSearchParams(a.slice(t+1)),l={};return n.forEach((i,s)=>{l[s]=i}),l}function Pa(a){const t=window.location.hash,n=t.indexOf("?"),l=n===-1?t:t.slice(0,n),i=new URLSearchParams;for(const[c,p]of Object.entries(a))p&&i.set(c,p);const s=i.toString(),r=s?`${l}?${s}`:l;window.history.replaceState(null,"",r)}function Gt({fields:a,values:t,onChange:n,syncUrl:l=!0}){F(()=>{if(!l)return;const r=Hl(),c={...t};let p=!1;for(const o of a){const v=r[o.key];v!==void 0&&v!==c[o.key]&&(c[o.key]=v,p=!0)}p&&n(c)},[]);function i(r,c){const p={...t,[r]:c};n(p),l&&Pa(p)}function s(){const r={};for(const c of a)r[c.key]="";n(r),l&&Pa(r)}return e("div",{class:"filter-bar",children:[a.map(r=>e("div",{class:"filter-field",children:[e("label",{children:r.label}),r.type==="select"?e("select",{value:t[r.key]??"",onChange:c=>i(r.key,c.target.value),children:[e("option",{value:"",children:"All"}),r.options?.map(c=>e("option",{value:c.value,children:c.label},c.value))]}):e("input",{type:"date",value:t[r.key]??"",placeholder:r.placeholder,onChange:c=>i(r.key,c.target.value)})]},r.key)),e("button",{class:"btn btn-secondary filter-clear",type:"button",onClick:s,children:"Clear"})]})}const Bl=new Set(["notifications.telegram_bot_token","notifications.discord_webhook_url","notifications.slack_webhook_url","telegram.bot_token"]);function Vl(a){return Bl.has(a)}function G(a){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",session_ttl:"Session TTL (seconds)",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",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",session_absolute_lifetime:"Absolute Lifetime (seconds)",session_max_renewals:"Max Renewals",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",poll_interval_sec:"Poll Interval (seconds)",default_timeout_sec:"Default Timeout (seconds)",max_timeout_sec:"Max Timeout (seconds)",max_pending_count:"Max Pending Count"}[a]??a.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function ee(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i];const s=a[n];if(!s)return"";const r=s[l];return typeof r=="boolean"?Vl(i)?"":String(r):r??""}function Oe(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i]==="true";const s=a[n];if(!s)return!1;const r=s[l];return typeof r=="boolean"?r:r==="true"}function ot(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return!1;const s=a[n];return s?s[l]===!0:!1}const kt=[{value:"dcent",label:"D'CENT Wallet",description:"Hardware wallet with WalletConnect signing"}];function In(a){switch(a){case"NONE":return"neutral";case"GRACE":return"warning";case"LOCKED":return"success";default:return"neutral"}}function oe({label:a,value:t,copy:n,children:l}){return e("div",{class:"detail-row",children:[e("div",{class:"detail-row-label",children:a}),e("div",{class:"detail-row-value",children:[l??t??"—",n&&t&&e(ft,{value:t})]})]})}const Gl=[{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 System > Signing SDK settings.",warningCondition:a=>!a?.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 System > Signing SDK and Notifications > Telegram settings.",warningCondition:a=>!a?.signingEnabled||!a?.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:a=>!a?.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:a=>!a?.telegramBotConfigured},{value:"rest",label:"REST API",description:"Manual approval via REST API endpoints (POST /approve, /reject)"}],zl=[{key:"overview",label:"Overview"},{key:"transactions",label:"Transactions"},{key:"owner",label:"Owner"},{key:"staking",label:"Staking"},{key:"mcp",label:"MCP"}],lt=20,ql=[{value:"PENDING",label:"PENDING"},{value:"APPROVED",label:"APPROVED"},{value:"SUBMITTED",label:"SUBMITTED"},{value:"CONFIRMED",label:"CONFIRMED"},{value:"FAILED",label:"FAILED"}],jl=[{value:"TRANSFER",label:"TRANSFER"},{value:"TOKEN_TRANSFER",label:"TOKEN_TRANSFER"},{value:"CONTRACT_CALL",label:"CONTRACT_CALL"},{value:"APPROVE",label:"APPROVE"},{value:"BATCH",label:"BATCH"}],Yl=[{key:"status",label:"Status",type:"select",options:ql},{key:"type",label:"Type",type:"select",options:jl}],Yt=["Time","Type","To","Amount","Network","Status","Tx Hash"];function Xl(a){return a==="CONFIRMED"?"success":a==="FAILED"?"danger":"warning"}function Jl({id:a}){const t=d(null),n=d(!0),l=d(!1),i=d(""),s=d(!1),r=d(!1),c=d(!1),p=d(!1),o=d(null),v=d([]),h=d(!0),f=d(null),N=d(!0),P=d([]),E=d(!0),y=d(0),D=d(0),U=d({status:"",type:""}),K=d(!1),I=d(null),A=d(!1),k=d(null),u=d(!0),m=d(!1),S=d(null),g=d(!1),O=d(""),$=d(!1),q=d(""),H=d(null),J=d(!1),ce=d(!1),pe=d(""),re=d(!1),ne=d("overview"),we=d("USD"),Pe=d(1),Ee=d([]),Ae=d(!0),Te=async()=>{try{const b=await V(R.WALLET(a));t.value=b}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{n.value=!1}},tt=async()=>{s.value=!0;try{const b=await ve(R.WALLET(a),{name:i.value});t.value=b,l.value=!1,T("success","Wallet name updated")}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{s.value=!1}},L=async()=>{c.value=!0;try{await Ke(R.WALLET(a)),T("success","Wallet terminated"),window.location.hash="#/wallets"}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{c.value=!1}},ae=async()=>{ce.value=!0;try{await ie(R.WALLET_SUSPEND(a),{reason:pe.value.trim()||void 0}),T("success","Wallet suspended"),J.value=!1,pe.value="",await Te()}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{ce.value=!1}},ge=async()=>{re.value=!0;try{await ie(R.WALLET_RESUME(a)),T("success","Wallet resumed"),await Te()}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{re.value=!1}},zt=()=>{i.value=t.value.name,l.value=!0},qt=()=>{l.value=!1},w=async()=>{p.value=!0;try{const b=await ie(R.MCP_TOKENS,{walletId:a});o.value=b,T("success","MCP token provisioned successfully")}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{p.value=!1}},x=async()=>{h.value=!0;try{const b=await V(R.WALLET_NETWORKS(a));v.value=b.availableNetworks??[]}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code)),v.value=[]}finally{h.value=!1}},Z=async()=>{N.value=!0;try{f.value=await V(R.ADMIN_WALLET_BALANCE(a))}catch{f.value=null}finally{N.value=!1}},de=async b=>{E.value=!0;try{const X=(b??D.value)*lt,wt=await V(`${R.ADMIN_WALLET_TRANSACTIONS(a)}?offset=${X}&limit=${lt}`);P.value=wt.items,y.value=wt.total}catch{P.value=[],y.value=0}finally{E.value=!1}},Me=Ht(()=>{let b=P.value;const z=U.value;return z.status&&(b=b.filter(X=>X.status===z.status)),z.type&&(b=b.filter(X=>X.type===z.type)),b}),Ge=async()=>{Ae.value=!0;try{const b=await V(R.ADMIN_WALLET_STAKING(a));Ee.value=b.positions??[]}catch{Ee.value=[]}finally{Ae.value=!1}},j=async()=>{u.value=!0;try{k.value=await V(R.WALLET_WC_SESSION(a))}catch{k.value=null}finally{u.value=!1}},at=()=>{S.value&&clearInterval(S.value),S.value=setInterval(async()=>{try{const b=await V(R.WALLET_WC_PAIR_STATUS(a));b.status==="connected"?(S.value&&clearInterval(S.value),S.value=null,K.value=!1,I.value=null,k.value=b.session??null,T("success","Wallet connected via WalletConnect")):(b.status==="expired"||b.status==="none")&&(S.value&&clearInterval(S.value),S.value=null,K.value=!1,I.value=null,T("error","Pairing expired. Try again."))}catch{}},3e3)},bt=async()=>{A.value=!0;try{const b=await ie(R.WALLET_WC_PAIR(a));I.value=b,K.value=!0,at()}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");z.code==="WC_NOT_CONFIGURED"?(T("error","WalletConnect is not configured. Redirecting to settings..."),le.value={tab:"walletconnect",fieldName:"walletconnect.project_id"},window.location.hash="#/wallets"):T("error",W(z.code))}finally{A.value=!1}},On=async()=>{m.value=!0;try{await Ke(R.WALLET_WC_SESSION(a)),k.value=null,T("success","WalletConnect session disconnected")}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code))}finally{m.value=!1}},_a=()=>{O.value=t.value?.ownerAddress??"",q.value=t.value?.walletType??"",g.value=!0},Ln=()=>{g.value=!1},Rn=async()=>{if(!O.value.trim()){T("error","Owner address is required");return}$.value=!0;try{const b={owner_address:O.value.trim()};q.value&&(b.wallet_type=q.value),await ve(R.WALLET_OWNER(a),b),await Te(),g.value=!1;const z=kt.find(X=>X.value===q.value);z?T("success",`Owner set with ${z.label} auto-setup`):T("success","Owner address updated")}catch(b){const z=b instanceof _?b:new _(0,"UNKNOWN","Unknown error");T("error",W(z.code,z.serverMessage))}finally{$.value=!1}},Pn=async()=>{try{const b=await V(R.ADMIN_SETTINGS),z=b.signing_sdk?.enabled==="true",X=b.telegram?.bot_token===!0,wt=!!b.walletconnect?.project_id&&b.walletconnect.project_id!=="";H.value={signingEnabled:z,telegramBotConfigured:X,wcConfigured:wt}}catch{}},Mn=async b=>{try{await ve(R.WALLET_OWNER(a),{owner_address:t.value.ownerAddress,approval_method:b??null}),await Te(),T("success","Approval method updated")}catch(z){const X=z instanceof _?z:new _(0,"UNKNOWN","Unknown error");T("error",W(X.code,X.serverMessage))}};F(()=>{Te(),x(),Z(),de(),j(),Ge(),Pn(),Vt().then(({currency:b,rate:z})=>{we.value=b,Pe.value=z}).catch(()=>{})},[a]),F(()=>()=>{S.value&&clearInterval(S.value)},[]),F(()=>{de()},[D.value]);const ba=D.value*lt,Un=y.value>0?ba+1:0,Wn=Math.min(ba+lt,y.value),$n=D.value>0,Kn=(D.value+1)*lt<y.value;function Fn(){return t.value?e(Y,{children:[e("div",{class:"detail-grid",children:[e(oe,{label:"ID",value:t.value.id,copy:!0}),e(oe,{label:"Public Key",value:t.value.publicKey,copy:!0}),e(oe,{label:"Chain",value:t.value.chain}),e(oe,{label:"Environment",children:e(B,{variant:t.value.environment==="mainnet"?"warning":"info",children:t.value.environment})}),e(oe,{label:"Status",children:e(B,{variant:t.value.status==="ACTIVE"?"success":t.value.status==="SUSPENDED"?"warning":"danger",children:t.value.status})}),t.value.status==="SUSPENDED"&&e(Y,{children:[e(oe,{label:"Suspended At",value:t.value.suspendedAt?ue(t.value.suspendedAt):"--"}),e(oe,{label:"Suspension Reason",value:t.value.suspensionReason??"--"})]}),e(oe,{label:"Created",value:ue(t.value.createdAt)}),e(oe,{label:"Updated",value:t.value.updatedAt?ue(t.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:Z,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(b=>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:b.network})}),b.error?e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:b.error}):b.native?e("div",{children:[e(oe,{label:"Native",children:e("span",{children:[b.native.balance," ",b.native.symbol,b.native.usd!=null&&e("span",{style:{color:"var(--color-text-secondary)",marginLeft:"var(--space-2)",fontSize:"0.85rem"},children:["(",Fe(b.native.usd,we.value,Pe.value),")"]})]})}),b.tokens.length>0?b.tokens.map(z=>e(oe,{label:z.symbol,value:z.balance},z.address)):null]}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Balance unavailable"})]},b.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(b=>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:b.name??b.network})},b.network))})]})]}):null}function Hn(){return e(Y,{children:[e(Gt,{fields:Yl,values:U.value,onChange:b=>{U.value=b},syncUrl:!1}),e("div",{class:"table-container",style:{marginTop:"var(--space-3)"},children:e("table",{children:[e("thead",{children:e("tr",{children:Yt.map(b=>e("th",{children:b},b))})}),e("tbody",{children:E.value&&Me.value.length===0?e("tr",{children:e("td",{colSpan:Yt.length,class:"table-loading",children:"Loading..."})}):Me.value.length===0?e("tr",{children:e("td",{colSpan:Yt.length,class:"table-empty",children:"No transactions yet"})}):Me.value.map(b=>e("tr",{children:[e("td",{children:b.createdAt?ue(b.createdAt):"—"}),e("td",{children:e(B,{variant:"info",children:b.type})}),e("td",{children:b.toAddress?Mt(b.toAddress):"—"}),e("td",{children:b.amount?b.formattedAmount??b.amount:"—"}),e("td",{children:b.network??"—"}),e("td",{children:e(B,{variant:Xl(b.status),children:b.status})}),e("td",{children:e(ya,{network:b.network??"",txHash:b.txHash})})]},b.id))})]})}),e("div",{class:"pagination",style:{marginTop:"var(--space-3)"},children:[e("span",{class:"pagination-info",children:["Showing ",Un,"-",Wn," of ",y.value]}),e("div",{class:"pagination-buttons",children:[e(M,{variant:"secondary",size:"sm",disabled:!$n,onClick:()=>{D.value=D.value-1},children:"Previous"}),e(M,{variant:"secondary",size:"sm",disabled:!Kn,onClick:()=>{D.value=D.value+1},children:"Next"})]})]})]})}function Bn(){return t.value?e("div",{class:"owner-section",children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Owner Wallet"}),t.value.ownerState==="NONE"&&t.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:_a,children:"Set Owner Address"})]}),g.value&&t.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:q.value,onChange:b=>{q.value=b.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)"}),kt.map(b=>e("option",{value:b.value,children:b.label},b.value))]}),q.value&&e("p",{style:{marginTop:"var(--space-1)",fontSize:"0.8rem",color:"var(--color-text-secondary)"},children:kt.find(b=>b.value===q.value)?.description})]}),e(oe,{label:"Address",children:g.value?e("div",{class:"inline-edit",children:[e("input",{value:O.value,onInput:b=>{O.value=b.target.value},class:"inline-edit-input",placeholder:"Enter owner wallet address"}),e(M,{size:"sm",onClick:Rn,loading:$.value,children:"Save"}),e(M,{size:"sm",variant:"secondary",onClick:Ln,children:"Cancel"})]}):e("span",{children:[t.value.ownerAddress?e(Y,{children:[Mt(t.value.ownerAddress),e(ft,{value:t.value.ownerAddress})]}):"Not set",t.value.ownerState!=="LOCKED"&&t.value.status==="ACTIVE"&&e("button",{class:"btn btn-ghost btn-sm",onClick:_a,title:"Set owner address",children:"✎"})]})}),e(oe,{label:"State",children:[e(B,{variant:In(t.value.ownerState),children:t.value.ownerState}),t.value.walletType&&e(B,{variant:"info",style:{marginLeft:"var(--space-2)"},children:kt.find(b=>b.value===t.value.walletType)?.label??t.value.walletType})]}),t.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."})]}),t.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:Gl.map(b=>e("label",{style:{display:"flex",alignItems:"flex-start",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",background:t.value?.approvalMethod===b.value?"var(--color-bg-secondary)":"transparent",borderRadius:"var(--radius-md)",cursor:"pointer"},children:[e("input",{type:"radio",name:"approval_method",value:b.value??"",checked:t.value?.approvalMethod===b.value,onChange:()=>Mn(b.value),style:{marginTop:"2px"}}),e("div",{children:[e("div",{style:{fontWeight:500,fontSize:"0.9rem"},children:b.label}),e("div",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:b.description}),b.warning&&b.warningCondition?.(H.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:b.warning})]})]},b.value??"auto"))})]}),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"}),u.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):k.value?e("div",{children:[e(oe,{label:"Status",children:e(B,{variant:"success",children:"Connected"})}),e(oe,{label:"Peer",value:k.value.peerName??"Unknown"}),e(oe,{label:"Chain ID",value:k.value.chainId}),e(oe,{label:"Expires",value:ue(k.value.expiry)}),e("div",{style:{marginTop:"var(--space-3)"},children:e(M,{variant:"danger",onClick:On,loading:m.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."}),t.value?.ownerAddress?e(M,{onClick:bt,loading:A.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 Vn(){function b(X){return X==="lido"?"info":"neutral"}function z(X){return X==="COMPLETED"?"success":X==="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:Ge,loading:Ae.value,children:"Refresh"})]}),Ae.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):Ee.value.length===0?e(Ra,{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(X=>e("tr",{children:[e("td",{children:e(B,{variant:b(X.protocol),children:X.protocol==="lido"?"Lido":"Jito"})}),e("td",{children:X.asset}),e("td",{children:X.chain==="ethereum"?`${(Number(X.balance)/1e18).toFixed(6)} stETH`:`${(Number(X.balance)/1e9).toFixed(6)} JitoSOL`}),e("td",{children:X.balanceUsd?Fe(Number(X.balanceUsd),we.value,Pe.value):"—"}),e("td",{children:X.apy??"—"}),e("td",{children:X.pendingUnstake?e("span",{style:{display:"flex",alignItems:"center",gap:"var(--space-2)"},children:[e(B,{variant:z(X.pendingUnstake.status),children:X.pendingUnstake.status}),e("span",{style:{fontSize:"0.85em",color:"var(--color-text-secondary)"},children:X.chain==="ethereum"?`${(Number(X.pendingUnstake.amount)/1e18).toFixed(4)} stETH`:`${(Number(X.pendingUnstake.amount)/1e9).toFixed(4)} JitoSOL`})]}):"—"})]},`${X.protocol}-${X.chain}`))})]})})]})}function Gn(){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(oe,{label:"Token Path",value:o.value.tokenPath}),e(oe,{label:"Expires At",value:ue(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(ft,{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:w,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:w,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)"}}):t.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:b=>{i.value=b.target.value},class:"inline-edit-input"}),e(M,{size:"sm",onClick:tt,loading:s.value,children:"Save"}),e(M,{size:"sm",variant:"secondary",onClick:qt,children:"Cancel"})]}):e("span",{children:[t.value.name,e("button",{class:"btn btn-ghost btn-sm",onClick:zt,title:"Edit name",children:"✎"})]})}),e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[t.value.status==="ACTIVE"&&e(M,{variant:"secondary",onClick:()=>{J.value=!0},children:"Suspend Wallet"}),t.value.status==="SUSPENDED"&&e(M,{variant:"primary",onClick:ge,loading:re.value,children:"Resume Wallet"}),t.value.status!=="TERMINATED"&&e(M,{variant:"danger",onClick:()=>{r.value=!0},children:"Terminate Wallet"})]})]}),e(Ve,{tabs:zl,activeTab:ne.value,onTabChange:b=>{ne.value=b}}),ne.value==="overview"&&e(Fn,{}),ne.value==="transactions"&&e(Hn,{}),ne.value==="owner"&&e(Bn,{}),ne.value==="staking"&&e(Vn,{}),ne.value==="mcp"&&e(Gn,{}),e(be,{open:r.value,title:"Terminate Wallet",onCancel:()=>{r.value=!1},onConfirm:L,confirmText:"Terminate",confirmVariant:"danger",loading:c.value,children:e("p",{children:["Are you sure you want to terminate wallet ",e("strong",{children:t.value.name}),"? This action cannot be undone."]})}),e(be,{open:K.value,title:"Scan QR Code",onCancel:()=>{K.value=!1,S.value&&clearInterval(S.value),S.value=null},children:I.value&&e("div",{style:{textAlign:"center"},children:[e("img",{src:I.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(be,{open:J.value,title:"Suspend Wallet",onCancel:()=>{J.value=!1,pe.value=""},onConfirm:ae,confirmText:"Suspend",confirmVariant:"danger",loading:ce.value,children:[e("p",{style:{marginBottom:"var(--space-3)"},children:["Are you sure you want to suspend wallet ",e("strong",{children:t.value.name}),"? Suspended wallets cannot process transactions until resumed."]}),e(C,{label:"Reason (optional)",name:"suspend-reason",value:pe.value,onChange:b=>{pe.value=b},placeholder:"e.g. suspicious activity"})]})]}):e(Ra,{title:"Wallet not found",description:"The wallet may have been deleted."})]})}const Zl={mainnet:"Solana Mainnet",devnet:"Solana Devnet",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"},qe=["mainnet","devnet","testnet"],it=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia"];function Ql(a){if(a<=0)return"";const t=Math.ceil(a/1e3);if(t<60)return`${t}s`;const n=Math.floor(t/60),l=t%60;return l>0?`${n}m ${l}s`:`${n}m`}function ei(a){return qe.includes(a)?"solana":"evm"}function ti(){const a=d({}),t=d({}),n=d({}),l=d(!1),i=d(!0),s=d({}),r=d({}),c=d({}),p=d({}),o=d({}),v=d({}),h=(m,S)=>{const g={},O=[...qe,...it];for(const $ of O){const q=[],H=m.rpc_pool;if(H){const re=H[$];if(typeof re=="string"&&re!=="[]")try{const ne=JSON.parse(re);Array.isArray(ne)&&q.push(...ne.filter(we=>typeof we=="string"&&we.length>0))}catch{}}const J=S[$]??[],ce=new Set(q),pe=[];for(const re of q)pe.push({url:re,isBuiltin:J.includes(re),enabled:!0});for(const re of J)ce.has(re)||pe.push({url:re,isBuiltin:!0,enabled:!0});g[$]=pe}return g},f=async()=>{try{try{const g=await V(R.ADMIN_RPC_STATUS);g.builtinUrls&&(p.value=g.builtinUrls),c.value=g.networks??{}}catch{}const m=await V(R.ADMIN_SETTINGS);a.value=m;const S=h(m,p.value);n.value=S,t.value=JSON.parse(JSON.stringify(S))}catch(m){const S=m instanceof _?m:new _(0,"UNKNOWN","Unknown error");T("error",W(S.code))}finally{i.value=!1}};F(()=>{f()},[]),F(()=>{const m=async()=>{try{const g=await V(R.ADMIN_RPC_STATUS);c.value=g.networks??{},g.builtinUrls&&(p.value=g.builtinUrls)}catch{}};m();const S=setInterval(m,15e3);return()=>clearInterval(S)},[]);const N=async(m,S)=>{const g=`${m}:${S}`;o.value={...o.value,[g]:!0};try{const O=await ie(R.ADMIN_SETTINGS_TEST_RPC,{url:S,chain:ei(m)});v.value={...v.value,[g]:O}}catch{v.value={...v.value,[g]:{success:!1,latencyMs:0,error:"Request failed"}}}finally{o.value={...o.value,[g]:!1}}},P=()=>{for(const m of[...qe,...it]){const S=n.value[m]??[],g=t.value[m]??[];if(S.length!==g.length)return!0;for(let O=0;O<S.length;O++)if(S[O].url!==g[O].url||S[O].enabled!==g[O].enabled)return!0}return!1},E=Ht(()=>{let m=0;for(const S of[...qe,...it]){const g=n.value[S]??[],O=t.value[S]??[];if(g.length!==O.length){m++;continue}for(let $=0;$<g.length;$++)if(g[$].url!==O[$].url||g[$].enabled!==O[$].enabled){m++;break}}return m}),y=async()=>{l.value=!0;try{const m=[];for(const O of[...qe,...it]){const q=(t.value[O]??[]).filter(H=>!H.isBuiltin&&H.enabled).map(H=>H.url);m.push({key:`rpc_pool.${O}`,value:JSON.stringify(q)})}const S=await ve(R.ADMIN_SETTINGS,{settings:m});a.value=S.settings;const g=h(S.settings);n.value=g,t.value=JSON.parse(JSON.stringify(g)),T("success","RPC settings saved and applied")}catch(m){const S=m instanceof _?m:new _(0,"UNKNOWN","Unknown error");T("error",W(S.code))}finally{l.value=!1}},D=()=>{t.value=JSON.parse(JSON.stringify(n.value))};F(()=>(Ne({id:"wallets-rpc",isDirty:P,save:y,discard:D}),()=>Se("wallets-rpc")),[]);const U=m=>{s.value={...s.value,[m]:!s.value[m]}},K=m=>{const S=(r.value[m]??"").trim();if(!S)return;if(!S.startsWith("https://")){T("warning","URL must start with https://");return}const g=t.value[m]??[];if(g.some(q=>q.url===S)){T("warning","URL already exists in this network");return}const O=[...g];O.findIndex(q=>q.isBuiltin&&!g.slice(0,g.indexOf(q)).some(H=>!H.isBuiltin));const $=O.reduce((q,H,J)=>H.isBuiltin?q:J+1,0);O.splice($,0,{url:S,isBuiltin:!1,enabled:!0}),t.value={...t.value,[m]:O},r.value={...r.value,[m]:""}},I=(m,S)=>{const g=[...t.value[m]??[]];g[S]?.isBuiltin||(g.splice(S,1),t.value={...t.value,[m]:g})},A=(m,S,g)=>{const O=[...t.value[m]??[]],$=g==="up"?S-1:S+1;if($<0||$>=O.length)return;const q=O[S],H=O[$];!q||!H||([O[S],O[$]]=[O[$],O[S]],t.value={...t.value,[m]:O})},k=(m,S)=>{const g=[...t.value[m]??[]],O=g[S];O?.isBuiltin&&(g[S]={...O,enabled:!O.enabled},t.value={...t.value,[m]:g})};function u({network:m}){const S=t.value[m]??[],g=s.value[m]??!1,O=S.filter(H=>H.enabled).length,$=c.value[m]??[],q=H=>$.find(J=>J.url===H);return e("details",{class:"rpc-pool-network",open:g,"data-testid":`rpc-network-${m}`,children:[e("summary",{class:"rpc-pool-network-header",onClick:H=>{H.preventDefault(),U(m)},children:[e("span",{children:Zl[m]??m}),e("span",{class:"rpc-pool-url-count",children:[O," URL",O!==1?"s":""]})]}),g&&e("div",{class:"rpc-url-list",children:[S.map((H,J)=>{const ce=q(H.url),pe=`${m}:${H.url}`,re=o.value[pe]??!1,ne=v.value[pe];return e("div",{class:`rpc-url-item${H.isBuiltin?" rpc-url-item--builtin":""}${H.enabled?"":" rpc-url-disabled"}`,"data-testid":`rpc-url-${m}-${J}`,children:[e("span",{class:"rpc-url-priority",children:["#",J+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-${m}-${J}`,children:ce?ce.status==="available"?e(Y,{children:[e("span",{class:"rpc-url-status-dot rpc-url-status-dot--available"}),e("span",{children:"Available"})]}):e(Y,{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:[Ql(ce.cooldownRemainingMs)," remaining"]}),e(B,{variant:"warning",children:[ce.failureCount," fail",ce.failureCount!==1?"s":""]})]}):e(Y,{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(m,H.url),loading:re,children:"Test"}),ne&&e("span",{class:`rpc-test-result ${ne.success?"rpc-test-result--success":"rpc-test-result--failure"}`,children:[e(B,{variant:ne.success?"success":"danger",children:ne.success?"OK":"FAIL"}),ne.success&&e(Y,{children:[" ",ne.latencyMs,"ms",ne.blockNumber!==void 0&&` (block #${ne.blockNumber.toLocaleString()})`]}),ne.error&&` - ${ne.error}`]})]}),e("span",{class:"rpc-url-actions",children:[e("button",{class:"btn btn-ghost btn-sm rpc-action-btn",onClick:()=>A(m,J,"up"),disabled:J===0,title:"Move up","aria-label":"Move up",children:"↑"}),e("button",{class:"btn btn-ghost btn-sm rpc-action-btn",onClick:()=>A(m,J,"down"),disabled:J===S.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:()=>k(m,J),title:H.enabled?"Disable":"Enable","aria-label":H.enabled?"Disable":"Enable",children:H.enabled?"On":"Off"}):e("button",{class:"btn btn-ghost btn-sm rpc-action-btn rpc-delete-btn",onClick:()=>I(m,J),title:"Remove","aria-label":"Remove",children:"×"})]})]},`${m}-${J}`)}),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[m]??"",onInput:H=>{r.value={...r.value,[m]:H.target.value}},onKeyDown:H=>{H.key==="Enter"&&K(m)}}),e(M,{variant:"secondary",size:"sm",onClick:()=>K(m),children:"Add"})]})]})]})}return i.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{children:[E.value>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[E.value," unsaved change",E.value>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:y,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"}),qe.map(m=>e(u,{network:m},m))]}),e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"EVM"}),it.map(m=>e(u,{network:m},m))]})]})]})]})}function ai(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=async()=>{try{const o=await V(R.ADMIN_SETTINGS);a.value=o}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{l.value=!1}};F(()=>{i()},[]);const s=(o,v)=>{const h=String(v);t.value={...t.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([h])=>h.startsWith("walletconnect.")).map(([h,f])=>({key:h,value:f})),v=await ve(R.ADMIN_SETTINGS,{settings:o});a.value=v.settings,t.value={},T("success","Settings saved and applied")}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{n.value=!1}},c=()=>{t.value={}};F(()=>(Ne({id:"wallets-walletconnect",isDirty:()=>Object.keys(t.value).filter(o=>o.startsWith("walletconnect.")).length>0,save:r,discard:c}),()=>Se("wallets-walletconnect")),[]);const p=Object.keys(t.value).filter(o=>o.startsWith("walletconnect.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{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:c,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(C,{label:G("project_id"),name:"walletconnect.project_id",type:"text",value:ee(a.value,t.value,"walletconnect","project_id"),onChange:o=>s("walletconnect.project_id",o),description:"WalletConnect Cloud project identifier"})}),e("div",{class:"settings-field-full",children:e(C,{label:G("relay_url"),name:"walletconnect.relay_url",type:"text",value:ee(a.value,t.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 ni=[{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"}]}],li=50;function ii(){const a=d([]),t=d(!0),n=d(!1),l=d(""),i=d("solana"),s=d("testnet"),r=d(null),c=d(!1),p=d(null),o=d(""),v=d({chain:"",environment:"",status:""}),h=d({}),f=d("USD"),N=d(1),P=async()=>{try{const A=await V(R.WALLETS);a.value=A.items}catch(A){const k=A instanceof _?A:new _(0,"UNKNOWN","Unknown error");T("error",W(k.code))}finally{t.value=!1}},E=async A=>{const k=A.slice(0,li),u={};await Promise.allSettled(k.map(async m=>{try{const g=(await V(R.ADMIN_WALLET_BALANCE(m.id))).balances?.[0];g?.native?u[m.id]={balance:g.native.balance,symbol:g.native.symbol,usd:g.native.usd}:u[m.id]=null}catch{u[m.id]=null}})),h.value={...h.value,...u}},y=Ht(()=>{let A=a.value;const k=o.value.toLowerCase();k&&(A=A.filter(m=>m.name.toLowerCase().includes(k)||m.publicKey.toLowerCase().includes(k)));const u=v.value;return u.chain&&(A=A.filter(m=>m.chain===u.chain)),u.environment&&(A=A.filter(m=>m.environment===u.environment)),u.status&&(A=A.filter(m=>m.status===u.status)),A}),D=[{key:"name",header:"Name"},{key:"chain",header:"Chain"},{key:"environment",header:"Environment",render:A=>e(B,{variant:A.environment==="mainnet"?"warning":"info",children:A.environment})},{key:"publicKey",header:"Public Key",render:A=>e("span",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[Mt(A.publicKey)," ",e(ft,{value:A.publicKey})]})},{key:"balance",header:"Balance",render:A=>{const k=h.value[A.id];return k===void 0?e("span",{style:{color:"var(--color-text-secondary)"},children:"Loading..."}):k===null?e("span",{style:{color:"var(--color-text-secondary)"},children:"--"}):e("span",{children:[k.balance," ",k.symbol,k.usd!=null&&e("span",{style:{color:"var(--color-text-secondary)",marginLeft:"var(--space-1)",fontSize:"0.85em"},children:["(",Fe(k.usd,f.value,N.value),")"]})]})}},{key:"status",header:"Status",render:A=>e(B,{variant:A.status==="ACTIVE"?"success":A.status==="SUSPENDED"?"warning":"danger",children:A.status})},{key:"ownerState",header:"Owner",render:A=>e(B,{variant:In(A.ownerState),children:A.ownerState})},{key:"createdAt",header:"Created",render:A=>ue(A.createdAt)}],U=async()=>{if(!l.value.trim()){r.value="Name is required";return}r.value=null,c.value=!0;try{const A=await ie(R.WALLETS,{name:l.value.trim(),chain:i.value,environment:s.value});A.session?.token?(p.value=A.session.token,T("success","Wallet created with session")):T("success","Wallet created"),l.value="",i.value="solana",s.value="testnet",n.value=!1,t.value=!0,await P()}catch(A){const k=A instanceof _?A:new _(0,"UNKNOWN","Unknown error");r.value=W(k.code)}finally{c.value=!1}},K=A=>{window.location.hash="#/wallets/"+A.id},I=A=>{i.value=A};return F(()=>{P().then(()=>{a.value.length>0&&E(a.value)}),Vt().then(({currency:A,rate:k})=>{f.value=A,N.value=k}).catch(()=>{})},[]),e(Y,{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(C,{label:"Name",name:"name",value:l.value,onChange:A=>{l.value=A},required:!0,placeholder:"e.g. trading-bot",error:r.value??void 0}),e(C,{label:"Chain",name:"chain",type:"select",value:i.value,onChange:I,options:[{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}]}),e(C,{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:U,loading:c.value,children:"Create"}),e(M,{variant:"secondary",onClick:()=>{n.value=!1,r.value=null},children:"Cancel"})]})]}),p.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:p.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(p.value),T("success","Token copied")},children:"Copy"}),e(M,{variant:"secondary",onClick:()=>{p.value=null},children:"Dismiss"})]})]}),e(Gt,{fields:ni,values:v.value,onChange:A=>{v.value=A},syncUrl:!1}),e(Cn,{value:o.value,onSearch:A=>{o.value=A},placeholder:"Search by name or public key..."}),e(He,{columns:D,data:y.value,loading:t.value,onRowClick:K,emptyMessage:"No wallets yet"})]})}const Ma=[{key:"wallets",label:"Wallets"},{key:"rpc",label:"RPC Endpoints"},{key:"walletconnect",label:"WalletConnect"}];function si(){const a=d("wallets");return F(()=>{const t=le.value;t&&t.tab&&(a.value=t.tab,setTimeout(()=>{_e.value=t.fieldName},100),le.value=null)},[le.value]),e("div",{class:"page",children:[e(et,{pageName:"Wallets",tabName:Ma.find(t=>t.key===a.value)?.label??"",onPageClick:()=>{a.value="wallets"}}),e(Ve,{tabs:Ma,activeTab:a.value,onTabChange:t=>{a.value=t}}),a.value==="wallets"&&e(ii,{}),a.value==="rpc"&&e(ti,{}),a.value==="walletconnect"&&e(ai,{})]})}function Ua(){const a=De.value,t=a.startsWith("/wallets/")?a.slice(9):null;return t?e(Jl,{id:t}):e(si,{})}const Wa=[{key:"transactions",label:"All Transactions"},{key:"monitor",label:"Monitor Settings"}],Ie=20,ri=[{value:"all",label:"All"},{value:"outgoing",label:"Outgoing"},{value:"incoming",label:"Incoming"}],oi=[{value:"TRANSFER",label:"TRANSFER"},{value:"TOKEN_TRANSFER",label:"TOKEN_TRANSFER"},{value:"CONTRACT_CALL",label:"CONTRACT_CALL"},{value:"APPROVE",label:"APPROVE"},{value:"BATCH",label:"BATCH"}],ci=[{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"}],di=[{value:"DETECTED",label:"DETECTED"},{value:"CONFIRMED",label:"CONFIRMED"}],ui=[{value:"solana",label:"Solana"},{value:"evm",label:"EVM"}],vi=[{value:"true",label:"Yes"},{value:"false",label:"No"}],hi=[{value:"mainnet",label:"mainnet"},{value:"devnet",label:"devnet"},{value:"testnet",label:"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"}],Nt=["Time","Direction","Wallet","Counterparty","Amount","Network","Status","Tx Hash"];function pi(a){return a==="CONFIRMED"?"success":a==="FAILED"?"danger":"warning"}function $a(a){return{id:`out-${a.id}`,direction:"outgoing",time:a.createdAt,walletId:a.walletId,walletName:a.walletName,counterparty:a.toAddress,amount:a.amount,formattedAmount:a.formattedAmount,amountUsd:a.amountUsd,network:a.network??a.chain,status:a.status,txHash:a.txHash,chain:a.chain,outgoing:a}}function Ka(a){return{id:`in-${a.id}`,direction:"incoming",time:a.detectedAt,walletId:a.walletId,walletName:a.walletName,counterparty:a.fromAddress,amount:a.amount,formattedAmount:a.formattedAmount,amountUsd:null,network:a.network,status:a.status,txHash:a.txHash,chain:a.chain,incoming:a}}function Fa(){const a=d("transactions"),t=d([]),n=d(0),l=d(0),i=d(!0),s=d(null),r=d("all"),c=d({wallet_id:"",type:"",status:"",network:"",chain:"",suspicious:"",since:"",until:""}),p=d(""),o=d(0),v=d(null),h=d("USD"),f=d(1),N=d([]),P=d({}),E=d({}),y=d(!1),D=d(!0),U=d([]),K=d(!0),I=d({}),A=d(null),k=(w,x)=>{E.value={...E.value,[w]:String(x)}},u=(w,x)=>ee(P.value,E.value,w,x),m=async()=>{y.value=!0;try{const w=Object.entries(E.value).filter(([Z])=>Z.startsWith("incoming.")).map(([Z,de])=>({key:Z,value:de}));if(w.length===0){T("info","No changes to save"),y.value=!1;return}const x=await ve(R.ADMIN_SETTINGS,{settings:w});P.value=x.settings,E.value={},T("success","Settings saved and applied")}catch(w){const x=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");T("error",W(x.code))}finally{y.value=!1}},S=()=>{E.value={}};F(()=>(Object.keys(E.value).filter(x=>x.startsWith("incoming.")).length>0?Ne({id:"transactions-monitor",isDirty:()=>Object.keys(E.value).filter(x=>x.startsWith("incoming.")).length>0,save:m,discard:S}):Se("transactions-monitor"),()=>Se("transactions-monitor")),[E.value]);function g(){const w=r.value,x=[{key:"wallet_id",label:"Wallet",type:"select",options:N.value}];return(w==="outgoing"||w==="all")&&x.push({key:"type",label:"Type",type:"select",options:oi}),w==="outgoing"?x.push({key:"status",label:"Status",type:"select",options:ci}):w==="incoming"&&x.push({key:"status",label:"Status",type:"select",options:di}),x.push({key:"network",label:"Network",type:"select",options:hi}),(w==="incoming"||w==="all")&&(x.push({key:"chain",label:"Chain",type:"select",options:ui}),x.push({key:"suspicious",label:"Suspicious",type:"select",options:vi})),x.push({key:"since",label:"Since",type:"date"},{key:"until",label:"Until",type:"date"}),x}const O=async()=>{const w=new URLSearchParams,x=c.value;if(x.wallet_id&&w.set("wallet_id",x.wallet_id),x.type&&w.set("type",x.type),x.status&&r.value!=="all"&&w.set("status",x.status),x.network&&w.set("network",x.network),x.since){const Z=new Date(x.since);isNaN(Z.getTime())||w.set("since",String(Math.floor(Z.getTime()/1e3)))}if(x.until){const Z=new Date(x.until);isNaN(Z.getTime())||(Z.setHours(23,59,59,999),w.set("until",String(Math.floor(Z.getTime()/1e3))))}return p.value&&w.set("search",p.value),w.set("offset",String(o.value*Ie)),w.set("limit",String(Ie)),V(`${R.ADMIN_TRANSACTIONS}?${w.toString()}`)},$=async()=>{const w=new URLSearchParams,x=c.value;return x.wallet_id&&w.set("wallet_id",x.wallet_id),x.chain&&w.set("chain",x.chain),x.status&&r.value!=="all"&&w.set("status",x.status),x.suspicious&&w.set("suspicious",x.suspicious),w.set("offset",String(o.value*Ie)),w.set("limit",String(Ie)),V(`${R.ADMIN_INCOMING}?${w.toString()}`)},q=async()=>{i.value=!0,s.value=null;try{const w=r.value;if(w==="outgoing"){const x=await O();t.value=x.items.map($a),n.value=x.total,l.value=0}else if(w==="incoming"){const x=await $();t.value=x.items.map(Ka),n.value=0,l.value=x.total}else{const[x,Z]=await Promise.all([O(),$()]),de=[...x.items.map($a),...Z.items.map(Ka)];de.sort((Me,Ge)=>(Ge.time??0)-(Me.time??0)),t.value=de,n.value=x.total,l.value=Z.total}}catch(w){w instanceof _?s.value=W(w.code):s.value="An unexpected error occurred."}finally{i.value=!1}},H=async()=>{try{const w=await V(R.WALLETS),x=Array.isArray(w)?w:w.items??[];N.value=x.map(de=>({value:de.id,label:de.name||de.id.slice(0,8)})),U.value=x;const Z={};for(const de of x)Z[de.id]=de.monitorIncoming??!1;I.value=Z}catch{}finally{K.value=!1}},J=async()=>{try{const w=await V(R.ADMIN_SETTINGS);P.value=w}catch(w){const x=w instanceof _?w:new _(0,"UNKNOWN","Unknown error");T("error",W(x.code))}finally{D.value=!1}};F(()=>{q(),H(),Vt().then(({currency:w,rate:x})=>{h.value=w,f.value=x}).catch(()=>{}),J()},[]),F(()=>{q()},[c.value,p.value,o.value,r.value]),F(()=>{const w=le.value;w&&w.tab&&(a.value=w.tab,le.value=null,setTimeout(()=>{_e.value=w.fieldName},100))},[le.value]);function ce(w){a.value=w}function pe(w){c.value=w,o.value=0}function re(w){p.value=w,o.value=0}function ne(w){r.value=w,o.value=0,c.value={...c.value,type:"",status:"",chain:"",suspicious:""}}function we(w){v.value=v.value===w.id?null:w.id}function Pe(){o.value>0&&(o.value=o.value-1)}function Ee(){const w=n.value+l.value;(o.value+1)*Ie<w&&(o.value=o.value+1)}async function Ae(w){if(window.confirm("Are you sure you want to cancel this transaction?"))try{await ie(R.ADMIN_TX_CANCEL(w)),T("success","Transaction cancelled"),await q()}catch(x){const Z=x instanceof _?x:new _(0,"UNKNOWN","Unknown error");T("error",W(Z.code))}}async function Te(w){if(window.confirm("Are you sure you want to reject this transaction?"))try{await ie(R.ADMIN_TX_REJECT(w)),T("success","Transaction rejected"),await q()}catch(x){const Z=x instanceof _?x:new _(0,"UNKNOWN","Unknown error");T("error",W(Z.code))}}async function tt(w){const x=I.value[w]??!1;A.value=w;try{const Z=await kl(R.WALLET_PATCH(w),{monitorIncoming:!x});I.value={...I.value,[w]:Z.monitorIncoming}}catch(Z){const de=Z instanceof _?Z:new _(0,"UNKNOWN","Unknown error");T("error",W(de.code))}finally{A.value=null}}function L(){const w=n.value+l.value,x=o.value*Ie,Z=w>0?x+1:0,de=Math.min(x+Ie,w),Me=o.value>0,Ge=(o.value+1)*Ie<w;return e(Y,{children:[s.value&&e("div",{class:"dashboard-error",children:[e("span",{children:s.value}),e(M,{variant:"secondary",size:"sm",onClick:q,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:j=>ne(j.target.value),children:ri.map(j=>e("option",{value:j.value,children:j.label},j.value))})]})}),e(Gt,{fields:g(),values:c.value,onChange:pe}),r.value!=="incoming"&&e(Cn,{value:p.value,onSearch:re,placeholder:"Search by txHash or recipient address..."}),e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:Nt.map(j=>e("th",{children:j},j))})}),e("tbody",{children:i.value&&t.value.length===0?e("tr",{children:e("td",{colSpan:Nt.length,class:"table-loading",children:"Loading..."})}):t.value.length===0?e("tr",{children:e("td",{colSpan:Nt.length,class:"table-empty",children:"No transactions found"})}):t.value.map(j=>e(Y,{children:[e("tr",{class:`clickable${v.value===j.id?" row-expanded":""}`,style:{cursor:"pointer"},onClick:()=>we(j),children:[e("td",{children:j.time?ue(j.time):"—"}),e("td",{children:e(B,{variant:j.direction==="outgoing"?"info":"success",children:j.direction==="outgoing"?"Outgoing":"Incoming"})}),e("td",{children:j.walletName??j.walletId.slice(0,8)}),e("td",{children:j.counterparty?Mt(j.counterparty):"—"}),e("td",{children:j.amount?(()=>{const at=j.formattedAmount??j.amount;if(j.amountUsd!=null){const bt=Fe(j.amountUsd,h.value,f.value);return bt?`${at} (${bt})`:at}return at})():"—"}),e("td",{children:j.network}),e("td",{children:e(B,{variant:pi(j.status),children:j.status})}),e("td",{children:e(ya,{network:j.network,txHash:j.txHash})})]},j.id),v.value===j.id&&e("tr",{class:"row-expand",children:e("td",{colSpan:Nt.length,children:[j.outgoing?ae(j.outgoing):null,j.incoming?ge(j.incoming):null]})},`${j.id}-expand`)]}))})]})}),e("div",{class:"pagination",children:[e("span",{class:"pagination-info",children:["Showing ",Z,"-",de," of ",w]}),e("div",{class:"pagination-buttons",children:[e(M,{variant:"secondary",size:"sm",disabled:!Me,onClick:Pe,children:"Previous"}),e(M,{variant:"secondary",size:"sm",disabled:!Ge,onClick:Ee,children:"Next"})]})]})]})}function ae(w){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:w.id})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet ID"}),e("span",{class:"detail-value",children:w.walletId})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet Name"}),e("span",{class:"detail-value",children:w.walletName??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Type"}),e("span",{class:"detail-value",children:w.type})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Status"}),e("span",{class:"detail-value",children:w.status})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Tier"}),e("span",{class:"detail-value",children:w.tier??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"To Address"}),e("span",{class:"detail-value",children:w.toAddress??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Amount"}),e("span",{class:"detail-value",children:w.amount??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Amount USD"}),e("span",{class:"detail-value",children:w.amountUsd!=null?`$${w.amountUsd.toFixed(2)}`:"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Network"}),e("span",{class:"detail-value",children:w.network??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Chain"}),e("span",{class:"detail-value",children:w.chain})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Tx Hash"}),e("span",{class:"detail-value",children:w.txHash??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Created At"}),e("span",{class:"detail-value",children:w.createdAt?ue(w.createdAt):"—"})]}),w.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:x=>{x.stopPropagation(),Ae(w.id)},children:"Cancel"}),e(M,{variant:"secondary",size:"sm",onClick:x=>{x.stopPropagation(),Te(w.id)},children:"Reject"})]})})]})}function ge(w){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:w.id})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Tx Hash"}),e("span",{class:"detail-value",children:w.txHash})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet ID"}),e("span",{class:"detail-value",children:w.walletId})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Wallet Name"}),e("span",{class:"detail-value",children:w.walletName??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"From Address"}),e("span",{class:"detail-value",children:w.fromAddress})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Amount"}),e("span",{class:"detail-value",children:w.amount})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Token Address"}),e("span",{class:"detail-value",children:w.tokenAddress??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Chain"}),e("span",{class:"detail-value",children:w.chain})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Network"}),e("span",{class:"detail-value",children:w.network})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Status"}),e("span",{class:"detail-value",children:w.status})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Block Number"}),e("span",{class:"detail-value",children:w.blockNumber??"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Detected At"}),e("span",{class:"detail-value",children:w.detectedAt?ue(w.detectedAt):"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Confirmed At"}),e("span",{class:"detail-value",children:w.confirmedAt?ue(w.confirmedAt):"—"})]}),e("div",{class:"detail-item",children:[e("span",{class:"detail-label",children:"Suspicious"}),e("span",{class:"detail-value",children:w.suspicious?"Yes":"No"})]})]})}function zt(){const w=Object.keys(E.value).filter(x=>x.startsWith("incoming.")).length;return e(Y,{children:[w>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[w," unsaved change",w>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(M,{variant:"ghost",size:"sm",onClick:S,children:"Discard"}),e(M,{variant:"primary",size:"sm",onClick:m,loading:y.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:D.value?e("span",{children:"Loading settings..."}):e(Y,{children:[e("div",{class:"settings-fields-grid",children:[e(C,{label:"Monitoring Enabled",name:"incoming.enabled",type:"select",value:u("incoming","enabled")||"false",onChange:x=>k("incoming.enabled",x),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}]}),e(C,{label:"Poll Interval (seconds)",name:"incoming.poll_interval",type:"number",value:Number(u("incoming","poll_interval"))||30,onChange:x=>k("incoming.poll_interval",x),min:5,max:3600}),e(C,{label:"Retention Days",name:"incoming.retention_days",type:"number",value:Number(u("incoming","retention_days"))||90,onChange:x=>k("incoming.retention_days",x),min:1,max:365}),e(C,{label:"Suspicious Dust USD Threshold",name:"incoming.suspicious_dust_usd",type:"number",value:Number(u("incoming","suspicious_dust_usd"))||.01,onChange:x=>k("incoming.suspicious_dust_usd",x),min:0,max:1e3}),e(C,{label:"Suspicious Amount Multiplier",name:"incoming.suspicious_amount_multiplier",type:"number",value:Number(u("incoming","suspicious_amount_multiplier"))||10,onChange:x=>k("incoming.suspicious_amount_multiplier",x),min:1,max:1e3}),e(C,{label:"Notification Cooldown (minutes)",name:"incoming.cooldown_minutes",type:"number",value:Number(u("incoming","cooldown_minutes"))||5,onChange:x=>k("incoming.cooldown_minutes",x),min:1,max:1440}),e(C,{label:"WebSocket URL (optional)",name:"incoming.wss_url",type:"text",value:u("incoming","wss_url"),onChange:x=>k("incoming.wss_url",x),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:K.value?e("span",{children:"Loading wallets..."}):U.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:U.value.map(x=>e("tr",{children:[e("td",{children:x.name||x.id.slice(0,8)}),e("td",{children:x.chain}),e("td",{children:e(B,{variant:(x.status??"ACTIVE")==="ACTIVE"?"success":"warning",children:x.status??"ACTIVE"})}),e("td",{children:e(M,{variant:I.value[x.id]?"primary":"secondary",size:"sm",onClick:()=>tt(x.id),loading:A.value===x.id,children:I.value[x.id]?"ON":"OFF"})})]},x.id))})]})})})]})]})}const qt=Wa.find(w=>w.key===a.value)?.label;return e("div",{class:"page",children:[e(et,{pageName:"Transactions",tabName:qt,onPageClick:()=>{a.value="transactions"}}),e(Ve,{tabs:Wa,activeTab:a.value,onTabChange:ce}),e("div",{style:{marginTop:"var(--space-4)"},children:a.value==="transactions"?L():zt()})]})}const mi=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia"],Xt=["Symbol","Name","Address","Decimals","Source","Actions"];function fi(a){return a.length<=10?a:`${a.slice(0,6)}...${a.slice(-4)}`}function gi(){const a=d("ethereum-mainnet"),t=d([]),n=d(!0),l=d(null),i=d(!1),s=d(""),r=d(""),c=d(""),p=d("18"),o=d(!1),v=d(!1),h=d(null),f=gt(null),N=async()=>{n.value=!0,l.value=null;try{const I=await V(`${R.TOKENS}?network=${encodeURIComponent(a.value)}`);t.value=I.tokens}catch(I){I instanceof _?l.value=W(I.code):l.value="An unexpected error occurred.",t.value=[]}finally{n.value=!1}};F(()=>{N()},[a.value]);function P(I){a.value=I.target.value}function E(){s.value="",r.value="",c.value="",p.value="18",v.value=!1,i.value=!1,f.current&&clearTimeout(f.current)}async function y(I){v.value=!0;try{const A=await V(`${R.TOKENS_RESOLVE}?network=${encodeURIComponent(a.value)}&address=${encodeURIComponent(I)}`);r.value=A.symbol,c.value=A.name,p.value=String(A.decimals),T("success",`Resolved: ${A.symbol} (${A.name})`)}catch{}finally{v.value=!1}}function D(I){const A=I.target.value;s.value=A,f.current&&clearTimeout(f.current),/^0x[a-fA-F0-9]{40}$/.test(A)&&(f.current=setTimeout(()=>y(A),500))}async function U(){if(!s.value||!r.value||!c.value){T("error","Please fill in all required fields.");return}o.value=!0;try{await ie(R.TOKENS,{network:a.value,address:s.value,symbol:r.value,name:c.value,decimals:Number(p.value)}),T("success",`Token ${r.value} added successfully.`),E(),await N()}catch(I){I instanceof _?T("error",W(I.code)):T("error","Failed to add token.")}finally{o.value=!1}}async function K(I){h.value=I;try{await Ke(R.TOKENS,{network:a.value,address:I}),T("success","Token removed successfully."),await N()}catch(A){A instanceof _?T("error",W(A.code)):T("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:a.value,onChange:P,children:mi.map(I=>e("option",{value:I,children:I},I))})]}),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:D,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:I=>{r.value=I.target.value},placeholder:"e.g. USDC"})]}),e("div",{class:"form-field",children:[e("label",{for:"token-name",children:"Name"}),e("input",{id:"token-name",type:"text",value:c.value,onInput:I=>{c.value=I.target.value},placeholder:"e.g. USD Coin"})]}),e("div",{class:"form-field",children:[e("label",{for:"token-decimals",children:"Decimals"}),e("input",{id:"token-decimals",type:"number",value:p.value,onInput:I=>{p.value=I.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:U,children:"Submit"}),e(M,{variant:"secondary",size:"sm",onClick:E,children:"Cancel"})]})]}),e("div",{class:"table-container",style:{marginTop:"var(--space-3)"},children:e("table",{children:[e("thead",{children:e("tr",{children:Xt.map(I=>e("th",{children:I},I))})}),e("tbody",{children:n.value&&t.value.length===0?e("tr",{children:e("td",{colSpan:Xt.length,class:"table-loading",children:"Loading..."})}):t.value.length===0?e("tr",{children:e("td",{colSpan:Xt.length,class:"table-empty",children:"No tokens found for this network"})}):t.value.map(I=>e("tr",{children:[e("td",{children:I.symbol}),e("td",{children:I.name}),e("td",{title:I.address,children:fi(I.address)}),e("td",{children:I.decimals}),e("td",{children:e(B,{variant:I.source==="builtin"?"neutral":"info",children:I.source==="builtin"?"Built-in":"Custom"})}),e("td",{children:I.source==="custom"?e(M,{variant:"danger",size:"sm",loading:h.value===I.address,onClick:()=>K(I.address),children:"Delete"}):"—"})]},I.address))})]})})]})}function We({legend:a,children:t,description:n}){return e("fieldset",{class:"field-group",children:[e("legend",{class:"field-group-legend",children:a}),n&&e("p",{class:"field-group-description",children:n}),e("div",{class:"field-group-body",children:t})]})}function yi(a,t,n){t.value=a,n.value=!0}const Ha=[{key:"sessions",label:"Sessions"},{key:"settings",label:"Settings"}],Jt=["security.session_ttl","security.session_absolute_lifetime","security.session_max_renewals","security.max_sessions_per_wallet","security.max_pending_tx","security.rate_limit_session_rpm","security.rate_limit_tx_rpm"];function _i(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=async()=>{try{const o=await V(R.ADMIN_SETTINGS);a.value=o}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{l.value=!1}};F(()=>{i()},[]);const s=(o,v)=>{const h=String(v);t.value={...t.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([h])=>Jt.includes(h)).map(([h,f])=>({key:h,value:f})),v=await ve(R.ADMIN_SETTINGS,{settings:o});a.value=v.settings,t.value={},T("success","Session settings saved and applied")}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{n.value=!1}},c=()=>{t.value={}};F(()=>(Ne({id:"sessions-settings",isDirty:()=>Object.keys(t.value).filter(o=>Jt.includes(o)).length>0,save:r,discard:c}),()=>Se("sessions-settings")),[]);const p=Object.keys(t.value).filter(o=>Jt.includes(o)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{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:c,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(We,{legend:"Lifetime",description:"Session duration and renewal limits",children:e("div",{class:"settings-fields-grid",children:[e(C,{label:G("session_ttl"),name:"security.session_ttl",type:"number",value:Number(ee(a.value,t.value,"security","session_ttl"))||0,onChange:o=>s("security.session_ttl",o),min:300,description:"How long a session token is valid before renewal"}),e(C,{label:G("session_absolute_lifetime"),name:"security.session_absolute_lifetime",type:"number",value:Number(ee(a.value,t.value,"security","session_absolute_lifetime"))||0,onChange:o=>s("security.session_absolute_lifetime",o),min:0,description:"Maximum total session duration regardless of renewals"}),e(C,{label:G("session_max_renewals"),name:"security.session_max_renewals",type:"number",value:Number(ee(a.value,t.value,"security","session_max_renewals"))||0,onChange:o=>s("security.session_max_renewals",o),min:0,description:"Maximum number of times a session can be renewed"}),e(C,{label:G("max_sessions_per_wallet"),name:"security.max_sessions_per_wallet",type:"number",value:Number(ee(a.value,t.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(We,{legend:"Rate Limits",description:"Request throttling per session and transaction",children:e("div",{class:"settings-fields-grid",children:[e(C,{label:G("max_pending_tx"),name:"security.max_pending_tx",type:"number",value:Number(ee(a.value,t.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(C,{label:G("rate_limit_session_rpm"),name:"security.rate_limit_session_rpm",type:"number",value:Number(ee(a.value,t.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(C,{label:G("rate_limit_tx_rpm"),name:"security.rate_limit_tx_rpm",type:"number",value:Number(ee(a.value,t.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 bi(){const a=d("sessions");F(()=>{const u=le.value;u&&u.tab&&(a.value=u.tab,setTimeout(()=>{_e.value=u.fieldName},100),le.value=null)},[le.value]);const t=d([]),n=d(""),l=d(""),i=d([]),s=d(!1),r=d(!0),c=d(!1),p=d(!1),o=d(""),v=d(!1),h=d(""),f=d(!1),N=d(null),P=d(!1),E=d(new Set),y=async()=>{try{const u=await V(R.WALLETS);t.value=u.items.filter(m=>m.status==="ACTIVE")}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{r.value=!1}},D=async()=>{s.value=!0;try{const u=n.value?`${R.SESSIONS}?walletId=${n.value}`:R.SESSIONS,m=await V(u);i.value=m}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{s.value=!1}},U=u=>{const m=new Set(E.value);m.has(u)?m.delete(u):m.add(u),E.value=m},K=async()=>{c.value=!0;try{const u=Array.from(E.value),m=u.length===1?{walletId:u[0]}:{walletIds:u},S=await ie(R.SESSIONS,m);o.value=S.token,p.value=!0,P.value=!1,await D()}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{c.value=!1}},I=async()=>{f.value=!0;try{await Ke(R.SESSION(h.value)),T("success","Session revoked"),v.value=!1,await D()}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{f.value=!1}},A=async u=>{N.value=u;try{const m=await ie(R.ADMIN_SESSION_REISSUE(u),{});o.value=m.token,p.value=!0,await D()}catch(m){const S=m instanceof _?m:new _(0,"UNKNOWN","Unknown error");T("error",W(S.code))}finally{N.value=null}};F(()=>{y()},[]),F(()=>{i.value=[],D()},[n.value]);const k=[{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(B,{variant:u.source==="mcp"?"info":"neutral",children:u.source==="mcp"?"MCP":"API"})},{key:"status",header:"Status",render:u=>e(B,{variant:u.status==="ACTIVE"?"success":u.status==="EXPIRED"?"warning":"danger",children:u.status})},{key:"expiresAt",header:"Expires At",render:u=>ue(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=>ue(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:()=>A(u.id),loading:N.value===u.id,children:"Reissue"}),e(M,{size:"sm",variant:"danger",onClick:()=>yi(u.id,h,v),children:"Revoke"})]}):null}];return e("div",{class:"page",children:[e(et,{pageName:"Sessions",tabName:Ha.find(u=>u.key===a.value)?.label??"",onPageClick:()=>{a.value="sessions"}}),e(Ve,{tabs:Ha,activeTab:a.value,onTabChange:u=>{a.value=u}}),a.value==="sessions"&&e(Y,{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"}),t.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:()=>{E.value=new Set,P.value=!0},disabled:t.value.length===0,children:"Create Session"})]}),e(He,{columns:k,data:l.value?i.value.filter(u=>u.source===l.value):i.value,loading:s.value,emptyMessage:"No sessions"}),e(be,{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(ft,{value:o.value,label:"Copy Token"})]})]}),e(be,{open:v.value,title:"Revoke Session",onCancel:()=>{v.value=!1},onConfirm:I,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(be,{open:P.value,title:"Create Session",onCancel:()=>{P.value=!1},onConfirm:K,confirmText:`Create Session (${E.value.size} wallet${E.value.size!==1?"s":""})`,confirmDisabled:E.value.size===0,loading:c.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:t.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:E.value.has(u.id),onChange:()=>U(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))})]})})]}),a.value==="settings"&&e(_i,{})]})}const wi={mainnet:"SOL",devnet:"SOL",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 Si(a){return a&&wi[a]||"Native"}const Ba=["ethereum-mainnet","ethereum-sepolia","polygon-mainnet","polygon-amoy","arbitrum-mainnet","arbitrum-sepolia","optimism-mainnet","optimism-sepolia","base-mainnet","base-sepolia"];function Ti({rules:a,onChange:t,errors:n,network:l}){const i=d([]),s=d(!1),r=y=>D=>{t({...a,[y]:D})},c=y=>D=>{const U=Number(D),K={...a};D===""||D===0||Number.isNaN(U)?delete K[y]:K[y]=U,t(K)},p=a.token_limits||{},o=y=>D=>{const U=String(D),I={...p.native||{instant_max:"",notify_max:"",delay_max:""},[y]:U};if(!I.instant_max&&!I.notify_max&&!I.delay_max){const A={...p};delete A.native,t({...a,token_limits:Object.keys(A).length>0?A:void 0})}else t({...a,token_limits:{...p,native:I}})},v=(y,D,U)=>{const I={...p[y]||{instant_max:"0",notify_max:"0",delay_max:"0"},[D]:U};t({...a,token_limits:{...p,[y]:I}})},h=y=>{const D={...p};delete D[y],t({...a,token_limits:Object.keys(D).length>0?D:void 0})},f=y=>{if(!y||p[y])return;const D={instant_max:"0",notify_max:"0",delay_max:"0"};t({...a,token_limits:{...p,[y]:D}})},N=()=>{const y=prompt("Enter CAIP-19 asset ID (e.g., eip155:1/erc20:0xa0b8...)");if(!y||p[y])return;const D={instant_max:"0",notify_max:"0",delay_max:"0"};t({...a,token_limits:{...p,[y]:D}})};F(()=>{if(!l){i.value=[];return}if(!Ba.includes(l)){i.value=[];return}s.value=!0,V(`${R.TOKENS}?network=${l}`).then(y=>{i.value=y.tokens}).catch(()=>{i.value=[]}).finally(()=>{s.value=!1})},[l]);const P=Object.entries(p).filter(([y])=>y!=="native").map(([y,D])=>({assetId:y,symbol:i.value.find(U=>U.assetId===y)?.symbol||y.split("/").pop()?.split(":").pop()||y,instant_max:D.instant_max,notify_max:D.notify_max,delay_max:D.delay_max})),E=Si(l);return e("div",{class:"policy-form-fields",children:[e("h4",{children:"USD Amount Tiers"}),e("div",{class:"policy-form-grid",children:[e(C,{label:"Instant Max USD",name:"instant_max_usd",type:"number",value:a.instant_max_usd??"",onChange:c("instant_max_usd"),placeholder:"Optional"}),e(C,{label:"Notify Max USD",name:"notify_max_usd",type:"number",value:a.notify_max_usd??"",onChange:c("notify_max_usd"),placeholder:"Optional"}),e(C,{label:"Delay Max USD",name:"delay_max_usd",type:"number",value:a.delay_max_usd??"",onChange:c("delay_max_usd"),placeholder:"Optional"})]}),e("h4",{children:"Token-Specific Limits"}),e("h5",{children:["Native Token (",E,")"]}),e("div",{class:"policy-form-grid",children:[e(C,{label:`Instant Max (${E})`,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(C,{label:`Notify Max (${E})`,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(C,{label:`Delay Max (${E})`,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"}),P.map((y,D)=>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:y.symbol}),e("span",{style:{fontSize:"0.75rem",color:"var(--text-secondary)",flex:1,marginLeft:"0.5rem",overflow:"hidden",textOverflow:"ellipsis"},children:y.assetId}),e("button",{class:"btn btn-ghost btn-sm",onClick:()=>h(y.assetId),title:"Remove",children:"x"})]}),e("div",{class:"policy-form-grid",children:[e(C,{label:"Instant Max",name:`token-${D}-instant`,value:y.instant_max,onChange:U=>v(y.assetId,"instant_max",String(U)),placeholder:"e.g. 100",error:n[`token_limits.${y.assetId}.instant_max`]}),e(C,{label:"Notify Max",name:`token-${D}-notify`,value:y.notify_max,onChange:U=>v(y.assetId,"notify_max",String(U)),placeholder:"e.g. 500",error:n[`token_limits.${y.assetId}.notify_max`]}),e(C,{label:"Delay Max",name:`token-${D}-delay`,value:y.delay_max,onChange:U=>v(y.assetId,"delay_max",String(U)),placeholder:"e.g. 1000",error:n[`token_limits.${y.assetId}.delay_max`]})]})]},y.assetId)),l&&Ba.includes(l)&&i.value.length>0&&e("div",{style:{display:"flex",gap:"0.5rem",alignItems:"flex-end",marginTop:"0.5rem"},children:e(C,{label:"Select Token",name:"add-token-select",type:"select",value:"",onChange:y=>f(y),options:[{label:s.value?"Loading...":"-- Select a token --",value:""},...i.value.filter(y=>y.assetId&&!p[y.assetId]).map(y=>({label:`${y.symbol} (${y.name})`,value:y.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(C,{label:"Daily Limit USD (24h rolling)",name:"daily_limit_usd",type:"number",value:a.daily_limit_usd??"",onChange:c("daily_limit_usd"),placeholder:"e.g. 500",error:n.daily_limit_usd}),e(C,{label:"Monthly Limit USD (30d rolling)",name:"monthly_limit_usd",type:"number",value:a.monthly_limit_usd??"",onChange:c("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(C,{label:"Instant Max (lamports/wei)",name:"instant_max",value:a.instant_max||"",onChange:r("instant_max"),error:n.instant_max}),e(C,{label:"Notify Max (lamports/wei)",name:"notify_max",value:a.notify_max||"",onChange:r("notify_max"),error:n.notify_max}),e(C,{label:"Delay Max (lamports/wei)",name:"delay_max",value:a.delay_max||"",onChange:r("delay_max"),error:n.delay_max})]}),e(C,{label:"Delay Duration (seconds, min 60)",name:"delay_seconds",type:"number",value:a.delay_seconds??900,onChange:r("delay_seconds"),error:n.delay_seconds,required:!0,min:60})]})}function Re({items:a,onAdd:t,onRemove:n,renderRow:l,onChange:i,addLabel:s="+ Add",minItems:r=0,error:c}){return e("div",{class:"dynamic-row-list",children:[a.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:a.length<=r,title:"Remove",children:"x"})]},o)),e("button",{class:"btn btn-secondary btn-sm",onClick:t,children:s}),c&&e("span",{class:"form-error",children:c})]})}function ki({rules:a,onChange:t,errors:n}){const l=a.allowed_addresses||[];return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>t({...a,allowed_addresses:[...l,""]}),onRemove:i=>t({...a,allowed_addresses:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,allowed_addresses:r})},renderRow:(i,s,r)=>e(C,{label:`Address ${s+1}`,name:`address-${s}`,value:i,onChange:c=>r(s,c),placeholder:"Wallet address",error:n[`allowed_addresses.${s}`],required:!0}),addLabel:"+ Add Address",error:n.allowed_addresses})})}function Ni({rules:a,onChange:t,errors:n}){const l=i=>s=>{t({...a,[i]:s})};return e("div",{class:"policy-form-fields",children:[e(C,{label:"Max Requests",name:"max_requests",type:"number",value:a.max_requests??100,onChange:l("max_requests"),error:n.max_requests,required:!0,min:1}),e(C,{label:"Window (seconds)",name:"window_seconds",type:"number",value:a.window_seconds??3600,onChange:l("window_seconds"),error:n.window_seconds,required:!0,min:1})]})}function Ei({rules:a,onChange:t,errors:n}){const l=i=>{const s={...a};i===""||i===void 0?delete s.maxAmount:s.maxAmount=i,t(s)};return e("div",{class:"policy-form-fields",children:[e(C,{label:"Max Amount (lamports/wei, optional)",name:"maxAmount",value:a.maxAmount??"",onChange:l,error:n.maxAmount,placeholder:"Leave empty for no limit"}),e(C,{label:"Block Unlimited Approvals",name:"blockUnlimited",type:"checkbox",value:a.blockUnlimited??!0,onChange:i=>t({...a,blockUnlimited:i})})]})}const Ai=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function Ci({rules:a,onChange:t,errors:n}){return e("div",{class:"policy-form-fields",children:e(C,{label:"Override Tier",name:"tier",type:"select",value:a.tier??"DELAY",onChange:l=>t({...a,tier:l}),options:Ai,error:n.tier})})}const Ii=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function Di({rules:a,onChange:t,errors:n}){const l=a.tokens||[];return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>t({...a,tokens:[...l,{address:"",symbol:"",chain:""}]}),onRemove:i=>t({...a,tokens:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,tokens:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(C,{label:`Address ${s+1}`,name:`token-addr-${s}`,value:i.address,onChange:c=>r(s,{...i,address:c}),placeholder:"Token mint/contract address",error:n[`tokens.${s}.address`],required:!0}),e(C,{label:"Symbol",name:`token-symbol-${s}`,value:i.symbol,onChange:c=>r(s,{...i,symbol:c}),placeholder:"e.g. USDC"}),e(C,{label:"Chain",name:`token-chain-${s}`,type:"select",value:i.chain,onChange:c=>{const p={...i,chain:c};c||delete p.chain,r(s,p)},options:Ii})]}),addLabel:"+ Add Token",error:n.tokens})})}const xi=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function Oi({rules:a,onChange:t,errors:n}){const l=a.contracts||[];return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>t({...a,contracts:[...l,{address:"",name:"",chain:""}]}),onRemove:i=>t({...a,contracts:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,contracts:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(C,{label:`Address ${s+1}`,name:`contract-addr-${s}`,value:i.address,onChange:c=>r(s,{...i,address:c}),placeholder:"Contract address",error:n[`contracts.${s}.address`],required:!0}),e(C,{label:"Name",name:`contract-name-${s}`,value:i.name,onChange:c=>r(s,{...i,name:c}),placeholder:"e.g. Uniswap Router"}),e(C,{label:"Chain",name:`contract-chain-${s}`,type:"select",value:i.chain,onChange:c=>{const p={...i,chain:c};c||delete p.chain,r(s,p)},options:xi})]}),addLabel:"+ Add Contract",error:n.contracts})})}function Li({rules:a,onChange:t,errors:n}){const l=a.methods||[],i=s=>{t({...a,methods:s})};return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>i([...l,{contractAddress:"",selectors:[""]}]),onRemove:s=>i(l.filter((r,c)=>c!==s)),onChange:(s,r)=>{const c=[...l];c[s]=r,i(c)},renderRow:(s,r,c)=>e("div",{style:{flex:1},children:[e(C,{label:`Contract Address ${r+1}`,name:`method-addr-${r}`,value:s.contractAddress,onChange:p=>c(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(Re,{items:s.selectors,onAdd:()=>c(r,{...s,selectors:[...s.selectors,""]}),onRemove:p=>c(r,{...s,selectors:s.selectors.filter((o,v)=>v!==p)}),onChange:(p,o)=>{const v=[...s.selectors];v[p]=o,c(r,{...s,selectors:v})},renderRow:(p,o,v)=>e(C,{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 Ri({rules:a,onChange:t,errors:n}){const l=a.spenders||[];return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>t({...a,spenders:[...l,{address:"",name:"",maxAmount:""}]}),onRemove:i=>t({...a,spenders:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,s.maxAmount||delete r[i].maxAmount,t({...a,spenders:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(C,{label:`Address ${s+1}`,name:`spender-addr-${s}`,value:i.address,onChange:c=>r(s,{...i,address:c}),placeholder:"Spender address",error:n[`spenders.${s}.address`],required:!0}),e(C,{label:"Name",name:`spender-name-${s}`,value:i.name,onChange:c=>r(s,{...i,name:c}),placeholder:"e.g. Uniswap"}),e(C,{label:"Max Amount",name:`spender-max-${s}`,value:i.maxAmount||"",onChange:c=>r(s,{...i,maxAmount:c}),placeholder:"Leave empty for unlimited",error:n[`spenders.${s}.maxAmount`]})]}),addLabel:"+ Add Spender",error:n.spenders})})}const Pi=Array.from({length:24},(a,t)=>({label:`${String(t).padStart(2,"0")}:00`,value:String(t)})),Mi=Array.from({length:24},(a,t)=>({label:`${String(t+1).padStart(2,"0")}:00`,value:String(t+1)})),Ui=[{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 Wi({rules:a,onChange:t,errors:n}){const l=a.allowed_hours||{start:0,end:24},i=a.allowed_days||[],s=c=>p=>{const o={...l,[c]:Number(p)};t({...a,allowed_hours:o})},r=c=>{const p=i.includes(c)?i.filter(o=>o!==c):[...i,c].sort((o,v)=>o-v);t({...a,allowed_days:p})};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Allowed Hours"}),e("div",{class:"policy-form-grid",children:[e(C,{label:"Start Hour",name:"allowed_hours_start",type:"select",value:String(l.start),onChange:s("start"),options:Pi,error:n.allowed_hours}),e(C,{label:"End Hour",name:"allowed_hours_end",type:"select",value:String(l.end),onChange:s("end"),options:Mi})]}),e("h4",{children:"Allowed Days"}),e("div",{style:{display:"flex",gap:"0.75rem",flexWrap:"wrap"},children:Ui.map(c=>e("label",{style:{display:"flex",alignItems:"center",gap:"0.25rem",cursor:"pointer"},children:[e("input",{type:"checkbox",checked:i.includes(c.value),onChange:()=>r(c.value)}),c.label]},c.value))}),n.allowed_days&&e("span",{class:"form-error",children:n.allowed_days})]})}const $i=[{label:"mainnet",value:"mainnet"},{label:"devnet",value:"devnet"},{label:"testnet",value:"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 Ki({rules:a,onChange:t,errors:n}){const l=a.networks||[];return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>t({...a,networks:[...l,{network:"mainnet",name:""}]}),onRemove:i=>t({...a,networks:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,networks:r})},renderRow:(i,s,r)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(C,{label:`Network ${s+1}`,name:`network-sel-${s}`,type:"select",value:i.network,onChange:c=>r(s,{...i,network:c}),options:$i,error:n[`networks.${s}.network`],required:!0}),e(C,{label:"Label",name:`network-name-${s}`,value:i.name,onChange:c=>r(s,{...i,name:c}),placeholder:"Optional label"})]}),addLabel:"+ Add Network",error:n.networks})})}function Fi({rules:a,onChange:t,errors:n}){const l=a.domains||[];return e("div",{class:"policy-form-fields",children:e(Re,{items:l,onAdd:()=>t({...a,domains:[...l,""]}),onRemove:i=>t({...a,domains:l.filter((s,r)=>r!==i)}),onChange:(i,s)=>{const r=[...l];r[i]=s,t({...a,domains:r})},renderRow:(i,s,r)=>e(C,{label:`Domain ${s+1}`,name:`domain-${s}`,value:i,onChange:c=>r(s,c),placeholder:"e.g. api.example.com or *.service.io",error:n[`domains.${s}`],required:!0}),addLabel:"+ Add Domain",error:n.domains})})}function Va({type:a,rules:t,onChange:n,errors:l,network:i}){switch(a){case"SPENDING_LIMIT":return e(Ti,{rules:t,onChange:n,errors:l,network:i});case"WHITELIST":return e(ki,{rules:t,onChange:n,errors:l});case"RATE_LIMIT":return e(Ni,{rules:t,onChange:n,errors:l});case"APPROVE_AMOUNT_LIMIT":return e(Ei,{rules:t,onChange:n,errors:l});case"APPROVE_TIER_OVERRIDE":return e(Ci,{rules:t,onChange:n,errors:l});case"ALLOWED_TOKENS":return e(Di,{rules:t,onChange:n,errors:l});case"CONTRACT_WHITELIST":return e(Oi,{rules:t,onChange:n,errors:l});case"METHOD_WHITELIST":return e(Li,{rules:t,onChange:n,errors:l});case"APPROVED_SPENDERS":return e(Ri,{rules:t,onChange:n,errors:l});case"TIME_RESTRICTION":return e(Wi,{rules:t,onChange:n,errors:l});case"ALLOWED_NETWORKS":return e(Ki,{rules:t,onChange:n,errors:l});case"X402_ALLOWED_DOMAINS":return e(Fi,{rules:t,onChange:n,errors:l});default:return e("p",{class:"policy-form-placeholder",children:"This policy type uses JSON editor. Toggle to JSON mode."})}}function ua(a){const t=typeof a=="string"?Number(a):a;return Number.isNaN(t)?String(a):t.toLocaleString("en-US")}function Hi(a){return a===86400?"1d":a%86400===0?`${a/86400}d`:a===3600?"1h":a%3600===0?`${a/3600}h`:a===60?"1m":a%60===0?`${a/60}m`:`${a}s`}const Zt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Bi(a){if(!a||a.length===0)return"";const t=[...a].sort((l,i)=>l-i);let n=!0;for(let l=1;l<t.length;l++)if(t[l]!==t[l-1]+1){n=!1;break}return n&&t.length>2?`${Zt[t[0]]}-${Zt[t[t.length-1]]}`:t.map(l=>Zt[l]??String(l)).join(", ")}function Ga(a){return String(a).padStart(2,"0")}function Vi({rules:a}){const t=Number(a.instant_max??0),n=Number(a.notify_max??0),l=Number(a.delay_max??0),i=Math.max(t,n,l,1),s=[{label:"Instant",value:a.instant_max,width:t/i*100,cls:"instant"},{label:"Notify",value:a.notify_max,width:n/i*100,cls:"notify"},{label:"Delay",value:a.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?ua(r.value):""})]},r.cls))})}function za(a){return a.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:2})}function Gi({rules:a}){const t=a.daily_limit_usd,n=a.monthly_limit_usd;return!t&&!n?null:e("div",{class:"cumulative-limits",children:[e("div",{class:"cumulative-limits-label",children:"Cumulative Limits"}),t&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Daily (24h)"}),e("span",{class:"cumulative-limit-value",children:["$",za(t)]})]}),n&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Monthly (30d)"}),e("span",{class:"cumulative-limit-value",children:["$",za(n)]})]})]})}const zi={INSTANT:"success",NOTIFY:"info",DELAY:"warning",APPROVAL:"danger"};function qi({type:a,rules:t}){switch(a){case"SPENDING_LIMIT":return e("div",{class:"spending-limit-summary",children:[e(Vi,{rules:t}),e(Gi,{rules:t})]});case"ALLOWED_TOKENS":{const n=t.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(B,{variant:"info",children:l.symbol||(l.address?l.address.slice(0,8)+"...":"?")},i))})}case"RATE_LIMIT":{const n=t.max_requests,l=t.window_seconds;return e("span",{class:"rules-vis-text",children:[n," req / ",Hi(l)]})}case"WHITELIST":{const n=t.allowed_addresses||[];return e(B,{variant:"neutral",children:[n.length," addresses"]})}case"TIME_RESTRICTION":{const n=t.allowed_days||[],l=t.allowed_hours,i=Bi(n),s=l?`${Ga(l.start)}:00-${Ga(l.end)}:00`:"";return e("span",{class:"rules-vis-text",children:[i," ",s]})}case"CONTRACT_WHITELIST":{const n=t.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(B,{variant:"neutral",children:s.name||(s.address?s.address.slice(0,8)+"...":"?")},r)),i>0&&e(B,{variant:"neutral",children:["+",i," more"]})]})}case"METHOD_WHITELIST":{const n=t.methods||[],l=n.length,i=n.reduce((s,r)=>s+(r.selectors?.length||0),0);return e(B,{variant:"neutral",children:[l," contracts, ",i," methods"]})}case"APPROVED_SPENDERS":{const n=t.spenders||[];return e(B,{variant:"neutral",children:[n.length," spenders"]})}case"APPROVE_AMOUNT_LIMIT":{const n=t.maxAmount,l=t.blockUnlimited;return n&&l?e("span",{class:"rules-vis-text",children:["Max: ",ua(n)," + Block unlimited"]}):n?e("span",{class:"rules-vis-text",children:["Max: ",ua(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=t.tier||"DELAY",l=zi[n]||"neutral";return e(B,{variant:l,children:n})}case"ALLOWED_NETWORKS":{const n=t.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(B,{variant:"info",children:s.network},r)),i>0&&e(B,{variant:"info",children:["+",i," more"]})]})}case"X402_ALLOWED_DOMAINS":{const n=t.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(B,{variant:"neutral",children:s},r)),i>0&&e(B,{variant:"neutral",children:["+",i," more"]})]})}default:{const n=JSON.stringify(t);return e("span",{class:"rules-summary",children:n.length>60?n.slice(0,60)+"...":n})}}}const Dn=[{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"}],Qt={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."},st={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:[]}};function Et(a,t){const n={};if(a==="SPENDING_LIMIT"){t.instant_max&&!/^\d+$/.test(t.instant_max)&&(n.instant_max="Positive integer required"),t.notify_max&&!/^\d+$/.test(t.notify_max)&&(n.notify_max="Positive integer required"),t.delay_max&&!/^\d+$/.test(t.delay_max)&&(n.delay_max="Positive integer required");const l=!!(t.instant_max||t.notify_max||t.delay_max),i=!!(t.instant_max_usd||t.notify_max_usd||t.delay_max_usd),s=t.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 P=parseFloat(N.instant_max||"0"),E=parseFloat(N.notify_max||"0"),y=parseFloat(N.delay_max||"0");P>E&&(n[`token_limits.${h}.instant_max`]="Must be <= Notify Max"),E>y&&(n[`token_limits.${h}.notify_max`]="Must be <= Delay Max")}}const c=Number(t.delay_seconds);(t.delay_seconds===void 0||t.delay_seconds===""||Number.isNaN(c)||c<60)&&(n.delay_seconds="Minimum 60 seconds");const p=t.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=t.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(a==="WHITELIST"){const l=t.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(a==="RATE_LIMIT"){const l=Number(t.max_requests);(!t.max_requests||Number.isNaN(l)||l<1||!Number.isInteger(l))&&(n.max_requests="Positive integer required");const i=Number(t.window_seconds);(!t.window_seconds||Number.isNaN(i)||i<1||!Number.isInteger(i))&&(n.window_seconds="Positive integer required")}else if(a==="APPROVE_AMOUNT_LIMIT")t.maxAmount&&!/^\d+$/.test(t.maxAmount)&&(n.maxAmount="Must be a positive integer string");else if(a==="ALLOWED_TOKENS"){const l=t.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(a==="CONTRACT_WHITELIST"){const l=t.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(a==="METHOD_WHITELIST"){const l=t.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,c)=>{(!r||r.trim()==="")&&(n[`methods.${s}.selectors.${c}`]="Selector required")})})}else if(a==="APPROVED_SPENDERS"){const l=t.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(a==="TIME_RESTRICTION"){(t.allowed_days||[]).length===0&&(n.allowed_days="At least one day required");const i=t.allowed_hours;i&&i.start>=i.end&&(n.allowed_hours="Start must be before end")}else if(a==="ALLOWED_NETWORKS"){const l=t.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(a==="X402_ALLOWED_DOMAINS"){const l=t.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 ji(a,t){if(!a)return"Global";const n=t.find(l=>l.id===a);return n?n.name:a.slice(0,8)+"..."}function ea(a){const t=Dn.find(n=>n.value===a);return t?t.label:a}const qa=[{key:"policies",label:"Policies"},{key:"defaults",label:"Defaults"}],ta=["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"];function Yi(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=async()=>{try{const o=await V(R.ADMIN_SETTINGS);a.value=o}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{l.value=!1}};F(()=>{i()},[]);const s=(o,v)=>{const h=String(v);t.value={...t.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([h])=>ta.includes(h)).map(([h,f])=>({key:h,value:f})),v=await ve(R.ADMIN_SETTINGS,{settings:o});a.value=v.settings,t.value={},T("success","Policy defaults saved and applied")}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{n.value=!1}},c=()=>{t.value={}};F(()=>(Ne({id:"policies-defaults",isDirty:()=>Object.keys(t.value).filter(o=>ta.includes(o)).length>0,save:r,discard:c}),()=>Se("policies-defaults")),[]);const p=Object.keys(t.value).filter(o=>ta.includes(o)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{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:c,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(C,{label:G("policy_defaults_delay_seconds"),name:"security.policy_defaults_delay_seconds",type:"number",value:Number(ee(a.value,t.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(C,{label:G("policy_defaults_approval_timeout"),name:"security.policy_defaults_approval_timeout",type:"number",value:Number(ee(a.value,t.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(C,{label:G("default_deny_tokens"),name:"policy.default_deny_tokens",type:"checkbox",value:Oe(a.value,t.value,"policy","default_deny_tokens"),onChange:o=>s("policy.default_deny_tokens",o),description:"Deny token transfers unless a matching whitelist policy exists"}),e(C,{label:G("default_deny_contracts"),name:"policy.default_deny_contracts",type:"checkbox",value:Oe(a.value,t.value,"policy","default_deny_contracts"),onChange:o=>s("policy.default_deny_contracts",o),description:"Deny contract calls unless a matching whitelist policy exists"}),e(C,{label:G("default_deny_spenders"),name:"policy.default_deny_spenders",type:"checkbox",value:Oe(a.value,t.value,"policy","default_deny_spenders"),onChange:o=>s("policy.default_deny_spenders",o),description:"Deny token approvals unless a matching whitelist policy exists"}),e(C,{label:G("default_deny_x402_domains"),name:"policy.default_deny_x402_domains",type:"checkbox",value:Oe(a.value,t.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("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 Xi(){const a=d("policies");F(()=>{const L=le.value;L&&L.tab&&(a.value=L.tab,setTimeout(()=>{_e.value=L.fieldName},100),le.value=null)},[le.value]);const t=d([]),n=d([]),l=d("__all__"),i=d(!1),s=d(!0),r=d(!1),c=d("SPENDING_LIMIT"),p=d(""),o=d(JSON.stringify(st.SPENDING_LIMIT,null,2)),v=d(st.SPENDING_LIMIT),h=d({}),f=d(!1),N=d(0),P=d(!0),E=d(""),y=d(null),D=d(!1),U=d(!1),K=d(null),I=d(""),A=d({}),k=d(!1),u=d({}),m=d(0),S=d(!0),g=d(null),O=d(!1),$=d(!1),q=d(null),H=d(!1),J=async()=>{try{const L=await V(R.WALLETS);t.value=L.items}catch(L){const ae=L instanceof _?L:new _(0,"UNKNOWN","Unknown error");T("error",W(ae.code))}finally{s.value=!1}},ce=async()=>{i.value=!0;try{let L=R.POLICIES;l.value!=="__all__"&&l.value!=="__global__"&&(L=`${R.POLICIES}?walletId=${l.value}`);const ae=await V(L);l.value==="__global__"?n.value=ae.filter(ge=>ge.walletId===null):n.value=ae}catch(L){const ae=L instanceof _?L:new _(0,"UNKNOWN","Unknown error");T("error",W(ae.code))}finally{i.value=!1}},pe=async()=>{y.value=null;let L;if(f.value)try{L=JSON.parse(o.value)}catch{y.value="Invalid JSON in rules field";return}else{const ae=Et(c.value,v.value);if(Object.keys(ae).length>0){h.value=ae;return}h.value={},L=v.value}D.value=!0;try{await ie(R.POLICIES,{walletId:p.value||void 0,type:c.value,rules:L,priority:N.value,enabled:P.value,network:E.value||void 0}),T("success","Policy created"),r.value=!1,c.value="SPENDING_LIMIT",p.value="",E.value="",o.value=JSON.stringify(st.SPENDING_LIMIT,null,2),v.value=st.SPENDING_LIMIT,h.value={},f.value=!1,N.value=0,P.value=!0,y.value=null,await ce()}catch(ae){const ge=ae instanceof _?ae:new _(0,"UNKNOWN","Unknown error");T("error",W(ge.code))}finally{D.value=!1}},re=L=>{K.value=L,I.value=JSON.stringify(L.rules,null,2),A.value={...L.rules},k.value=!1,u.value={},m.value=L.priority,S.value=L.enabled,g.value=null,U.value=!0},ne=async()=>{g.value=null;let L;if(k.value)try{L=JSON.parse(I.value)}catch{g.value="Invalid JSON in rules field";return}else{const ae=Et(K.value.type,A.value);if(Object.keys(ae).length>0){u.value=ae;return}u.value={},L=A.value}O.value=!0;try{await ve(R.POLICY(K.value.id),{rules:L,priority:m.value,enabled:S.value}),T("success","Policy updated"),U.value=!1,await ce()}catch(ae){const ge=ae instanceof _?ae:new _(0,"UNKNOWN","Unknown error");T("error",W(ge.code))}finally{O.value=!1}},we=()=>{if(!k.value)I.value=JSON.stringify(A.value,null,2);else try{A.value=JSON.parse(I.value),g.value=null}catch{g.value="Invalid JSON — cannot switch to form mode";return}k.value=!k.value},Pe=L=>{q.value=L,$.value=!0},Ee=async()=>{H.value=!0;try{await Ke(R.POLICY(q.value.id)),T("success","Policy deleted"),$.value=!1,await ce()}catch(L){const ae=L instanceof _?L:new _(0,"UNKNOWN","Unknown error");T("error",W(ae.code))}finally{H.value=!1}},Ae=L=>{const ae=L;c.value=ae;const ge=st[ae];ge&&(o.value=JSON.stringify(ge,null,2),v.value={...ge}),h.value={},f.value=!1},Te=()=>{if(!f.value)o.value=JSON.stringify(v.value,null,2);else try{v.value=JSON.parse(o.value),y.value=null}catch{y.value="Invalid JSON — cannot switch to form mode";return}f.value=!f.value};F(()=>{J()},[]),F(()=>{ce()},[l.value]);const tt=[{key:"type",header:"Type",render:L=>e(B,{variant:L.type==="SPENDING_LIMIT"?"success":"info",children:ea(L.type)})},{key:"walletId",header:"Wallet",render:L=>ji(L.walletId,t.value)},{key:"network",header:"Network",render:L=>L.network??"All"},{key:"rules",header:"Rules",render:L=>e(qi,{type:L.type,rules:L.rules})},{key:"priority",header:"Priority"},{key:"enabled",header:"Enabled",render:L=>e(B,{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:ae=>{ae.stopPropagation(),re(L)},children:"Edit"}),e(M,{size:"sm",variant:"danger",onClick:()=>Pe(L),children:"Delete"})]})}];return e("div",{class:"page",children:[e(et,{pageName:"Policies",tabName:qa.find(L=>L.key===a.value)?.label??"",onPageClick:()=>{a.value="policies"}}),e(Ve,{tabs:qa,activeTab:a.value,onTabChange:L=>{a.value=L}}),a.value==="policies"&&e(Y,{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"}),t.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(C,{label:"Type",name:"type",type:"select",value:c.value,onChange:Ae,options:Dn,description:Qt[c.value]??""}),e(C,{label:"Wallet",name:"walletId",type:"select",value:p.value,onChange:L=>{p.value=L},options:[{label:"Global (no wallet)",value:""},...t.value.map(L=>({label:`${L.name} (${L.chain}/${L.network})`,value:L.id}))]}),e(C,{label:"Network Scope",name:"network",value:E.value,onChange:L=>{E.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:Te,children:f.value?"Switch to Form":"JSON Direct Edit"})]}),f.value?e(C,{label:"",name:"rules",type:"textarea",value:o.value,onChange:L=>{o.value=L},error:y.value??void 0}):e(Va,{type:c.value,rules:v.value,onChange:L=>{v.value=L,Object.keys(h.value).length>0&&(h.value=Et(c.value,L))},errors:h.value,network:E.value})]}),e(C,{label:"Priority",name:"priority",type:"number",value:N.value,onChange:L=>{N.value=L},min:0,max:999}),e(C,{label:"Enabled",name:"enabled",type:"checkbox",value:P.value,onChange:L=>{P.value=L}}),e("div",{class:"inline-form-actions",children:[e(M,{onClick:pe,loading:D.value,children:"Create"}),e(M,{variant:"secondary",onClick:()=>{r.value=!1,y.value=null},children:"Cancel"})]})]}),e(He,{columns:tt,data:n.value,loading:i.value,emptyMessage:"No policies found"}),e(be,{open:U.value,title:"Edit Policy",onCancel:()=>{U.value=!1},onConfirm:ne,confirmText:"Save",loading:O.value,children:K.value&&e("div",{children:[e("div",{class:"policy-type-readonly",children:["Type: ",ea(K.value.type),Qt[K.value.type]&&e("span",{class:"form-description",children:Qt[K.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:we,children:k.value?"Switch to Form":"JSON Direct Edit"})]}),k.value?e("div",{class:"edit-rules-textarea",children:e(C,{label:"",name:"edit-rules",type:"textarea",value:I.value,onChange:L=>{I.value=L},error:g.value??void 0})}):e(Va,{type:K.value.type,rules:A.value,onChange:L=>{A.value=L,Object.keys(u.value).length>0&&(u.value=Et(K.value.type,L))},errors:u.value,network:K.value.network??""})]}),e(C,{label:"Priority",name:"edit-priority",type:"number",value:m.value,onChange:L=>{m.value=L},min:0,max:999}),e(C,{label:"Enabled",name:"edit-enabled",type:"checkbox",value:S.value,onChange:L=>{S.value=L}})]})}),e(be,{open:$.value,title:"Delete Policy",onCancel:()=>{$.value=!1},onConfirm:Ee,confirmText:"Delete",confirmVariant:"danger",loading:H.value,children:q.value&&e("p",{children:["Are you sure you want to delete this"," ",e("strong",{children:ea(q.value.type)})," policy? This action cannot be undone."]})})]}),a.value==="defaults"&&e(Yi,{})]})}function Ji(){return e(Zi,{})}function Zi(){const a=d([]),t=d(!0),n=d(!1),l=d(null),i=d("ADMIN"),s=d(!1),r=d(!1),c=d(null),p=d(!1),o=async()=>{t.value=!0;try{const y=await V(R.ADMIN_TELEGRAM_USERS);a.value=y.users}catch(y){const D=y instanceof _?y:new _(0,"UNKNOWN","Unknown error");T("error",W(D.code))}finally{t.value=!1}};F(()=>{o()},[]);const v=y=>{l.value=y,i.value="ADMIN",n.value=!0},h=async()=>{if(l.value){s.value=!0;try{await ve(R.ADMIN_TELEGRAM_USER(l.value.chat_id),{role:i.value}),T("success",`User approved as ${i.value}`),n.value=!1,l.value=null,await o()}catch(y){const D=y instanceof _?y:new _(0,"UNKNOWN","Unknown error");T("error",W(D.code))}finally{s.value=!1}}},f=y=>{c.value=y,r.value=!0},N=async()=>{if(c.value){p.value=!0;try{await Ke(R.ADMIN_TELEGRAM_USER(c.value.chat_id)),T("success","User deleted"),r.value=!1,c.value=null,await o()}catch(y){const D=y instanceof _?y:new _(0,"UNKNOWN","Unknown error");T("error",W(D.code))}finally{p.value=!1}}},P=y=>y==="PENDING"?"warning":y==="ADMIN"?"success":"info";return e("div",{class:"page",children:[e(He,{columns:[{key:"chat_id",header:"Chat ID",render:y=>String(y.chat_id)},{key:"username",header:"Username",render:y=>y.username??"-"},{key:"role",header:"Role",render:y=>e(B,{variant:P(y.role),children:y.role})},{key:"registered_at",header:"Registered",render:y=>ue(y.registered_at)},{key:"approved_at",header:"Approved",render:y=>y.approved_at?ue(y.approved_at):"-"},{key:"actions",header:"Actions",render:y=>e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[y.role==="PENDING"&&e(M,{size:"sm",variant:"primary",onClick:()=>v(y),children:"Approve"}),e(M,{size:"sm",variant:"danger",onClick:()=>f(y),children:"Delete"})]})}],data:a.value,loading:t.value,emptyMessage:"No Telegram users registered. Users appear here after sending /start to the bot."}),e(be,{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:y=>{i.value=y.target.value},children:[e("option",{value:"ADMIN",children:"ADMIN"}),e("option",{value:"READONLY",children:"READONLY"})]})]})]})}),e(be,{open:r.value,title:"Delete Telegram User",onCancel:()=>{r.value=!1,c.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 aa=20,ja=[{key:"channels",label:"Channels & Logs"},{key:"telegram",label:"Telegram Users"},{key:"settings",label:"Settings"},{key:"balance",label:"Balance Monitor"}],Qi=[{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 es(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=d([]),s=d(!1),r=async()=>{try{const f=await V(R.ADMIN_SETTINGS);a.value=f}catch(f){const N=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");T("error",W(N.code))}finally{l.value=!1}};F(()=>{r()},[]);const c=(f,N)=>{const P=String(N);t.value={...t.value,[f]:P}},p=async()=>{n.value=!0;try{const f=Object.entries(t.value).filter(([P])=>P.startsWith("notifications.")||P.startsWith("telegram.")).map(([P,E])=>({key:P,value:E})),N=await ve(R.ADMIN_SETTINGS,{settings:f});a.value=N.settings,t.value={},T("success","Notification settings saved and applied")}catch(f){const N=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");T("error",W(N.code))}finally{n.value=!1}},o=()=>{t.value={}};F(()=>(Ne({id:"notifications-settings",isDirty:()=>Object.keys(t.value).filter(f=>f.startsWith("notifications.")||f.startsWith("telegram.")).length>0,save:p,discard:o}),()=>Se("notifications-settings")),[]);const v=async()=>{s.value=!0,i.value=[];try{const f=await ie(R.ADMIN_NOTIFICATIONS_TEST,{});if(i.value=f.results,f.results.length===0)T("info","No notification channels configured");else{const N=f.results.every(P=>P.success);T(N?"success":"warning",N?"All test notifications sent":"Some channels failed")}}catch(f){const N=f instanceof _?f:new _(0,"UNKNOWN","Unknown error");T("error",W(N.code))}finally{s.value=!1}},h=Object.keys(t.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(Y,{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(C,{label:"Enabled",name:"notifications.enabled",type:"checkbox",value:Oe(a.value,t.value,"notifications","enabled"),onChange:f=>c("notifications.enabled",f),description:"Enable or disable notifications globally"})}),e(C,{label:G("locale"),name:"notifications.locale",type:"select",value:ee(a.value,t.value,"notifications","locale")||"en",onChange:f=>c("notifications.locale",f),options:[{label:"English",value:"en"},{label:"Korean",value:"ko"}],description:"Language for notification messages"})]}),e(We,{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(C,{label:G("telegram_bot_token"),name:"notifications.telegram_bot_token",type:"password",value:ee(a.value,t.value,"notifications","telegram_bot_token"),onChange:f=>c("notifications.telegram_bot_token",f),placeholder:ot(a.value,t.value,"notifications","telegram_bot_token")?"(configured)":"",description:"Bot token for Telegram notifications"}),e(C,{label:G("telegram_chat_id"),name:"notifications.telegram_chat_id",type:"text",value:ee(a.value,t.value,"notifications","telegram_chat_id"),onChange:f=>c("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(C,{label:G("bot_token"),name:"telegram.bot_token",type:"password",value:ee(a.value,t.value,"telegram","bot_token"),onChange:f=>c("telegram.bot_token",f),placeholder:ot(a.value,t.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(C,{label:"Locale",name:"telegram.locale",type:"select",value:ee(a.value,t.value,"telegram","locale")||"en",onChange:f=>c("telegram.locale",f),options:[{label:"English",value:"en"},{label:"한국어",value:"ko"}],description:"Language for Telegram bot messages"})]})]})]}),e(We,{legend:"Other Channels",description:"Discord, ntfy, 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:"ntfy:"})," Use any"," ",e("a",{href:"https://ntfy.sh",target:"_blank",rel:"noopener noreferrer",children:"ntfy server"})," (self-hosted or ntfy.sh)."," ",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(C,{label:G("discord_webhook_url"),name:"notifications.discord_webhook_url",type:"password",value:ee(a.value,t.value,"notifications","discord_webhook_url"),onChange:f=>c("notifications.discord_webhook_url",f),placeholder:ot(a.value,t.value,"notifications","discord_webhook_url")?"(configured)":"",description:"Webhook URL for Discord notifications"}),e(C,{label:G("ntfy_server"),name:"notifications.ntfy_server",type:"text",value:ee(a.value,t.value,"notifications","ntfy_server"),onChange:f=>c("notifications.ntfy_server",f),description:"Server URL for ntfy notifications"}),e(C,{label:G("ntfy_topic"),name:"notifications.ntfy_topic",type:"text",value:ee(a.value,t.value,"notifications","ntfy_topic"),onChange:f=>c("notifications.ntfy_topic",f),description:"Topic name for ntfy notifications"}),e(C,{label:"Slack Webhook URL",name:"notifications.slack_webhook_url",type:"password",value:ee(a.value,t.value,"notifications","slack_webhook_url"),onChange:f=>c("notifications.slack_webhook_url",f),placeholder:ot(a.value,t.value,"notifications","slack_webhook_url")?"(configured)":"",description:"Webhook URL for Slack notifications"}),e(C,{label:G("rate_limit_rpm"),name:"notifications.rate_limit_rpm",type:"number",value:Number(ee(a.value,t.value,"notifications","rate_limit_rpm"))||20,onChange:f=>c("notifications.rate_limit_rpm",f),min:1,max:1e3,description:"Max notifications per minute"})]})]}),e(We,{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"}]}],P=N.flatMap(I=>I.events.map(A=>A.event)).filter(I=>!f.has(I)),E=ee(a.value,t.value,"notifications","notify_events")||"[]";let y=[];try{const I=JSON.parse(E);Array.isArray(I)&&(y=I)}catch{}const D=y.length===0?P:y,U=(I,A)=>{const k=A?[...D,I]:D.filter(m=>m!==I),u=k.length===P.length&&P.every(m=>k.includes(m))?[]:k;c("notifications.notify_events",JSON.stringify(u))},K=(I,A)=>{const k=I.events.filter(S=>!f.has(S.event)).map(S=>S.event);let u;if(A)u=[...new Set([...D,...k])];else{const S=new Set(k);u=D.filter(g=>!S.has(g))}const m=u.length===P.length&&P.every(S=>u.includes(S))?[]:u;c("notifications.notify_events",JSON.stringify(m))};return e("div",{class:"event-filter-groups",children:N.map(I=>{const A=I.events.filter(m=>!f.has(m.event)),k=A.every(m=>D.includes(m.event)),u=A.some(m=>D.includes(m.event));return e("details",{class:"event-filter-group",open:!0,children:[e("summary",{class:"event-filter-group-header",children:[e("span",{class:"event-filter-group-label",children:I.label}),e("label",{class:"event-filter-group-all",onClick:m=>m.stopPropagation(),children:[e("input",{type:"checkbox",checked:k,ref:m=>{m&&(m.indeterminate=u&&!k)},onChange:m=>K(I,m.target.checked)})," All"]})]}),e("div",{class:"event-filter-events",children:I.events.map(m=>{const S=f.has(m.event);return e("label",{class:`event-filter-event ${S?"event-broadcast":""}`,children:[e("input",{type:"checkbox",checked:S||D.includes(m.event),disabled:S,onChange:g=>U(m.event,g.target.checked)}),e("code",{children:m.event}),e("span",{class:"event-desc",children:m.desc}),S&&e("span",{class:"event-broadcast-badge",children:"Always sent"})]},m.event)})})]},I.category)})})})(),e("div",{class:"settings-info-box",style:{marginTop:"0.5rem"},children:"Applies to all notification channels (Telegram, Discord, ntfy, Slack) and wallet app side channel. Broadcast events (Kill Switch, Auto Stop, Suspicious TX) always bypass the filter."})]}),e("div",{class:"notif-test-section",children:[e(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(B,{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 Ya={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 ts(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=async()=>{try{const v=await V(R.ADMIN_SETTINGS);a.value=v}catch(v){const h=v instanceof _?v:new _(0,"UNKNOWN","Unknown error");T("error",W(h.code))}finally{l.value=!1}};F(()=>{i()},[]);const s=(v,h)=>{const f=String(h);t.value={...t.value,[v]:f}},r=async()=>{n.value=!0;try{const v=Object.entries(t.value).filter(([f])=>f.startsWith("monitoring.")).map(([f,N])=>({key:f,value:N})),h=await ve(R.ADMIN_SETTINGS,{settings:v});a.value=h.settings,t.value={},T("success","Settings saved and applied")}catch(v){const h=v instanceof _?v:new _(0,"UNKNOWN","Unknown error");T("error",W(h.code))}finally{n.value=!1}},c=()=>{t.value={}};F(()=>(Ne({id:"notifications-balance",isDirty:()=>Object.keys(t.value).filter(v=>v.startsWith("monitoring.")).length>0,save:r,discard:c}),()=>Se("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(t.value).filter(v=>v.startsWith("monitoring.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{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:c,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(C,{label:G(v.key),name:`monitoring.${v.key}`,type:"checkbox",value:Oe(a.value,t.value,"monitoring",v.key),onChange:h=>s(`monitoring.${v.key}`,h),description:Ya[v.key]})},v.key):e(C,{label:G(v.key),name:`monitoring.${v.key}`,type:"number",value:Number(ee(a.value,t.value,"monitoring",v.key))||0,onChange:h=>s(`monitoring.${v.key}`,h),min:v.min,max:v.max,description:Ya[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 Xa(){const a=d("channels");F(()=>{const u=le.value;u&&u.tab&&(a.value=u.tab,setTimeout(()=>{_e.value=u.fieldName},100),le.value=null)},[le.value]);const t=d(null),n=d(!0),l=d(!1),i=d(null),s=d(null),r=d(null),c=d(!0),p=d(1),o=d(null),v=d({eventType:"",channel:"",status:"",since:"",until:""}),h=async()=>{try{const u=await V(R.ADMIN_NOTIFICATIONS_STATUS);t.value=u}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{n.value=!1}},f=async u=>{c.value=!0;try{const m=new URLSearchParams;m.set("page",String(u)),m.set("pageSize",String(aa));const S=v.value;if(S.eventType&&m.set("eventType",S.eventType),S.channel&&m.set("channel",S.channel),S.status&&m.set("status",S.status),S.since){const O=new Date(S.since);isNaN(O.getTime())||m.set("since",String(Math.floor(O.getTime()/1e3)))}if(S.until){const O=new Date(S.until);isNaN(O.getTime())||(O.setHours(23,59,59,999),m.set("until",String(Math.floor(O.getTime()/1e3))))}const g=await V(`${R.ADMIN_NOTIFICATIONS_LOG}?${m.toString()}`);r.value=g}catch(m){const S=m instanceof _?m:new _(0,"UNKNOWN","Unknown error");T("error",W(S.code))}finally{c.value=!1}},N=async()=>{l.value=!0,s.value=null;try{const m=(await ie(R.ADMIN_NOTIFICATIONS_TEST,{})).results;s.value=m,m.every(g=>g.success)?T("success","Test sent successfully"):T("warning","Some channels failed")}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{l.value=!1}},P=async u=>{i.value=u,s.value=null;try{const S=(await ie(R.ADMIN_NOTIFICATIONS_TEST,{channel:u})).results;s.value=S,S.every(O=>O.success)?T("success",`Test sent to ${u}`):T("warning",`${u} test failed`)}catch(m){const S=m instanceof _?m:new _(0,"UNKNOWN","Unknown error");T("error",W(S.code))}finally{i.value=null}},E=()=>{p.value>1&&(p.value-=1,f(p.value))},y=()=>{const u=r.value?Math.ceil(r.value.total/aa):1;p.value<u&&(p.value+=1,f(p.value))},D=u=>{o.value=o.value?.id===u.id?null:u},U=u=>{v.value=u,p.value=1,f(1)};F(()=>{h(),f(1);const u=setInterval(()=>f(p.value),3e4);return()=>clearInterval(u)},[]);const K=n.value&&!t.value,I=t.value?.channels.some(u=>u.enabled)??!1,A=r.value?Math.max(1,Math.ceil(r.value.total/aa)):1,k=[{key:"eventType",header:"Event Type"},{key:"walletId",header:"Wallet ID",render:u=>u.walletId?e("a",{href:`#/wallets/${u.walletId}`,class:"wallet-link",onClick:m=>m.stopPropagation(),title:u.walletId,children:[u.walletId.slice(0,8),"..."]}):"—"},{key:"channel",header:"Channel",render:u=>e("span",{style:{textTransform:"capitalize"},children:u.channel})},{key:"status",header:"Status",render:u=>e(B,{variant:u.status==="sent"?"success":"danger",children:u.status})},{key:"createdAt",header:"Time",render:u=>ue(u.createdAt)}];return e("div",{class:"page",children:[e(et,{pageName:"Notifications",tabName:ja.find(u=>u.key===a.value)?.label??"",onPageClick:()=>{a.value="channels"}}),e(Ve,{tabs:ja,activeTab:a.value,onTabChange:u=>{a.value=u}}),a.value==="telegram"?e(Ji,{}):a.value==="settings"?e(es,{}):a.value==="balance"?e(ts,{}):e(Y,{children:[e("h2",{children:"Channel Status"}),t.value&&!t.value.enabled&&e("div",{class:"notif-disabled-banner",children:["Notifications are disabled."," ",e("a",{href:"#",onClick:u=>{u.preventDefault(),a.value="settings"},children:"Enable them in the Settings tab"})]}),K?e("div",{class:"channel-grid",children:[1,2,3].map(u=>e("div",{class:"channel-card",children:e("div",{class:"stat-skeleton"})},u))}):e("div",{class:"channel-grid",children:t.value?.channels.map(u=>e("div",{class:"channel-card",children:e("div",{class:"channel-card-header",children:[e("span",{class:"channel-card-name",children:u.name}),e("div",{class:"channel-card-actions",children:[e(B,{variant:u.enabled?"success":"neutral",children:u.enabled?"Connected":"Not Configured"}),u.enabled&&e(M,{variant:"secondary",size:"sm",onClick:()=>P(u.name),loading:i.value===u.name,children:"Test"})]})]})},u.name))}),e("div",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-6)"},children:[e(M,{onClick:N,loading:l.value,disabled:!I,children:"Test All Channels"}),s.value&&e("div",{class:"test-results",children:s.value.map(u=>e("div",{class:"test-result-item",children:[e("span",{class:u.success?"test-result-success":"test-result-failure",children:u.success?"✓":"✗"}),e("span",{style:{textTransform:"capitalize"},children:u.channel}),!u.success&&u.error&&e("span",{class:"test-result-failure",children:[" - ",u.error]})]},u.channel))})]}),e("h2",{children:"Delivery Log"}),e(Gt,{fields:Qi,values:v.value,onChange:U,syncUrl:!1}),e(He,{columns:k,data:r.value?.logs??[],loading:c.value,emptyMessage:"No notification logs",onRowClick:D}),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 ",A,r.value?` (${r.value.total} total)`:""]}),e("div",{class:"pagination-buttons",children:[e(M,{variant:"secondary",size:"sm",onClick:E,disabled:p.value<=1,children:"Previous"}),e(M,{variant:"secondary",size:"sm",onClick:y,disabled:p.value>=A,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 na=[{key:"killswitch",label:"Kill Switch"},{key:"autostop",label:"AutoStop Rules"},{key:"jwt",label:"Invalidate Sessions"},{key:"password",label:"Master Password"}];function as(){const a=d(null),t=d(!0),n=d(!1),l=async()=>{try{const h=await V(R.ADMIN_KILL_SWITCH);a.value=h}catch(h){const f=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");T("error",W(f.code))}finally{t.value=!1}};F(()=>{l()},[]);const i=async()=>{n.value=!0;try{await ie(R.ADMIN_KILL_SWITCH),T("success","Kill switch activated - all operations suspended"),await l()}catch(h){const f=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");T("error",W(f.code))}finally{n.value=!1}},s=async()=>{n.value=!0;try{await ie(R.ADMIN_KILL_SWITCH_ESCALATE),T("success","Kill switch escalated to LOCKED"),await l()}catch(h){const f=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");T("error",W(f.code))}finally{n.value=!1}},r=async()=>{n.value=!0;try{await ie(R.ADMIN_RECOVER),T("success","Kill switch recovered - operations resumed"),await l()}catch(h){const f=h instanceof _?h:new _(0,"UNKNOWN","Unknown error");T("error",W(f.code))}finally{n.value=!1}},c=a.value,p=c?.state==="ACTIVE",o=c?.state==="SUSPENDED",v=c?.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:t.value?e("span",{children:"Loading..."}):c?e(Y,{children:[e("div",{class:"ks-state-card",style:{marginBottom:"var(--space-4)"},children:[e(B,{variant:p?"success":v?"danger":"warning",children:c.state}),!p&&c.activatedAt&&e("span",{class:"ks-state-info",children:["Since ",ue(c.activatedAt),c.activatedBy?` by ${c.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(Y,{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 ns(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=async()=>{try{const o=await V(R.ADMIN_SETTINGS);a.value=o}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{l.value=!1}};F(()=>{i()},[]);const s=(o,v)=>{const h=String(v);t.value={...t.value,[o]:h}},r=async()=>{n.value=!0;try{const o=Object.entries(t.value).filter(([h])=>h.startsWith("autostop.")).map(([h,f])=>({key:h,value:f})),v=await ve(R.ADMIN_SETTINGS,{settings:o});a.value=v.settings,t.value={},T("success","AutoStop settings saved and applied")}catch(o){const v=o instanceof _?o:new _(0,"UNKNOWN","Unknown error");T("error",W(v.code))}finally{n.value=!1}},c=()=>{t.value={}};F(()=>(Ne({id:"security-autostop",isDirty:()=>Object.keys(t.value).filter(o=>o.startsWith("autostop.")).length>0,save:r,discard:c}),()=>Se("security-autostop")),[]);const p=Object.keys(t.value).filter(o=>o.startsWith("autostop.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{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:c,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(C,{label:G("enabled"),name:"autostop.enabled",type:"checkbox",value:Oe(a.value,t.value,"autostop","enabled"),onChange:o=>s("autostop.enabled",o),description:"Enable or disable AutoStop protection rules"})}),e(We,{legend:"Activity Detection",description:"Detects failures and unusual transaction patterns",children:e("div",{class:"settings-fields-grid",children:[e(C,{label:G("consecutive_failures_threshold"),name:"autostop.consecutive_failures_threshold",type:"number",value:Number(ee(a.value,t.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(C,{label:G("unusual_activity_threshold"),name:"autostop.unusual_activity_threshold",type:"number",value:Number(ee(a.value,t.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(C,{label:G("unusual_activity_window_sec"),name:"autostop.unusual_activity_window_sec",type:"number",value:Number(ee(a.value,t.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(We,{legend:"Idle Detection",description:"Monitors inactivity and revokes idle sessions",children:e("div",{class:"settings-fields-grid",children:[e(C,{label:G("idle_timeout_sec"),name:"autostop.idle_timeout_sec",type:"number",value:Number(ee(a.value,t.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(C,{label:G("idle_check_interval_sec"),name:"autostop.idle_check_interval_sec",type:"number",value:Number(ee(a.value,t.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 ls(){const a=d(!1),t=d(!1),n=async()=>{t.value=!0;try{await ie(R.ADMIN_ROTATE_SECRET),a.value=!1,T("success","All session tokens invalidated. Old tokens remain valid for 5 minutes.")}catch(l){const i=l instanceof _?l:new _(0,"UNKNOWN","Unknown error");T("error",W(i.code))}finally{t.value=!1}};return e(Y,{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:()=>{a.value=!0},children:"Invalidate All Tokens"})})]}),e(be,{open:a.value,title:"Invalidate All Session Tokens",onCancel:()=>{a.value=!1},onConfirm:n,confirmText:"Invalidate",confirmVariant:"primary",loading:t.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 is(){const a=d(""),t=d(""),n=d(""),l=d(!1),i=d(null),s=()=>t.value.length<8?(i.value="New password must be at least 8 characters.",!1):t.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 ve(R.ADMIN_MASTER_PASSWORD,{newPassword:t.value}),T("success","Master password changed. Please log in again."),a.value="",t.value="",n.value="",setTimeout(()=>Bt(),500)}catch(c){const p=c instanceof _?c:new _(0,"UNKNOWN","Unknown error");T("error",W(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(C,{label:"Current Password",name:"current-password",type:"password",value:a.value,onChange:c=>{a.value=String(c)}}),e(C,{label:"New Password",name:"new-password",type:"password",value:t.value,onChange:c=>{t.value=String(c)},description:"Minimum 8 characters"}),e(C,{label:"Confirm New Password",name:"confirm-password",type:"password",value:n.value,onChange:c=>{n.value=String(c)}}),e("div",{children:e(M,{variant:"primary",onClick:r,loading:l.value,disabled:!a.value||!t.value||!n.value,children:"Change Password"})})]})]})]})}function ss(){const a=(()=>{const l=location.hash,i=l.indexOf("?");if(i>=0){const r=new URLSearchParams(l.slice(i+1)).get("tab");if(r&&na.some(c=>c.key===r))return r}return"killswitch"})(),t=d(a);F(()=>{const l=le.value;l&&l.tab&&(t.value=l.tab,setTimeout(()=>{_e.value=l.fieldName},100),le.value=null)},[le.value]);const n=na.find(l=>l.key===t.value)?.label??"";return e("div",{class:"page",children:[e(et,{pageName:"Security",tabName:n,onPageClick:()=>{t.value="killswitch"}}),e(Ve,{tabs:na,activeTab:t.value,onTabChange:l=>{t.value=l}}),t.value==="killswitch"&&e(as,{}),t.value==="autostop"&&e(ns,{}),t.value==="jwt"&&e(ls,{}),t.value==="password"&&e(is,{})]})}const At=[{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 rs({value:a,onChange:t,name:n}){const l=d(""),i=d(!1),s=d(null),r=d(!1),c=gt(null),p=Ht(()=>{const v=l.value.toLowerCase();return v?At.filter(h=>h.code.toLowerCase().includes(v)||h.name.toLowerCase().includes(v)||h.symbol.includes(v)):At});F(()=>{if(a==="USD"){s.value="1 USD = $1.00";return}r.value=!0,V(`${R.ADMIN_FOREX_RATES}?currencies=${a}`).then(v=>{const h=v.rates[a];s.value=h?.preview??null}).catch(()=>{s.value=null}).finally(()=>{r.value=!1})},[a]),F(()=>{const v=h=>{c.current&&!c.current.contains(h.target)&&(i.value=!1,l.value="")};return document.addEventListener("mousedown",v),()=>document.removeEventListener("mousedown",v)},[]);const o=At.find(v=>v.code===a)??At[0];return e("div",{class:"currency-select",ref:c,children:[n&&e("input",{type:"hidden",name:n,value:a}),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===a?"currency-select-option--active":""}`,onClick:()=>{t(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 os=["display.","daemon.","oracle.","signing_sdk.","gas_condition."],cs=new Set(["security.rate_limit_global_ip_rpm"]);function la(a){return os.some(t=>a.startsWith(t))||cs.has(a)}function ds(){const a=d({}),t=d({}),n=d(!1),l=d(!0),i=d([]),s=d(!0);d(null),d(""),d(!1);const r=d(!1),c=d(!1),p=d(""),o=d(!1),v=async()=>{try{const g=await V(R.ADMIN_SETTINGS);a.value=g}catch(g){const O=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");T("error",W(O.code))}finally{l.value=!1}},h=async()=>{try{const g=await V(R.ADMIN_API_KEYS);i.value=g.keys}catch{}finally{s.value=!1}};F(()=>{v(),h()},[]),F(()=>{const g=le.value;g&&(setTimeout(()=>{_e.value=g.fieldName},100),le.value=null)},[le.value]);const f=(g,O)=>ee(a.value,t.value,g,O),N=(g,O)=>Oe(a.value,t.value,g,O),P=(g,O)=>ot(a.value,t.value,g,O),E=(g,O)=>{const $=String(O);t.value={...t.value,[g]:$}},y=async()=>{n.value=!0;try{const g=Object.entries(t.value).filter(([$])=>la($)).map(([$,q])=>({key:$,value:q})),O=await ve(R.ADMIN_SETTINGS,{settings:g});a.value=O.settings,t.value={},T("success","Settings saved and applied")}catch(g){const O=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");T("error",W(O.code))}finally{n.value=!1}},D=()=>{t.value={}};F(()=>(Ne({id:"system-settings",isDirty:()=>Object.keys(t.value).filter(g=>la(g)).length>0,save:y,discard:D}),()=>Se("system-settings")),[]);const U=async()=>{c.value=!0;try{await ie(R.ADMIN_SHUTDOWN),r.value=!1,p.value="",T("info","Shutdown initiated"),o.value=!0}catch(g){const O=g instanceof _?g:new _(0,"UNKNOWN","Unknown error");T("error",W(O.code))}finally{c.value=!1}},K=Object.keys(t.value).filter(g=>la(g)).length;function I(){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(C,{label:"Cross Validation Threshold (%)",name:"oracle.cross_validation_threshold",type:"number",value:Number(f("oracle","cross_validation_threshold"))||5,onChange:g=>E("oracle.cross_validation_threshold",g),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(C,{label:"CoinGecko API Key",name:"oracle.coingecko_api_key",type:"password",value:P("oracle","coingecko_api_key")?"••••••••":"",onChange:g=>E("oracle.coingecko_api_key",g),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 A(){const g=_e.value==="display.currency";return F(()=>{if(g){const O=document.querySelector('[name="display.currency"]');O&&O.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const $=setTimeout(()=>{_e.value=""},2500);return()=>clearTimeout($)}},[g]),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${g?" form-field--highlight":""}`,children:[e("label",{children:G("currency")}),e(rs,{name:"display.currency",value:f("display","currency")||"USD",onChange:O=>E("display.currency",O)})]})}),e("div",{class:"settings-info-box",children:"All USD amounts in the dashboard, notifications, and API responses will be converted to the selected currency. Policy evaluation always uses USD. The “≈” prefix indicates an approximate conversion."})]})]})}function k(){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(C,{label:G("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:g=>E("security.rate_limit_global_ip_rpm",g),min:10,description:"Maximum API requests per minute from a single IP address"})})})]})}function u(){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(C,{label:G("log_level"),name:"daemon.log_level",type:"select",value:f("daemon","log_level")||"info",onChange:g=>E("daemon.log_level",g),options:[{label:"debug",value:"debug"},{label:"info",value:"info"},{label:"warn",value:"warn"},{label:"error",value:"error"}],description:"Daemon logging verbosity level"})})})]})}function m(){return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Signing SDK"}),e("p",{class:"settings-description",children:"Configure the Wallet Signing SDK for owner approval via mobile wallet app"})]}),e("div",{class:"settings-category-body",children:[e("div",{class:"settings-fields-grid",children:[e(C,{label:"SDK Enabled",name:"signing_sdk.enabled",type:"select",value:f("signing_sdk","enabled")||"false",onChange:g=>E("signing_sdk.enabled",g),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable Signing SDK for wallet app approval"}),e(C,{label:G("request_expiry_min"),name:"signing_sdk.request_expiry_min",type:"number",value:Number(f("signing_sdk","request_expiry_min"))||30,onChange:g=>E("signing_sdk.request_expiry_min",g),min:1,max:1440,description:"Minutes before a sign request expires"}),e(C,{label:G("preferred_channel"),name:"signing_sdk.preferred_channel",type:"select",value:f("signing_sdk","preferred_channel")||"ntfy",onChange:g=>E("signing_sdk.preferred_channel",g),options:[{label:"ntfy",value:"ntfy"},{label:"Telegram",value:"telegram"}],description:"Preferred signing channel for SDK requests"}),e(C,{label:G("preferred_wallet"),name:"signing_sdk.preferred_wallet",type:"text",value:f("signing_sdk","preferred_wallet"),onChange:g=>E("signing_sdk.preferred_wallet",g),placeholder:"Optional wallet app name",description:"Preferred wallet app for deep linking"}),e(C,{label:G("ntfy_request_topic_prefix"),name:"signing_sdk.ntfy_request_topic_prefix",type:"text",value:f("signing_sdk","ntfy_request_topic_prefix"),onChange:g=>E("signing_sdk.ntfy_request_topic_prefix",g),description:"ntfy topic prefix for sign requests"}),e(C,{label:G("ntfy_response_topic_prefix"),name:"signing_sdk.ntfy_response_topic_prefix",type:"text",value:f("signing_sdk","ntfy_response_topic_prefix"),onChange:g=>E("signing_sdk.ntfy_response_topic_prefix",g),description:"ntfy topic prefix for sign responses"})]}),e("div",{class:"settings-info-box",children:"Enable the Signing SDK to allow wallet owners to approve/reject transactions from their mobile wallet app. Requires a signing channel (ntfy or Telegram) to deliver sign requests."}),e("div",{class:"settings-subgroup",style:{marginTop:"1rem",borderTop:"1px solid var(--border)",paddingTop:"1rem"},children:[e("div",{class:"settings-subgroup-title",children:"Wallet App Notifications"}),e("p",{class:"settings-description",style:{marginBottom:"0.75rem"},children:"Push notifications to wallet apps via ntfy side channel."}),e("div",{class:"settings-fields-grid",children:e("div",{class:"settings-field-full",children:e(C,{label:"Notifications Enabled",name:"signing_sdk.notifications_enabled",type:"checkbox",value:N("signing_sdk","notifications_enabled"),onChange:g=>E("signing_sdk.notifications_enabled",g),description:"Push event notifications to wallet apps"})})}),e("div",{class:"settings-info-box",style:{marginTop:"0.5rem"},children:"Category filtering is configured in Notifications > Settings."})]})]})]})}function S(){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(C,{label:"Gas Condition Enabled",name:"gas_condition.enabled",type:"select",value:f("gas_condition","enabled")||"true",onChange:g=>E("gas_condition.enabled",g),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable gas conditional execution for agents"}),e(C,{label:G("poll_interval_sec"),name:"gas_condition.poll_interval_sec",type:"number",value:Number(f("gas_condition","poll_interval_sec"))||30,onChange:g=>E("gas_condition.poll_interval_sec",g),min:10,max:300,description:"How often to check gas prices (seconds)"}),e(C,{label:G("default_timeout_sec"),name:"gas_condition.default_timeout_sec",type:"number",value:Number(f("gas_condition","default_timeout_sec"))||3600,onChange:g=>E("gas_condition.default_timeout_sec",g),min:60,max:86400,description:"Default wait timeout when not specified in request (seconds)"}),e(C,{label:G("max_timeout_sec"),name:"gas_condition.max_timeout_sec",type:"number",value:Number(f("gas_condition","max_timeout_sec"))||86400,onChange:g=>E("gas_condition.max_timeout_sec",g),min:60,max:86400,description:"Maximum allowed timeout for gas conditions (seconds)"}),e(C,{label:G("max_pending_count"),name:"gas_condition.max_pending_count",type:"number",value:Number(f("gas_condition","max_pending_count"))||100,onChange:g=>E("gas_condition.max_pending_count",g),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."})]})]})}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."})]}),K>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[K," unsaved change",K>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:y,loading:n.value,children:"Save"})]})]}),l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(Y,{children:[e(I,{}),e(A,{}),e(k,{}),e(u,{}),e(m,{}),e(S,{})]}),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(be,{open:r.value,title:"Shutdown Daemon",onCancel:()=>{r.value=!1,p.value=""},onConfirm:U,confirmText:"Shutdown",confirmVariant:"danger",confirmDisabled:p.value!=="SHUTDOWN",loading:c.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:g=>{p.value=g.target.value},placeholder:"SHUTDOWN"})]})]})]})}const Ja=[{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"}];function us(){const a=d([]),t=d({}),n=d([]),l=d(!0),i=d(null),s=d(""),r=d(!1),c=d(null),p=d({}),o=async()=>{try{const k=await V(R.ADMIN_SETTINGS);t.value=k}catch(k){const u=k instanceof _?k:new _(0,"UNKNOWN","Unknown error");T("error",W(u.code))}},v=async()=>{try{const k=await V(R.ADMIN_API_KEYS);n.value=k.keys}catch{}},h=async()=>{try{const k=await V(R.ACTIONS_PROVIDERS);a.value=k.providers??[]}catch{}},f=async()=>{l.value=!0,await Promise.all([o(),v(),h()]),l.value=!1};F(()=>{f()},[]);const N=async(k,u)=>{const m=`actions.${k}_enabled`;c.value=k;try{const S=await ve(R.ADMIN_SETTINGS,{settings:[{key:m,value:String(u)}]});t.value=S.settings,T("success",`${u?"Enabled":"Disabled"} ${k.replace(/_/g," ")}`)}catch(S){const g=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");T("error",W(g.code))}finally{c.value=null}},P=async k=>{r.value=!0;try{await ve(R.ADMIN_API_KEY(k),{apiKey:s.value}),T("success",`API key saved for ${k}`),i.value=null,s.value="",await v()}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}finally{r.value=!1}},E=async k=>{try{await Ke(R.ADMIN_API_KEY(k)),T("success",`API key deleted for ${k}`),await v()}catch(u){const m=u instanceof _?u:new _(0,"UNKNOWN","Unknown error");T("error",W(m.code))}},y=async(k,u)=>{const m=`actions.${k}`;try{const S=await ve(R.ADMIN_SETTINGS,{settings:[{key:m,value:u}]});t.value=S.settings;const g={...p.value};delete g[k],p.value=g,T("success","Setting updated")}catch(S){const g=S instanceof _?S:new _(0,"UNKNOWN","Unknown error");T("error",W(g.code))}};function D(k){const u=t.value.actions;return u?u[`${k}_enabled`]==="true":!1}function U(k){return a.value.some(u=>u.name.toLowerCase().replace(/[\s-]/g,"_")===k||u.name.toLowerCase().includes(k.replace(/_/g," ")))}function K(k){return n.value.find(u=>u.providerName===k||u.providerName.toLowerCase().replace(/[\s-]/g,"_")===k)}function I(k){return a.value.find(u=>u.name.toLowerCase().replace(/[\s-]/g,"_")===k||u.name.toLowerCase().includes(k.replace(/_/g," ")))}function A(k){const u=D(k.key),m=U(k.key);return u&&k.requiresApiKey&&!K(k.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:[Ja.map(k=>{const u=A(k),m=D(k.key),S=I(k.key),g=K(k.key),O=c.value===k.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:[k.name,S&&e(B,{variant:"info",children:S.version}),e(B,{variant:(k.chain==="solana","info"),children:k.chain})]}),e("p",{class:"settings-description",style:{marginTop:"var(--space-1)"},children:[k.description,k.docsUrl&&e(Y,{children:[" ","—"," ",e("a",{href:k.docsUrl,target:"_blank",rel:"noopener noreferrer",children:"Docs"})]})]})]}),e(B,{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(C,{label:"Enabled",name:`actions.${k.key}_enabled`,type:"checkbox",value:m,onChange:$=>N(k.key,!!$),disabled:O}),O&&e("span",{style:{fontSize:"var(--font-size-sm)",color:"var(--text-secondary)"},children:"Saving..."})]}),k.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===k.key?e("div",{style:{display:"flex",alignItems:"flex-end",gap:"var(--space-2)"},children:[e(C,{label:"API Key",type:"password",name:`apikey-${k.key}`,value:s.value,onChange:$=>{s.value=String($)},placeholder:"Enter API key"}),e(M,{onClick:()=>P(k.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:g?.hasKey?g.maskedKey:"Not set"}),e(M,{variant:"ghost",onClick:()=>{i.value=k.key,s.value=""},size:"sm",children:g?.hasKey?"Update":"Set"}),g?.hasKey&&e(M,{variant:"danger",onClick:()=>E(k.key),size:"sm",children:"Delete"})]})]}),k.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($=>{const q=t.value.actions,H=p.value[$]??q?.[$]??"";return e("div",{style:{marginBottom:"var(--space-2)"},onBlur:()=>{const J=p.value[$];J!==void 0&&y($,J)},children:e(C,{label:G($),name:`actions.${$}`,type:"text",value:H,onChange:J=>{p.value={...p.value,[$]:String(J)}}})},$)})]}),m&&S&&S.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:"Chain"}),e("th",{children:"Risk Level"}),e("th",{children:"Default Tier"})]})}),e("tbody",{children:S.actions.map($=>e("tr",{children:[e("td",{children:$.name}),e("td",{children:e(B,{variant:"info",children:$.chain})}),e("td",{children:$.riskLevel}),e("td",{children:$.defaultTier})]},$.name))})]})]})]})]},k.key)}),Ja.length===0&&e("div",{class:"empty-state",children:e("p",{children:"No action providers available."})})]})}function xn(a){const t=a.slice(1)||"/dashboard",n=t.indexOf("?");return n>=0?t.slice(0,n):t}const De=me(xn(window.location.hash)),Ct=me(!1);window.addEventListener("hashchange",()=>{De.value=xn(window.location.hash)});const vs={"/dashboard":"Dashboard","/wallets":"Wallets","/transactions":"Transactions","/sessions":"Sessions","/tokens":"Token Registry","/actions":"Actions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"},hs={"/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","/actions":"Manage DeFi action providers and API keys","/policies":"Configure transaction policies and rules","/notifications":"Channel status, delivery logs, and settings","/security":"Emergency controls and automatic protection rules","/system":"API keys, display preferences, and daemon configuration"};function ps(a){return a.startsWith("/wallets/")?"Wallet Detail":vs[a]??"Dashboard"}function Za(a){return hs[a]}const ms=[{path:"/dashboard",label:"Dashboard"},{path:"/wallets",label:"Wallets"},{path:"/transactions",label:"Transactions"},{path:"/sessions",label:"Sessions"},{path:"/tokens",label:"Tokens"},{path:"/actions",label:"Actions"},{path:"/policies",label:"Policies"},{path:"/notifications",label:"Notifications"},{path:"/security",label:"Security"},{path:"/system",label:"System"}];function fs(){const a=De.value;return a==="/transactions"?e(Fa,{}):a==="/incoming"?(window.location.hash="#/transactions",e(Fa,{})):a==="/tokens"?e(gi,{}):a==="/actions"?e(us,{}):a==="/sessions"?e(bi,{}):a==="/policies"?e(Xi,{}):a==="/notifications"?e(Xa,{}):a==="/telegram-users"?(window.location.hash="#/notifications",e(Xa,{})):a==="/settings"?(window.location.hash="#/dashboard",e(La,{})):a==="/walletconnect"?(window.location.hash="#/wallets",e(Ua,{})):a==="/security"?e(ss,{}):a==="/system"?e(ds,{}):a.startsWith("/wallets")?e(Ua,{}):e(La,{})}function gs(){return F(()=>{const a=t=>{(t.metaKey||t.ctrlKey)&&t.key==="k"&&(t.preventDefault(),Ct.value=!Ct.value)};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[]),e("div",{class:"layout",children:[e("aside",{class:"sidebar",children:[e("div",{class:"sidebar-brand",children:"WAIaaS"}),e("nav",{class:"sidebar-nav",children:ms.map(a=>{const t=a.path==="/wallets"?De.value.startsWith("/wallets"):De.value===a.path;return e("a",{href:`#${a.path}`,class:`sidebar-link ${t?"active":""}`,onClick:n=>{En.value&&(n.preventDefault(),An({type:"nav",execute:()=>{window.location.hash=`#${a.path}`}}))},children:a.label})})})]}),e("main",{class:"main",children:[e("header",{class:"header",children:[e("div",{class:"header-left",children:[e("h1",{class:"header-title",children:ps(De.value)}),Za(De.value)&&e("p",{class:"header-subtitle",children:Za(De.value)})]}),e("div",{class:"header-actions",children:[e("button",{class:"btn-search",onClick:()=>{Ct.value=!0},title:"Search settings (Ctrl+K)",children:"🔍"}),e("button",{class:"btn-logout",onClick:()=>Bt(),children:"Logout"})]})]}),e("div",{class:"content",children:e(fs,{})})]}),e(bl,{open:Ct}),e(Tl,{})]})}const It={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 ys(){return e("div",{style:It.overlay,children:e("div",{style:It.content,children:[e("h1",{style:It.title,children:"Daemon Shutting Down"}),e("p",{style:It.message,children:"The daemon is shutting down. Please wait or restart."})]})})}function _s(){return dl.value?e(ys,{}):cl.value?e(Y,{children:[e(gs,{}),e(Pl,{})]}):e(ml,{})}Zn(e(_s,{}),document.getElementById("app"));
|