UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

41 lines (40 loc) 6.05 kB
"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("styled-components"),i=require("@privy-io/urls"),o=require("./WarningBanner-COl_Q0K3.js"),n=require("./WalletInfoCard-CHdyZdLe.js"),a=require("./context-D-ZJYjUg.js"),l=require("./internal-context-BJv4f_bO.js"),s=require("./get-is-unified-wallet-UpdjHxOV.js"),d=require("./ScreenLayout-CMb-Fua0.js");require("@heroicons/react/24/outline/ExclamationTriangleIcon"),require("lucide-react"),require("./ModalHeader-BCPQgekO.js"),require("./useActiveWallet-Cn6zOXx5.js"),require("zustand"),require("react-device-detect"),require("./use-export-wallet-B5ujV5Nk.js"),require("@privy-io/js-sdk-core"),require("eventemitter3"),require("viem/utils"),require("./useWallets-CKAypPZB.js"),require("./events-context-Di6--rDg.js"),require("viem"),require("./getPublicClient-BsmZyCGX.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-CHKhHgKJ.js"),require("./shared-DBm7PUrg.js"),require("tinycolor2"),require("ofetch"),require("@privy-io/are-addresses-equal"),require("./Screen-BfKedqka.js"),require("./index-ByFhjjzH.js");const c=({address:r,accessToken:t,appConfigTheme:i,onClose:a,isLoading:l=!1,exportButtonProps:s,onBack:c})=>/*#__PURE__*/e.jsx(d.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:c,showBack:!!c,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:l?/*#__PURE__*/e.jsx(p,{}):t&&s&&/*#__PURE__*/e.jsx(g,{accessToken:t,dimensions:{height:"44px"},...s})})]})});let u=t.styled.div` display: flex; flex-direction: column; gap: 1.25rem; text-align: left; `,p=()=>/*#__PURE__*/e.jsx(h,{children:/*#__PURE__*/e.jsx(y,{children:"Loading..."})}),h=t.styled.div` display: flex; gap: 12px; height: 44px; `,y=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); `;function g(t){let[o,n]=r.useState(t.dimensions.width),[a,l]=r.useState(void 0),s=r.useRef(null);r.useEffect((()=>{if(s.current&&void 0===o){let{width:e}=s.current.getBoundingClientRect();n(e)}let e=getComputedStyle(document.documentElement);l({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 d="ethereum"===t.chainType&&!t.imported&&!t.isUnifiedWallet;/*#__PURE__*/return e.jsx("div",{ref:s,children:o&& /*#__PURE__*/e.jsxs(f,{children:[/*#__PURE__*/e.jsx("iframe",{style:{position:"absolute",zIndex:1},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:d,...a}:{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:d,...a},hash:{token:t.accessToken}})}),/*#__PURE__*/e.jsx(v,{children:"Loading..."}),d&&/*#__PURE__*/e.jsx(v,{children:"Loading..."})]})})}const x={component:()=>{let[t,i]=r.useState(null),{authenticated:o,user:n}=s.usePrivyContext(),{closePrivyModal:d,createAnalyticsEvent:u,clientAnalyticsId:p,client:h}=l.usePrivyInternal(),y=a.useAppConfig(),{data:g,onUserCloseViaDialogOrKeybindRef:x}=s.usePrivyModal(),{onFailure:f,onSuccess:v,origin:m,appId:j,appClientId:q,entropyId:w,entropyIdVerifier:I,walletId:k,hdWalletIndex:b,chainType:C,address:A,isUnifiedWallet:W,imported:P,showBackButton:_}=g.keyExport,E=e=>{d({shouldCallAuthOnSuccess:!1}),f("string"==typeof e?Error(e):e)},S=()=>{d({shouldCallAuthOnSuccess:!1}),v(),u({eventName:"embedded_wallet_key_export_completed",payload:{walletAddress:A}})};return r.useEffect((()=>{if(!o)return E("User must be authenticated before exporting their wallet");h.getAccessToken().then(i).catch(E)}),[o,n]),x.current=S,/*#__PURE__*/e.jsx(c,{address:A,accessToken:t,appConfigTheme:y.appearance.palette.colorScheme,onClose:S,isLoading:!t,onBack:_?S:void 0,exportButtonProps:t?{origin:m,appId:j,appClientId:q,clientAnalyticsId:p,entropyId:w,entropyIdVerifier:I,walletId:k,hdWalletIndex:b,isUnifiedWallet:W,imported:P,chainType:C}:void 0})}};let f=t.styled.div` overflow: visible; position: relative; overflow: none; height: 44px; display: flex; gap: 12px; `,v=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=x,exports.EmbeddedWalletKeyExportView=c,exports.default=x;