@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 9.61 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("@heroicons/react/24/outline/ExclamationTriangleIcon"),t=require("@heroicons/react/24/outline/WalletIcon"),n=require("react"),o=require("./Button-Bm_Ft0Dw.js"),s=require("styled-components"),i=require("./ModalHeader-DB7Tbjwz.js"),a=require("./StackedContainer-ByB6Mdu0.js"),c=require("./Address-5znFAhQw.js"),l=require("./internal-context-NWsAL807.js"),d=require("./get-is-unified-wallet-D4ouXJpi.js"),u=require("./capitalizeFirstLetter-D-K8mqBm.js"),h=require("./context-DFq1obBO.js"),f=require("@heroicons/react/24/outline/ExclamationCircleIcon"),p=require("@heroicons/react/24/outline/Square2StackIcon");function x(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("./useActiveWallet-BOX8xCn9.js"),require("zustand"),require("react-device-detect"),require("./prepareFundingModalData-Cnd6rhhJ.js"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("./events-context-Di6--rDg.js"),require("viem"),require("viem/utils"),require("./getPublicClient-CGlodIp_.js"),require("./useWallets-BLFNjTwC.js"),require("@heroicons/react/24/outline/ArrowLeftIcon"),require("@heroicons/react/24/outline/ArrowRightIcon"),require("@heroicons/react/24/outline/QuestionMarkCircleIcon"),require("@heroicons/react/24/outline/XMarkIcon"),require("lucide-react"),require("ofetch"),require("tinycolor2");var y=/*#__PURE__*/x(r),m=/*#__PURE__*/x(t),g=/*#__PURE__*/x(f),j=/*#__PURE__*/x(p);const b=/*#__PURE__*/s.styled.span.withConfig({displayName:"CircleBorder",componentId:"sc-9056b8b8-0"})(["&&{width:82px;height:82px;border-width:4px;border-style:solid;border-color:",";border-bottom-color:transparent;border-radius:50%;display:inline-block;box-sizing:border-box;animation:rotation 1.2s linear infinite;transition:border-color 800ms;border-bottom-color:",";}"],(e=>e.color??"var(--privy-color-accent)"),(e=>e.color??"var(--privy-color-accent)"));function v(r){/*#__PURE__*/return e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",...r,children:[/*#__PURE__*/e.jsx("circle",{cx:"12",cy:"12",r:"10"}),/*#__PURE__*/e.jsx("line",{x1:"12",x2:"12",y1:"8",y2:"12"}),/*#__PURE__*/e.jsx("line",{x1:"12",x2:"12.01",y1:"16",y2:"16"})]})}const w=({onTransfer:r,isTransferring:t,transferSuccess:n})=>/*#__PURE__*/e.jsx(o.PrimaryButton,{...n?{success:!0,children:"Success!"}:{warn:!0,loading:t,onClick:r,children:"Transfer and delete account"}}),C=/*#__PURE__*/s.styled.div.withConfig({displayName:"ConnectContainer",componentId:"sc-3505eb4c-0"})(["display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;width:100%;padding-bottom:16px;"]),T=/*#__PURE__*/s.styled.div.withConfig({displayName:"GappedContainer",componentId:"sc-3505eb4c-1"})(["display:flex;flex-direction:column;&& p{font-size:14px;}width:100%;gap:16px;"]),k=/*#__PURE__*/s.styled.div.withConfig({displayName:"DisclosedAccountContainer",componentId:"sc-3505eb4c-2"})(["display:flex;cursor:pointer;align-items:center;width:100%;border:1px solid var(--privy-color-foreground-4) !important;border-radius:var(--privy-border-radius-md);padding:8px 10px;font-size:14px;font-weight:500;gap:8px;"]),q=/*#__PURE__*/s.styled(g.default).withConfig({displayName:"StyledExclamationCircleIcon",componentId:"sc-3505eb4c-3"})(["position:relative;width:",";height:",";color:var(--privy-color-foreground-3);margin-left:auto;"],(({$iconSize:e})=>`${e}px`),(({$iconSize:e})=>`${e}px`)),I=/*#__PURE__*/s.styled(j.default).withConfig({displayName:"StyledCopyIcon",componentId:"sc-3505eb4c-4"})(["position:relative;width:15px;height:15px;color:var(--privy-color-foreground-3);margin-left:auto;"]),A=/*#__PURE__*/s.styled.ol.withConfig({displayName:"ListContainer",componentId:"sc-3505eb4c-5"})(["display:flex;flex-direction:column;font-size:14px;width:100%;text-align:left;"]),S=/*#__PURE__*/s.styled.li.withConfig({displayName:"ListItem",componentId:"sc-3505eb4c-6"})(["font-size:14px;list-style-type:auto;list-style-position:outside;margin-left:1rem;margin-bottom:0.5rem;&:last-child{margin-bottom:0;}"]),W=/*#__PURE__*/s.styled.div.withConfig({displayName:"CircleContainer",componentId:"sc-3505eb4c-7"})(["position:relative;width:60px;height:60px;margin:10px;display:flex;justify-content:center;align-items:center;"]);let M=()=>/*#__PURE__*/e.jsx(W,{children:/*#__PURE__*/e.jsx(q,{$iconSize:60})});const N=({address:r,onClose:t,onRetry:n,onTransfer:o,isTransferring:s,transferSuccess:a})=>{let{defaultChain:l}=h.useAppConfig(),d=l.blockExplorers?.default.url??"https://etherscan.io";/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(i.ModalHeader,{onClose:t,backFn:n}),/*#__PURE__*/e.jsxs(C,{children:[/*#__PURE__*/e.jsx(M,{}),/*#__PURE__*/e.jsxs(T,{children:[/*#__PURE__*/e.jsx("h3",{children:"Check account assets before transferring"}),/*#__PURE__*/e.jsx("p",{children:"Before transferring, ensure there are no assets in the other account. Assets in that account will not transfer automatically and may be lost."}),/*#__PURE__*/e.jsxs(A,{children:[/*#__PURE__*/e.jsx("p",{children:" To check your balance, you can:"}),/*#__PURE__*/e.jsx(S,{children:"Log out and log back into the other account, or "}),/*#__PURE__*/e.jsxs(S,{children:["Copy your wallet address and use a"," ",/*#__PURE__*/e.jsx("u",{children:/*#__PURE__*/e.jsx("a",{target:"_blank",href:d,children:"block explorer"})})," ","to see if the account holds any assets."]})]}),/*#__PURE__*/e.jsxs(k,{onClick:()=>navigator.clipboard.writeText(r).catch(console.error),children:[/*#__PURE__*/e.jsx(m.default,{color:"var(--privy-color-foreground-1)",strokeWidth:2,height:"28px",width:"28px"}),/*#__PURE__*/e.jsx(c.Address,{address:r,showCopyIcon:!1}),/*#__PURE__*/e.jsx(I,{})]}),/*#__PURE__*/e.jsx(w,{onTransfer:o,isTransferring:s,transferSuccess:a})]})]}),/*#__PURE__*/e.jsx(i.BlobbyFooter,{})]})},L={component:()=>{let{initiateAccountTransfer:r,closePrivyModal:t}=l.usePrivyInternal(),{data:o,navigate:s,lastScreen:i,setModalData:a}=d.usePrivyModal(),[c,u]=n.useState(void 0),[h,f]=n.useState(!1),[p,x]=n.useState(!1),y=async()=>{try{if(!o?.accountTransfer?.nonce||!o?.accountTransfer?.account)throw Error("missing account transfer inputs");x(!0),await r({nonce:o?.accountTransfer?.nonce,account:o?.accountTransfer?.account,accountType:o?.accountTransfer?.linkMethod,externalWalletMetadata:o?.accountTransfer?.externalWalletMetadata,telegramWebAppData:o?.accountTransfer?.telegramWebAppData,telegramAuthResult:o?.accountTransfer?.telegramAuthResult,farcasterEmbeddedAddress:o?.accountTransfer?.farcasterEmbeddedAddress,oAuthUserInfo:o?.accountTransfer?.oAuthUserInfo}),f(!0),x(!1),setTimeout(t,1e3)}catch(e){a({errorModalData:{error:e,previousScreen:i||"LinkConflictScreen"}}),s("ErrorScreen",!0)}};return c?/*#__PURE__*/e.jsx(N,{address:c,onClose:t,onRetry:()=>u(void 0),onTransfer:y,isTransferring:p,transferSuccess:h}):/*#__PURE__*/e.jsx(z,{onClose:t,onInfo:()=>u(o?.accountTransfer?.embeddedWalletAddress),onContinue:()=>u(o?.accountTransfer?.embeddedWalletAddress),onTransfer:y,isTransferring:p,transferSuccess:h,data:o})}},z=({onClose:r,onContinue:t,onInfo:n,onTransfer:s,transferSuccess:c,isTransferring:l,data:d})=>{if(!d?.accountTransfer?.linkMethod||!d?.accountTransfer?.displayName)return;let h={method:d?.accountTransfer?.linkMethod,handle:d?.accountTransfer?.displayName,disclosedAccount:d?.accountTransfer?.embeddedWalletAddress?{type:"wallet",handle:d?.accountTransfer?.embeddedWalletAddress}:void 0};/*#__PURE__*/return e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(i.ModalHeader,{closeable:!0}),/*#__PURE__*/e.jsxs(C,{children:[/*#__PURE__*/e.jsx(a.e,{children:/*#__PURE__*/e.jsxs("div",{children:[/*#__PURE__*/e.jsx(b,{color:"var(--privy-color-error)"}),/*#__PURE__*/e.jsx(y.default,{height:38,width:38,stroke:"var(--privy-color-error)"})]})}),/*#__PURE__*/e.jsxs(T,{children:[/*#__PURE__*/e.jsxs("h3",{children:[function(e){switch(e){case"sms":return"Phone number";case"email":return"Email address";case"siwe":return"Wallet address";case"siws":return"Solana wallet address";case"linkedin":return"LinkedIn profile";case"google":case"apple":case"discord":case"github":case"instagram":case"spotify":case"tiktok":case"line":case"twitch":case"twitter":case"telegram":case"farcaster":return`${u.e(e.replace("_oauth",""))} profile`;default:return e.startsWith("privy:")?"Cross-app account":e}}(h.method)," is associated with another account"]}),/*#__PURE__*/e.jsxs("p",{children:["Do you want to transfer",/*#__PURE__*/e.jsx("b",{children:h.handle?` ${h.handle}`:""})," to this account instead? This will delete your other account."]}),/*#__PURE__*/e.jsx(B,{onClick:n,disclosedAccount:h.disclosedAccount})]}),/*#__PURE__*/e.jsxs(T,{style:{gap:12,marginTop:12},children:[d?.accountTransfer?.embeddedWalletAddress?/*#__PURE__*/e.jsx(o.PrimaryButton,{onClick:t,children:"Continue"}):/*#__PURE__*/e.jsx(w,{onTransfer:s,transferSuccess:c,isTransferring:l}),/*#__PURE__*/e.jsx(o.SecondaryButton,{onClick:r,children:"No thanks"})]})]}),/*#__PURE__*/e.jsx(i.BlobbyFooter,{})]})};function B({disclosedAccount:r,onClick:t}){return r?/*#__PURE__*/e.jsxs(k,{onClick:t,children:[/*#__PURE__*/e.jsx(m.default,{color:"var(--privy-color-foreground-1)",strokeWidth:2,height:"28px",width:"28px"}),/*#__PURE__*/e.jsx(c.Address,{address:r.handle,showCopyIcon:!1}),/*#__PURE__*/e.jsx(v,{width:15,height:15,color:"var(--privy-color-foreground-3)",style:{marginLeft:"auto"}})]}):null}exports.LinkConflictScreen=L,exports.LinkConflictScreenView=z,exports.default=L;