@zerodev/wallet-react-ui 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_types/auth/index.d.ts +2 -1
- package/dist/_types/auth/index.d.ts.map +1 -1
- package/dist/_types/shared/components/PoweredBy/index.d.ts.map +1 -1
- package/dist/_types/shared/components/Screen/index.d.ts +2 -1
- package/dist/_types/shared/components/Screen/index.d.ts.map +1 -1
- package/dist/_types/shared/components/TopNav/index.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +353 -334
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +3 -3
- package/src/auth/index.tsx +3 -0
- package/src/shared/components/PoweredBy/index.tsx +5 -4
- package/src/shared/components/Screen/index.tsx +24 -4
- package/src/shared/components/TopNav/index.tsx +4 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare function AuthFlow({ onClose: userOnClose, }?: {
|
|
1
|
+
export declare function AuthFlow({ onClose: userOnClose, size, }?: {
|
|
2
2
|
onClose?: (() => void) | undefined;
|
|
3
|
+
size?: 'sm' | 'md' | 'lg' | undefined;
|
|
3
4
|
}): import("react/jsx-runtime").JSX.Element | null;
|
|
4
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.tsx"],"names":[],"mappings":"AA+DA,wBAAgB,QAAQ,CAAC,EACvB,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/index.tsx"],"names":[],"mappings":"AA+DA,wBAAgB,QAAQ,CAAC,EACvB,OAAO,EAAE,WAAW,EACpB,IAAI,GACL,GAAE;IACD,OAAO,CAAC,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAAA;IAClC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;CACjC,kDAyCL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/components/PoweredBy/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,wBAAgB,SAAS,CAAC,EACxB,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/components/PoweredBy/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAE1C,wBAAgB,SAAS,CAAC,EACxB,SAAS,EACT,KAAK,GACN,EAAE;IACD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,aAAa,CAAA;CACtB,2CAiBA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
-
export declare function Screen({ children, className, contentClassName, style, topNav, }: {
|
|
2
|
+
export declare function Screen({ children, className, contentClassName, size, style, topNav, }: {
|
|
3
3
|
children: ReactNode;
|
|
4
4
|
className?: string | undefined;
|
|
5
5
|
contentClassName?: string | undefined;
|
|
6
|
+
size?: 'sm' | 'md' | 'lg' | undefined;
|
|
6
7
|
style?: CSSProperties | undefined;
|
|
7
8
|
topNav?: ReactNode;
|
|
8
9
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/components/Screen/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAUrD,wBAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IACjC,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/components/Screen/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAUrD,wBAAgB,MAAM,CAAC,EACrB,QAAQ,EACR,SAAS,EACT,gBAAgB,EAChB,IAAW,EACX,KAAK,EACL,MAAM,GACP,EAAE;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IAC9B,gBAAgB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrC,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,SAAS,CAAA;IACrC,KAAK,CAAC,EAAE,aAAa,GAAG,SAAS,CAAA;IACjC,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB,2CA2DA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/components/TopNav/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,eAAO,MAAM,cAAc,KAAK,CAAA;AAEhC,wBAAgB,MAAM,CAAC,EACrB,MAAM,EACN,OAAO,EACP,KAAK,EACL,IAAI,EACJ,SAAS,GACV,EAAE;IACD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/shared/components/TopNav/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC,eAAO,MAAM,cAAc,KAAK,CAAA;AAEhC,wBAAgB,MAAM,CAAC,EACrB,MAAM,EACN,OAAO,EACP,KAAK,EACL,IAAI,EACJ,SAAS,GACV,EAAE;IACD,MAAM,CAAC,EAAE,MAAM,IAAI,CAAA;IACnB,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,2CA8BA"}
|
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("react"),b=require("zustand"),d=require("@zerodev/react-ui"),q=require("wagmi"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("react"),b=require("zustand"),d=require("@zerodev/react-ui"),q=require("wagmi"),j=require("@zerodev/wallet-react"),X=require("zustand/middleware"),H=52;function Y({onBack:t,onClose:o,title:r,logo:n,className:s}){return e.jsxs("div",{className:d.cn("zd:absolute zd:top-4 zd:left-0 zd:right-0 zd:flex zd:flex-row zd:items-center zd:justify-between",s),style:{height:`calc(${H/4} * var(--zd-spacing))`},children:[t?e.jsx(d.IconButton,{iconName:"chevronLeft",onClick:t}):e.jsx("div",{className:"zd:h-13 zd:w-13"}),n&&e.jsx("div",{className:"zd:absolute zd:left-0 zd:right-0 zd:flex zd:items-center zd:justify-center zd:pointer-events-none",children:n}),r&&e.jsx("div",{className:"zd:absolute zd:left-0 zd:right-0 zd:flex zd:items-center zd:justify-center zd:pointer-events-none",children:e.jsx(d.Text,{className:"zd:text-body1",children:r})}),e.jsx(d.IconButton,{iconName:"x",onClick:o})]})}function J({layer:t,rect:o}){const{id:r,matrix:n,fillOpacity:s,stops:c}=t;return e.jsxs(e.Fragment,{children:[e.jsx("defs",{children:e.jsx("radialGradient",{id:r,cx:"0",cy:"0",r:"1",gradientUnits:"userSpaceOnUse",gradientTransform:`matrix(${n.join(" ")})`,children:c.map((i,u)=>e.jsx("stop",{offset:i.offset,stopColor:i.color,stopOpacity:i.opacity},i.color+u.toString()))})}),e.jsx("rect",{x:o.x,y:o.y,width:o.width,height:o.height,fill:`url(#${r})`,fillOpacity:s})]})}const Z="-6 -6 412 812";function Q(){return e.jsx("div",{className:"zd:absolute zd:inset-0 zd:z-0 zd:rounded-4xl zd:pointer-events-none",children:e.jsx("svg",{width:"100%",height:"100%",viewBox:Z,preserveAspectRatio:"none",role:"img","aria-label":"Decorative gradient background",children:e.jsx("rect",{x:"-6",y:"-6",width:"412",height:"812",fill:"#FBF7F2"})})})}function ee(){const t=h.useId(),o=[{id:`${t}-blue`,matrix:[1850,0,0,645,381.44,0],fillOpacity:1,stops:[{offset:0,color:"#45ABFB",opacity:.66},{offset:.4615,color:"#1E9AFB",opacity:.35},{offset:1,color:"#45ABFB",opacity:0}]},{id:`${t}-offwhite-tr`,matrix:[55.28,0,0,773.36,386.68,13.28],fillOpacity:1,stops:[{offset:0,color:"#F7F5F0",opacity:.1},{offset:1,color:"#45ABFB",opacity:0}]},{id:`${t}-warmgrey`,matrix:[326.72,0,0,855.52,0,50.32],fillOpacity:1,stops:[{offset:0,color:"#E3CFC3",opacity:1},{offset:1,color:"#E3CFC3",opacity:0}]},{id:`${t}-orange`,matrix:[580,0,0,380,200,835],fillOpacity:1,stops:[{offset:0,color:"#EE6C2E",opacity:.8},{offset:.55,color:"#EE6C2E",opacity:.6},{offset:1,color:"#EE6C2E",opacity:.15}]},{id:`${t}-peach`,matrix:[520,0,0,560,180,830],fillOpacity:1,stops:[{offset:0,color:"#FAC8AC",opacity:1},{offset:1,color:"#F27B3E",opacity:0}]},{id:`${t}-white-bl`,matrix:[90.72,0,0,550.48,38.04,702.64],fillOpacity:1,stops:[{offset:0,color:"white",opacity:.58},{offset:1,color:"white",opacity:0}]}];return e.jsx("div",{className:"zd:absolute zd:inset-0 zd:z-0 zd:rounded-4xl zd:pointer-events-none zd:overflow-hidden",children:e.jsxs("svg",{width:"100%",height:"100%",viewBox:"0 0 400 800",preserveAspectRatio:"none",role:"presentation",children:[o.map(r=>e.jsx(J,{layer:r,rect:{x:0,y:0,width:400,height:800}},r.id)),e.jsx("defs",{children:e.jsxs("linearGradient",{id:`${t}-vfade`,x1:"0",y1:"0",x2:"0",y2:"800",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0",stopColor:"white",stopOpacity:"0.55"}),e.jsx("stop",{offset:"0.45",stopColor:"white",stopOpacity:"0.52"}),e.jsx("stop",{offset:"0.65",stopColor:"white",stopOpacity:"0.5"}),e.jsx("stop",{offset:"0.85",stopColor:"white",stopOpacity:"0.5"}),e.jsx("stop",{offset:"1",stopColor:"white",stopOpacity:"0.5"})]})}),e.jsx("rect",{x:"0",y:"0",width:"400",height:"800",fill:`url(#${t}-vfade)`}),e.jsx("defs",{children:e.jsxs("linearGradient",{id:`${t}-bluefade`,x1:"0",y1:"800",x2:"120",y2:"640",gradientUnits:"userSpaceOnUse",children:[e.jsx("stop",{offset:"0",stopColor:"#A7B8E2",stopOpacity:"1"}),e.jsx("stop",{offset:"0.33",stopColor:"#A7B8E2",stopOpacity:"0.7"}),e.jsx("stop",{offset:"0.66",stopColor:"#A7B8E2",stopOpacity:"0.35"}),e.jsx("stop",{offset:"1",stopColor:"#A7B8E2",stopOpacity:"0"})]})}),e.jsx("rect",{x:"0",y:"0",width:"400",height:"800",fill:`url(#${t}-bluefade)`})]})})}function te(){const t=h.useId(),o=[{id:`${t}-g6`,cx:.9536,cy:0,rx:.9385,ry:1.2256,stops:[{offset:0,color:"#45ABFB",opacity:.6},{offset:.4615,color:"#1E9AFB",opacity:.32},{offset:1,color:"#45ABFB",opacity:0}]},{id:`${t}-g5`,cx:.9667,cy:.0166,rx:.1382,ry:.9667,stops:[{offset:0,color:"#F7F5F0",opacity:.1},{offset:1,color:"#45ABFB",opacity:0}]},{id:`${t}-g4`,cx:0,cy:.0629,rx:.8168,ry:1.0694,stops:[{offset:0,color:"#E3CFC3",opacity:1},{offset:1,color:"#E3CFC3",opacity:0}]},{id:`${t}-g3`,cx:.0393,cy:1,rx:1.0628,ry:1.0303,stops:[{offset:0,color:"#FF6B1F",opacity:1},{offset:.476,color:"#E76000",opacity:.72},{offset:1,color:"#E76000",opacity:0}]},{id:`${t}-g2`,cx:.3476,cy:1,rx:.9614,ry:.338,stops:[{offset:0,color:"#FAC8AC",opacity:.7},{offset:1,color:"#F27B3E",opacity:0}]},{id:`${t}-g1`,cx:.0951,cy:.8783,rx:.2268,ry:.6881,stops:[{offset:0,color:"#FFFFFF",opacity:.58},{offset:1,color:"#FFFFFF",opacity:0}]}];return e.jsx("div",{className:"zd:absolute zd:inset-0 zd:z-0 zd:rounded-4xl zd:pointer-events-none zd:overflow-hidden",children:e.jsxs("svg",{width:"100%",height:"100%",preserveAspectRatio:"none",role:"presentation",children:[e.jsx("rect",{width:"100%",height:"100%",fill:"#130E0B"}),e.jsx("defs",{children:o.map(r=>e.jsx("radialGradient",{id:r.id,cx:`${r.cx/r.rx*100}%`,cy:`${r.cy/r.ry*100}%`,r:"100%",gradientUnits:"objectBoundingBox",gradientTransform:`scale(${r.rx}, ${r.ry})`,children:r.stops.map((n,s)=>e.jsx("stop",{offset:n.offset,stopColor:n.color,stopOpacity:n.opacity},n.color+s.toString()))},r.id))}),o.map(r=>e.jsx("rect",{width:"100%",height:"100%",fill:`url(#${r.id})`},`${r.id}-rect`))]})})}const ne=H+16;function se({children:t,className:o,contentClassName:r,size:n="lg",style:s,topNav:c}){return e.jsxs("div",{"data-zd-size":n,className:d.cn("zd:relative zd:flex zd:flex-col zd:text-left","zd:w-100 zd:h-202.5 zd:max-w-full zd:max-h-full zd:overflow-hidden zd:rounded-[38px]",o),style:s,children:[e.jsx(te,{}),e.jsxs("div",{className:d.cn("zd:flex zd:flex-1 zd:flex-col zd:m-1.5 zd:px-4 zd:overflow-hidden zd:rounded-4xl zd:relative",r),style:{clipPath:"inset(0 round 32px)"},children:[e.jsx(Q,{}),e.jsx(ee,{}),e.jsxs("div",{className:"zd:relative zd:z-10 zd:flex zd:flex-1 zd:flex-col zd:min-h-0",children:[c,e.jsx("div",{className:"zd:flex zd:flex-1 zd:flex-col zd:min-h-0 zd:overflow-y-auto zd:overflow-x-hidden",style:{paddingTop:`calc(${ne/4} * var(--zd-spacing))`},children:t})]})]})]})}const re=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/error.webp").href:new URL("error.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),oe=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/loading.webp").href:new URL("loading.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),ie=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/send.webp").href:new URL("send.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),ae=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/success.webp").href:new URL("success.webp",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href),de={error:re,loading:oe,send:ie,success:ae};function I({imageName:t,title:o,children:r,className:n}){return e.jsxs("div",{className:d.cn("zd:flex zd:flex-col zd:gap-8 zd:items-center",n),children:[e.jsx("img",{src:de[t],alt:t,className:"zd:w-[118px] zd:h-[118px] zd:bg-transparent"}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:items-center",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center zd:whitespace-pre-wrap",children:o}),e.jsx(d.Text,{className:"zd:text-center zd:whitespace-pre-wrap",children:r})]})]})}function G(){const o=q.useConfig().connectors.find(r=>r.id==="zerodev-wallet");if(!o||!("getKitStore"in o))throw new Error("useKitStore must be used with the zeroDevWallet connector");return o.getKitStore()}function C(){const t=G(),o=b.useStore(t,l=>l.auth.step),r=b.useStore(t,l=>l.auth.stepHistory),n=b.useStore(t,l=>l.auth.email),s=b.useStore(t,l=>l.auth.otpId),c=b.useStore(t,l=>l.auth.otpEncryptionTargetBundle),i=b.useStore(t,l=>l.auth.enabledMethods),u=b.useStore(t,l=>l.auth.config);return{step:o,email:n,otpId:s,otpEncryptionTargetBundle:c,enabledMethods:i,config:u,goToStep:t.getState().auth.goToStep,goBack:r.length>0?t.getState().auth.goBack:null,reset:t.getState().auth.reset,setEmail:t.getState().auth.setEmail,setOtpSession:t.getState().auth.setOtpSession,clearOtpSession:t.getState().auth.clearOtpSession}}function A({className:t,style:o}){return e.jsxs("div",{className:d.cn("zd:gap-1.5 zd:flex zd:flex-row zd:items-center",t),children:[e.jsx(d.Text,{children:"Powered by"}),e.jsx(d.ZeroDevLogo,{variant:"lockup",tone:"black",className:"zd:h-4.5 zd:w-auto",style:o})]})}function ce(){const{email:t,setOtpSession:o}=C(),{mutateAsync:r,isPending:n}=j.useSendMagicLink(),[s,c]=h.useState(60),i=s<=0&&!n;h.useEffect(()=>{if(s<=0)return;const l=setInterval(()=>{c(p=>Math.max(0,p-1))},1e3);return()=>{clearInterval(l)}},[s]);const u=async()=>{if(!(!t||!i))try{const{otpId:l,otpEncryptionTargetBundle:p}=await r({email:t});o({otpId:l,otpEncryptionTargetBundle:p}),c(60)}catch{}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsxs(I,{imageName:"send",title:`Check your email!
|
|
2
2
|
An Email is On Its Way`,children:["We've sent a magic link to"," ",e.jsx(d.Text,{as:"span",className:"zd:text-solarOrange",children:t}),`
|
|
3
|
-
`,"Please open the email and click the link to log in."]}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(d.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!i,onClick:u,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:i?"Resend":`Resend in ${r} ${r===1?"second":"seconds"}`})]})})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function le(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).has("code")}function B(){if(typeof window>"u")return;const t=new URL(window.location.href);t.searchParams.has("code")&&(t.searchParams.delete("code"),window.history.replaceState(null,"",t.toString()))}function ue({title:t="Oops, something went wrong",message:n="We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request.",showRetry:o=!1,showChooseAnother:s=!0}){const{goToStep:r,goBack:l,reset:i}=C(),u=l??(()=>r("sign-up"));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[e.jsx(F,{imageName:"error",title:t,children:n}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-1",children:[o&&e.jsx(d.Button,{action:"primary",text:"Try again",onClick:u}),s&&e.jsx(d.Button,{action:o?"secondary":"primary",onClick:()=>{B(),r("sign-up")},text:"Choose another sign-in method"}),!o&&!s&&e.jsx(d.Button,{action:"primary",text:"Start over",onClick:i})]})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const pe=4,fe=8,he=6;function xe(t){return Math.max(pe,Math.min(fe,t))}function me({char:t,isFocused:n}){return e.jsx(d.Wrapper,{"data-testid":"code-input-box","data-active":n||void 0,className:d.cn("zd:h-16 zd:w-14 zd:rounded-lg zd:flex zd:items-center zd:justify-center",n&&"zd:border-[1.5px] zd:border-greyScale"),children:e.jsx(d.Text,{className:"zd:text-h2",children:t})})}function ze({onChange:t,onComplete:n,disabled:o=!1,error:s=!1,autoFocus:r=!1,length:l=he,"data-testid":i}){const u=xe(l),c=h.useMemo(()=>Array.from({length:u},(f,z)=>({id:`char-${z}`,index:z})),[u]),[p,j]=h.useState(""),[m,S]=h.useState(!1),E=h.useRef(null);h.useEffect(()=>{var f;r&&!o&&((f=E.current)==null||f.focus())},[r,o]),h.useEffect(()=>{j(f=>f.slice(0,u))},[u]);const v=f=>{const z=f.slice(0,u).toUpperCase();j(z),t==null||t(z),z.length===u&&setTimeout(()=>{var I;n==null||n(z),(I=E.current)==null||I.blur()},0)};return e.jsxs("button",{type:"button",className:"zd:flex zd:flex-row zd:items-center zd:justify-between zd:gap-2 zd:w-full zd:cursor-text",onClick:()=>{var f;return(f=E.current)==null?void 0:f.focus()},disabled:o,"data-testid":i,children:[e.jsx("input",{ref:E,value:p,onChange:f=>v(f.target.value),onFocus:()=>S(!0),onBlur:()=>S(!1),maxLength:u,disabled:o,className:"zd:absolute zd:opacity-0 zd:pointer-events-none",style:{position:"absolute",opacity:0},"aria-label":"Verification code"}),c.map(f=>e.jsx(me,{char:p[f.index]??"",isFocused:!s&&m&&f.index===p.length},f.id))]})}function ge(){const{email:t,otpId:n,otpEncryptionTargetBundle:o,setOtpSession:s,clearOtpSession:r,goToStep:l,config:i}=C(),{mutateAsync:u,isPending:c}=y.useSendOTP(),{mutateAsync:p,isPending:j}=y.useVerifyOTP(),[m,S]=h.useState(""),[E,v]=h.useState(!1),[f,z]=h.useState(60);h.useEffect(()=>{if(f<=0)return;const w=setInterval(()=>{z(T=>Math.max(0,T-1))},1e3);return()=>clearInterval(w)},[f]);const I=async()=>{var w,T;if(!(!m.trim()||!n||!o)){v(!1);try{await p({otpId:n,code:m.trim(),otpEncryptionTargetBundle:o}),r(),l("authenticated"),(w=i==null?void 0:i.onSuccess)==null||w.call(i)}catch(L){v(!0),(T=i==null?void 0:i.onError)==null||T.call(i,L)}}},g=w=>{S(w)},P=async()=>{if(!(!t||f>0||c))try{const{otpId:w,otpEncryptionTargetBundle:T}=await u({email:t});s({otpId:w,otpEncryptionTargetBundle:T}),z(60),v(!1)}catch{v(!0)}},O=f<=0&&!c;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center zd:items-center",children:[e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Enter verification code"}),e.jsxs(d.Text,{className:"zd:text-center",children:["Enter the code from the email we sent to"," ",e.jsx(d.Text,{className:"zd:text-solarOrange",children:t})]})]}),e.jsx(ze,{onComplete:g,onChange:()=>v(!1),disabled:j,error:E,autoFocus:!0}),e.jsx(d.Button,{text:"Confirm code",onClick:I,disabled:!m.trim()||j}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(d.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!O,onClick:P,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:O?"Resend":`Resend in ${f} ${f===1?"second":"seconds"}`})]})})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function ye({termsAndConditionsUrl:t,privacyPolicyUrl:n,agreedToTerms:o,setAgreedToTerms:s,highlight:r=!1}){const l=!!(t||n);return e.jsxs("div",{className:"zd:flex zd:flex-col zd:items-center zd:gap-5",children:[l&&e.jsxs("div",{className:`zd:flex zd:flex-row zd:items-center zd:gap-2 zd:rounded-md zd:p-2 zd:transition-colors ${r?"zd:border zd:border-negative":"zd:border zd:border-transparent"}`,children:[e.jsx("input",{type:"checkbox",checked:o,onChange:i=>s(i.target.checked),className:"zd:cursor-pointer zd:[color-scheme:light]"}),e.jsxs(d.Text,{className:"zd:flex-1",children:["I agree to the"," ",t&&e.jsx(d.Text,{as:"a",href:t,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Terms & Conditions"}),t&&n&&" and ",n&&e.jsx(d.Text,{as:"a",href:n,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Privacy Policy"})]})]}),e.jsx(A,{})]})}const je=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function R(t){return je.test(t.trim())}const we=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/blob.webm").href:new URL("blob.webm",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href);function Se({className:t}){return e.jsx("video",{className:t,style:{aspectRatio:"1 / 1"},src:we,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,"aria-hidden":"true",tabIndex:-1})}function U(t){return t instanceof Error?t.name==="AbortError"||t.name==="NotAllowedError"?!0:t.message.toLowerCase().includes("oauth popup was closed"):!1}function ve(){const{goToStep:t,setEmail:n,setOtpSession:o,config:s,enabledMethods:r}=C(),[l,i]=h.useState(!1),[u,c]=h.useState(!1),[p,j]=h.useState(""),m=(s==null?void 0:s.emailAuthMethod)==="otp",{mutateAsync:S,isPending:E}=y.useSendOTP(),{mutateAsync:v,isPending:f}=y.useSendMagicLink(),z=E||f,[I,g]=h.useState(null),{mutateAsync:P,isPending:O}=y.useAuthenticateOAuth({mutation:{onSuccess:async()=>{var a;t("authenticated"),(a=s==null?void 0:s.onSuccess)==null||a.call(s)},onError:a=>{var x;(x=s==null?void 0:s.onError)==null||x.call(s,a)}}}),{mutate:w,isPending:T}=y.useRegisterPasskey({mutation:{onSuccess:()=>{var a;t("authenticated"),(a=s==null?void 0:s.onSuccess)==null||a.call(s)},onError:a=>{var x;U(a)||g(a instanceof Error?a.message:String(a)),(x=s==null?void 0:s.onError)==null||x.call(s,a)}}}),{mutate:L,isPending:W}=y.useLoginPasskey({mutation:{onSuccess:()=>{var a;t("authenticated"),(a=s==null?void 0:s.onSuccess)==null||a.call(s)},onError:a=>{var x;U(a)||g(a instanceof Error?a.message:String(a)),(x=s==null?void 0:s.onError)==null||x.call(s,a)}}}),N=O||z||T||W,k=!!(s!=null&&s.termsAndConditionsUrl||s!=null&&s.privacyPolicyUrl)&&!l,V=()=>{if(!N){if(k){c(!0);return}g(null),w()}},D=()=>{if(!N){if(k){c(!0);return}g(null),L()}},K=async()=>{if(k){c(!0);return}g(null);try{await P({provider:"google"})}catch(a){const x=a instanceof Error?a.message:String(a);U(a)||g(x)}},M=m?async()=>{if(!(!p||N)&&R(p)){if(k){c(!0);return}g(null);try{const{otpId:a,otpEncryptionTargetBundle:x}=await S({email:p});n(p),o({otpId:a,otpEncryptionTargetBundle:x}),t("otp-input")}catch(a){g(a instanceof Error?a.message:"Failed to send verification code")}}}:async()=>{if(!(!p||N)&&R(p)){if(k){c(!0);return}g(null);try{const{otpId:a,otpEncryptionTargetBundle:x}=await v({email:p});n(p),o({otpId:a,otpEncryptionTargetBundle:x}),t("email-verification")}catch(a){g(a instanceof Error?a.message:"Failed to send verification code")}}};return I?e.jsx("div",{className:"zd:flex zd:items-center zd:justify-center zd:h-full",children:e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:max-w-md",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Error occurred"}),e.jsx(d.Text,{className:"zd:text-center zd:text-red-500",children:I}),e.jsx(d.Button,{action:"primary",text:"Try again",onClick:()=>g(null)})]})}):e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-between zd:pb-4 zd:overflow-y-auto zd:overflow-x-hidden",children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-center",children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:items-center",children:[e.jsx("div",{className:"zd:w-full zd:px-16 zd:py-4",children:e.jsx(Se,{className:"zd:w-full zd:pointer-events-none zd:select-none"})}),e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Continue to your wallet"}),e.jsx(d.Text,{className:"zd:mt-2 zd:text-center zd:text-greyScale/50",children:"Choose a sign-in method to proceed"})]}),e.jsxs("div",{className:"zd:mt-6 zd:flex zd:flex-col zd:gap-4 zd:mb-4",children:[r.includes("passkey")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:gap-2",children:[e.jsx(d.Button,{action:"secondary",text:"Create a passkey",iconName:"key",trailIcon:!0,disabled:N,onClick:V}),e.jsx(d.Button,{action:"secondary",text:"Log in with passkey",iconName:"key",trailIcon:!0,disabled:N,onClick:D})]}),e.jsxs("div",{className:"zd:flex zd:items-center zd:gap-3",children:[e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"}),e.jsx(d.Text,{className:"zd:text-body3",children:"or"}),e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"})]})]}),e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:gap-2",children:[r.includes("google")&&e.jsx(d.ListItem,{iconName:"google",title:"Google",chevron:!0,className:"zd:rounded-3xl",disabled:N,onClick:K}),r.includes("email")&&e.jsx(d.Input,{iconName:"email",placeholder:"Enter your email",value:p,onChange:a=>j(a.target.value),type:"email",autoCapitalize:"none",autoComplete:"email",disabled:N,variant:"listItemStyle",containerClassName:"zd:rounded-3xl",onKeyDown:a=>{a.key==="Enter"&&p&&!N&&M()},children:z?e.jsx("div",{className:"zd:w-13 zd:h-13 zd:flex zd:items-center zd:justify-center",children:e.jsx("div",{className:"zd:w-5 zd:h-5 zd:border-2 zd:border-solarOrange zd:border-t-transparent zd:rounded-full zd:animate-spin"})}):e.jsx("button",{type:"button",disabled:!R(p)||k,className:`zd:w-13 zd:h-13 zd:rounded-2xl zd:flex zd:items-center zd:justify-center zd:transition-colors ${R(p)&&!k?"zd:cursor-pointer":"zd:cursor-not-allowed zd:opacity-50"}`,onClick:()=>M(),children:e.jsx(d.Icon,{name:"chevronRight",className:"zd:text-greyScale"})})})]})]})]}),e.jsx("div",{className:"zd:px-4",children:e.jsx(ye,{termsAndConditionsUrl:s==null?void 0:s.termsAndConditionsUrl,privacyPolicyUrl:s==null?void 0:s.privacyPolicyUrl,agreedToTerms:l,setAgreedToTerms:a=>{i(a),a&&c(!1)},highlight:u})})]})}function Ne(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("code")}function be(){const{otpId:t,otpEncryptionTargetBundle:n,goToStep:o,clearOtpSession:s,config:r}=C(),[l]=h.useState(Ne),[i,u]=h.useState(null),c=h.useRef(!1),{mutate:p,isPending:j}=y.useVerifyMagicLink({mutation:{onSuccess:async()=>{var m;s(),o("authenticated"),(m=r==null?void 0:r.onSuccess)==null||m.call(r)},onError:m=>{var S;u(m),(S=r==null?void 0:r.onError)==null||S.call(r,m)}}});return h.useEffect(()=>{if(!(c.current||!l)){if(c.current=!0,!t||!n){B(),o(null);return}p({otpId:t,code:l,otpEncryptionTargetBundle:n})}},[t,n,l,p,o]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[!i&&j&&e.jsx(F,{imageName:"loading",title:"Verifying Your Email",children:"Please wait while we securely connect your wallet."}),!i&&!l&&!j&&e.jsxs(e.Fragment,{children:[e.jsxs(F,{imageName:"error",title:"Invalid Link",children:["This verification link is invalid or incomplete.",e.jsx("br",{}),"Please check your email and try again with the correct link."]}),e.jsx(d.Button,{action:"primary",onClick:()=>{B(),o("sign-up")},text:"Choose another sign-in method"})]}),i!=null&&e.jsxs(e.Fragment,{children:[e.jsx(F,{imageName:"error",title:"Oops, something went wrong",children:"We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request."}),e.jsx(d.Button,{action:"primary",onClick:()=>{B(),o("sign-up")},text:"Choose another sign-in method"})]})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function Ee(){const{goToStep:t}=C(),{connect:n,connectors:o,isPending:s}=q.useConnect(),r=o.filter(i=>i.id!=="zerodev-wallet"),l=i=>{n({connector:i},{onSuccess:()=>{t(null)}})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Select your wallet"}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-2",children:r.length===0?e.jsx(d.Text,{className:"zd:text-center",children:"No wallets detected. Install a browser wallet extension to continue."}):r.map(i=>e.jsx(d.ListItem,{title:i.name,iconName:"walletOutline",...i.icon?{imageUri:i.icon}:{},disabled:s,onClick:()=>l(i),className:"zd:rounded-3xl"},i.uid))})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const Te={"wallet-selection":"Choose your wallet"};function Ce(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(F,{imageName:"loading",title:"Authenticating...",children:"Please wait while we complete the OAuth authentication."})})}function Ie(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(F,{imageName:"loading",title:"Passkey authentication",children:"Please authenticate with your passkey."})})}function ke(t){switch(t){case"sign-up":return e.jsx(ve,{});case"email-verification":return e.jsx(ce,{});case"otp-input":return e.jsx(ge,{});case"verifying-otp":return e.jsx(be,{});case"oauth-in-progress":return e.jsx(Ce,{});case"passkey-prompt":return e.jsx(Ie,{});case"wallet-selection":return e.jsx(Ee,{});case"error":return e.jsx(ue,{});default:return null}}function Fe({onClose:t}={}){const{step:n,goToStep:o,goBack:s,reset:r}=C(),l=b.useStore(G(),p=>p.logo);h.useEffect(()=>{n===null&&le()&&o("verifying-otp")},[n,o]);const i=ke(n);if(!i)return null;const u=()=>{B(),r(),t==null||t()},c=n?Te[n]:void 0;return e.jsx(ne,{contentClassName:n==="sign-up"?"zd:px-0":void 0,topNav:e.jsx(Y,{...s!==null&&{onBack:s},onClose:u,...c&&{title:c},...n==="sign-up"&&{...l&&{logo:l},className:"zd:px-4"}}),children:i})}const $="zerodev:auth:otpSession";function Ae(){if(typeof window>"u")return null;try{const t=window.localStorage.getItem($);if(!t)return null;const n=JSON.parse(t);return!(n!=null&&n.otpId)||!(n!=null&&n.otpEncryptionTargetBundle)?null:n}catch{return null}}function Be(t){if(!(typeof window>"u"))try{window.localStorage.setItem($,JSON.stringify(t))}catch{}}function _(){if(!(typeof window>"u"))try{window.localStorage.removeItem($)}catch{}}const Oe=(t,n,o)=>({auth:{step:null,stepHistory:[],enabledMethods:[],email:null,otpId:null,otpEncryptionTargetBundle:null,config:null,initialize:s=>{const r=Ae();t(l=>({auth:{...l.auth,config:s,enabledMethods:s.enabledMethods,...r&&{otpId:r.otpId,otpEncryptionTargetBundle:r.otpEncryptionTargetBundle}}}))},goToStep:s=>{t(r=>({auth:{...r.auth,step:s,stepHistory:r.auth.step===null?r.auth.stepHistory:[...r.auth.stepHistory,r.auth.step]}}))},goBack:()=>{const{auth:s}=n();if(s.stepHistory.length===0)return;const r=[...s.stepHistory],l=r.pop();t(i=>({auth:{...i.auth,step:l,stepHistory:r}}))},reset:()=>{_(),t(s=>({auth:{...s.auth,step:null,stepHistory:[],email:null,otpId:null,otpEncryptionTargetBundle:null}}))},setEmail:s=>{t(r=>({auth:{...r.auth,email:s}}))},setOtpSession:({otpId:s,otpEncryptionTargetBundle:r})=>{Be({otpId:s,otpEncryptionTargetBundle:r}),t(l=>({auth:{...l.auth,otpId:s,otpEncryptionTargetBundle:r}}))},clearOtpSession:()=>{_(),t(s=>({auth:{...s.auth,otpId:null,otpEncryptionTargetBundle:null}}))}}}),Re=(t={})=>b.create()(X.subscribeWithSelector((n,o,s)=>({pendingRequests:[],userConfirmationListenerActive:!1,logo:t.logo??null,addPendingRequest:r=>n(l=>({pendingRequests:[...l.pendingRequests,r]})),removePendingRequest:r=>n(l=>({pendingRequests:l.pendingRequests.filter(i=>i.id!==r)})),clearPendingRequests:()=>n({pendingRequests:[]}),setUserConfirmationListenerActive:r=>n({userConfirmationListenerActive:r}),...Oe(n,o)})));function Pe(t){return new Promise((n,o)=>{const s=t.subscribe(r=>r.auth.step,r=>{r==="authenticated"?(s(),n()):r===null&&(s(),o(new Error("Auth flow dismissed")))})})}function Le(t){var s,r;const n=y.zeroDevWallet(t),o=Re({logo:(s=t.config)==null?void 0:s.logo});return(r=t.config)!=null&&r.auth&&o.getState().auth.initialize(t.config.auth),l=>{const i=n(l);return{...i,async connect(u){var c;try{return await i.connect(u)}catch(p){if(u!=null&&u.isReconnecting||!((c=t.config)!=null&&c.auth)||!(p instanceof y.NotAuthenticatedError))throw p;if(o.getState().auth.step!==null)throw new Error("Auth flow already in progress");return o.getState().auth.goToStep("sign-up"),await Pe(o),i.connect(u)}},async disconnect(){var u,c;await((u=i.disconnect)==null?void 0:u.call(i)),(c=t.config)!=null&&c.auth&&o.getState().auth.reset()},async setup(){var u;await((u=i.setup)==null?void 0:u.call(i)),typeof window>"u"},getKitStore(){return o}}}}exports.AuthFlow=Fe;exports.useAuth=C;exports.zeroDevWallet=Le;
|
|
3
|
+
`,"Please open the email and click the link to log in."]}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(d.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!i,onClick:u,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:i?"Resend":`Resend in ${s} ${s===1?"second":"seconds"}`})]})})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function le(){return typeof window>"u"?!1:new URLSearchParams(window.location.search).has("code")}function B(){if(typeof window>"u")return;const t=new URL(window.location.href);t.searchParams.has("code")&&(t.searchParams.delete("code"),window.history.replaceState(null,"",t.toString()))}function ue({title:t="Oops, something went wrong",message:o="We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request.",showRetry:r=!1,showChooseAnother:n=!0}){const{goToStep:s,goBack:c,reset:i}=C(),u=c??(()=>s("sign-up"));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[e.jsx(I,{imageName:"error",title:t,children:o}),e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-1",children:[r&&e.jsx(d.Button,{action:"primary",text:"Try again",onClick:u}),n&&e.jsx(d.Button,{action:r?"secondary":"primary",onClick:()=>{B(),s("sign-up")},text:"Choose another sign-in method"}),!r&&!n&&e.jsx(d.Button,{action:"primary",text:"Start over",onClick:i})]})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const pe=4,fe=8,he=6;function xe(t){return Math.max(pe,Math.min(fe,t))}function me({char:t,isFocused:o}){return e.jsx(d.Wrapper,{"data-testid":"code-input-box","data-active":o||void 0,className:d.cn("zd:h-16 zd:w-14 zd:rounded-lg zd:flex zd:items-center zd:justify-center",o&&"zd:border-[1.5px] zd:border-greyScale"),children:e.jsx(d.Text,{className:"zd:text-h2",children:t})})}function ze({onChange:t,onComplete:o,disabled:r=!1,error:n=!1,autoFocus:s=!1,length:c=he,"data-testid":i}){const u=xe(c),l=h.useMemo(()=>Array.from({length:u},(f,z)=>({id:`char-${z}`,index:z})),[u]),[p,y]=h.useState(""),[m,S]=h.useState(!1),E=h.useRef(null);h.useEffect(()=>{var f;s&&!r&&((f=E.current)==null||f.focus())},[s,r]),h.useEffect(()=>{y(f=>f.slice(0,u))},[u]);const v=f=>{const z=f.slice(0,u).toUpperCase();y(z),t==null||t(z),z.length===u&&setTimeout(()=>{var k;o==null||o(z),(k=E.current)==null||k.blur()},0)};return e.jsxs("button",{type:"button",className:"zd:flex zd:flex-row zd:items-center zd:justify-between zd:gap-2 zd:w-full zd:cursor-text",onClick:()=>{var f;return(f=E.current)==null?void 0:f.focus()},disabled:r,"data-testid":i,children:[e.jsx("input",{ref:E,value:p,onChange:f=>v(f.target.value),onFocus:()=>S(!0),onBlur:()=>S(!1),maxLength:u,disabled:r,className:"zd:absolute zd:opacity-0 zd:pointer-events-none",style:{position:"absolute",opacity:0},"aria-label":"Verification code"}),l.map(f=>e.jsx(me,{char:p[f.index]??"",isFocused:!n&&m&&f.index===p.length},f.id))]})}function ge(){const{email:t,otpId:o,otpEncryptionTargetBundle:r,setOtpSession:n,clearOtpSession:s,goToStep:c,config:i}=C(),{mutateAsync:u,isPending:l}=j.useSendOTP(),{mutateAsync:p,isPending:y}=j.useVerifyOTP(),[m,S]=h.useState(""),[E,v]=h.useState(!1),[f,z]=h.useState(60);h.useEffect(()=>{if(f<=0)return;const w=setInterval(()=>{z(T=>Math.max(0,T-1))},1e3);return()=>clearInterval(w)},[f]);const k=async()=>{var w,T;if(!(!m.trim()||!o||!r)){v(!1);try{await p({otpId:o,code:m.trim(),otpEncryptionTargetBundle:r}),s(),c("authenticated"),(w=i==null?void 0:i.onSuccess)==null||w.call(i)}catch(L){v(!0),(T=i==null?void 0:i.onError)==null||T.call(i,L)}}},g=w=>{S(w)},P=async()=>{if(!(!t||f>0||l))try{const{otpId:w,otpEncryptionTargetBundle:T}=await u({email:t});n({otpId:w,otpEncryptionTargetBundle:T}),z(60),v(!1)}catch{v(!0)}},O=f<=0&&!l;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center zd:items-center",children:[e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Enter verification code"}),e.jsxs(d.Text,{className:"zd:text-center",children:["Enter the code from the email we sent to"," ",e.jsx(d.Text,{className:"zd:text-solarOrange",children:t})]})]}),e.jsx(ze,{onComplete:g,onChange:()=>v(!1),disabled:y,error:E,autoFocus:!0}),e.jsx(d.Button,{text:"Confirm code",onClick:k,disabled:!m.trim()||y}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-1",children:e.jsxs(d.Text,{className:"zd:text-center",children:["Did not get an email?"," ",e.jsx("button",{type:"button",disabled:!O,onClick:P,className:"zd:cursor-pointer zd:underline zd:disabled:opacity-50 zd:disabled:cursor-not-allowed",children:O?"Resend":`Resend in ${f} ${f===1?"second":"seconds"}`})]})})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function ye({termsAndConditionsUrl:t,privacyPolicyUrl:o,agreedToTerms:r,setAgreedToTerms:n,highlight:s=!1}){const c=!!(t||o);return e.jsxs("div",{className:"zd:flex zd:flex-col zd:items-center zd:gap-5",children:[c&&e.jsxs("div",{className:`zd:flex zd:flex-row zd:items-center zd:gap-2 zd:rounded-md zd:p-2 zd:transition-colors ${s?"zd:border zd:border-negative":"zd:border zd:border-transparent"}`,children:[e.jsx("input",{type:"checkbox",checked:r,onChange:i=>n(i.target.checked),className:"zd:cursor-pointer zd:[color-scheme:light]"}),e.jsxs(d.Text,{className:"zd:flex-1",children:["I agree to the"," ",t&&e.jsx(d.Text,{as:"a",href:t,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Terms & Conditions"}),t&&o&&" and ",o&&e.jsx(d.Text,{as:"a",href:o,target:"_blank",rel:"noopener noreferrer",className:"zd:underline",children:"Privacy Policy"})]})]}),e.jsx(A,{})]})}const je=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function R(t){return je.test(t.trim())}const we=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/blob.webm").href:new URL("blob.webm",document.currentScript&&document.currentScript.tagName.toUpperCase()==="SCRIPT"&&document.currentScript.src||document.baseURI).href);function Se({className:t}){return e.jsx("video",{className:t,style:{aspectRatio:"1 / 1"},src:we,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,"aria-hidden":"true",tabIndex:-1})}function U(t){return t instanceof Error?t.name==="AbortError"||t.name==="NotAllowedError"?!0:t.message.toLowerCase().includes("oauth popup was closed"):!1}function ve(){const{goToStep:t,setEmail:o,setOtpSession:r,config:n,enabledMethods:s}=C(),[c,i]=h.useState(!1),[u,l]=h.useState(!1),[p,y]=h.useState(""),m=(n==null?void 0:n.emailAuthMethod)==="otp",{mutateAsync:S,isPending:E}=j.useSendOTP(),{mutateAsync:v,isPending:f}=j.useSendMagicLink(),z=E||f,[k,g]=h.useState(null),{mutateAsync:P,isPending:O}=j.useAuthenticateOAuth({mutation:{onSuccess:async()=>{var a;t("authenticated"),(a=n==null?void 0:n.onSuccess)==null||a.call(n)},onError:a=>{var x;(x=n==null?void 0:n.onError)==null||x.call(n,a)}}}),{mutate:w,isPending:T}=j.useRegisterPasskey({mutation:{onSuccess:()=>{var a;t("authenticated"),(a=n==null?void 0:n.onSuccess)==null||a.call(n)},onError:a=>{var x;U(a)||g(a instanceof Error?a.message:String(a)),(x=n==null?void 0:n.onError)==null||x.call(n,a)}}}),{mutate:L,isPending:W}=j.useLoginPasskey({mutation:{onSuccess:()=>{var a;t("authenticated"),(a=n==null?void 0:n.onSuccess)==null||a.call(n)},onError:a=>{var x;U(a)||g(a instanceof Error?a.message:String(a)),(x=n==null?void 0:n.onError)==null||x.call(n,a)}}}),N=O||z||T||W,F=!!(n!=null&&n.termsAndConditionsUrl||n!=null&&n.privacyPolicyUrl)&&!c,D=()=>{if(!N){if(F){l(!0);return}g(null),w()}},V=()=>{if(!N){if(F){l(!0);return}g(null),L()}},K=async()=>{if(F){l(!0);return}g(null);try{await P({provider:"google"})}catch(a){const x=a instanceof Error?a.message:String(a);U(a)||g(x)}},M=m?async()=>{if(!(!p||N)&&R(p)){if(F){l(!0);return}g(null);try{const{otpId:a,otpEncryptionTargetBundle:x}=await S({email:p});o(p),r({otpId:a,otpEncryptionTargetBundle:x}),t("otp-input")}catch(a){g(a instanceof Error?a.message:"Failed to send verification code")}}}:async()=>{if(!(!p||N)&&R(p)){if(F){l(!0);return}g(null);try{const{otpId:a,otpEncryptionTargetBundle:x}=await v({email:p});o(p),r({otpId:a,otpEncryptionTargetBundle:x}),t("email-verification")}catch(a){g(a instanceof Error?a.message:"Failed to send verification code")}}};return k?e.jsx("div",{className:"zd:flex zd:items-center zd:justify-center zd:h-full",children:e.jsxs("div",{className:"zd:flex zd:flex-col zd:gap-4 zd:max-w-md",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Error occurred"}),e.jsx(d.Text,{className:"zd:text-center zd:text-red-500",children:k}),e.jsx(d.Button,{action:"primary",text:"Try again",onClick:()=>g(null)})]})}):e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-between zd:pb-4 zd:overflow-y-auto zd:overflow-x-hidden",children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:justify-center",children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:items-center",children:[e.jsx("div",{className:"zd:w-full zd:px-16 zd:py-4",children:e.jsx(Se,{className:"zd:w-full zd:pointer-events-none zd:select-none"})}),e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Continue to your wallet"}),e.jsx(d.Text,{className:"zd:mt-2 zd:text-center zd:text-greyScale/50",children:"Choose a sign-in method to proceed"})]}),e.jsxs("div",{className:"zd:mt-6 zd:flex zd:flex-col zd:gap-4 zd:mb-4",children:[s.includes("passkey")&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:gap-2",children:[e.jsx(d.Button,{action:"secondary",text:"Create a passkey",iconName:"key",trailIcon:!0,disabled:N,onClick:D}),e.jsx(d.Button,{action:"secondary",text:"Log in with passkey",iconName:"key",trailIcon:!0,disabled:N,onClick:V})]}),e.jsxs("div",{className:"zd:flex zd:items-center zd:gap-3",children:[e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"}),e.jsx(d.Text,{className:"zd:text-body3",children:"or"}),e.jsx("div",{className:"zd:h-px zd:flex-1 zd:bg-greyScale/30"})]})]}),e.jsxs("div",{className:"zd:px-4 zd:flex zd:flex-col zd:gap-2",children:[s.includes("google")&&e.jsx(d.ListItem,{iconName:"google",title:"Google",chevron:!0,className:"zd:rounded-3xl",disabled:N,onClick:K}),s.includes("email")&&e.jsx(d.Input,{iconName:"email",placeholder:"Enter your email",value:p,onChange:a=>y(a.target.value),type:"email",autoCapitalize:"none",autoComplete:"email",disabled:N,variant:"listItemStyle",containerClassName:"zd:rounded-3xl",onKeyDown:a=>{a.key==="Enter"&&p&&!N&&M()},children:z?e.jsx("div",{className:"zd:w-13 zd:h-13 zd:flex zd:items-center zd:justify-center",children:e.jsx("div",{className:"zd:w-5 zd:h-5 zd:border-2 zd:border-solarOrange zd:border-t-transparent zd:rounded-full zd:animate-spin"})}):e.jsx("button",{type:"button",disabled:!R(p)||F,className:`zd:w-13 zd:h-13 zd:rounded-2xl zd:flex zd:items-center zd:justify-center zd:transition-colors ${R(p)&&!F?"zd:cursor-pointer":"zd:cursor-not-allowed zd:opacity-50"}`,onClick:()=>M(),children:e.jsx(d.Icon,{name:"chevronRight",className:"zd:text-greyScale"})})})]})]})]}),e.jsx("div",{className:"zd:px-4",children:e.jsx(ye,{termsAndConditionsUrl:n==null?void 0:n.termsAndConditionsUrl,privacyPolicyUrl:n==null?void 0:n.privacyPolicyUrl,agreedToTerms:c,setAgreedToTerms:a=>{i(a),a&&l(!1)},highlight:u})})]})}function Ne(){return typeof window>"u"?null:new URLSearchParams(window.location.search).get("code")}function be(){const{otpId:t,otpEncryptionTargetBundle:o,goToStep:r,clearOtpSession:n,config:s}=C(),[c]=h.useState(Ne),[i,u]=h.useState(null),l=h.useRef(!1),{mutate:p,isPending:y}=j.useVerifyMagicLink({mutation:{onSuccess:async()=>{var m;n(),r("authenticated"),(m=s==null?void 0:s.onSuccess)==null||m.call(s)},onError:m=>{var S;u(m),(S=s==null?void 0:s.onError)==null||S.call(s,m)}}});return h.useEffect(()=>{if(!(l.current||!c)){if(l.current=!0,!t||!o){B(),r(null);return}p({otpId:t,code:c,otpEncryptionTargetBundle:o})}},[t,o,c,p,r]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:items-center zd:justify-center",children:[!i&&y&&e.jsx(I,{imageName:"loading",title:"Verifying Your Email",children:"Please wait while we securely connect your wallet."}),!i&&!c&&!y&&e.jsxs(e.Fragment,{children:[e.jsxs(I,{imageName:"error",title:"Invalid Link",children:["This verification link is invalid or incomplete.",e.jsx("br",{}),"Please check your email and try again with the correct link."]}),e.jsx(d.Button,{action:"primary",onClick:()=>{B(),r("sign-up")},text:"Choose another sign-in method"})]}),i!=null&&e.jsxs(e.Fragment,{children:[e.jsx(I,{imageName:"error",title:"Oops, something went wrong",children:"We couldn't complete the sign-in process. This could be due to timeout, an expired link, or a cancelled request."}),e.jsx(d.Button,{action:"primary",onClick:()=>{B(),r("sign-up")},text:"Choose another sign-in method"})]})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}function Ee(){const{goToStep:t}=C(),{connect:o,connectors:r,isPending:n}=q.useConnect(),s=r.filter(i=>i.id!=="zerodev-wallet"),c=i=>{o({connector:i},{onSuccess:()=>{t(null)}})};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"zd:flex-1 zd:flex zd:flex-col zd:gap-8 zd:justify-center",children:[e.jsx(d.Text,{className:"zd:text-h2 zd:text-center",children:"Select your wallet"}),e.jsx("div",{className:"zd:flex zd:flex-col zd:gap-2",children:s.length===0?e.jsx(d.Text,{className:"zd:text-center",children:"No wallets detected. Install a browser wallet extension to continue."}):s.map(i=>e.jsx(d.ListItem,{title:i.name,iconName:"walletOutline",...i.icon?{imageUri:i.icon}:{},disabled:n,onClick:()=>c(i),className:"zd:rounded-3xl"},i.uid))})]}),e.jsx(A,{className:"zd:self-center zd:pt-4 zd:pb-6"})]})}const Te={"wallet-selection":"Choose your wallet"};function Ce(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(I,{imageName:"loading",title:"Authenticating...",children:"Please wait while we complete the OAuth authentication."})})}function ke(){return e.jsx("div",{className:"zd:flex zd:flex-1 zd:items-center zd:justify-center",children:e.jsx(I,{imageName:"loading",title:"Passkey authentication",children:"Please authenticate with your passkey."})})}function Fe(t){switch(t){case"sign-up":return e.jsx(ve,{});case"email-verification":return e.jsx(ce,{});case"otp-input":return e.jsx(ge,{});case"verifying-otp":return e.jsx(be,{});case"oauth-in-progress":return e.jsx(Ce,{});case"passkey-prompt":return e.jsx(ke,{});case"wallet-selection":return e.jsx(Ee,{});case"error":return e.jsx(ue,{});default:return null}}function Ie({onClose:t,size:o}={}){const{step:r,goToStep:n,goBack:s,reset:c}=C(),i=b.useStore(G(),y=>y.logo);h.useEffect(()=>{r===null&&le()&&n("verifying-otp")},[r,n]);const u=Fe(r);if(!u)return null;const l=()=>{B(),c(),t==null||t()},p=r?Te[r]:void 0;return e.jsx(se,{...o&&{size:o},contentClassName:r==="sign-up"?"zd:px-0":void 0,topNav:e.jsx(Y,{...s!==null&&{onBack:s},onClose:l,...p&&{title:p},...r==="sign-up"&&{...i&&{logo:i},className:"zd:px-4"}}),children:u})}const $="zerodev:auth:otpSession";function Ae(){if(typeof window>"u")return null;try{const t=window.localStorage.getItem($);if(!t)return null;const o=JSON.parse(t);return!(o!=null&&o.otpId)||!(o!=null&&o.otpEncryptionTargetBundle)?null:o}catch{return null}}function Be(t){if(!(typeof window>"u"))try{window.localStorage.setItem($,JSON.stringify(t))}catch{}}function _(){if(!(typeof window>"u"))try{window.localStorage.removeItem($)}catch{}}const Oe=(t,o,r)=>({auth:{step:null,stepHistory:[],enabledMethods:[],email:null,otpId:null,otpEncryptionTargetBundle:null,config:null,initialize:n=>{const s=Ae();t(c=>({auth:{...c.auth,config:n,enabledMethods:n.enabledMethods,...s&&{otpId:s.otpId,otpEncryptionTargetBundle:s.otpEncryptionTargetBundle}}}))},goToStep:n=>{t(s=>({auth:{...s.auth,step:n,stepHistory:s.auth.step===null?s.auth.stepHistory:[...s.auth.stepHistory,s.auth.step]}}))},goBack:()=>{const{auth:n}=o();if(n.stepHistory.length===0)return;const s=[...n.stepHistory],c=s.pop();t(i=>({auth:{...i.auth,step:c,stepHistory:s}}))},reset:()=>{_(),t(n=>({auth:{...n.auth,step:null,stepHistory:[],email:null,otpId:null,otpEncryptionTargetBundle:null}}))},setEmail:n=>{t(s=>({auth:{...s.auth,email:n}}))},setOtpSession:({otpId:n,otpEncryptionTargetBundle:s})=>{Be({otpId:n,otpEncryptionTargetBundle:s}),t(c=>({auth:{...c.auth,otpId:n,otpEncryptionTargetBundle:s}}))},clearOtpSession:()=>{_(),t(n=>({auth:{...n.auth,otpId:null,otpEncryptionTargetBundle:null}}))}}}),Re=(t={})=>b.create()(X.subscribeWithSelector((o,r,n)=>({pendingRequests:[],userConfirmationListenerActive:!1,logo:t.logo??null,addPendingRequest:s=>o(c=>({pendingRequests:[...c.pendingRequests,s]})),removePendingRequest:s=>o(c=>({pendingRequests:c.pendingRequests.filter(i=>i.id!==s)})),clearPendingRequests:()=>o({pendingRequests:[]}),setUserConfirmationListenerActive:s=>o({userConfirmationListenerActive:s}),...Oe(o,r)})));function Pe(t){return new Promise((o,r)=>{const n=t.subscribe(s=>s.auth.step,s=>{s==="authenticated"?(n(),o()):s===null&&(n(),r(new Error("Auth flow dismissed")))})})}function Le(t){var n,s;const o=j.zeroDevWallet(t),r=Re({logo:(n=t.config)==null?void 0:n.logo});return(s=t.config)!=null&&s.auth&&r.getState().auth.initialize(t.config.auth),c=>{const i=o(c);return{...i,async connect(u){var l;try{return await i.connect(u)}catch(p){if(u!=null&&u.isReconnecting||!((l=t.config)!=null&&l.auth)||!(p instanceof j.NotAuthenticatedError))throw p;if(r.getState().auth.step!==null)throw new Error("Auth flow already in progress");return r.getState().auth.goToStep("sign-up"),await Pe(r),i.connect(u)}},async disconnect(){var u,l;await((u=i.disconnect)==null?void 0:u.call(i)),(l=t.config)!=null&&l.auth&&r.getState().auth.reset()},async setup(){var u;await((u=i.setup)==null?void 0:u.call(i)),typeof window>"u"},getKitStore(){return r}}}}exports.AuthFlow=Ie;exports.useAuth=C;exports.zeroDevWallet=Le;
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|