superstack-wallet-sdk 0.4.7 → 0.4.8

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.
@@ -1,2 +1,2 @@
1
- import{useState as e,useMemo as n,createRef as i,useEffect as t}from"react";import{useWallet as o}from"./context.js";import{buildOAuthState as a,buildCodeVerifierAndChallenge as l,getGoogleOAuth2Link as r,getTwitterOAuth2Link as c}from"./utils/oauth.js";import{theme as d}from"./styles/theme.js";function s(){const{connect:e,disconnect:n,isConnecting:i}=o();return{connect:e,disconnect:n,isConnecting:i}}function h(){const{error:e,session:n,isInitialized:i,wallet:t}=o();return{isAuthenticated:null!==t,authenticated:null!==t,error:e,session:n,isInitialized:i,ready:i}}function f(){const{wallet:e}=o();return{wallet:e}}function u({client:o,isOpen:s,onClose:h,onLogin:f,isLoading:u=!1}){const[g,y]=e(""),[v,m]=e(""),[p,w]=e(!1),[C,P]=e(!1),[F,S]=e(["","","","","",""]),[E,V]=e(!1),[x,L]=e(!1),[D,_]=e(!1),j=n(()=>Array(6).fill(null).map(()=>i()),[]),A=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),I=e=>/^\+[1-9]\d{1,3}\d{6,14}$/.test(e);return t(()=>{F.forEach((e,n)=>{if(j[n]&&j[n].current){const i=j[n].current;i&&e&&(i.style.fontSize=d.typography.fontSizes.xl)}})},[F,j]),{email:g,setEmail:y,emailSent:C,setEmailSent:P,sendingCode:E,setVerificationCode:S,verificationCode:F,verifyingCode:x,connectingPhantom:D,inputRefs:j,handleCodeChange:(e,n)=>{var i,t,o;if(n.length<=1){const t=[...F];t[e]=n,S(t),n&&e<5&&(null===(i=j[e+1].current)||void 0===i||i.focus())}else if(n.length>1){const e=n.replace(/\D/g,"").slice(0,6).split(""),i=[...Array(6).fill("")];e.forEach((e,n)=>{n<6&&(i[n]=e)}),S(i);const a=i.findIndex(e=>""===e);-1!==a?null===(t=j[a].current)||void 0===t||t.focus():i[5]&&(null===(o=j[5].current)||void 0===o||o.focus())}},handleKeyDown:(e,n)=>{var i;"Backspace"===n.key&&!F[e]&&e>0&&(null===(i=j[e-1].current)||void 0===i||i.focus())},handleContainerPaste:e=>{var n,i;e.preventDefault();const t=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6).split(""),o=[...Array(6).fill("")];t.forEach((e,n)=>{n<6&&(o[n]=e)}),S(o);const a=o.findIndex(e=>""===e);-1!==a?null===(n=j[a].current)||void 0===n||n.focus():o[5]&&(null===(i=j[5].current)||void 0===i||i.focus())},handleSendVerificationCode:async(e=g)=>{try{if(!A(e))return void alert("Please enter a valid email address");V(!0),await o.sendEmailVerificationCode(e),P(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{V(!1)}},handleCodeSubmit:async(e=F.join(""),n=g)=>{try{if(6!==e.length)return void alert("Please enter a valid verification code");L(!0);const i=await o.verifyEmailVerificationCode({email:n,code:e});i&&(null==f||f(i),null==h||h())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{L(!1)}},handlePhoneCodeSubmit:async(e=F.join(""),n=v)=>{try{if(6!==e.length)return void alert("Please enter a valid verification code");L(!0);const i=await o.verifyPhoneVerificationCode({phone:n,code:e});i&&(null==f||f(i),null==h||h())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{L(!1)}},handleSendPhoneVerificationCode:async(e=v)=>{try{if(!I(e))return void alert("Please enter a valid phone number");await o.sendPhoneVerificationCode(e),w(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{V(!1)}},handleGetChallenge:async(e,n)=>await o.getSignChallenge({method:null!=n?n:"phantom",id:e}),handleLoginWithChallenge:async(e,n)=>{try{const i=await o.loginWithChallenge(e,n);i&&(null==f||f(i),null==h||h())}catch(e){alert("Failed to login with challenge"),console.error("Failed to login with challenge",e)}finally{L(!1)}},phone:v,setPhone:m,phoneSent:p,setPhoneSent:w,onOauthLogin:async e=>{const n=a(e),{codeVerifier:i,codeChallenge:t}=await l(e),d=await o.oauthInit({provider:e,redirect_uri:window.location.href,state:n,code_challenge:t}),{url:s,client_id:h}=d;if(!s&&!h)throw console.error("OAuth init failed."),new Error("init failed");const f={client_id:h,redirect_uri:s,state:n,code_challenge:t},u="google"===e?await r(f):await c(f);window.location.href=u},handlePhantomLogin:async()=>{try{_(!0);const e=await o.connectPhantom();e&&(null==f||f(e),null==h||h())}catch(e){console.error("Phantom login error:",e),alert("Failed to connect to Phantom wallet. Please make sure you have the Phantom extension installed.")}finally{_(!1)}},isOpen:s,onClose:h,onLogin:f,isLoading:u}}export{f as useActiveWallet,s as useConnect,u as useLoginModal,h as useWalletStatus};
1
+ import{useState as e,useMemo as n,createRef as t,useEffect as i}from"react";import{useWallet as o}from"./context.js";import{buildOAuthState as a,buildCodeVerifierAndChallenge as l,getGoogleOAuth2Link as r,getTwitterOAuth2Link as c}from"./utils/oauth.js";import{theme as s}from"./styles/theme.js";function d(){const{connect:e,disconnect:n,isConnecting:t}=o();return{connect:e,disconnect:n,isConnecting:t}}function h(){const{error:e,session:n,isInitialized:t,wallet:i}=o();return{isAuthenticated:null!==i,authenticated:null!==i,error:e,session:n,isInitialized:t,ready:t}}function f(){const{wallet:e}=o();return{wallet:e}}function u({client:o,isOpen:d,onClose:h,onLogin:f,isLoading:u=!1}){const[g,y]=e(""),[v,m]=e(""),[w,p]=e(!1),[C,P]=e(!1),[S,F]=e(["","","","","",""]),[E,L]=e(!1),[V,x]=e(!1),[D,_]=e(!1),j=n(()=>Array(6).fill(null).map(()=>t()),[]),A=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),I=e=>/^\+[1-9]\d{1,3}\d{6,14}$/.test(e);return i(()=>{S.forEach((e,n)=>{if(j[n]&&j[n].current){const t=j[n].current;t&&e&&(t.style.fontSize=s.typography.fontSizes.xl)}})},[S,j]),{email:g,setEmail:y,emailSent:C,setEmailSent:P,sendingCode:E,setVerificationCode:F,verificationCode:S,verifyingCode:V,connectingPhantom:D,inputRefs:j,handleCodeChange:(e,n)=>{var t,i,o;if(n.length<=1){const i=[...S];i[e]=n,F(i),n&&e<5&&(null===(t=j[e+1].current)||void 0===t||t.focus())}else if(n.length>1){const e=n.replace(/\D/g,"").slice(0,6).split(""),t=[...Array(6).fill("")];e.forEach((e,n)=>{n<6&&(t[n]=e)}),F(t);const a=t.findIndex(e=>""===e);-1!==a?null===(i=j[a].current)||void 0===i||i.focus():t[5]&&(null===(o=j[5].current)||void 0===o||o.focus())}},handleKeyDown:(e,n)=>{var t;"Backspace"===n.key&&!S[e]&&e>0&&(null===(t=j[e-1].current)||void 0===t||t.focus())},handleContainerPaste:e=>{var n,t;e.preventDefault();const i=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6).split(""),o=[...Array(6).fill("")];i.forEach((e,n)=>{n<6&&(o[n]=e)}),F(o);const a=o.findIndex(e=>""===e);-1!==a?null===(n=j[a].current)||void 0===n||n.focus():o[5]&&(null===(t=j[5].current)||void 0===t||t.focus())},handleSendVerificationCode:async(e=g)=>{try{if(!A(e))return void alert("Please enter a valid email address");L(!0),await o.sendEmailVerificationCode(e),P(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{L(!1)}},handleCodeSubmit:async(e=S.join(""),n=g)=>{try{if(6!==e.length)return void alert("Please enter a valid verification code");x(!0);const t=await o.verifyEmailVerificationCode({email:n,code:e});t&&(null==f||f(t),null==h||h())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{x(!1)}},handlePhoneCodeSubmit:async(e=S.join(""),n=v)=>{try{if(6!==e.length)return void alert("Please enter a valid verification code");x(!0);const t=await o.verifyPhoneVerificationCode({phone:n,code:e});t&&(null==f||f(t),null==h||h())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{x(!1)}},handleSendPhoneVerificationCode:async(e=v)=>{try{if(!I(e))return void alert("Please enter a valid phone number");await o.sendPhoneVerificationCode(e),p(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{L(!1)}},handleGetChallenge:async(e,n)=>await o.getSignChallenge({method:null!=n?n:"phantom",id:e}),handleLoginWithChallenge:async(e,n)=>{try{const t=await o.loginWithChallenge(e,n);t&&(null==f||f(t),null==h||h())}catch(e){alert("Failed to login with challenge"),console.error("Failed to login with challenge",e)}finally{x(!1)}},phone:v,setPhone:m,phoneSent:w,setPhoneSent:p,onOauthLogin:async e=>{const n=a(e),{codeVerifier:t,codeChallenge:i}=await l(e),s=new URL(window.location.href);s.searchParams.forEach((e,n)=>{s.searchParams.delete(n)});const d=s.toString(),h=await o.oauthInit({provider:e,redirect_uri:d,state:n,code_challenge:i}),{url:f,client_id:u}=h;if(!f&&!u)throw console.error("OAuth init failed."),new Error("init failed");const g={client_id:u,redirect_uri:f,state:n,code_challenge:i},y="google"===e?await r(g):await c(g);window.location.href=y},handlePhantomLogin:async()=>{try{_(!0);const e=await o.connectPhantom();e&&(null==f||f(e),null==h||h())}catch(e){console.error("Phantom login error:",e),alert("Failed to connect to Phantom wallet. Please make sure you have the Phantom extension installed.")}finally{_(!1)}},isOpen:d,onClose:h,onLogin:f,isLoading:u}}export{f as useActiveWallet,d as useConnect,u as useLoginModal,h as useWalletStatus};
2
2
  //# sourceMappingURL=hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["../../../../src/hooks.ts"],"sourcesContent":[null],"names":["useConnect","connect","disconnect","isConnecting","useWallet","useWalletStatus","error","session","isInitialized","wallet","isAuthenticated","authenticated","ready","useActiveWallet","useLoginModal","client","isOpen","onClose","onLogin","isLoading","email","setEmail","useState","phone","setPhone","phoneSent","setPhoneSent","emailSent","setEmailSent","verificationCode","setVerificationCode","sendingCode","setSendingCode","verifyingCode","setVerifyingCode","connectingPhantom","setConnectingPhantom","inputRefs","useMemo","Array","fill","map","createRef","validateEmail","test","validatePhone","useEffect","forEach","value","index","current","input","style","fontSize","theme","typography","fontSizes","xl","handleCodeChange","length","newCode","_a","focus","digits","replace","slice","split","digit","i","nextEmptyIndex","findIndex","d","_b","_c","handleKeyDown","e","key","handleContainerPaste","preventDefault","clipboardData","getData","handleSendVerificationCode","async","emailInput","alert","sendEmailVerificationCode","console","handleCodeSubmit","code","join","verifyEmailVerificationCode","handlePhoneCodeSubmit","phoneInput","verifyPhoneVerificationCode","handleSendPhoneVerificationCode","sendPhoneVerificationCode","handleGetChallenge","address","method","getSignChallenge","id","handleLoginWithChallenge","type","params","loginWithChallenge","onOauthLogin","state","buildOAuthState","codeVerifier","codeChallenge","buildCodeVerifierAndChallenge","response","oauthInit","provider","redirect_uri","window","location","href","code_challenge","url","client_id","Error","oauth2Link","getGoogleOAuth2Link","getTwitterOAuth2Link","handlePhantomLogin","connectPhantom"],"mappings":"iTAYgBA,IACd,MAAMC,QAAEA,EAAOC,WAAEA,EAAUC,aAAEA,GAAiBC,IAE9C,MAAO,CACLH,UACAC,aACAC,eAEJ,UAEgBE,IACd,MAAMC,MAAEA,EAAKC,QAAEA,EAAOC,cAAEA,EAAaC,OAAEA,GAAWL,IAElD,MAAO,CACLM,gBAA4B,OAAXD,EACjBE,cAA0B,OAAXF,EACfH,QACAC,UACAC,gBACAI,MAAOJ,EAEX,UAEgBK,IACd,MAAMJ,OAAEA,GAAWL,IACnB,MAAO,CAAEK,SACX,CAEM,SAAUK,GAAcC,OAC5BA,EAAMC,OACNA,EAAMC,QACNA,EAAOC,QACPA,EAAOC,UACPA,GAAY,IAEZ,MAAOC,EAAOC,GAAYC,EAAS,KAC5BC,EAAOC,GAAYF,EAAS,KAC5BG,EAAWC,GAAgBJ,GAAS,IACpCK,EAAWC,GAAgBN,GAAS,IACpCO,EAAkBC,GAAuBR,EAAS,CACvD,GACA,GACA,GACA,GACA,GACA,MAEKS,EAAaC,GAAkBV,GAAS,IACxCW,EAAeC,GAAoBZ,GAAS,IAC5Ca,EAAmBC,GAAwBd,GAAS,GAErDe,EAAYC,EAChB,IACEC,MAAM,GACHC,KAAK,MACLC,IAAI,IAAMC,KACf,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,GACrB,MAAM3B,QAAeM,EAAO+G,iBACxBrH,IACFS,SAAAA,EAAUT,GACVQ,SAAAA,IAEJ,CAAE,MAAOX,GACPgF,QAAQhF,MAAM,uBAAwBA,GACtC8E,MACE,kGAEJ,SACEhD,GAAqB,EACvB,GA6CApB,SACAC,UACAC,UACAC,YAEJ"}
1
+ {"version":3,"file":"hooks.js","sources":["../../../../src/hooks.ts"],"sourcesContent":[null],"names":["useConnect","connect","disconnect","isConnecting","useWallet","useWalletStatus","error","session","isInitialized","wallet","isAuthenticated","authenticated","ready","useActiveWallet","useLoginModal","client","isOpen","onClose","onLogin","isLoading","email","setEmail","useState","phone","setPhone","phoneSent","setPhoneSent","emailSent","setEmailSent","verificationCode","setVerificationCode","sendingCode","setSendingCode","verifyingCode","setVerifyingCode","connectingPhantom","setConnectingPhantom","inputRefs","useMemo","Array","fill","map","createRef","validateEmail","test","validatePhone","useEffect","forEach","value","index","current","input","style","fontSize","theme","typography","fontSizes","xl","handleCodeChange","length","newCode","_a","focus","digits","replace","slice","split","digit","i","nextEmptyIndex","findIndex","d","_b","_c","handleKeyDown","e","key","handleContainerPaste","preventDefault","clipboardData","getData","handleSendVerificationCode","async","emailInput","alert","sendEmailVerificationCode","console","handleCodeSubmit","code","join","verifyEmailVerificationCode","handlePhoneCodeSubmit","phoneInput","verifyPhoneVerificationCode","handleSendPhoneVerificationCode","sendPhoneVerificationCode","handleGetChallenge","address","method","getSignChallenge","id","handleLoginWithChallenge","type","params","loginWithChallenge","onOauthLogin","state","buildOAuthState","codeVerifier","codeChallenge","buildCodeVerifierAndChallenge","currentUrl","URL","window","location","href","searchParams","delete","redirect_uri","toString","response","oauthInit","provider","code_challenge","url","client_id","Error","oauth2Link","getGoogleOAuth2Link","getTwitterOAuth2Link","handlePhantomLogin","connectPhantom"],"mappings":"iTAYgBA,IACd,MAAMC,QAAEA,EAAOC,WAAEA,EAAUC,aAAEA,GAAiBC,IAE9C,MAAO,CACLH,UACAC,aACAC,eAEJ,UAE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AAMC,GACjD9F,IACFS,SAAAA,EAAUT,GACVQ,SAAAA,IAEJ,CAAE,MAAO0D,GACPS,MAAM,kCACNE,QAAQhF,MAAM,iCAAkCqE,EAClD,SACEzC,GAAiB,EACnB,GAqGAX,QACAC,WACAC,YACAC,eACA+E,aA9FmBvB,MAAOoB,IAC1B,MAAMI,EAAQC,EAAgBL,IACxBM,aAAEA,EAAYC,cAAEA,SACdC,EAA8BR,GAGhCS,EAAa,IAAIC,IAAIC,OAAOC,SAASC,MAC3CJ,EAAWK,aAAarE,QAAQ,CAACC,EAAO4B,KACtCmC,EAAWK,aAAaC,OAAOzC,KAEjC,MAAM0C,EAAeP,EAAWQ,WAC1BC,QAAiBzG,EAAO0G,UAAU,CACtCC,SAAUpB,EACVgB,aAAcA,EACdZ,QACAiB,eAAgBd,KAGZe,IAAEA,EAAGC,UAAEA,GAAcL,EAC3B,IAAKI,IAAQC,EAEX,MADAvC,QAAQhF,MAAM,sBACR,IAAIwH,MAAM,eAElB,MAAMvB,EAAS,CACbsB,UAAWA,EACXP,aAAcM,EACdlB,QACAiB,eAAgBd,GAEZkB,EACK,WAATzB,QACU0B,EAAoBzB,SACpB0B,EAAqB1B,GACjCU,OAAOC,SAASC,KAAOY,GA8DvBG,mBA3DyBhD,UACzB,IACE9C,GAAqB,GACrB,MAAM3B,QAAeM,EAAOoH,iBACxB1H,IACFS,SAAAA,EAAUT,GACVQ,SAAAA,IAEJ,CAAE,MAAOX,GACPgF,QAAQhF,MAAM,uBAAwBA,GACtC8E,MACE,kGAEJ,SACEhD,GAAqB,EACvB,GA6CApB,SACAC,UACAC,UACAC,YAEJ"}
package/dist/index.cjs CHANGED
@@ -293,5 +293,5 @@ const jl=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff
293
293
  color: ${rg.colors.text.tertiary};
294
294
  text-align: center;
295
295
  margin-top: ${rg.spacing.lg};
296
- `;async function Bg(e){const t=e.toLowerCase(),n=r.v4(),o=await async function(e){const t=new TextEncoder,n=t.encode(e),r=await crypto.subtle.digest("SHA-256",n),o=Array.from(new Uint8Array(r));return btoa(String.fromCharCode(...o)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}(n);return sessionStorage.setItem(`${t}_oauthCodeVerifier`,JSON.stringify({code_verifier:n,code_challenge:o,timestamp:Date.now()})),{codeVerifier:n,codeChallenge:o}}const Cg=()=>{if("undefined"!=typeof document&&document.getElementById("superstack-wallet-styles"))return;if("undefined"==typeof document)return;const e=document.createElement("link");e.id="superstack-wallet-fonts",e.rel="stylesheet",e.href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap",document.head.appendChild(e);const t=document.createElement("style");t.id="superstack-wallet-styles",t.textContent=`\n /* 只影响嵌入钱包模态框 */\n #embedded-wallet-modal {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 9999;\n display: flex;\n align-items: center;\n justify-content: center;\n background-color: rgba(0, 0, 0, 0.5);\n }\n \n /* 以下类选择器都只对SDK自己的元素生效 */\n .superstack-wallet-container {\n font-family: 'Montserrat', sans-serif;\n color: ${rg.colors.text.primary};\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n \n /* 直接选择SDK组件,而不是使用通配符 */\n .superstack-wallet-container h1,\n .superstack-wallet-container h2,\n .superstack-wallet-container h3,\n .superstack-wallet-container h4,\n .superstack-wallet-container h5,\n .superstack-wallet-container h6 {\n font-family: 'Montserrat', sans-serif;\n font-weight: ${rg.typography.fontWeights.semibold};\n line-height: 1.2;\n margin-bottom: ${rg.spacing.md};\n }\n \n .superstack-wallet-container p {\n font-family: 'Montserrat', sans-serif;\n margin-bottom: ${rg.spacing.md};\n }\n \n /* 为SDK定义的按钮添加类名 */\n .superstack-wallet-btn {\n font-family: 'Montserrat', sans-serif;\n cursor: pointer;\n }\n \n /* 为SDK定义的输入域添加类名 */\n .superstack-wallet-input {\n font-family: 'Montserrat', sans-serif;\n }\n \n /* 模态内容应该有自己的样式,不影响外部 */\n #embedded-wallet-modal .modal-content {\n background-color: ${rg.colors.background.main};\n border-radius: ${rg.borderRadius.md};\n padding: ${rg.spacing.lg};\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n max-width: 480px;\n width: 100%;\n }\n `,document.head.appendChild(t)};var Og=Object.freeze({__proto__:null,injectStyles:Cg,theme:rg});function Rg({client:e,isOpen:t,onClose:n,onLogin:s,isLoading:a=!1}){const[i,c]=o.useState(""),[u,l]=o.useState(""),[d,f]=o.useState(!1),[h,p]=o.useState(!1),[g,b]=o.useState(["","","","","",""]),[y,w]=o.useState(!1),[v,x]=o.useState(!1),[E,P]=o.useState(!1),k=o.useMemo(()=>Array(6).fill(null).map(()=>o.createRef()),[]),A=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),I=e=>/^\+[1-9]\d{1,3}\d{6,14}$/.test(e);return o.useEffect(()=>{g.forEach((e,t)=>{if(k[t]&&k[t].current){const n=k[t].current;n&&e&&(n.style.fontSize=rg.typography.fontSizes.xl)}})},[g,k]),{email:i,setEmail:c,emailSent:h,setEmailSent:p,sendingCode:y,setVerificationCode:b,verificationCode:g,verifyingCode:v,connectingPhantom:E,inputRefs:k,handleCodeChange:(e,t)=>{var n,r,o;if(t.length<=1){const r=[...g];r[e]=t,b(r),t&&e<5&&(null===(n=k[e+1].current)||void 0===n||n.focus())}else if(t.length>1){const e=t.replace(/\D/g,"").slice(0,6).split(""),n=[...Array(6).fill("")];e.forEach((e,t)=>{t<6&&(n[t]=e)}),b(n);const s=n.findIndex(e=>""===e);-1!==s?null===(r=k[s].current)||void 0===r||r.focus():n[5]&&(null===(o=k[5].current)||void 0===o||o.focus())}},handleKeyDown:(e,t)=>{var n;"Backspace"===t.key&&!g[e]&&e>0&&(null===(n=k[e-1].current)||void 0===n||n.focus())},handleContainerPaste:e=>{var t,n;e.preventDefault();const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6).split(""),o=[...Array(6).fill("")];r.forEach((e,t)=>{t<6&&(o[t]=e)}),b(o);const s=o.findIndex(e=>""===e);-1!==s?null===(t=k[s].current)||void 0===t||t.focus():o[5]&&(null===(n=k[5].current)||void 0===n||n.focus())},handleSendVerificationCode:async(t=i)=>{try{if(!A(t))return void alert("Please enter a valid email address");w(!0),await e.sendEmailVerificationCode(t),p(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{w(!1)}},handleCodeSubmit:async(t=g.join(""),r=i)=>{try{if(6!==t.length)return void alert("Please enter a valid verification code");x(!0);const o=await e.verifyEmailVerificationCode({email:r,code:t});o&&(null==s||s(o),null==n||n())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{x(!1)}},handlePhoneCodeSubmit:async(t=g.join(""),r=u)=>{try{if(6!==t.length)return void alert("Please enter a valid verification code");x(!0);const o=await e.verifyPhoneVerificationCode({phone:r,code:t});o&&(null==s||s(o),null==n||n())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{x(!1)}},handleSendPhoneVerificationCode:async(t=u)=>{try{if(!I(t))return void alert("Please enter a valid phone number");await e.sendPhoneVerificationCode(t),f(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{w(!1)}},handleGetChallenge:async(t,n)=>await e.getSignChallenge({method:null!=n?n:"phantom",id:t}),handleLoginWithChallenge:async(t,r)=>{try{const o=await e.loginWithChallenge(t,r);o&&(null==s||s(o),null==n||n())}catch(e){alert("Failed to login with challenge"),console.error("Failed to login with challenge",e)}finally{x(!1)}},phone:u,setPhone:l,phoneSent:d,setPhoneSent:f,onOauthLogin:async t=>{const n=function(e){const t=e.toLowerCase(),n=r.v4();return sessionStorage.setItem(`${t}_oauthState`,JSON.stringify({state:n,timestamp:Date.now()})),n}(t),{codeVerifier:o,codeChallenge:s}=await Bg(t),a=await e.oauthInit({provider:t,redirect_uri:window.location.href,state:n,code_challenge:s}),{url:i,client_id:c}=a;if(!i&&!c)throw console.error("OAuth init failed."),new Error("init failed");const u={client_id:c,redirect_uri:i,state:n,code_challenge:s},l="google"===t?await async function(e){const t={response_type:"code",client_id:e.client_id,redirect_uri:e.redirect_uri,scope:["openid","email","profile"].join("%20"),code_challenge:e.code_challenge,code_challenge_method:"S256",state:e.state};return`https://accounts.google.com/o/oauth2/v2/auth?${m.stringify(t,{encode:!1})}`}(u):await async function(e){const t={response_type:"code",client_id:e.client_id,redirect_uri:e.redirect_uri,scope:["tweet.read","users.read"].join("%20"),code_challenge:e.code_challenge,code_challenge_method:"S256",state:e.state};return`https://twitter.com/i/oauth2/authorize?${m.stringify(t,{encode:!1})}`}(u);window.location.href=l},handlePhantomLogin:async()=>{try{P(!0);const t=await e.connectPhantom();t&&(null==s||s(t),null==n||n())}catch(e){console.error("Phantom login error:",e),alert("Failed to connect to Phantom wallet. Please make sure you have the Phantom extension installed.")}finally{P(!1)}},isOpen:t,onClose:n,onLogin:s,isLoading:a}}const zg=({client:e,isOpen:t,onClose:n,onLogin:r,isLoading:o=!1,enableEmail:a=!0,enablePhone:i=!1,enableGoogle:c=!0,enableTwitter:u=!1,enablePhantom:l=!0})=>{const{email:d,setEmail:f,emailSent:h,sendingCode:m,setEmailSent:g,verifyingCode:b,verificationCode:y,connectingPhantom:w,inputRefs:v,handleCodeChange:x,handleKeyDown:E,handleContainerPaste:P,handleSendVerificationCode:k,handleCodeSubmit:A,onOauthLogin:I,handlePhantomLogin:N}=Rg({client:e,isOpen:t,onClose:n,onLogin:r,isLoading:o});return t?p.default.createElement(sg,null,p.default.createElement(ag,null,p.default.createElement(ig,null,p.default.createElement(cg,null,"Connect Wallet"),p.default.createElement(ug,{onClick:n},p.default.createElement(lg,{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},p.default.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))),o?p.default.createElement(dg,null,p.default.createElement(fg,null,p.default.createElement(s.Loader2,{size:24})),p.default.createElement(hg,null,"Loading...")):p.default.createElement(p.default.Fragment,null,h?p.default.createElement(Pg,null,p.default.createElement("div",null,p.default.createElement(kg,null,"Enter Verification Code"),p.default.createElement(Ag,null,"We sent a verification code to ",d)),p.default.createElement(Ig,{onPaste:P},y.map((e,t)=>p.default.createElement(Ng,{key:t},p.default.createElement(Sg,{ref:v[t],type:"text",maxLength:1,value:e,onChange:e=>x(t,e.target.value),onKeyDown:e=>E(t,e),onPaste:e=>{0!==t&&(e.preventDefault(),P(e))}})))),p.default.createElement(gg,{onClick:()=>A(),disabled:6!==y.join("").length||b},b?"Verifying...":"Verify Code"),p.default.createElement(Tg,{onClick:()=>g(!1)},"Back to Email")):p.default.createElement(pg,null,a&&p.default.createElement(pg,null,p.default.createElement(mg,{type:"email",value:d,onChange:e=>f(e.target.value),placeholder:"Enter your email",disabled:m}),p.default.createElement(gg,{onClick:()=>k(),disabled:!d||m},m?"Sending...":"Send Verification Code")),(c||u||l)&&a&&p.default.createElement(bg,null,p.default.createElement(yg,null),p.default.createElement(wg,null,"Or continue with"),p.default.createElement(yg,null)),(c||u||l)&&p.default.createElement(p.default.Fragment,null,p.default.createElement(vg,null,c&&p.default.createElement(xg,{onClick:()=>I("google")},p.default.createElement(Eg,null,p.default.createElement("img",{src:"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/google/google-original.svg",alt:"Google",width:20,height:20})),"Google"),u&&p.default.createElement(xg,{onClick:()=>I("twitter")},p.default.createElement(Eg,null,p.default.createElement("img",{src:"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/twitter/twitter-original.svg",alt:"Twitter",width:20,height:20})),"X")),l&&p.default.createElement(xg,{onClick:N,disabled:w},p.default.createElement(Eg,null,p.default.createElement("img",{src:"https://explorer-api.walletconnect.com/v3/logo/md/b6ec7b81-bb4f-427d-e290-7631e6e50d00?projectId=34357d3c125c2bcf2ce2bc3309d98715",alt:"Phantom",width:20,height:20})),w?"Connecting...":"Phantom")),!a&&!i&&!c&&!u&&!l&&p.default.createElement("div",{style:{textAlign:"center",padding:"20px",color:"#666"}},"No login methods are currently enabled."))),p.default.createElement($g,null,"By connecting your wallet, you agree to our Terms of Service and Privacy Policy"))):null};class Mg{constructor(){this.container=null,this.root=null}createContainer(){if("undefined"==typeof document)return null;this.removeExistingContainer();const e=document.createElement("div");return e.id="embedded-wallet-modal",document.body.appendChild(e),e}removeExistingContainer(){if("undefined"==typeof document)return;const e=document.getElementById("embedded-wallet-modal");e&&e.parentNode&&e.parentNode.removeChild(e)}showLoginModal({client:e,isLoading:t=!1,onClose:n,onLogin:r,enableEmail:o=!0,enablePhone:s=!1,enableGoogle:a=!0,enableTwitter:i=!1,enablePhantom:c=!0}){return new Promise((u,l)=>{try{if("undefined"==typeof window)return void u();import("react-dom/client").then(({createRoot:l})=>{if(this.container=this.createContainer(),!this.container)return void u();this.root=l(this.container);const d=()=>{this.hideModal(),null==n||n()},f=e=>{this.hideModal(),null==r||r(e)};this.root&&this.root.render(p.default.createElement(zg,{client:e,isOpen:!0,onClose:d,isLoading:t,onLogin:f,enableEmail:o,enablePhone:s,enableGoogle:a,enableTwitter:i,enablePhantom:c})),u()}).catch(e=>{console.error("Error importing createRoot:",e),l(e)})}catch(e){console.error("Error showing modal:",e),l(e)}})}hideModal(){this.root&&(this.root.unmount(),this.container&&this.container.parentNode&&(document.body.removeChild(this.container),this.container=null))}}const _g={isAuthenticated:!1,isConnecting:!1,isInitialized:!1,walletInfo:null,wallet:null,session:null,error:null,enableEmail:!0,enablePhone:!1,enableGoogle:!0,enableTwitter:!1,enablePhantom:!0},Fg=o.createContext({});function jg(e,t){switch(t.type){case"SET_CONNECTING":return{...e,isConnecting:t.payload};case"SET_INITIALIZED":return{...e,isInitialized:t.payload};case"SET_SESSION":return{...e,isAuthenticated:!0,session:t.payload,error:null};case"SET_WALLET_INFO":return{...e,walletInfo:t.payload};case"SET_WALLET":return{...e,wallet:t.payload};case"SET_ERROR":return{...e,error:t.payload};case"RESET":return{..._g,isInitialized:!0};default:return e}}function Lg(){const e=o.useContext(Fg);if(!e)throw new Error("useWallet must be used within a WalletProvider");return e}"undefined"!=typeof window&&Promise.resolve().then(function(){return Og}).then(({injectStyles:e})=>{e()}),exports.ACCESS_TOKEN_KEY=w,exports.STORAGE_STATE_KEY=b,exports.Storage=v,exports.WALLET_TYPE_KEY=y,exports.WalletClient=hh,exports.WalletProvider=function({children:e,config:t}){var n,r,s,a,i,c;const u=o.useRef(null);u.current||(u.current=new hh(t));const l=u.current,d=o.useRef(null!==(n=t.modalManager)&&void 0!==n?n:null),[f,h]=o.useReducer(jg,{..._g,enableEmail:null===(r=t.enableEmail)||void 0===r||r,enablePhone:null!==(s=t.enablePhone)&&void 0!==s&&s,enableGoogle:null===(a=t.enableGoogle)||void 0===a||a,enableTwitter:null!==(i=t.enableTwitter)&&void 0!==i&&i,enablePhantom:null===(c=t.enablePhantom)||void 0===c||c}),{walletInfo:m}=f,g=o.useRef(!1),b=o.useCallback(()=>(d.current||"undefined"==typeof window||(d.current=new Mg),d.current),[]);o.useEffect(()=>{t.modalManager&&(d.current=t.modalManager)},[t.modalManager]),o.useEffect(()=>{!async function(){if(!(m||g.current||f.isInitialized)){g.current=!0;try{const e=await l.reconnect();e&&(h({type:"SET_WALLET_INFO",payload:e}),h({type:"SET_WALLET",payload:l}))}catch(e){console.error("Auto reconnect failed:",e)}finally{h({type:"SET_INITIALIZED",payload:!0})}}}()},[l]),o.useEffect(()=>{const e=async()=>{try{if(x.isConnecting)return;h({type:"SET_CONNECTING",payload:!0});const e=new URLSearchParams(window.location.search),t=e.get("wallet_oauth_provider"),n=e.get("wallet_oauth_state"),r=e.get("wallet_oauth_code");if(t&&n&&r){const e=function(e){const t=e.toLowerCase(),n=sessionStorage.getItem(`${t}_oauthCodeVerifier`);if(!n)return null;const r=JSON.parse(n);return sessionStorage.removeItem(`${t}_oauthCodeVerifier`),Date.now()-r.timestamp>6e5?null:{codeVerifier:r.code_verifier,codeChallenge:r.code_challenge}}(t);if(!e)throw new Error("No code verifier found");const{codeVerifier:o,codeChallenge:s}=e;let a;if("twitter"===t)a="TwitterOAuth";else{if("google"!==t)throw new Error("Unsupported provider");a="GoogleOAuth"}b().showLoginModal({client:l,isLoading:!0,enableEmail:f.enableEmail,enablePhone:f.enablePhone,enableGoogle:f.enableGoogle,enableTwitter:f.enableTwitter,enablePhantom:f.enablePhantom});const i=await l.oauthLogin(a,{state:n,code:r,code_verifier:o});if(i){h({type:"SET_WALLET_INFO",payload:i}),h({type:"SET_WALLET",payload:l});const e=new URL(window.location.href);e.searchParams.delete("wallet_oauth_provider"),e.searchParams.delete("wallet_oauth_state"),e.searchParams.delete("wallet_oauth_code"),history.replaceState(null,"",e.toString())}}}catch(e){console.log("oauth login error: ",e)}finally{h({type:"SET_CONNECTING",payload:!1}),await b().hideModal()}};return e(),window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)}},[]);const y=o.useCallback(async()=>{try{h({type:"SET_CONNECTING",payload:!0});b().showLoginModal({client:l,enableEmail:f.enableEmail,enablePhone:f.enablePhone,enableGoogle:f.enableGoogle,enableTwitter:f.enableTwitter,enablePhantom:f.enablePhantom,onClose:()=>{h({type:"SET_CONNECTING",payload:!1})},onLogin:e=>{h({type:"SET_CONNECTING",payload:!1}),h({type:"SET_WALLET_INFO",payload:e}),h({type:"SET_WALLET",payload:l})}})}catch(e){h({type:"SET_ERROR",payload:e instanceof Error?e.message:"Failed to connect"}),h({type:"SET_CONNECTING",payload:!1})}},[l]),w=o.useCallback(async()=>{await l.logout(),h({type:"RESET"})},[l]);o.useEffect(()=>{var e;"phantom"===v.getWalletType()&&l.getPhantomAdapter()&&(null===(e=l.getPhantomAdapter())||void 0===e||e.on("disconnect",()=>{w()}))},[l]);const x={...f,connect:y,disconnect:w};return p.default.createElement(Fg.Provider,{value:x},e)},exports.injectStyles=Cg,exports.isVersionedTransaction=g,exports.theme=rg,exports.useActiveWallet=function(){const{wallet:e}=Lg();return{wallet:e}},exports.useCoinbaseOnramp=function(){const{wallet:e}=Lg(),t=null==e?void 0:e.solanaAddress,n=null==e?void 0:e.ethereumAddress;return{getCoinbaseOnrampUrl:async(r,o="solana",s)=>{if(!e||!t||!n)throw new Error("Wallet not found");const a="solana"===o?t:n;return pf({sessionToken:await(null==e?void 0:e.fetchCoinbaseToken(a,o)),presetCryptoAmount:Number(r),redirectUrl:s||window.location.href})}}},exports.useConnect=function(){const{connect:e,disconnect:t,isConnecting:n}=Lg();return{connect:e,disconnect:t,isConnecting:n}},exports.useLoginModal=Rg,exports.useWallet=Lg,exports.useWalletStatus=function(){const{error:e,session:t,isInitialized:n,wallet:r}=Lg();return{isAuthenticated:null!==r,authenticated:null!==r,error:e,session:t,isInitialized:n,ready:n}};
296
+ `;async function Bg(e){const t=e.toLowerCase(),n=r.v4(),o=await async function(e){const t=new TextEncoder,n=t.encode(e),r=await crypto.subtle.digest("SHA-256",n),o=Array.from(new Uint8Array(r));return btoa(String.fromCharCode(...o)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}(n);return sessionStorage.setItem(`${t}_oauthCodeVerifier`,JSON.stringify({code_verifier:n,code_challenge:o,timestamp:Date.now()})),{codeVerifier:n,codeChallenge:o}}const Cg=()=>{if("undefined"!=typeof document&&document.getElementById("superstack-wallet-styles"))return;if("undefined"==typeof document)return;const e=document.createElement("link");e.id="superstack-wallet-fonts",e.rel="stylesheet",e.href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400;500;600;700&display=swap",document.head.appendChild(e);const t=document.createElement("style");t.id="superstack-wallet-styles",t.textContent=`\n /* 只影响嵌入钱包模态框 */\n #embedded-wallet-modal {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n z-index: 9999;\n display: flex;\n align-items: center;\n justify-content: center;\n background-color: rgba(0, 0, 0, 0.5);\n }\n \n /* 以下类选择器都只对SDK自己的元素生效 */\n .superstack-wallet-container {\n font-family: 'Montserrat', sans-serif;\n color: ${rg.colors.text.primary};\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n \n /* 直接选择SDK组件,而不是使用通配符 */\n .superstack-wallet-container h1,\n .superstack-wallet-container h2,\n .superstack-wallet-container h3,\n .superstack-wallet-container h4,\n .superstack-wallet-container h5,\n .superstack-wallet-container h6 {\n font-family: 'Montserrat', sans-serif;\n font-weight: ${rg.typography.fontWeights.semibold};\n line-height: 1.2;\n margin-bottom: ${rg.spacing.md};\n }\n \n .superstack-wallet-container p {\n font-family: 'Montserrat', sans-serif;\n margin-bottom: ${rg.spacing.md};\n }\n \n /* 为SDK定义的按钮添加类名 */\n .superstack-wallet-btn {\n font-family: 'Montserrat', sans-serif;\n cursor: pointer;\n }\n \n /* 为SDK定义的输入域添加类名 */\n .superstack-wallet-input {\n font-family: 'Montserrat', sans-serif;\n }\n \n /* 模态内容应该有自己的样式,不影响外部 */\n #embedded-wallet-modal .modal-content {\n background-color: ${rg.colors.background.main};\n border-radius: ${rg.borderRadius.md};\n padding: ${rg.spacing.lg};\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n max-width: 480px;\n width: 100%;\n }\n `,document.head.appendChild(t)};var Og=Object.freeze({__proto__:null,injectStyles:Cg,theme:rg});function Rg({client:e,isOpen:t,onClose:n,onLogin:s,isLoading:a=!1}){const[i,c]=o.useState(""),[u,l]=o.useState(""),[d,f]=o.useState(!1),[h,p]=o.useState(!1),[g,b]=o.useState(["","","","","",""]),[y,w]=o.useState(!1),[v,x]=o.useState(!1),[E,P]=o.useState(!1),k=o.useMemo(()=>Array(6).fill(null).map(()=>o.createRef()),[]),A=e=>/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e),I=e=>/^\+[1-9]\d{1,3}\d{6,14}$/.test(e);return o.useEffect(()=>{g.forEach((e,t)=>{if(k[t]&&k[t].current){const n=k[t].current;n&&e&&(n.style.fontSize=rg.typography.fontSizes.xl)}})},[g,k]),{email:i,setEmail:c,emailSent:h,setEmailSent:p,sendingCode:y,setVerificationCode:b,verificationCode:g,verifyingCode:v,connectingPhantom:E,inputRefs:k,handleCodeChange:(e,t)=>{var n,r,o;if(t.length<=1){const r=[...g];r[e]=t,b(r),t&&e<5&&(null===(n=k[e+1].current)||void 0===n||n.focus())}else if(t.length>1){const e=t.replace(/\D/g,"").slice(0,6).split(""),n=[...Array(6).fill("")];e.forEach((e,t)=>{t<6&&(n[t]=e)}),b(n);const s=n.findIndex(e=>""===e);-1!==s?null===(r=k[s].current)||void 0===r||r.focus():n[5]&&(null===(o=k[5].current)||void 0===o||o.focus())}},handleKeyDown:(e,t)=>{var n;"Backspace"===t.key&&!g[e]&&e>0&&(null===(n=k[e-1].current)||void 0===n||n.focus())},handleContainerPaste:e=>{var t,n;e.preventDefault();const r=e.clipboardData.getData("text").replace(/\D/g,"").slice(0,6).split(""),o=[...Array(6).fill("")];r.forEach((e,t)=>{t<6&&(o[t]=e)}),b(o);const s=o.findIndex(e=>""===e);-1!==s?null===(t=k[s].current)||void 0===t||t.focus():o[5]&&(null===(n=k[5].current)||void 0===n||n.focus())},handleSendVerificationCode:async(t=i)=>{try{if(!A(t))return void alert("Please enter a valid email address");w(!0),await e.sendEmailVerificationCode(t),p(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{w(!1)}},handleCodeSubmit:async(t=g.join(""),r=i)=>{try{if(6!==t.length)return void alert("Please enter a valid verification code");x(!0);const o=await e.verifyEmailVerificationCode({email:r,code:t});o&&(null==s||s(o),null==n||n())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{x(!1)}},handlePhoneCodeSubmit:async(t=g.join(""),r=u)=>{try{if(6!==t.length)return void alert("Please enter a valid verification code");x(!0);const o=await e.verifyPhoneVerificationCode({phone:r,code:t});o&&(null==s||s(o),null==n||n())}catch(e){alert("Failed to verify code"),console.error("Failed to verify code",e)}finally{x(!1)}},handleSendPhoneVerificationCode:async(t=u)=>{try{if(!I(t))return void alert("Please enter a valid phone number");await e.sendPhoneVerificationCode(t),f(!0)}catch(e){alert("Failed to send verification code"),console.error("Failed to send verification code",e)}finally{w(!1)}},handleGetChallenge:async(t,n)=>await e.getSignChallenge({method:null!=n?n:"phantom",id:t}),handleLoginWithChallenge:async(t,r)=>{try{const o=await e.loginWithChallenge(t,r);o&&(null==s||s(o),null==n||n())}catch(e){alert("Failed to login with challenge"),console.error("Failed to login with challenge",e)}finally{x(!1)}},phone:u,setPhone:l,phoneSent:d,setPhoneSent:f,onOauthLogin:async t=>{const n=function(e){const t=e.toLowerCase(),n=r.v4();return sessionStorage.setItem(`${t}_oauthState`,JSON.stringify({state:n,timestamp:Date.now()})),n}(t),{codeVerifier:o,codeChallenge:s}=await Bg(t),a=new URL(window.location.href);a.searchParams.forEach((e,t)=>{a.searchParams.delete(t)});const i=a.toString(),c=await e.oauthInit({provider:t,redirect_uri:i,state:n,code_challenge:s}),{url:u,client_id:l}=c;if(!u&&!l)throw console.error("OAuth init failed."),new Error("init failed");const d={client_id:l,redirect_uri:u,state:n,code_challenge:s},f="google"===t?await async function(e){const t={response_type:"code",client_id:e.client_id,redirect_uri:e.redirect_uri,scope:["openid","email","profile"].join("%20"),code_challenge:e.code_challenge,code_challenge_method:"S256",state:e.state};return`https://accounts.google.com/o/oauth2/v2/auth?${m.stringify(t,{encode:!1})}`}(d):await async function(e){const t={response_type:"code",client_id:e.client_id,redirect_uri:e.redirect_uri,scope:["tweet.read","users.read"].join("%20"),code_challenge:e.code_challenge,code_challenge_method:"S256",state:e.state};return`https://twitter.com/i/oauth2/authorize?${m.stringify(t,{encode:!1})}`}(d);window.location.href=f},handlePhantomLogin:async()=>{try{P(!0);const t=await e.connectPhantom();t&&(null==s||s(t),null==n||n())}catch(e){console.error("Phantom login error:",e),alert("Failed to connect to Phantom wallet. Please make sure you have the Phantom extension installed.")}finally{P(!1)}},isOpen:t,onClose:n,onLogin:s,isLoading:a}}const zg=({client:e,isOpen:t,onClose:n,onLogin:r,isLoading:o=!1,enableEmail:a=!0,enablePhone:i=!1,enableGoogle:c=!0,enableTwitter:u=!1,enablePhantom:l=!0})=>{const{email:d,setEmail:f,emailSent:h,sendingCode:m,setEmailSent:g,verifyingCode:b,verificationCode:y,connectingPhantom:w,inputRefs:v,handleCodeChange:x,handleKeyDown:E,handleContainerPaste:P,handleSendVerificationCode:k,handleCodeSubmit:A,onOauthLogin:I,handlePhantomLogin:N}=Rg({client:e,isOpen:t,onClose:n,onLogin:r,isLoading:o});return t?p.default.createElement(sg,null,p.default.createElement(ag,null,p.default.createElement(ig,null,p.default.createElement(cg,null,"Connect Wallet"),p.default.createElement(ug,{onClick:n},p.default.createElement(lg,{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},p.default.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M6 18L18 6M6 6l12 12"})))),o?p.default.createElement(dg,null,p.default.createElement(fg,null,p.default.createElement(s.Loader2,{size:24})),p.default.createElement(hg,null,"Loading...")):p.default.createElement(p.default.Fragment,null,h?p.default.createElement(Pg,null,p.default.createElement("div",null,p.default.createElement(kg,null,"Enter Verification Code"),p.default.createElement(Ag,null,"We sent a verification code to ",d)),p.default.createElement(Ig,{onPaste:P},y.map((e,t)=>p.default.createElement(Ng,{key:t},p.default.createElement(Sg,{ref:v[t],type:"text",maxLength:1,value:e,onChange:e=>x(t,e.target.value),onKeyDown:e=>E(t,e),onPaste:e=>{0!==t&&(e.preventDefault(),P(e))}})))),p.default.createElement(gg,{onClick:()=>A(),disabled:6!==y.join("").length||b},b?"Verifying...":"Verify Code"),p.default.createElement(Tg,{onClick:()=>g(!1)},"Back to Email")):p.default.createElement(pg,null,a&&p.default.createElement(pg,null,p.default.createElement(mg,{type:"email",value:d,onChange:e=>f(e.target.value),placeholder:"Enter your email",disabled:m}),p.default.createElement(gg,{onClick:()=>k(),disabled:!d||m},m?"Sending...":"Send Verification Code")),(c||u||l)&&a&&p.default.createElement(bg,null,p.default.createElement(yg,null),p.default.createElement(wg,null,"Or continue with"),p.default.createElement(yg,null)),(c||u||l)&&p.default.createElement(p.default.Fragment,null,p.default.createElement(vg,null,c&&p.default.createElement(xg,{onClick:()=>I("google")},p.default.createElement(Eg,null,p.default.createElement("img",{src:"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/google/google-original.svg",alt:"Google",width:20,height:20})),"Google"),u&&p.default.createElement(xg,{onClick:()=>I("twitter")},p.default.createElement(Eg,null,p.default.createElement("img",{src:"https://cdn.jsdelivr.net/gh/devicons/devicon/icons/twitter/twitter-original.svg",alt:"Twitter",width:20,height:20})),"X")),l&&p.default.createElement(xg,{onClick:N,disabled:w},p.default.createElement(Eg,null,p.default.createElement("img",{src:"https://explorer-api.walletconnect.com/v3/logo/md/b6ec7b81-bb4f-427d-e290-7631e6e50d00?projectId=34357d3c125c2bcf2ce2bc3309d98715",alt:"Phantom",width:20,height:20})),w?"Connecting...":"Phantom")),!a&&!i&&!c&&!u&&!l&&p.default.createElement("div",{style:{textAlign:"center",padding:"20px",color:"#666"}},"No login methods are currently enabled."))),p.default.createElement($g,null,"By connecting your wallet, you agree to our Terms of Service and Privacy Policy"))):null};class Mg{constructor(){this.container=null,this.root=null}createContainer(){if("undefined"==typeof document)return null;this.removeExistingContainer();const e=document.createElement("div");return e.id="embedded-wallet-modal",document.body.appendChild(e),e}removeExistingContainer(){if("undefined"==typeof document)return;const e=document.getElementById("embedded-wallet-modal");e&&e.parentNode&&e.parentNode.removeChild(e)}showLoginModal({client:e,isLoading:t=!1,onClose:n,onLogin:r,enableEmail:o=!0,enablePhone:s=!1,enableGoogle:a=!0,enableTwitter:i=!1,enablePhantom:c=!0}){return new Promise((u,l)=>{try{if("undefined"==typeof window)return void u();import("react-dom/client").then(({createRoot:l})=>{if(this.container=this.createContainer(),!this.container)return void u();this.root=l(this.container);const d=()=>{this.hideModal(),null==n||n()},f=e=>{this.hideModal(),null==r||r(e)};this.root&&this.root.render(p.default.createElement(zg,{client:e,isOpen:!0,onClose:d,isLoading:t,onLogin:f,enableEmail:o,enablePhone:s,enableGoogle:a,enableTwitter:i,enablePhantom:c})),u()}).catch(e=>{console.error("Error importing createRoot:",e),l(e)})}catch(e){console.error("Error showing modal:",e),l(e)}})}hideModal(){this.root&&(this.root.unmount(),this.container&&this.container.parentNode&&(document.body.removeChild(this.container),this.container=null))}}const _g={isAuthenticated:!1,isConnecting:!1,isInitialized:!1,walletInfo:null,wallet:null,session:null,error:null,enableEmail:!0,enablePhone:!1,enableGoogle:!0,enableTwitter:!1,enablePhantom:!0},Fg=o.createContext({});function jg(e,t){switch(t.type){case"SET_CONNECTING":return{...e,isConnecting:t.payload};case"SET_INITIALIZED":return{...e,isInitialized:t.payload};case"SET_SESSION":return{...e,isAuthenticated:!0,session:t.payload,error:null};case"SET_WALLET_INFO":return{...e,walletInfo:t.payload};case"SET_WALLET":return{...e,wallet:t.payload};case"SET_ERROR":return{...e,error:t.payload};case"RESET":return{..._g,isInitialized:!0};default:return e}}function Lg(){const e=o.useContext(Fg);if(!e)throw new Error("useWallet must be used within a WalletProvider");return e}"undefined"!=typeof window&&Promise.resolve().then(function(){return Og}).then(({injectStyles:e})=>{e()}),exports.ACCESS_TOKEN_KEY=w,exports.STORAGE_STATE_KEY=b,exports.Storage=v,exports.WALLET_TYPE_KEY=y,exports.WalletClient=hh,exports.WalletProvider=function({children:e,config:t}){var n,r,s,a,i,c;const u=o.useRef(null);u.current||(u.current=new hh(t));const l=u.current,d=o.useRef(null!==(n=t.modalManager)&&void 0!==n?n:null),[f,h]=o.useReducer(jg,{..._g,enableEmail:null===(r=t.enableEmail)||void 0===r||r,enablePhone:null!==(s=t.enablePhone)&&void 0!==s&&s,enableGoogle:null===(a=t.enableGoogle)||void 0===a||a,enableTwitter:null!==(i=t.enableTwitter)&&void 0!==i&&i,enablePhantom:null===(c=t.enablePhantom)||void 0===c||c}),{walletInfo:m}=f,g=o.useRef(!1),b=o.useCallback(()=>(d.current||"undefined"==typeof window||(d.current=new Mg),d.current),[]);o.useEffect(()=>{t.modalManager&&(d.current=t.modalManager)},[t.modalManager]),o.useEffect(()=>{!async function(){if(!(m||g.current||f.isInitialized)){g.current=!0;try{const e=await l.reconnect();e&&(h({type:"SET_WALLET_INFO",payload:e}),h({type:"SET_WALLET",payload:l}))}catch(e){console.error("Auto reconnect failed:",e)}finally{h({type:"SET_INITIALIZED",payload:!0})}}}()},[l]),o.useEffect(()=>{const e=async()=>{try{if(x.isConnecting)return;h({type:"SET_CONNECTING",payload:!0});const e=new URLSearchParams(window.location.search),t=e.get("wallet_oauth_provider"),n=e.get("wallet_oauth_state"),r=e.get("wallet_oauth_code");if(t&&n&&r){const e=function(e){const t=e.toLowerCase(),n=sessionStorage.getItem(`${t}_oauthCodeVerifier`);if(!n)return null;const r=JSON.parse(n);return sessionStorage.removeItem(`${t}_oauthCodeVerifier`),Date.now()-r.timestamp>6e5?null:{codeVerifier:r.code_verifier,codeChallenge:r.code_challenge}}(t);if(!e)throw new Error("No code verifier found");const{codeVerifier:o,codeChallenge:s}=e;let a;if("twitter"===t)a="TwitterOAuth";else{if("google"!==t)throw new Error("Unsupported provider");a="GoogleOAuth"}b().showLoginModal({client:l,isLoading:!0,enableEmail:f.enableEmail,enablePhone:f.enablePhone,enableGoogle:f.enableGoogle,enableTwitter:f.enableTwitter,enablePhantom:f.enablePhantom});const i=await l.oauthLogin(a,{state:n,code:r,code_verifier:o});if(i){h({type:"SET_WALLET_INFO",payload:i}),h({type:"SET_WALLET",payload:l});const e=new URL(window.location.href);e.searchParams.delete("wallet_oauth_provider"),e.searchParams.delete("wallet_oauth_state"),e.searchParams.delete("wallet_oauth_code"),history.replaceState(null,"",e.toString())}}}catch(e){console.log("oauth login error: ",e)}finally{h({type:"SET_CONNECTING",payload:!1}),await b().hideModal()}};return e(),window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)}},[]);const y=o.useCallback(async()=>{try{h({type:"SET_CONNECTING",payload:!0});b().showLoginModal({client:l,enableEmail:f.enableEmail,enablePhone:f.enablePhone,enableGoogle:f.enableGoogle,enableTwitter:f.enableTwitter,enablePhantom:f.enablePhantom,onClose:()=>{h({type:"SET_CONNECTING",payload:!1})},onLogin:e=>{h({type:"SET_CONNECTING",payload:!1}),h({type:"SET_WALLET_INFO",payload:e}),h({type:"SET_WALLET",payload:l})}})}catch(e){h({type:"SET_ERROR",payload:e instanceof Error?e.message:"Failed to connect"}),h({type:"SET_CONNECTING",payload:!1})}},[l]),w=o.useCallback(async()=>{await l.logout(),h({type:"RESET"})},[l]);o.useEffect(()=>{var e;"phantom"===v.getWalletType()&&l.getPhantomAdapter()&&(null===(e=l.getPhantomAdapter())||void 0===e||e.on("disconnect",()=>{w()}))},[l]);const x={...f,connect:y,disconnect:w};return p.default.createElement(Fg.Provider,{value:x},e)},exports.injectStyles=Cg,exports.isVersionedTransaction=g,exports.theme=rg,exports.useActiveWallet=function(){const{wallet:e}=Lg();return{wallet:e}},exports.useCoinbaseOnramp=function(){const{wallet:e}=Lg(),t=null==e?void 0:e.solanaAddress,n=null==e?void 0:e.ethereumAddress;return{getCoinbaseOnrampUrl:async(r,o="solana",s)=>{if(!e||!t||!n)throw new Error("Wallet not found");const a="solana"===o?t:n;return pf({sessionToken:await(null==e?void 0:e.fetchCoinbaseToken(a,o)),presetCryptoAmount:Number(r),redirectUrl:s||window.location.href})}}},exports.useConnect=function(){const{connect:e,disconnect:t,isConnecting:n}=Lg();return{connect:e,disconnect:t,isConnecting:n}},exports.useLoginModal=Rg,exports.useWallet=Lg,exports.useWalletStatus=function(){const{error:e,session:t,isInitialized:n,wallet:r}=Lg();return{isAuthenticated:null!==r,authenticated:null!==r,error:e,session:t,isInitialized:n,ready:n}};
297
297
  //# sourceMappingURL=index.cjs.map