UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) • 12.1 kB
"use strict";var e=require("react/jsx-runtime"),n=require("react"),t=require("./ModalHeader-DB7Tbjwz.js"),l=require("./ScreenHeader-CyURV6Ti.js"),a=require("./FundWalletMethodHeader-BKgYjMau.js"),i=require("./Chip-ChrHHazc.js"),o=require("./Subtitle-Dtmrw8l5.js"),r=require("./context-DFq1obBO.js"),c=require("./useActiveWallet-BOX8xCn9.js"),s=require("./internal-context-NWsAL807.js"),d=require("./get-is-unified-wallet-D4ouXJpi.js"),u=require("./useWallets-BLFNjTwC.js"),p=require("./WalletOverflowButton-iCeXR9aA.js"),y=require("./index-NJrQkxJ7.js"),h=require("react-device-detect"),w=require("styled-components"),m=require("./InjectedWalletIcon-UY3nMvZo.js"),C=require("./styles-D4VeJNv1.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("./LoadingSkeleton-DoCrfGnl.js"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("zustand"),require("./prepareFundingModalData-Cnd6rhhJ.js"),require("eventemitter3"),require("./events-context-Di6--rDg.js"),require("viem"),require("viem/utils"),require("./getPublicClient-CGlodIp_.js"),require("ofetch"),require("lucide-react"),require("uuid"),require("jose"),require("@coinbase/wallet-sdk"),require("@privy-io/ethereum"),require("mipd"),require("@privy-io/popup"),require("./paths-DizMb-lU.js"),require("./usePrivy-CcfSRv1R.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("js-cookie"),require("./frame-B14fp9oC.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("viem/accounts"),require("./use-sign-with-user-signer-BcAsQTGF.js"),require("./getEmbeddedConnectedWallet-6TsVZJkD.js"),require("@heroicons/react/24/outline/WalletIcon");const f=({provider:n,displayName:t,logo:l,connectOnly:a,connector:i})=>{let o,{navigate:r,setModalData:u}=d.usePrivyModal(),{connectWallet:p}=s.usePrivyInternal(),w=c.useRecentlyUsedLogin(),C=c.useExternalWalletListing(n),f="wallet_connect_v2"===i.connectorType?n:i.walletClientType,j=window.matchMedia("(display-mode: standalone)").matches,v=c.getWalletConfigForConnector({connectorType:i.connectorType,walletClientType:f});o=v&&v.chainTypes.includes(i.chainType)?()=>{v.isInstalled||"solana"===i.chainType&&"isInstalled"in i&&i.isInstalled?(p(i,f),r(a?"ConnectOnlyStatusScreen":"ConnectionStatusScreen")):h.isMobile?(u({installWalletModalData:{walletConfig:v,chainType:i.chainType,connectOnly:a}}),r("WalletInterstitialScreen")):(u({installWalletModalData:{walletConfig:v,chainType:i.chainType,connectOnly:a}}),r("InstallWalletScreen"))}:"coinbase_wallet"!==i.connectorType||"eoaOnly"!==i.coinbaseWalletConfig.preference?.options||!h.isMobile||j||c.isCoinbaseWalletInstalled()?()=>{(!y.e(window.navigator.userAgent)||event?.isTrusted)&&(p(i,f),a?"wallet_connect_v2"===i.connectorType?(u((e=>({...e,externalConnectWallet:{...e?.externalConnectWallet,preSelectedWalletId:"wallet_connect_qr"}}))),r("ConnectOnlyLandingScreen")):r("ConnectOnlyStatusScreen"):r("ConnectionStatusScreen"))}:()=>{window.location.href=`https://go.cb-w.com/dapp?cb_url=${encodeURI(window.location.href)}`};let q=t||C?.metadata?.shortName||C?.name||i.walletClientType;/*#__PURE__*/return e.jsxs(g,{onClick:o,children:[/*#__PURE__*/e.jsx(m.InjectedWalletIcon,{icon:l||C?.image_url?.md,name:q}),/*#__PURE__*/e.jsx("span",{children:q}),/*#__PURE__*/e.jsxs(x,{id:"chip-container",children:[w?.walletClientType===f&&w?.chainType===i.chainType?/*#__PURE__*/e.jsx(T,{color:"gray",children:"Recent"}):/*#__PURE__*/e.jsx("span",{id:"connect-text",children:"Connect"}),"solana"===i.chainType&&/*#__PURE__*/e.jsx(T,{color:"gray",children:"Solana"})]})]})};let g=/*#__PURE__*/w.styled(c.LoginMethodButton).withConfig({displayName:"ConnectWalletButton",componentId:"sc-5fe2f19b-0"})(["> span{color:var(--privy-color-foreground);}> #chip-container > #connect-text{font-weight:500;color:var(--privy-color-accent);opacity:0;transition:opacity 0.1s ease-out;}:hover > #chip-container > #connect-text{opacity:1;}@media (max-width:440px){> #chip-container > #connect-text{display:none;}}"]),T=/*#__PURE__*/w.styled(i.Chip).withConfig({displayName:"StyledChip",componentId:"sc-5fe2f19b-1"})(["margin-left:auto;"]),x=/*#__PURE__*/w.styled.div.withConfig({displayName:"ChipContainer",componentId:"sc-5fe2f19b-2"})(["display:flex;flex-wrap:wrap;gap:8px;margin-left:auto;"]);const j=["coinbase_wallet","base_account"];let v=["metamask","okx_wallet","rainbow","uniswap","bybit_wallet","ronin_wallet","haha_wallet","uniswap_extension","zerion","rabby_wallet","cryptocom","binance","kraken_wallet"];const q=["safe"],_=["phantom","backpack","solflare","jupiter","universal_profile"],b={component:()=>{let i,{connectors:h}=s.usePrivyInternal(),{setModalData:w,data:m,navigate:C}=d.usePrivyModal(),g=r.useAppConfig(),{wallets:T}=u.useWallets(),x=h.filter(c.isSolanaWalletConnector).flatMap((e=>e.wallets)),[b,S]=n.useState("default"),I="solana"===m?.funding?.chainType,$=!!m?.funding?.crossChainBridgingEnabled;i="ethereum"===m?.funding?.chainType?m.funding.erc20Address&&!m.funding.isUSDC?"ethereum-only":$&&!m.funding.chain.testnet?"ethereum-and-solana":"ethereum-only":$&&!m.funding?.isUSDC?"ethereum-and-solana":"solana-only";let M=T.filter((e=>"privy"!==e.walletClientType)),O=M.map((e=>e.walletClientType)),k=x.filter((e=>"privy"!==e.walletClientType)),A=k.map((e=>e.walletClientType)),B=[],F={...m.funding};F.usingDefaultFundingMethod&&(F.usingDefaultFundingMethod=!1);let D=({wallet:e,walletChainType:n})=>{w({...m,funding:{...F,connectedWallet:e,onContinueWithExternalWallet:()=>C(L({destChainType:I?"solana":"ethereum",sourceChainType:n}))},solanaFundingData:m?.solanaFundingData?{...m.solanaFundingData,sourceWalletData:{address:e.address,walletClientType:e.walletClientType}}:void 0}),C("FundingAmountEditScreen")};"solana-only"!==i&&B.push(...M.map(((n,t)=>/*#__PURE__*/e.jsx(W,{onClick:()=>D({wallet:n,walletChainType:"ethereum"}),icon:n.meta.icon,name:n.meta.name,chainType:n.type},t)))),"ethereum-only"!==i&&B.push(...k.map(((n,t)=>/*#__PURE__*/e.jsx(W,{onClick:()=>D({wallet:n,walletChainType:"solana"}),icon:n.meta.icon,name:n.meta.name,chainType:n.type},t)))),B.push(...(({walletList:n,walletChainType:t,connectors:l,connectOnly:a,ignore:i,walletConnectEnabled:o,forceWallet:r})=>{let c=[],s=[],d=[],u=l.filter((e=>"ethereum-only"===t?"ethereum"===e.chainType:"solana-only"!==t||"solana"===e.chainType)),p=u.find((e=>"wallet_connect_v2"===e.connectorType));for(let[l,h]of(r?[r.wallet]:n).entries()){if("detected_ethereum_wallets"===h)for(let[n,t]of u.filter((({chainType:e,connectorType:n,walletClientType:t})=>"solana"!==e&&("uniswap_wallet_extension"===t||"uniswap_extension"===t?!i.includes("uniswap"):"crypto.com_wallet_extension"===t||"crypto.com_onchain"===t?!i.includes("cryptocom"):"injected"===n&&!i.includes(t)))).entries()){let{walletClientType:i,walletBranding:o,chainType:r}=t;("unknown"===i?s:c).push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:i,logo:o.icon,displayName:o.name,connector:t},`${l}-${h}-${i}-${r}-${n}`))}if("detected_solana_wallets"===h)for(let[n,o]of u.filter((({chainType:e,walletClientType:n})=>{if("solana"===e)return"ethereum-only"!==t&&!i.includes(n)})).entries()){let{walletClientType:t,walletBranding:i,chainType:r}=o;("unknown"===t?s:c).push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:t,logo:i.icon,displayName:i.name,connector:o},`${l}-${h}-${t}-${r}-${n}`))}if(_.includes(h)){let n=u.find((e=>"injected"===e.connectorType&&e.walletClientType===h||e.connectorType===h));if(n&&c.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:n},`${l}-${h}`)),"solana-only"===t||"ethereum-and-solana"===t){let n=u.find((({chainType:e,walletClientType:n})=>"solana"===e&&n===h));n&&c.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:n},`${h}-solana`))}}else if(v.includes(h)){let n=u.find((e=>"uniswap"===h?"uniswap_wallet_extension"===e.walletClientType||"uniswap_extension"===e.walletClientType:"cryptocom"===h?"crypto.com_wallet_extension"===e.walletClientType||"crypto.com_onchain"===e.walletClientType:"injected"===e.connectorType&&e.walletClientType===h));if(o&&!n&&(n=p),n&&c.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:n,logo:"injected"===n.connectorType?n.walletBranding.icon:void 0,displayName:"injected"===n.connectorType?n.walletBranding.name:void 0},`${l}-${h}`)),"solana-only"===t||"ethereum-and-solana"===t){let n=u.find((({chainType:e,walletClientType:n})=>"solana"===e&&n===h));n&&c.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:n},`${h}-solana`))}}else if(j.includes(h)){let n=u.find((({connectorType:e})=>e===h));n&&c.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:n,displayName:"coinbase_wallet"===n.walletClientType?"Coinbase":"Base",logo:"coinbase_wallet"===n.walletClientType?y.COINBASE_WALLET_DATA_URI:y.BASE_ACCOUNT_DATA_URI},`${l}-${h}`))}else if(q.includes(h))p&&d.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:p},`${l}-${h}`));else if("wallet_connect"===h)p&&d.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,connector:p,logo:p.walletBranding.icon,displayName:"WalletConnect"},`${l}-${h}`));else if(h===r?.wallet){let t="ethereum"===r.chainType&&n.includes("detected_ethereum_wallets"),i="solana"===r.chainType&&n.includes("detected_solana_wallets");if(t||i){let n=u.find((({walletClientType:e})=>e===h));n&&c.push(/*#__PURE__*/e.jsx(f,{connectOnly:a,provider:h,displayName:n.walletBranding?.name,logo:n.walletBranding?.icon,connector:n},`${l}-${h}`))}}}return[...s,...c,...d]})({walletList:g.appearance.walletList.filter((e=>!M.some((n=>n.walletClientType===e))&&!k.some((n=>n.walletClientType===e)))),walletChainType:i,connectors:h,connectOnly:!0,ignore:[...g.appearance.walletList,...O,...A],walletConnectEnabled:g.externalWallets.walletConnect.enabled}));let E=/*#__PURE__*/e.jsx(p.WalletOverflowButton,{text:"More wallets",onClick:()=>S("overflow")}),L=({sourceChainType:e,destChainType:n})=>"ethereum"===e&&"solana"===n?"AwaitingEvmToSolBridgingScreen":"ethereum"===e&&"ethereum"===n?"AwaitingExternalEthereumTransferScreen":"solana"===e&&"ethereum"===n?"AwaitingSolToEvmBridgingScreen":F.externalSolanaFundingScreen;return n.useEffect((()=>{w({...m,externalConnectWallet:{onCompleteNavigateTo:({address:e,walletClientType:n,walletChainType:t})=>{let l=t??"ethereum",a="ethereum"===l?M.find((t=>t.address===e&&t.walletClientType===n)):k.find((t=>t.address===e&&t.walletClientType===n));return w({...m,funding:{...F,connectedWallet:a,onContinueWithExternalWallet:()=>{C(L({destChainType:I?"solana":"ethereum",sourceChainType:l}))}},solanaFundingData:m?.solanaFundingData?{...m.solanaFundingData,sourceWalletData:{address:e||"",walletClientType:n||""}}:void 0}),"FundingAmountEditScreen"}}})}),[]),"overflow"===b?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(t.ModalHeader,{backFn:()=>S("default")},"header"),/*#__PURE__*/e.jsxs(c.LoginMethodContainer,{children:[/*#__PURE__*/e.jsx(o.Subtitle,{style:{color:"var(--privy-color-foreground-3)",textAlign:"left"},children:"More wallets"}),B]}),/*#__PURE__*/e.jsx(t.BlobbyFooter,{})]}):/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(a.t,{}),/*#__PURE__*/e.jsx(l.CenteredScreenHeader,{title:"Transfer from wallet",description:"Connect a wallet to deposit funds or send funds manually to your wallet address."}),/*#__PURE__*/e.jsxs(c.LoginMethodContainer,{children:[B.length>4?B.slice(0,3):B,B.length>4&&E]}),/*#__PURE__*/e.jsx(t.BlobbyFooter,{})]})}};let W=({onClick:n,icon:t,name:l,chainType:a})=>/*#__PURE__*/e.jsxs(c.LoginMethodButton,{onClick:n,children:[/*#__PURE__*/e.jsx(C.IconContainer,{style:{width:20},children:/*#__PURE__*/e.jsx("img",{src:t})}),l,/*#__PURE__*/e.jsx(i.Chip,{color:"gray",style:{marginLeft:"auto"},children:"Connected"}),"solana"===a&&/*#__PURE__*/e.jsx(i.Chip,{color:"gray",children:"Solana"})]});exports.TransferFromWalletScreen=b,exports.default=b;