@privy-io/react-auth
Version:
React client for the Privy Auth API
32 lines (28 loc) • 12.2 kB
JavaScript
;var e=require("react/jsx-runtime"),n=require("react"),t=require("./ModalHeader-BCPQgekO.js"),l=require("./ScreenHeader-CgYJ5Fmg.js"),a=require("./FundWalletMethodHeader-BUHyY_8M.js"),i=require("./Chip-C6r7fZiR.js"),r=require("./Subtitle-CR8zM7ZJ.js"),o=require("./context-D-ZJYjUg.js"),c=require("./useActiveWallet-Cn6zOXx5.js"),s=require("./internal-context-BJv4f_bO.js"),u=require("./get-is-unified-wallet-UpdjHxOV.js"),d=require("./useWallets-CKAypPZB.js"),p=require("./WalletOverflowButton-BqeWaSEy.js"),y=require("./index-C8lpxYDX.js"),h=require("react-device-detect"),w=require("styled-components"),m=require("./InjectedWalletIcon-UY3nMvZo.js"),C=require("./styles-DUvzIwf1.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-BoyADunQ.js"),require("@privy-io/js-sdk-core"),require("tinycolor2"),require("zustand"),require("./use-export-wallet-B5ujV5Nk.js"),require("eventemitter3"),require("viem/utils"),require("./events-context-Di6--rDg.js"),require("viem"),require("./getPublicClient-BsmZyCGX.js"),require("ofetch"),require("@privy-io/are-addresses-equal"),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-cfS6o4tX.js"),require("@scure/base"),require("@headlessui/react"),require("@walletconnect/ethereum-provider"),require("@privy-io/urls"),require("./PrivyPluginContext-DsgaS6n9.js"),require("./getEmbeddedConnectedWallet-pJd-l936.js"),require("js-cookie"),require("./frame-Oz7volks.js"),require("@privy-io/routes"),require("x402/client"),require("@privy-io/api-base"),require("viem/accounts"),require("./use-sign-with-user-signer-Cu_6Bx7m.js"),require("@heroicons/react/24/outline/WalletIcon"),require("./LinkPasskeyScreen-CjdxFDoA.js"),require("./TodoList-Cii_KrAk.js"),require("./ScreenLayout-CMb-Fua0.js"),require("./Screen-BfKedqka.js"),require("./index-ByFhjjzH.js");const g=({provider:n,displayName:t,logo:l,connectOnly:a,connector:i})=>{let r,{navigate:o,setModalData:d}=u.usePrivyModal(),{connectWallet:p}=s.usePrivyInternal(),w=c.useRecentlyUsedLogin(),C=c.useExternalWalletListing(n),g="wallet_connect_v2"===i.connectorType?n:i.walletClientType,x=window.matchMedia("(display-mode: standalone)").matches,q=c.getWalletConfigForConnector({connectorType:i.connectorType,walletClientType:g});r=q&&q.chainTypes.includes(i.chainType)?()=>{q.isInstalled||"solana"===i.chainType&&"isInstalled"in i&&i.isInstalled?(p(i,g),o(a?"ConnectOnlyStatusScreen":"ConnectionStatusScreen")):h.isMobile?(d({installWalletModalData:{walletConfig:q,chainType:i.chainType,connectOnly:a}}),o("WalletInterstitialScreen")):(d({installWalletModalData:{walletConfig:q,chainType:i.chainType,connectOnly:a}}),o("InstallWalletScreen"))}:"coinbase_wallet"!==i.connectorType||"eoaOnly"!==i.coinbaseWalletConfig.preference?.options||!h.isMobile||x||c.isCoinbaseWalletInstalled()?()=>{(!y.e(window.navigator.userAgent)||event?.isTrusted)&&(p(i,g),a?"wallet_connect_v2"===i.connectorType?(d((e=>({...e,externalConnectWallet:{...e?.externalConnectWallet,preSelectedWalletId:"wallet_connect_qr"}}))),o("ConnectOnlyLandingScreen")):o("ConnectOnlyStatusScreen"):o("ConnectionStatusScreen"))}:()=>{window.location.href=`https://go.cb-w.com/dapp?cb_url=${encodeURI(window.location.href)}`};let v=t||C?.metadata?.shortName||C?.name||i.walletClientType;/*#__PURE__*/return e.jsxs(T,{onClick:r,children:[/*#__PURE__*/e.jsx(m.InjectedWalletIcon,{icon:l||C?.image_url?.md,name:v}),/*#__PURE__*/e.jsx("span",{children:v}),/*#__PURE__*/e.jsxs(j,{id:"chip-container",children:[w?.walletClientType===g&&w?.chainType===i.chainType?/*#__PURE__*/e.jsx(f,{color:"gray",children:"Recent"}):/*#__PURE__*/e.jsx("span",{id:"connect-text",children:"Connect"}),"solana"===i.chainType&&/*#__PURE__*/e.jsx(f,{color:"gray",children:"Solana"})]})]})};let T=w.styled(c.LoginMethodButton)`
/* Wallet name text color */
> span {
color: var(--privy-color-foreground);
}
/* Show "Connect" on hover */
> #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;
}
}
`,f=w.styled(i.Chip)`
margin-left: auto;
`,j=w.styled.div`
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-left: auto;
`;const x=["coinbase_wallet","base_account"];let q=["metamask","okx_wallet","rainbow","uniswap","bybit_wallet","ronin_wallet","haha_wallet","uniswap_extension","zerion","rabby_wallet","cryptocom","binance","kraken_wallet"];const v=["safe"],_=["phantom","backpack","solflare","jupiter","universal_profile"],S={component:()=>{let i,{connectors:h}=s.usePrivyInternal(),{setModalData:w,data:m,navigate:C}=u.usePrivyModal(),T=o.useAppConfig(),{wallets:f}=d.useWallets(),j=h.filter(c.isSolanaWalletConnector).flatMap((e=>e.wallets)),[S,b]=n.useState("default"),$="solana"===m?.funding?.chainType,k=!!m?.funding?.crossChainBridgingEnabled;i="ethereum"===m?.funding?.chainType?m.funding.erc20Address&&!m.funding.isUSDC?"ethereum-only":k&&!m.funding.chain.testnet?"ethereum-and-solana":"ethereum-only":k&&!m.funding?.isUSDC?"ethereum-and-solana":"solana-only";let I=f.filter((e=>"privy"!==e.walletClientType)),M=I.map((e=>e.walletClientType)),O=j.filter((e=>"privy"!==e.walletClientType)),A=O.map((e=>e.walletClientType)),F=[],L={...m.funding};L.usingDefaultFundingMethod&&(L.usingDefaultFundingMethod=!1);let B=({wallet:e,walletChainType:n})=>{w({...m,funding:{...L,connectedWallet:e,onContinueWithExternalWallet:()=>C(E({destChainType:$?"solana":"ethereum",sourceChainType:n}))},solanaFundingData:m?.solanaFundingData?{...m.solanaFundingData,sourceWalletData:{address:e.address,walletClientType:e.walletClientType}}:void 0}),C("FundingAmountEditScreen")};"solana-only"!==i&&F.push(...I.map(((n,t)=>/*#__PURE__*/e.jsx(W,{onClick:()=>B({wallet:n,walletChainType:"ethereum"}),icon:n.meta.icon,name:n.meta.name,chainType:n.type},t)))),"ethereum-only"!==i&&F.push(...O.map(((n,t)=>/*#__PURE__*/e.jsx(W,{onClick:()=>B({wallet:n,walletChainType:"solana"}),icon:n.meta.icon,name:n.meta.name,chainType:n.type},t)))),F.push(...(({walletList:n,walletChainType:t,connectors:l,connectOnly:a,ignore:i,walletConnectEnabled:r,forceWallet:o})=>{let c=[],s=[],u=[],d=l.filter((e=>"ethereum-only"===t?"ethereum"===e.chainType:"solana-only"!==t||"solana"===e.chainType)),p=d.find((e=>"wallet_connect_v2"===e.connectorType));for(let[l,h]of(o?[o.wallet]:n).entries()){if("detected_ethereum_wallets"===h)for(let[n,t]of d.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:r,chainType:o}=t;("unknown"===i?s:c).push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:i,logo:r.icon,displayName:r.name,connector:t},`${l}-${h}-${i}-${o}-${n}`))}if("detected_solana_wallets"===h)for(let[n,r]of d.filter((({chainType:e,walletClientType:n})=>{if("solana"===e)return"ethereum-only"!==t&&!i.includes(n)})).entries()){let{walletClientType:t,walletBranding:i,chainType:o}=r;("unknown"===t?s:c).push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:t,logo:i.icon,displayName:i.name,connector:r},`${l}-${h}-${t}-${o}-${n}`))}if(_.includes(h)){let n=d.find((e=>"injected"===e.connectorType&&e.walletClientType===h||e.connectorType===h));if(n&&c.push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:h,connector:n},`${l}-${h}`)),"solana-only"===t||"ethereum-and-solana"===t){let n=d.find((({chainType:e,walletClientType:n})=>"solana"===e&&n===h));n&&c.push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:h,connector:n},`${h}-solana`))}}else if(q.includes(h)){let n=d.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(r&&!n&&(n=p),n&&c.push(/*#__PURE__*/e.jsx(g,{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=d.find((({chainType:e,walletClientType:n})=>"solana"===e&&n===h));n&&c.push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:h,connector:n},`${h}-solana`))}}else if(x.includes(h)){let n=d.find((({connectorType:e})=>e===h));n&&c.push(/*#__PURE__*/e.jsx(g,{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(v.includes(h))p&&u.push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:h,connector:p},`${l}-${h}`));else if("wallet_connect"===h)p&&u.push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:h,connector:p,logo:p.walletBranding.icon,displayName:"WalletConnect"},`${l}-${h}`));else if(h===o?.wallet){let t="ethereum"===o.chainType&&n.includes("detected_ethereum_wallets"),i="solana"===o.chainType&&n.includes("detected_solana_wallets");if(t||i){let n=d.find((({walletClientType:e})=>e===h));n&&c.push(/*#__PURE__*/e.jsx(g,{connectOnly:a,provider:h,displayName:n.walletBranding?.name,logo:n.walletBranding?.icon,connector:n},`${l}-${h}`))}}}return[...s,...c,...u]})({walletList:T.appearance.walletList.filter((e=>!I.some((n=>n.walletClientType===e))&&!O.some((n=>n.walletClientType===e)))),walletChainType:i,connectors:h,connectOnly:!0,ignore:[...T.appearance.walletList,...M,...A],walletConnectEnabled:T.externalWallets.walletConnect.enabled}));let D=/*#__PURE__*/e.jsx(p.WalletOverflowButton,{text:"More wallets",onClick:()=>b("overflow")}),E=({sourceChainType:e,destChainType:n})=>"ethereum"===e&&"solana"===n?"AwaitingEvmToSolBridgingScreen":"ethereum"===e&&"ethereum"===n?"AwaitingExternalEthereumTransferScreen":"solana"===e&&"ethereum"===n?"AwaitingSolToEvmBridgingScreen":L.externalSolanaFundingScreen;return n.useEffect((()=>{w({...m,externalConnectWallet:{onCompleteNavigateTo:({address:e,walletClientType:n,walletChainType:t})=>{let l=t??"ethereum",a="ethereum"===l?I.find((t=>t.address===e&&t.walletClientType===n)):O.find((t=>t.address===e&&t.walletClientType===n));return w({...m,funding:{...L,connectedWallet:a,onContinueWithExternalWallet:()=>{C(E({destChainType:$?"solana":"ethereum",sourceChainType:l}))}},solanaFundingData:m?.solanaFundingData?{...m.solanaFundingData,sourceWalletData:{address:e||"",walletClientType:n||""}}:void 0}),"FundingAmountEditScreen"}}})}),[]),"overflow"===S?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(t.ModalHeader,{backFn:()=>b("default")},"header"),/*#__PURE__*/e.jsxs(c.LoginMethodContainer,{children:[/*#__PURE__*/e.jsx(r.Subtitle,{style:{color:"var(--privy-color-foreground-3)",textAlign:"left"},children:"More wallets"}),F]}),/*#__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:[F.length>4?F.slice(0,3):F,F.length>4&&D]}),/*#__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=S,exports.default=S;