@privy-io/react-auth
Version:
React client for the Privy Auth API
32 lines (28 loc) • 11.6 kB
JavaScript
import{jsxs as e,jsx as n,Fragment as t}from"react/jsx-runtime";import{useState as l,useEffect as a}from"react";import{M as o,B as i}from"./ModalHeader-BnVmXtvG.mjs";import{C as r}from"./ScreenHeader-CHmc4-Lu.mjs";import{t as c}from"./FundWalletMethodHeader-Cb-ACySl.mjs";import{C as s}from"./Chip-D2-wZOHJ.mjs";import{S as p}from"./Subtitle-CV-2yKE4.mjs";import{u as d}from"./context-DLtU3JQy.mjs";import{r as m,z as y,e as u,A as h,j as w,Q as f}from"./useActiveWallet-CvP7iYvj.mjs";import{u as T}from"./internal-context-Z-fyxadS.mjs";import{a as C}from"./privy-context-DrMxzgOR.mjs";import{u as g}from"./useWallets-BzNCTucF.mjs";import{W as v}from"./WalletOverflowButton-CPDxFP5w.mjs";import{A as _,D as j,E as x}from"./index-YDEix4mU.mjs";import{isMobile as S}from"react-device-detect";import{styled as W}from"styled-components";import{I as b}from"./InjectedWalletIcon-DLcYOGDj.mjs";import{y as $}from"./use-export-wallet-_wu5ex5t.mjs";import{I as k}from"./styles-DDaGxKdi.mjs";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"./LoadingSkeleton-U6-3yFwI.mjs";import"@privy-io/js-sdk-core";import"tinycolor2";import"zustand";import"./events-context-CI0iqAXA.mjs";import"viem";import"viem/utils";import"ofetch";import"@privy-io/are-addresses-equal";import"lucide-react";import"uuid";import"jose";import"eventemitter3";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"mipd";import"@privy-io/popup";import"./paths-3HW55qZg.mjs";import"./usePrivy-C_sY2Duk.mjs";import"@scure/base";import"@headlessui/react";import"@walletconnect/ethereum-provider";import"@privy-io/urls";import"./PrivyPluginContext-2QN2dVUw.mjs";import"./getEmbeddedConnectedWallet-JzK4iD-L.mjs";import"js-cookie";import"./frame-uzTmvtww.mjs";import"@privy-io/routes";import"x402/client";import"@privy-io/api-base";import"viem/accounts";import"./use-sign-with-user-signer-Do5Oi_rb.mjs";import"@heroicons/react/24/outline/WalletIcon";import"./LinkPasskeyScreen-DmtRo8xi.mjs";import"./TodoList-CgrU7uwu.mjs";import"./ScreenLayout-D1p_ntex.mjs";import"./Screen-Cycy3IzT.mjs";import"./index-Dq_xe9dz.mjs";const O=({provider:t,displayName:l,logo:a,connectOnly:o,connector:i})=>{let r,{navigate:c,setModalData:s}=C(),{connectWallet:p}=T(),d=m(),h=y(t),w="wallet_connect_v2"===i.connectorType?t:i.walletClientType,f=window.matchMedia("(display-mode: standalone)").matches,g=u({connectorType:i.connectorType,walletClientType:w});r=g&&g.chainTypes.includes(i.chainType)?()=>{g.isInstalled||"solana"===i.chainType&&"isInstalled"in i&&i.isInstalled?(p(i,w),c(o?"ConnectOnlyStatusScreen":"ConnectionStatusScreen")):S?(s({installWalletModalData:{walletConfig:g,chainType:i.chainType,connectOnly:o}}),c("WalletInterstitialScreen")):(s({installWalletModalData:{walletConfig:g,chainType:i.chainType,connectOnly:o}}),c("InstallWalletScreen"))}:"coinbase_wallet"!==i.connectorType||"eoaOnly"!==i.coinbaseWalletConfig.preference?.options||!S||f||$()?()=>{(!_(window.navigator.userAgent)||event?.isTrusted)&&(p(i,w),o?"wallet_connect_v2"===i.connectorType?(s((e=>({...e,externalConnectWallet:{...e?.externalConnectWallet,preSelectedWalletId:"wallet_connect_qr"}}))),c("ConnectOnlyLandingScreen")):c("ConnectOnlyStatusScreen"):c("ConnectionStatusScreen"))}:()=>{window.location.href=`https://go.cb-w.com/dapp?cb_url=${encodeURI(window.location.href)}`};let v=l||h?.metadata?.shortName||h?.name||i.walletClientType;/*#__PURE__*/return e(D,{onClick:r,children:[/*#__PURE__*/n(b,{icon:a||h?.image_url?.md,name:v}),/*#__PURE__*/n("span",{children:v}),/*#__PURE__*/e(M,{id:"chip-container",children:[d?.walletClientType===w&&d?.chainType===i.chainType?/*#__PURE__*/n(I,{color:"gray",children:"Recent"}):/*#__PURE__*/n("span",{id:"connect-text",children:"Connect"}),"solana"===i.chainType&&/*#__PURE__*/n(I,{color:"gray",children:"Solana"})]})]})};let D=W(h)`
/* 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;
}
}
`,I=W(s)`
margin-left: auto;
`,M=W.div`
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-left: auto;
`;const F=["coinbase_wallet","base_account"];let A=["metamask","okx_wallet","rainbow","uniswap","bybit_wallet","ronin_wallet","haha_wallet","uniswap_extension","zerion","rabby_wallet","cryptocom","binance","kraken_wallet"];const B=["safe"],E=["phantom","backpack","solflare","jupiter","universal_profile"],L={component:()=>{let s,{connectors:m}=T(),{setModalData:y,data:u,navigate:h}=C(),_=d(),{wallets:S}=g(),W=m.filter(w).flatMap((e=>e.wallets)),[b,$]=l("default"),k="solana"===u?.funding?.chainType,D=!!u?.funding?.crossChainBridgingEnabled;s="ethereum"===u?.funding?.chainType?u.funding.erc20Address&&!u.funding.isUSDC?"ethereum-only":D&&!u.funding.chain.testnet?"ethereum-and-solana":"ethereum-only":D&&!u.funding?.isUSDC?"ethereum-and-solana":"solana-only";let I=S.filter((e=>"privy"!==e.walletClientType)),M=I.map((e=>e.walletClientType)),L=W.filter((e=>"privy"!==e.walletClientType)),P=L.map((e=>e.walletClientType)),q=[],z={...u.funding};z.usingDefaultFundingMethod&&(z.usingDefaultFundingMethod=!1);let H=({wallet:e,walletChainType:n})=>{y({...u,funding:{...z,connectedWallet:e,onContinueWithExternalWallet:()=>h(U({destChainType:k?"solana":"ethereum",sourceChainType:n}))},solanaFundingData:u?.solanaFundingData?{...u.solanaFundingData,sourceWalletData:{address:e.address,walletClientType:e.walletClientType}}:void 0}),h("FundingAmountEditScreen")};"solana-only"!==s&&q.push(...I.map(((e,t)=>/*#__PURE__*/n(N,{onClick:()=>H({wallet:e,walletChainType:"ethereum"}),icon:e.meta.icon,name:e.meta.name,chainType:e.type},t)))),"ethereum-only"!==s&&q.push(...L.map(((e,t)=>/*#__PURE__*/n(N,{onClick:()=>H({wallet:e,walletChainType:"solana"}),icon:e.meta.icon,name:e.meta.name,chainType:e.type},t)))),q.push(...(({walletList:e,walletChainType:t,connectors:l,connectOnly:a,ignore:o,walletConnectEnabled:i,forceWallet:r})=>{let c=[],s=[],p=[],d=l.filter((e=>"ethereum-only"===t?"ethereum"===e.chainType:"solana-only"!==t||"solana"===e.chainType)),m=d.find((e=>"wallet_connect_v2"===e.connectorType));for(let[l,y]of(r?[r.wallet]:e).entries()){if("detected_ethereum_wallets"===y)for(let[e,t]of d.filter((({chainType:e,connectorType:n,walletClientType:t})=>"solana"!==e&&("uniswap_wallet_extension"===t||"uniswap_extension"===t?!o.includes("uniswap"):"crypto.com_wallet_extension"===t||"crypto.com_onchain"===t?!o.includes("cryptocom"):"injected"===n&&!o.includes(t)))).entries()){let{walletClientType:o,walletBranding:i,chainType:r}=t;("unknown"===o?s:c).push(/*#__PURE__*/n(O,{connectOnly:a,provider:o,logo:i.icon,displayName:i.name,connector:t},`${l}-${y}-${o}-${r}-${e}`))}if("detected_solana_wallets"===y)for(let[e,i]of d.filter((({chainType:e,walletClientType:n})=>{if("solana"===e)return"ethereum-only"!==t&&!o.includes(n)})).entries()){let{walletClientType:t,walletBranding:o,chainType:r}=i;("unknown"===t?s:c).push(/*#__PURE__*/n(O,{connectOnly:a,provider:t,logo:o.icon,displayName:o.name,connector:i},`${l}-${y}-${t}-${r}-${e}`))}if(E.includes(y)){let e=d.find((e=>"injected"===e.connectorType&&e.walletClientType===y||e.connectorType===y));if(e&&c.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:e},`${l}-${y}`)),"solana-only"===t||"ethereum-and-solana"===t){let e=d.find((({chainType:e,walletClientType:n})=>"solana"===e&&n===y));e&&c.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:e},`${y}-solana`))}}else if(A.includes(y)){let e=d.find((e=>"uniswap"===y?"uniswap_wallet_extension"===e.walletClientType||"uniswap_extension"===e.walletClientType:"cryptocom"===y?"crypto.com_wallet_extension"===e.walletClientType||"crypto.com_onchain"===e.walletClientType:"injected"===e.connectorType&&e.walletClientType===y));if(i&&!e&&(e=m),e&&c.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:e,logo:"injected"===e.connectorType?e.walletBranding.icon:void 0,displayName:"injected"===e.connectorType?e.walletBranding.name:void 0},`${l}-${y}`)),"solana-only"===t||"ethereum-and-solana"===t){let e=d.find((({chainType:e,walletClientType:n})=>"solana"===e&&n===y));e&&c.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:e},`${y}-solana`))}}else if(F.includes(y)){let e=d.find((({connectorType:e})=>e===y));e&&c.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:e,displayName:"coinbase_wallet"===e.walletClientType?"Coinbase":"Base",logo:"coinbase_wallet"===e.walletClientType?j:x},`${l}-${y}`))}else if(B.includes(y))m&&p.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:m},`${l}-${y}`));else if("wallet_connect"===y)m&&p.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,connector:m,logo:m.walletBranding.icon,displayName:"WalletConnect"},`${l}-${y}`));else if(y===r?.wallet){let t="ethereum"===r.chainType&&e.includes("detected_ethereum_wallets"),o="solana"===r.chainType&&e.includes("detected_solana_wallets");if(t||o){let e=d.find((({walletClientType:e})=>e===y));e&&c.push(/*#__PURE__*/n(O,{connectOnly:a,provider:y,displayName:e.walletBranding?.name,logo:e.walletBranding?.icon,connector:e},`${l}-${y}`))}}}return[...s,...c,...p]})({walletList:_.appearance.walletList.filter((e=>!I.some((n=>n.walletClientType===e))&&!L.some((n=>n.walletClientType===e)))),walletChainType:s,connectors:m,connectOnly:!0,ignore:[..._.appearance.walletList,...M,...P],walletConnectEnabled:_.externalWallets.walletConnect.enabled}));let R=/*#__PURE__*/n(v,{text:"More wallets",onClick:()=>$("overflow")}),U=({sourceChainType:e,destChainType:n})=>"ethereum"===e&&"solana"===n?"AwaitingEvmToSolBridgingScreen":"ethereum"===e&&"ethereum"===n?"AwaitingExternalEthereumTransferScreen":"solana"===e&&"ethereum"===n?"AwaitingSolToEvmBridgingScreen":z.externalSolanaFundingScreen;return a((()=>{y({...u,externalConnectWallet:{onCompleteNavigateTo:({address:e,walletClientType:n,walletChainType:t})=>{let l=t??"ethereum",a="ethereum"===l?I.find((t=>t.address===e&&t.walletClientType===n)):L.find((t=>t.address===e&&t.walletClientType===n));return y({...u,funding:{...z,connectedWallet:a,onContinueWithExternalWallet:()=>{h(U({destChainType:k?"solana":"ethereum",sourceChainType:l}))}},solanaFundingData:u?.solanaFundingData?{...u.solanaFundingData,sourceWalletData:{address:e||"",walletClientType:n||""}}:void 0}),"FundingAmountEditScreen"}}})}),[]),/*#__PURE__*/e(t,"overflow"===b?{children:[/*#__PURE__*/n(o,{backFn:()=>$("default")},"header"),/*#__PURE__*/e(f,{children:[/*#__PURE__*/n(p,{style:{color:"var(--privy-color-foreground-3)",textAlign:"left"},children:"More wallets"}),q]}),/*#__PURE__*/n(i,{})]}:{children:[/*#__PURE__*/n(c,{}),/*#__PURE__*/n(r,{title:"Transfer from wallet",description:"Connect a wallet to deposit funds or send funds manually to your wallet address."}),/*#__PURE__*/e(f,{children:[q.length>4?q.slice(0,3):q,q.length>4&&R]}),/*#__PURE__*/n(i,{})]})}};let N=({onClick:t,icon:l,name:a,chainType:o})=>/*#__PURE__*/e(h,{onClick:t,children:[/*#__PURE__*/n(k,{style:{width:20},children:/*#__PURE__*/n("img",{src:l})}),a,/*#__PURE__*/n(s,{color:"gray",style:{marginLeft:"auto"},children:"Connected"}),"solana"===o&&/*#__PURE__*/n(s,{color:"gray",children:"Solana"})]});export{L as TransferFromWalletScreen,L as default};