@privy-io/react-auth
Version:
React client for the Privy Auth API
26 lines (25 loc) • 5.65 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("styled-components"),i=require("@privy-io/urls"),o=require("./WarningBanner-DUcGaIpZ.js"),n=require("./WalletInfoCard-B7ARTvO5.js"),a=require("./context-Cg3IEi80.js"),s=require("./internal-context-BJv4f_bO.js"),l=require("./privy-context-CrM9_s6G.js"),c=require("./ScreenLayout-C4QHZMbl.js");require("@heroicons/react/24/outline/ExclamationTriangleIcon"),require("lucide-react"),require("./ModalHeader-C5Wuo3-1.js"),require("./useActiveWallet-BfMD5hzE.js"),require("zustand"),require("react-device-detect"),require("./use-export-wallet-_EIyxyle.js"),require("./useWallets-dikDynAG.js"),require("viem"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("viem/utils"),require("./events-context-Di6--rDg.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("./ErrorMessage-BfTVyue9.js"),require("./LabelXs-C8rLnCfU.js"),require("./Address-BeuDoSGB.js"),require("./shared-DBm7PUrg.js"),require("tinycolor2"),require("ofetch"),require("@privy-io/are-addresses-equal"),require("./Screen-DWnRbzSA.js"),require("./index-ByFhjjzH.js");const d=({address:r,accessToken:t,appConfigTheme:i,onClose:a,exportButtonProps:s,onBack:l})=>/*#__PURE__*/e.jsx(c.ScreenLayout,{title:"Export wallet",subtitle:/*#__PURE__*/e.jsxs(e.Fragment,{children:["Copy either your private key or seed phrase to export your wallet."," ",/*#__PURE__*/e.jsx("a",{href:"https://privy-io.notion.site/Transferring-your-account-9dab9e16c6034a7ab1ff7fa479b02828",target:"blank",rel:"noopener noreferrer",children:"Learn more"})]}),onClose:a,onBack:l,showBack:!!l,watermark:!0,children:/*#__PURE__*/e.jsxs(u,{children:[/*#__PURE__*/e.jsx(o.WarningBanner,{theme:i,children:"Never share your private key or seed phrase with anyone."}),/*#__PURE__*/e.jsx(n.WalletInfoCard,{title:"Your wallet",address:r,showCopyButton:!0}),/*#__PURE__*/e.jsx("div",{style:{width:"100%"},children:t&&s&&/*#__PURE__*/e.jsx(p,{accessToken:t,dimensions:{height:"44px"},...s})})]})});let u=t.styled.div`
display: flex;
flex-direction: column;
gap: 1.25rem;
text-align: left;
`;function p(t){let[o,n]=r.useState(t.dimensions.width),[a,s]=r.useState(!1),[l,c]=r.useState(void 0),d=r.useRef(null);r.useEffect((()=>{if(d.current&&void 0===o){let{width:e}=d.current.getBoundingClientRect();n(e)}let e=getComputedStyle(document.documentElement);c({background:e.getPropertyValue("--privy-color-background"),background2:e.getPropertyValue("--privy-color-background-2"),foreground3:e.getPropertyValue("--privy-color-foreground-3"),foregroundAccent:e.getPropertyValue("--privy-color-foreground-accent"),accent:e.getPropertyValue("--privy-color-accent"),accentDark:e.getPropertyValue("--privy-color-accent-dark"),success:e.getPropertyValue("--privy-color-success"),colorScheme:e.getPropertyValue("color-scheme")})}),[]);let u="ethereum"===t.chainType&&!t.imported&&!t.isUnifiedWallet;/*#__PURE__*/return e.jsx("div",{ref:d,children:o&&
/*#__PURE__*/e.jsxs(h,{children:[/*#__PURE__*/e.jsx("iframe",{style:{position:"absolute",zIndex:1,opacity:a?1:0,transition:"opacity 50ms ease-in-out",pointerEvents:a?"auto":"none"},onLoad:()=>setTimeout((()=>s(!0)),1500),width:o,height:t.dimensions.height,allow:"clipboard-write self *",src:i.constructURL({origin:t.origin,path:`/apps/${t.appId}/embedded-wallets/export`,query:t.isUnifiedWallet?{v:"1-unified",wallet_id:t.walletId,client_id:t.appClientId,width:`${o}px`,caid:t.clientAnalyticsId,phrase_export:u,...l}:{v:"1",entropy_id:t.entropyId,entropy_id_verifier:t.entropyIdVerifier,hd_wallet_index:t.hdWalletIndex,chain_type:t.chainType,client_id:t.appClientId,width:`${o}px`,caid:t.clientAnalyticsId,phrase_export:u,...l},hash:{token:t.accessToken}})}),/*#__PURE__*/e.jsx(g,{children:"Loading..."}),u&&/*#__PURE__*/e.jsx(g,{children:"Loading..."})]})})}const y={component:()=>{let[t,i]=r.useState(null),{authenticated:o,user:n}=l.usePrivyContext(),{closePrivyModal:c,createAnalyticsEvent:u,clientAnalyticsId:p,client:y}=s.usePrivyInternal(),h=a.useAppConfig(),{data:g,onUserCloseViaDialogOrKeybindRef:x}=l.usePrivyModal(),{onFailure:f,onSuccess:v,origin:m,appId:q,appClientId:j,entropyId:w,entropyIdVerifier:I,walletId:k,hdWalletIndex:b,chainType:C,address:A,isUnifiedWallet:W,imported:_,showBackButton:E}=g.keyExport,P=e=>{c({shouldCallAuthOnSuccess:!1}),f("string"==typeof e?Error(e):e)},S=()=>{c({shouldCallAuthOnSuccess:!1}),v(),u({eventName:"embedded_wallet_key_export_completed",payload:{walletAddress:A}})};return r.useEffect((()=>{if(!o)return P("User must be authenticated before exporting their wallet");y.getAccessToken().then(i).catch(P)}),[o,n]),x.current=S,/*#__PURE__*/e.jsx(d,{address:A,accessToken:t,appConfigTheme:h.appearance.palette.colorScheme,onClose:S,isLoading:!t,onBack:E?S:void 0,exportButtonProps:t?{origin:m,appId:q,appClientId:j,clientAnalyticsId:p,entropyId:w,entropyIdVerifier:I,walletId:k,hdWalletIndex:b,isUnifiedWallet:W,imported:_,chainType:C}:void 0})}};let h=t.styled.div`
overflow: visible;
position: relative;
overflow: none;
height: 44px;
display: flex;
gap: 12px;
`,g=t.styled.div`
display: flex;
align-items: center;
justify-content: center;
width: 100%;
height: 100%;
font-size: 16px;
font-weight: 500;
border-radius: var(--privy-border-radius-md);
background-color: var(--privy-color-background-2);
color: var(--privy-color-foreground-3);
`;exports.EmbeddedWalletKeyExportScreen=y,exports.EmbeddedWalletKeyExportView=d,exports.default=y;