@waiaas/daemon 2.5.0 → 2.6.0-rc

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 (142) hide show
  1. package/dist/api/middleware/error-handler.d.ts +1 -1
  2. package/dist/api/middleware/error-handler.js +2 -2
  3. package/dist/api/middleware/error-handler.js.map +1 -1
  4. package/dist/api/routes/admin.d.ts.map +1 -1
  5. package/dist/api/routes/admin.js +6 -30
  6. package/dist/api/routes/admin.js.map +1 -1
  7. package/dist/api/routes/incoming.d.ts +40 -0
  8. package/dist/api/routes/incoming.d.ts.map +1 -0
  9. package/dist/api/routes/incoming.js +281 -0
  10. package/dist/api/routes/incoming.js.map +1 -0
  11. package/dist/api/routes/openapi-schemas.d.ts +243 -2
  12. package/dist/api/routes/openapi-schemas.d.ts.map +1 -1
  13. package/dist/api/routes/openapi-schemas.js +77 -0
  14. package/dist/api/routes/openapi-schemas.js.map +1 -1
  15. package/dist/api/routes/wallets.d.ts +4 -0
  16. package/dist/api/routes/wallets.d.ts.map +1 -1
  17. package/dist/api/routes/wallets.js +173 -1
  18. package/dist/api/routes/wallets.js.map +1 -1
  19. package/dist/api/routes/x402.js +1 -1
  20. package/dist/api/routes/x402.js.map +1 -1
  21. package/dist/api/server.d.ts +4 -0
  22. package/dist/api/server.d.ts.map +1 -1
  23. package/dist/api/server.js +12 -0
  24. package/dist/api/server.js.map +1 -1
  25. package/dist/infrastructure/config/loader.d.ts +43 -0
  26. package/dist/infrastructure/config/loader.d.ts.map +1 -1
  27. package/dist/infrastructure/config/loader.js +13 -1
  28. package/dist/infrastructure/config/loader.js.map +1 -1
  29. package/dist/infrastructure/database/index.d.ts +1 -1
  30. package/dist/infrastructure/database/index.d.ts.map +1 -1
  31. package/dist/infrastructure/database/index.js +1 -1
  32. package/dist/infrastructure/database/index.js.map +1 -1
  33. package/dist/infrastructure/database/migrate.d.ts +2 -2
  34. package/dist/infrastructure/database/migrate.d.ts.map +1 -1
  35. package/dist/infrastructure/database/migrate.js +83 -5
  36. package/dist/infrastructure/database/migrate.js.map +1 -1
  37. package/dist/infrastructure/database/schema.d.ts +381 -1
  38. package/dist/infrastructure/database/schema.d.ts.map +1 -1
  39. package/dist/infrastructure/database/schema.js +42 -2
  40. package/dist/infrastructure/database/schema.js.map +1 -1
  41. package/dist/infrastructure/settings/hot-reload.d.ts +9 -0
  42. package/dist/infrastructure/settings/hot-reload.d.ts.map +1 -1
  43. package/dist/infrastructure/settings/hot-reload.js +34 -5
  44. package/dist/infrastructure/settings/hot-reload.js.map +1 -1
  45. package/dist/infrastructure/settings/setting-keys.d.ts +2 -2
  46. package/dist/infrastructure/settings/setting-keys.d.ts.map +1 -1
  47. package/dist/infrastructure/settings/setting-keys.js +12 -3
  48. package/dist/infrastructure/settings/setting-keys.js.map +1 -1
  49. package/dist/lifecycle/daemon.d.ts +3 -1
  50. package/dist/lifecycle/daemon.d.ts.map +1 -1
  51. package/dist/lifecycle/daemon.js +84 -4
  52. package/dist/lifecycle/daemon.js.map +1 -1
  53. package/dist/notifications/channels/discord.d.ts.map +1 -1
  54. package/dist/notifications/channels/discord.js +17 -8
  55. package/dist/notifications/channels/discord.js.map +1 -1
  56. package/dist/notifications/channels/format-utils.d.ts +11 -0
  57. package/dist/notifications/channels/format-utils.d.ts.map +1 -0
  58. package/dist/notifications/channels/format-utils.js +19 -0
  59. package/dist/notifications/channels/format-utils.js.map +1 -0
  60. package/dist/notifications/channels/ntfy.d.ts.map +1 -1
  61. package/dist/notifications/channels/ntfy.js +15 -2
  62. package/dist/notifications/channels/ntfy.js.map +1 -1
  63. package/dist/notifications/channels/slack.d.ts.map +1 -1
  64. package/dist/notifications/channels/slack.js +16 -7
  65. package/dist/notifications/channels/slack.js.map +1 -1
  66. package/dist/notifications/channels/telegram.d.ts.map +1 -1
  67. package/dist/notifications/channels/telegram.js +17 -5
  68. package/dist/notifications/channels/telegram.js.map +1 -1
  69. package/dist/notifications/notification-service.d.ts +14 -0
  70. package/dist/notifications/notification-service.d.ts.map +1 -1
  71. package/dist/notifications/notification-service.js +83 -2
  72. package/dist/notifications/notification-service.js.map +1 -1
  73. package/dist/services/incoming/__tests__/incoming-tx-monitor-service.test.d.ts +11 -0
  74. package/dist/services/incoming/__tests__/incoming-tx-monitor-service.test.d.ts.map +1 -0
  75. package/dist/services/incoming/__tests__/incoming-tx-monitor-service.test.js +432 -0
  76. package/dist/services/incoming/__tests__/incoming-tx-monitor-service.test.js.map +1 -0
  77. package/dist/services/incoming/__tests__/incoming-tx-queue.test.d.ts +12 -0
  78. package/dist/services/incoming/__tests__/incoming-tx-queue.test.d.ts.map +1 -0
  79. package/dist/services/incoming/__tests__/incoming-tx-queue.test.js +419 -0
  80. package/dist/services/incoming/__tests__/incoming-tx-queue.test.js.map +1 -0
  81. package/dist/services/incoming/__tests__/incoming-tx-workers.test.d.ts +14 -0
  82. package/dist/services/incoming/__tests__/incoming-tx-workers.test.d.ts.map +1 -0
  83. package/dist/services/incoming/__tests__/incoming-tx-workers.test.js +452 -0
  84. package/dist/services/incoming/__tests__/incoming-tx-workers.test.js.map +1 -0
  85. package/dist/services/incoming/__tests__/integration-pitfall.test.d.ts +17 -0
  86. package/dist/services/incoming/__tests__/integration-pitfall.test.d.ts.map +1 -0
  87. package/dist/services/incoming/__tests__/integration-pitfall.test.js +653 -0
  88. package/dist/services/incoming/__tests__/integration-pitfall.test.js.map +1 -0
  89. package/dist/services/incoming/__tests__/integration-resilience.test.d.ts +14 -0
  90. package/dist/services/incoming/__tests__/integration-resilience.test.d.ts.map +1 -0
  91. package/dist/services/incoming/__tests__/integration-resilience.test.js +501 -0
  92. package/dist/services/incoming/__tests__/integration-resilience.test.js.map +1 -0
  93. package/dist/services/incoming/__tests__/integration-wiring.test.d.ts +15 -0
  94. package/dist/services/incoming/__tests__/integration-wiring.test.d.ts.map +1 -0
  95. package/dist/services/incoming/__tests__/integration-wiring.test.js +355 -0
  96. package/dist/services/incoming/__tests__/integration-wiring.test.js.map +1 -0
  97. package/dist/services/incoming/__tests__/safety-rules.test.d.ts +10 -0
  98. package/dist/services/incoming/__tests__/safety-rules.test.d.ts.map +1 -0
  99. package/dist/services/incoming/__tests__/safety-rules.test.js +165 -0
  100. package/dist/services/incoming/__tests__/safety-rules.test.js.map +1 -0
  101. package/dist/services/incoming/__tests__/subscription-multiplexer.test.d.ts +2 -0
  102. package/dist/services/incoming/__tests__/subscription-multiplexer.test.d.ts.map +1 -0
  103. package/dist/services/incoming/__tests__/subscription-multiplexer.test.js +267 -0
  104. package/dist/services/incoming/__tests__/subscription-multiplexer.test.js.map +1 -0
  105. package/dist/services/incoming/incoming-tx-monitor-service.d.ts +98 -0
  106. package/dist/services/incoming/incoming-tx-monitor-service.d.ts.map +1 -0
  107. package/dist/services/incoming/incoming-tx-monitor-service.js +336 -0
  108. package/dist/services/incoming/incoming-tx-monitor-service.js.map +1 -0
  109. package/dist/services/incoming/incoming-tx-queue.d.ts +52 -0
  110. package/dist/services/incoming/incoming-tx-queue.d.ts.map +1 -0
  111. package/dist/services/incoming/incoming-tx-queue.js +109 -0
  112. package/dist/services/incoming/incoming-tx-queue.js.map +1 -0
  113. package/dist/services/incoming/incoming-tx-workers.d.ts +89 -0
  114. package/dist/services/incoming/incoming-tx-workers.d.ts.map +1 -0
  115. package/dist/services/incoming/incoming-tx-workers.js +176 -0
  116. package/dist/services/incoming/incoming-tx-workers.js.map +1 -0
  117. package/dist/services/incoming/index.d.ts +14 -0
  118. package/dist/services/incoming/index.d.ts.map +1 -0
  119. package/dist/services/incoming/index.js +11 -0
  120. package/dist/services/incoming/index.js.map +1 -0
  121. package/dist/services/incoming/safety-rules.d.ts +70 -0
  122. package/dist/services/incoming/safety-rules.d.ts.map +1 -0
  123. package/dist/services/incoming/safety-rules.js +68 -0
  124. package/dist/services/incoming/safety-rules.js.map +1 -0
  125. package/dist/services/incoming/subscription-multiplexer.d.ts +87 -0
  126. package/dist/services/incoming/subscription-multiplexer.d.ts.map +1 -0
  127. package/dist/services/incoming/subscription-multiplexer.js +169 -0
  128. package/dist/services/incoming/subscription-multiplexer.js.map +1 -0
  129. package/dist/services/signing-sdk/approval-channel-router.d.ts +1 -1
  130. package/dist/services/signing-sdk/approval-channel-router.d.ts.map +1 -1
  131. package/dist/services/signing-sdk/approval-channel-router.js +2 -3
  132. package/dist/services/signing-sdk/approval-channel-router.js.map +1 -1
  133. package/dist/services/signing-sdk/channels/wallet-notification-channel.js +1 -1
  134. package/dist/services/signing-sdk/channels/wallet-notification-channel.js.map +1 -1
  135. package/dist/services/x402/x402-domain-policy.d.ts +6 -1
  136. package/dist/services/x402/x402-domain-policy.d.ts.map +1 -1
  137. package/dist/services/x402/x402-domain-policy.js +6 -2
  138. package/dist/services/x402/x402-domain-policy.js.map +1 -1
  139. package/package.json +4 -4
  140. package/public/admin/assets/index-D06O_cSo.js +1 -0
  141. package/public/admin/index.html +1 -1
  142. package/public/admin/assets/index-BLLOYSZp.js +0 -1
@@ -0,0 +1 @@
1
+ var ut,H,ya,ga,we,Gt,ba,wa,Sa,Ut,Dt,Lt,He={},ka=[],an=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,vt=Array.isArray;function ve(a,t){for(var n in t)a[n]=t[n];return a}function $t(a){a&&a.parentNode&&a.parentNode.removeChild(a)}function nn(a,t,n){var l,i,s,o={};for(s in t)s=="key"?l=t[s]:s=="ref"?i=t[s]:o[s]=t[s];if(arguments.length>2&&(o.children=arguments.length>3?ut.call(arguments,2):n),typeof a=="function"&&a.defaultProps!=null)for(s in a.defaultProps)o[s]===void 0&&(o[s]=a.defaultProps[s]);return it(a,o,l,i,null)}function it(a,t,n,l,i){var s={type:a,props:t,key:n,ref:l,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:i??++ya,__i:-1,__u:0};return i==null&&H.vnode!=null&&H.vnode(s),s}function G(a){return a.children}function $e(a,t){this.props=a,this.context=t}function Le(a,t){if(t==null)return a.__?Le(a.__,a.__i+1):null;for(var n;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null)return n.__e;return typeof a.type=="function"?Le(a):null}function Na(a){var t,n;if((a=a.__)!=null&&a.__c!=null){for(a.__e=a.__c.base=null,t=0;t<a.__k.length;t++)if((n=a.__k[t])!=null&&n.__e!=null){a.__e=a.__c.base=n.__e;break}return Na(a)}}function jt(a){(!a.__d&&(a.__d=!0)&&we.push(a)&&!rt.__r++||Gt!=H.debounceRendering)&&((Gt=H.debounceRendering)||ba)(rt)}function rt(){for(var a,t,n,l,i,s,o,c=1;we.length;)we.length>c&&we.sort(wa),a=we.shift(),c=we.length,a.__d&&(n=void 0,l=void 0,i=(l=(t=a).__v).__e,s=[],o=[],t.__P&&((n=ve({},l)).__v=l.__v+1,H.vnode&&H.vnode(n),Kt(t.__P,n,l,t.__n,t.__P.namespaceURI,32&l.__u?[i]:null,s,i??Le(l),!!(32&l.__u),o),n.__v=l.__v,n.__.__k[n.__i]=n,Ca(s,n,o),l.__e=l.__=null,n.__e!=i&&Na(n)));rt.__r=0}function Ta(a,t,n,l,i,s,o,c,h,r,u){var d,m,p,E,N,b,I,x=l&&l.__k||ka,F=t.length;for(h=ln(n,t,x,h,F),d=0;d<F;d++)(p=n.__k[d])!=null&&(m=p.__i==-1?He:x[p.__i]||He,p.__i=d,b=Kt(a,p,m,i,s,o,c,h,r,u),E=p.__e,p.ref&&m.ref!=p.ref&&(m.ref&&Ft(m.ref,null,p),u.push(p.ref,p.__c||E,p)),N==null&&E!=null&&(N=E),(I=!!(4&p.__u))||m.__k===p.__k?h=Ea(p,h,a,I):typeof p.type=="function"&&b!==void 0?h=b:E&&(h=E.nextSibling),p.__u&=-7);return n.__e=N,h}function ln(a,t,n,l,i){var s,o,c,h,r,u=n.length,d=u,m=0;for(a.__k=new Array(i),s=0;s<i;s++)(o=t[s])!=null&&typeof o!="boolean"&&typeof o!="function"?(typeof o=="string"||typeof o=="number"||typeof o=="bigint"||o.constructor==String?o=a.__k[s]=it(null,o,null,null,null):vt(o)?o=a.__k[s]=it(G,{children:o},null,null,null):o.constructor===void 0&&o.__b>0?o=a.__k[s]=it(o.type,o.props,o.key,o.ref?o.ref:null,o.__v):a.__k[s]=o,h=s+m,o.__=a,o.__b=a.__b+1,c=null,(r=o.__i=sn(o,n,h,d))!=-1&&(d--,(c=n[r])&&(c.__u|=2)),c==null||c.__v==null?(r==-1&&(i>u?m--:i<u&&m++),typeof o.type!="function"&&(o.__u|=4)):r!=h&&(r==h-1?m--:r==h+1?m++:(r>h?m--:m++,o.__u|=4))):a.__k[s]=null;if(d)for(s=0;s<u;s++)(c=n[s])!=null&&(2&c.__u)==0&&(c.__e==l&&(l=Le(c)),Ia(c,c));return l}function Ea(a,t,n,l){var i,s;if(typeof a.type=="function"){for(i=a.__k,s=0;i&&s<i.length;s++)i[s]&&(i[s].__=a,t=Ea(i[s],t,n,l));return t}a.__e!=t&&(l&&(t&&a.type&&!t.parentNode&&(t=Le(a)),n.insertBefore(a.__e,t||null)),t=a.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function sn(a,t,n,l){var i,s,o,c=a.key,h=a.type,r=t[n],u=r!=null&&(2&r.__u)==0;if(r===null&&c==null||u&&c==r.key&&h==r.type)return n;if(l>(u?1:0)){for(i=n-1,s=n+1;i>=0||s<t.length;)if((r=t[o=i>=0?i--:s++])!=null&&(2&r.__u)==0&&c==r.key&&h==r.type)return o}return-1}function Yt(a,t,n){t[0]=="-"?a.setProperty(t,n??""):a[t]=n==null?"":typeof n!="number"||an.test(t)?n:n+"px"}function Ze(a,t,n,l,i){var s,o;e:if(t=="style")if(typeof n=="string")a.style.cssText=n;else{if(typeof l=="string"&&(a.style.cssText=l=""),l)for(t in l)n&&t in n||Yt(a.style,t,"");if(n)for(t in n)l&&n[t]==l[t]||Yt(a.style,t,n[t])}else if(t[0]=="o"&&t[1]=="n")s=t!=(t=t.replace(Sa,"$1")),o=t.toLowerCase(),t=o in a||t=="onFocusOut"||t=="onFocusIn"?o.slice(2):t.slice(2),a.l||(a.l={}),a.l[t+s]=n,n?l?n.u=l.u:(n.u=Ut,a.addEventListener(t,s?Lt:Dt,s)):a.removeEventListener(t,s?Lt:Dt,s);else{if(i=="http://www.w3.org/2000/svg")t=t.replace(/xlink(H|:h)/,"h").replace(/sName$/,"s");else if(t!="width"&&t!="height"&&t!="href"&&t!="list"&&t!="form"&&t!="tabIndex"&&t!="download"&&t!="rowSpan"&&t!="colSpan"&&t!="role"&&t!="popover"&&t in a)try{a[t]=n??"";break e}catch{}typeof n=="function"||(n==null||n===!1&&t[4]!="-"?a.removeAttribute(t):a.setAttribute(t,t=="popover"&&n==1?"":n))}}function Jt(a){return function(t){if(this.l){var n=this.l[t.type+a];if(t.t==null)t.t=Ut++;else if(t.t<n.u)return;return n(H.event?H.event(t):t)}}}function Kt(a,t,n,l,i,s,o,c,h,r){var u,d,m,p,E,N,b,I,x,F,V,k,W,P,_,L,Y,Q=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(h=!!(32&n.__u),s=[c=t.__e=n.__e]),(u=H.__b)&&u(t);e:if(typeof Q=="function")try{if(I=t.props,x="prototype"in Q&&Q.prototype.render,F=(u=Q.contextType)&&l[u.__c],V=u?F?F.props.value:u.__:l,n.__c?b=(d=t.__c=n.__c).__=d.__E:(x?t.__c=d=new Q(I,V):(t.__c=d=new $e(I,V),d.constructor=Q,d.render=on),F&&F.sub(d),d.state||(d.state={}),d.__n=l,m=d.__d=!0,d.__h=[],d._sb=[]),x&&d.__s==null&&(d.__s=d.state),x&&Q.getDerivedStateFromProps!=null&&(d.__s==d.state&&(d.__s=ve({},d.__s)),ve(d.__s,Q.getDerivedStateFromProps(I,d.__s))),p=d.props,E=d.state,d.__v=t,m)x&&Q.getDerivedStateFromProps==null&&d.componentWillMount!=null&&d.componentWillMount(),x&&d.componentDidMount!=null&&d.__h.push(d.componentDidMount);else{if(x&&Q.getDerivedStateFromProps==null&&I!==p&&d.componentWillReceiveProps!=null&&d.componentWillReceiveProps(I,V),t.__v==n.__v||!d.__e&&d.shouldComponentUpdate!=null&&d.shouldComponentUpdate(I,d.__s,V)===!1){for(t.__v!=n.__v&&(d.props=I,d.state=d.__s,d.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(ee){ee&&(ee.__=t)}),k=0;k<d._sb.length;k++)d.__h.push(d._sb[k]);d._sb=[],d.__h.length&&o.push(d);break e}d.componentWillUpdate!=null&&d.componentWillUpdate(I,d.__s,V),x&&d.componentDidUpdate!=null&&d.__h.push(function(){d.componentDidUpdate(p,E,N)})}if(d.context=V,d.props=I,d.__P=a,d.__e=!1,W=H.__r,P=0,x){for(d.state=d.__s,d.__d=!1,W&&W(t),u=d.render(d.props,d.state,d.context),_=0;_<d._sb.length;_++)d.__h.push(d._sb[_]);d._sb=[]}else do d.__d=!1,W&&W(t),u=d.render(d.props,d.state,d.context),d.state=d.__s;while(d.__d&&++P<25);d.state=d.__s,d.getChildContext!=null&&(l=ve(ve({},l),d.getChildContext())),x&&!m&&d.getSnapshotBeforeUpdate!=null&&(N=d.getSnapshotBeforeUpdate(p,E)),L=u,u!=null&&u.type===G&&u.key==null&&(L=Aa(u.props.children)),c=Ta(a,vt(L)?L:[L],t,n,l,i,s,o,c,h,r),d.base=t.__e,t.__u&=-161,d.__h.length&&o.push(d),b&&(d.__E=d.__=null)}catch(ee){if(t.__v=null,h||s!=null)if(ee.then){for(t.__u|=h?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;s[s.indexOf(c)]=null,t.__e=c}else{for(Y=s.length;Y--;)$t(s[Y]);xt(t)}else t.__e=n.__e,t.__k=n.__k,ee.then||xt(t);H.__e(ee,t,n)}else s==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=rn(n.__e,t,n,l,i,s,o,h,r);return(u=H.diffed)&&u(t),128&t.__u?void 0:c}function xt(a){a&&a.__c&&(a.__c.__e=!0),a&&a.__k&&a.__k.forEach(xt)}function Ca(a,t,n){for(var l=0;l<n.length;l++)Ft(n[l],n[++l],n[++l]);H.__c&&H.__c(t,a),a.some(function(i){try{a=i.__h,i.__h=[],a.some(function(s){s.call(i)})}catch(s){H.__e(s,i.__v)}})}function Aa(a){return typeof a!="object"||a==null||a.__b&&a.__b>0?a:vt(a)?a.map(Aa):ve({},a)}function rn(a,t,n,l,i,s,o,c,h){var r,u,d,m,p,E,N,b=n.props||He,I=t.props,x=t.type;if(x=="svg"?i="http://www.w3.org/2000/svg":x=="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((p=s[r])&&"setAttribute"in p==!!x&&(x?p.localName==x:p.nodeType==3)){a=p,s[r]=null;break}}if(a==null){if(x==null)return document.createTextNode(I);a=document.createElementNS(i,x,I.is&&I),c&&(H.__m&&H.__m(t,s),c=!1),s=null}if(x==null)b===I||c&&a.data==I||(a.data=I);else{if(s=s&&ut.call(a.childNodes),!c&&s!=null)for(b={},r=0;r<a.attributes.length;r++)b[(p=a.attributes[r]).name]=p.value;for(r in b)if(p=b[r],r!="children"){if(r=="dangerouslySetInnerHTML")d=p;else if(!(r in I)){if(r=="value"&&"defaultValue"in I||r=="checked"&&"defaultChecked"in I)continue;Ze(a,r,null,p,i)}}for(r in I)p=I[r],r=="children"?m=p:r=="dangerouslySetInnerHTML"?u=p:r=="value"?E=p:r=="checked"?N=p:c&&typeof p!="function"||b[r]===p||Ze(a,r,p,b[r],i);if(u)c||d&&(u.__html==d.__html||u.__html==a.innerHTML)||(a.innerHTML=u.__html),t.__k=[];else if(d&&(a.innerHTML=""),Ta(t.type=="template"?a.content:a,vt(m)?m:[m],t,n,l,x=="foreignObject"?"http://www.w3.org/1999/xhtml":i,s,o,s?s[0]:n.__k&&Le(n,0),c,h),s!=null)for(r=s.length;r--;)$t(s[r]);c||(r="value",x=="progress"&&E==null?a.removeAttribute("value"):E!=null&&(E!==a[r]||x=="progress"&&!E||x=="option"&&E!=b[r])&&Ze(a,r,E,b[r],i),r="checked",N!=null&&N!=a[r]&&Ze(a,r,N,b[r],i))}return a}function Ft(a,t,n){try{if(typeof a=="function"){var l=typeof a.__u=="function";l&&a.__u(),l&&t==null||(a.__u=a(t))}else a.current=t}catch(i){H.__e(i,n)}}function Ia(a,t,n){var l,i;if(H.unmount&&H.unmount(a),(l=a.ref)&&(l.current&&l.current!=a.__e||Ft(l,null,t)),(l=a.__c)!=null){if(l.componentWillUnmount)try{l.componentWillUnmount()}catch(s){H.__e(s,t)}l.base=l.__P=null}if(l=a.__k)for(i=0;i<l.length;i++)l[i]&&Ia(l[i],t,n||typeof a.type!="function");n||$t(a.__e),a.__c=a.__=a.__e=void 0}function on(a,t,n){return this.constructor(a,n)}function cn(a,t,n){var l,i,s,o;t==document&&(t=document.documentElement),H.__&&H.__(a,t),i=(l=!1)?null:t.__k,s=[],o=[],Kt(t,a=t.__k=nn(G,null,[a]),i||He,He,t.namespaceURI,i?null:t.firstChild?ut.call(t.childNodes):null,s,i?i.__e:t.firstChild,l,o),Ca(s,a,o)}ut=ka.slice,H={__e:function(a,t,n,l){for(var i,s,o;t=t.__;)if((i=t.__c)&&!i.__)try{if((s=i.constructor)&&s.getDerivedStateFromError!=null&&(i.setState(s.getDerivedStateFromError(a)),o=i.__d),i.componentDidCatch!=null&&(i.componentDidCatch(a,l||{}),o=i.__d),o)return i.__E=i}catch(c){a=c}throw a}},ya=0,ga=function(a){return a!=null&&a.constructor===void 0},$e.prototype.setState=function(a,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=ve({},this.state),typeof a=="function"&&(a=a(ve({},n),this.props)),a&&ve(n,a),a!=null&&this.__v&&(t&&this._sb.push(t),jt(this))},$e.prototype.forceUpdate=function(a){this.__v&&(this.__e=!0,a&&this.__h.push(a),jt(this))},$e.prototype.render=G,we=[],ba=typeof Promise=="function"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,wa=function(a,t){return a.__v.__b-t.__v.__b},rt.__r=0,Sa=/(PointerCapture)$|Capture$/i,Ut=0,Dt=Jt(!1),Lt=Jt(!0);var dn=0;function e(a,t,n,l,i,s){t||(t={});var o,c,h=t;if("ref"in h)for(c in h={},t)c=="ref"?o=t[c]:h[c]=t[c];var r={type:a,props:h,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--dn,__i:-1,__u:0,__source:i,__self:s};if(typeof a=="function"&&(o=a.defaultProps))for(c in o)h[c]===void 0&&(h[c]=o[c]);return H.vnode&&H.vnode(r),r}var ot,ie,kt,Xt,Ot=0,Da=[],X=H,Zt=X.__b,Qt=X.__r,ea=X.diffed,ta=X.__c,aa=X.unmount,na=X.__;function La(a,t){X.__h&&X.__h(ie,a,Ot||t),Ot=0;var n=ie.__H||(ie.__H={__:[],__h:[]});return a>=n.__.length&&n.__.push({}),n.__[a]}function R(a,t){var n=La(ot++,3);!X.__s&&xa(n.__H,t)&&(n.__=a,n.u=t,ie.__H.__h.push(n))}function Bt(a){return Ot=5,ht(function(){return{current:a}},[])}function ht(a,t){var n=La(ot++,7);return xa(n.__H,t)&&(n.__=a(),n.__H=t,n.__h=a),n.__}function un(){for(var a;a=Da.shift();)if(a.__P&&a.__H)try{a.__H.__h.forEach(st),a.__H.__h.forEach(Rt),a.__H.__h=[]}catch(t){a.__H.__h=[],X.__e(t,a.__v)}}X.__b=function(a){ie=null,Zt&&Zt(a)},X.__=function(a,t){a&&t.__k&&t.__k.__m&&(a.__m=t.__k.__m),na&&na(a,t)},X.__r=function(a){Qt&&Qt(a),ot=0;var t=(ie=a.__c).__H;t&&(kt===ie?(t.__h=[],ie.__h=[],t.__.forEach(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.forEach(st),t.__h.forEach(Rt),t.__h=[],ot=0)),kt=ie},X.diffed=function(a){ea&&ea(a);var t=a.__c;t&&t.__H&&(t.__H.__h.length&&(Da.push(t)!==1&&Xt===X.requestAnimationFrame||((Xt=X.requestAnimationFrame)||vn)(un)),t.__H.__.forEach(function(n){n.u&&(n.__H=n.u),n.u=void 0})),kt=ie=null},X.__c=function(a,t){t.some(function(n){try{n.__h.forEach(st),n.__h=n.__h.filter(function(l){return!l.__||Rt(l)})}catch(l){t.some(function(i){i.__h&&(i.__h=[])}),t=[],X.__e(l,n.__v)}}),ta&&ta(a,t)},X.unmount=function(a){aa&&aa(a);var t,n=a.__c;n&&n.__H&&(n.__H.__.forEach(function(l){try{st(l)}catch(i){t=i}}),n.__H=void 0,t&&X.__e(t,n.__v))};var la=typeof requestAnimationFrame=="function";function vn(a){var t,n=function(){clearTimeout(l),la&&cancelAnimationFrame(t),setTimeout(a)},l=setTimeout(n,35);la&&(t=requestAnimationFrame(n))}function st(a){var t=ie,n=a.__c;typeof n=="function"&&(a.__c=void 0,n()),ie=t}function Rt(a){var t=ie;a.__c=a.__(),ie=t}function xa(a,t){return!a||a.length!==t.length||t.some(function(n,l){return n!==a[l]})}var hn=Symbol.for("preact-signals");function pt(){if(_e>1)_e--;else{for(var a,t=!1;Ke!==void 0;){var n=Ke;for(Ke=void 0,Pt++;n!==void 0;){var l=n.o;if(n.o=void 0,n.f&=-3,!(8&n.f)&&Pa(n))try{n.c()}catch(i){t||(a=i,t=!0)}n=l}}if(Pt=0,_e--,t)throw a}}function pn(a){if(_e>0)return a();_e++;try{return a()}finally{pt()}}var B=void 0;function Oa(a){var t=B;B=void 0;try{return a()}finally{B=t}}var Ke=void 0,_e=0,Pt=0,ct=0;function Ra(a){if(B!==void 0){var t=a.n;if(t===void 0||t.t!==B)return t={i:0,S:a,p:B.s,n:void 0,t:B,e:void 0,x:void 0,r:t},B.s!==void 0&&(B.s.n=t),B.s=t,a.n=t,32&B.f&&a.S(t),t;if(t.i===-1)return t.i=0,t.n!==void 0&&(t.n.p=t.p,t.p!==void 0&&(t.p.n=t.n),t.p=B.s,t.n=void 0,B.s.n=t,B.s=t),t}}function ae(a,t){this.v=a,this.i=0,this.n=void 0,this.t=void 0,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}ae.prototype.brand=hn;ae.prototype.h=function(){return!0};ae.prototype.S=function(a){var t=this,n=this.t;n!==a&&a.e===void 0&&(a.x=n,this.t=a,n!==void 0?n.e=a:Oa(function(){var l;(l=t.W)==null||l.call(t)}))};ae.prototype.U=function(a){var t=this;if(this.t!==void 0){var n=a.e,l=a.x;n!==void 0&&(n.x=l,a.e=void 0),l!==void 0&&(l.e=n,a.x=void 0),a===this.t&&(this.t=l,l===void 0&&Oa(function(){var i;(i=t.Z)==null||i.call(t)}))}};ae.prototype.subscribe=function(a){var t=this;return Ge(function(){var n=t.value,l=B;B=void 0;try{a(n)}finally{B=l}},{name:"sub"})};ae.prototype.valueOf=function(){return this.value};ae.prototype.toString=function(){return this.value+""};ae.prototype.toJSON=function(){return this.value};ae.prototype.peek=function(){var a=B;B=void 0;try{return this.value}finally{B=a}};Object.defineProperty(ae.prototype,"value",{get:function(){var a=Ra(this);return a!==void 0&&(a.i=this.i),this.v},set:function(a){if(a!==this.v){if(Pt>100)throw new Error("Cycle detected");this.v=a,this.i++,ct++,_e++;try{for(var t=this.t;t!==void 0;t=t.x)t.t.N()}finally{pt()}}}});function ne(a,t){return new ae(a,t)}function Pa(a){for(var t=a.s;t!==void 0;t=t.n)if(t.S.i!==t.i||!t.S.h()||t.S.i!==t.i)return!0;return!1}function Wa(a){for(var t=a.s;t!==void 0;t=t.n){var n=t.S.n;if(n!==void 0&&(t.r=n),t.S.n=t,t.i=-1,t.n===void 0){a.s=t;break}}}function Ma(a){for(var t=a.s,n=void 0;t!==void 0;){var l=t.p;t.i===-1?(t.S.U(t),l!==void 0&&(l.n=t.n),t.n!==void 0&&(t.n.p=l)):n=t,t.S.n=t.r,t.r!==void 0&&(t.r=void 0),t=l}a.s=n}function Ne(a,t){ae.call(this,void 0),this.x=a,this.s=void 0,this.g=ct-1,this.f=4,this.W=t?.watched,this.Z=t?.unwatched,this.name=t?.name}Ne.prototype=new ae;Ne.prototype.h=function(){if(this.f&=-3,1&this.f)return!1;if((36&this.f)==32||(this.f&=-5,this.g===ct))return!0;if(this.g=ct,this.f|=1,this.i>0&&!Pa(this))return this.f&=-2,!0;var a=B;try{Wa(this),B=this;var t=this.x();(16&this.f||this.v!==t||this.i===0)&&(this.v=t,this.f&=-17,this.i++)}catch(n){this.v=n,this.f|=16,this.i++}return B=a,Ma(this),this.f&=-2,!0};Ne.prototype.S=function(a){if(this.t===void 0){this.f|=36;for(var t=this.s;t!==void 0;t=t.n)t.S.S(t)}ae.prototype.S.call(this,a)};Ne.prototype.U=function(a){if(this.t!==void 0&&(ae.prototype.U.call(this,a),this.t===void 0)){this.f&=-33;for(var t=this.s;t!==void 0;t=t.n)t.S.U(t)}};Ne.prototype.N=function(){if(!(2&this.f)){this.f|=6;for(var a=this.t;a!==void 0;a=a.x)a.t.N()}};Object.defineProperty(Ne.prototype,"value",{get:function(){if(1&this.f)throw new Error("Cycle detected");var a=Ra(this);if(this.h(),a!==void 0&&(a.i=this.i),16&this.f)throw this.v;return this.v}});function Ve(a,t){return new Ne(a,t)}function Ua(a){var t=a.u;if(a.u=void 0,typeof t=="function"){_e++;var n=B;B=void 0;try{t()}catch(l){throw a.f&=-2,a.f|=8,Ht(a),l}finally{B=n,pt()}}}function Ht(a){for(var t=a.s;t!==void 0;t=t.n)t.S.U(t);a.x=void 0,a.s=void 0,Ua(a)}function mn(a){if(B!==this)throw new Error("Out-of-order effect");Ma(this),B=a,this.f&=-2,8&this.f&&Ht(this),pt()}function Oe(a,t){this.x=a,this.u=void 0,this.s=void 0,this.o=void 0,this.f=32,this.name=t?.name}Oe.prototype.c=function(){var a=this.S();try{if(8&this.f||this.x===void 0)return;var t=this.x();typeof t=="function"&&(this.u=t)}finally{a()}};Oe.prototype.S=function(){if(1&this.f)throw new Error("Cycle detected");this.f|=1,this.f&=-9,Ua(this),Wa(this),_e++;var a=B;return B=this,mn.bind(this,a)};Oe.prototype.N=function(){2&this.f||(this.f|=2,this.o=Ke,Ke=this)};Oe.prototype.d=function(){this.f|=8,1&this.f||Ht(this)};Oe.prototype.dispose=function(){this.d()};function Ge(a,t){var n=new Oe(a,t);try{n.c()}catch(i){throw n.d(),i}var l=n.d.bind(n);return l[Symbol.dispose]=l,l}var $a,mt,Qe,fn=typeof window<"u"&&!!window.__PREACT_SIGNALS_DEVTOOLS__,Ka=[];Ge(function(){$a=this.N})();function Re(a,t){H[a]=t.bind(null,H[a]||function(){})}function dt(a){if(Qe){var t=Qe;Qe=void 0,t()}Qe=a&&a.S()}function Fa(a){var t=this,n=a.data,l=v(n);l.value=n;var i=ht(function(){for(var c=t,h=t.__v;h=h.__;)if(h.__c){h.__c.__$f|=4;break}var r=Ve(function(){var p=l.value.value;return p===0?0:p===!0?"":p||""}),u=Ve(function(){return!Array.isArray(r.value)&&!ga(r.value)}),d=Ge(function(){if(this.N=Ba,u.value){var p=r.value;c.__v&&c.__v.__e&&c.__v.__e.nodeType===3&&(c.__v.__e.data=p)}}),m=t.__$u.d;return t.__$u.d=function(){d(),m.call(this)},[u,r]},[]),s=i[0],o=i[1];return s.value?o.peek():o.value}Fa.displayName="ReactiveTextNode";Object.defineProperties(ae.prototype,{constructor:{configurable:!0,value:void 0},type:{configurable:!0,value:Fa},props:{configurable:!0,get:function(){return{data:this}}},__b:{configurable:!0,value:1}});Re("__b",function(a,t){if(typeof t.type=="string"){var n,l=t.props;for(var i in l)if(i!=="children"){var s=l[i];s instanceof ae&&(n||(t.__np=n={}),n[i]=s,l[i]=s.peek())}}a(t)});Re("__r",function(a,t){if(a(t),t.type!==G){dt();var n,l=t.__c;l&&(l.__$f&=-2,(n=l.__$u)===void 0&&(l.__$u=n=(function(i,s){var o;return Ge(function(){o=this},{name:s}),o.c=i,o})(function(){var i;fn&&((i=n.y)==null||i.call(n)),l.__$f|=1,l.setState({})},typeof t.type=="function"?t.type.displayName||t.type.name:""))),mt=l,dt(n)}});Re("__e",function(a,t,n,l){dt(),mt=void 0,a(t,n,l)});Re("diffed",function(a,t){dt(),mt=void 0;var n;if(typeof t.type=="string"&&(n=t.__e)){var l=t.__np,i=t.props;if(l){var s=n.U;if(s)for(var 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],u=l[h];r===void 0?(r=_n(n,h,u,i),s[h]=r):r.o(u,i)}}}a(t)});function _n(a,t,n,l){var i=t in a&&a.ownerSVGElement===void 0,s=ne(n);return{o:function(o,c){s.value=o,l=c},d:Ge(function(){this.N=Ba;var o=s.value.value;l[t]!==o&&(l[t]=o,i?a[t]=o:o!=null&&(o!==!1||t[4]==="-")?a.setAttribute(t,o):a.removeAttribute(t))})}}Re("unmount",function(a,t){if(typeof t.type=="string"){var n=t.__e;if(n){var l=n.U;if(l){n.U=void 0;for(var i in l){var s=l[i];s&&s.d()}}}}else{var o=t.__c;if(o){var c=o.__$u;c&&(o.__$u=void 0,c.d())}}a(t)});Re("__h",function(a,t,n,l){(l<3||l===9)&&(t.__$f|=2),a(t,n,l)});$e.prototype.shouldComponentUpdate=function(a,t){if(this.__R)return!0;var n=this.__$u,l=n&&n.s!==void 0;for(var i in t)return!0;if(this.__f||typeof this.u=="boolean"&&this.u===!0){var s=2&this.__$f;if(!(l||s||4&this.__$f)||1&this.__$f)return!0}else if(!(l||4&this.__$f)||3&this.__$f)return!0;for(var o in a)if(o!=="__source"&&a[o]!==this.props[o])return!0;for(var c in this.props)if(!(c in a))return!0;return!1};function v(a,t){return ht(function(){return ne(a,t)},[])}function yn(a,t){var n=Bt(a);return n.current=a,mt.__$f|=4,ht(function(){return Ve(function(){return n.current()},t)},[])}var gn=function(a){queueMicrotask(function(){queueMicrotask(a)})};function bn(){pn(function(){for(var a;a=Ka.shift();)$a.call(a)})}function Ba(){Ka.push(this)===1&&(H.requestAnimationFrame||gn)(bn)}const qe=ne(null),wn=Ve(()=>qe.value!==null),Ha=ne(900),Sn=ne(!1);let Ie=null;const De=()=>{Vt()};function kn(){document.addEventListener("mousemove",De,{passive:!0}),document.addEventListener("keydown",De,{passive:!0}),document.addEventListener("click",De,{passive:!0}),Vt()}function Nn(){document.removeEventListener("mousemove",De),document.removeEventListener("keydown",De),document.removeEventListener("click",De),Ie!==null&&(clearTimeout(Ie),Ie=null)}function Vt(){Ie!==null&&clearTimeout(Ie),Ie=setTimeout(()=>{qt()},Ha.value*1e3)}function Tn(a,t){qe.value=a,t!==void 0&&(Ha.value=t),kn(),location.hash="#/dashboard"}function qt(){qe.value=null,Nn(),location.hash="#/login"}const C={ADMIN_STATUS:"/v1/admin/status",ADMIN_KILL_SWITCH:"/v1/admin/kill-switch",ADMIN_KILL_SWITCH_ESCALATE:"/v1/admin/kill-switch/escalate",ADMIN_RECOVER:"/v1/admin/recover",ADMIN_SHUTDOWN:"/v1/admin/shutdown",ADMIN_ROTATE_SECRET:"/v1/admin/rotate-secret",WALLETS:"/v1/wallets",WALLET:a=>`/v1/wallets/${a}`,SESSIONS:"/v1/sessions",SESSION:a=>`/v1/sessions/${a}`,POLICIES:"/v1/policies",POLICY:a=>`/v1/policies/${a}`,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:a=>`/v1/wallets/${a}/networks`,WALLET_DEFAULT_NETWORK:a=>`/v1/wallets/${a}/default-network`,ADMIN_WALLET_BALANCE:a=>`/v1/admin/wallets/${a}/balance`,ADMIN_WALLET_TRANSACTIONS:a=>`/v1/admin/wallets/${a}/transactions`,ADMIN_API_KEYS:"/v1/admin/api-keys",ADMIN_API_KEY:a=>`/v1/admin/api-keys/${a}`,ADMIN_FOREX_RATES:"/v1/admin/forex/rates",ADMIN_TELEGRAM_USERS:"/v1/admin/telegram-users",ADMIN_TELEGRAM_USER:a=>`/v1/admin/telegram-users/${a}`,WALLET_OWNER:a=>`/v1/wallets/${a}/owner`,WALLET_WITHDRAW:a=>`/v1/wallets/${a}/withdraw`,WALLET_WC_PAIR:a=>`/v1/wallets/${a}/wc/pair`,WALLET_WC_SESSION:a=>`/v1/wallets/${a}/wc/session`,WALLET_WC_PAIR_STATUS:a=>`/v1/wallets/${a}/wc/pair/status`,WALLET_OWNER_VERIFY:a=>`/v1/wallets/${a}/owner/verify`,WALLET_SUSPEND:a=>`/v1/wallets/${a}/suspend`,WALLET_RESUME:a=>`/v1/wallets/${a}/resume`,ADMIN_AGENT_PROMPT:"/v1/admin/agent-prompt",ADMIN_SESSION_REISSUE:a=>`/v1/admin/sessions/${a}/reissue`},Fe=ne(""),Ae=ne(null),Be=ne(!1),he={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)"}},En=async a=>{if(a.preventDefault(),!!Fe.value.trim()){Be.value=!0,Ae.value=null;try{const t=await fetch(C.ADMIN_STATUS,{headers:{"X-Master-Password":Fe.value},signal:AbortSignal.timeout(1e4)});if(t.status===401){Ae.value="Invalid master password";return}if(!t.ok){Ae.value="Cannot connect to daemon";return}const n=await t.json();Tn(Fe.value,n.adminTimeout)}catch{Ae.value="Cannot connect to daemon"}finally{Be.value=!1}}};function Cn(){return e("div",{style:he.wrapper,children:e("form",{style:he.card,onSubmit:En,children:[e("h1",{style:he.title,children:"WAIaaS Admin"}),e("p",{style:he.subtitle,children:"Enter master password to continue"}),e("input",{type:"password",placeholder:"Master password",autoFocus:!0,value:Fe.value,onInput:a=>{Fe.value=a.target.value},style:he.input}),e("button",{type:"submit",disabled:Be.value,style:{...he.button,...Be.value?he.buttonDisabled:{}},children:Be.value?"Signing in...":"Sign in"}),Ae.value&&e("p",{style:he.error,children:Ae.value})]})})}const An=[{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:"wallets.monitoring.enabled",label:"Enabled",description:"Enable or disable balance monitoring",page:"/wallets",tab:"monitoring",fieldName:"monitoring.enabled",keywords:["balance","monitoring","toggle","enable"]},{id:"wallets.monitoring.check_interval_sec",label:"Check Interval (seconds)",description:"How often to check wallet balances",page:"/wallets",tab:"monitoring",fieldName:"monitoring.check_interval_sec",keywords:["balance","monitoring","interval","frequency"]},{id:"wallets.monitoring.low_balance_threshold_sol",label:"Low Balance Threshold (SOL)",description:"Alert when SOL balance drops below this amount",page:"/wallets",tab:"monitoring",fieldName:"monitoring.low_balance_threshold_sol",keywords:["balance","monitoring","threshold","solana","alert","low"]},{id:"wallets.monitoring.low_balance_threshold_eth",label:"Low Balance Threshold (ETH)",description:"Alert when ETH balance drops below this amount",page:"/wallets",tab:"monitoring",fieldName:"monitoring.low_balance_threshold_eth",keywords:["balance","monitoring","threshold","ethereum","alert","low"]},{id:"wallets.monitoring.cooldown_hours",label:"Alert Cooldown (hours)",description:"Suppress duplicate alerts for this many hours",page:"/wallets",tab:"monitoring",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.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:"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"]}],ce=ne(""),Z=ne(null),In={"/wallets":"Wallets","/sessions":"Sessions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"};function Dn(a){if(!a.trim())return[];const t=a.toLowerCase();return An.filter(n=>[n.label,n.description,n.keywords.join(" ")].join(" ").toLowerCase().includes(t)).slice(0,10)}function Ln(a){const t=In[a.page]??a.page;return a.tab?`${t} > ${a.tab}`:t}function xn({open:a}){const t=v(""),n=v(0),l=Bt(null),i=a.value?Dn(t.value):[];if(R(()=>{a.value&&(t.value="",n.value=0,requestAnimationFrame(()=>{l.current?.focus()}))},[a.value]),!a.value)return null;const s=()=>{a.value=!1,t.value="",n.value=0},o=r=>{r.target.classList.contains("search-overlay")&&s()},c=r=>{window.location.hash="#"+r.page,r.tab?Z.value={tab:r.tab,fieldName:r.fieldName}:setTimeout(()=>{ce.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:t.value,onInput:r=>{t.value=r.target.value,n.value=0}})}),e("div",{class:"search-results",children:[t.value.trim()&&i.length===0&&e("div",{class:"search-empty",children:"No settings found"}),i.map((r,u)=>e("button",{class:`search-result-item${u===n.value?" selected":""}`,onClick:()=>c(r),onMouseEnter:()=>{n.value=u},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:Ln(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 ke=ne([]),Va=Ve(()=>ke.value.some(a=>a.isDirty()));function ge(a){ke.value=[...ke.value.filter(t=>t.id!==a.id),a]}function be(a){ke.value=ke.value.filter(t=>t.id!==a)}async function On(){const a=ke.value.filter(t=>t.isDirty());try{for(const t of a)await t.save();return!0}catch{return!1}}function Rn(){const a=ke.value.filter(t=>t.isDirty());for(const t of a)t.discard()}function S({label:a,name:t,type:n="text",value:l,onChange:i,options:s,error:o,required:c,disabled:h,placeholder:r,min:u,max:d,description:m}){const p=ce.value===t;if(R(()=>{if(p){const N=document.querySelector(`[name="${t}"]`);N&&N.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const b=setTimeout(()=>{ce.value=""},2500);return()=>clearTimeout(b)}},[p,t]),n==="checkbox")return e("div",{class:`form-field${p?" form-field--highlight":""}`,children:[e("label",{children:[e("input",{type:"checkbox",name:t,checked:!!l,onChange:N=>i(N.target.checked),disabled:h}),a,c&&e("span",{children:" *"})]}),m&&e("span",{class:"form-description",children:m}),o&&e("span",{class:"form-error",children:o})]});const E=`field-${t}`;return e("div",{class:`form-field${p?" form-field--highlight":""}`,children:[e("label",{for:E,children:[a,c&&e("span",{children:" *"})]}),n==="select"?e("select",{id:E,name:t,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:E,name:t,value:l,onInput:N=>i(N.target.value),disabled:h,placeholder:r}):e("input",{id:E,type:n,name:t,value:l,onInput:N=>{const b=N.target;i(n==="number"?Number(b.value):b.value)},disabled:h,placeholder:r,min:u,max:d,required:c}),m&&e("span",{class:"form-description",children:m}),o&&e("span",{class:"form-error",children:o})]})}function A({variant:a="primary",size:t="md",loading:n=!1,disabled:l=!1,onClick:i,children:s,type:o="button"}){const c=["btn",`btn-${a}`,t==="sm"?"btn-sm":""].filter(Boolean).join(" ");return e("button",{type:o,class:c,disabled:l||n,onClick:i,children:n?"...":s})}function U({variant:a,children:t}){return e("span",{class:`badge badge-${a}`,children:t})}const Ue=ne(null),We=ne(!1);function qa(a){Ue.value=a}function Pn(){const a=Ue.value;if(!a)return null;const t=async()=>{We.value=!0;const i=await On();We.value=!1,i&&(Ue.value=null,a.execute())},n=()=>{Rn(),Ue.value=null,a.execute()},l=()=>{Ue.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(A,{variant:"secondary",onClick:l,disabled:We.value,children:"Cancel"}),e(A,{variant:"ghost",onClick:n,disabled:We.value,children:"Discard & Navigate"}),e(A,{variant:"primary",onClick:t,loading:We.value,children:"Save & Navigate"})]})]})})}class f extends Error{constructor(t,n,l){super(`[${t}] ${n}: ${l}`),this.status=t,this.code=n,this.serverMessage=l,this.name="ApiError"}}async function ft(a,t){const n={"Content-Type":"application/json",...t?.headers};qe.value!==null&&(n["X-Master-Password"]=qe.value);let l;try{l=await fetch(a,{...t,headers:n,signal:AbortSignal.timeout(1e4)})}catch(i){const s=i;throw s.name==="AbortError"||s.name==="TimeoutError"?new f(0,"TIMEOUT","Request timed out"):new f(0,"NETWORK_ERROR","Cannot connect to daemon")}if(l.status===401)throw qt(),new f(401,"INVALID_MASTER_PASSWORD","Authentication failed");if(!l.ok){let i={};try{i=await l.json()}catch{}throw new f(l.status,i.code??"UNKNOWN",i.message??"Unknown error")}return Vt(),await l.json()}const q=a=>ft(a,{method:"GET"}),te=(a,t)=>ft(a,{method:"POST",body:t?JSON.stringify(t):void 0}),le=(a,t)=>ft(a,{method:"PUT",body:t?JSON.stringify(t):void 0}),xe=a=>ft(a,{method:"DELETE"});function Wn(a){const t=Math.floor(a/86400),n=Math.floor(a%86400/3600),l=Math.floor(a%3600/60);return t>0?`${t}d ${n}h ${l}m`:n>0?`${n}h ${l}m`:`${l}m`}function se(a){const t=new Date(a*1e3),n=l=>l.toString().padStart(2,"0");return`${t.getFullYear()}-${n(t.getMonth()+1)}-${n(t.getDate())} ${n(t.getHours())}:${n(t.getMinutes())}`}function Wt(a){return a.length<=10?a:`${a.slice(0,4)}..${a.slice(-4)}`}const Mn=new Set(["KRW","JPY","VND","CLP","HUF","PKR"]),Un=new Set(["KWD","BHD"]);function $n(a){return Mn.has(a)?0:Un.has(a)?3:2}function Kn(a,t,n){const l=a*n,i=$n(t),s=new Intl.NumberFormat("en-US",{style:"currency",currency:t,minimumFractionDigits:i,maximumFractionDigits:i}).format(l);return t==="USD"?s:`≈${s}`}let Ce=null;const Fn=300*1e3;async function Bn(){if(Ce&&Date.now()-Ce.fetchedAt<Fn)return{currency:Ce.currency,rate:Ce.rate};try{const t=(await q(C.ADMIN_SETTINGS)).display?.["display.currency"]??"USD";if(t==="USD")return Ce={currency:"USD",rate:1,fetchedAt:Date.now()},{currency:"USD",rate:1};const i=(await q(`${C.ADMIN_FOREX_RATES}?currencies=${t}`)).rates[t]?.rate??null;return Ce={currency:t,rate:i,fetchedAt:Date.now()},{currency:t,rate:i}}catch{return{currency:"USD",rate:1}}}function Hn(a,t,n){return a==null?"":n==null?`$${a.toFixed(2)}`:Kn(a,t,n)}function Te({columns:a,data:t,onRowClick:n,emptyMessage:l="No data",loading:i=!1}){return e("div",{class:"table-container",children:e("table",{children:[e("thead",{children:e("tr",{children:a.map(s=>e("th",{style:s.width?{width:s.width}:void 0,children:s.header},s.key))})}),e("tbody",{children:i?e("tr",{children:e("td",{colSpan:a.length,class:"table-loading",children:"Loading..."})}):!t||t.length===0?e("tr",{children:e("td",{colSpan:a.length,class:"table-empty",children:l})}):t.map((s,o)=>e("tr",{class:n?"clickable":"",onClick:n?()=>n(s):void 0,children:a.map(c=>e("td",{children:c.render?c.render(s):s[c.key]},c.key))},o))})]})})}const Vn={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."},qn=new Set(["ACTION_VALIDATION_FAILED","CONSTRAINT_VIOLATED","INVALID_ADDRESS","INVALID_SIGNATURE"]);function D(a,t){return t&&qn.has(a)?t:Vn[a]??`An error occurred (${a}).`}const me=ne([]);let zn=0;function g(a,t){const n=zn++;me.value=[...me.value,{id:n,type:a,message:t}],setTimeout(()=>{me.value=me.value.filter(l=>l.id!==n)},5e3)}function Gn(a){me.value=me.value.filter(t=>t.id!==a)}function jn(){return me.value.length===0?null:e("div",{class:"toast-container",children:me.value.map(a=>e("div",{class:`toast toast-${a.type}`,onClick:()=>Gn(a.id),children:a.message},a.id))})}function ue({label:a,value:t,loading:n,badge:l,href:i}){const s=e(G,{children:[e("div",{class:"stat-label",children:[a,i&&e("span",{class:"stat-link-arrow",children:" →"})]}),n?e("div",{class:"stat-skeleton"}):l?e(U,{variant:l,children:t}):e("div",{class:"stat-value",children:t})]});return i?e("a",{href:i,class:"stat-card stat-card-link",style:{textDecoration:"none",color:"inherit",cursor:"pointer"},children:s}):e("div",{class:"stat-card",children:s})}function Yn(a,t){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=Hn(n.amountUsd,a,t);return l?`${n.amount} (${l})`:n.amount}},{key:"status",header:"Status",render:n=>{const l=n.status==="CONFIRMED"?"success":n.status==="FAILED"?"danger":"warning";return e(U,{variant:l,children:n.status})}}]}async function Jn(a){try{await navigator.clipboard.writeText(a)}catch{const t=document.createElement("textarea");t.value=a,t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select(),document.execCommand("copy"),document.body.removeChild(t)}}function ia(){const a=v(null),t=v(!0),n=v(null),l=v("USD"),i=v(1),s=v(!1),o=v(null),c=async()=>{t.value=!0,n.value=null;try{const d=await q(C.ADMIN_STATUS);a.value=d}catch(d){d instanceof f?n.value=D(d.code):n.value="An unexpected error occurred."}finally{t.value=!1}},h=async()=>{s.value=!0;try{const d=await te(C.ADMIN_AGENT_PROMPT,{});if(d.walletCount===0){g("warning","No active wallets found");return}o.value=d.prompt,g("success",`Prompt generated for ${d.walletCount} wallet(s)`)}catch(d){d instanceof f?g("error",D(d.code)):g("error","Failed to generate agent prompt")}finally{s.value=!1}},r=async()=>{o.value&&(await Jn(o.value),g("success","Copied to clipboard!"))};R(()=>{c(),Bn().then(({currency:m,rate:p})=>{l.value=m,i.value=p}).catch(()=>{});const d=setInterval(c,3e4);return()=>clearInterval(d)},[]);const u=t.value&&!a.value;return e("div",{class:"page",children:[n.value&&e("div",{class:"dashboard-error",children:[e("span",{children:n.value}),e(A,{variant:"secondary",size:"sm",onClick:c,children:"Retry"})]}),a.value?.updateAvailable&&e("div",{class:"update-banner",role:"status",children:[e("span",{class:"update-banner-icon",children:"⬆"}),e("span",{children:[e("strong",{children:"Update available:"})," ",a.value.version," ","→"," ",a.value.latestVersion," — ","Run ",e("code",{children:"waiaas update"})," to update."]})]}),e("div",{class:"stat-grid",children:[e(ue,{label:"Version",value:a.value?.version??"—",loading:u,badge:a.value&&a.value.updateAvailable?"warning":void 0}),e(ue,{label:"Uptime",value:a.value?Wn(a.value.uptime):"—",loading:u}),e(ue,{label:"Wallets",value:a.value?.walletCount?.toString()??"—",loading:u,href:"#/wallets"}),e(ue,{label:"Active Sessions",value:a.value?.activeSessionCount?.toString()??"—",loading:u,href:"#/sessions"})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ue,{label:"Kill Switch",value:a.value?.killSwitchState==="ACTIVATED"?"ACTIVATED":"NORMAL",loading:u,badge:a.value?a.value.killSwitchState==="ACTIVATED"?"danger":"success":void 0}),e(ue,{label:"Status",value:a.value?.status??"—",loading:u})]}),e("div",{class:"stat-grid",style:{marginTop:"var(--space-4)"},children:[e(ue,{label:"Policies",value:a.value?.policyCount?.toString()??"—",loading:u,href:"#/policies"}),e(ue,{label:"Recent Txns (24h)",value:a.value?.recentTxCount?.toString()??"—",loading:u}),e(ue,{label:"Failed Txns (24h)",value:a.value?.failedTxCount?.toString()??"—",loading:u,badge:a.value?a.value.failedTxCount===0?"success":"danger":void 0})]}),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(G,{children:[e("pre",{class:"prompt-preview",children:o.value}),e("div",{style:{display:"flex",gap:"var(--space-2)",marginTop:"var(--space-3)"},children:[e(A,{variant:"primary",size:"sm",onClick:r,children:"Copy to Clipboard"}),e(A,{variant:"secondary",size:"sm",onClick:h,loading:s.value,children:"Regenerate"})]})]}):e(A,{variant:"primary",size:"sm",onClick:h,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(Te,{columns:Yn(l.value,i.value),data:a.value?.recentTransactions??[],loading:u,emptyMessage:"No recent transactions"})]})]})}function re({open:a,title:t,children:n,onConfirm:l,onCancel:i,confirmText:s="Confirm",cancelText:o="Cancel",confirmVariant:c="primary",confirmDisabled:h=!1,loading:r=!1}){return R(()=>{if(!a)return;const u=d=>{d.key==="Escape"&&i()};return document.addEventListener("keydown",u),()=>document.removeEventListener("keydown",u)},[a,i]),a?e("div",{class:"modal-overlay",onClick:i,children:e("div",{class:"modal-card",onClick:u=>u.stopPropagation(),children:[e("div",{class:"modal-header",children:t}),e("div",{class:"modal-body",children:n}),e("div",{class:"modal-footer",children:[e(A,{variant:"secondary",onClick:i,disabled:r,children:o}),l&&e(A,{variant:c,onClick:l,loading:r,disabled:h,children:s})]})]})}):null}function ze({value:a,label:t}){const n=v(!1);return e("button",{class:"btn btn-ghost btn-sm",onClick:async()=>{try{await navigator.clipboard.writeText(a)}catch{const i=document.createElement("textarea");i.value=a,i.style.position="fixed",i.style.left="-9999px",document.body.appendChild(i),i.select(),document.execCommand("copy"),document.body.removeChild(i)}n.value=!0,setTimeout(()=>{n.value=!1},2e3)},children:n.value?"Copied!":t??"Copy"})}function Xn({title:a,description:t,actionLabel:n,onAction:l}){return e("div",{class:"empty-state",children:[e("h3",{children:a}),t&&e("p",{children:t}),n&&l&&e("button",{class:"btn btn-primary",onClick:l,children:n})]})}function je({tabs:a,activeTab:t,onTabChange:n}){return e("div",{class:"tab-nav",children:a.map(l=>e("button",{class:`tab-btn ${t===l.key?"active":""}`,onClick:()=>{l.key!==t&&(Va.value?qa({type:"tab",execute:()=>n(l.key)}):n(l.key))},children:l.label},l.key))})}function Ye({pageName:a,tabName:t,onPageClick:n}){return t?e("nav",{class:"breadcrumb","aria-label":"Breadcrumb",children:[e("button",{class:"breadcrumb-page",onClick:n,type:"button",children:a}),e("span",{class:"breadcrumb-separator","aria-hidden":"true",children:">"}),e("span",{class:"breadcrumb-current","aria-current":"page",children:t})]}):null}const Zn=new Set(["notifications.telegram_bot_token","notifications.discord_webhook_url","notifications.slack_webhook_url","telegram.bot_token"]);function Qn(a){return Zn.has(a)}function O(a){return{enabled:"Enabled",telegram_bot_token:"Telegram Bot Token",telegram_chat_id:"Telegram Chat ID",discord_webhook_url:"Discord Webhook URL",ntfy_server:"Ntfy Server",ntfy_topic:"Ntfy Topic",locale:"Locale",rate_limit_rpm:"Rate Limit (RPM)",solana_mainnet:"Solana Mainnet",solana_devnet:"Solana Devnet",solana_testnet:"Solana Testnet",evm_ethereum_mainnet:"Ethereum Mainnet",evm_ethereum_sepolia:"Ethereum Sepolia",evm_polygon_mainnet:"Polygon Mainnet",evm_polygon_amoy:"Polygon Amoy",evm_arbitrum_mainnet:"Arbitrum Mainnet",evm_arbitrum_sepolia:"Arbitrum Sepolia",evm_optimism_mainnet:"Optimism Mainnet",evm_optimism_sepolia:"Optimism Sepolia",evm_base_mainnet:"Base Mainnet",evm_base_sepolia:"Base Sepolia",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)"}[a]??a.replace(/_/g," ").replace(/\b\w/g,n=>n.toUpperCase())}function K(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i];const s=a[n];if(!s)return"";const o=s[l];return typeof o=="boolean"?Qn(i)?"":String(o):o??""}function fe(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return t[i]==="true";const s=a[n];if(!s)return!1;const o=s[l];return typeof o=="boolean"?o:o==="true"}function et(a,t,n,l){const i=`${n}.${l}`;if(t[i]!==void 0)return!1;const s=a[n];return s?s[l]===!0:!1}const el=[{key:"name",header:"Name"},{key:"chain",header:"Chain"},{key:"environment",header:"Environment",render:a=>e(U,{variant:a.environment==="mainnet"?"warning":"info",children:a.environment})},{key:"publicKey",header:"Public Key",render:a=>e("span",{style:{display:"flex",alignItems:"center",gap:"0.25rem"},children:[Wt(a.publicKey)," ",e(ze,{value:a.publicKey})]})},{key:"status",header:"Status",render:a=>e(U,{variant:a.status==="ACTIVE"?"success":a.status==="SUSPENDED"?"warning":"danger",children:a.status})},{key:"ownerState",header:"Owner",render:a=>e(U,{variant:za(a.ownerState),children:a.ownerState})},{key:"createdAt",header:"Created",render:a=>se(a.createdAt)}];function za(a){switch(a){case"NONE":return"neutral";case"GRACE":return"warning";case"LOCKED":return"success";default:return"neutral"}}function J({label:a,value:t,copy:n,children:l}){return e("div",{class:"detail-row",children:[e("div",{class:"detail-row-label",children:a}),e("div",{class:"detail-row-value",children:[l??t??"—",n&&t&&e(ze,{value:t})]})]})}const tl=[{value:null,label:"Auto (Global Fallback)",description:"System decides based on configured channels: Wallet App (ntfy) > Wallet App (Telegram) > WalletConnect > Telegram Bot > REST"},{value:"sdk_ntfy",label:"Wallet App (ntfy)",description:"Push sign request to wallet app via ntfy server",warning:"Signing SDK is not enabled. Go to System > Signing SDK settings.",warningCondition:a=>!a?.signingEnabled},{value:"sdk_telegram",label:"Wallet App (Telegram)",description:"Push sign request to wallet app via Telegram with universal link",warning:"Signing SDK or Telegram bot is not configured. Check System > Signing SDK and Notifications > Telegram settings.",warningCondition:a=>!a?.signingEnabled||!a?.telegramBotConfigured},{value:"walletconnect",label:"WalletConnect",description:"Approve via connected WalletConnect wallet (D'CENT, MetaMask, etc.)",warning:"WalletConnect project ID is not configured. Go to Wallets > WalletConnect tab.",warningCondition:a=>!a?.wcConfigured},{value:"telegram_bot",label:"Telegram Bot",description:"Approve/reject via Telegram bot /approve and /reject commands",warning:"Telegram bot token is not configured. Go to Notifications > Settings > Telegram.",warningCondition:a=>!a?.telegramBotConfigured},{value:"rest",label:"REST API",description:"Manual approval via REST API endpoints (POST /approve, /reject)"}];function al({id:a}){const t=v(null),n=v(!0),l=v(!1),i=v(""),s=v(!1),o=v(!1),c=v(!1),h=v(!1),r=v(null),u=v([]),d=v(!0),m=v(!1),p=v(null),E=v(!0),N=v([]),b=v(!0),I=v(!1),x=v(null),F=v(!1),V=v(null),k=v(!0),W=v(!1),P=v(null),_=v(!1),L=v(""),Y=v(!1),Q=v(null),ee=v(!1),de=v(!1),T=v(""),M=v(!1),j=async()=>{try{const y=await q(C.WALLET(a));t.value=y}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{n.value=!1}},Pe=async()=>{s.value=!0;try{const y=await le(C.WALLET(a),{name:i.value});t.value=y,l.value=!1,g("success","Wallet name updated")}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{s.value=!1}},_t=async()=>{c.value=!0;try{await xe(C.WALLET(a)),g("success","Wallet terminated"),window.location.hash="#/wallets"}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{c.value=!1}},yt=async()=>{de.value=!0;try{await te(C.WALLET_SUSPEND(a),{reason:T.value.trim()||void 0}),g("success","Wallet suspended"),ee.value=!1,T.value="",await j()}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{de.value=!1}},gt=async()=>{M.value=!0;try{await te(C.WALLET_RESUME(a)),g("success","Wallet resumed"),await j()}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{M.value=!1}},bt=()=>{i.value=t.value.name,l.value=!0},wt=()=>{l.value=!1},Je=async()=>{h.value=!0;try{const y=await te(C.MCP_TOKENS,{walletId:a});r.value=y,g("success","MCP token provisioned successfully")}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{h.value=!1}},Xe=async()=>{d.value=!0;try{const y=await q(C.WALLET_NETWORKS(a));u.value=y.availableNetworks??[]}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code)),u.value=[]}finally{d.value=!1}},St=async()=>{E.value=!0;try{p.value=await q(C.ADMIN_WALLET_BALANCE(a))}catch{p.value=null}finally{E.value=!1}},w=async()=>{b.value=!0;try{const y=await q(C.ADMIN_WALLET_TRANSACTIONS(a));N.value=y.items}catch{N.value=[]}finally{b.value=!1}},z=async()=>{k.value=!0;try{V.value=await q(C.WALLET_WC_SESSION(a))}catch{V.value=null}finally{k.value=!1}},oe=()=>{P.value&&clearInterval(P.value),P.value=setInterval(async()=>{try{const y=await q(C.WALLET_WC_PAIR_STATUS(a));y.status==="connected"?(P.value&&clearInterval(P.value),P.value=null,I.value=!1,x.value=null,V.value=y.session??null,g("success","Wallet connected via WalletConnect")):(y.status==="expired"||y.status==="none")&&(P.value&&clearInterval(P.value),P.value=null,I.value=!1,x.value=null,g("error","Pairing expired. Try again."))}catch{}},3e3)},ja=async()=>{F.value=!0;try{const y=await te(C.WALLET_WC_PAIR(a));x.value=y,I.value=!0,oe()}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");$.code==="WC_NOT_CONFIGURED"?(g("error","WalletConnect is not configured. Redirecting to settings..."),Z.value={tab:"walletconnect",fieldName:"walletconnect.project_id"},window.location.hash="#/wallets"):g("error",D($.code))}finally{F.value=!1}},Ya=async()=>{W.value=!0;try{await xe(C.WALLET_WC_SESSION(a)),V.value=null,g("success","WalletConnect session disconnected")}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code))}finally{W.value=!1}},zt=()=>{L.value=t.value?.ownerAddress??"",_.value=!0},Ja=()=>{_.value=!1},Xa=async()=>{if(!L.value.trim()){g("error","Owner address is required");return}Y.value=!0;try{await le(C.WALLET_OWNER(a),{owner_address:L.value.trim()}),await j(),_.value=!1,g("success","Owner address updated")}catch(y){const $=y instanceof f?y:new f(0,"UNKNOWN","Unknown error");g("error",D($.code,$.serverMessage))}finally{Y.value=!1}},Za=async y=>{m.value=!0;try{await le(C.WALLET_DEFAULT_NETWORK(a),{network:y}),g("success",`Default network changed to ${y}`),await j(),await Xe()}catch($){const Ee=$ instanceof f?$:new f(0,"UNKNOWN","Unknown error");g("error",D(Ee.code))}finally{m.value=!1}},Qa=async()=>{try{const y=await q(C.ADMIN_SETTINGS),$=y.signing_sdk?.enabled==="true",Ee=y.telegram?.bot_token===!0,tn=!!y.walletconnect?.project_id&&y.walletconnect.project_id!=="";Q.value={signingEnabled:$,telegramBotConfigured:Ee,wcConfigured:tn}}catch{}},en=async y=>{try{await le(C.WALLET_OWNER(a),{owner_address:t.value.ownerAddress,approval_method:y??null}),await j(),g("success","Approval method updated")}catch($){const Ee=$ instanceof f?$:new f(0,"UNKNOWN","Unknown error");g("error",D(Ee.code,Ee.serverMessage))}};return R(()=>{j(),Xe(),St(),w(),z(),Qa()},[a]),R(()=>()=>{P.value&&clearInterval(P.value)},[]),e("div",{class:"page",children:[e("a",{href:"#/wallets",class:"back-link",children:"← Back to Wallets"}),n.value?e("div",{class:"stat-skeleton",style:{height:"200px",marginTop:"var(--space-4)"}}):t.value?e("div",{class:"wallet-detail",children:[e("div",{class:"detail-header",children:[e("div",{class:"detail-name",children:l.value?e("div",{class:"inline-edit",children:[e("input",{value:i.value,onInput:y=>{i.value=y.target.value},class:"inline-edit-input"}),e(A,{size:"sm",onClick:Pe,loading:s.value,children:"Save"}),e(A,{size:"sm",variant:"secondary",onClick:wt,children:"Cancel"})]}):e("span",{children:[t.value.name,e("button",{class:"btn btn-ghost btn-sm",onClick:bt,title:"Edit name",children:"✎"})]})}),e("div",{style:{display:"flex",gap:"var(--space-2)"},children:[t.value.status==="ACTIVE"&&e(A,{variant:"secondary",onClick:()=>{ee.value=!0},children:"Suspend Wallet"}),t.value.status==="SUSPENDED"&&e(A,{variant:"primary",onClick:gt,loading:M.value,children:"Resume Wallet"}),t.value.status!=="TERMINATED"&&e(A,{variant:"danger",onClick:()=>{o.value=!0},children:"Terminate Wallet"})]})]}),e("div",{class:"detail-grid",children:[e(J,{label:"ID",value:t.value.id,copy:!0}),e(J,{label:"Public Key",value:t.value.publicKey,copy:!0}),e(J,{label:"Chain",value:t.value.chain}),e(J,{label:"Environment",children:e(U,{variant:t.value.environment==="mainnet"?"warning":"info",children:t.value.environment})}),e(J,{label:"Default Network",value:t.value.defaultNetwork??t.value.network}),e(J,{label:"Status",children:e(U,{variant:t.value.status==="ACTIVE"?"success":t.value.status==="SUSPENDED"?"warning":"danger",children:t.value.status})}),t.value.status==="SUSPENDED"&&e(G,{children:[e(J,{label:"Suspended At",value:t.value.suspendedAt?se(t.value.suspendedAt):"--"}),e(J,{label:"Suspension Reason",value:t.value.suspensionReason??"--"})]}),e(J,{label:"Created",value:se(t.value.createdAt)}),e(J,{label:"Updated",value:t.value.updatedAt?se(t.value.updatedAt):"Never"})]}),e("div",{class:"balance-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Balances"}),E.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):p.value?.balances?.length?e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-3)"},children:p.value.balances.map(y=>e("div",{style:{padding:"var(--space-3)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",background:y.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:y.network}),y.isDefault&&e("span",{class:"badge badge-info",style:{fontSize:"0.7rem"},children:"Default"})]}),y.error?e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:y.error}):y.native?e("div",{children:[e(J,{label:"Native",value:`${y.native.balance} ${y.native.symbol}`}),y.tokens.length>0?y.tokens.map($=>e(J,{label:$.symbol,value:$.balance},$.address)):null]}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Balance unavailable"})]},y.network))}):e("p",{style:{color:"var(--color-text-secondary)"},children:"No balance data available"})]}),e("div",{class:"networks-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Available Networks"}),d.value?e("div",{class:"stat-skeleton",style:{height:"80px"}}):e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:(u.value??[]).map(y=>e("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"var(--space-2) var(--space-3)",background:"var(--color-bg-secondary)",borderRadius:"var(--radius-md)"},children:[e("span",{children:[y.name??y.network,y.isDefault&&e(U,{variant:"success",style:{marginLeft:"var(--space-2)"},children:"Default"})]}),!y.isDefault&&t.value?.status==="ACTIVE"&&e(A,{size:"sm",variant:"secondary",onClick:()=>Za(y.network),loading:m.value,children:"Set Default"})]},y.network))})]}),e("div",{class:"transactions-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Recent Transactions"}),e(Te,{columns:[{key:"createdAt",header:"Time",render:y=>y.createdAt?se(y.createdAt):"--"},{key:"type",header:"Type",render:y=>y.type},{key:"toAddress",header:"To",render:y=>y.toAddress?Wt(y.toAddress):"--"},{key:"amount",header:"Amount",render:y=>y.amount??"--"},{key:"status",header:"Status",render:y=>e(U,{variant:y.status==="CONFIRMED"?"success":y.status==="FAILED"?"danger":"warning",children:y.status})},{key:"network",header:"Network",render:y=>y.network??"--"}],data:N.value,loading:b.value,emptyMessage:"No transactions yet"})]}),e("div",{class:"owner-section",style:{marginTop:"var(--space-6)"},children:[e("h3",{style:{marginBottom:"var(--space-3)"},children:"Owner Wallet"}),t.value.ownerState==="NONE"&&t.value.status!=="TERMINATED"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginBottom:"var(--space-4)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500},children:"What is an Owner Wallet?"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem",marginBottom:"var(--space-3)"},children:"Register an Owner wallet to enable transaction approval (APPROVAL policy) for high-value transfers. Connect D'CENT, MetaMask, or other WalletConnect-compatible wallets to approve transactions directly."}),e(A,{size:"sm",onClick:zt,children:"Set Owner Address"})]}),e(J,{label:"Address",children:_.value?e("div",{class:"inline-edit",children:[e("input",{value:L.value,onInput:y=>{L.value=y.target.value},class:"inline-edit-input",placeholder:"Enter owner wallet address"}),e(A,{size:"sm",onClick:Xa,loading:Y.value,children:"Save"}),e(A,{size:"sm",variant:"secondary",onClick:Ja,children:"Cancel"})]}):e("span",{children:[t.value.ownerAddress?e(G,{children:[Wt(t.value.ownerAddress),e(ze,{value:t.value.ownerAddress})]}):"Not set",t.value.ownerState!=="LOCKED"&&t.value.status==="ACTIVE"&&e("button",{class:"btn btn-ghost btn-sm",onClick:zt,title:"Set owner address",children:"✎"})]})}),e(J,{label:"State",children:e(U,{variant:za(t.value.ownerState),children:t.value.ownerState})}),t.value.ownerState==="GRACE"&&e("div",{style:{background:"var(--color-bg-secondary)",border:"1px solid var(--color-border)",borderRadius:"var(--radius-md)",padding:"var(--space-3) var(--space-4)",marginTop:"var(--space-3)"},children:[e("p",{style:{marginBottom:"var(--space-2)",fontWeight:500,fontSize:"0.85rem"},children:"Verify Owner"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Sign a verification message with the Owner wallet to transition from GRACE to LOCKED. Connect via WalletConnect first, then trigger an APPROVAL-tier transaction or use the CLI/SDK to call the verify endpoint."})]}),t.value.ownerState!=="NONE"&&e("div",{style:{marginTop:"var(--space-4)",paddingTop:"var(--space-3)",borderTop:"1px solid var(--color-border)"},children:[e("h4",{style:{marginBottom:"var(--space-2)",fontSize:"0.9rem"},children:"Approval Method"}),e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem",marginBottom:"var(--space-3)"},children:'Choose how transaction approvals are delivered to the owner. Leave as "Auto (Global Fallback)" to use the system-wide priority.'}),e("div",{style:{display:"flex",flexDirection:"column",gap:"var(--space-2)"},children:tl.map(y=>e("label",{style:{display:"flex",alignItems:"flex-start",gap:"var(--space-2)",padding:"var(--space-2) var(--space-3)",background:t.value?.approvalMethod===y.value?"var(--color-bg-secondary)":"transparent",borderRadius:"var(--radius-md)",cursor:"pointer"},children:[e("input",{type:"radio",name:"approval_method",value:y.value??"",checked:t.value?.approvalMethod===y.value,onChange:()=>en(y.value),style:{marginTop:"2px"}}),e("div",{children:[e("div",{style:{fontWeight:500,fontSize:"0.9rem"},children:y.label}),e("div",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:y.description}),y.warning&&y.warningCondition?.(Q.value)&&e("div",{style:{marginTop:"var(--space-1)",padding:"var(--space-1) var(--space-2)",background:"var(--color-warning-bg, #fff3cd)",border:"1px solid var(--color-warning-border, #ffc107)",borderRadius:"var(--radius-sm)",fontSize:"0.75rem",color:"var(--color-warning-text, #856404)"},children:y.warning})]})]},y.value??"auto"))})]}),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"}),k.value?e("div",{class:"stat-skeleton",style:{height:"60px"}}):V.value?e("div",{children:[e(J,{label:"Status",children:e(U,{variant:"success",children:"Connected"})}),e(J,{label:"Peer",value:V.value.peerName??"Unknown"}),e(J,{label:"Chain ID",value:V.value.chainId}),e(J,{label:"Expires",value:se(V.value.expiry)}),e("div",{style:{marginTop:"var(--space-3)"},children:e(A,{variant:"danger",onClick:Ya,loading:W.value,children:"Disconnect"})})]}):e("div",{children:[e("p",{style:{marginBottom:"var(--space-3)",color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Connect an external wallet (D'CENT, MetaMask, Phantom) via WalletConnect for transaction approval."}),t.value?.ownerAddress?e(A,{onClick:ja,loading:F.value,children:"Connect Wallet"}):e("p",{style:{color:"var(--color-text-secondary)",fontSize:"0.85rem"},children:"Set an Owner address first to enable WalletConnect."})]})]})]}),e("div",{class:"mcp-setup-section",style:{marginTop:"var(--space-6)"},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(J,{label:"Token Path",value:r.value.tokenPath}),e(J,{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(ze,{value:JSON.stringify({mcpServers:r.value.claudeDesktopConfig},null,2),label:"Copy Config"})})]}),e("div",{style:{marginTop:"var(--space-3)"},children:e(A,{variant:"secondary",onClick:Je,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(A,{onClick:Je,loading:h.value,children:"Setup MCP"})]})]}),e(re,{open:o.value,title:"Terminate Wallet",onCancel:()=>{o.value=!1},onConfirm:_t,confirmText:"Terminate",confirmVariant:"danger",loading:c.value,children:e("p",{children:["Are you sure you want to terminate wallet ",e("strong",{children:t.value.name}),"? This action cannot be undone."]})}),e(re,{open:I.value,title:"Scan QR Code",onCancel:()=>{I.value=!1,P.value&&clearInterval(P.value),P.value=null},children:x.value&&e("div",{style:{textAlign:"center"},children:[e("img",{src:x.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(re,{open:ee.value,title:"Suspend Wallet",onCancel:()=>{ee.value=!1,T.value=""},onConfirm:yt,confirmText:"Suspend",confirmVariant:"danger",loading:de.value,children:[e("p",{style:{marginBottom:"var(--space-3)"},children:["Are you sure you want to suspend wallet ",e("strong",{children:t.value.name}),"? Suspended wallets cannot process transactions until resumed."]}),e(S,{label:"Reason (optional)",name:"suspend-reason",value:T.value,onChange:y=>{T.value=y},placeholder:"e.g. suspicious activity"})]})]}):e(Xn,{title:"Wallet not found",description:"The wallet may have been deleted."})]})}const nl=["solana_mainnet","solana_devnet","solana_testnet"],ll=["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"],il={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"},sa={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"},sl=[{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 rl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v({}),s=v({}),o=async()=>{try{const p=await q(C.ADMIN_SETTINGS);a.value=p}catch(p){const E=p instanceof f?p:new f(0,"UNKNOWN","Unknown error");g("error",D(E.code))}finally{l.value=!1}};R(()=>{o()},[]);const c=(p,E)=>{const N=String(E);t.value={...t.value,[p]:N}},h=async()=>{n.value=!0;try{const p=Object.entries(t.value).filter(([N])=>N.startsWith("rpc.")).map(([N,b])=>({key:N,value:b})),E=await le(C.ADMIN_SETTINGS,{settings:p});a.value=E.settings,t.value={},g("success","Settings saved and applied")}catch(p){const E=p instanceof f?p:new f(0,"UNKNOWN","Unknown error");g("error",D(E.code))}finally{n.value=!1}},r=()=>{t.value={}};R(()=>(ge({id:"wallets-rpc",isDirty:()=>Object.keys(t.value).filter(p=>p.startsWith("rpc.")).length>0,save:h,discard:r}),()=>be("wallets-rpc")),[]);const u=async p=>{const E=p.split(".")[1]??"",N=K(a.value,t.value,"rpc",E);if(!N){g("warning","Enter a URL before testing");return}const b=E.startsWith("solana")?"solana":"evm";s.value={...s.value,[p]:!0};try{const I=await te(C.ADMIN_SETTINGS_TEST_RPC,{url:N,chain:b});i.value={...i.value,[p]:I}}catch{i.value={...i.value,[p]:{success:!1,latencyMs:0,error:"Request failed"}}}finally{s.value={...s.value,[p]:!1}}};function d({shortKey:p}){const E=`rpc.${p}`,N=i.value[E],b=s.value[E];return e("div",{class:"settings-field-full",children:[e("div",{class:"rpc-field-row",children:[e(S,{label:O(p),name:E,type:"text",value:K(a.value,t.value,"rpc",p),onChange:I=>c(E,I),placeholder:"https://...",description:il[p]}),e(A,{variant:"ghost",size:"sm",onClick:()=>u(E),loading:!!b,children:"Test"})]}),N&&e("div",{class:`rpc-test-result ${N.success?"rpc-test-result--success":"rpc-test-result--failure"}`,children:[e(U,{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 m=Object.keys(t.value).filter(p=>p.startsWith("rpc.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{children:[m>0&&e("div",{class:"settings-save-bar",children:[e("span",{children:[m," unsaved change",m>1?"s":""]}),e("div",{class:"settings-save-bar-actions",children:[e(A,{variant:"ghost",size:"sm",onClick:r,children:"Discard"}),e(A,{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:nl.map(p=>e(d,{shortKey:p},p))})]}),e("div",{class:"settings-subgroup",children:[e("div",{class:"settings-subgroup-title",children:"EVM"}),e("div",{class:"settings-fields-grid",children:[ll.map(p=>e(d,{shortKey:p},p)),e("div",{class:"settings-field-full",children:e(S,{label:O("evm_default_network"),name:"rpc.evm_default_network",type:"select",value:K(a.value,t.value,"rpc","evm_default_network")||"ethereum-sepolia",onChange:p=>c("rpc.evm_default_network",p),options:sl,description:"Default EVM network for new wallets"})})]})]})]})]})]})}function ol(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const u=await q(C.ADMIN_SETTINGS);a.value=u}catch(u){const d=u instanceof f?u:new f(0,"UNKNOWN","Unknown error");g("error",D(d.code))}finally{l.value=!1}};R(()=>{i()},[]);const s=(u,d)=>{const m=String(d);t.value={...t.value,[u]:m}},o=async()=>{n.value=!0;try{const u=Object.entries(t.value).filter(([m])=>m.startsWith("monitoring.")).map(([m,p])=>({key:m,value:p})),d=await le(C.ADMIN_SETTINGS,{settings:u});a.value=d.settings,t.value={},g("success","Settings saved and applied")}catch(u){const d=u instanceof f?u:new f(0,"UNKNOWN","Unknown error");g("error",D(d.code))}finally{n.value=!1}},c=()=>{t.value={}};R(()=>(ge({id:"wallets-monitoring",isDirty:()=>Object.keys(t.value).filter(u=>u.startsWith("monitoring.")).length>0,save:o,discard:c}),()=>be("wallets-monitoring")),[]);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(t.value).filter(u=>u.startsWith("monitoring.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{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(A,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(A,{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(u=>u.type==="checkbox"?e("div",{class:"settings-field-full",children:e(S,{label:O(u.key),name:`monitoring.${u.key}`,type:"checkbox",value:fe(a.value,t.value,"monitoring",u.key),onChange:d=>s(`monitoring.${u.key}`,d),description:sa[u.key]})},u.key):e(S,{label:O(u.key),name:`monitoring.${u.key}`,type:"number",value:Number(K(a.value,t.value,"monitoring",u.key))||0,onChange:d=>s(`monitoring.${u.key}`,d),min:u.min,max:u.max,description:sa[u.key]},u.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 cl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await q(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{l.value=!1}};R(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([d])=>d.startsWith("walletconnect.")).map(([d,m])=>({key:d,value:m})),u=await le(C.ADMIN_SETTINGS,{settings:r});a.value=u.settings,t.value={},g("success","Settings saved and applied")}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{n.value=!1}},c=()=>{t.value={}};R(()=>(ge({id:"wallets-walletconnect",isDirty:()=>Object.keys(t.value).filter(r=>r.startsWith("walletconnect.")).length>0,save:o,discard:c}),()=>be("wallets-walletconnect")),[]);const h=Object.keys(t.value).filter(r=>r.startsWith("walletconnect.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{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(A,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(A,{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(S,{label:O("project_id"),name:"walletconnect.project_id",type:"text",value:K(a.value,t.value,"walletconnect","project_id"),onChange:r=>s("walletconnect.project_id",r),description:"WalletConnect Cloud project identifier"})}),e("div",{class:"settings-field-full",children:e(S,{label:O("relay_url"),name:"walletconnect.relay_url",type:"text",value:K(a.value,t.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."})]})]})]})}function dl(){const a=v([]),t=v(!0),n=v(!1),l=v(""),i=v("solana"),s=v("testnet"),o=v(null),c=v(!1),h=v(null),r=async()=>{try{const p=await q(C.WALLETS);a.value=p.items}catch(p){const E=p instanceof f?p:new f(0,"UNKNOWN","Unknown error");g("error",D(E.code))}finally{t.value=!1}},u=async()=>{if(!l.value.trim()){o.value="Name is required";return}o.value=null,c.value=!0;try{const p=await te(C.WALLETS,{name:l.value.trim(),chain:i.value,environment:s.value});p.session?.token?(h.value=p.session.token,g("success","Wallet created with session")):g("success","Wallet created"),l.value="",i.value="solana",s.value="testnet",n.value=!1,t.value=!0,await r()}catch(p){const E=p instanceof f?p:new f(0,"UNKNOWN","Unknown error");o.value=D(E.code)}finally{c.value=!1}},d=p=>{window.location.hash="#/wallets/"+p.id},m=p=>{i.value=p};return R(()=>{r()},[]),e(G,{children:[e("div",{class:"page-actions",children:!n.value&&e(A,{onClick:()=>{n.value=!0},children:"Create Wallet"})}),n.value&&e("div",{class:"inline-form",children:[e(S,{label:"Name",name:"name",value:l.value,onChange:p=>{l.value=p},required:!0,placeholder:"e.g. trading-bot",error:o.value??void 0}),e(S,{label:"Chain",name:"chain",type:"select",value:i.value,onChange:m,options:[{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}]}),e(S,{label:"Environment",name:"environment",type:"select",value:s.value,onChange:p=>{s.value=p},options:[{label:"Testnet",value:"testnet"},{label:"Mainnet",value:"mainnet"}]}),e("div",{class:"inline-form-actions",children:[e(A,{onClick:u,loading:c.value,children:"Create"}),e(A,{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:p=>p.target.select()}),e(A,{variant:"secondary",onClick:()=>{navigator.clipboard.writeText(h.value),g("success","Token copied")},children:"Copy"}),e(A,{variant:"secondary",onClick:()=>{h.value=null},children:"Dismiss"})]})]}),e(Te,{columns:el,data:a.value,loading:t.value,onRowClick:d,emptyMessage:"No wallets yet"})]})}const ra=[{key:"wallets",label:"Wallets"},{key:"rpc",label:"RPC Endpoints"},{key:"monitoring",label:"Balance Monitoring"},{key:"walletconnect",label:"WalletConnect"}];function ul(){const a=v("wallets");return R(()=>{const t=Z.value;t&&t.tab&&(a.value=t.tab,setTimeout(()=>{ce.value=t.fieldName},100),Z.value=null)},[Z.value]),e("div",{class:"page",children:[e(Ye,{pageName:"Wallets",tabName:ra.find(t=>t.key===a.value)?.label??"",onPageClick:()=>{a.value="wallets"}}),e(je,{tabs:ra,activeTab:a.value,onTabChange:t=>{a.value=t}}),a.value==="wallets"&&e(dl,{}),a.value==="rpc"&&e(rl,{}),a.value==="monitoring"&&e(ol,{}),a.value==="walletconnect"&&e(cl,{})]})}function oa(){const a=pe.value,t=a.startsWith("/wallets/")?a.slice(9):null;return t?e(al,{id:t}):e(ul,{})}function Se({legend:a,children:t,description:n}){return e("fieldset",{class:"field-group",children:[e("legend",{class:"field-group-legend",children:a}),n&&e("p",{class:"field-group-description",children:n}),e("div",{class:"field-group-body",children:t})]})}function vl(a,t,n){t.value=a,n.value=!0}const ca=[{key:"sessions",label:"Sessions"},{key:"settings",label:"Settings"}],Nt=["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 hl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await q(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{l.value=!1}};R(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([d])=>Nt.includes(d)).map(([d,m])=>({key:d,value:m})),u=await le(C.ADMIN_SETTINGS,{settings:r});a.value=u.settings,t.value={},g("success","Session settings saved and applied")}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{n.value=!1}},c=()=>{t.value={}};R(()=>(ge({id:"sessions-settings",isDirty:()=>Object.keys(t.value).filter(r=>Nt.includes(r)).length>0,save:o,discard:c}),()=>be("sessions-settings")),[]);const h=Object.keys(t.value).filter(r=>Nt.includes(r)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{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(A,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(A,{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(Se,{legend:"Lifetime",description:"Session duration and renewal limits",children:e("div",{class:"settings-fields-grid",children:[e(S,{label:O("session_ttl"),name:"security.session_ttl",type:"number",value:Number(K(a.value,t.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(S,{label:O("session_absolute_lifetime"),name:"security.session_absolute_lifetime",type:"number",value:Number(K(a.value,t.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(S,{label:O("session_max_renewals"),name:"security.session_max_renewals",type:"number",value:Number(K(a.value,t.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(S,{label:O("max_sessions_per_wallet"),name:"security.max_sessions_per_wallet",type:"number",value:Number(K(a.value,t.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(Se,{legend:"Rate Limits",description:"Request throttling per session and transaction",children:e("div",{class:"settings-fields-grid",children:[e(S,{label:O("max_pending_tx"),name:"security.max_pending_tx",type:"number",value:Number(K(a.value,t.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(S,{label:O("rate_limit_session_rpm"),name:"security.rate_limit_session_rpm",type:"number",value:Number(K(a.value,t.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(S,{label:O("rate_limit_tx_rpm"),name:"security.rate_limit_tx_rpm",type:"number",value:Number(K(a.value,t.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 pl(){const a=v("sessions");R(()=>{const _=Z.value;_&&_.tab&&(a.value=_.tab,setTimeout(()=>{ce.value=_.fieldName},100),Z.value=null)},[Z.value]);const t=v([]),n=v(""),l=v(""),i=v([]),s=v(!1),o=v(!0),c=v(!1),h=v(!1),r=v(""),u=v(!1),d=v(""),m=v(!1),p=v(null),E=v(!1),N=v(new Set),b=v(""),I=async()=>{try{const _=await q(C.WALLETS);t.value=_.items.filter(L=>L.status==="ACTIVE")}catch(_){const L=_ instanceof f?_:new f(0,"UNKNOWN","Unknown error");g("error",D(L.code))}finally{o.value=!1}},x=async()=>{s.value=!0;try{const _=n.value?`${C.SESSIONS}?walletId=${n.value}`:C.SESSIONS,L=await q(_);i.value=L}catch(_){const L=_ instanceof f?_:new f(0,"UNKNOWN","Unknown error");g("error",D(L.code))}finally{s.value=!1}},F=_=>{const L=new Set(N.value);L.has(_)?(L.delete(_),b.value===_&&(b.value=L.size>0?Array.from(L)[0]??"":"")):(L.add(_),L.size===1&&(b.value=_)),N.value=L},V=async()=>{c.value=!0;try{const _=Array.from(N.value),L=_.length===1?{walletId:_[0]}:{walletIds:_,defaultWalletId:b.value||_[0]},Y=await te(C.SESSIONS,L);r.value=Y.token,h.value=!0,E.value=!1,await x()}catch(_){const L=_ instanceof f?_:new f(0,"UNKNOWN","Unknown error");g("error",D(L.code))}finally{c.value=!1}},k=async()=>{m.value=!0;try{await xe(C.SESSION(d.value)),g("success","Session revoked"),u.value=!1,await x()}catch(_){const L=_ instanceof f?_:new f(0,"UNKNOWN","Unknown error");g("error",D(L.code))}finally{m.value=!1}},W=async _=>{p.value=_;try{const L=await te(C.ADMIN_SESSION_REISSUE(_),{});r.value=L.token,h.value=!0,await x()}catch(L){const Y=L instanceof f?L:new f(0,"UNKNOWN","Unknown error");g("error",D(Y.code))}finally{p.value=null}};R(()=>{I()},[]),R(()=>{i.value=[],x()},[n.value]);const P=[{key:"id",header:"ID",render:_=>_.id.slice(0,8)+"..."},{key:"walletName",header:"Wallet",render:_=>_.wallets&&_.wallets.length>0?e("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:_.wallets.map(L=>e("span",{children:[L.name??L.id.slice(0,8),L.isDefault&&e(U,{variant:"info",children:"default"})]},L.id))}):_.walletName??_.walletId.slice(0,8)+"..."},{key:"source",header:"Source",render:_=>e(U,{variant:_.source==="mcp"?"info":"neutral",children:_.source==="mcp"?"MCP":"API"})},{key:"status",header:"Status",render:_=>e(U,{variant:_.status==="ACTIVE"?"success":_.status==="EXPIRED"?"warning":"danger",children:_.status})},{key:"expiresAt",header:"Expires At",render:_=>se(_.expiresAt)},{key:"renewals",header:"Renewals",render:_=>`${_.renewalCount}/${_.maxRenewals}`},{key:"tokenIssuedCount",header:"Tokens",render:_=>String(_.tokenIssuedCount??1)},{key:"createdAt",header:"Created",render:_=>se(_.createdAt)},{key:"actions",header:"Actions",render:_=>_.status==="ACTIVE"?e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[e(A,{size:"sm",variant:"secondary",onClick:()=>W(_.id),loading:p.value===_.id,children:"Reissue"}),e(A,{size:"sm",variant:"danger",onClick:()=>vl(_.id,d,u),children:"Revoke"})]}):null}];return e("div",{class:"page",children:[e(Ye,{pageName:"Sessions",tabName:ca.find(_=>_.key===a.value)?.label??"",onPageClick:()=>{a.value="sessions"}}),e(je,{tabs:ca,activeTab:a.value,onTabChange:_=>{a.value=_}}),a.value==="sessions"&&e(G,{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:_=>{n.value=_.target.value},disabled:o.value,children:[e("option",{value:"",children:"All Wallets"}),t.value.map(_=>e("option",{value:_.id,children:[_.name," (",_.chain,"/",_.network,")"]},_.id))]})]}),e("div",{class:"session-wallet-select",children:[e("label",{for:"source-select",children:"Source"}),e("select",{id:"source-select",value:l.value,onChange:_=>{l.value=_.target.value},children:[e("option",{value:"",children:"All"}),e("option",{value:"api",children:"API"}),e("option",{value:"mcp",children:"MCP"})]})]}),e(A,{onClick:()=>{N.value=new Set,b.value="",E.value=!0},disabled:t.value.length===0,children:"Create Session"})]}),e(Te,{columns:P,data:l.value?i.value.filter(_=>_.source===l.value):i.value,loading:s.value,emptyMessage:"No sessions"}),e(re,{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(ze,{value:r.value,label:"Copy Token"})]})]}),e(re,{open:u.value,title:"Revoke Session",onCancel:()=>{u.value=!1},onConfirm:k,confirmText:"Revoke",confirmVariant:"danger",loading:m.value,children:e("p",{children:"Are you sure you want to revoke this session? The associated token will be immediately invalidated."})}),e(re,{open:E.value,title:"Create Session",onCancel:()=>{E.value=!1},onConfirm:V,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:t.value.map(_=>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(_.id),onChange:()=>F(_.id)}),e("span",{children:_.name}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:["(",_.chain,"/",_.network,")"]})]},_.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:t.value.filter(_=>N.value.has(_.id)).map(_=>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:b.value===_.id,onChange:()=>{b.value=_.id}}),e("span",{children:_.name}),e("span",{style:{color:"var(--color-text-secondary)",fontSize:"0.8rem"},children:["(",_.chain,"/",_.network,")"]})]},_.id))})]})]})]}),a.value==="settings"&&e(hl,{})]})}function ml({rules:a,onChange:t,errors:n}){const l=s=>o=>{t({...a,[s]:o})},i=s=>o=>{const c=Number(o),h={...a};o===""||o===0||Number.isNaN(c)?delete h[s]:h[s]=c,t(h)};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Native Amount Tiers"}),e("div",{class:"policy-form-grid",children:[e(S,{label:"Instant Max (lamports/wei)",name:"instant_max",value:a.instant_max||"",onChange:l("instant_max"),error:n.instant_max,required:!0}),e(S,{label:"Notify Max (lamports/wei)",name:"notify_max",value:a.notify_max||"",onChange:l("notify_max"),error:n.notify_max,required:!0}),e(S,{label:"Delay Max (lamports/wei)",name:"delay_max",value:a.delay_max||"",onChange:l("delay_max"),error:n.delay_max,required:!0})]}),e("h4",{children:"USD Amount Tiers (Optional)"}),e("div",{class:"policy-form-grid",children:[e(S,{label:"Instant Max USD",name:"instant_max_usd",type:"number",value:a.instant_max_usd??"",onChange:i("instant_max_usd"),placeholder:"Optional"}),e(S,{label:"Notify Max USD",name:"notify_max_usd",type:"number",value:a.notify_max_usd??"",onChange:i("notify_max_usd"),placeholder:"Optional"}),e(S,{label:"Delay Max USD",name:"delay_max_usd",type:"number",value:a.delay_max_usd??"",onChange:i("delay_max_usd"),placeholder:"Optional"})]}),e("h4",{children:"Cumulative USD Limits (Optional)"}),e("div",{class:"policy-form-grid",children:[e(S,{label:"Daily Limit USD (24h rolling)",name:"daily_limit_usd",type:"number",value:a.daily_limit_usd??"",onChange:i("daily_limit_usd"),placeholder:"e.g. 500",error:n.daily_limit_usd}),e(S,{label:"Monthly Limit USD (30d rolling)",name:"monthly_limit_usd",type:"number",value:a.monthly_limit_usd??"",onChange:i("monthly_limit_usd"),placeholder:"e.g. 5000",error:n.monthly_limit_usd})]}),e(S,{label:"Delay Duration (seconds, min 60)",name:"delay_seconds",type:"number",value:a.delay_seconds??900,onChange:l("delay_seconds"),error:n.delay_seconds,required:!0,min:60})]})}function ye({items:a,onAdd:t,onRemove:n,renderRow:l,onChange:i,addLabel:s="+ Add",minItems:o=0,error:c}){return e("div",{class:"dynamic-row-list",children:[a.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:a.length<=o,title:"Remove",children:"x"})]},r)),e("button",{class:"btn btn-secondary btn-sm",onClick:t,children:s}),c&&e("span",{class:"form-error",children:c})]})}function fl({rules:a,onChange:t,errors:n}){const l=a.allowed_addresses||[];return e("div",{class:"policy-form-fields",children:e(ye,{items:l,onAdd:()=>t({...a,allowed_addresses:[...l,""]}),onRemove:i=>t({...a,allowed_addresses:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,allowed_addresses:o})},renderRow:(i,s,o)=>e(S,{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 _l({rules:a,onChange:t,errors:n}){const l=i=>s=>{t({...a,[i]:s})};return e("div",{class:"policy-form-fields",children:[e(S,{label:"Max Requests",name:"max_requests",type:"number",value:a.max_requests??100,onChange:l("max_requests"),error:n.max_requests,required:!0,min:1}),e(S,{label:"Window (seconds)",name:"window_seconds",type:"number",value:a.window_seconds??3600,onChange:l("window_seconds"),error:n.window_seconds,required:!0,min:1})]})}function yl({rules:a,onChange:t,errors:n}){const l=i=>{const s={...a};i===""||i===void 0?delete s.maxAmount:s.maxAmount=i,t(s)};return e("div",{class:"policy-form-fields",children:[e(S,{label:"Max Amount (lamports/wei, optional)",name:"maxAmount",value:a.maxAmount??"",onChange:l,error:n.maxAmount,placeholder:"Leave empty for no limit"}),e(S,{label:"Block Unlimited Approvals",name:"blockUnlimited",type:"checkbox",value:a.blockUnlimited??!0,onChange:i=>t({...a,blockUnlimited:i})})]})}const gl=[{label:"Instant",value:"INSTANT"},{label:"Notify",value:"NOTIFY"},{label:"Delay",value:"DELAY"},{label:"Approval",value:"APPROVAL"}];function bl({rules:a,onChange:t,errors:n}){return e("div",{class:"policy-form-fields",children:e(S,{label:"Override Tier",name:"tier",type:"select",value:a.tier??"DELAY",onChange:l=>t({...a,tier:l}),options:gl,error:n.tier})})}const wl=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function Sl({rules:a,onChange:t,errors:n}){const l=a.tokens||[];return e("div",{class:"policy-form-fields",children:e(ye,{items:l,onAdd:()=>t({...a,tokens:[...l,{address:"",symbol:"",chain:""}]}),onRemove:i=>t({...a,tokens:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,tokens:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(S,{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(S,{label:"Symbol",name:`token-symbol-${s}`,value:i.symbol,onChange:c=>o(s,{...i,symbol:c}),placeholder:"e.g. USDC"}),e(S,{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:wl})]}),addLabel:"+ Add Token",error:n.tokens})})}const kl=[{label:"All Chains",value:""},{label:"Solana",value:"solana"},{label:"Ethereum",value:"ethereum"}];function Nl({rules:a,onChange:t,errors:n}){const l=a.contracts||[];return e("div",{class:"policy-form-fields",children:e(ye,{items:l,onAdd:()=>t({...a,contracts:[...l,{address:"",name:"",chain:""}]}),onRemove:i=>t({...a,contracts:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,contracts:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(S,{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(S,{label:"Name",name:`contract-name-${s}`,value:i.name,onChange:c=>o(s,{...i,name:c}),placeholder:"e.g. Uniswap Router"}),e(S,{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:kl})]}),addLabel:"+ Add Contract",error:n.contracts})})}function Tl({rules:a,onChange:t,errors:n}){const l=a.methods||[],i=s=>{t({...a,methods:s})};return e("div",{class:"policy-form-fields",children:e(ye,{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(S,{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(ye,{items:s.selectors,onAdd:()=>c(o,{...s,selectors:[...s.selectors,""]}),onRemove:h=>c(o,{...s,selectors:s.selectors.filter((r,u)=>u!==h)}),onChange:(h,r)=>{const u=[...s.selectors];u[h]=r,c(o,{...s,selectors:u})},renderRow:(h,r,u)=>e(S,{label:`Selector ${r+1}`,name:`method-sel-${o}-${r}`,value:h,onChange:d=>u(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 El({rules:a,onChange:t,errors:n}){const l=a.spenders||[];return e("div",{class:"policy-form-fields",children:e(ye,{items:l,onAdd:()=>t({...a,spenders:[...l,{address:"",name:"",maxAmount:""}]}),onRemove:i=>t({...a,spenders:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,s.maxAmount||delete o[i].maxAmount,t({...a,spenders:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(S,{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(S,{label:"Name",name:`spender-name-${s}`,value:i.name,onChange:c=>o(s,{...i,name:c}),placeholder:"e.g. Uniswap"}),e(S,{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 Cl=Array.from({length:24},(a,t)=>({label:`${String(t).padStart(2,"0")}:00`,value:String(t)})),Al=Array.from({length:24},(a,t)=>({label:`${String(t+1).padStart(2,"0")}:00`,value:String(t+1)})),Il=[{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 Dl({rules:a,onChange:t,errors:n}){const l=a.allowed_hours||{start:0,end:24},i=a.allowed_days||[],s=c=>h=>{const r={...l,[c]:Number(h)};t({...a,allowed_hours:r})},o=c=>{const h=i.includes(c)?i.filter(r=>r!==c):[...i,c].sort((r,u)=>r-u);t({...a,allowed_days:h})};return e("div",{class:"policy-form-fields",children:[e("h4",{children:"Allowed Hours"}),e("div",{class:"policy-form-grid",children:[e(S,{label:"Start Hour",name:"allowed_hours_start",type:"select",value:String(l.start),onChange:s("start"),options:Cl,error:n.allowed_hours}),e(S,{label:"End Hour",name:"allowed_hours_end",type:"select",value:String(l.end),onChange:s("end"),options:Al})]}),e("h4",{children:"Allowed Days"}),e("div",{style:{display:"flex",gap:"0.75rem",flexWrap:"wrap"},children:Il.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 Ll=[{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 xl({rules:a,onChange:t,errors:n}){const l=a.networks||[];return e("div",{class:"policy-form-fields",children:e(ye,{items:l,onAdd:()=>t({...a,networks:[...l,{network:"mainnet",name:""}]}),onRemove:i=>t({...a,networks:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,networks:o})},renderRow:(i,s,o)=>e("div",{class:"dynamic-row-fields",style:{display:"flex",gap:"0.5rem",flex:1},children:[e(S,{label:`Network ${s+1}`,name:`network-sel-${s}`,type:"select",value:i.network,onChange:c=>o(s,{...i,network:c}),options:Ll,error:n[`networks.${s}.network`],required:!0}),e(S,{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 Ol({rules:a,onChange:t,errors:n}){const l=a.domains||[];return e("div",{class:"policy-form-fields",children:e(ye,{items:l,onAdd:()=>t({...a,domains:[...l,""]}),onRemove:i=>t({...a,domains:l.filter((s,o)=>o!==i)}),onChange:(i,s)=>{const o=[...l];o[i]=s,t({...a,domains:o})},renderRow:(i,s,o)=>e(S,{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 da({type:a,rules:t,onChange:n,errors:l}){switch(a){case"SPENDING_LIMIT":return e(ml,{rules:t,onChange:n,errors:l});case"WHITELIST":return e(fl,{rules:t,onChange:n,errors:l});case"RATE_LIMIT":return e(_l,{rules:t,onChange:n,errors:l});case"APPROVE_AMOUNT_LIMIT":return e(yl,{rules:t,onChange:n,errors:l});case"APPROVE_TIER_OVERRIDE":return e(bl,{rules:t,onChange:n,errors:l});case"ALLOWED_TOKENS":return e(Sl,{rules:t,onChange:n,errors:l});case"CONTRACT_WHITELIST":return e(Nl,{rules:t,onChange:n,errors:l});case"METHOD_WHITELIST":return e(Tl,{rules:t,onChange:n,errors:l});case"APPROVED_SPENDERS":return e(El,{rules:t,onChange:n,errors:l});case"TIME_RESTRICTION":return e(Dl,{rules:t,onChange:n,errors:l});case"ALLOWED_NETWORKS":return e(xl,{rules:t,onChange:n,errors:l});case"X402_ALLOWED_DOMAINS":return e(Ol,{rules:t,onChange:n,errors:l});default:return e("p",{class:"policy-form-placeholder",children:"This policy type uses JSON editor. Toggle to JSON mode."})}}function Mt(a){const t=typeof a=="string"?Number(a):a;return Number.isNaN(t)?String(a):t.toLocaleString("en-US")}function Rl(a){return a===86400?"1d":a%86400===0?`${a/86400}d`:a===3600?"1h":a%3600===0?`${a/3600}h`:a===60?"1m":a%60===0?`${a/60}m`:`${a}s`}const Tt=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"];function Pl(a){if(!a||a.length===0)return"";const t=[...a].sort((l,i)=>l-i);let n=!0;for(let l=1;l<t.length;l++)if(t[l]!==t[l-1]+1){n=!1;break}return n&&t.length>2?`${Tt[t[0]]}-${Tt[t[t.length-1]]}`:t.map(l=>Tt[l]??String(l)).join(", ")}function ua(a){return String(a).padStart(2,"0")}function Wl({rules:a}){const t=Number(a.instant_max??0),n=Number(a.notify_max??0),l=Number(a.delay_max??0),i=Math.max(t,n,l,1),s=[{label:"Instant",value:a.instant_max,width:t/i*100,cls:"instant"},{label:"Notify",value:a.notify_max,width:n/i*100,cls:"notify"},{label:"Delay",value:a.delay_max,width:l/i*100,cls:"delay"},{label:"Approval",value:"",width:100,cls:"approval"}];return e("div",{class:"tier-bars",children:s.map(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?Mt(o.value):""})]},o.cls))})}function va(a){return a.toLocaleString("en-US",{minimumFractionDigits:0,maximumFractionDigits:2})}function Ml({rules:a}){const t=a.daily_limit_usd,n=a.monthly_limit_usd;return!t&&!n?null:e("div",{class:"cumulative-limits",children:[e("div",{class:"cumulative-limits-label",children:"Cumulative Limits"}),t&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Daily (24h)"}),e("span",{class:"cumulative-limit-value",children:["$",va(t)]})]}),n&&e("div",{class:"cumulative-limit-row",children:[e("span",{class:"cumulative-limit-type",children:"Monthly (30d)"}),e("span",{class:"cumulative-limit-value",children:["$",va(n)]})]})]})}const Ul={INSTANT:"success",NOTIFY:"info",DELAY:"warning",APPROVAL:"danger"};function $l({type:a,rules:t}){switch(a){case"SPENDING_LIMIT":return e("div",{class:"spending-limit-summary",children:[e(Wl,{rules:t}),e(Ml,{rules:t})]});case"ALLOWED_TOKENS":{const n=t.tokens||[];return n.length===0?e("span",{class:"rules-vis-text",children:"No tokens"}):e("div",{class:"rules-vis-badges",children:n.map((l,i)=>e(U,{variant:"info",children:l.symbol||(l.address?l.address.slice(0,8)+"...":"?")},i))})}case"RATE_LIMIT":{const n=t.max_requests,l=t.window_seconds;return e("span",{class:"rules-vis-text",children:[n," req / ",Rl(l)]})}case"WHITELIST":{const n=t.allowed_addresses||[];return e(U,{variant:"neutral",children:[n.length," addresses"]})}case"TIME_RESTRICTION":{const n=t.allowed_days||[],l=t.allowed_hours,i=Pl(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=t.contracts||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No contracts"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,o)=>e(U,{variant:"neutral",children:s.name||(s.address?s.address.slice(0,8)+"...":"?")},o)),i>0&&e(U,{variant:"neutral",children:["+",i," more"]})]})}case"METHOD_WHITELIST":{const n=t.methods||[],l=n.length,i=n.reduce((s,o)=>s+(o.selectors?.length||0),0);return e(U,{variant:"neutral",children:[l," contracts, ",i," methods"]})}case"APPROVED_SPENDERS":{const n=t.spenders||[];return e(U,{variant:"neutral",children:[n.length," spenders"]})}case"APPROVE_AMOUNT_LIMIT":{const n=t.maxAmount,l=t.blockUnlimited;return n&&l?e("span",{class:"rules-vis-text",children:["Max: ",Mt(n)," + Block unlimited"]}):n?e("span",{class:"rules-vis-text",children:["Max: ",Mt(n)]}):l?e("span",{class:"rules-vis-text",children:"Block unlimited only"}):e("span",{class:"rules-vis-text",children:"No limits"})}case"APPROVE_TIER_OVERRIDE":{const n=t.tier||"DELAY",l=Ul[n]||"neutral";return e(U,{variant:l,children:n})}case"ALLOWED_NETWORKS":{const n=t.networks||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No networks"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,o)=>e(U,{variant:"info",children:s.network},o)),i>0&&e(U,{variant:"info",children:["+",i," more"]})]})}case"X402_ALLOWED_DOMAINS":{const n=t.domains||[];if(n.length===0)return e("span",{class:"rules-vis-text",children:"No domains"});const l=n.slice(0,3),i=n.length-3;return e("div",{class:"rules-vis-badges",children:[l.map((s,o)=>e(U,{variant:"neutral",children:s},o)),i>0&&e(U,{variant:"neutral",children:["+",i," more"]})]})}default:{const n=JSON.stringify(t);return e("span",{class:"rules-summary",children:n.length>60?n.slice(0,60)+"...":n})}}}const Ga=[{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"}],Me={SPENDING_LIMIT:{instant_max:"1000000",notify_max:"5000000",delay_max:"10000000",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 tt(a,t){const n={};if(a==="SPENDING_LIMIT"){(!t.instant_max||!/^\d+$/.test(t.instant_max))&&(n.instant_max="Positive integer required"),(!t.notify_max||!/^\d+$/.test(t.notify_max))&&(n.notify_max="Positive integer required"),(!t.delay_max||!/^\d+$/.test(t.delay_max))&&(n.delay_max="Positive integer required");const l=Number(t.delay_seconds);(t.delay_seconds===void 0||t.delay_seconds===""||Number.isNaN(l)||l<60)&&(n.delay_seconds="Minimum 60 seconds");const i=t.daily_limit_usd;if(i!==void 0&&i!==""){const o=Number(i);(Number.isNaN(o)||o<=0)&&(n.daily_limit_usd="Must be a positive number")}const s=t.monthly_limit_usd;if(s!==void 0&&s!==""){const o=Number(s);(Number.isNaN(o)||o<=0)&&(n.monthly_limit_usd="Must be a positive number")}}else if(a==="WHITELIST"){const l=t.allowed_addresses||[];l.length===0&&(n.allowed_addresses="At least one address required"),l.forEach((i,s)=>{(!i||i.trim()==="")&&(n[`allowed_addresses.${s}`]="Address required")})}else if(a==="RATE_LIMIT"){const l=Number(t.max_requests);(!t.max_requests||Number.isNaN(l)||l<1||!Number.isInteger(l))&&(n.max_requests="Positive integer required");const i=Number(t.window_seconds);(!t.window_seconds||Number.isNaN(i)||i<1||!Number.isInteger(i))&&(n.window_seconds="Positive integer required")}else if(a==="APPROVE_AMOUNT_LIMIT")t.maxAmount&&!/^\d+$/.test(t.maxAmount)&&(n.maxAmount="Must be a positive integer string");else if(a==="ALLOWED_TOKENS"){const l=t.tokens||[];l.length===0&&(n.tokens="At least one token required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`tokens.${s}.address`]="Address required")})}else if(a==="CONTRACT_WHITELIST"){const l=t.contracts||[];l.length===0&&(n.contracts="At least one contract required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`contracts.${s}.address`]="Address required")})}else if(a==="METHOD_WHITELIST"){const l=t.methods||[];l.length===0&&(n.methods="At least one method entry required"),l.forEach((i,s)=>{(!i.contractAddress||i.contractAddress.trim()==="")&&(n[`methods.${s}.contractAddress`]="Contract address required"),!i.selectors||i.selectors.length===0?n[`methods.${s}.selectors`]="At least one selector required":i.selectors.forEach((o,c)=>{(!o||o.trim()==="")&&(n[`methods.${s}.selectors.${c}`]="Selector required")})})}else if(a==="APPROVED_SPENDERS"){const l=t.spenders||[];l.length===0&&(n.spenders="At least one spender required"),l.forEach((i,s)=>{(!i.address||i.address.trim()==="")&&(n[`spenders.${s}.address`]="Address required"),i.maxAmount&&!/^\d+$/.test(i.maxAmount)&&(n[`spenders.${s}.maxAmount`]="Must be a positive integer")})}else if(a==="TIME_RESTRICTION"){(t.allowed_days||[]).length===0&&(n.allowed_days="At least one day required");const i=t.allowed_hours;i&&i.start>=i.end&&(n.allowed_hours="Start must be before end")}else if(a==="ALLOWED_NETWORKS"){const l=t.networks||[];l.length===0&&(n.networks="At least one network required"),l.forEach((i,s)=>{(!i.network||i.network.trim()==="")&&(n[`networks.${s}.network`]="Network required")})}else if(a==="X402_ALLOWED_DOMAINS"){const l=t.domains||[];l.length===0&&(n.domains="At least one domain required"),l.forEach((i,s)=>{(!i||i.trim()==="")&&(n[`domains.${s}`]="Domain required")})}return n}function Kl(a,t){if(!a)return"Global";const n=t.find(l=>l.id===a);return n?n.name:a.slice(0,8)+"..."}function Et(a){const t=Ga.find(n=>n.value===a);return t?t.label:a}const ha=[{key:"policies",label:"Policies"},{key:"defaults",label:"Defaults"}],Ct=["security.policy_defaults_delay_seconds","security.policy_defaults_approval_timeout","policy.default_deny_tokens","policy.default_deny_contracts","policy.default_deny_spenders"];function Fl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await q(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{l.value=!1}};R(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([d])=>Ct.includes(d)).map(([d,m])=>({key:d,value:m})),u=await le(C.ADMIN_SETTINGS,{settings:r});a.value=u.settings,t.value={},g("success","Policy defaults saved and applied")}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{n.value=!1}},c=()=>{t.value={}};R(()=>(ge({id:"policies-defaults",isDirty:()=>Object.keys(t.value).filter(r=>Ct.includes(r)).length>0,save:o,discard:c}),()=>be("policies-defaults")),[]);const h=Object.keys(t.value).filter(r=>Ct.includes(r)).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{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(A,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(A,{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(S,{label:O("policy_defaults_delay_seconds"),name:"security.policy_defaults_delay_seconds",type:"number",value:Number(K(a.value,t.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(S,{label:O("policy_defaults_approval_timeout"),name:"security.policy_defaults_approval_timeout",type:"number",value:Number(K(a.value,t.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(S,{label:O("default_deny_tokens"),name:"policy.default_deny_tokens",type:"checkbox",value:fe(a.value,t.value,"policy","default_deny_tokens"),onChange:r=>s("policy.default_deny_tokens",r),description:"Deny token transfers unless a matching whitelist policy exists"}),e(S,{label:O("default_deny_contracts"),name:"policy.default_deny_contracts",type:"checkbox",value:fe(a.value,t.value,"policy","default_deny_contracts"),onChange:r=>s("policy.default_deny_contracts",r),description:"Deny contract calls unless a matching whitelist policy exists"}),e(S,{label:O("default_deny_spenders"),name:"policy.default_deny_spenders",type:"checkbox",value:fe(a.value,t.value,"policy","default_deny_spenders"),onChange:r=>s("policy.default_deny_spenders",r),description:"Deny token approvals unless a matching whitelist policy exists"}),e(S,{label:O("default_deny_x402_domains"),name:"policy.default_deny_x402_domains",type:"checkbox",value:fe(a.value,t.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 Bl(){const a=v("policies");R(()=>{const w=Z.value;w&&w.tab&&(a.value=w.tab,setTimeout(()=>{ce.value=w.fieldName},100),Z.value=null)},[Z.value]);const t=v([]),n=v([]),l=v("__all__"),i=v(!1),s=v(!0),o=v(!1),c=v("SPENDING_LIMIT"),h=v(""),r=v(JSON.stringify(Me.SPENDING_LIMIT,null,2)),u=v(Me.SPENDING_LIMIT),d=v({}),m=v(!1),p=v(0),E=v(!0),N=v(""),b=v(null),I=v(!1),x=v(!1),F=v(null),V=v(""),k=v({}),W=v(!1),P=v({}),_=v(0),L=v(!0),Y=v(null),Q=v(!1),ee=v(!1),de=v(null),T=v(!1),M=async()=>{try{const w=await q(C.WALLETS);t.value=w.items}catch(w){const z=w instanceof f?w:new f(0,"UNKNOWN","Unknown error");g("error",D(z.code))}finally{s.value=!1}},j=async()=>{i.value=!0;try{let w=C.POLICIES;l.value!=="__all__"&&l.value!=="__global__"&&(w=`${C.POLICIES}?walletId=${l.value}`);const z=await q(w);l.value==="__global__"?n.value=z.filter(oe=>oe.walletId===null):n.value=z}catch(w){const z=w instanceof f?w:new f(0,"UNKNOWN","Unknown error");g("error",D(z.code))}finally{i.value=!1}},Pe=async()=>{b.value=null;let w;if(m.value)try{w=JSON.parse(r.value)}catch{b.value="Invalid JSON in rules field";return}else{const z=tt(c.value,u.value);if(Object.keys(z).length>0){d.value=z;return}d.value={},w=u.value}I.value=!0;try{await te(C.POLICIES,{walletId:h.value||void 0,type:c.value,rules:w,priority:p.value,enabled:E.value,network:N.value||void 0}),g("success","Policy created"),o.value=!1,c.value="SPENDING_LIMIT",h.value="",N.value="",r.value=JSON.stringify(Me.SPENDING_LIMIT,null,2),u.value=Me.SPENDING_LIMIT,d.value={},m.value=!1,p.value=0,E.value=!0,b.value=null,await j()}catch(z){const oe=z instanceof f?z:new f(0,"UNKNOWN","Unknown error");g("error",D(oe.code))}finally{I.value=!1}},_t=w=>{F.value=w,V.value=JSON.stringify(w.rules,null,2),k.value={...w.rules},W.value=!1,P.value={},_.value=w.priority,L.value=w.enabled,Y.value=null,x.value=!0},yt=async()=>{Y.value=null;let w;if(W.value)try{w=JSON.parse(V.value)}catch{Y.value="Invalid JSON in rules field";return}else{const z=tt(F.value.type,k.value);if(Object.keys(z).length>0){P.value=z;return}P.value={},w=k.value}Q.value=!0;try{await le(C.POLICY(F.value.id),{rules:w,priority:_.value,enabled:L.value}),g("success","Policy updated"),x.value=!1,await j()}catch(z){const oe=z instanceof f?z:new f(0,"UNKNOWN","Unknown error");g("error",D(oe.code))}finally{Q.value=!1}},gt=()=>{if(!W.value)V.value=JSON.stringify(k.value,null,2);else try{k.value=JSON.parse(V.value),Y.value=null}catch{Y.value="Invalid JSON — cannot switch to form mode";return}W.value=!W.value},bt=w=>{de.value=w,ee.value=!0},wt=async()=>{T.value=!0;try{await xe(C.POLICY(de.value.id)),g("success","Policy deleted"),ee.value=!1,await j()}catch(w){const z=w instanceof f?w:new f(0,"UNKNOWN","Unknown error");g("error",D(z.code))}finally{T.value=!1}},Je=w=>{const z=w;c.value=z;const oe=Me[z];oe&&(r.value=JSON.stringify(oe,null,2),u.value={...oe}),d.value={},m.value=!1},Xe=()=>{if(!m.value)r.value=JSON.stringify(u.value,null,2);else try{u.value=JSON.parse(r.value),b.value=null}catch{b.value="Invalid JSON — cannot switch to form mode";return}m.value=!m.value};R(()=>{M()},[]),R(()=>{j()},[l.value]);const St=[{key:"type",header:"Type",render:w=>e(U,{variant:w.type==="SPENDING_LIMIT"?"success":"info",children:Et(w.type)})},{key:"walletId",header:"Wallet",render:w=>Kl(w.walletId,t.value)},{key:"network",header:"Network",render:w=>w.network??"All"},{key:"rules",header:"Rules",render:w=>e($l,{type:w.type,rules:w.rules})},{key:"priority",header:"Priority"},{key:"enabled",header:"Enabled",render:w=>e(U,{variant:w.enabled?"success":"danger",children:w.enabled?"ON":"OFF"})},{key:"actions",header:"Actions",render:w=>e("span",{style:{display:"flex",gap:"0.25rem"},children:[e("button",{class:"btn btn-ghost btn-sm",onClick:z=>{z.stopPropagation(),_t(w)},children:"Edit"}),e(A,{size:"sm",variant:"danger",onClick:()=>bt(w),children:"Delete"})]})}];return e("div",{class:"page",children:[e(Ye,{pageName:"Policies",tabName:ha.find(w=>w.key===a.value)?.label??"",onPageClick:()=>{a.value="policies"}}),e(je,{tabs:ha,activeTab:a.value,onTabChange:w=>{a.value=w}}),a.value==="policies"&&e(G,{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:w=>{l.value=w.target.value},disabled:s.value,children:[e("option",{value:"__all__",children:"All Policies"}),e("option",{value:"__global__",children:"Global Only"}),t.value.map(w=>e("option",{value:w.id,children:[w.name," (",w.chain,"/",w.network,")"]},w.id))]})]}),!o.value&&e(A,{onClick:()=>{o.value=!0},children:"Create Policy"})]}),o.value&&e("div",{class:"inline-form",children:[e(S,{label:"Type",name:"type",type:"select",value:c.value,onChange:Je,options:Ga}),e(S,{label:"Wallet",name:"walletId",type:"select",value:h.value,onChange:w=>{h.value=w},options:[{label:"Global (no wallet)",value:""},...t.value.map(w=>({label:`${w.name} (${w.chain}/${w.network})`,value:w.id}))]}),e(S,{label:"Network Scope",name:"network",value:N.value,onChange:w=>{N.value=w},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:m.value?"Switch to Form":"JSON Direct Edit"})]}),m.value?e(S,{label:"",name:"rules",type:"textarea",value:r.value,onChange:w=>{r.value=w},error:b.value??void 0}):e(da,{type:c.value,rules:u.value,onChange:w=>{u.value=w,Object.keys(d.value).length>0&&(d.value=tt(c.value,w))},errors:d.value})]}),e(S,{label:"Priority",name:"priority",type:"number",value:p.value,onChange:w=>{p.value=w},min:0,max:999}),e(S,{label:"Enabled",name:"enabled",type:"checkbox",value:E.value,onChange:w=>{E.value=w}}),e("div",{class:"inline-form-actions",children:[e(A,{onClick:Pe,loading:I.value,children:"Create"}),e(A,{variant:"secondary",onClick:()=>{o.value=!1,b.value=null},children:"Cancel"})]})]}),e(Te,{columns:St,data:n.value,loading:i.value,emptyMessage:"No policies found"}),e(re,{open:x.value,title:"Edit Policy",onCancel:()=>{x.value=!1},onConfirm:yt,confirmText:"Save",loading:Q.value,children:F.value&&e("div",{children:[e("div",{class:"policy-type-readonly",children:["Type: ",Et(F.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:gt,children:W.value?"Switch to Form":"JSON Direct Edit"})]}),W.value?e("div",{class:"edit-rules-textarea",children:e(S,{label:"",name:"edit-rules",type:"textarea",value:V.value,onChange:w=>{V.value=w},error:Y.value??void 0})}):e(da,{type:F.value.type,rules:k.value,onChange:w=>{k.value=w,Object.keys(P.value).length>0&&(P.value=tt(F.value.type,w))},errors:P.value})]}),e(S,{label:"Priority",name:"edit-priority",type:"number",value:_.value,onChange:w=>{_.value=w},min:0,max:999}),e(S,{label:"Enabled",name:"edit-enabled",type:"checkbox",value:L.value,onChange:w=>{L.value=w}})]})}),e(re,{open:ee.value,title:"Delete Policy",onCancel:()=>{ee.value=!1},onConfirm:wt,confirmText:"Delete",confirmVariant:"danger",loading:T.value,children:de.value&&e("p",{children:["Are you sure you want to delete this"," ",e("strong",{children:Et(de.value.type)})," policy? This action cannot be undone."]})})]}),a.value==="defaults"&&e(Fl,{})]})}function Hl(){return e(Vl,{})}function Vl(){const a=v([]),t=v(!0),n=v(!1),l=v(null),i=v("ADMIN"),s=v(!1),o=v(!1),c=v(null),h=v(!1),r=async()=>{t.value=!0;try{const b=await q(C.ADMIN_TELEGRAM_USERS);a.value=b.users}catch(b){const I=b instanceof f?b:new f(0,"UNKNOWN","Unknown error");g("error",D(I.code))}finally{t.value=!1}};R(()=>{r()},[]);const u=b=>{l.value=b,i.value="ADMIN",n.value=!0},d=async()=>{if(l.value){s.value=!0;try{await le(C.ADMIN_TELEGRAM_USER(l.value.chat_id),{role:i.value}),g("success",`User approved as ${i.value}`),n.value=!1,l.value=null,await r()}catch(b){const I=b instanceof f?b:new f(0,"UNKNOWN","Unknown error");g("error",D(I.code))}finally{s.value=!1}}},m=b=>{c.value=b,o.value=!0},p=async()=>{if(c.value){h.value=!0;try{await xe(C.ADMIN_TELEGRAM_USER(c.value.chat_id)),g("success","User deleted"),o.value=!1,c.value=null,await r()}catch(b){const I=b instanceof f?b:new f(0,"UNKNOWN","Unknown error");g("error",D(I.code))}finally{h.value=!1}}},E=b=>b==="PENDING"?"warning":b==="ADMIN"?"success":"info";return e("div",{class:"page",children:[e(Te,{columns:[{key:"chat_id",header:"Chat ID",render:b=>String(b.chat_id)},{key:"username",header:"Username",render:b=>b.username??"-"},{key:"role",header:"Role",render:b=>e(U,{variant:E(b.role),children:b.role})},{key:"registered_at",header:"Registered",render:b=>se(b.registered_at)},{key:"approved_at",header:"Approved",render:b=>b.approved_at?se(b.approved_at):"-"},{key:"actions",header:"Actions",render:b=>e("div",{style:{display:"flex",gap:"var(--space-1)"},children:[b.role==="PENDING"&&e(A,{size:"sm",variant:"primary",onClick:()=>u(b),children:"Approve"}),e(A,{size:"sm",variant:"danger",onClick:()=>m(b),children:"Delete"})]})}],data:a.value,loading:t.value,emptyMessage:"No Telegram users registered. Users appear here after sending /start to the bot."}),e(re,{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:b=>{i.value=b.target.value},children:[e("option",{value:"ADMIN",children:"ADMIN"}),e("option",{value:"READONLY",children:"READONLY"})]})]})]})}),e(re,{open:o.value,title:"Delete Telegram User",onCancel:()=>{o.value=!1,c.value=null},onConfirm:p,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 At=20,pa=[{key:"channels",label:"Channels & Logs"},{key:"telegram",label:"Telegram Users"},{key:"settings",label:"Settings"}];function ql(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v([]),s=v(!1),o=async()=>{try{const m=await q(C.ADMIN_SETTINGS);a.value=m}catch(m){const p=m instanceof f?m:new f(0,"UNKNOWN","Unknown error");g("error",D(p.code))}finally{l.value=!1}};R(()=>{o()},[]);const c=(m,p)=>{const E=String(p);t.value={...t.value,[m]:E}},h=async()=>{n.value=!0;try{const m=Object.entries(t.value).filter(([E])=>E.startsWith("notifications.")||E.startsWith("telegram.")).map(([E,N])=>({key:E,value:N})),p=await le(C.ADMIN_SETTINGS,{settings:m});a.value=p.settings,t.value={},g("success","Notification settings saved and applied")}catch(m){const p=m instanceof f?m:new f(0,"UNKNOWN","Unknown error");g("error",D(p.code))}finally{n.value=!1}},r=()=>{t.value={}};R(()=>(ge({id:"notifications-settings",isDirty:()=>Object.keys(t.value).filter(m=>m.startsWith("notifications.")||m.startsWith("telegram.")).length>0,save:h,discard:r}),()=>be("notifications-settings")),[]);const u=async()=>{s.value=!0,i.value=[];try{const m=await te(C.ADMIN_NOTIFICATIONS_TEST,{});if(i.value=m.results,m.results.length===0)g("info","No notification channels configured");else{const p=m.results.every(E=>E.success);g(p?"success":"warning",p?"All test notifications sent":"Some channels failed")}}catch(m){const p=m instanceof f?m:new f(0,"UNKNOWN","Unknown error");g("error",D(p.code))}finally{s.value=!1}},d=Object.keys(t.value).filter(m=>m.startsWith("notifications.")||m.startsWith("telegram.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{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(A,{variant:"ghost",size:"sm",onClick:r,children:"Discard"}),e(A,{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(S,{label:"Enabled",name:"notifications.enabled",type:"checkbox",value:fe(a.value,t.value,"notifications","enabled"),onChange:m=>c("notifications.enabled",m),description:"Enable or disable notifications globally"})}),e(S,{label:O("locale"),name:"notifications.locale",type:"select",value:K(a.value,t.value,"notifications","locale")||"en",onChange:m=>c("notifications.locale",m),options:[{label:"English",value:"en"},{label:"Korean",value:"ko"}],description:"Language for notification messages"})]}),e(Se,{legend:"Telegram",description:"Telegram notification channel and bot configuration",children:[e("div",{class:"settings-fields-grid",children:[e(S,{label:O("telegram_bot_token"),name:"notifications.telegram_bot_token",type:"password",value:K(a.value,t.value,"notifications","telegram_bot_token"),onChange:m=>c("notifications.telegram_bot_token",m),placeholder:et(a.value,t.value,"notifications","telegram_bot_token")?"(configured)":"",description:"Bot token for Telegram notifications"}),e(S,{label:O("telegram_chat_id"),name:"notifications.telegram_chat_id",type:"text",value:K(a.value,t.value,"notifications","telegram_chat_id"),onChange:m=>c("notifications.telegram_chat_id",m),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(S,{label:O("bot_token"),name:"telegram.bot_token",type:"password",value:K(a.value,t.value,"telegram","bot_token"),onChange:m=>c("telegram.bot_token",m),placeholder:et(a.value,t.value,"telegram","bot_token")?"(configured)":"Leave empty to use notification token",description:"Dedicated bot token for Telegram bot (optional, uses notification token if empty)"}),e(S,{label:"Locale",name:"telegram.locale",type:"select",value:K(a.value,t.value,"telegram","locale")||"en",onChange:m=>c("telegram.locale",m),options:[{label:"English",value:"en"},{label:"한국어",value:"ko"}],description:"Language for Telegram bot messages"})]})]})]}),e(Se,{legend:"Other Channels",description:"Discord, ntfy, Slack, and rate limiting",children:e("div",{class:"settings-fields-grid",children:[e(S,{label:O("discord_webhook_url"),name:"notifications.discord_webhook_url",type:"password",value:K(a.value,t.value,"notifications","discord_webhook_url"),onChange:m=>c("notifications.discord_webhook_url",m),placeholder:et(a.value,t.value,"notifications","discord_webhook_url")?"(configured)":"",description:"Webhook URL for Discord notifications"}),e(S,{label:O("ntfy_server"),name:"notifications.ntfy_server",type:"text",value:K(a.value,t.value,"notifications","ntfy_server"),onChange:m=>c("notifications.ntfy_server",m),description:"Server URL for ntfy notifications"}),e(S,{label:O("ntfy_topic"),name:"notifications.ntfy_topic",type:"text",value:K(a.value,t.value,"notifications","ntfy_topic"),onChange:m=>c("notifications.ntfy_topic",m),description:"Topic name for ntfy notifications"}),e(S,{label:"Slack Webhook URL",name:"notifications.slack_webhook_url",type:"password",value:K(a.value,t.value,"notifications","slack_webhook_url"),onChange:m=>c("notifications.slack_webhook_url",m),placeholder:et(a.value,t.value,"notifications","slack_webhook_url")?"(configured)":"",description:"Webhook URL for Slack notifications"}),e(S,{label:O("rate_limit_rpm"),name:"notifications.rate_limit_rpm",type:"number",value:Number(K(a.value,t.value,"notifications","rate_limit_rpm"))||20,onChange:m=>c("notifications.rate_limit_rpm",m),min:1,max:1e3,description:"Max notifications per minute"})]})}),e(Se,{legend:"Category Filter",description:"Filter which notification categories are delivered. Leave all unchecked to receive all.",children:[(()=>{const m=[{value:"transaction",label:"Transaction Events"},{value:"policy",label:"Policy Violations"},{value:"security_alert",label:"Security Alerts"},{value:"session",label:"Session Events"},{value:"owner",label:"Owner Events"},{value:"system",label:"System Notifications"}],p=K(a.value,t.value,"notifications","notify_categories")||"[]";let E=[];try{const b=JSON.parse(p);Array.isArray(b)&&(E=b)}catch{}const N=(b,I)=>{const x=I?[...E,b]:E.filter(F=>F!==b);c("notifications.notify_categories",JSON.stringify(x))};return e("div",{class:"settings-fields-grid",children:m.map(b=>e(S,{label:b.label,name:`notify_cat_${b.value}`,type:"checkbox",value:E.includes(b.value),onChange:I=>N(b.value,!!I)},b.value))})})(),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(A,{variant:"secondary",size:"sm",onClick:u,loading:s.value,children:"Test Notification"}),i.value.length>0&&e("div",{class:"test-results",children:i.value.map(m=>e("div",{class:`test-result-item ${m.success?"test-result-success":"test-result-failure"}`,children:[e(U,{variant:m.success?"success":"danger",children:m.success?"OK":"FAIL"}),e("span",{children:m.channel}),m.error&&e("span",{style:"font-size: var(--font-size-xs); color: var(--color-danger);",children:[" - ",m.error]})]},m.channel))})]})]})]})]})}function ma(){const a=v("channels");R(()=>{const k=Z.value;k&&k.tab&&(a.value=k.tab,setTimeout(()=>{ce.value=k.fieldName},100),Z.value=null)},[Z.value]);const t=v(null),n=v(!0),l=v(!1),i=v(null),s=v(null),o=v(null),c=v(!0),h=v(1),r=v(null),u=async()=>{try{const k=await q(C.ADMIN_NOTIFICATIONS_STATUS);t.value=k}catch(k){const W=k instanceof f?k:new f(0,"UNKNOWN","Unknown error");g("error",D(W.code))}finally{n.value=!1}},d=async k=>{c.value=!0;try{const W=await q(`${C.ADMIN_NOTIFICATIONS_LOG}?page=${k}&pageSize=${At}`);o.value=W}catch(W){const P=W instanceof f?W:new f(0,"UNKNOWN","Unknown error");g("error",D(P.code))}finally{c.value=!1}},m=async()=>{l.value=!0,s.value=null;try{const W=(await te(C.ADMIN_NOTIFICATIONS_TEST,{})).results;s.value=W,W.every(_=>_.success)?g("success","Test sent successfully"):g("warning","Some channels failed")}catch(k){const W=k instanceof f?k:new f(0,"UNKNOWN","Unknown error");g("error",D(W.code))}finally{l.value=!1}},p=async k=>{i.value=k,s.value=null;try{const P=(await te(C.ADMIN_NOTIFICATIONS_TEST,{channel:k})).results;s.value=P,P.every(L=>L.success)?g("success",`Test sent to ${k}`):g("warning",`${k} test failed`)}catch(W){const P=W instanceof f?W:new f(0,"UNKNOWN","Unknown error");g("error",D(P.code))}finally{i.value=null}},E=()=>{h.value>1&&(h.value-=1,d(h.value))},N=()=>{const k=o.value?Math.ceil(o.value.total/At):1;h.value<k&&(h.value+=1,d(h.value))},b=k=>{r.value=r.value?.id===k.id?null:k};R(()=>{u(),d(1);const k=setInterval(()=>d(h.value),3e4);return()=>clearInterval(k)},[]);const I=n.value&&!t.value,x=t.value?.channels.some(k=>k.enabled)??!1,F=o.value?Math.max(1,Math.ceil(o.value.total/At)):1,V=[{key:"eventType",header:"Event Type"},{key:"walletId",header:"Wallet ID",render:k=>k.walletId?k.walletId.slice(0,8)+"...":"—"},{key:"channel",header:"Channel",render:k=>e("span",{style:{textTransform:"capitalize"},children:k.channel})},{key:"status",header:"Status",render:k=>e(U,{variant:k.status==="sent"?"success":"danger",children:k.status})},{key:"createdAt",header:"Time",render:k=>se(k.createdAt)}];return e("div",{class:"page",children:[e(Ye,{pageName:"Notifications",tabName:pa.find(k=>k.key===a.value)?.label??"",onPageClick:()=>{a.value="channels"}}),e(je,{tabs:pa,activeTab:a.value,onTabChange:k=>{a.value=k}}),a.value==="telegram"?e(Hl,{}):a.value==="settings"?e(ql,{}):e(G,{children:[e("h2",{children:"Channel Status"}),t.value&&!t.value.enabled&&e("div",{class:"notif-disabled-banner",children:["Notifications are disabled."," ",e("a",{href:"#",onClick:k=>{k.preventDefault(),a.value="settings"},children:"Enable them in the Settings tab"})]}),I?e("div",{class:"channel-grid",children:[1,2,3].map(k=>e("div",{class:"channel-card",children:e("div",{class:"stat-skeleton"})},k))}):e("div",{class:"channel-grid",children:t.value?.channels.map(k=>e("div",{class:"channel-card",children:e("div",{class:"channel-card-header",children:[e("span",{class:"channel-card-name",children:k.name}),e("div",{class:"channel-card-actions",children:[e(U,{variant:k.enabled?"success":"neutral",children:k.enabled?"Connected":"Not Configured"}),k.enabled&&e(A,{variant:"secondary",size:"sm",onClick:()=>p(k.name),loading:i.value===k.name,children:"Test"})]})]})},k.name))}),e("div",{style:{marginTop:"var(--space-4)",marginBottom:"var(--space-6)"},children:[e(A,{onClick:m,loading:l.value,disabled:!x,children:"Test All Channels"}),s.value&&e("div",{class:"test-results",children:s.value.map(k=>e("div",{class:"test-result-item",children:[e("span",{class:k.success?"test-result-success":"test-result-failure",children:k.success?"✓":"✗"}),e("span",{style:{textTransform:"capitalize"},children:k.channel}),!k.success&&k.error&&e("span",{class:"test-result-failure",children:[" - ",k.error]})]},k.channel))})]}),e("h2",{children:"Delivery Log"}),e(Te,{columns:V,data:o.value?.logs??[],loading:c.value,emptyMessage:"No notification logs",onRowClick:b}),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(A,{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 ",F,o.value?` (${o.value.total} total)`:""]}),e("div",{class:"pagination-buttons",children:[e(A,{variant:"secondary",size:"sm",onClick:E,disabled:h.value<=1,children:"Previous"}),e(A,{variant:"secondary",size:"sm",onClick:N,disabled:h.value>=F,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 fa=[{key:"killswitch",label:"Kill Switch"},{key:"autostop",label:"AutoStop Rules"},{key:"jwt",label:"Invalidate Sessions"}];function zl(){const a=v(null),t=v(!0),n=v(!1),l=async()=>{try{const d=await q(C.ADMIN_KILL_SWITCH);a.value=d}catch(d){const m=d instanceof f?d:new f(0,"UNKNOWN","Unknown error");g("error",D(m.code))}finally{t.value=!1}};R(()=>{l()},[]);const i=async()=>{n.value=!0;try{await te(C.ADMIN_KILL_SWITCH),g("success","Kill switch activated - all operations suspended"),await l()}catch(d){const m=d instanceof f?d:new f(0,"UNKNOWN","Unknown error");g("error",D(m.code))}finally{n.value=!1}},s=async()=>{n.value=!0;try{await te(C.ADMIN_KILL_SWITCH_ESCALATE),g("success","Kill switch escalated to LOCKED"),await l()}catch(d){const m=d instanceof f?d:new f(0,"UNKNOWN","Unknown error");g("error",D(m.code))}finally{n.value=!1}},o=async()=>{n.value=!0;try{await te(C.ADMIN_RECOVER),g("success","Kill switch recovered - operations resumed"),await l()}catch(d){const m=d instanceof f?d:new f(0,"UNKNOWN","Unknown error");g("error",D(m.code))}finally{n.value=!1}},c=a.value,h=c?.state==="ACTIVE",r=c?.state==="SUSPENDED",u=c?.state==="LOCKED";return e("div",{class:"settings-category",children:[e("div",{class:"settings-category-header",children:[e("h3",{children:"Kill Switch"}),e("p",{class:"settings-description",children:"Emergency stop - suspends all wallet operations immediately. 3-state: ACTIVE (normal) → SUSPENDED (paused) → LOCKED (permanent)."})]}),e("div",{class:"settings-category-body",children:t.value?e("span",{children:"Loading..."}):c?e(G,{children:[e("div",{class:"ks-state-card",style:{marginBottom:"var(--space-4)"},children:[e(U,{variant:h?"success":u?"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(A,{variant:"danger",onClick:i,loading:n.value,children:"Activate Kill Switch"}),r&&e(G,{children:[e(A,{variant:"primary",onClick:o,loading:n.value,children:"Recover"}),e(A,{variant:"danger",onClick:s,loading:n.value,children:"Escalate to LOCKED"})]}),u&&e(A,{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."}),u&&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 Gl(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=async()=>{try{const r=await q(C.ADMIN_SETTINGS);a.value=r}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{l.value=!1}};R(()=>{i()},[]);const s=(r,u)=>{const d=String(u);t.value={...t.value,[r]:d}},o=async()=>{n.value=!0;try{const r=Object.entries(t.value).filter(([d])=>d.startsWith("autostop.")).map(([d,m])=>({key:d,value:m})),u=await le(C.ADMIN_SETTINGS,{settings:r});a.value=u.settings,t.value={},g("success","AutoStop settings saved and applied")}catch(r){const u=r instanceof f?r:new f(0,"UNKNOWN","Unknown error");g("error",D(u.code))}finally{n.value=!1}},c=()=>{t.value={}};R(()=>(ge({id:"security-autostop",isDirty:()=>Object.keys(t.value).filter(r=>r.startsWith("autostop.")).length>0,save:o,discard:c}),()=>be("security-autostop")),[]);const h=Object.keys(t.value).filter(r=>r.startsWith("autostop.")).length;return l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{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(A,{variant:"ghost",size:"sm",onClick:c,children:"Discard"}),e(A,{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(S,{label:O("enabled"),name:"autostop.enabled",type:"checkbox",value:fe(a.value,t.value,"autostop","enabled"),onChange:r=>s("autostop.enabled",r),description:"Enable or disable AutoStop protection rules"})}),e(Se,{legend:"Activity Detection",description:"Detects failures and unusual transaction patterns",children:e("div",{class:"settings-fields-grid",children:[e(S,{label:O("consecutive_failures_threshold"),name:"autostop.consecutive_failures_threshold",type:"number",value:Number(K(a.value,t.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(S,{label:O("unusual_activity_threshold"),name:"autostop.unusual_activity_threshold",type:"number",value:Number(K(a.value,t.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(S,{label:O("unusual_activity_window_sec"),name:"autostop.unusual_activity_window_sec",type:"number",value:Number(K(a.value,t.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(Se,{legend:"Idle Detection",description:"Monitors inactivity and revokes idle sessions",children:e("div",{class:"settings-fields-grid",children:[e(S,{label:O("idle_timeout_sec"),name:"autostop.idle_timeout_sec",type:"number",value:Number(K(a.value,t.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(S,{label:O("idle_check_interval_sec"),name:"autostop.idle_check_interval_sec",type:"number",value:Number(K(a.value,t.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 jl(){const a=v(!1),t=v(!1),n=async()=>{t.value=!0;try{await te(C.ADMIN_ROTATE_SECRET),a.value=!1,g("success","All session tokens invalidated. Old tokens remain valid for 5 minutes.")}catch(l){const i=l instanceof f?l:new f(0,"UNKNOWN","Unknown error");g("error",D(i.code))}finally{t.value=!1}};return e(G,{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(A,{variant:"secondary",onClick:()=>{a.value=!0},children:"Invalidate All Tokens"})})]}),e(re,{open:a.value,title:"Invalidate All Session Tokens",onCancel:()=>{a.value=!1},onConfirm:n,confirmText:"Invalidate",confirmVariant:"primary",loading:t.value,children:e("p",{children:"This will rotate the signing key and invalidate all active session tokens after 5 minutes. Every wallet will need to create a new session to continue API access. Use this when a token may have been compromised."})})]})}function Yl(){const a=v("killswitch");R(()=>{const n=Z.value;n&&n.tab&&(a.value=n.tab,setTimeout(()=>{ce.value=n.fieldName},100),Z.value=null)},[Z.value]);const t=fa.find(n=>n.key===a.value)?.label??"";return e("div",{class:"page",children:[e(Ye,{pageName:"Security",tabName:t,onPageClick:()=>{a.value="killswitch"}}),e(je,{tabs:fa,activeTab:a.value,onTabChange:n=>{a.value=n}}),a.value==="killswitch"&&e(zl,{}),a.value==="autostop"&&e(Gl,{}),a.value==="jwt"&&e(jl,{})]})}const at=[{code:"USD",name:"US Dollar",symbol:"$"},{code:"KRW",name:"Korean Won",symbol:"₩"},{code:"JPY",name:"Japanese Yen",symbol:"¥"},{code:"EUR",name:"Euro",symbol:"€"},{code:"GBP",name:"British Pound",symbol:"£"},{code:"CNY",name:"Chinese Yuan",symbol:"¥"},{code:"CAD",name:"Canadian Dollar",symbol:"CA$"},{code:"AUD",name:"Australian Dollar",symbol:"A$"},{code:"CHF",name:"Swiss Franc",symbol:"CHF"},{code:"SGD",name:"Singapore Dollar",symbol:"S$"},{code:"HKD",name:"Hong Kong Dollar",symbol:"HK$"},{code:"INR",name:"Indian Rupee",symbol:"₹"},{code:"TWD",name:"Taiwan Dollar",symbol:"NT$"},{code:"THB",name:"Thai Baht",symbol:"฿"},{code:"MYR",name:"Malaysian Ringgit",symbol:"RM"},{code:"IDR",name:"Indonesian Rupiah",symbol:"Rp"},{code:"PHP",name:"Philippine Peso",symbol:"₱"},{code:"VND",name:"Vietnamese Dong",symbol:"₫"},{code:"BRL",name:"Brazilian Real",symbol:"R$"},{code:"MXN",name:"Mexican Peso",symbol:"MX$"},{code:"CLP",name:"Chilean Peso",symbol:"CL$"},{code:"TRY",name:"Turkish Lira",symbol:"₺"},{code:"PLN",name:"Polish Zloty",symbol:"zł"},{code:"CZK",name:"Czech Koruna",symbol:"Kč"},{code:"HUF",name:"Hungarian Forint",symbol:"Ft"},{code:"SEK",name:"Swedish Krona",symbol:"kr"},{code:"NOK",name:"Norwegian Krone",symbol:"kr"},{code:"DKK",name:"Danish Krone",symbol:"kr"},{code:"NZD",name:"New Zealand Dollar",symbol:"NZ$"},{code:"ZAR",name:"South African Rand",symbol:"R"},{code:"ILS",name:"Israeli Shekel",symbol:"₪"},{code:"SAR",name:"Saudi Riyal",symbol:"SR"},{code:"AED",name:"UAE Dirham",symbol:"AED"},{code:"KWD",name:"Kuwaiti Dinar",symbol:"KD"},{code:"BHD",name:"Bahraini Dinar",symbol:"BD"},{code:"NGN",name:"Nigerian Naira",symbol:"₦"},{code:"RUB",name:"Russian Ruble",symbol:"₽"},{code:"UAH",name:"Ukrainian Hryvnia",symbol:"₴"},{code:"PKR",name:"Pakistani Rupee",symbol:"Rs"},{code:"BDT",name:"Bangladeshi Taka",symbol:"৳"},{code:"LKR",name:"Sri Lankan Rupee",symbol:"Rs"},{code:"MMK",name:"Myanmar Kyat",symbol:"K"},{code:"GEL",name:"Georgian Lari",symbol:"₾"}];function Jl({value:a,onChange:t,name:n}){const l=v(""),i=v(!1),s=v(null),o=v(!1),c=Bt(null),h=yn(()=>{const u=l.value.toLowerCase();return u?at.filter(d=>d.code.toLowerCase().includes(u)||d.name.toLowerCase().includes(u)||d.symbol.includes(u)):at});R(()=>{if(a==="USD"){s.value="1 USD = $1.00";return}o.value=!0,q(`${C.ADMIN_FOREX_RATES}?currencies=${a}`).then(u=>{const d=u.rates[a];s.value=d?.preview??null}).catch(()=>{s.value=null}).finally(()=>{o.value=!1})},[a]),R(()=>{const u=d=>{c.current&&!c.current.contains(d.target)&&(i.value=!1,l.value="")};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]);const r=at.find(u=>u.code===a)??at[0];return e("div",{class:"currency-select",ref:c,children:[n&&e("input",{type:"hidden",name:n,value:a}),e("button",{type:"button",class:"currency-select-trigger",onClick:()=>{i.value=!i.value},children:[e("span",{class:"currency-select-value",children:[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:u=>{l.value=u.target.value},autoFocus:!0}),e("div",{class:"currency-select-list",children:[h.value.map(u=>e("button",{type:"button",class:`currency-select-option ${u.code===a?"currency-select-option--active":""}`,onClick:()=>{t(u.code),i.value=!1,l.value=""},children:[e("span",{class:"currency-option-code",children:u.code}),e("span",{class:"currency-option-name",children:u.name}),e("span",{class:"currency-option-symbol",children:u.symbol})]},u.code)),h.value.length===0&&e("div",{class:"currency-select-empty",children:"No currencies found"})]})]})]})}const Xl=["display.","daemon.","oracle.","signing_sdk."],Zl=new Set(["security.rate_limit_global_ip_rpm"]);function It(a){return Xl.some(t=>a.startsWith(t))||Zl.has(a)}function Ql(){const a=v({}),t=v({}),n=v(!1),l=v(!0),i=v([]),s=v(!0),o=v(null),c=v(""),h=v(!1),r=v(!1),u=v(!1),d=v(""),m=v(!1),p=async()=>{try{const T=await q(C.ADMIN_SETTINGS);a.value=T}catch(T){const M=T instanceof f?T:new f(0,"UNKNOWN","Unknown error");g("error",D(M.code))}finally{l.value=!1}},E=async()=>{try{const T=await q(C.ADMIN_API_KEYS);i.value=T.keys}catch{}finally{s.value=!1}};R(()=>{p(),E()},[]),R(()=>{const T=Z.value;T&&(setTimeout(()=>{ce.value=T.fieldName},100),Z.value=null)},[Z.value]);const N=(T,M)=>K(a.value,t.value,T,M),b=(T,M)=>fe(a.value,t.value,T,M),I=(T,M)=>{const j=String(M);t.value={...t.value,[T]:j}},x=async()=>{n.value=!0;try{const T=Object.entries(t.value).filter(([j])=>It(j)).map(([j,Pe])=>({key:j,value:Pe})),M=await le(C.ADMIN_SETTINGS,{settings:T});a.value=M.settings,t.value={},g("success","Settings saved and applied")}catch(T){const M=T instanceof f?T:new f(0,"UNKNOWN","Unknown error");g("error",D(M.code))}finally{n.value=!1}},F=()=>{t.value={}};R(()=>(ge({id:"system-settings",isDirty:()=>Object.keys(t.value).filter(T=>It(T)).length>0,save:x,discard:F}),()=>be("system-settings")),[]);const V=async T=>{h.value=!0;try{await le(C.ADMIN_API_KEY(T),{apiKey:c.value}),g("success",`API key saved for ${T}`),o.value=null,c.value="",await E()}catch(M){const j=M instanceof f?M:new f(0,"UNKNOWN","Unknown error");g("error",D(j.code))}finally{h.value=!1}},k=async T=>{try{await xe(C.ADMIN_API_KEY(T)),g("success",`API key deleted for ${T}`),await E()}catch(M){const j=M instanceof f?M:new f(0,"UNKNOWN","Unknown error");g("error",D(j.code))}},W=async()=>{u.value=!0;try{await te(C.ADMIN_SHUTDOWN),r.value=!1,d.value="",g("info","Shutdown initiated"),m.value=!0}catch(T){const M=T instanceof f?T:new f(0,"UNKNOWN","Unknown error");g("error",D(M.code))}finally{u.value=!1}},P=Object.keys(t.value).filter(T=>It(T)).length;function _(){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(T=>e("div",{class:"settings-field-row",children:[e("div",{class:"settings-field-label",children:[e("span",{children:T.providerName}),T.requiresApiKey&&!T.hasKey&&e(U,{variant:"warning",children:"Required"})]}),e("div",{class:"settings-field-value",children:o.value===T.providerName?e("div",{class:"api-key-edit-row",children:[e(S,{label:"API Key",type:"password",name:`apikey-${T.providerName}`,value:c.value,onChange:M=>{c.value=String(M)},placeholder:"Enter API key"}),e(A,{onClick:()=>V(T.providerName),loading:h.value,size:"sm",children:"Save"}),e(A,{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:T.hasKey?T.maskedKey:"Not set"}),e(A,{variant:"ghost",onClick:()=>{o.value=T.providerName,c.value=""},size:"sm",children:T.hasKey?"Change":"Set"}),T.hasKey&&e(A,{variant:"danger",onClick:()=>k(T.providerName),size:"sm",children:"Delete"})]})})]},T.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(S,{label:"Cross Validation Threshold (%)",name:"oracle.cross_validation_threshold",type:"number",value:Number(N("oracle","cross_validation_threshold"))||5,onChange:T=>I("oracle.cross_validation_threshold",T),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 Y(){const T=ce.value==="display.currency";return R(()=>{if(T){const M=document.querySelector('[name="display.currency"]');M&&M.closest(".form-field")?.scrollIntoView({behavior:"smooth",block:"center"});const j=setTimeout(()=>{ce.value=""},2500);return()=>clearTimeout(j)}},[T]),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${T?" form-field--highlight":""}`,children:[e("label",{children:O("currency")}),e(Jl,{name:"display.currency",value:N("display","currency")||"USD",onChange:M=>I("display.currency",M)})]})}),e("div",{class:"settings-info-box",children:"All USD amounts in the dashboard, notifications, and API responses will be converted to the selected currency. Policy evaluation always uses USD. The “≈” prefix indicates an approximate conversion."})]})]})}function Q(){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(S,{label:O("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:T=>I("security.rate_limit_global_ip_rpm",T),min:10,description:"Maximum API requests per minute from a single IP address"})})})]})}function ee(){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(S,{label:O("log_level"),name:"daemon.log_level",type:"select",value:N("daemon","log_level")||"info",onChange:T=>I("daemon.log_level",T),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(S,{label:"SDK Enabled",name:"signing_sdk.enabled",type:"select",value:N("signing_sdk","enabled")||"false",onChange:T=>I("signing_sdk.enabled",T),options:[{label:"Yes",value:"true"},{label:"No",value:"false"}],description:"Enable Signing SDK for wallet app approval"}),e(S,{label:O("request_expiry_min"),name:"signing_sdk.request_expiry_min",type:"number",value:Number(N("signing_sdk","request_expiry_min"))||30,onChange:T=>I("signing_sdk.request_expiry_min",T),min:1,max:1440,description:"Minutes before a sign request expires"}),e(S,{label:O("preferred_channel"),name:"signing_sdk.preferred_channel",type:"select",value:N("signing_sdk","preferred_channel")||"ntfy",onChange:T=>I("signing_sdk.preferred_channel",T),options:[{label:"ntfy",value:"ntfy"},{label:"Telegram",value:"telegram"}],description:"Preferred signing channel for SDK requests"}),e(S,{label:O("preferred_wallet"),name:"signing_sdk.preferred_wallet",type:"text",value:N("signing_sdk","preferred_wallet"),onChange:T=>I("signing_sdk.preferred_wallet",T),placeholder:"Optional wallet app name",description:"Preferred wallet app for deep linking"}),e(S,{label:O("ntfy_request_topic_prefix"),name:"signing_sdk.ntfy_request_topic_prefix",type:"text",value:N("signing_sdk","ntfy_request_topic_prefix"),onChange:T=>I("signing_sdk.ntfy_request_topic_prefix",T),description:"ntfy topic prefix for sign requests"}),e(S,{label:O("ntfy_response_topic_prefix"),name:"signing_sdk.ntfy_response_topic_prefix",type:"text",value:N("signing_sdk","ntfy_response_topic_prefix"),onChange:T=>I("signing_sdk.ntfy_response_topic_prefix",T),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(S,{label:"Notifications Enabled",name:"signing_sdk.notifications_enabled",type:"checkbox",value:b("signing_sdk","notifications_enabled"),onChange:T=>I("signing_sdk.notifications_enabled",T),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:[m.value&&e("div",{class:"shutdown-overlay",children:[e("h2",{children:"Daemon is shutting down..."}),e("p",{children:"You can close this tab."})]}),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(A,{variant:"ghost",size:"sm",onClick:F,children:"Discard"}),e(A,{variant:"primary",size:"sm",onClick:x,loading:n.value,children:"Save"})]})]}),l.value?e("div",{class:"empty-state",children:e("p",{children:"Loading settings..."})}):e(G,{children:[e(_,{}),e(L,{}),e(Y,{}),e(Q,{}),e(ee,{}),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(A,{variant:"danger",onClick:()=>{r.value=!0},children:"Shutdown Daemon"})})]}),e(re,{open:r.value,title:"Shutdown Daemon",onCancel:()=>{r.value=!1,d.value=""},onConfirm:W,confirmText:"Shutdown",confirmVariant:"danger",confirmDisabled:d.value!=="SHUTDOWN",loading:u.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:T=>{d.value=T.target.value},placeholder:"SHUTDOWN"})]})]})]})}const pe=ne(window.location.hash.slice(1)||"/dashboard"),nt=ne(!1);window.addEventListener("hashchange",()=>{pe.value=window.location.hash.slice(1)||"/dashboard"});const ei={"/dashboard":"Dashboard","/wallets":"Wallets","/sessions":"Sessions","/policies":"Policies","/notifications":"Notifications","/security":"Security","/system":"System"},ti={"/dashboard":"System overview and key metrics","/wallets":"Manage wallets, balances, and connections","/sessions":"View and manage active sessions","/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 ai(a){return a.startsWith("/wallets/")?"Wallet Detail":ei[a]??"Dashboard"}function _a(a){return ti[a]}const ni=[{path:"/dashboard",label:"Dashboard"},{path:"/wallets",label:"Wallets"},{path:"/sessions",label:"Sessions"},{path:"/policies",label:"Policies"},{path:"/notifications",label:"Notifications"},{path:"/security",label:"Security"},{path:"/system",label:"System"}];function li(){const a=pe.value;return a==="/sessions"?e(pl,{}):a==="/policies"?e(Bl,{}):a==="/notifications"?e(ma,{}):a==="/telegram-users"?(window.location.hash="#/notifications",e(ma,{})):a==="/settings"?(window.location.hash="#/dashboard",e(ia,{})):a==="/walletconnect"?(window.location.hash="#/wallets",e(oa,{})):a==="/security"?e(Yl,{}):a==="/system"?e(Ql,{}):a.startsWith("/wallets")?e(oa,{}):e(ia,{})}function ii(){return R(()=>{const a=t=>{(t.metaKey||t.ctrlKey)&&t.key==="k"&&(t.preventDefault(),nt.value=!nt.value)};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[]),e("div",{class:"layout",children:[e("aside",{class:"sidebar",children:[e("div",{class:"sidebar-brand",children:"WAIaaS"}),e("nav",{class:"sidebar-nav",children:ni.map(a=>{const t=a.path==="/wallets"?pe.value.startsWith("/wallets"):pe.value===a.path;return e("a",{href:`#${a.path}`,class:`sidebar-link ${t?"active":""}`,onClick:n=>{Va.value&&(n.preventDefault(),qa({type:"nav",execute:()=>{window.location.hash=`#${a.path}`}}))},children:a.label})})})]}),e("main",{class:"main",children:[e("header",{class:"header",children:[e("div",{class:"header-left",children:[e("h1",{class:"header-title",children:ai(pe.value)}),_a(pe.value)&&e("p",{class:"header-subtitle",children:_a(pe.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:()=>qt(),children:"Logout"})]})]}),e("div",{class:"content",children:e(li,{})})]}),e(xn,{open:nt}),e(Pn,{})]})}const lt={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 si(){return e("div",{style:lt.overlay,children:e("div",{style:lt.content,children:[e("h1",{style:lt.title,children:"Daemon Shutting Down"}),e("p",{style:lt.message,children:"The daemon is shutting down. Please wait or restart."})]})})}function ri(){return Sn.value?e(si,{}):wn.value?e(G,{children:[e(ii,{}),e(jn,{})]}):e(Cn,{})}cn(e(ri,{}),document.getElementById("app"));
@@ -4,7 +4,7 @@
4
4
  <meta charset="UTF-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>WAIaaS Admin</title>
7
- <script type="module" crossorigin src="/admin/assets/index-BLLOYSZp.js"></script>
7
+ <script type="module" crossorigin src="/admin/assets/index-D06O_cSo.js"></script>
8
8
  <link rel="stylesheet" crossorigin href="/admin/assets/index-CCmvYamK.css">
9
9
  </head>
10
10
  <body>