@waiaas/daemon 2.6.0-rc.9 → 2.6.0

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