UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

113 lines (107 loc) 5.48 kB
"use strict";var e=require("./use-export-wallet-_EIyxyle.js"),r=require("react/jsx-runtime"),t=require("lucide-react"),o=require("react"),s=require("styled-components"),n=require("./index-DchMyzt9.js"),l=require("./ScreenLayout-C4QHZMbl.js");const i=async({operation:r,until:t,delay:o,interval:s,attempts:n,signal:l})=>{let i,a=0;for(;a<n;){if(l?.aborted)return{status:"aborted",result:i,attempts:a};a++;try{if(i=await r(),t(i))return{status:"success",result:i,attempts:a};a<n&&await e.sleep(s)}catch(r){a<n&&await e.sleep(s)}}return{status:"max_attempts",result:i,attempts:a}},a=e=>{try{return e.location.origin}catch{return}};let d=s.styled.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; } `,c=s.styled.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; `,u=s.styled.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; } `,p=s.styled.div` svg { width: 1rem; height: 1rem; border-radius: var(--privy-border-radius-full); overflow: hidden; } `,f=s.styled.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; `,y=s.styled.div` color: var(--privy-color-foreground); svg { width: 1.25rem; height: 1.25rem; } `;let h=s.styled.div` display: flex; flex-direction: column; gap: 0.75rem; width: 100%; `,m=s.styled.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; } `,g=s.styled.div` display: flex; align-items: center; gap: 1rem; width: 100%; `,v=s.styled.div` svg { width: 2.25rem; height: 2.25rem; border-radius: var(--privy-border-radius-full); overflow: hidden; } `,x=s.styled.div` display: flex; flex-direction: column; align-items: flex-start; gap: 0.125rem; `,w=s.styled.span` color: var(--privy-color-foreground); font-size: 0.875rem; font-weight: 600; line-height: 1.25rem; `,b=s.styled.span` color: var(--privy-color-foreground-3); font-size: 0.75rem; font-weight: 400; line-height: 1.125rem; `;exports.AmountInput=({currency:e="usd",value:t,onChange:s,inputMode:l="decimal",autoFocus:i})=>{let[a,u]=o.useState("0"),p=o.useRef(null),f=t??a,y=n.SUPPORTED_CURRENCIES[e]?.symbol??"$",h=o.useCallback((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):u(r)}),[s]),m=o.useCallback((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())}),[]),g=o.useMemo((()=>(f.includes("."),f)),[f]);/*#__PURE__*/return r.jsxs(d,{onClick:()=>p.current?.focus(),children:[/*#__PURE__*/r.jsx(c,{children:y}),g,/*#__PURE__*/r.jsx("input",{ref:p,type:"text",inputMode:l,value:g,onChange:h,onKeyDown:m,autoFocus:i,placeholder:"0",style:{width:1,height:"1rem",opacity:0,alignSelf:"center",fontSize:"1rem"}}),/*#__PURE__*/r.jsx(c,{style:{opacity:0},children:y})]})},exports.CurrencySelector=({selectedAsset:e,onEditSourceAsset:o})=>{let{icon:s}=n.SUPPORTED_CURRENCIES[e];/*#__PURE__*/return r.jsxs(u,{onClick:o,children:[/*#__PURE__*/r.jsx(p,{children:s}),/*#__PURE__*/r.jsx(f,{children:e.toLocaleUpperCase()}),/*#__PURE__*/r.jsx(y,{children:/*#__PURE__*/r.jsx(t.ChevronDown,{})})]})},exports.SelectSourceAsset=({opts:e,isLoading:t,onSelectSource:o})=>/*#__PURE__*/r.jsx(l.ScreenLayout,{showClose:!1,showBack:!0,onBack:()=>o(e.source.selectedAsset),title:"Select currency",children:/*#__PURE__*/r.jsx(h,{children:e.source.assets.map((e=>{let{icon:s,name:l}=n.SUPPORTED_CURRENCIES[e];/*#__PURE__*/return r.jsx(m,{onClick:()=>o(e),disabled:t,children:/*#__PURE__*/r.jsxs(g,{children:[/*#__PURE__*/r.jsx(v,{children:s}),/*#__PURE__*/r.jsxs(x,{children:[/*#__PURE__*/r.jsx(w,{children:l}),/*#__PURE__*/r.jsx(b,{children:e.toLocaleUpperCase()})]})]})},e)}))})}),exports.poll=i,exports.pollPopupForRedirect=async(e,r)=>{let t=await i({operation:async()=>({done:a(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"}};