@privy-io/react-auth
Version:
React client for the Privy Auth API
148 lines (137 loc) • 26.1 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),n=require("@heroicons/react/24/outline"),t=require("@tanstack/react-virtual"),l=require("react"),i=require("react-device-detect"),o=require("styled-components"),a=require("./ModalHeader-C5Wuo3-1.js"),r=require("./CopyableText-DbFeIZI0.js"),s=require("./Link-BdtTp2J4.js"),c=require("./QrCode-Bbg48Zky.js"),d=require("./EmailInputForm-Y-nHsEtF.js"),u=require("./context-Cg3IEi80.js"),h=require("./useI18n-DUN0YTKn.js"),p=require("./useActiveWallet-BfMD5hzE.js"),g=require("./use-export-wallet-_EIyxyle.js"),m=require("./internal-context-BJv4f_bO.js"),w=require("./WalletCards-BfpeHH5n.js"),y=require("./Screen-DWnRbzSA.js");const f={phantom:{mobile:{native:"phantom://",universal:"https://phantom.app/ul/"}},solflare:{mobile:{native:void 0,universal:"https://solflare.com/ul/v1/"}},metamask:{image_url:{sm:p.Metamask,md:p.Metamask}}};class v{static normalize(e){return e.replace(/[-_]wallet$/,"").replace(/[-_]extension$/,"").toLowerCase()}isEth(e){return e.chains.some((e=>e.includes("eip155:")))}isSol(e){return e.chains.some((e=>e.includes("solana:")))}inAllowList(e,n){if(!this.normalizedAllowList||0===this.normalizedAllowList.length||"listing"===n&&this.includeWalletConnect)return!0;let t=v.normalize(e);return this.normalizedAllowList.some((e=>t===v.normalize(e)))}inDenyList(e,n){return"listing"===n&&"rabby"===e||"agw"===v.normalize(e)}chainMatches(e){return"ethereum-only"===this.chainFilter?"ethereum"===e:"solana-only"!==this.chainFilter||"solana"===e}getAllowListKey(e,n,t,l){let i=v.normalize(e);for(let e of this.normalizedAllowList||[])if(i===v.normalize(e))return e;if("connector"===n){if(("injected"===t||"solana_adapter"===t)&&"ethereum"===l&&this.detectedEth)return"detected_ethereum_wallets";if(("injected"===t||"solana_adapter"===t)&&"solana"===l&&this.detectedSol)return"detected_solana_wallets"}if("listing"===n&&this.includeWalletConnect)return"wallet_connect"}connectorOk(e){return!!("null"!==e.connectorType&&"walletconnect_solana"!==e.walletBranding.id&&this.chainMatches(e.chainType)&&(this.inAllowList(e.walletClientType,"connector")||("injected"===e.connectorType||"solana_adapter"===e.connectorType)&&("ethereum"===e.chainType&&this.detectedEth||"solana"===e.chainType&&this.detectedSol)))}listingOk(e){if(e.slug.includes("coinbase"))return!1;if("ethereum-only"===this.chainFilter){if(!this.isEth(e))return!1}else if("solana-only"===this.chainFilter&&!this.isSol(e))return!1;return!(!this.inAllowList(e.slug,"listing")||this.inDenyList(e.slug,"listing"))}getWallets(e,n){let t=new Map,l=e=>{let n=t.get(e.id);if(n){n.chainType!==e.chainType&&(n.chainType="multi");let t=new Set(n.chains);e.chains.forEach((e=>t.add(e))),n.chains=Array.from(t),!n.icon&&e.icon&&(n.icon=e.icon),!n.url&&e.url&&(n.url=e.url),!n.listing&&e.listing&&(n.listing=e.listing),!n.allowListKey&&e.allowListKey&&(n.allowListKey=e.allowListKey)}else t.set(e.id,e)};e.filter((e=>this.connectorOk(e))).forEach((e=>{let n=v.normalize(e.walletClientType);l({id:n,label:e.walletBranding?.name??n,source:"connector",connector:e,chainType:e.chainType,icon:e.walletBranding?.icon,url:void 0,chains:["ethereum"===e.chainType?"eip155":"solana"],allowListKey:this.getAllowListKey(e.walletClientType,"connector",e.connectorType,e.chainType)})}));let i=e.find((e=>"wallet_connect_v2"===e.connectorType)),o=e.find((e=>"walletconnect_solana"===e.walletBranding.id));n.filter((e=>this.listingOk(e))).forEach((n=>{let t=[...n.chains].filter((e=>e.includes("eip155:")||e.includes("solana:")));if(e.some((e=>v.normalize(e.walletClientType)===v.normalize(n.slug)&&"ethereum"===e.chainType&&"null"!==e.connectorType))||i||n.mobile.native||n.mobile.universal||p.mobileWalletsConfig[n.slug]?.chainTypes.includes("ethereum")||(t=t.filter((e=>!e.includes("eip155:")))),e.some((e=>v.normalize(e.walletClientType)===v.normalize(n.slug)&&"solana"===e.chainType&&"null"!==e.connectorType))||o||n.mobile.native||n.mobile.universal||p.mobileWalletsConfig[n.slug]?.chainTypes.includes("solana")||(t=t.filter((e=>!e.includes("solana:")))),!t.length)return;let a=v.normalize(n.slug),r=f[n.slug],s=r?.image_url?.sm||n.image_url?.sm;t.some((e=>e.includes("eip155:")))&&l({id:a,label:n.name||a,source:"listing",listing:n,chainType:"ethereum",icon:s,url:n.homepage,chains:t,allowListKey:this.getAllowListKey(n.slug,"listing")}),t.some((e=>e.includes("solana:")))&&l({id:a,label:n.name||a,source:"listing",listing:n,chainType:"solana",icon:s,url:n.homepage,chains:t,allowListKey:this.getAllowListKey(n.slug,"listing")})})),this.includeWalletConnectQr&&i&&l({id:"wallet_connect_qr",label:"WalletConnect",source:"connector",connector:i,chainType:"ethereum",icon:g.WALLET_CONNECT_LOGO_DATA_URI,url:void 0,chains:["eip155"],allowListKey:"wallet_connect_qr"}),this.includeWalletConnectQrSolana&&o&&l({id:"wallet_connect_qr_solana",label:"WalletConnect",source:"connector",connector:o,chainType:"solana",icon:g.WALLET_CONNECT_LOGO_DATA_URI,url:void 0,chains:["solana"],allowListKey:"wallet_connect_qr_solana"});let a=Array.from(t.values());a.forEach((e=>{let n=f[e.listing?.slug||e.id];n?.image_url?.sm&&(e.icon=n.image_url.sm)}));let r=new Map;return this.normalizedAllowList?.forEach(((e,n)=>{r.set(v.normalize(e),n)})),{wallets:a.slice().sort(((e,n)=>{if(e.allowListKey&&n.allowListKey){let t=this.normalizedAllowList?.findIndex((n=>v.normalize(n)===v.normalize(e.allowListKey)))??-1,l=this.normalizedAllowList?.findIndex((e=>v.normalize(e)===v.normalize(n.allowListKey)))??-1;if(t!==l&&t>=0&&l>=0)return t-l}if(e.allowListKey&&!n.allowListKey)return-1;if(!e.allowListKey&&n.allowListKey)return 1;let t=v.normalize(e.id),l=v.normalize(n.id);"binance-defi"===t?t="binance":"universalprofiles"===t?t="universal_profile":"cryptocom-defi"===t?t="cryptocom":"bitkeep"===t&&(t="bitget_wallet"),"binance-defi"===l?l="binance":"universalprofiles"===l?l="universal_profile":"cryptocom-defi"===l?l="cryptocom":"bitkeep"===l&&(l="bitget_wallet");let i=r.has(t),o=r.has(l);return i&&o?r.get(t)-r.get(l):i?-1:o?1:"connector"===e.source&&"listing"===n.source?-1:"listing"===e.source&&"connector"===n.source?1:e.label.toLowerCase().localeCompare(n.label.toLowerCase())})),walletCount:a.length}}constructor(e,n){this.chainFilter=e,n&&n.length>0&&(this.normalizedAllowList=n.map(String),this.normalizedAllowList.includes("binance")&&this.normalizedAllowList.push("binance-defi-wallet"),this.normalizedAllowList.includes("bitget_wallet")&&this.normalizedAllowList.push("bitkeep")),this.detectedEth=this.normalizedAllowList?.includes("detected_ethereum_wallets")??!1,this.detectedSol=this.normalizedAllowList?.includes("detected_solana_wallets")??!1,this.includeWalletConnect=this.normalizedAllowList?.includes("wallet_connect")??!1,this.includeWalletConnectQr=this.normalizedAllowList?.includes("wallet_connect_qr")??!1,this.includeWalletConnectQrSolana=this.normalizedAllowList?.includes("wallet_connect_qr_solana")??!1}}var x=n=>/*#__PURE__*/e.jsxs("svg",{viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",...n,children:[/*#__PURE__*/e.jsx("path",{d:"m0 0h32v32h-32z",fill:"#5469d4"}),/*#__PURE__*/e.jsx("path",{d:"m15.997 5.333-.143.486v14.106l.143.143 6.548-3.87z",fill:"#c2ccf4"}),/*#__PURE__*/e.jsx("path",{d:"m15.996 5.333-6.548 10.865 6.548 3.87z",fill:"#fff"}),/*#__PURE__*/e.jsx("path",{d:"m15.997 21.306-.08.098v5.025l.08.236 6.552-9.227z",fill:"#c2ccf4"}),/*#__PURE__*/e.jsx("path",{d:"m15.996 26.665v-5.36l-6.548-3.867z",fill:"#fff"}),/*#__PURE__*/e.jsx("path",{d:"m15.995 20.07 6.548-3.87-6.548-2.976v6.847z",fill:"#8698e8"}),/*#__PURE__*/e.jsx("path",{d:"m9.448 16.2 6.548 3.87v-6.846z",fill:"#c2ccf4"})]}),b=n=>/*#__PURE__*/e.jsxs("svg",{viewBox:"0 0 32 32",xmlns:"http://www.w3.org/2000/svg",...n,children:[/*#__PURE__*/e.jsxs("linearGradient",{id:"a",gradientUnits:"userSpaceOnUse",x1:"7.233",x2:"24.766",y1:"24.766",y2:"7.234",children:[/*#__PURE__*/e.jsx("stop",{offset:"0",stopColor:"#9945ff"}),/*#__PURE__*/e.jsx("stop",{offset:".2",stopColor:"#7962e7"}),/*#__PURE__*/e.jsx("stop",{offset:"1",stopColor:"#00d18c"})]}),/*#__PURE__*/e.jsx("path",{d:"m0 0h32v32h-32z",fill:"#10111a"}),/*#__PURE__*/e.jsx("path",{clipRule:"evenodd",d:"m9.873 20.41a.645.645 0 0 1 .476-.21l14.662.012a.323.323 0 0 1 .238.54l-3.123 3.438a.643.643 0 0 1 -.475.21l-14.662-.012a.323.323 0 0 1 -.238-.54zm15.376-2.862a.322.322 0 0 1 -.238.54l-14.662.012a.642.642 0 0 1 -.476-.21l-3.122-3.44a.323.323 0 0 1 .238-.54l14.662-.012a.644.644 0 0 1 .475.21zm-15.376-9.738a.644.644 0 0 1 .476-.21l14.662.012a.322.322 0 0 1 .238.54l-3.123 3.438a.643.643 0 0 1 -.475.21l-14.662-.012a.323.323 0 0 1 -.238-.54z",fill:"url(#a)",fillRule:"evenodd"})]});const C=o.styled.div`
display: flex;
justify-content: space-between;
align-items: center;
`,j=o.styled.button`
padding: 0.25rem;
height: 30px;
width: 30px;
display: flex;
align-items: center;
justify-content: center;
border-radius: var(--privy-border-radius-full);
background: var(--privy-color-background-2);
`,L=o.styled.div`
position: relative;
display: inline-flex;
align-items: center;
&::after {
content: ' ';
border-radius: var(--privy-border-radius-full);
height: 6px;
width: 6px;
background-color: var(--privy-color-icon-success);
position: absolute;
right: -3px;
top: -3px;
}
`,T=o.styled.img`
width: 32px;
height: 32px;
border-radius: 0.25rem;
object-fit: contain;
`,_=o.styled.span`
display: flex;
gap: 0.25rem;
align-items: center;
padding: 0.25rem 0.5rem;
font-size: 0.75rem;
font-weight: 500;
line-height: 1.125rem; /* 150% */
border-radius: var(--privy-border-radius-sm);
background-color: var(--privy-color-background-2);
svg {
width: 100%;
max-width: 1rem;
max-height: 1rem;
stroke-width: 2;
}
`,W=o.styled.div`
display: flex;
flex-direction: column;
gap: 0.5rem;
max-height: 24rem;
overflow-y: scroll;
&::-webkit-scrollbar {
display: none;
}
scrollbar-gutter: stable both-edges;
scrollbar-width: none;
-ms-overflow-style: none;
${e=>"light"===e.$colorScheme?"background: linear-gradient(var(--privy-color-background), var(--privy-color-background) 70%) bottom, linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0.06)) bottom;":"dark"===e.$colorScheme?"background: linear-gradient(var(--privy-color-background), var(--privy-color-background) 70%) bottom, linear-gradient(rgba(255, 255, 255, 0) 20%, rgba(255, 255, 255, 0.06)) bottom;":void 0}
background-repeat: no-repeat;
background-size:
100% 32px,
100% 16px;
background-attachment: local, scroll;
`;function k({enabled:e=!0,walletList:n,walletChainType:t}){let i=u.useAppConfig(),{connectors:o}=m.usePrivyInternal(),{listings:a,loading:r}=p.useExternalWalletListings(e),s=t??i.appearance.walletChainType,c=n??i.appearance?.walletList,d=l.useMemo((()=>new v(s,c)),[s,c]),{wallets:h,walletCount:g}=l.useMemo((()=>d.getWallets(o,a)),[d,o,a]),[w,y]=l.useState(""),f=l.useMemo((()=>w?h.filter((e=>e.label.toLowerCase().includes(w.toLowerCase()))):h),[w,h]),[x,b]=l.useState();return{selected:x,setSelected:b,search:w,setSearch:y,loadingListings:r,wallets:f,walletCount:g}}let S=e=>!e||"string"!=typeof e&&(e instanceof p.EthereumNullConnector||e instanceof p.SolanaNullConnector);const z=({index:n,style:t,data:l,recent:i})=>{let o=l.wallets[n],{walletChainType:a,handleWalletClick:r}=l,{t:s}=h.useI18n(),c={...t,boxSizing:"border-box"};return o?/*#__PURE__*/e.jsxs(q,{style:c,onClick:()=>r(o),children:[o.icon&&(o.connector&&!S(o.connector)?/*#__PURE__*/e.jsx(L,{children:"string"==typeof o.icon?/*#__PURE__*/e.jsx(T,{src:o.icon}):/*#__PURE__*/e.jsx(o.icon,{style:{width:"32px",height:"32px"}})}):"string"==typeof o.icon?/*#__PURE__*/e.jsx(T,{src:o.icon}):/*#__PURE__*/e.jsx(o.icon,{style:{width:"32px",height:"32px"}})),/*#__PURE__*/e.jsx(N,{children:o.label}),i?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(_,{children:s("connectWallet.lastUsed")}),/*#__PURE__*/e.jsx(M,{children:/*#__PURE__*/e.jsxs(e.Fragment,{children:["ethereum-only"===a&&/*#__PURE__*/e.jsx(x,{}),"solana-only"===a&&/*#__PURE__*/e.jsx(b,{})]})})]}):/*#__PURE__*/e.jsx(M,{children:!("ethereum-only"===a||"solana-only"===a)&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[o.chains?.some((e=>e.startsWith("eip155")))&&/*#__PURE__*/e.jsx(x,{}),o.chains?.some((e=>e.startsWith("solana")))&&/*#__PURE__*/e.jsx(b,{})]})})]}):null};let A=o.styled.div`
position: sticky;
// Offset by negative margin to account for focus outline
margin-top: -3px;
padding-top: 3px;
top: -3px;
z-index: 1;
background: var(--privy-color-background);
padding-bottom: calc(var(--screen-space) / 2);
`,E=o.styled.div`
display: flex;
flex-direction: column;
gap: ${5}px;
`,q=o.styled.button`
&& {
gap: 0.5rem;
align-items: center;
display: flex;
position: relative;
text-align: left;
font-weight: 500;
transition: background 200ms ease-in;
width: calc(100% - 4px);
border-radius: var(--privy-border-radius-md);
padding: 0.75em;
border: 1px solid var(--privy-color-foreground-4);
justify-content: space-between;
}
&:hover {
background: var(--privy-color-background-2);
}
`,M=o.styled.span`
display: flex;
align-items: center;
justify-content: end;
position: relative;
& > svg {
border-radius: var(--privy-border-radius-full);
stroke-width: 2.5;
width: 100%;
max-height: 1rem;
max-width: 1rem;
flex-shrink: 0;
}
& > svg:not(:last-child) {
border-radius: var(--privy-border-radius-full);
margin-right: -0.375rem;
}
`,I=o.styled.div`
height: 60px;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
`,N=o.styled.span`
text-overflow: ellipsis;
white-space: nowrap;
color: var(--privy-color-foreground);
font-weight: 400;
flex: 1;
`,B=o.styled(r.CopyableText)`
&& {
margin: 0.5rem auto 0 auto;
}
`,O=o.styled.div`
text-align: center;
margin-top: 1rem;
font-size: 0.875rem;
font-weight: 400;
color: var(--privy-color-foreground-3);
`;exports.Chip=_,exports.CloseButton=j,exports.Header=C,exports.ScrollContainer=W,exports.WalletFilterer=v,exports.WalletIcon=T,exports.WalletRow=z,exports.i=({className:o,customDescription:r,connectOnly:C,preSelectedWalletId:j,hideHeader:L,..._})=>{let W=u.useAppConfig(),{t:K}=h.useI18n(),{connectors:U}=m.usePrivyInternal(),F=_.walletChainType||W.appearance.walletChainType,D=_.walletList||W.appearance?.walletList,{onBack:P,onClose:$,app:R}=_,{selected:Q,setSelected:V,qrUrl:H,setQrUrl:G,connecting:Y,uiState:J,errorCode:X,wallets:Z,walletCount:ee,handleConnect:ne,handleBack:te,showSearchBar:le,isInitialConnectView:ie,title:oe,search:ae,setSearch:re}=function({onConnect:e,onBack:n,onClose:t,onConnectError:o,walletList:a,walletChainType:r,app:s}){let c=u.useAppConfig(),{connectors:d}=m.usePrivyInternal(),{t:w}=h.useI18n(),{wallets:y,walletCount:f,search:v,setSearch:x,selected:b,setSelected:C}=k({enabled:p.shouldFetchWcRegistryListings(a??[]),walletList:a,walletChainType:r}),[j,L]=l.useState(),[T,_]=l.useState(),[W,S]=l.useState(),[z,A]=l.useState(),E=!b&&!W&&!z,q=E&&(f>6||v.length>0),M=d.find((e=>"wallet_connect_v2"===e.connectorType)),I=l.useCallback((async(n,t)=>{if(!n)return;let l=t?.name??"Wallet";if(z?.connector!==n||"loading"!==j){if(L("loading"),"string"==typeof n)return g.connectorLogger.debug("Connecting wallet via deeplink",{wallet:l,url:n.length>80?`${n.slice(0,80)}...`:n}),A({connector:n,name:l,icon:t?.icon,id:t?.id,url:t?.url}),void window.open(n,"_blank");g.connectorLogger.debug("Connecting wallet via connector",{wallet:l,connectorType:n.connectorType}),A({connector:n,name:t?.name??n.walletBranding.name??"Wallet",icon:t?.icon??n.walletBranding.icon,id:t?.id,url:t?.url});try{let t=await n.connect({showPrompt:!0});if(!t)return g.connectorLogger.warn("Wallet connection returned null",{wallet:l,connectorType:n.connectorType}),L("error"),_(void 0),void o?.(new m.PrivyConnectorError("Unable to connect wallet"));g.connectorLogger.debug("Wallet connection successful",{wallet:l,connectorType:n.connectorType}),L("success"),_(void 0),p.setActiveWallet({address:t.address,client:t.walletClientType,appId:c.id}),setTimeout((()=>{e({connector:n,wallet:t})}),u.DEFAULT_SUCCESS_SCREEN_DURATION_MS)}catch(e){if(e?.message?.includes("already pending for origin")||e?.message?.includes("wallet_requestPermissions"))return void g.connectorLogger.debug("Connection request already pending, maintaining loading state",{wallet:l});let t=e instanceof Error?e.message:String(e?.message||"Unknown error");g.connectorLogger.error("Wallet connection failed",e,{wallet:l,connectorType:n.connectorType,errorCode:e?.privyErrorCode}),L("error"),_(e?.privyErrorCode),o?.(e instanceof Error?e:new m.PrivyConnectorError(t||"Unable to connect wallet"))}}else g.connectorLogger.debug("Duplicate connection attempt prevented",{wallet:l})}),[c.id,e,z,j]),N=l.useCallback((()=>W?(L(void 0),_(void 0),A(void 0),void S(void 0)):z?(L(void 0),_(void 0),void A(void 0)):b?(L(void 0),_(void 0),A(void 0),void C(void 0)):"error"===j||"loading"===j?(L(void 0),_(void 0),void A(void 0)):void n?.()),[W,z,b,j,n]),B=l.useMemo((()=>z?.connector===M&&W&&i.isMobile&&z?.name?w("connectWallet.goToWallet",{walletName:z.name}):z?.connector===M&&W&&z?.name?w("connectWallet.scanToConnect",{walletName:z.name}):W&&z?.name?i.isMobile?w("connectWallet.goToWallet",{walletName:z.name}):w("connectWallet.scanToConnect",{walletName:z.name}):"string"==typeof z?.connector?w("connectWallet.openOrInstall",{walletName:z.name}):b&&!z?w("connectWallet.selectNetwork"):z?null:w("connectWallet.selectYourWallet")),[z,W,b,M,w]);return{selected:b,setSelected:C,qrUrl:W,setQrUrl:S,connecting:z,uiState:j,errorCode:T,search:v,setSearch:x,wallets:y,walletCount:f,wc:M,isInitialConnectView:E,showSearchBar:q,title:B,handleConnect:I,handleBack:N,onClose:t,onConnect:e,app:s}}({..._,walletList:D,walletChainType:F}),se=U.find((e=>"wallet_connect_v2"===e.connectorType)),ce=U.find((e=>"walletconnect_solana"===e.walletBranding.id)),de=l.useRef(null),ue=t.useVirtualizer({count:Z.length,getScrollElement:()=>de.current,estimateSize:()=>56,overscan:6,gap:5}),he=l.useCallback((async e=>{let n="solana-only"!==F&&e.chains?.some((e=>e.startsWith("eip155"))),t="ethereum-only"!==F&&e.chains?.some((e=>e.startsWith("solana"))),l=()=>{let n=e.id;return p.mobileWalletsConfig[n]||p.mobileWalletsConfig[`${n}_wallet`]},o=n=>{let t=v.normalize(e.id);return U.find((e=>v.normalize(e.walletClientType)===t&&e.chainType===n&&"wallet_connect_v2"!==e.connectorType&&!("ethereum"===e.chainType&&e instanceof p.EthereumNullConnector||"solana"===e.chainType&&e instanceof p.SolanaNullConnector)))},a=async()=>{if(!se||!e.listing)return!1;let n=f[e.listing.slug]?{...e.listing,...f[e.listing.slug]}:e.listing;return se.setWalletEntry(n,G),await se.resetConnection(e.id),await ne(se,{name:e.label,icon:e.icon,id:e.id,url:e.url}),!0},r=async()=>!!ce&&!!e.listing&&(await ce.disconnect(),ce.wallet.setWalletEntry(e.listing,G),await new Promise((e=>setTimeout(e,100))),await ne(ce,{name:e.label,icon:e.icon,id:e.id,url:e.url}),!0),s=async n=>{let t=(e=>{let n=l();if(n)return n.getMobileRedirect({isSolana:e,connectOnly:!!C,useUniversalLink:!1})})(n);return!!t&&(await ne(t,{name:e.label,icon:e.icon,id:e.id,url:e.url}),!0)};if(n&&t)V(e);else{if(n&&!t){let n=o("ethereum");if(n&&!S(n))return g.connectorLogger.debug("Attempting injected EVM connection",{wallet:e.id,connectorType:n.connectorType}),void await ne(n,{name:e.label,icon:e.icon,id:e.id,url:e.url});if(i.isMobile&&l()){if(await s(!1)||await a())return}else if(await a()||await s(!1))return}if(t&&!n){let n=o("solana");if(n&&!S(n))return g.connectorLogger.debug("Attempting injected Solana connection",{wallet:e.id,connectorType:n.connectorType}),void await ne(n,{name:e.label,icon:e.icon,id:e.id,url:e.url});if(i.isMobile){if(await s(!0)||await r())return}else if(await r()||await s(!0))return}if(!S(e.connector)){if(g.connectorLogger.debug("Using fallback direct connector",{wallet:e.id,connectorType:e.connector?.connectorType}),se&&"wallet_connect_v2"===e.connector?.connectorType)if(await se.resetConnection(e.id),"wallet_connect_qr"!==e.id&&e.listing){let n=f[e.listing.slug]?{...e.listing,...f[e.listing.slug]}:e.listing;se.setWalletEntry(n,G)}else se.setWalletEntry({id:"wallet_connect_qr",name:"WalletConnect",rdns:"",slug:"wallet-connect",homepage:"",chains:["eip155"],mobile:{native:"",universal:void 0}},G);return ce&&"walletconnect_solana"===e.connector?.walletBranding.id&&(await ce.disconnect(),"wallet_connect_qr_solana"!==e.id&&e.listing?ce.wallet.setWalletEntry(e.listing,G):ce.wallet.setWalletEntry({id:"wallet_connect_solana_qr",name:"WalletConnect",rdns:"",slug:"wallet-connect-solana",homepage:"",chains:["solana"],mobile:{native:"",universal:void 0}},G),await new Promise((e=>setTimeout(e,100)))),void await ne(e.connector,{name:e.label,icon:e.icon,id:e.id,url:e.url})}e.url?await ne(e.url,{name:e.label,icon:e.icon,id:e.id,url:e.url}):g.connectorLogger.warn("No available connection method for wallet",{wallet:e.id})}}),[se,ce,ne,V,G,F,C,U]);return l.useEffect((()=>{if(!j)return;let e=Z.find((({id:e})=>e===j));e&&he(e).catch(console.error)}),[j]),/*#__PURE__*/e.jsxs(y.Screen,{className:o,children:[/*#__PURE__*/e.jsx(y.Screen.Header,{icon:L&&ie?void 0:Y&&!H||H&&i.isMobile&&Y?.icon?Y.icon:Y?void 0:w.WalletCards,iconVariant:Y&&!H||H&&i.isMobile?"loading":void 0,iconLoadingStatus:Y&&!H||H&&i.isMobile?{success:"success"===J,fail:"error"===J}:void 0,title:L&&ie?void 0:Y&&!H?K("connectWallet.waitingForWallet",{walletName:Y.name}):H&&i.isMobile?K("connectWallet.waitingForWallet",{walletName:Y?.name??"connection"}):oe,subtitle:L&&ie?void 0:Y&&!H&&"string"==typeof Y.connector?K("connectWallet.installAndConnect",{walletName:Y.name}):Y&&!H&&"string"!=typeof Y.connector?"error"===J?X===m.PrivyErrorCode.NO_SOLANA_ACCOUNTS?`The connected wallet has no Solana accounts. Please add a Solana account in ${Y.name} and try again.`:K("connectWallet.tryConnectingAgain"):K("connectionStatus.connectOneWallet"):ie?r??(R?K("connectWallet.connectToAccount",{appName:R.name}):null):null,showBack:!!P||!ie,showClose:!0,onBack:P||te,onClose:$}),/*#__PURE__*/e.jsxs(y.Screen.Body,{ref:de,$colorScheme:W.appearance.palette.colorScheme,style:{marginBottom:H?"0.5rem":void 0},children:[le&&/*#__PURE__*/e.jsx(A,{children:/*#__PURE__*/e.jsxs(d.EmailUpdateForm,{style:{background:"transparent"},children:[/*#__PURE__*/e.jsx(p.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(n.MagnifyingGlassIcon,{})}),/*#__PURE__*/e.jsx("input",{className:"login-method-button",type:"text",placeholder:K("connectWallet.searchPlaceholder",{count:String(ee)}),onChange:e=>re(e.target.value),value:ae})]})}),H&&i.isMobile&&"loading"===J&&/*#__PURE__*/e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"1rem"},children:[/*#__PURE__*/e.jsx(a.Button,{variant:"primary",onClick:()=>window.open(H.universal??H.native,"_blank"),style:{width:"100%"},children:K("connectWallet.openInApp")}),/*#__PURE__*/e.jsx(B,{value:H.universal??H.native,iconOnly:!0,children:"Copy link"})]}),H&&!i.isMobile&&"loading"===J&&/*#__PURE__*/e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"1rem"},children:/*#__PURE__*/e.jsx(B,{value:H.universal??H.native,iconOnly:!0,children:K("connectWallet.copyLink")})}),H&&!i.isMobile&&/*#__PURE__*/e.jsx(c.QrCode,{size:280,url:H.universal??H.native,squareLogoElement:Y?.icon?"string"==typeof Y.icon?n=>/*#__PURE__*/e.jsx("svg",{...n,children:/*#__PURE__*/e.jsx("image",{href:Y.icon,height:n.height,width:n.width})}):Y.icon:g.WalletConnect}),H&&!i.isMobile&&Y?.url&&("binance"===Y.id||"binanceus"===Y.id||"binance-defi"===Y.id)&&/*#__PURE__*/e.jsxs(O,{children:[/*#__PURE__*/e.jsxs("span",{children:["Don't have ",Y.name,"? "]}),/*#__PURE__*/e.jsx(s.Link,{href:Y.url,target:"_blank",size:"sm",children:"Download here"})]}),/*#__PURE__*/e.jsxs(E,{children:[Y&&!H&&"string"==typeof Y.connector&&/*#__PURE__*/e.jsxs(q,{onClick:()=>window.open(Y.connector,"_blank"),children:[Y.icon&&("string"==typeof Y.icon?/*#__PURE__*/e.jsx(T,{src:Y.icon}):/*#__PURE__*/e.jsx(Y.icon,{})),/*#__PURE__*/e.jsx(N,{children:Y.name})]}),Q?.chains.some((e=>e.startsWith("eip155")))&&!Y&&/*#__PURE__*/e.jsxs(q,{onClick:()=>he({...Q,chains:Q.chains.filter((e=>e.startsWith("eip155")))}),children:[Q.icon&&("string"==typeof Q.icon?/*#__PURE__*/e.jsx(T,{src:Q.icon}):/*#__PURE__*/e.jsx(Q.icon,{})),/*#__PURE__*/e.jsx(N,{children:Q.label}),/*#__PURE__*/e.jsx(M,{children:/*#__PURE__*/e.jsx(x,{})})]}),Q?.chains.some((e=>e.startsWith("solana")))&&!Y&&/*#__PURE__*/e.jsxs(q,{onClick:()=>he({...Q,chains:Q.chains.filter((e=>e.startsWith("solana")))}),children:[Q.icon&&("string"==typeof Q.icon?/*#__PURE__*/e.jsx(T,{src:Q.icon}):/*#__PURE__*/e.jsx(Q.icon,{})),/*#__PURE__*/e.jsx(N,{children:Q.label}),/*#__PURE__*/e.jsx(M,{children:/*#__PURE__*/e.jsx(b,{})})]}),ie&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[!(ee>0)&&/*#__PURE__*/e.jsx(I,{children:K("connectWallet.noWalletsFound")}),ee>0&&!H&&/*#__PURE__*/e.jsx("div",{style:{maxHeight:56*Math.min(Z.length,5)+5,width:"100%"},children:/*#__PURE__*/e.jsx("div",{style:{height:`${ue.getTotalSize()}px`,width:"100%",position:"relative"},children:ue.getVirtualItems().map((n=>/*#__PURE__*/e.jsx(z,{index:n.index,style:{position:"absolute",top:0,left:0,height:`${n.size}px`,transform:`translateY(${n.start}px)`},data:{wallets:Z,walletChainType:F,handleWalletClick:he}},n.key)))})})]})]})]}),/*#__PURE__*/e.jsxs(y.Screen.Footer,{children:[Y&&!H&&"string"!=typeof Y.connector&&"error"===J&&/*#__PURE__*/e.jsx(y.Screen.Actions,{children:/*#__PURE__*/e.jsx(a.Button,{style:{width:"100%",alignItems:"center"},variant:"error",onClick:()=>ne(Y.connector,{name:Y.name,icon:Y.icon,id:Y.id,url:Y.url}),children:K("connectWallet.retry")})}),!!(R&&R.legal.privacyPolicyUrl&&R.legal.termsAndConditionsUrl)&&/*#__PURE__*/e.jsx(a.TermsAndConditions,{app:R,alwaysShowImplicitConsent:!0}),/*#__PURE__*/e.jsx(y.Screen.Watermark,{})]})]})},exports.useWalletsListController=k;