@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 25.8 kB
JavaScript
"use strict";var e=require("react/jsx-runtime"),n=require("@heroicons/react/24/outline"),t=require("@tanstack/react-virtual"),i=require("react"),l=require("react-device-detect"),a=require("styled-components"),o=require("./Button-BEaVAnh4.js"),r=require("@heroicons/react/24/outline/CheckIcon"),s=require("./copy-BiZ7dtqy.js"),c=require("./Link-DmzPZ_M7.js"),d=require("./ModalHeader-n6Aqpos_.js"),u=require("./QrCode-D-MkB93C.js"),h=require("./EmailInputForm-tjrhBacA.js"),p=require("./context-BPd2qxKv.js"),m=require("./useI18n-5uCrUblH.js"),g=require("./useActiveWallet-B-Pd49hn.js"),y=require("./internal-context-NWsAL807.js"),w=require("./WalletCards-BfpeHH5n.js"),f=require("./prepareFundingModalData-Do7d2fgq.js"),v=require("./Screen-J7z62u7O.js");function x(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var b=/*#__PURE__*/x(r);let C=/*#__PURE__*/a.styled.button.withConfig({displayName:"CopyTextButton",componentId:"sc-4b0620dc-0"})(["display:flex;align-items:center;gap:0.5rem;&:hover{text-decoration:underline;}svg{width:0.875rem;height:0.875rem;}"]),j=/*#__PURE__*/a.styled.span.withConfig({displayName:"CopiedText",componentId:"sc-4b0620dc-1"})(["display:flex;align-items:center;gap:0.25rem;font-size:0.875rem;color:var(--privy-color-foreground-2);"]),W=/*#__PURE__*/a.styled(b.default).withConfig({displayName:"GreenCheck",componentId:"sc-4b0620dc-2"})(["color:var(--privy-color-success);"]),k=/*#__PURE__*/a.styled(s.Copy).withConfig({displayName:"StyledCopy",componentId:"sc-4b0620dc-3"})(["color:var(--privy-color-foreground-3);opactiy:0.5;"]);function T({children:n,iconOnly:t,value:l,hideCopyIcon:a,...o}){let[r,s]=i.useState(!1);/*#__PURE__*/return e.jsxs(C,{...o,onClick:()=>{navigator.clipboard.writeText(l||n).catch(console.error),s(!0),setTimeout((()=>s(!1)),1500)},children:[n," ",r?/*#__PURE__*/e.jsxs(j,{children:[/*#__PURE__*/e.jsx(W,{})," ",!t&&"Copied"]}):!a&&/*#__PURE__*/e.jsx(k,{})]})}const _={phantom:{mobile:{native:"phantom://",universal:"https://phantom.app/ul/"}},solflare:{mobile:{native:void 0,universal:"https://solflare.com/ul/v1/"}},metamask:{image_url:{sm:g.Metamask,md:g.Metamask}}};class S{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=S.normalize(e);return this.normalizedAllowList.some((e=>t===S.normalize(e)))}inDenyList(e,n){return"listing"===n&&"rabby"===e}chainMatches(e){return"ethereum-only"===this.chainFilter?"ethereum"===e:"solana-only"!==this.chainFilter||"solana"===e}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,i=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)}else t.set(e.id,e)};e.filter((e=>this.connectorOk(e))).forEach((e=>{let n=S.normalize(e.walletClientType);i({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"]})}));let l=e.find((e=>"wallet_connect_v2"===e.connectorType)),a=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=>S.normalize(e.walletClientType)===S.normalize(n.slug)&&"ethereum"===e.chainType&&"null"!==e.connectorType))||l||n.mobile.native||n.mobile.universal||g.mobileWalletsConfig[n.slug]?.chainTypes.includes("ethereum")||(t=t.filter((e=>!e.includes("eip155:")))),e.some((e=>S.normalize(e.walletClientType)===S.normalize(n.slug)&&"solana"===e.chainType&&"null"!==e.connectorType))||a||n.mobile.native||n.mobile.universal||g.mobileWalletsConfig[n.slug]?.chainTypes.includes("solana")||(t=t.filter((e=>!e.includes("solana:")))),!t.length)return;let o=S.normalize(n.slug),r=_[n.slug],s=r?.image_url?.sm||n.image_url?.sm;t.some((e=>e.includes("eip155:")))&&i({id:o,label:n.name||o,source:"listing",listing:n,chainType:"ethereum",icon:s,url:n.homepage,chains:t}),t.some((e=>e.includes("solana:")))&&i({id:o,label:n.name||o,source:"listing",listing:n,chainType:"solana",icon:s,url:n.homepage,chains:t})})),this.includeWalletConnectQr&&l&&i({id:"wallet_connect_qr",label:"WalletConnect",source:"connector",connector:l,chainType:"ethereum",icon:f.WALLET_CONNECT_LOGO_DATA_URI,url:void 0,chains:["eip155"]}),this.includeWalletConnectQrSolana&&a&&i({id:"wallet_connect_qr_solana",label:"WalletConnect",source:"connector",connector:a,chainType:"solana",icon:f.WALLET_CONNECT_LOGO_DATA_URI,url:void 0,chains:["solana"]});let o=Array.from(t.values());o.forEach((e=>{let n=_[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(S.normalize(e),n)})),{wallets:o.slice().sort(((e,n)=>{let t=S.normalize(e.id),i=S.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"===i?i="binance":"universalprofiles"===i?i="universal_profile":"cryptocom-defi"===i?i="cryptocom":"bitkeep"===i&&(i="bitget_wallet");let l=r.has(t),a=r.has(i);return l&&a?r.get(t)-r.get(i):l?-1:a?1:"connector"===e.source&&"listing"===n.source?-1:"listing"===e.source&&"connector"===n.source?1:e.label.toLowerCase().localeCompare(n.label.toLowerCase())})),walletCount:o.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 z=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"})]}),L=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 I=/*#__PURE__*/a.styled.div.withConfig({displayName:"Header",componentId:"sc-9b65f2b6-0"})(["display:flex;justify-content:space-between;align-items:center;"]),N=/*#__PURE__*/a.styled.button.withConfig({displayName:"CloseButton",componentId:"sc-9b65f2b6-1"})(["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);"]),A=/*#__PURE__*/a.styled.div.withConfig({displayName:"WalletIconWithActiveIndicator",componentId:"sc-9b65f2b6-2"})(["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;}"]),E=/*#__PURE__*/a.styled.img.withConfig({displayName:"WalletIcon",componentId:"sc-9b65f2b6-3"})(["width:32px;height:32px;border-radius:0.25rem;object-fit:contain;"]),q=/*#__PURE__*/a.styled.span.withConfig({displayName:"Chip",componentId:"sc-9b65f2b6-4"})(["display:flex;gap:0.25rem;align-items:center;padding:0.25rem 0.5rem;font-size:0.75rem;font-weight:500;line-height:1.125rem;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;}"]),B=/*#__PURE__*/a.styled.div.withConfig({displayName:"ScrollContainer",componentId:"sc-9b65f2b6-5"})(["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;"," background-repeat:no-repeat;background-size:100% 32px,100% 16px;background-attachment:local,scroll;"],(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));function M({enabled:e=!0,walletList:n,walletChainType:t}){let l=p.useAppConfig(),{connectors:a}=y.usePrivyInternal(),{listings:o,loading:r}=g.useExternalWalletListings(e),s=t??l.appearance.walletChainType,c=n??l.appearance?.walletList,d=i.useMemo((()=>new S(s,c)),[s,c]),{wallets:u,walletCount:h}=i.useMemo((()=>d.getWallets(a,o)),[d,a,o]),[m,w]=i.useState(""),f=i.useMemo((()=>m?u.filter((e=>e.label.toLowerCase().includes(m.toLowerCase()))):u),[m,u]),[v,x]=i.useState();return{selected:v,setSelected:x,search:m,setSearch:w,loadingListings:r,wallets:f,walletCount:h}}let O=e=>!e||"string"!=typeof e&&(e instanceof g.EthereumNullConnector||e instanceof g.SolanaNullConnector);const F=({index:n,style:t,data:i,recent:l})=>{let a=i.wallets[n],{walletChainType:o,handleWalletClick:r}=i,{t:s}=m.useI18n(),c={...t,boxSizing:"border-box"};return a?/*#__PURE__*/e.jsxs(P,{style:c,onClick:()=>r(a),children:[a.icon&&(a.connector&&!O(a.connector)?/*#__PURE__*/e.jsx(A,{children:"string"==typeof a.icon?/*#__PURE__*/e.jsx(E,{src:a.icon}):/*#__PURE__*/e.jsx(a.icon,{style:{width:"32px",height:"32px"}})}):"string"==typeof a.icon?/*#__PURE__*/e.jsx(E,{src:a.icon}):/*#__PURE__*/e.jsx(a.icon,{style:{width:"32px",height:"32px"}})),/*#__PURE__*/e.jsx(Q,{children:a.label}),l?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(q,{children:s("connectWallet.lastUsed")}),/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsxs(e.Fragment,{children:["ethereum-only"===o&&/*#__PURE__*/e.jsx(z,{}),"solana-only"===o&&/*#__PURE__*/e.jsx(L,{})]})})]}):/*#__PURE__*/e.jsx(R,{children:!("ethereum-only"===o||"solana-only"===o)&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[a.chains?.some((e=>e.startsWith("eip155")))&&/*#__PURE__*/e.jsx(z,{}),a.chains?.some((e=>e.startsWith("solana")))&&/*#__PURE__*/e.jsx(L,{})]})})]}):null};let U=/*#__PURE__*/a.styled.div.withConfig({displayName:"StickySearchContainer",componentId:"sc-5a8fc7d8-0"})(["position:sticky;margin-top:-3px;padding-top:3px;top:-3px;z-index:1;background:var(--privy-color-background);padding-bottom:calc(var(--screen-space) / 2);"]),D=/*#__PURE__*/a.styled.div.withConfig({displayName:"WalletListContainer",componentId:"sc-5a8fc7d8-1"})(["display:flex;flex-direction:column;gap:","px;"],5),P=/*#__PURE__*/a.styled.button.withConfig({displayName:"Button",componentId:"sc-5a8fc7d8-2"})(["&&{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);}"]),R=/*#__PURE__*/a.styled.span.withConfig({displayName:"ButtonBadge",componentId:"sc-5a8fc7d8-3"})(["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;}"]),$=/*#__PURE__*/a.styled.div.withConfig({displayName:"EmptyContainer",componentId:"sc-5a8fc7d8-4"})(["height:60px;display:flex;align-items:center;justify-content:center;text-align:center;"]),Q=/*#__PURE__*/a.styled.span.withConfig({displayName:"WalletName",componentId:"sc-5a8fc7d8-5"})(["text-overflow:ellipsis;white-space:nowrap;color:var(--privy-color-foreground);font-weight:400;flex:1;"]),H=/*#__PURE__*/a.styled(T).withConfig({displayName:"StyledCopyableText",componentId:"sc-5a8fc7d8-6"})(["&&{margin:0.5rem auto 0 auto;}"]),G=/*#__PURE__*/a.styled.div.withConfig({displayName:"BinanceDownloadMessage",componentId:"sc-5a8fc7d8-7"})(["text-align:center;margin-top:1rem;font-size:0.875rem;font-weight:400;color:var(--privy-color-foreground-3);"]);exports.Chip=q,exports.CloseButton=N,exports.CopyableText=T,exports.Header=I,exports.ScrollContainer=B,exports.WalletFilterer=S,exports.WalletIcon=E,exports.WalletRow=F,exports.i=({className:a,customDescription:r,connectOnly:s,preSelectedWalletId:x,hideHeader:b,...C})=>{let j=p.useAppConfig(),{t:W}=m.useI18n(),{connectors:k}=y.usePrivyInternal(),T=C.walletChainType||j.appearance.walletChainType,I=C.walletList||j.appearance?.walletList,{onBack:N,onClose:A,app:q}=C,{selected:B,setSelected:V,qrUrl:Y,setQrUrl:J,connecting:K,uiState:X,errorCode:Z,wallets:ee,walletCount:ne,handleConnect:te,handleBack:ie,showSearchBar:le,isInitialConnectView:ae,title:oe,search:re,setSearch:se}=function({onConnect:e,onBack:n,onClose:t,onConnectError:a,walletList:o,walletChainType:r,app:s}){let c=p.useAppConfig(),{connectors:d}=y.usePrivyInternal(),{t:u}=m.useI18n(),{wallets:h,walletCount:w,search:f,setSearch:v,selected:x,setSelected:b}=M({enabled:g.shouldFetchWcRegistryListings(o??[]),walletList:o,walletChainType:r}),[C,j]=i.useState(),[W,k]=i.useState(),[T,_]=i.useState(),[S,z]=i.useState(),L=!x&&!T&&!S,I=L&&(w>6||f.length>0),N=d.find((e=>"wallet_connect_v2"===e.connectorType)),A=i.useCallback((async(n,t)=>{if(n){if(S?.connector===n&&"loading"===C)return void console.log("Already connecting to this wallet, skipping duplicate attempt");if(j("loading"),"string"==typeof n)return z({connector:n,name:t?.name??"Wallet",icon:t?.icon,id:t?.id,url:t?.url}),void window.open(n,"_blank");z({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 j("error"),k(void 0),void a?.(new y.PrivyConnectorError("Unable to connect wallet"));j("success"),k(void 0),g.setActiveWallet({address:t.address,client:t.walletClientType,appId:c.id}),setTimeout((()=>{e({connector:n,wallet:t})}),p.DEFAULT_SUCCESS_SCREEN_DURATION_MS)}catch(n){if(console.error("ERROR: ",{e:n}),n?.message?.includes("already pending for origin")||n?.message?.includes("wallet_requestPermissions"))return void console.log("Connection request already pending, maintaining loading state");j("error"),k(n?.privyErrorCode),a?.(n instanceof Error?n:new y.PrivyConnectorError(n?.message||"Unable to connect wallet"))}}}),[c.id,e,S,C]),E=i.useCallback((()=>T?(j(void 0),k(void 0),z(void 0),void _(void 0)):S?(j(void 0),k(void 0),void z(void 0)):x?(j(void 0),k(void 0),z(void 0),void b(void 0)):"error"===C||"loading"===C?(j(void 0),k(void 0),void z(void 0)):void n?.()),[T,S,x,C,n]),q=i.useMemo((()=>S?.connector===N&&T&&l.isMobile&&S?.name?u("connectWallet.goToWallet",{walletName:S.name}):S?.connector===N&&T&&S?.name?u("connectWallet.scanToConnect",{walletName:S.name}):T&&S?.name?l.isMobile?u("connectWallet.goToWallet",{walletName:S.name}):u("connectWallet.scanToConnect",{walletName:S.name}):"string"==typeof S?.connector?u("connectWallet.openOrInstall",{walletName:S.name}):x&&!S?u("connectWallet.selectNetwork"):S?null:u("connectWallet.selectYourWallet")),[S,T,x,N,u]);return{selected:x,setSelected:b,qrUrl:T,setQrUrl:_,connecting:S,uiState:C,errorCode:W,search:f,setSearch:v,wallets:h,walletCount:w,wc:N,isInitialConnectView:L,showSearchBar:I,title:q,handleConnect:A,handleBack:E,onClose:t,onConnect:e,app:s}}({...C,walletList:I,walletChainType:T}),ce=k.find((e=>"wallet_connect_v2"===e.connectorType)),de=k.find((e=>"walletconnect_solana"===e.walletBranding.id)),ue=i.useRef(null),he=t.useVirtualizer({count:ee.length,getScrollElement:()=>ue.current,estimateSize:()=>56,overscan:6,gap:5}),pe=i.useCallback((async e=>{let n="solana-only"!==T&&e.chains?.some((e=>e.startsWith("eip155"))),t="ethereum-only"!==T&&e.chains?.some((e=>e.startsWith("solana"))),i=()=>{let n=e.id;return g.mobileWalletsConfig[n]||g.mobileWalletsConfig[`${n}_wallet`]},a=n=>{let t=S.normalize(e.id);return k.find((e=>S.normalize(e.walletClientType)===t&&e.chainType===n&&!("ethereum"===e.chainType&&e instanceof g.EthereumNullConnector||"solana"===e.chainType&&e instanceof g.SolanaNullConnector)))},o=async()=>{if(!ce||!e.listing)return!1;let n=_[e.listing.slug]?{...e.listing,..._[e.listing.slug]}:e.listing;return ce.setWalletEntry(n,J),await ce.resetConnection(e.id),await te(ce,{name:e.label,icon:e.icon,id:e.id,url:e.url}),!0},r=async()=>!!de&&!!e.listing&&(await de.disconnect(),de.wallet.setWalletEntry(e.listing,J),await new Promise((e=>setTimeout(e,100))),await te(de,{name:e.label,icon:e.icon,id:e.id,url:e.url}),!0),c=async n=>{let t=(e=>{let n=i();if(n)return n.getMobileRedirect({isSolana:e,connectOnly:!!s,useUniversalLink:!1})})(n);return!!t&&(await te(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=a("ethereum");if(n&&!O(n))return void await te(n,{name:e.label,icon:e.icon,id:e.id,url:e.url});if(l.isMobile&&i()){if(await c(!1)||await o())return}else if(await o()||await c(!1))return}if(t&&!n){let n=a("solana");if(n&&!O(n))return void await te(n,{name:e.label,icon:e.icon,id:e.id,url:e.url});if(l.isMobile){if(await c(!0)||await r())return}else if(await r()||await c(!0))return}if(!O(e.connector)){if(ce&&"wallet_connect_v2"===e.connector?.connectorType)if(await ce.resetConnection(e.id),"wallet_connect_qr"!==e.id&&e.listing){let n=_[e.listing.slug]?{...e.listing,..._[e.listing.slug]}:e.listing;ce.setWalletEntry(n,J)}else ce.setWalletEntry({id:"wallet_connect_qr",name:"WalletConnect",rdns:"",slug:"wallet-connect",homepage:"",chains:["eip155"],mobile:{native:"",universal:void 0}},J);return de&&"walletconnect_solana"===e.connector?.walletBranding.id&&(await de.disconnect(),"wallet_connect_qr_solana"!==e.id&&e.listing?de.wallet.setWalletEntry(e.listing,J):de.wallet.setWalletEntry({id:"wallet_connect_solana_qr",name:"WalletConnect",rdns:"",slug:"wallet-connect-solana",homepage:"",chains:["solana"],mobile:{native:"",universal:void 0}},J),await new Promise((e=>setTimeout(e,100)))),void await te(e.connector,{name:e.label,icon:e.icon,id:e.id,url:e.url})}e.url&&await te(e.url,{name:e.label,icon:e.icon,id:e.id,url:e.url})}}),[ce,de,te,V,J,T,s,k]);return i.useEffect((()=>{if(!x)return;let e=ee.find((({id:e})=>e===x));e&&pe(e).catch(console.error)}),[x]),/*#__PURE__*/e.jsxs(v.Screen,{className:a,children:[/*#__PURE__*/e.jsx(v.Screen.Header,{icon:b&&ae?void 0:K&&!Y||Y&&l.isMobile&&K?.icon?K.icon:K?void 0:w.WalletCards,iconVariant:K&&!Y||Y&&l.isMobile?"loading":void 0,iconLoadingStatus:K&&!Y||Y&&l.isMobile?{success:"success"===X,fail:"error"===X}:void 0,title:b&&ae?void 0:K&&!Y?W("connectWallet.waitingForWallet",{walletName:K.name}):Y&&l.isMobile?W("connectWallet.waitingForWallet",{walletName:K?.name??"connection"}):oe,subtitle:b&&ae?void 0:K&&!Y&&"string"==typeof K.connector?W("connectWallet.installAndConnect",{walletName:K.name}):K&&!Y&&"string"!=typeof K.connector?"error"===X?Z===y.PrivyErrorCode.NO_SOLANA_ACCOUNTS?`The connected wallet has no Solana accounts. Please add a Solana account in ${K.name} and try again.`:W("connectWallet.tryConnectingAgain"):W("connectionStatus.connectOneWallet"):ae?r??(q?W("connectWallet.connectToAccount",{appName:q.name}):null):null,showBack:!!N||!ae,showClose:!0,onBack:N||ie,onClose:A}),/*#__PURE__*/e.jsxs(v.Screen.Body,{ref:ue,$colorScheme:j.appearance.palette.colorScheme,style:{marginBottom:Y?"0.5rem":void 0},children:[le&&/*#__PURE__*/e.jsx(U,{children:/*#__PURE__*/e.jsxs(h.EmailUpdateForm,{style:{background:"transparent"},children:[/*#__PURE__*/e.jsx(g.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(n.MagnifyingGlassIcon,{})}),/*#__PURE__*/e.jsx("input",{className:"login-method-button",type:"text",placeholder:W("connectWallet.searchPlaceholder",{count:String(ne)}),onChange:e=>se(e.target.value),value:re})]})}),Y&&l.isMobile&&"loading"===X&&/*#__PURE__*/e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"1rem"},children:[/*#__PURE__*/e.jsx(o.Button,{variant:"primary",onClick:()=>window.open(Y.universal??Y.native,"_blank"),style:{width:"100%"},children:W("connectWallet.openInApp")}),/*#__PURE__*/e.jsx(H,{value:Y.universal??Y.native,iconOnly:!0,children:"Copy link"})]}),Y&&!l.isMobile&&"loading"===X&&/*#__PURE__*/e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"1rem"},children:/*#__PURE__*/e.jsx(H,{value:Y.universal??Y.native,iconOnly:!0,children:W("connectWallet.copyLink")})}),Y&&!l.isMobile&&/*#__PURE__*/e.jsx(u.QrCode,{size:280,url:Y.universal??Y.native,squareLogoElement:K?.icon?"string"==typeof K.icon?n=>/*#__PURE__*/e.jsx("svg",{...n,children:/*#__PURE__*/e.jsx("image",{href:K.icon,height:n.height,width:n.width})}):K.icon:f.WalletConnect}),Y&&!l.isMobile&&K?.url&&("binance"===K.id||"binanceus"===K.id||"binance-defi"===K.id)&&/*#__PURE__*/e.jsxs(G,{children:[/*#__PURE__*/e.jsxs("span",{children:["Don't have ",K.name,"? "]}),/*#__PURE__*/e.jsx(c.Link,{href:K.url,target:"_blank",size:"sm",children:"Download here"})]}),/*#__PURE__*/e.jsxs(D,{children:[K&&!Y&&"string"==typeof K.connector&&/*#__PURE__*/e.jsxs(P,{onClick:()=>window.open(K.connector,"_blank"),children:[K.icon&&("string"==typeof K.icon?/*#__PURE__*/e.jsx(E,{src:K.icon}):/*#__PURE__*/e.jsx(K.icon,{})),/*#__PURE__*/e.jsx(Q,{children:K.name})]}),B?.chains.some((e=>e.startsWith("eip155")))&&!K&&/*#__PURE__*/e.jsxs(P,{onClick:()=>pe({...B,chains:B.chains.filter((e=>e.startsWith("eip155")))}),children:[B.icon&&("string"==typeof B.icon?/*#__PURE__*/e.jsx(E,{src:B.icon}):/*#__PURE__*/e.jsx(B.icon,{})),/*#__PURE__*/e.jsx(Q,{children:B.label}),/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsx(z,{})})]}),B?.chains.some((e=>e.startsWith("solana")))&&!K&&/*#__PURE__*/e.jsxs(P,{onClick:()=>pe({...B,chains:B.chains.filter((e=>e.startsWith("solana")))}),children:[B.icon&&("string"==typeof B.icon?/*#__PURE__*/e.jsx(E,{src:B.icon}):/*#__PURE__*/e.jsx(B.icon,{})),/*#__PURE__*/e.jsx(Q,{children:B.label}),/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsx(L,{})})]}),ae&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[!(ne>0)&&/*#__PURE__*/e.jsx($,{children:W("connectWallet.noWalletsFound")}),ne>0&&!Y&&/*#__PURE__*/e.jsx("div",{style:{maxHeight:56*Math.min(ee.length,5)+5,width:"100%"},children:/*#__PURE__*/e.jsx("div",{style:{height:`${he.getTotalSize()}px`,width:"100%",position:"relative"},children:he.getVirtualItems().map((n=>/*#__PURE__*/e.jsx(F,{index:n.index,style:{position:"absolute",top:0,left:0,height:`${n.size}px`,transform:`translateY(${n.start}px)`},data:{wallets:ee,walletChainType:T,handleWalletClick:pe}},n.key)))})})]})]})]}),/*#__PURE__*/e.jsxs(v.Screen.Footer,{children:[K&&!Y&&"string"!=typeof K.connector&&"error"===X&&/*#__PURE__*/e.jsx(v.Screen.Actions,{children:/*#__PURE__*/e.jsx(o.Button,{style:{width:"100%",alignItems:"center"},variant:"error",onClick:()=>te(K.connector,{name:K.name,icon:K.icon,id:K.id,url:K.url}),children:W("connectWallet.retry")})}),!!(q&&q.legal.privacyPolicyUrl&&q.legal.termsAndConditionsUrl)&&/*#__PURE__*/e.jsx(d.TermsAndConditions,{app:q,alwaysShowImplicitConsent:!0}),/*#__PURE__*/e.jsx(v.Screen.Watermark,{})]})]})},exports.useWalletsListController=M;