@privy-io/react-auth
Version:
React client for the Privy Auth API
113 lines (107 loc) • 5.21 kB
JavaScript
import{k as e}from"./use-export-wallet-_wu5ex5t.mjs";import{jsxs as r,jsx as t}from"react/jsx-runtime";import{ChevronDown as o}from"lucide-react";import{useState as n,useRef as i,useCallback as a,useMemo as l}from"react";import{styled as s}from"styled-components";import{K as d}from"./index-YDEix4mU.mjs";import{S as c}from"./ScreenLayout-D1p_ntex.mjs";const u=async({operation:r,until:t,delay:o,interval:n,attempts:i,signal:a})=>{let l,s=0;for(;s<i;){if(a?.aborted)return{status:"aborted",result:l,attempts:s};s++;try{if(l=await r(),t(l))return{status:"success",result:l,attempts:s};s<i&&await e(n)}catch(r){s<i&&await e(n)}}return{status:"max_attempts",result:l,attempts:s}},m=e=>{try{return e.location.origin}catch{return}},p=async(e,r)=>{let t=await u({operation:async()=>({done:m(e)===window.location.origin,closed:e.closed}),until:({done:e,closed:r})=>e||r,delay:0,interval:500,attempts:360,signal:r});return"aborted"===t.status?(e.close(),{status:"aborted"}):"max_attempts"===t.status?{status:"timeout"}:t.result.done?(e.close(),{status:"redirected"}):{status:"closed"}},f=({currency:e="usd",value:o,onChange:s,inputMode:c="decimal",autoFocus:u})=>{let[m,p]=n("0"),f=i(null),h=o??m,v=d[e]?.symbol??"$",w=a((e=>{let r=e.target.value,t=(r=r.replace(/[^\d.]/g,"")).split(".");t.length>2&&(r=t[0]+"."+t.slice(1).join("")),2===t.length&&t[1].length>2&&(r=`${t[0]}.${t[1].slice(0,2)}`),r.length>1&&"0"===r[0]&&"."!==r[1]&&(r=r.slice(1)),(""===r||"."===r)&&(r="0"),s?s(r):p(r)}),[s]),b=a((e=>{!(["Delete","Backspace","Tab","Escape","Enter",".","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(e.key)||(e.ctrlKey||e.metaKey)&&["a","c","v","x"].includes(e.key.toLowerCase()))&&(e.key>="0"&&e.key<="9"||e.preventDefault())}),[]),x=l((()=>(h.includes("."),h)),[h]);/*#__PURE__*/return r(g,{onClick:()=>f.current?.focus(),children:[/*#__PURE__*/t(y,{children:v}),x,/*#__PURE__*/t("input",{ref:f,type:"text",inputMode:c,value:x,onChange:w,onKeyDown:b,autoFocus:u,placeholder:"0",style:{width:1,height:"1rem",opacity:0,alignSelf:"center",fontSize:"1rem"}}),/*#__PURE__*/t(y,{style:{opacity:0},children:v})]})},h=({selectedAsset:e,onEditSourceAsset:n})=>{let{icon:i}=d[e];/*#__PURE__*/return r(v,{onClick:n,children:[/*#__PURE__*/t(w,{children:i}),/*#__PURE__*/t(b,{children:e.toLocaleUpperCase()}),/*#__PURE__*/t(x,{children:/*#__PURE__*/t(o,{})})]})};let g=s.span`
background-color: var(--privy-color-background);
width: 100%;
text-align: center;
border: none;
font-kerning: none;
font-feature-settings: 'calt' off;
display: flex;
justify-content: center;
align-items: flex-start;
cursor: pointer;
&:focus {
outline: none !important;
border: none !important;
box-shadow: none !important;
}
&& {
color: var(--privy-color-foreground);
font-size: 3.75rem;
font-style: normal;
font-weight: 600;
line-height: 5.375rem;
}
`,y=s.span`
color: var(--privy-color-foreground);
font-kerning: none;
font-feature-settings: 'calt' off;
font-size: 1rem;
font-style: normal;
font-weight: 600;
line-height: 1.5rem;
margin-top: 0.75rem;
`,v=s.button`
display: flex;
align-items: center;
justify-content: space-between;
width: auto;
gap: 0.5rem;
border: 1px solid var(--privy-color-border-default);
border-radius: var(--privy-border-radius-full);
&& {
margin: auto;
padding: 0.5rem 1rem;
}
`,w=s.div`
svg {
width: 1rem;
height: 1rem;
border-radius: var(--privy-border-radius-full);
overflow: hidden;
}
`,b=s.span`
color: var(--privy-color-foreground);
font-kerning: none;
font-feature-settings: 'calt' off;
font-size: 0.875rem;
font-style: normal;
font-weight: 500;
line-height: 1.375rem;
`,x=s.div`
color: var(--privy-color-foreground);
svg {
width: 1.25rem;
height: 1.25rem;
}
`;const k=({opts:e,isLoading:o,onSelectSource:n})=>/*#__PURE__*/t(c,{showClose:!1,showBack:!0,onBack:()=>n(e.source.selectedAsset),title:"Select currency",children:/*#__PURE__*/t(C,{children:e.source.assets.map((e=>{let{icon:i,name:a}=d[e];/*#__PURE__*/return t(S,{onClick:()=>n(e),disabled:o,children:/*#__PURE__*/r(A,{children:[/*#__PURE__*/t(j,{children:i}),/*#__PURE__*/r(L,{children:[/*#__PURE__*/t(z,{children:a}),/*#__PURE__*/t(D,{children:e.toLocaleUpperCase()})]})]})},e)}))})});let C=s.div`
display: flex;
flex-direction: column;
gap: 0.75rem;
width: 100%;
`,S=s.button`
border-color: var(--privy-color-border-default);
border-width: 1px;
border-radius: var(--privy-border-radius-mdlg);
border-style: solid;
display: flex;
&& {
padding: 0.75rem 1rem;
}
`,A=s.div`
display: flex;
align-items: center;
gap: 1rem;
width: 100%;
`,j=s.div`
svg {
width: 2.25rem;
height: 2.25rem;
border-radius: var(--privy-border-radius-full);
overflow: hidden;
}
`,L=s.div`
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 0.125rem;
`,z=s.span`
color: var(--privy-color-foreground);
font-size: 0.875rem;
font-weight: 600;
line-height: 1.25rem;
`,D=s.span`
color: var(--privy-color-foreground-3);
font-size: 0.75rem;
font-weight: 400;
line-height: 1.125rem;
`;export{f as A,h as C,k as S,u as a,p};