@stacknet/userutils 0.2.51 → 0.2.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -0
- package/dist/components/index.cjs +2 -2
- package/dist/components/index.d.cts +17 -2
- package/dist/components/index.d.ts +17 -2
- package/dist/components/index.js +2 -2
- package/dist/hooks/index.cjs +2 -2
- package/dist/hooks/index.d.cts +24 -2
- package/dist/hooks/index.d.ts +24 -2
- package/dist/hooks/index.js +2 -2
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/server/index.d.cts +1 -1
- package/dist/server/index.d.ts +1 -1
- package/dist/types/index.d.cts +23 -1
- package/dist/types/index.d.ts +23 -1
- package/package.json +1 -1
- /package/dist/{index-BrziGArs.d.cts → config-BrziGArs.d.cts} +0 -0
- /package/dist/{index-BrziGArs.d.ts → config-BrziGArs.d.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function Qe(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function Ve(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function Ye(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let s=new URL(e,t);return s.origin!==t?"/":s.pathname+s.search+s.hash}catch{return "/"}}function Ge(e){try{let t=e.split(".");if(t.length!==3)return null;let s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}function oe(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function j(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function re(){let[e,t]=react.useState(null),[s,l]=react.useState(true),f=react.useCallback(()=>{let o=oe();o&&o.expiresAt>Date.now()?t({userId:o.userId,address:o.address,chain:o.chain,expiresAt:o.expiresAt,planId:o.planId,authMethod:o.authMethod}):t(null),l(false);},[]);react.useEffect(()=>{f();},[f]);let h=react.useCallback(async(o="")=>{try{let r=await fetch(`${o}/api/auth/session`);if(r.ok){let i=await r.json();if(i.session)return t(i.session),i.session}return t(null),null}catch{return null}},[]),m=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:m,refresh:h,readSession:f}}function ae(e="__csrf",t="x-csrf-token"){let[s,l]=react.useState(null);react.useEffect(()=>{l(j(e));},[e]);let f=s?{[t]:s}:{};return {token:s,headers:f}}function ie(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[s,l]=react.useState(null),f=react.useCallback(async(r="phantom")=>{l(null);try{let i=typeof window<"u"?window:null,p=r==="phantom"?i?.phantom?.solana||i?.solana:i?.solflare;if(!p)return l(`${r} wallet not found`),null;let d=(await p.connect()).publicKey.toString();return t({connected:!0,address:d,chain:"solana",provider:r}),d}catch(i){return l(i.message||"Failed to connect wallet"),null}},[]),h=react.useCallback(async()=>{l(null);try{let i=(typeof window<"u"?window:null)?.ethereum;if(!i)return l("MetaMask not found"),null;let p=i;i.providers?.length&&(p=i.providers.find(n=>n.isMetaMask)||i);let d=(await p.request({method:"eth_requestAccounts"}))[0];return d?(t({connected:!0,address:d,chain:"ethereum",provider:"metamask"}),d):(l("No account selected"),null)}catch(r){return l(r.message||"Failed to connect wallet"),null}},[]),m=react.useCallback(async(r,i)=>{l(null);let p=i?.chain||e.chain,a=i?.provider||e.provider,d=i?.address||e.address;try{if(p==="solana"){let n=typeof window<"u"?window:null,c=a==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!c)throw new Error("Wallet not available");let g=new TextEncoder().encode(r),b=await c.signMessage(g,"utf8"),v=new Uint8Array(b.signature||b),x="";for(let L=0;L<v.byteLength;L++)x+=String.fromCharCode(v[L]);return btoa(x)}if(p==="ethereum"){let c=(typeof window<"u"?window:null)?.ethereum;if(c?.providers?.length&&(c=c.providers.find(b=>b.isMetaMask)||c),!c)throw new Error("MetaMask not available");return await c.request({method:"personal_sign",params:[r,d]})}throw new Error("No wallet connected")}catch(n){return l(n.message||"Signing failed"),null}},[e]),o=react.useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:s,connectSolana:f,connectEVM:h,signMessage:m,disconnect:o}}var et="https://stacknet.magma-rpc.com/auth/bridge",q="stacknet-auth-bridge";function ce(e){let t=e?.bridgeUrl||et,s=e?.disabled||false,l=react.useRef(null),[f,h]=react.useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),m=react.useRef([]),o=react.useRef(false),r=react.useCallback(n=>{let c={...n,protocol:q};o.current&&l.current?.contentWindow?l.current.contentWindow.postMessage(c,new URL(t).origin):m.current.push(c);},[t]);react.useEffect(()=>{if(s)return;let n=g=>{if(!(!g.data||g.data.protocol!==q)){try{if(g.origin!==new URL(t).origin)return}catch{return}switch(g.data.type){case "bridge:ready":o.current=true,h(b=>({...b,ready:true}));for(let b of m.current)l.current?.contentWindow?.postMessage(b,g.origin);m.current=[],l.current?.contentWindow?.postMessage({protocol:q,type:"auth:check"},g.origin),l.current?.contentWindow?.postMessage({protocol:q,type:"auth:resolve-stack"},g.origin);break;case "auth:status":h(b=>({...b,known:g.data.known,identity:g.data.identity,identityCount:g.data.identityCount||0}));break;case "auth:resolved-stack":h(b=>({...b,resolvedStackId:g.data.stackId||null}));break;}}};window.addEventListener("message",n);let c=document.createElement("iframe");return c.src=t,c.style.display="none",c.setAttribute("aria-hidden","true"),c.setAttribute("tabindex","-1"),c.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(c),l.current=c,()=>{window.removeEventListener("message",n),c.parentNode&&c.parentNode.removeChild(c),l.current=null,o.current=false;}},[t,s]);let i=react.useCallback(n=>{r({type:"auth:connected",...n});},[r]),p=react.useCallback(n=>{r({type:"auth:disconnected",...n});},[r]),a=react.useCallback(()=>{r({type:"auth:clear"}),h({ready:f.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[r,f.ready]),d=react.useCallback(()=>{r({type:"auth:check"});},[r]);return {...f,reportConnected:i,reportDisconnected:p,clearAll:a,refresh:d}}async function Ue(e,t,s,l){let f=e.apiVersion||"v2",h=`${e.baseUrl}/api/${f}${s}`;try{let m=await fetch(h,{method:t,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),o=await m.json();return m.ok?o.success&&o.data!==void 0?{success:!0,data:o.data}:{success:!0,data:o}:{success:!1,error:o.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(m){return {success:false,error:{code:"NETWORK_ERROR",message:m instanceof Error?m.message:"Network error"}}}}function de(e){return {getNetworkStatus:()=>Ue(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>Ue(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:t,address:s})}}function pe(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:l,signMessage:f,disconnect:h}=ie(),{session:m,isAuthenticated:o,refresh:r,readSession:i}=re(),{headers:p}=ae(),a=ce({disabled:typeof window>"u"}),[d,n]=react.useState(false),[c,g]=react.useState(null),[b,v]=react.useState(false),x=e.apiBaseUrl||"",L=e.stacknetUrl||"https://stacknet.magma-rpc.com",P=e.stackId||a.resolvedStackId||"",N=de({baseUrl:L,stackId:P}),S=react.useCallback(async(w,C,_,D)=>{n(true),g(null);try{let I=C;if(!I){let R=await _();if(!R)return n(!1),!1;I=R;}let O=await N.getWeb3Challenge(w,I);if(!O.success||!O.data)return g("Failed to get challenge"),n(!1),!1;let J=await f(O.data.message,{chain:w,provider:D,address:I});if(!J)return n(!1),!1;let $={chain:w,message:O.data.message,signature:J,stackId:P};w==="solana"&&($.publicKey=I);let E=await fetch(`${x}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)});if(!E.ok){let R=await E.json().catch(()=>({}));return g(R.error||"Authentication failed"),n(!1),!1}return a.reportConnected({address:I,chain:w,method:D||(w==="solana"?"phantom":"metamask"),stackId:P}),i(),n(!1),!0}catch(I){return g(I.message||"Authentication failed"),n(false),false}},[x,N,f,i,a,P]),T=react.useCallback(async(w="phantom")=>{let C=await s(w);return C?S("solana",C,()=>s(w),w):false},[s,S]),A=react.useCallback(async()=>{let w=await l();return w?S("ethereum",w,l,"metamask"):false},[l,S]),G=react.useCallback(async w=>{n(true),g(null);try{let C=await fetch(`${x}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:w})});if(!C.ok){let _=await C.json().catch(()=>({}));return g(_.error||"Invalid code"),n(!1),!1}return i(),n(!1),!0}catch(C){return g(C.message||"OTP verification failed"),n(false),false}},[x,i]),Z=react.useCallback(async()=>{t.address&&t.chain&&a.reportDisconnected({address:t.address,chain:t.chain,stackId:P});try{await fetch(`${x}/api/auth/logout`,{method:"POST",headers:p});}catch{}h(),i();},[x,p,h,i,t,a,P]);return react.useEffect(()=>{if(!e.autoConnect||b||o||!a.ready||!a.known||!a.identity)return;v(true);let{chain:w,method:C}=a.identity;w==="solana"&&(C==="phantom"||C==="solflare")?T(C):w==="ethereum"&&A();},[e.autoConnect,b,o,a,T,A]),{session:m,isAuthenticated:o,wallet:t,loading:d,error:c,authenticateSolana:T,authenticateEVM:A,authenticateOTP:G,logout:Z,refresh:()=>r(x),stackId:P,bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount,resolvedStackId:a.resolvedStackId}}}function me(e,t="https://stacknet.magma-rpc.com"){let[s,l]=react.useState(null),[f,h]=react.useState(false),[m,o]=react.useState(null),r=react.useCallback(async p=>{h(true),o(null);try{let a=await fetch(`${t}/api/v2/stacks/${p}`);if(!a.ok)return o("Stack not found"),h(!1),null;let d=await a.json(),n=d.data?.stack||d.stack||d,c={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(g=>({provider:g.provider,enabled:g.enabled!==!1}))};return l(c),h(!1),c}catch(a){return o(a.message),h(false),null}},[t]);react.useEffect(()=>{e&&r(e);},[e,r]);let i=s?ot(s):[];return {config:s,loading:f,error:m,identityProviders:i,fetchConfig:r}}function ot(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let s of e.oauthProviders)s.enabled&&t.push({type:"oauth",id:s.provider,name:s.provider});return t}function it(e=""){let[t,s]=react.useState([]),[l,f]=react.useState(true),[h,m]=react.useState(null),o=react.useCallback(async()=>{try{let r=await fetch(`${e}/api/billing/plans`);if(r.ok){let i=await r.json();s(i.plans||i||[]);}}catch(r){m(r.message);}finally{f(false);}},[e]);return react.useEffect(()=>{o();},[o]),{plans:t,loading:l,error:h,refresh:o}}function ct(e=""){let[t,s]=react.useState(null),[l,f]=react.useState(true),[h,m]=react.useState(null),o=react.useCallback(async()=>{try{let p=await fetch(`${e}/api/billing/subscription`);if(p.ok){let a=await p.json();s(a.plan?a:null);}}catch(p){m(p.message);}finally{f(false);}},[e]);react.useEffect(()=>{o();},[o]);let r=react.useCallback(async p=>{let a=j(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({planId:p})})).json();return n.url||n.checkoutUrl||null},[e]),i=react.useCallback(async()=>{let p=j();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:p?{"x-csrf-token":p}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:t,loading:l,error:h,refresh:o,subscribe:r,cancel:i}}function pt(e=""){let[t,s]=react.useState(null),[l,f]=react.useState(true),[h,m]=react.useState(null),o=react.useCallback(async()=>{try{let r=await fetch(`${e}/api/billing/usage`);if(r.ok){let i=await r.json();s(i);}}catch(r){m(r.message);}finally{f(false);}},[e]);return react.useEffect(()=>{o();},[o]),{usage:t,loading:l,error:h,refresh:o}}function ft(e=""){let[t,s]=react.useState(false),[l,f]=react.useState(null),h=react.useCallback(async o=>{s(true),f(null);try{let r=j(),i=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...r?{"x-csrf-token":r}:{}},body:JSON.stringify({amountCents:o})}),p=await i.json();return i.ok?p.url||null:(f(p.error||"Purchase failed"),null)}catch(r){return f(r.message),null}finally{s(false);}},[e]),m=react.useCallback(async o=>{s(true),f(null);try{let r=j(),i=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...r?{"x-csrf-token":r}:{}},body:JSON.stringify({sessionId:o})}),p=await i.json();return i.ok?p:(f(p.error||"Verification failed"),null)}catch(r){return f(r.message),null}finally{s(false);}},[e]);return {purchase:h,verifySession:m,loading:t,error:l}}function ht(e="",t){let[s,l]=react.useState([]),[f,h]=react.useState(true),[m,o]=react.useState(null),r=t?.limit||50,i=t?.offset||0,p=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/history?limit=${r}&offset=${i}`);if(a.ok){let d=await a.json();l(d.records||d.history||(Array.isArray(d)?d:[]));}}catch(a){o(a.message);}finally{h(false);}},[e,r,i]);return react.useEffect(()=>{p();},[p]),{records:s,loading:f,error:m,refresh:p}}var Te=react.createContext(null);function wt(){let e=react.useContext(Te);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function bt({config:e,callbacks:t,children:s}){return jsxRuntime.jsx(Te.Provider,{value:{config:e,callbacks:t},children:s})}function X({length:e=6,onComplete:t,disabled:s=false,error:l,className:f="",inputClassName:h=""}){let [m,o]=react.useState(Array(e).fill("")),r=react.useCallback((a,d)=>{if(d.length>1){let c=d.replace(/\D/g,"").slice(0,e).split(""),g=[...m];c.forEach((v,x)=>{a+x<e&&(g[a+x]=v);}),o(g);let b=Math.min(a+c.length,e-1);document.getElementById(`userutils-otp-${b}`)?.focus(),g.every(v=>v!=="")&&setTimeout(()=>t(g.join("")),100);return}if(!/^\d?$/.test(d))return;let n=[...m];n[a]=d,o(n),d&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),d&&a===e-1&&n.every(c=>c!=="")&&setTimeout(()=>t(n.join("")),100);},[m,e,t]),i=react.useCallback((a,d)=>{if(d.key==="Backspace"&&!m[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let n=[...m];n[a-1]="",o(n);}if(d.key==="Enter"){let n=m.join("");n.length===e&&t(n);}},[m,e,t]);react.useCallback(()=>{o(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:f,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:m.map((a,d)=>jsxRuntime.jsx("input",{id:`userutils-otp-${d}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:n=>r(d,n.target.value),onKeyDown:n=>i(d,n),disabled:s,autoFocus:d===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${h}`},d))}),l&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}X.displayName="OTPInput";var Mt="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function ee({className:e}){return jsxRuntime.jsx("img",{src:Mt,alt:"Phantom",className:e})}function te({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function Ce({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxRuntime.jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsxRuntime.jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsxRuntime.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsxRuntime.jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsxRuntime.jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Me({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Lt({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:l,showOTP:f,className:h=""}){let m=pe(e),{isAuthenticated:o,wallet:r,loading:i,error:p,authenticateSolana:a,authenticateEVM:d,authenticateOTP:n,bridge:c,stackId:g}=m,b=!e.stackId&&!g,v=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:x,identityProviders:L,loading:P}=me(g||e.stackId||null,v),[N,S]=react.useState(b?"stack-select":"select"),[T,A]=react.useState(null),[G,Z]=react.useState(false),[w,C]=react.useState("idle"),[_,D]=react.useState(""),[I,O]=react.useState([]),[J,$]=react.useState(e.stackId||null),[E,R]=react.useState(false),[Re,We]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let k=()=>{let W=window;R(!!(W.phantom?.solana?.isPhantom||W.solana?.isPhantom));let B=W.ethereum;We(!!(B?.isMetaMask||B?.providers?.some(H=>H.isMetaMask)));};k(),window.addEventListener("ethereum#initialized",k);let z=setTimeout(k,500);return ()=>{window.removeEventListener("ethereum#initialized",k),clearTimeout(z);}},[]),react.useEffect(()=>{N==="stack-select"&&g&&($(g),S("select"));},[N,g]),react.useEffect(()=>{if(!(!c.ready||!b)&&c.identity){let k=[];c.resolvedStackId&&k.push({stackId:c.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(k.map(async z=>{try{let W=await fetch(`${v}/api/v2/stacks/${z.stackId}`);if(W.ok){let B=await W.json(),H=B.data?.stack||B;z.name=H.displayName||H.name,z.logoUrl=H.logoUrl;}}catch{}return z})).then(O);}},[c.ready,c.identity,c.resolvedStackId,b,v]),react.useEffect(()=>{o&&N==="success"&&t?.();},[o,N,t]);let Se=l||(L.length>0?L.filter(k=>k.type==="wallet").map(k=>k.id):["phantom","metamask"]),ve=f!==void 0?f:L.length>0?L.some(k=>k.type==="otp"):true,_e=async()=>{A("phantom"),S("connecting");let k=await a("phantom");S(k?"success":"error");},$e=async()=>{A("metamask"),S("connecting");let k=await d();S(k?"success":"error");},Be=async k=>{C("verifying"),D(""),await n(k)?(C("success"),S("success")):(C("error"),D("Invalid or expired code"),setTimeout(()=>C("idle"),2e3));},Ie=()=>{S(b&&!J?"stack-select":"select"),A(null),Z(false),C("idle"),D("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${h}`,children:[jsxRuntime.jsxs("div",{className:"mb-6 text-center",children:[x?.logoUrl&&N!=="stack-select"&&jsxRuntime.jsx("img",{src:x.logoUrl,alt:"",className:"h-10 w-10 mx-auto mb-3"}),jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:s}),x?.displayName&&N!=="stack-select"&&jsxRuntime.jsx("p",{className:"text-sm text-zinc-400 mt-1",children:x.displayName})]}),N==="stack-select"&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:I.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),I.map(k=>jsxRuntime.jsxs("button",{onClick:()=>{$(k.stackId),S("select");},className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[k.logoUrl?jsxRuntime.jsx("img",{src:k.logoUrl,alt:"",className:"h-10 w-10 flex-shrink-0"}):jsxRuntime.jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:k.name?.[0]?.toUpperCase()||"S"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-white",children:k.name||k.stackId}),jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:k.domain})]}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},k.stackId)),c.ready&&!c.known&&jsxRuntime.jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),N==="select"&&P&&jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),p&&N==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:p}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Ie,children:"Try Again"})]}),N==="success"&&jsxRuntime.jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),N==="connecting"&&i&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxRuntime.jsxs("div",{className:"mx-auto mb-3 h-14 w-14 animate-pulse",children:[T==="phantom"&&jsxRuntime.jsx(ee,{className:"h-14 w-14"}),T==="metamask"&&jsxRuntime.jsx(te,{className:"h-14 w-14"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:r.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:Ie,children:"Cancel"})]}),N==="select"&&!i&&!P&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[Se.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:_e,disabled:!E,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${E?"":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(ee,{className:"h-14 w-14 flex-shrink-0"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"Phantom"}),!E&&jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsxRuntime.jsx(Ce,{className:"h-8 w-8"})]}),Se.includes("metamask")&&Re&&jsxRuntime.jsxs("button",{onClick:$e,className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center bg-white p-2",children:jsxRuntime.jsx(te,{className:"h-10 w-10"})}),jsxRuntime.jsx("div",{className:"flex-1 text-left",children:jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"MetaMask"})}),jsxRuntime.jsx(Me,{className:"h-8 w-8"})]}),ve&&!G&&jsxRuntime.jsxs("button",{onClick:()=>Z(true),className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center border border-zinc-700 bg-[#2a2a3e]",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"28px",viewBox:"0 -960 960 960",width:"28px",fill:"#e3e3e3",children:jsxRuntime.jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsxRuntime.jsx("div",{className:"flex-1 text-left",children:jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"Access Code"})})]}),ve&&G&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsxRuntime.jsx(X,{onComplete:Be,disabled:w==="verifying",error:_}),w==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),w==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),x?.webPageUrl&&w==="idle"&&jsxRuntime.jsx("a",{href:`${x.webPageUrl}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})]})]})]})}function jt({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function At({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function Tt({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Ot({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
|
|
2
|
-
exports.ConnectWidget=
|
|
1
|
+
'use strict';var clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),react=require('react'),jsxRuntime=require('react/jsx-runtime');function Ke(...e){return tailwindMerge.twMerge(clsx.clsx(e))}function qe(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function Xe(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let r=new URL(e,t);return r.origin!==t?"/":r.pathname+r.search+r.hash}catch{return "/"}}function et(e){try{let t=e.split(".");if(t.length!==3)return null;let r=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)}catch{return null}}function le(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function z(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function ce(){let[e,t]=react.useState(null),[r,c]=react.useState(true),f=react.useCallback(()=>{let o=le();o&&o.expiresAt>Date.now()?t({userId:o.userId,address:o.address,chain:o.chain,expiresAt:o.expiresAt,planId:o.planId,authMethod:o.authMethod}):t(null),c(false);},[]);react.useEffect(()=>{f();},[f]);let m=react.useCallback(async(o="")=>{try{let a=await fetch(`${o}/api/auth/session`);if(a.ok){let i=await a.json();if(i.session)return t(i.session),i.session}return t(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:g,refresh:m,readSession:f}}function ue(e="__csrf",t="x-csrf-token"){let[r,c]=react.useState(null);react.useEffect(()=>{c(z(e));},[e]);let f=r?{[t]:r}:{};return {token:r,headers:f}}function de(){let[e,t]=react.useState({connected:false,address:null,chain:null,provider:null}),[r,c]=react.useState(null),f=react.useCallback(async(a="phantom")=>{c(null);try{let i=typeof window<"u"?window:null,p=a==="phantom"?i?.phantom?.solana||i?.solana:i?.solflare;if(!p)return c(`${a} wallet not found`),null;let d=(await p.connect()).publicKey.toString();return t({connected:!0,address:d,chain:"solana",provider:a}),d}catch(i){return c(i.message||"Failed to connect wallet"),null}},[]),m=react.useCallback(async()=>{c(null);try{let i=(typeof window<"u"?window:null)?.ethereum;if(!i)return c("MetaMask not found"),null;let p=i;i.providers?.length&&(p=i.providers.find(n=>n.isMetaMask)||i);let d=(await p.request({method:"eth_requestAccounts"}))[0];return d?(t({connected:!0,address:d,chain:"ethereum",provider:"metamask"}),d):(c("No account selected"),null)}catch(a){return c(a.message||"Failed to connect wallet"),null}},[]),g=react.useCallback(async(a,i)=>{c(null);let p=i?.chain||e.chain,s=i?.provider||e.provider,d=i?.address||e.address;try{if(p==="solana"){let n=typeof window<"u"?window:null,u=s==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!u)throw new Error("Wallet not available");let l=new TextEncoder().encode(a),y=await u.signMessage(l,"utf8"),b=new Uint8Array(y.signature||y),k="";for(let M=0;M<b.byteLength;M++)k+=String.fromCharCode(b[M]);return btoa(k)}if(p==="ethereum"){let u=(typeof window<"u"?window:null)?.ethereum;if(u?.providers?.length&&(u=u.providers.find(y=>y.isMetaMask)||u),!u)throw new Error("MetaMask not available");return await u.request({method:"personal_sign",params:[a,d]})}throw new Error("No wallet connected")}catch(n){return c(n.message||"Signing failed"),null}},[e]),o=react.useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),c(null);},[]);return {wallet:e,error:r,connectSolana:f,connectEVM:m,signMessage:g,disconnect:o}}var at="https://stacknet.magma-rpc.com/auth/bridge",ee="stacknet-auth-bridge";function fe(e){let t=e?.bridgeUrl||at,r=e?.disabled||false,c=react.useRef(null),[f,m]=react.useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),g=react.useRef([]),o=react.useRef(false),a=react.useCallback(n=>{let u={...n,protocol:ee};o.current&&c.current?.contentWindow?c.current.contentWindow.postMessage(u,new URL(t).origin):g.current.push(u);},[t]);react.useEffect(()=>{if(r)return;let n=l=>{if(!(!l.data||l.data.protocol!==ee)){try{if(l.origin!==new URL(t).origin)return}catch{return}switch(l.data.type){case "bridge:ready":o.current=true,m(y=>({...y,ready:true}));for(let y of g.current)c.current?.contentWindow?.postMessage(y,l.origin);g.current=[],c.current?.contentWindow?.postMessage({protocol:ee,type:"auth:check"},l.origin),c.current?.contentWindow?.postMessage({protocol:ee,type:"auth:resolve-stack"},l.origin);break;case "auth:status":m(y=>({...y,known:l.data.known,identity:l.data.identity,identityCount:l.data.identityCount||0}));break;case "auth:resolved-stack":m(y=>({...y,resolvedStackId:l.data.stackId||null}));break;}}};window.addEventListener("message",n);let u=document.createElement("iframe");return u.src=t,u.style.display="none",u.setAttribute("aria-hidden","true"),u.setAttribute("tabindex","-1"),u.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(u),c.current=u,()=>{window.removeEventListener("message",n),u.parentNode&&u.parentNode.removeChild(u),c.current=null,o.current=false;}},[t,r]);let i=react.useCallback(n=>{a({type:"auth:connected",...n});},[a]),p=react.useCallback(n=>{a({type:"auth:disconnected",...n});},[a]),s=react.useCallback(()=>{a({type:"auth:clear"}),m({ready:f.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[a,f.ready]),d=react.useCallback(()=>{a({type:"auth:check"});},[a]);return {...f,reportConnected:i,reportDisconnected:p,clearAll:s,refresh:d}}async function Oe(e,t,r,c){let f=e.apiVersion||"v2",m=`${e.baseUrl}/api/${f}${r}`;try{let g=await fetch(m,{method:t,headers:{"Content-Type":"application/json"},body:c?JSON.stringify(c):void 0}),o=await g.json();return g.ok?o.success&&o.data!==void 0?{success:!0,data:o.data}:{success:!0,data:o}:{success:!1,error:o.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(g){return {success:false,error:{code:"NETWORK_ERROR",message:g instanceof Error?g.message:"Network error"}}}}function ge(e){return {getNetworkStatus:()=>Oe(e,"GET","/network/status"),getWeb3Challenge:(t,r)=>Oe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:t,address:r})}}function he(e={apiBaseUrl:""}){let{wallet:t,connectSolana:r,connectEVM:c,signMessage:f,disconnect:m}=de(),{session:g,isAuthenticated:o,refresh:a,readSession:i}=ce(),{headers:p}=ue(),s=fe({disabled:typeof window>"u"}),[d,n]=react.useState(false),[u,l]=react.useState(null),[y,b]=react.useState(false),k=e.apiBaseUrl||"",M=e.stacknetUrl||"https://stacknet.magma-rpc.com",v=e.stackId||s.resolvedStackId||"",S=ge({baseUrl:M,stackId:v}),L=react.useCallback(async(C,N,H,W)=>{n(true),l(null);try{let j=N;if(!j){let F=await H();if(!F)return n(!1),!1;j=F;}let _=await S.getWeb3Challenge(C,j);if(!_.success||!_.data)return l("Failed to get challenge"),n(!1),!1;let q=await f(_.data.message,{chain:C,provider:W,address:j});if(!q)return n(!1),!1;let Q={chain:C,message:_.data.message,signature:q,stackId:v};C==="solana"&&(Q.publicKey=j);let $=await fetch(`${k}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!$.ok){let F=await $.json().catch(()=>({}));return l(F.error||"Authentication failed"),n(!1),!1}return s.reportConnected({address:j,chain:C,method:W||(C==="solana"?"phantom":"metamask"),stackId:v}),i(),n(!1),!0}catch(j){return l(j.message||"Authentication failed"),n(false),false}},[k,S,f,i,s,v]),T=react.useCallback(async(C="phantom")=>{let N=await r(C);return N?L("solana",N,()=>r(C),C):false},[r,L]),A=react.useCallback(async()=>{let C=await c();return C?L("ethereum",C,c,"metamask"):false},[c,L]),U=react.useCallback(async C=>{n(true),l(null);try{let N=await fetch(`${k}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:C})});if(!N.ok){let H=await N.json().catch(()=>({}));return l(H.error||"Invalid code"),n(!1),!1}return i(),n(!1),!0}catch(N){return l(N.message||"OTP verification failed"),n(false),false}},[k,i]),O=react.useCallback(async()=>{t.address&&t.chain&&s.reportDisconnected({address:t.address,chain:t.chain,stackId:v});try{await fetch(`${k}/api/auth/logout`,{method:"POST",headers:p});}catch{}m(),i();},[k,p,m,i,t,s,v]);return react.useEffect(()=>{if(!e.autoConnect||y||o||!s.ready||!s.known||!s.identity)return;b(true);let{chain:C,method:N}=s.identity;C==="solana"&&(N==="phantom"||N==="solflare")?T(N):C==="ethereum"&&A();},[e.autoConnect,y,o,s,T,A]),{session:g,isAuthenticated:o,wallet:t,loading:d,error:u,authenticateSolana:T,authenticateEVM:A,authenticateOTP:U,logout:O,refresh:()=>a(k),stackId:v,bridge:{ready:s.ready,known:s.known,identity:s.identity,identityCount:s.identityCount,resolvedStackId:s.resolvedStackId}}}function ke(e,t="https://stacknet.magma-rpc.com"){let[r,c]=react.useState(null),[f,m]=react.useState(false),[g,o]=react.useState(null),a=react.useCallback(async p=>{m(true),o(null);try{let s=await fetch(`${t}/api/v2/stacks/${p}`);if(!s.ok)return o("Stack not found"),m(!1),null;let d=await s.json(),n=d.data?.stack||d.stack||d,u={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(l=>({provider:l.provider,enabled:l.enabled!==!1}))};return c(u),m(!1),u}catch(s){return o(s.message),m(false),null}},[t]);react.useEffect(()=>{e&&a(e);},[e,a]);let i=r?ut(r):[];return {config:r,loading:f,error:g,identityProviders:i,fetchConfig:a}}function ut(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let r of e.oauthProviders)r.enabled&&t.push({type:"oauth",id:r.provider,name:r.provider});return t}function ft(e=""){let[t,r]=react.useState([]),[c,f]=react.useState(true),[m,g]=react.useState(null),o=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/plans`);if(a.ok){let i=await a.json();r(i.plans||i||[]);}}catch(a){g(a.message);}finally{f(false);}},[e]);return react.useEffect(()=>{o();},[o]),{plans:t,loading:c,error:m,refresh:o}}function mt(e=""){let[t,r]=react.useState(null),[c,f]=react.useState(true),[m,g]=react.useState(null),o=react.useCallback(async()=>{try{let p=await fetch(`${e}/api/billing/subscription`);if(p.ok){let s=await p.json();r(s.plan?s:null);}}catch(p){g(p.message);}finally{f(false);}},[e]);react.useEffect(()=>{o();},[o]);let a=react.useCallback(async p=>{let s=z(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({planId:p})})).json();return n.url||n.checkoutUrl||null},[e]),i=react.useCallback(async()=>{let p=z();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:p?{"x-csrf-token":p}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:t,loading:c,error:m,refresh:o,subscribe:a,cancel:i}}function kt(e=""){let[t,r]=react.useState(null),[c,f]=react.useState(true),[m,g]=react.useState(null),o=react.useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/usage`);if(a.ok){let i=await a.json();r(i);}}catch(a){g(a.message);}finally{f(false);}},[e]);return react.useEffect(()=>{o();},[o]),{usage:t,loading:c,error:m,refresh:o}}function bt(e=""){let[t,r]=react.useState(false),[c,f]=react.useState(null),m=react.useCallback(async o=>{r(true),f(null);try{let a=z(),i=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({amountCents:o})}),p=await i.json();return i.ok?p.url||null:(f(p.error||"Purchase failed"),null)}catch(a){return f(a.message),null}finally{r(false);}},[e]),g=react.useCallback(async o=>{r(true),f(null);try{let a=z(),i=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({sessionId:o})}),p=await i.json();return i.ok?p:(f(p.error||"Verification failed"),null)}catch(a){return f(a.message),null}finally{r(false);}},[e]);return {purchase:m,verifySession:g,loading:t,error:c}}function Ct(e="",t){let[r,c]=react.useState([]),[f,m]=react.useState(true),[g,o]=react.useState(null),a=t?.limit||50,i=t?.offset||0,p=react.useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/history?limit=${a}&offset=${i}`);if(s.ok){let d=await s.json();c(d.records||d.history||(Array.isArray(d)?d:[]));}}catch(s){o(s.message);}finally{m(false);}},[e,a,i]);return react.useEffect(()=>{p();},[p]),{records:r,loading:f,error:g,refresh:p}}function Nt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function Se(e,t){let[r,c]=react.useState(null),[f,m]=react.useState(true),[g,o]=react.useState(false),[a,i]=react.useState(null),p=t?.apiBaseUrl??"",s=t?.scope??"global",d=react.useCallback(l=>s==="global"?`${p}/api/user/profile/${l}`:`${p}/api/v2/stacks/${s.stackId}/members/${l}/profile`,[p,s]),n=react.useCallback(async()=>{if(!e){c(null),m(false);return}m(true),i(null);try{let l=await fetch(d(e));if(l.ok){let y=await l.json(),b=y.profile||y.data?.profile||y;c({mid:b.mid||e,username:b.username||"",avatarUrl:b.avatar_url||b.avatarUrl,bio:b.bio,createdAt:b.created_at||b.createdAt,updatedAt:b.updated_at||b.updatedAt});}else if(l.status===404)c({mid:e,username:""});else throw new Error(`${l.status}`)}catch(l){i(l instanceof Error?l.message:"Failed to load profile");}finally{m(false);}},[e,d]);react.useEffect(()=>{n();},[n]);let u=react.useCallback(async l=>{if(!e)return false;o(true),i(null);try{let y=Nt(),b=await fetch(d(e),{method:"PUT",headers:{"Content-Type":"application/json",...y?{"x-csrf-token":y}:{}},credentials:"same-origin",body:JSON.stringify({username:l.username,avatar_url:l.avatarUrl,bio:l.bio})});if(!b.ok){let v=await b.json().catch(()=>({}));throw new Error(v.error||v.message||`Update failed: ${b.status}`)}let k=await b.json(),M=k.profile||k.data?.profile||k;return c(v=>({mid:v?.mid||e,username:l.username??v?.username??"",avatarUrl:l.avatarUrl??v?.avatarUrl,bio:l.bio??v?.bio,createdAt:v?.createdAt,updatedAt:M.updated_at||M.updatedAt||Date.now()})),!0}catch(y){return i(y instanceof Error?y.message:"Update failed"),false}finally{o(false);}},[e,d]);return {profile:r,loading:f,saving:g,error:a,updateProfile:u,refresh:n}}var _e=react.createContext(null);function It(){let e=react.useContext(_e);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Lt({config:e,callbacks:t,children:r}){return jsxRuntime.jsx(_e.Provider,{value:{config:e,callbacks:t},children:r})}function ne({length:e=6,onComplete:t,disabled:r=false,error:c,className:f="",inputClassName:m=""}){let [g,o]=react.useState(Array(e).fill("")),a=react.useCallback((s,d)=>{if(d.length>1){let u=d.replace(/\D/g,"").slice(0,e).split(""),l=[...g];u.forEach((b,k)=>{s+k<e&&(l[s+k]=b);}),o(l);let y=Math.min(s+u.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),l.every(b=>b!=="")&&setTimeout(()=>t(l.join("")),100);return}if(!/^\d?$/.test(d))return;let n=[...g];n[s]=d,o(n),d&&s<e-1&&document.getElementById(`userutils-otp-${s+1}`)?.focus(),d&&s===e-1&&n.every(u=>u!=="")&&setTimeout(()=>t(n.join("")),100);},[g,e,t]),i=react.useCallback((s,d)=>{if(d.key==="Backspace"&&!g[s]&&s>0){document.getElementById(`userutils-otp-${s-1}`)?.focus();let n=[...g];n[s-1]="",o(n);}if(d.key==="Enter"){let n=g.join("");n.length===e&&t(n);}},[g,e,t]);react.useCallback(()=>{o(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxRuntime.jsxs("div",{className:f,children:[jsxRuntime.jsx("div",{className:"flex gap-2 justify-center",children:g.map((s,d)=>jsxRuntime.jsx("input",{id:`userutils-otp-${d}`,type:"text",inputMode:"numeric",maxLength:e,value:s,onChange:n=>a(d,n.target.value),onKeyDown:n=>i(d,n),disabled:r,autoFocus:d===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${m}`},d))}),c&&jsxRuntime.jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:c})]})}ne.displayName="OTPInput";var At="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function re({className:e}){return jsxRuntime.jsx("img",{src:At,alt:"Phantom",className:e})}function oe({className:e}){return jsxRuntime.jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsxRuntime.jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsxRuntime.jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsxRuntime.jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsxRuntime.jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsxRuntime.jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsxRuntime.jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsxRuntime.jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsxRuntime.jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsxRuntime.jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function Le({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxRuntime.jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsxRuntime.jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsxRuntime.jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsxRuntime.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsxRuntime.jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsxRuntime.jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Ue({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsxRuntime.jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsxRuntime.jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsxRuntime.jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Et({config:e,onSuccess:t,title:r="Log in or Sign up",showWallets:c,showOTP:f,className:m=""}){let g=he(e),{isAuthenticated:o,wallet:a,loading:i,error:p,authenticateSolana:s,authenticateEVM:d,authenticateOTP:n,bridge:u,stackId:l}=g,y=!e.stackId&&!l,b=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:k,identityProviders:M,loading:v}=ke(l||e.stackId||null,b),[S,L]=react.useState(y?"stack-select":"select"),[T,A]=react.useState(null),[U,O]=react.useState(false),[C,N]=react.useState("idle"),[H,W]=react.useState(""),[j,_]=react.useState([]),[q,Q]=react.useState(e.stackId||null),[$,F]=react.useState(false),[He,Qe]=react.useState(false);react.useEffect(()=>{if(typeof window>"u")return;let x=()=>{let B=window;F(!!(B.phantom?.solana?.isPhantom||B.solana?.isPhantom));let V=B.ethereum;Qe(!!(V?.isMetaMask||V?.providers?.some(Y=>Y.isMetaMask)));};x(),window.addEventListener("ethereum#initialized",x);let R=setTimeout(x,500);return ()=>{window.removeEventListener("ethereum#initialized",x),clearTimeout(R);}},[]),react.useEffect(()=>{S==="stack-select"&&l&&(Q(l),L("select"));},[S,l]),react.useEffect(()=>{if(!(!u.ready||!y)&&u.identity){let x=[];u.resolvedStackId&&x.push({stackId:u.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(x.map(async R=>{try{let B=await fetch(`${b}/api/v2/stacks/${R.stackId}`);if(B.ok){let V=await B.json(),Y=V.data?.stack||V;R.name=Y.displayName||Y.name,R.logoUrl=Y.logoUrl;}}catch{}return R})).then(_);}},[u.ready,u.identity,u.resolvedStackId,y,b]),react.useEffect(()=>{o&&S==="success"&&t?.();},[o,S,t]);let je=c||(M.length>0?M.filter(x=>x.type==="wallet").map(x=>x.id):["phantom","metamask"]),Ae=f!==void 0?f:M.length>0?M.some(x=>x.type==="otp"):true,Ve=async()=>{A("phantom"),L("connecting");let x=await s("phantom");L(x?"success":"error");},Ye=async()=>{A("metamask"),L("connecting");let x=await d();L(x?"success":"error");},Ge=async x=>{N("verifying"),W(""),await n(x)?(N("success"),L("success")):(N("error"),W("Invalid or expired code"),setTimeout(()=>N("idle"),2e3));},ze=()=>{L(y&&!q?"stack-select":"select"),A(null),O(false),N("idle"),W("");};return jsxRuntime.jsxs("div",{className:`w-full max-w-md space-y-3 ${m}`,children:[jsxRuntime.jsxs("div",{className:"mb-6 text-center",children:[k?.logoUrl&&S!=="stack-select"&&jsxRuntime.jsx("img",{src:k.logoUrl,alt:"",className:"h-10 w-10 mx-auto mb-3"}),jsxRuntime.jsx("h1",{className:"font-semibold text-2xl text-white",children:r}),k?.displayName&&S!=="stack-select"&&jsxRuntime.jsx("p",{className:"text-sm text-zinc-400 mt-1",children:k.displayName})]}),S==="stack-select"&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:j.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),j.map(x=>jsxRuntime.jsxs("button",{onClick:()=>{Q(x.stackId),L("select");},className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[x.logoUrl?jsxRuntime.jsx("img",{src:x.logoUrl,alt:"",className:"h-10 w-10 flex-shrink-0"}):jsxRuntime.jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:x.name?.[0]?.toUpperCase()||"S"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-white",children:x.name||x.stackId}),jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:x.domain})]}),jsxRuntime.jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},x.stackId)),u.ready&&!u.known&&jsxRuntime.jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),S==="select"&&v&&jsxRuntime.jsx("div",{className:"flex items-center justify-center py-8",children:jsxRuntime.jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),p&&S==="error"&&jsxRuntime.jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsxRuntime.jsx("p",{className:"text-center text-red-400 text-sm",children:p}),jsxRuntime.jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:ze,children:"Try Again"})]}),S==="success"&&jsxRuntime.jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),S==="connecting"&&i&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxRuntime.jsxs("div",{className:"mx-auto mb-3 h-14 w-14 animate-pulse",children:[T==="phantom"&&jsxRuntime.jsx(re,{className:"h-14 w-14"}),T==="metamask"&&jsxRuntime.jsx(oe,{className:"h-14 w-14"})]}),jsxRuntime.jsx("p",{className:"font-medium text-sm text-white",children:a.connected?"Signing message...":"Connecting wallet..."}),jsxRuntime.jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsxRuntime.jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:ze,children:"Cancel"})]}),S==="select"&&!i&&!v&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[je.includes("phantom")&&jsxRuntime.jsxs("button",{onClick:Ve,disabled:!$,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${$?"":"cursor-not-allowed opacity-50"}`,children:[jsxRuntime.jsx(re,{className:"h-14 w-14 flex-shrink-0"}),jsxRuntime.jsxs("div",{className:"flex-1 text-left",children:[jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"Phantom"}),!$&&jsxRuntime.jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsxRuntime.jsx(Le,{className:"h-8 w-8"})]}),je.includes("metamask")&&He&&jsxRuntime.jsxs("button",{onClick:Ye,className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center bg-white p-2",children:jsxRuntime.jsx(oe,{className:"h-10 w-10"})}),jsxRuntime.jsx("div",{className:"flex-1 text-left",children:jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"MetaMask"})}),jsxRuntime.jsx(Ue,{className:"h-8 w-8"})]}),Ae&&!U&&jsxRuntime.jsxs("button",{onClick:()=>O(true),className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsxRuntime.jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center border border-zinc-700 bg-[#2a2a3e]",children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"28px",viewBox:"0 -960 960 960",width:"28px",fill:"#e3e3e3",children:jsxRuntime.jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsxRuntime.jsx("div",{className:"flex-1 text-left",children:jsxRuntime.jsx("span",{className:"font-medium text-lg text-white",children:"Access Code"})})]}),Ae&&U&&jsxRuntime.jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsxRuntime.jsx(ne,{onComplete:Ge,disabled:C==="verifying",error:H}),C==="verifying"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),C==="success"&&jsxRuntime.jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),k?.webPageUrl&&C==="idle"&&jsxRuntime.jsx("a",{href:`${k.webPageUrl}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})]})]})]})}function _t({mid:e,apiBaseUrl:t="",scope:r,onSave:c,className:f}){let{profile:m,loading:g,saving:o,error:a,updateProfile:i}=Se(e,{apiBaseUrl:t,scope:r}),[p,s]=react.useState(null),[d,n]=react.useState(null),[u,l]=react.useState(null),y=react.useRef(null),[b,k]=react.useState(false),M=p??m?.username??"",v=d??m?.bio??"",S=u??m?.avatarUrl,L=react.useCallback(U=>{let O=U.target.files?.[0];if(!O)return;let C=new FileReader;C.onload=()=>{l(C.result),k(true);},C.readAsDataURL(O);},[]),T=async()=>{await i({username:M||void 0,avatarUrl:u??m?.avatarUrl,bio:v||void 0})&&(k(false),c?.());};if(g)return jsxRuntime.jsxs("div",{className:f,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsxRuntime.jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let A=r==="global"||!r?"Global profile":`Stack profile (${r.stackId})`;return jsxRuntime.jsxs("div",{className:f,style:{display:"grid",gap:"1.5rem"},children:[jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:A}),jsxRuntime.jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>y.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:S?jsxRuntime.jsx("img",{src:S,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsxRuntime.jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsxRuntime.jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsxRuntime.jsx("input",{type:"text",value:M,onChange:U=>{s(U.target.value),k(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsxRuntime.jsx("input",{ref:y,type:"file",accept:"image/*",onChange:L,style:{display:"none"}})]}),jsxRuntime.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsxRuntime.jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsxRuntime.jsx("input",{type:"text",value:v,onChange:U=>{n(U.target.value),k(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),a&&jsxRuntime.jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:a}),b&&jsxRuntime.jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsxRuntime.jsx("button",{onClick:T,disabled:o,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:o?"wait":"pointer",opacity:o?.6:1},children:o?"Saving...":"Save"}),jsxRuntime.jsx("button",{onClick:()=>{s(null),n(null),l(null),k(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsxRuntime.jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 100M tokens"})]})]})}function $t({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsxRuntime.jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function Bt({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsxRuntime.jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsxRuntime.jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsxRuntime.jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsxRuntime.jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function Qt({className:e}){return jsxRuntime.jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsxRuntime.jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Yt({className:e}){return jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsxRuntime.jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsxRuntime.jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsxRuntime.jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsxRuntime.jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
|
|
2
|
+
exports.ConnectWidget=Et;exports.DiscordIcon=Qt;exports.EthereumIcon=Ue;exports.GoogleIcon=Bt;exports.MetaMaskIcon=oe;exports.OTPInput=ne;exports.PhantomIcon=re;exports.ProfileSettings=_t;exports.SolanaIcon=Le;exports.TelegramIcon=Yt;exports.TwitterIcon=$t;exports.UserUtilsProvider=Lt;exports.cn=Ke;exports.createStackNetClient=ge;exports.decodeJwtPayloadClient=et;exports.formatTokens=qe;exports.readCSRFCookie=z;exports.readSessionCookie=le;exports.useAuthBridge=fe;exports.useBillingHistory=Ct;exports.useCSRFToken=ue;exports.usePlans=ft;exports.usePrepaidCheckout=bt;exports.useProfile=Se;exports.useSession=ce;exports.useStackAuth=he;exports.useStackConfig=ke;exports.useSubscription=mt;exports.useUsage=kt;exports.useUserUtilsContext=It;exports.useWeb3Wallet=de;exports.validateRedirectUrl=Xe;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './
|
|
2
|
-
export { B as BillingPlan, a as BillingRecord, M as MPCNode, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig } from './
|
|
1
|
+
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './config-BrziGArs.cjs';
|
|
2
|
+
export { B as BillingPlan, a as BillingRecord, M as MPCNode, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig } from './config-BrziGArs.cjs';
|
|
3
|
+
export { ProfileScope, ProfileUpdateInput, UserProfile } from './types/index.cjs';
|
|
3
4
|
export { cn, decodeJwtPayloadClient, formatTokens, readCSRFCookie, readSessionCookie, validateRedirectUrl } from './utils/index.cjs';
|
|
4
|
-
export { BridgeIdentity, StackPublicConfig, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.cjs';
|
|
5
|
-
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.cjs';
|
|
5
|
+
export { BridgeIdentity, StackPublicConfig, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.cjs';
|
|
6
|
+
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, ProfileSettings, ProfileSettingsProps, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.cjs';
|
|
6
7
|
import 'clsx';
|
|
7
8
|
import 'react/jsx-runtime';
|
|
8
9
|
import 'react';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './
|
|
2
|
-
export { B as BillingPlan, a as BillingRecord, M as MPCNode, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig } from './
|
|
1
|
+
import { A as APIResponse, N as NetworkStatus, W as Web3Chain } from './config-BrziGArs.js';
|
|
2
|
+
export { B as BillingPlan, a as BillingRecord, M as MPCNode, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig } from './config-BrziGArs.js';
|
|
3
|
+
export { ProfileScope, ProfileUpdateInput, UserProfile } from './types/index.js';
|
|
3
4
|
export { cn, decodeJwtPayloadClient, formatTokens, readCSRFCookie, readSessionCookie, validateRedirectUrl } from './utils/index.js';
|
|
4
|
-
export { BridgeIdentity, StackPublicConfig, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.js';
|
|
5
|
-
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.js';
|
|
5
|
+
export { BridgeIdentity, StackPublicConfig, WalletState, useAuthBridge, useBillingHistory, useCSRFToken, usePlans, usePrepaidCheckout, useProfile, useSession, useStackAuth, useStackConfig, useSubscription, useUsage, useWeb3Wallet } from './hooks/index.js';
|
|
6
|
+
export { ConnectWidget, ConnectWidgetProps, DiscordIcon, EthereumIcon, GoogleIcon, MetaMaskIcon, OTPInput, OTPInputProps, PhantomIcon, ProfileSettings, ProfileSettingsProps, SolanaIcon, TelegramIcon, TwitterIcon, UserUtilsProvider, UserUtilsProviderProps, useUserUtilsContext } from './components/index.js';
|
|
6
7
|
import 'clsx';
|
|
7
8
|
import 'react/jsx-runtime';
|
|
8
9
|
import 'react';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useState,useCallback,useEffect,useRef,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function Qe(...e){return twMerge(clsx(e))}function Ve(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function Ye(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let s=new URL(e,t);return s.origin!==t?"/":s.pathname+s.search+s.hash}catch{return "/"}}function Ge(e){try{let t=e.split(".");if(t.length!==3)return null;let s=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(s)}catch{return null}}function oe(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function j(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(s=>s.trim()).find(s=>s.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function re(){let[e,t]=useState(null),[s,l]=useState(true),f=useCallback(()=>{let o=oe();o&&o.expiresAt>Date.now()?t({userId:o.userId,address:o.address,chain:o.chain,expiresAt:o.expiresAt,planId:o.planId,authMethod:o.authMethod}):t(null),l(false);},[]);useEffect(()=>{f();},[f]);let h=useCallback(async(o="")=>{try{let r=await fetch(`${o}/api/auth/session`);if(r.ok){let i=await r.json();if(i.session)return t(i.session),i.session}return t(null),null}catch{return null}},[]),m=!!e&&e.expiresAt>Date.now();return {session:e,loading:s,isAuthenticated:m,refresh:h,readSession:f}}function ae(e="__csrf",t="x-csrf-token"){let[s,l]=useState(null);useEffect(()=>{l(j(e));},[e]);let f=s?{[t]:s}:{};return {token:s,headers:f}}function ie(){let[e,t]=useState({connected:false,address:null,chain:null,provider:null}),[s,l]=useState(null),f=useCallback(async(r="phantom")=>{l(null);try{let i=typeof window<"u"?window:null,p=r==="phantom"?i?.phantom?.solana||i?.solana:i?.solflare;if(!p)return l(`${r} wallet not found`),null;let d=(await p.connect()).publicKey.toString();return t({connected:!0,address:d,chain:"solana",provider:r}),d}catch(i){return l(i.message||"Failed to connect wallet"),null}},[]),h=useCallback(async()=>{l(null);try{let i=(typeof window<"u"?window:null)?.ethereum;if(!i)return l("MetaMask not found"),null;let p=i;i.providers?.length&&(p=i.providers.find(n=>n.isMetaMask)||i);let d=(await p.request({method:"eth_requestAccounts"}))[0];return d?(t({connected:!0,address:d,chain:"ethereum",provider:"metamask"}),d):(l("No account selected"),null)}catch(r){return l(r.message||"Failed to connect wallet"),null}},[]),m=useCallback(async(r,i)=>{l(null);let p=i?.chain||e.chain,a=i?.provider||e.provider,d=i?.address||e.address;try{if(p==="solana"){let n=typeof window<"u"?window:null,c=a==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!c)throw new Error("Wallet not available");let g=new TextEncoder().encode(r),b=await c.signMessage(g,"utf8"),v=new Uint8Array(b.signature||b),x="";for(let L=0;L<v.byteLength;L++)x+=String.fromCharCode(v[L]);return btoa(x)}if(p==="ethereum"){let c=(typeof window<"u"?window:null)?.ethereum;if(c?.providers?.length&&(c=c.providers.find(b=>b.isMetaMask)||c),!c)throw new Error("MetaMask not available");return await c.request({method:"personal_sign",params:[r,d]})}throw new Error("No wallet connected")}catch(n){return l(n.message||"Signing failed"),null}},[e]),o=useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),l(null);},[]);return {wallet:e,error:s,connectSolana:f,connectEVM:h,signMessage:m,disconnect:o}}var et="https://stacknet.magma-rpc.com/auth/bridge",q="stacknet-auth-bridge";function ce(e){let t=e?.bridgeUrl||et,s=e?.disabled||false,l=useRef(null),[f,h]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),m=useRef([]),o=useRef(false),r=useCallback(n=>{let c={...n,protocol:q};o.current&&l.current?.contentWindow?l.current.contentWindow.postMessage(c,new URL(t).origin):m.current.push(c);},[t]);useEffect(()=>{if(s)return;let n=g=>{if(!(!g.data||g.data.protocol!==q)){try{if(g.origin!==new URL(t).origin)return}catch{return}switch(g.data.type){case "bridge:ready":o.current=true,h(b=>({...b,ready:true}));for(let b of m.current)l.current?.contentWindow?.postMessage(b,g.origin);m.current=[],l.current?.contentWindow?.postMessage({protocol:q,type:"auth:check"},g.origin),l.current?.contentWindow?.postMessage({protocol:q,type:"auth:resolve-stack"},g.origin);break;case "auth:status":h(b=>({...b,known:g.data.known,identity:g.data.identity,identityCount:g.data.identityCount||0}));break;case "auth:resolved-stack":h(b=>({...b,resolvedStackId:g.data.stackId||null}));break;}}};window.addEventListener("message",n);let c=document.createElement("iframe");return c.src=t,c.style.display="none",c.setAttribute("aria-hidden","true"),c.setAttribute("tabindex","-1"),c.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(c),l.current=c,()=>{window.removeEventListener("message",n),c.parentNode&&c.parentNode.removeChild(c),l.current=null,o.current=false;}},[t,s]);let i=useCallback(n=>{r({type:"auth:connected",...n});},[r]),p=useCallback(n=>{r({type:"auth:disconnected",...n});},[r]),a=useCallback(()=>{r({type:"auth:clear"}),h({ready:f.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[r,f.ready]),d=useCallback(()=>{r({type:"auth:check"});},[r]);return {...f,reportConnected:i,reportDisconnected:p,clearAll:a,refresh:d}}async function Ue(e,t,s,l){let f=e.apiVersion||"v2",h=`${e.baseUrl}/api/${f}${s}`;try{let m=await fetch(h,{method:t,headers:{"Content-Type":"application/json"},body:l?JSON.stringify(l):void 0}),o=await m.json();return m.ok?o.success&&o.data!==void 0?{success:!0,data:o.data}:{success:!0,data:o}:{success:!1,error:o.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(m){return {success:false,error:{code:"NETWORK_ERROR",message:m instanceof Error?m.message:"Network error"}}}}function de(e){return {getNetworkStatus:()=>Ue(e,"GET","/network/status"),getWeb3Challenge:(t,s)=>Ue(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:t,address:s})}}function pe(e={apiBaseUrl:""}){let{wallet:t,connectSolana:s,connectEVM:l,signMessage:f,disconnect:h}=ie(),{session:m,isAuthenticated:o,refresh:r,readSession:i}=re(),{headers:p}=ae(),a=ce({disabled:typeof window>"u"}),[d,n]=useState(false),[c,g]=useState(null),[b,v]=useState(false),x=e.apiBaseUrl||"",L=e.stacknetUrl||"https://stacknet.magma-rpc.com",P=e.stackId||a.resolvedStackId||"",N=de({baseUrl:L,stackId:P}),S=useCallback(async(w,C,_,D)=>{n(true),g(null);try{let I=C;if(!I){let R=await _();if(!R)return n(!1),!1;I=R;}let O=await N.getWeb3Challenge(w,I);if(!O.success||!O.data)return g("Failed to get challenge"),n(!1),!1;let J=await f(O.data.message,{chain:w,provider:D,address:I});if(!J)return n(!1),!1;let $={chain:w,message:O.data.message,signature:J,stackId:P};w==="solana"&&($.publicKey=I);let E=await fetch(`${x}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify($)});if(!E.ok){let R=await E.json().catch(()=>({}));return g(R.error||"Authentication failed"),n(!1),!1}return a.reportConnected({address:I,chain:w,method:D||(w==="solana"?"phantom":"metamask"),stackId:P}),i(),n(!1),!0}catch(I){return g(I.message||"Authentication failed"),n(false),false}},[x,N,f,i,a,P]),T=useCallback(async(w="phantom")=>{let C=await s(w);return C?S("solana",C,()=>s(w),w):false},[s,S]),A=useCallback(async()=>{let w=await l();return w?S("ethereum",w,l,"metamask"):false},[l,S]),G=useCallback(async w=>{n(true),g(null);try{let C=await fetch(`${x}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:w})});if(!C.ok){let _=await C.json().catch(()=>({}));return g(_.error||"Invalid code"),n(!1),!1}return i(),n(!1),!0}catch(C){return g(C.message||"OTP verification failed"),n(false),false}},[x,i]),Z=useCallback(async()=>{t.address&&t.chain&&a.reportDisconnected({address:t.address,chain:t.chain,stackId:P});try{await fetch(`${x}/api/auth/logout`,{method:"POST",headers:p});}catch{}h(),i();},[x,p,h,i,t,a,P]);return useEffect(()=>{if(!e.autoConnect||b||o||!a.ready||!a.known||!a.identity)return;v(true);let{chain:w,method:C}=a.identity;w==="solana"&&(C==="phantom"||C==="solflare")?T(C):w==="ethereum"&&A();},[e.autoConnect,b,o,a,T,A]),{session:m,isAuthenticated:o,wallet:t,loading:d,error:c,authenticateSolana:T,authenticateEVM:A,authenticateOTP:G,logout:Z,refresh:()=>r(x),stackId:P,bridge:{ready:a.ready,known:a.known,identity:a.identity,identityCount:a.identityCount,resolvedStackId:a.resolvedStackId}}}function me(e,t="https://stacknet.magma-rpc.com"){let[s,l]=useState(null),[f,h]=useState(false),[m,o]=useState(null),r=useCallback(async p=>{h(true),o(null);try{let a=await fetch(`${t}/api/v2/stacks/${p}`);if(!a.ok)return o("Stack not found"),h(!1),null;let d=await a.json(),n=d.data?.stack||d.stack||d,c={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(g=>({provider:g.provider,enabled:g.enabled!==!1}))};return l(c),h(!1),c}catch(a){return o(a.message),h(false),null}},[t]);useEffect(()=>{e&&r(e);},[e,r]);let i=s?ot(s):[];return {config:s,loading:f,error:m,identityProviders:i,fetchConfig:r}}function ot(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let s of e.oauthProviders)s.enabled&&t.push({type:"oauth",id:s.provider,name:s.provider});return t}function it(e=""){let[t,s]=useState([]),[l,f]=useState(true),[h,m]=useState(null),o=useCallback(async()=>{try{let r=await fetch(`${e}/api/billing/plans`);if(r.ok){let i=await r.json();s(i.plans||i||[]);}}catch(r){m(r.message);}finally{f(false);}},[e]);return useEffect(()=>{o();},[o]),{plans:t,loading:l,error:h,refresh:o}}function ct(e=""){let[t,s]=useState(null),[l,f]=useState(true),[h,m]=useState(null),o=useCallback(async()=>{try{let p=await fetch(`${e}/api/billing/subscription`);if(p.ok){let a=await p.json();s(a.plan?a:null);}}catch(p){m(p.message);}finally{f(false);}},[e]);useEffect(()=>{o();},[o]);let r=useCallback(async p=>{let a=j(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({planId:p})})).json();return n.url||n.checkoutUrl||null},[e]),i=useCallback(async()=>{let p=j();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:p?{"x-csrf-token":p}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:t,loading:l,error:h,refresh:o,subscribe:r,cancel:i}}function pt(e=""){let[t,s]=useState(null),[l,f]=useState(true),[h,m]=useState(null),o=useCallback(async()=>{try{let r=await fetch(`${e}/api/billing/usage`);if(r.ok){let i=await r.json();s(i);}}catch(r){m(r.message);}finally{f(false);}},[e]);return useEffect(()=>{o();},[o]),{usage:t,loading:l,error:h,refresh:o}}function ft(e=""){let[t,s]=useState(false),[l,f]=useState(null),h=useCallback(async o=>{s(true),f(null);try{let r=j(),i=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...r?{"x-csrf-token":r}:{}},body:JSON.stringify({amountCents:o})}),p=await i.json();return i.ok?p.url||null:(f(p.error||"Purchase failed"),null)}catch(r){return f(r.message),null}finally{s(false);}},[e]),m=useCallback(async o=>{s(true),f(null);try{let r=j(),i=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...r?{"x-csrf-token":r}:{}},body:JSON.stringify({sessionId:o})}),p=await i.json();return i.ok?p:(f(p.error||"Verification failed"),null)}catch(r){return f(r.message),null}finally{s(false);}},[e]);return {purchase:h,verifySession:m,loading:t,error:l}}function ht(e="",t){let[s,l]=useState([]),[f,h]=useState(true),[m,o]=useState(null),r=t?.limit||50,i=t?.offset||0,p=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/history?limit=${r}&offset=${i}`);if(a.ok){let d=await a.json();l(d.records||d.history||(Array.isArray(d)?d:[]));}}catch(a){o(a.message);}finally{h(false);}},[e,r,i]);return useEffect(()=>{p();},[p]),{records:s,loading:f,error:m,refresh:p}}var Te=createContext(null);function wt(){let e=useContext(Te);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function bt({config:e,callbacks:t,children:s}){return jsx(Te.Provider,{value:{config:e,callbacks:t},children:s})}function X({length:e=6,onComplete:t,disabled:s=false,error:l,className:f="",inputClassName:h=""}){let [m,o]=useState(Array(e).fill("")),r=useCallback((a,d)=>{if(d.length>1){let c=d.replace(/\D/g,"").slice(0,e).split(""),g=[...m];c.forEach((v,x)=>{a+x<e&&(g[a+x]=v);}),o(g);let b=Math.min(a+c.length,e-1);document.getElementById(`userutils-otp-${b}`)?.focus(),g.every(v=>v!=="")&&setTimeout(()=>t(g.join("")),100);return}if(!/^\d?$/.test(d))return;let n=[...m];n[a]=d,o(n),d&&a<e-1&&document.getElementById(`userutils-otp-${a+1}`)?.focus(),d&&a===e-1&&n.every(c=>c!=="")&&setTimeout(()=>t(n.join("")),100);},[m,e,t]),i=useCallback((a,d)=>{if(d.key==="Backspace"&&!m[a]&&a>0){document.getElementById(`userutils-otp-${a-1}`)?.focus();let n=[...m];n[a-1]="",o(n);}if(d.key==="Enter"){let n=m.join("");n.length===e&&t(n);}},[m,e,t]);useCallback(()=>{o(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:f,children:[jsx("div",{className:"flex gap-2 justify-center",children:m.map((a,d)=>jsx("input",{id:`userutils-otp-${d}`,type:"text",inputMode:"numeric",maxLength:e,value:a,onChange:n=>r(d,n.target.value),onKeyDown:n=>i(d,n),disabled:s,autoFocus:d===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${h}`},d))}),l&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:l})]})}X.displayName="OTPInput";var Mt="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function ee({className:e}){return jsx("img",{src:Mt,alt:"Phantom",className:e})}function te({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function Ce({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Me({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Lt({config:e,onSuccess:t,title:s="Log in or Sign up",showWallets:l,showOTP:f,className:h=""}){let m=pe(e),{isAuthenticated:o,wallet:r,loading:i,error:p,authenticateSolana:a,authenticateEVM:d,authenticateOTP:n,bridge:c,stackId:g}=m,b=!e.stackId&&!g,v=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:x,identityProviders:L,loading:P}=me(g||e.stackId||null,v),[N,S]=useState(b?"stack-select":"select"),[T,A]=useState(null),[G,Z]=useState(false),[w,C]=useState("idle"),[_,D]=useState(""),[I,O]=useState([]),[J,$]=useState(e.stackId||null),[E,R]=useState(false),[Re,We]=useState(false);useEffect(()=>{if(typeof window>"u")return;let k=()=>{let W=window;R(!!(W.phantom?.solana?.isPhantom||W.solana?.isPhantom));let B=W.ethereum;We(!!(B?.isMetaMask||B?.providers?.some(H=>H.isMetaMask)));};k(),window.addEventListener("ethereum#initialized",k);let z=setTimeout(k,500);return ()=>{window.removeEventListener("ethereum#initialized",k),clearTimeout(z);}},[]),useEffect(()=>{N==="stack-select"&&g&&($(g),S("select"));},[N,g]),useEffect(()=>{if(!(!c.ready||!b)&&c.identity){let k=[];c.resolvedStackId&&k.push({stackId:c.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(k.map(async z=>{try{let W=await fetch(`${v}/api/v2/stacks/${z.stackId}`);if(W.ok){let B=await W.json(),H=B.data?.stack||B;z.name=H.displayName||H.name,z.logoUrl=H.logoUrl;}}catch{}return z})).then(O);}},[c.ready,c.identity,c.resolvedStackId,b,v]),useEffect(()=>{o&&N==="success"&&t?.();},[o,N,t]);let Se=l||(L.length>0?L.filter(k=>k.type==="wallet").map(k=>k.id):["phantom","metamask"]),ve=f!==void 0?f:L.length>0?L.some(k=>k.type==="otp"):true,_e=async()=>{A("phantom"),S("connecting");let k=await a("phantom");S(k?"success":"error");},$e=async()=>{A("metamask"),S("connecting");let k=await d();S(k?"success":"error");},Be=async k=>{C("verifying"),D(""),await n(k)?(C("success"),S("success")):(C("error"),D("Invalid or expired code"),setTimeout(()=>C("idle"),2e3));},Ie=()=>{S(b&&!J?"stack-select":"select"),A(null),Z(false),C("idle"),D("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${h}`,children:[jsxs("div",{className:"mb-6 text-center",children:[x?.logoUrl&&N!=="stack-select"&&jsx("img",{src:x.logoUrl,alt:"",className:"h-10 w-10 mx-auto mb-3"}),jsx("h1",{className:"font-semibold text-2xl text-white",children:s}),x?.displayName&&N!=="stack-select"&&jsx("p",{className:"text-sm text-zinc-400 mt-1",children:x.displayName})]}),N==="stack-select"&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:I.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),I.map(k=>jsxs("button",{onClick:()=>{$(k.stackId),S("select");},className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[k.logoUrl?jsx("img",{src:k.logoUrl,alt:"",className:"h-10 w-10 flex-shrink-0"}):jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:k.name?.[0]?.toUpperCase()||"S"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-white",children:k.name||k.stackId}),jsx("p",{className:"text-xs text-zinc-500",children:k.domain})]}),jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},k.stackId)),c.ready&&!c.known&&jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),N==="select"&&P&&jsx("div",{className:"flex items-center justify-center py-8",children:jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),p&&N==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:p}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:Ie,children:"Try Again"})]}),N==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),N==="connecting"&&i&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxs("div",{className:"mx-auto mb-3 h-14 w-14 animate-pulse",children:[T==="phantom"&&jsx(ee,{className:"h-14 w-14"}),T==="metamask"&&jsx(te,{className:"h-14 w-14"})]}),jsx("p",{className:"font-medium text-sm text-white",children:r.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:Ie,children:"Cancel"})]}),N==="select"&&!i&&!P&&jsxs(Fragment,{children:[Se.includes("phantom")&&jsxs("button",{onClick:_e,disabled:!E,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${E?"":"cursor-not-allowed opacity-50"}`,children:[jsx(ee,{className:"h-14 w-14 flex-shrink-0"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-lg text-white",children:"Phantom"}),!E&&jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsx(Ce,{className:"h-8 w-8"})]}),Se.includes("metamask")&&Re&&jsxs("button",{onClick:$e,className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center bg-white p-2",children:jsx(te,{className:"h-10 w-10"})}),jsx("div",{className:"flex-1 text-left",children:jsx("span",{className:"font-medium text-lg text-white",children:"MetaMask"})}),jsx(Me,{className:"h-8 w-8"})]}),ve&&!G&&jsxs("button",{onClick:()=>Z(true),className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center border border-zinc-700 bg-[#2a2a3e]",children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"28px",viewBox:"0 -960 960 960",width:"28px",fill:"#e3e3e3",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("div",{className:"flex-1 text-left",children:jsx("span",{className:"font-medium text-lg text-white",children:"Access Code"})})]}),ve&&G&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsx(X,{onComplete:Be,disabled:w==="verifying",error:_}),w==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),w==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),x?.webPageUrl&&w==="idle"&&jsx("a",{href:`${x.webPageUrl}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})]})]})]})}function jt({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function At({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function Tt({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Ot({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
|
|
2
|
-
export{
|
|
1
|
+
import {clsx}from'clsx';import {twMerge}from'tailwind-merge';import {createContext,useState,useCallback,useEffect,useRef,useContext}from'react';import {jsx,jsxs,Fragment}from'react/jsx-runtime';function Ke(...e){return twMerge(clsx(e))}function qe(e){return e>=1e12?`${(e/1e12).toFixed(e%1e12===0?0:1)}T`:e>=1e9?`${(e/1e9).toFixed(e%1e9===0?0:1)}B`:e>=1e6?`${(e/1e6).toFixed(e%1e6===0?0:1)}M`:e>=1e3?`${(e/1e3).toFixed(0)}K`:e.toLocaleString()}function Xe(e,t){if(!e)return "/";if(e.startsWith("/")&&!e.startsWith("//"))return e;try{let r=new URL(e,t);return r.origin!==t?"/":r.pathname+r.search+r.hash}catch{return "/"}}function et(e){try{let t=e.split(".");if(t.length!==3)return null;let r=atob(t[1].replace(/-/g,"+").replace(/_/g,"/"));return JSON.parse(r)}catch{return null}}function le(){if(typeof document>"u")return null;try{let e=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith("stackauth_session="));if(!e)return null;let t=e.slice(18);return JSON.parse(atob(t.replace(/-/g,"+").replace(/_/g,"/")))}catch{return null}}function z(e="__csrf"){if(typeof document>"u")return null;let t=document.cookie.split(";").map(r=>r.trim()).find(r=>r.startsWith(`${e}=`));return t?t.slice(e.length+1):null}function ce(){let[e,t]=useState(null),[r,c]=useState(true),f=useCallback(()=>{let o=le();o&&o.expiresAt>Date.now()?t({userId:o.userId,address:o.address,chain:o.chain,expiresAt:o.expiresAt,planId:o.planId,authMethod:o.authMethod}):t(null),c(false);},[]);useEffect(()=>{f();},[f]);let m=useCallback(async(o="")=>{try{let a=await fetch(`${o}/api/auth/session`);if(a.ok){let i=await a.json();if(i.session)return t(i.session),i.session}return t(null),null}catch{return null}},[]),g=!!e&&e.expiresAt>Date.now();return {session:e,loading:r,isAuthenticated:g,refresh:m,readSession:f}}function ue(e="__csrf",t="x-csrf-token"){let[r,c]=useState(null);useEffect(()=>{c(z(e));},[e]);let f=r?{[t]:r}:{};return {token:r,headers:f}}function de(){let[e,t]=useState({connected:false,address:null,chain:null,provider:null}),[r,c]=useState(null),f=useCallback(async(a="phantom")=>{c(null);try{let i=typeof window<"u"?window:null,p=a==="phantom"?i?.phantom?.solana||i?.solana:i?.solflare;if(!p)return c(`${a} wallet not found`),null;let d=(await p.connect()).publicKey.toString();return t({connected:!0,address:d,chain:"solana",provider:a}),d}catch(i){return c(i.message||"Failed to connect wallet"),null}},[]),m=useCallback(async()=>{c(null);try{let i=(typeof window<"u"?window:null)?.ethereum;if(!i)return c("MetaMask not found"),null;let p=i;i.providers?.length&&(p=i.providers.find(n=>n.isMetaMask)||i);let d=(await p.request({method:"eth_requestAccounts"}))[0];return d?(t({connected:!0,address:d,chain:"ethereum",provider:"metamask"}),d):(c("No account selected"),null)}catch(a){return c(a.message||"Failed to connect wallet"),null}},[]),g=useCallback(async(a,i)=>{c(null);let p=i?.chain||e.chain,s=i?.provider||e.provider,d=i?.address||e.address;try{if(p==="solana"){let n=typeof window<"u"?window:null,u=s==="solflare"?n?.solflare:n?.phantom?.solana||n?.solana;if(!u)throw new Error("Wallet not available");let l=new TextEncoder().encode(a),y=await u.signMessage(l,"utf8"),b=new Uint8Array(y.signature||y),k="";for(let M=0;M<b.byteLength;M++)k+=String.fromCharCode(b[M]);return btoa(k)}if(p==="ethereum"){let u=(typeof window<"u"?window:null)?.ethereum;if(u?.providers?.length&&(u=u.providers.find(y=>y.isMetaMask)||u),!u)throw new Error("MetaMask not available");return await u.request({method:"personal_sign",params:[a,d]})}throw new Error("No wallet connected")}catch(n){return c(n.message||"Signing failed"),null}},[e]),o=useCallback(()=>{t({connected:false,address:null,chain:null,provider:null}),c(null);},[]);return {wallet:e,error:r,connectSolana:f,connectEVM:m,signMessage:g,disconnect:o}}var at="https://stacknet.magma-rpc.com/auth/bridge",ee="stacknet-auth-bridge";function fe(e){let t=e?.bridgeUrl||at,r=e?.disabled||false,c=useRef(null),[f,m]=useState({ready:false,known:false,identity:null,identityCount:0,resolvedStackId:null}),g=useRef([]),o=useRef(false),a=useCallback(n=>{let u={...n,protocol:ee};o.current&&c.current?.contentWindow?c.current.contentWindow.postMessage(u,new URL(t).origin):g.current.push(u);},[t]);useEffect(()=>{if(r)return;let n=l=>{if(!(!l.data||l.data.protocol!==ee)){try{if(l.origin!==new URL(t).origin)return}catch{return}switch(l.data.type){case "bridge:ready":o.current=true,m(y=>({...y,ready:true}));for(let y of g.current)c.current?.contentWindow?.postMessage(y,l.origin);g.current=[],c.current?.contentWindow?.postMessage({protocol:ee,type:"auth:check"},l.origin),c.current?.contentWindow?.postMessage({protocol:ee,type:"auth:resolve-stack"},l.origin);break;case "auth:status":m(y=>({...y,known:l.data.known,identity:l.data.identity,identityCount:l.data.identityCount||0}));break;case "auth:resolved-stack":m(y=>({...y,resolvedStackId:l.data.stackId||null}));break;}}};window.addEventListener("message",n);let u=document.createElement("iframe");return u.src=t,u.style.display="none",u.setAttribute("aria-hidden","true"),u.setAttribute("tabindex","-1"),u.setAttribute("sandbox","allow-scripts allow-same-origin"),document.body.appendChild(u),c.current=u,()=>{window.removeEventListener("message",n),u.parentNode&&u.parentNode.removeChild(u),c.current=null,o.current=false;}},[t,r]);let i=useCallback(n=>{a({type:"auth:connected",...n});},[a]),p=useCallback(n=>{a({type:"auth:disconnected",...n});},[a]),s=useCallback(()=>{a({type:"auth:clear"}),m({ready:f.ready,known:false,identity:null,identityCount:0,resolvedStackId:null});},[a,f.ready]),d=useCallback(()=>{a({type:"auth:check"});},[a]);return {...f,reportConnected:i,reportDisconnected:p,clearAll:s,refresh:d}}async function Oe(e,t,r,c){let f=e.apiVersion||"v2",m=`${e.baseUrl}/api/${f}${r}`;try{let g=await fetch(m,{method:t,headers:{"Content-Type":"application/json"},body:c?JSON.stringify(c):void 0}),o=await g.json();return g.ok?o.success&&o.data!==void 0?{success:!0,data:o.data}:{success:!0,data:o}:{success:!1,error:o.error||{code:"UNKNOWN_ERROR",message:"Unknown error"}}}catch(g){return {success:false,error:{code:"NETWORK_ERROR",message:g instanceof Error?g.message:"Network error"}}}}function ge(e){return {getNetworkStatus:()=>Oe(e,"GET","/network/status"),getWeb3Challenge:(t,r)=>Oe(e,"POST",`/stacks/${e.stackId}/auth/web3/challenge`,{chain:t,address:r})}}function he(e={apiBaseUrl:""}){let{wallet:t,connectSolana:r,connectEVM:c,signMessage:f,disconnect:m}=de(),{session:g,isAuthenticated:o,refresh:a,readSession:i}=ce(),{headers:p}=ue(),s=fe({disabled:typeof window>"u"}),[d,n]=useState(false),[u,l]=useState(null),[y,b]=useState(false),k=e.apiBaseUrl||"",M=e.stacknetUrl||"https://stacknet.magma-rpc.com",v=e.stackId||s.resolvedStackId||"",S=ge({baseUrl:M,stackId:v}),L=useCallback(async(C,N,H,W)=>{n(true),l(null);try{let j=N;if(!j){let F=await H();if(!F)return n(!1),!1;j=F;}let _=await S.getWeb3Challenge(C,j);if(!_.success||!_.data)return l("Failed to get challenge"),n(!1),!1;let q=await f(_.data.message,{chain:C,provider:W,address:j});if(!q)return n(!1),!1;let Q={chain:C,message:_.data.message,signature:q,stackId:v};C==="solana"&&(Q.publicKey=j);let $=await fetch(`${k}/api/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)});if(!$.ok){let F=await $.json().catch(()=>({}));return l(F.error||"Authentication failed"),n(!1),!1}return s.reportConnected({address:j,chain:C,method:W||(C==="solana"?"phantom":"metamask"),stackId:v}),i(),n(!1),!0}catch(j){return l(j.message||"Authentication failed"),n(false),false}},[k,S,f,i,s,v]),T=useCallback(async(C="phantom")=>{let N=await r(C);return N?L("solana",N,()=>r(C),C):false},[r,L]),A=useCallback(async()=>{let C=await c();return C?L("ethereum",C,c,"metamask"):false},[c,L]),U=useCallback(async C=>{n(true),l(null);try{let N=await fetch(`${k}/api/auth/otp`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({code:C})});if(!N.ok){let H=await N.json().catch(()=>({}));return l(H.error||"Invalid code"),n(!1),!1}return i(),n(!1),!0}catch(N){return l(N.message||"OTP verification failed"),n(false),false}},[k,i]),O=useCallback(async()=>{t.address&&t.chain&&s.reportDisconnected({address:t.address,chain:t.chain,stackId:v});try{await fetch(`${k}/api/auth/logout`,{method:"POST",headers:p});}catch{}m(),i();},[k,p,m,i,t,s,v]);return useEffect(()=>{if(!e.autoConnect||y||o||!s.ready||!s.known||!s.identity)return;b(true);let{chain:C,method:N}=s.identity;C==="solana"&&(N==="phantom"||N==="solflare")?T(N):C==="ethereum"&&A();},[e.autoConnect,y,o,s,T,A]),{session:g,isAuthenticated:o,wallet:t,loading:d,error:u,authenticateSolana:T,authenticateEVM:A,authenticateOTP:U,logout:O,refresh:()=>a(k),stackId:v,bridge:{ready:s.ready,known:s.known,identity:s.identity,identityCount:s.identityCount,resolvedStackId:s.resolvedStackId}}}function ke(e,t="https://stacknet.magma-rpc.com"){let[r,c]=useState(null),[f,m]=useState(false),[g,o]=useState(null),a=useCallback(async p=>{m(true),o(null);try{let s=await fetch(`${t}/api/v2/stacks/${p}`);if(!s.ok)return o("Stack not found"),m(!1),null;let d=await s.json(),n=d.data?.stack||d.stack||d,u={id:n.id,name:n.name,displayName:n.displayName||n.name,description:n.description,logoUrl:n.logoUrl,webPageUrl:n.webPageUrl,allowedChains:n.allowedChains||[],features:n.features,stripeProvider:n.stripeProvider,oauthProviders:n.oauthProviders?.map(l=>({provider:l.provider,enabled:l.enabled!==!1}))};return c(u),m(!1),u}catch(s){return o(s.message),m(false),null}},[t]);useEffect(()=>{e&&a(e);},[e,a]);let i=r?ut(r):[];return {config:r,loading:f,error:g,identityProviders:i,fetchConfig:a}}function ut(e){let t=[];if(e.features?.web3Auth!==false&&(e.allowedChains.includes("solana")&&(t.push({type:"wallet",id:"phantom",name:"Phantom",chain:"solana"}),t.push({type:"wallet",id:"solflare",name:"Solflare",chain:"solana"})),(e.allowedChains.includes("ethereum")||e.allowedChains.includes("polygon")||e.allowedChains.includes("base"))&&t.push({type:"wallet",id:"metamask",name:"MetaMask",chain:"ethereum"})),e.features?.apiKeyAuth!==false&&t.push({type:"otp",id:"otp",name:"Access Code"}),e.features?.oauthAuth&&e.oauthProviders)for(let r of e.oauthProviders)r.enabled&&t.push({type:"oauth",id:r.provider,name:r.provider});return t}function ft(e=""){let[t,r]=useState([]),[c,f]=useState(true),[m,g]=useState(null),o=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/plans`);if(a.ok){let i=await a.json();r(i.plans||i||[]);}}catch(a){g(a.message);}finally{f(false);}},[e]);return useEffect(()=>{o();},[o]),{plans:t,loading:c,error:m,refresh:o}}function mt(e=""){let[t,r]=useState(null),[c,f]=useState(true),[m,g]=useState(null),o=useCallback(async()=>{try{let p=await fetch(`${e}/api/billing/subscription`);if(p.ok){let s=await p.json();r(s.plan?s:null);}}catch(p){g(p.message);}finally{f(false);}},[e]);useEffect(()=>{o();},[o]);let a=useCallback(async p=>{let s=z(),n=await(await fetch(`${e}/api/billing/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",...s?{"x-csrf-token":s}:{}},body:JSON.stringify({planId:p})})).json();return n.url||n.checkoutUrl||null},[e]),i=useCallback(async()=>{let p=z();return (await fetch(`${e}/api/billing/cancel`,{method:"POST",headers:p?{"x-csrf-token":p}:{}})).ok?(await o(),true):false},[e,o]);return {subscription:t,loading:c,error:m,refresh:o,subscribe:a,cancel:i}}function kt(e=""){let[t,r]=useState(null),[c,f]=useState(true),[m,g]=useState(null),o=useCallback(async()=>{try{let a=await fetch(`${e}/api/billing/usage`);if(a.ok){let i=await a.json();r(i);}}catch(a){g(a.message);}finally{f(false);}},[e]);return useEffect(()=>{o();},[o]),{usage:t,loading:c,error:m,refresh:o}}function bt(e=""){let[t,r]=useState(false),[c,f]=useState(null),m=useCallback(async o=>{r(true),f(null);try{let a=z(),i=await fetch(`${e}/api/billing/prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({amountCents:o})}),p=await i.json();return i.ok?p.url||null:(f(p.error||"Purchase failed"),null)}catch(a){return f(a.message),null}finally{r(false);}},[e]),g=useCallback(async o=>{r(true),f(null);try{let a=z(),i=await fetch(`${e}/api/billing/verify-prepaid`,{method:"POST",headers:{"Content-Type":"application/json",...a?{"x-csrf-token":a}:{}},body:JSON.stringify({sessionId:o})}),p=await i.json();return i.ok?p:(f(p.error||"Verification failed"),null)}catch(a){return f(a.message),null}finally{r(false);}},[e]);return {purchase:m,verifySession:g,loading:t,error:c}}function Ct(e="",t){let[r,c]=useState([]),[f,m]=useState(true),[g,o]=useState(null),a=t?.limit||50,i=t?.offset||0,p=useCallback(async()=>{try{let s=await fetch(`${e}/api/billing/history?limit=${a}&offset=${i}`);if(s.ok){let d=await s.json();c(d.records||d.history||(Array.isArray(d)?d:[]));}}catch(s){o(s.message);}finally{m(false);}},[e,a,i]);return useEffect(()=>{p();},[p]),{records:r,loading:f,error:g,refresh:p}}function Nt(){if(typeof document>"u")return null;let e=document.cookie.split(";").map(t=>t.trim()).find(t=>t.startsWith("__csrf="));return e?e.slice(7):null}function Se(e,t){let[r,c]=useState(null),[f,m]=useState(true),[g,o]=useState(false),[a,i]=useState(null),p=t?.apiBaseUrl??"",s=t?.scope??"global",d=useCallback(l=>s==="global"?`${p}/api/user/profile/${l}`:`${p}/api/v2/stacks/${s.stackId}/members/${l}/profile`,[p,s]),n=useCallback(async()=>{if(!e){c(null),m(false);return}m(true),i(null);try{let l=await fetch(d(e));if(l.ok){let y=await l.json(),b=y.profile||y.data?.profile||y;c({mid:b.mid||e,username:b.username||"",avatarUrl:b.avatar_url||b.avatarUrl,bio:b.bio,createdAt:b.created_at||b.createdAt,updatedAt:b.updated_at||b.updatedAt});}else if(l.status===404)c({mid:e,username:""});else throw new Error(`${l.status}`)}catch(l){i(l instanceof Error?l.message:"Failed to load profile");}finally{m(false);}},[e,d]);useEffect(()=>{n();},[n]);let u=useCallback(async l=>{if(!e)return false;o(true),i(null);try{let y=Nt(),b=await fetch(d(e),{method:"PUT",headers:{"Content-Type":"application/json",...y?{"x-csrf-token":y}:{}},credentials:"same-origin",body:JSON.stringify({username:l.username,avatar_url:l.avatarUrl,bio:l.bio})});if(!b.ok){let v=await b.json().catch(()=>({}));throw new Error(v.error||v.message||`Update failed: ${b.status}`)}let k=await b.json(),M=k.profile||k.data?.profile||k;return c(v=>({mid:v?.mid||e,username:l.username??v?.username??"",avatarUrl:l.avatarUrl??v?.avatarUrl,bio:l.bio??v?.bio,createdAt:v?.createdAt,updatedAt:M.updated_at||M.updatedAt||Date.now()})),!0}catch(y){return i(y instanceof Error?y.message:"Update failed"),false}finally{o(false);}},[e,d]);return {profile:r,loading:f,saving:g,error:a,updateProfile:u,refresh:n}}var _e=createContext(null);function It(){let e=useContext(_e);if(!e)throw new Error("useUserUtilsContext must be used within <UserUtilsProvider>");return e}function Lt({config:e,callbacks:t,children:r}){return jsx(_e.Provider,{value:{config:e,callbacks:t},children:r})}function ne({length:e=6,onComplete:t,disabled:r=false,error:c,className:f="",inputClassName:m=""}){let [g,o]=useState(Array(e).fill("")),a=useCallback((s,d)=>{if(d.length>1){let u=d.replace(/\D/g,"").slice(0,e).split(""),l=[...g];u.forEach((b,k)=>{s+k<e&&(l[s+k]=b);}),o(l);let y=Math.min(s+u.length,e-1);document.getElementById(`userutils-otp-${y}`)?.focus(),l.every(b=>b!=="")&&setTimeout(()=>t(l.join("")),100);return}if(!/^\d?$/.test(d))return;let n=[...g];n[s]=d,o(n),d&&s<e-1&&document.getElementById(`userutils-otp-${s+1}`)?.focus(),d&&s===e-1&&n.every(u=>u!=="")&&setTimeout(()=>t(n.join("")),100);},[g,e,t]),i=useCallback((s,d)=>{if(d.key==="Backspace"&&!g[s]&&s>0){document.getElementById(`userutils-otp-${s-1}`)?.focus();let n=[...g];n[s-1]="",o(n);}if(d.key==="Enter"){let n=g.join("");n.length===e&&t(n);}},[g,e,t]);useCallback(()=>{o(Array(e).fill("")),document.getElementById("userutils-otp-0")?.focus();},[e]);return jsxs("div",{className:f,children:[jsx("div",{className:"flex gap-2 justify-center",children:g.map((s,d)=>jsx("input",{id:`userutils-otp-${d}`,type:"text",inputMode:"numeric",maxLength:e,value:s,onChange:n=>a(d,n.target.value),onKeyDown:n=>i(d,n),disabled:r,autoFocus:d===0,className:`w-12 h-14 text-center text-xl font-mono bg-secondary border border-primary/10 text-foreground focus:outline-none focus:border-primary/30 disabled:opacity-50 ${m}`},d))}),c&&jsx("p",{className:"text-center text-sm text-red-400 mt-2",children:c})]})}ne.displayName="OTPInput";var At="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTA4IiBoZWlnaHQ9IjEwOCIgdmlld0JveD0iMCAwIDEwOCAxMDgiIGZpbGw9Im5vbmUiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CjxyZWN0IHdpZHRoPSIxMDgiIGhlaWdodD0iMTA4IiByeD0iMjYiIGZpbGw9IiNBQjlGRjIiLz4KPHBhdGggZmlsbC1ydWxlPSJldmVub2RkIiBjbGlwLXJ1bGU9ImV2ZW5vZGQiIGQ9Ik00Ni41MjY3IDY5LjkyMjlDNDIuMDA1NCA3Ni44NTA5IDM0LjQyOTIgODUuNjE4MiAyNC4zNDggODUuNjE4MkMxOS41ODI0IDg1LjYxODIgMTUgODMuNjU2MyAxNSA3NS4xMzQyQzE1IDUzLjQzMDUgNDQuNjMyNiAxOS44MzI3IDcyLjEyNjggMTkuODMyN0M4Ny43NjggMTkuODMyNyA5NCAzMC42ODQ2IDk0IDQzLjAwNzlDOTQgNTguODI1OCA4My43MzU1IDc2LjkxMjIgNzMuNTMyMSA3Ni45MTIyQzcwLjI5MzkgNzYuOTEyMiA2OC43MDUzIDc1LjEzNDIgNjguNzA1MyA3Mi4zMTRDNjguNzA1MyA3MS41NzgzIDY4LjgyNzUgNzAuNzgxMiA2OS4wNzE5IDY5LjkyMjlDNjUuNTg5MyA3NS44Njk5IDU4Ljg2ODUgODEuMzg3OCA1Mi41NzU0IDgxLjM4NzhDNDcuOTkzIDgxLjM4NzggNDUuNjcxMyA3OC41MDYzIDQ1LjY3MTMgNzQuNDU5OEM0NS42NzEzIDcyLjk4ODQgNDUuOTc2OCA3MS40NTU2IDQ2LjUyNjcgNjkuOTIyOVpNODMuNjc2MSA0Mi41Nzk0QzgzLjY3NjEgNDYuMTcwNCA4MS41NTc1IDQ3Ljk2NTggNzkuMTg3NSA0Ny45NjU4Qzc2Ljc4MTYgNDcuOTY1OCA3NC42OTg5IDQ2LjE3MDQgNzQuNjk4OSA0Mi41Nzk0Qzc0LjY5ODkgMzguOTg4NSA3Ni43ODE2IDM3LjE5MzEgNzkuMTg3NSAzNy4xOTMxQzgxLjU1NzUgMzcuMTkzMSA4My42NzYxIDM4Ljk4ODUgODMuNjc2MSA0Mi41Nzk0Wk03MC4yMTAzIDQyLjU3OTVDNzAuMjEwMyA0Ni4xNzA0IDY4LjA5MTYgNDcuOTY1OCA2NS43MjE2IDQ3Ljk2NThDNjMuMzE1NyA0Ny45NjU4IDYxLjIzMyA0Ni4xNzA0IDYxLjIzMyA0Mi41Nzk1QzYxLjIzMyAzOC45ODg1IDYzLjMxNTcgMzcuMTkzMSA2NS43MjE2IDM3LjE5MzFDNjguMDkxNiAzNy4xOTMxIDcwLjIxMDMgMzguOTg4NSA3MC4yMTAzIDQyLjU3OTVaIiBmaWxsPSIjRkZGREY4Ii8+Cjwvc3ZnPgo=";function re({className:e}){return jsx("img",{src:At,alt:"Phantom",className:e})}function oe({className:e}){return jsxs("svg",{className:e,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 507.83 470.86",children:[jsx("polygon",{fill:"#e2761b",stroke:"#e2761b",strokeLinecap:"round",strokeLinejoin:"round",points:"482.09 0.5 284.32 147.38 320.9 60.72 482.09 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"25.54 0.5 221.72 148.77 186.93 60.72 25.54 0.5"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"410.93 340.97 358.26 421.67 470.96 452.67 503.36 342.76 410.93 340.97"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"4.67 342.76 36.87 452.67 149.57 421.67 96.9 340.97 4.67 342.76"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 111.8 252.13 223.7 257.1 219.73 136.85 143.21 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"364.42 204.62 286.91 135.46 284.32 257.1 396.03 252.13 364.42 204.62"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 216.75 388.87 158.71 343.55 149.57 421.67"}),jsx("polygon",{fill:"#e4761b",stroke:"#e4761b",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 358.26 421.67 348.92 343.55 290.88 388.87"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"358.26 421.67 290.88 388.87 296.25 432.8 295.65 451.28 358.26 421.67"}),jsx("polygon",{fill:"#d7c1b3",stroke:"#d7c1b3",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 212.18 451.28 211.78 432.8 216.75 388.87 149.57 421.67"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"213.17 314.54 157.12 298.04 196.67 279.95 213.17 314.54"}),jsx("polygon",{fill:"#233447",stroke:"#233447",strokeLinecap:"round",strokeLinejoin:"round",points:"294.46 314.54 310.96 279.95 350.71 298.04 294.46 314.54"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"149.57 421.67 159.11 340.97 96.9 342.76 149.57 421.67"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"348.72 340.97 358.26 421.67 410.93 342.76 348.72 340.97"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"396.03 252.13 284.32 257.1 294.66 314.54 311.16 279.95 350.91 298.04 396.03 252.13"}),jsx("polygon",{fill:"#cd6116",stroke:"#cd6116",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 196.87 279.95 213.17 314.54 223.7 257.1 111.8 252.13 157.12 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"111.8 252.13 158.71 343.55 157.12 298.04 111.8 252.13"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"350.91 298.04 348.92 343.55 396.03 252.13 350.91 298.04"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"223.7 257.1 213.17 314.54 226.29 382.31 229.27 293.07 223.7 257.1"}),jsx("polygon",{fill:"#e4751f",stroke:"#e4751f",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 278.96 292.87 281.34 382.31 294.66 314.54 284.32 257.1"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"294.66 314.54 281.34 382.31 290.88 388.87 348.92 343.55 350.91 298.04 294.66 314.54"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"157.12 298.04 158.71 343.55 216.75 388.87 226.29 382.31 213.17 314.54 157.12 298.04"}),jsx("polygon",{fill:"#c0ad9e",stroke:"#c0ad9e",strokeLinecap:"round",strokeLinejoin:"round",points:"295.65 451.28 296.25 432.8 291.28 428.42 216.35 428.42 211.78 432.8 212.18 451.28 149.57 421.67 171.43 439.55 215.75 470.36 291.88 470.36 336.4 439.55 358.26 421.67 295.65 451.28"}),jsx("polygon",{fill:"#161616",stroke:"#161616",strokeLinecap:"round",strokeLinejoin:"round",points:"290.88 388.87 281.34 382.31 226.29 382.31 216.75 388.87 211.78 432.8 216.35 428.42 291.28 428.42 296.25 432.8 290.88 388.87"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"490.44 156.92 507.33 75.83 482.09 0.5 290.88 142.41 364.42 204.62 468.37 235.03 491.43 208.2 481.49 201.05 497.39 186.54 485.07 177 500.97 164.87 490.44 156.92"}),jsx("polygon",{fill:"#763d16",stroke:"#763d16",strokeLinecap:"round",strokeLinejoin:"round",points:"0.5 75.83 17.39 156.92 6.66 164.87 22.56 177 10.44 186.54 26.34 201.05 16.4 208.2 39.26 235.03 143.21 204.62 216.75 142.41 25.54 0.5 0.5 75.83"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"468.37 235.03 364.42 204.62 396.03 252.13 348.92 343.55 410.93 342.76 503.36 342.76 468.37 235.03"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"143.21 204.62 39.26 235.03 4.67 342.76 96.9 342.76 158.71 343.55 111.8 252.13 143.21 204.62"}),jsx("polygon",{fill:"#f6851b",stroke:"#f6851b",strokeLinecap:"round",strokeLinejoin:"round",points:"284.32 257.1 290.88 142.41 321.1 60.72 186.93 60.72 216.75 142.41 223.7 257.1 226.09 293.27 226.29 382.31 281.34 382.31 281.74 293.27 284.32 257.1"})]})}function Le({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",className:e||"h-5 w-5",children:[jsxs("linearGradient",{id:"sol-g",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",gradientUnits:"userSpaceOnUse",children:[jsx("stop",{offset:"0",stopColor:"#9945ff"}),jsx("stop",{offset:"0.2",stopColor:"#7962e7"}),jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),jsx("path",{fill:"#10111a",d:"M0 0h32v32H0z"}),jsx("path",{fill:"url(#sol-g)",fillRule:"evenodd",d:"M9.873 20.41a.65.65 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54zm15.376-2.862a.322.322 0 0 1-.238.54l-14.662.012a.64.64 0 0 1-.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.64.64 0 0 1 .475.21zM9.873 7.81a.64.64 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.64.64 0 0 1-.475.21l-14.662-.012a.323.323 0 0 1-.238-.54z",clipRule:"evenodd"})]})}function Ue({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",className:e||"h-5 w-5",children:[jsx("rect",{width:"20",height:"20",rx:"4",fill:"#627EEA",fillOpacity:"0.2"}),jsx("path",{fill:"#627EEA",d:"M10 3l-4 6.5 4 2.5 4-2.5L10 3z"}),jsx("path",{fill:"#627EEA",fillOpacity:"0.6",d:"M6 9.5L10 12l4-2.5L10 17 6 9.5z"})]})}function Et({config:e,onSuccess:t,title:r="Log in or Sign up",showWallets:c,showOTP:f,className:m=""}){let g=he(e),{isAuthenticated:o,wallet:a,loading:i,error:p,authenticateSolana:s,authenticateEVM:d,authenticateOTP:n,bridge:u,stackId:l}=g,y=!e.stackId&&!l,b=e.stacknetUrl||"https://stacknet.magma-rpc.com",{config:k,identityProviders:M,loading:v}=ke(l||e.stackId||null,b),[S,L]=useState(y?"stack-select":"select"),[T,A]=useState(null),[U,O]=useState(false),[C,N]=useState("idle"),[H,W]=useState(""),[j,_]=useState([]),[q,Q]=useState(e.stackId||null),[$,F]=useState(false),[He,Qe]=useState(false);useEffect(()=>{if(typeof window>"u")return;let x=()=>{let B=window;F(!!(B.phantom?.solana?.isPhantom||B.solana?.isPhantom));let V=B.ethereum;Qe(!!(V?.isMetaMask||V?.providers?.some(Y=>Y.isMetaMask)));};x(),window.addEventListener("ethereum#initialized",x);let R=setTimeout(x,500);return ()=>{window.removeEventListener("ethereum#initialized",x),clearTimeout(R);}},[]),useEffect(()=>{S==="stack-select"&&l&&(Q(l),L("select"));},[S,l]),useEffect(()=>{if(!(!u.ready||!y)&&u.identity){let x=[];u.resolvedStackId&&x.push({stackId:u.resolvedStackId,domain:typeof window<"u"?window.location.origin:""}),Promise.all(x.map(async R=>{try{let B=await fetch(`${b}/api/v2/stacks/${R.stackId}`);if(B.ok){let V=await B.json(),Y=V.data?.stack||V;R.name=Y.displayName||Y.name,R.logoUrl=Y.logoUrl;}}catch{}return R})).then(_);}},[u.ready,u.identity,u.resolvedStackId,y,b]),useEffect(()=>{o&&S==="success"&&t?.();},[o,S,t]);let je=c||(M.length>0?M.filter(x=>x.type==="wallet").map(x=>x.id):["phantom","metamask"]),Ae=f!==void 0?f:M.length>0?M.some(x=>x.type==="otp"):true,Ve=async()=>{A("phantom"),L("connecting");let x=await s("phantom");L(x?"success":"error");},Ye=async()=>{A("metamask"),L("connecting");let x=await d();L(x?"success":"error");},Ge=async x=>{N("verifying"),W(""),await n(x)?(N("success"),L("success")):(N("error"),W("Invalid or expired code"),setTimeout(()=>N("idle"),2e3));},ze=()=>{L(y&&!q?"stack-select":"select"),A(null),O(false),N("idle"),W("");};return jsxs("div",{className:`w-full max-w-md space-y-3 ${m}`,children:[jsxs("div",{className:"mb-6 text-center",children:[k?.logoUrl&&S!=="stack-select"&&jsx("img",{src:k.logoUrl,alt:"",className:"h-10 w-10 mx-auto mb-3"}),jsx("h1",{className:"font-semibold text-2xl text-white",children:r}),k?.displayName&&S!=="stack-select"&&jsx("p",{className:"text-sm text-zinc-400 mt-1",children:k.displayName})]}),S==="stack-select"&&jsxs("div",{className:"space-y-3",children:[jsx("p",{className:"text-center text-sm text-zinc-400 mb-4",children:j.length>0?"Select a network to continue":"No previous connections found. Enter a Stack ID to continue."}),j.map(x=>jsxs("button",{onClick:()=>{Q(x.stackId),L("select");},className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[x.logoUrl?jsx("img",{src:x.logoUrl,alt:"",className:"h-10 w-10 flex-shrink-0"}):jsx("div",{className:"h-10 w-10 flex-shrink-0 bg-zinc-700 flex items-center justify-center text-zinc-400 text-sm font-mono",children:x.name?.[0]?.toUpperCase()||"S"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-white",children:x.name||x.stackId}),jsx("p",{className:"text-xs text-zinc-500",children:x.domain})]}),jsx("span",{className:"text-xs text-zinc-600",children:"Previously connected"})]},x.stackId)),u.ready&&!u.known&&jsx("p",{className:"text-center text-xs text-zinc-600 mt-4",children:"Connect to a stack for the first time to get started."})]}),S==="select"&&v&&jsx("div",{className:"flex items-center justify-center py-8",children:jsx("div",{className:"h-6 w-6 border-2 border-zinc-600 border-t-white animate-spin",style:{borderRadius:"50%"}})}),p&&S==="error"&&jsxs("div",{className:"mb-4 border border-red-500/30 bg-red-500/10 p-4",children:[jsx("p",{className:"text-center text-red-400 text-sm",children:p}),jsx("button",{className:"mt-3 w-full text-sm text-zinc-400 hover:text-white",onClick:ze,children:"Try Again"})]}),S==="success"&&jsxs("div",{className:"border border-green-500/30 bg-green-500/10 p-6 text-center",children:[jsx("p",{className:"font-medium text-green-400 text-sm",children:"Connected!"}),jsx("p",{className:"mt-1 text-xs text-zinc-400",children:"Redirecting..."})]}),S==="connecting"&&i&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 text-center",children:[jsxs("div",{className:"mx-auto mb-3 h-14 w-14 animate-pulse",children:[T==="phantom"&&jsx(re,{className:"h-14 w-14"}),T==="metamask"&&jsx(oe,{className:"h-14 w-14"})]}),jsx("p",{className:"font-medium text-sm text-white",children:a.connected?"Signing message...":"Connecting wallet..."}),jsx("p",{className:"mt-1 text-xs text-zinc-500",children:"Please confirm in your wallet"}),jsx("button",{className:"mt-4 text-sm text-zinc-500 hover:text-white",onClick:ze,children:"Cancel"})]}),S==="select"&&!i&&!v&&jsxs(Fragment,{children:[je.includes("phantom")&&jsxs("button",{onClick:Ve,disabled:!$,className:`flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a] ${$?"":"cursor-not-allowed opacity-50"}`,children:[jsx(re,{className:"h-14 w-14 flex-shrink-0"}),jsxs("div",{className:"flex-1 text-left",children:[jsx("span",{className:"font-medium text-lg text-white",children:"Phantom"}),!$&&jsx("p",{className:"text-xs text-zinc-500",children:"Not installed"})]}),jsx(Le,{className:"h-8 w-8"})]}),je.includes("metamask")&&He&&jsxs("button",{onClick:Ye,className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center bg-white p-2",children:jsx(oe,{className:"h-10 w-10"})}),jsx("div",{className:"flex-1 text-left",children:jsx("span",{className:"font-medium text-lg text-white",children:"MetaMask"})}),jsx(Ue,{className:"h-8 w-8"})]}),Ae&&!U&&jsxs("button",{onClick:()=>O(true),className:"flex w-full items-center gap-4 border border-zinc-800 bg-[#25252f] p-4 transition-colors hover:bg-[#2d2d3a]",children:[jsx("div",{className:"flex h-14 w-14 flex-shrink-0 items-center justify-center border border-zinc-700 bg-[#2a2a3e]",children:jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"28px",viewBox:"0 -960 960 960",width:"28px",fill:"#e3e3e3",children:jsx("path",{d:"M160-160q-33 0-56.5-23.5T80-240v-480q0-33 23.5-56.5T160-800h640q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160Z"})})}),jsx("div",{className:"flex-1 text-left",children:jsx("span",{className:"font-medium text-lg text-white",children:"Access Code"})})]}),Ae&&U&&jsxs("div",{className:"border border-zinc-800 bg-[#25252f] p-6 space-y-4",children:[jsx("p",{className:"text-center text-sm text-zinc-400",children:"Enter your 6-digit access code"}),jsx(ne,{onComplete:Ge,disabled:C==="verifying",error:H}),C==="verifying"&&jsx("p",{className:"text-center text-sm text-zinc-400 animate-pulse",children:"Verifying..."}),C==="success"&&jsx("p",{className:"text-center text-sm text-green-400",children:"Verified!"}),k?.webPageUrl&&C==="idle"&&jsx("a",{href:`${k.webPageUrl}/connect/pair`,target:"_blank",rel:"noopener noreferrer",className:"block text-center text-sm text-zinc-500 hover:text-white transition-colors",children:"Get code"})]})]})]})}function _t({mid:e,apiBaseUrl:t="",scope:r,onSave:c,className:f}){let{profile:m,loading:g,saving:o,error:a,updateProfile:i}=Se(e,{apiBaseUrl:t,scope:r}),[p,s]=useState(null),[d,n]=useState(null),[u,l]=useState(null),y=useRef(null),[b,k]=useState(false),M=p??m?.username??"",v=d??m?.bio??"",S=u??m?.avatarUrl,L=useCallback(U=>{let O=U.target.files?.[0];if(!O)return;let C=new FileReader;C.onload=()=>{l(C.result),k(true);},C.readAsDataURL(O);},[]),T=async()=>{await i({username:M||void 0,avatarUrl:u??m?.avatarUrl,bio:v||void 0})&&(k(false),c?.());};if(g)return jsxs("div",{className:f,style:{display:"grid",gap:"1.5rem"},children:[jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}}),jsx("div",{style:{height:40,background:"var(--x-color-neutral-800, #333)",animation:"pulse 2s infinite"}})]});let A=r==="global"||!r?"Global profile":`Stack profile (${r.stackId})`;return jsxs("div",{className:f,style:{display:"grid",gap:"1.5rem"},children:[jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #91918D)",textTransform:"uppercase",letterSpacing:"0.05em"},children:A}),jsxs("div",{style:{display:"grid",gap:"1.5rem",gridTemplateColumns:"1fr 1fr"},children:[jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Username"}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem"},children:[jsx("button",{type:"button",onClick:()=>y.current?.click(),style:{width:40,height:40,flexShrink:0,cursor:"pointer",overflow:"hidden",background:"var(--x-color-neutral-800, #262625)",border:"none",position:"relative",display:"flex",alignItems:"center",justifyContent:"center"},children:S?jsx("img",{src:S,alt:"",style:{width:"100%",height:"100%",objectFit:"cover"}}):jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",style:{color:"var(--x-color-neutral-500, #91918D)"},children:[jsx("path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2"}),jsx("circle",{cx:"12",cy:"7",r:"4"})]})}),jsx("input",{type:"text",value:M,onChange:U=>{s(U.target.value),k(true);},placeholder:"Enter username",maxLength:30,style:{flex:1,padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]}),jsx("input",{ref:y,type:"file",accept:"image/*",onChange:L,style:{display:"none"}})]}),jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[jsx("label",{style:{fontSize:14,color:"var(--x-color-neutral-400, #91918D)"},children:"Bio"}),jsx("input",{type:"text",value:v,onChange:U=>{n(U.target.value),k(true);},placeholder:"Tell us about yourself",maxLength:200,style:{width:"100%",padding:"0.75rem 1rem",fontSize:14,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-100, #FAFAF7)",border:"none",outline:"none"}})]})]}),a&&jsx("p",{style:{fontSize:13,color:"var(--x-color-red-500, #BF4D43)"},children:a}),b&&jsxs("div",{style:{display:"flex",gap:"0.5rem"},children:[jsx("button",{onClick:T,disabled:o,style:{padding:"0.5rem 1.25rem",fontSize:13,fontWeight:700,background:"var(--x-color-blue-600, #165DFC)",color:"#FFF",border:"none",cursor:o?"wait":"pointer",opacity:o?.6:1},children:o?"Saving...":"Save"}),jsx("button",{onClick:()=>{s(null),n(null),l(null),k(false);},style:{padding:"0.5rem 1.25rem",fontSize:13,background:"var(--x-color-neutral-800, #262625)",color:"var(--x-color-neutral-400, #91918D)",border:"none",cursor:"pointer"},children:"Cancel"}),jsx("p",{style:{fontSize:11,color:"var(--x-color-neutral-500, #666663)",alignSelf:"center",marginLeft:"0.5rem"},children:"Profile updates cost 100M tokens"})]})]})}function $t({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"black"}),jsx("path",{d:"M8.53901 8L14.7164 16.2153L8.5 22.8947H9.89907L15.3415 17.0468L19.7389 22.8947H24.5L17.975 14.2173L23.7612 8H22.3621L17.3499 13.3858L13.3001 8H8.53901ZM10.5964 9.02501H12.7837L22.4422 21.8695H20.255L10.5964 9.02501Z",fill:"#F7F7F7"})]})}function Bt({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#F1F2F9"}),jsx("path",{d:"M26.1001 16.2273C26.1001 15.5182 26.0365 14.8364 25.9183 14.1818H16.5001V18.05H21.8819C21.6501 19.3 20.9456 20.3591 19.8865 21.0682V23.5773H23.1183C25.0092 21.8364 26.1001 19.2727 26.1001 16.2273Z",fill:"#4285F4"}),jsx("path",{d:"M16.5001 26C19.2001 26 21.4637 25.1046 23.1182 23.5773L19.8864 21.0682C18.991 21.6682 17.8455 22.0227 16.5001 22.0227C13.8955 22.0227 11.691 20.2637 10.9046 17.9H7.56372V20.4909C9.20917 23.7591 12.591 26 16.5001 26Z",fill:"#34A853"}),jsx("path",{d:"M10.9047 17.8999C10.7047 17.2999 10.591 16.659 10.591 15.9999C10.591 15.3408 10.7047 14.6999 10.9047 14.0999V11.509H7.56376C6.86376 12.9025 6.49951 14.4405 6.50012 15.9999C6.50012 17.6136 6.88649 19.1408 7.56376 20.4908L10.9047 17.8999Z",fill:"#FBBC05"}),jsx("path",{d:"M16.5001 9.97726C17.9682 9.97726 19.2864 10.4818 20.3228 11.4727L23.191 8.60454C21.4591 6.99091 19.1955 6 16.5001 6C12.591 6 9.20917 8.2409 7.56372 11.5091L10.9046 14.1C11.691 11.7364 13.8955 9.97726 16.5001 9.97726Z",fill:"#EA4335"})]})}function Qt({className:e}){return jsxs("svg",{className:e||"h-8 w-8",viewBox:"0 0 33 32",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsx("rect",{x:"0.5",width:"32",height:"32",rx:"4",fill:"#5462EB"}),jsx("path",{d:"M23.5433 8.87438C22.2479 8.26174 20.8587 7.81038 19.4063 7.55187C19.3799 7.54688 19.3534 7.55934 19.3398 7.58428C19.1612 7.91179 18.9633 8.33905 18.8247 8.67487C17.2625 8.43382 15.7084 8.43382 14.1782 8.67487C14.0396 8.33158 13.8345 7.91179 13.6551 7.58428C13.6414 7.56018 13.615 7.54771 13.5886 7.55187C12.1369 7.80955 10.7478 8.26092 9.45159 8.87438C9.44037 8.87937 9.43075 8.88769 9.42437 8.89849C6.78947 12.9558 6.06766 16.9134 6.42176 20.8219C6.42336 20.841 6.43378 20.8593 6.4482 20.871C8.18663 22.1868 9.87059 22.9857 11.5233 23.5152C11.5497 23.5235 11.5778 23.5135 11.5946 23.491C11.9855 22.9408 12.334 22.3606 12.6328 21.7504C12.6505 21.7147 12.6336 21.6723 12.5976 21.6581C12.0448 21.442 11.5185 21.1785 11.0122 20.8793C10.9721 20.8552 10.9689 20.7961 11.0058 20.7679C11.1123 20.6856 11.2189 20.6 11.3206 20.5135C11.339 20.4977 11.3647 20.4944 11.3863 20.5044C14.7125 22.0696 18.3136 22.0696 21.6006 20.5044C21.6222 20.4936 21.6479 20.4969 21.6671 20.5127C21.7688 20.5991 21.8754 20.6856 21.9827 20.7679C22.0196 20.7961 22.0172 20.8552 21.9771 20.8793C21.4708 21.1843 20.9445 21.442 20.3909 21.6573C20.3548 21.6715 20.3388 21.7147 20.3564 21.7504C20.6617 22.3597 21.0101 22.9399 21.3939 23.4902C21.4099 23.5135 21.4387 23.5235 21.4652 23.5152C23.1259 22.9857 24.8099 22.1868 26.5483 20.871C26.5635 20.8593 26.5731 20.8419 26.5747 20.8228C26.9985 16.3041 25.8649 12.3789 23.5697 8.89931C23.5641 8.88769 23.5545 8.87937 23.5433 8.87438Z",fill:"#F7F7F7"})]})}function Yt({className:e}){return jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",className:e||"h-8 w-8",children:[jsx("rect",{width:"512",height:"512",rx:"15%",fill:"#37aee2"}),jsx("path",{fill:"#c8daea",d:"M199 404c-11 0-10-4-13-14l-32-105 245-144"}),jsx("path",{fill:"#a9c9dd",d:"M199 404c7 0 11-4 16-8l45-43-56-34"}),jsx("path",{fill:"#f6fbfe",d:"M204 319l135 99c14 9 26 4 30-14l55-258c5-22-9-32-24-25L79 245c-21 8-21 21-4 26l83 26 190-121c9-5 17-3 11 4"})]})}
|
|
2
|
+
export{Et as ConnectWidget,Qt as DiscordIcon,Ue as EthereumIcon,Bt as GoogleIcon,oe as MetaMaskIcon,ne as OTPInput,re as PhantomIcon,_t as ProfileSettings,Le as SolanaIcon,Yt as TelegramIcon,$t as TwitterIcon,Lt as UserUtilsProvider,Ke as cn,ge as createStackNetClient,et as decodeJwtPayloadClient,qe as formatTokens,z as readCSRFCookie,le as readSessionCookie,fe as useAuthBridge,Ct as useBillingHistory,ue as useCSRFToken,ft as usePlans,bt as usePrepaidCheckout,Se as useProfile,ce as useSession,he as useStackAuth,ke as useStackConfig,mt as useSubscription,kt as useUsage,It as useUserUtilsContext,de as useWeb3Wallet,Xe as validateRedirectUrl};
|
package/dist/server/index.d.cts
CHANGED
package/dist/server/index.d.ts
CHANGED
package/dist/types/index.d.cts
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
export { A as APIResponse, B as BillingPlan, a as BillingRecord, M as MPCNode, N as NetworkStatus, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig, W as Web3Chain } from '../
|
|
1
|
+
export { A as APIResponse, B as BillingPlan, a as BillingRecord, M as MPCNode, N as NetworkStatus, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig, W as Web3Chain } from '../config-BrziGArs.cjs';
|
|
2
|
+
|
|
3
|
+
/** User profile — global (network-wide) or stack-scoped */
|
|
4
|
+
interface UserProfile {
|
|
5
|
+
mid: string;
|
|
6
|
+
username: string;
|
|
7
|
+
avatarUrl?: string;
|
|
8
|
+
bio?: string;
|
|
9
|
+
createdAt?: number;
|
|
10
|
+
updatedAt?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Input for updating a profile */
|
|
13
|
+
interface ProfileUpdateInput {
|
|
14
|
+
username?: string;
|
|
15
|
+
avatarUrl?: string;
|
|
16
|
+
bio?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Scope for profile operations */
|
|
19
|
+
type ProfileScope = 'global' | {
|
|
20
|
+
stackId: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type { ProfileScope, ProfileUpdateInput, UserProfile };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
export { A as APIResponse, B as BillingPlan, a as BillingRecord, M as MPCNode, N as NetworkStatus, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig, W as Web3Chain } from '../
|
|
1
|
+
export { A as APIResponse, B as BillingPlan, a as BillingRecord, M as MPCNode, N as NetworkStatus, P as PrepaidCheckoutResult, b as PrepaidVerifyResult, c as PublicSession, S as Session, d as Subscription, U as UsageSummary, e as UserUtilsCallbacks, f as UserUtilsConfig, W as Web3Chain } from '../config-BrziGArs.js';
|
|
2
|
+
|
|
3
|
+
/** User profile — global (network-wide) or stack-scoped */
|
|
4
|
+
interface UserProfile {
|
|
5
|
+
mid: string;
|
|
6
|
+
username: string;
|
|
7
|
+
avatarUrl?: string;
|
|
8
|
+
bio?: string;
|
|
9
|
+
createdAt?: number;
|
|
10
|
+
updatedAt?: number;
|
|
11
|
+
}
|
|
12
|
+
/** Input for updating a profile */
|
|
13
|
+
interface ProfileUpdateInput {
|
|
14
|
+
username?: string;
|
|
15
|
+
avatarUrl?: string;
|
|
16
|
+
bio?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Scope for profile operations */
|
|
19
|
+
type ProfileScope = 'global' | {
|
|
20
|
+
stackId: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type { ProfileScope, ProfileUpdateInput, UserProfile };
|
package/package.json
CHANGED
|
File without changes
|
|
File without changes
|