UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) • 25 kB
"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-Bm_Ft0Dw.js"),r=require("@heroicons/react/24/outline/CheckIcon"),s=require("./copy-BiZ7dtqy.js"),c=require("./ModalHeader-DB7Tbjwz.js"),d=require("./QrCode-DsQD8cG6.js"),h=require("./EmailInputForm-tjrhBacA.js"),p=require("./context-DFq1obBO.js"),u=require("./useI18n-CY6Et_lH.js"),m=require("./useActiveWallet-BOX8xCn9.js"),g=require("./internal-context-NWsAL807.js"),y=require("./WalletCards-BfpeHH5n.js"),w=require("./prepareFundingModalData-Cnd6rhhJ.js"),f=require("./Screen-D9Tvi297.js");function v(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var x=/*#__PURE__*/v(r);let b=/*#__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;}"]),C=/*#__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);"]),j=/*#__PURE__*/a.styled(x.default).withConfig({displayName:"GreenCheck",componentId:"sc-4b0620dc-2"})(["color:var(--privy-color-success);"]),W=/*#__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(b,{...o,onClick:()=>{navigator.clipboard.writeText(l||n).catch(console.error),s(!0),setTimeout((()=>s(!1)),1500)},children:[n," ",r?/*#__PURE__*/e.jsxs(C,{children:[/*#__PURE__*/e.jsx(j,{})," ",!t&&"Copied"]}):!a&&/*#__PURE__*/e.jsx(W,{})]})}const k={phantom:{mobile:{native:"phantom://",universal:"https://phantom.app/ul/"}},solflare:{mobile:{native:void 0,universal:"https://solflare.com/ul/v1/"}},metamask:{image_url:{sm:m.Metamask,md:m.Metamask}}};class _{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=_.normalize(e);return this.normalizedAllowList.some((e=>t===_.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=_.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=>_.normalize(e.walletClientType)===_.normalize(n.slug)&&"ethereum"===e.chainType&&"null"!==e.connectorType))||l||n.mobile.native||n.mobile.universal||m.mobileWalletsConfig[n.slug]?.chainTypes.includes("ethereum")||(t=t.filter((e=>!e.includes("eip155:")))),e.some((e=>_.normalize(e.walletClientType)===_.normalize(n.slug)&&"solana"===e.chainType&&"null"!==e.connectorType))||a||n.mobile.native||n.mobile.universal||m.mobileWalletsConfig[n.slug]?.chainTypes.includes("solana")||(t=t.filter((e=>!e.includes("solana:")))),!t.length)return;let o=_.normalize(n.slug),r=k[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:w.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:w.WALLET_CONNECT_LOGO_DATA_URI,url:void 0,chains:["solana"]});let o=Array.from(t.values());o.forEach((e=>{let n=k[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(_.normalize(e),n)})),{wallets:o.slice().sort(((e,n)=>{let t=_.normalize(e.id),i=_.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 S=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"})]}),z=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 L=/*#__PURE__*/a.styled.div.withConfig({displayName:"Header",componentId:"sc-9b65f2b6-0"})(["display:flex;justify-content:space-between;align-items:center;"]),I=/*#__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;}"]),N=/*#__PURE__*/a.styled.img.withConfig({displayName:"WalletIcon",componentId:"sc-9b65f2b6-3"})(["width:32px;height:32px;border-radius:0.25rem;object-fit:contain;"]),E=/*#__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;}"]),q=/*#__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 B({enabled:e=!0,walletList:n,walletChainType:t}){let l=p.useAppConfig(),{connectors:a}=g.usePrivyInternal(),{listings:o,loading:r}=m.useExternalWalletListings(e),s=t??l.appearance.walletChainType,c=n??l.appearance?.walletList,d=i.useMemo((()=>new _(s,c)),[s,c]),{wallets:h,walletCount:u}=i.useMemo((()=>d.getWallets(a,o)),[d,a,o]),[y,w]=i.useState(""),f=i.useMemo((()=>y?h.filter((e=>e.label.toLowerCase().includes(y.toLowerCase()))):h),[y,h]),[v,x]=i.useState();return{selected:v,setSelected:x,search:y,setSearch:w,loadingListings:r,wallets:f,walletCount:u}}let M=e=>!e||"string"!=typeof e&&(e instanceof m.EthereumNullConnector||e instanceof m.SolanaNullConnector);const O=({index:n,style:t,data:i,recent:l})=>{let a=i.wallets[n],{walletChainType:o,handleWalletClick:r}=i,{t:s}=u.useI18n(),c={...t,boxSizing:"border-box"};return a?/*#__PURE__*/e.jsxs(P,{style:c,onClick:()=>r(a),children:[a.icon&&(a.connector&&!M(a.connector)?/*#__PURE__*/e.jsx(A,{children:"string"==typeof a.icon?/*#__PURE__*/e.jsx(N,{src:a.icon}):/*#__PURE__*/e.jsx(a.icon,{style:{width:"32px",height:"32px"}})}):"string"==typeof a.icon?/*#__PURE__*/e.jsx(N,{src:a.icon}):/*#__PURE__*/e.jsx(a.icon,{style:{width:"32px",height:"32px"}})),/*#__PURE__*/e.jsx($,{children:a.label}),l?/*#__PURE__*/e.jsxs(e.Fragment,{children:[/*#__PURE__*/e.jsx(E,{children:s("connectWallet.lastUsed")}),/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsxs(e.Fragment,{children:["ethereum-only"===o&&/*#__PURE__*/e.jsx(S,{}),"solana-only"===o&&/*#__PURE__*/e.jsx(z,{})]})})]}):/*#__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(S,{}),a.chains?.some((e=>e.startsWith("solana")))&&/*#__PURE__*/e.jsx(z,{})]})})]}):null};let F=/*#__PURE__*/a.styled.div.withConfig({displayName:"StickySearchContainer",componentId:"sc-34a6bff4-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);"]),U=/*#__PURE__*/a.styled.div.withConfig({displayName:"WalletListContainer",componentId:"sc-34a6bff4-1"})(["display:flex;flex-direction:column;gap:","px;"],5),P=/*#__PURE__*/a.styled.button.withConfig({displayName:"Button",componentId:"sc-34a6bff4-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-34a6bff4-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;}"]),D=/*#__PURE__*/a.styled.div.withConfig({displayName:"EmptyContainer",componentId:"sc-34a6bff4-4"})(["height:60px;display:flex;align-items:center;justify-content:center;text-align:center;"]),$=/*#__PURE__*/a.styled.span.withConfig({displayName:"WalletName",componentId:"sc-34a6bff4-5"})(["text-overflow:ellipsis;white-space:nowrap;color:var(--privy-color-foreground);font-weight:400;flex:1;"]),Q=/*#__PURE__*/a.styled(T).withConfig({displayName:"StyledCopyableText",componentId:"sc-34a6bff4-6"})(["&&{margin:0.5rem auto 0 auto;}"]);exports.Chip=E,exports.CloseButton=I,exports.CopyableText=T,exports.Header=L,exports.ScrollContainer=q,exports.WalletFilterer=_,exports.WalletIcon=N,exports.WalletRow=O,exports.i=({className:a,customDescription:r,connectOnly:s,preSelectedWalletId:v,hideHeader:x,...b})=>{let C=p.useAppConfig(),{t:j}=u.useI18n(),{connectors:W}=g.usePrivyInternal(),T=b.walletChainType||C.appearance.walletChainType,L=b.walletList||C.appearance?.walletList,{onBack:I,onClose:A,app:E}=b,{selected:q,setSelected:H,qrUrl:G,setQrUrl:V,connecting:Y,uiState:J,errorCode:K,wallets:X,walletCount:Z,handleConnect:ee,handleBack:ne,showSearchBar:te,isInitialConnectView:ie,title:le,search:ae,setSearch:oe}=function({onConnect:e,onBack:n,onClose:t,onConnectError:a,walletList:o,walletChainType:r,app:s}){let c=p.useAppConfig(),{connectors:d}=g.usePrivyInternal(),{t:h}=u.useI18n(),{wallets:y,walletCount:w,search:f,setSearch:v,selected:x,setSelected:b}=B({enabled:m.shouldFetchWcRegistryListings(o??[]),walletList:o,walletChainType:r}),[C,j]=i.useState(),[W,T]=i.useState(),[k,_]=i.useState(),[S,z]=i.useState(),L=!x&&!k&&!S,I=L&&(w>6||f.length>0),A=d.find((e=>"wallet_connect_v2"===e.connectorType)),N=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}),void window.open(n,"_blank");z({connector:n,name:t?.name??n.walletBranding.name??"Wallet",icon:t?.icon??n.walletBranding.icon});try{let t=await n.connect({showPrompt:!0});if(!t)return j("error"),T(void 0),void a?.(new g.PrivyConnectorError("Unable to connect wallet"));j("success"),T(void 0),m.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"),T(n?.privyErrorCode),a?.(n instanceof Error?n:new g.PrivyConnectorError(n?.message||"Unable to connect wallet"))}}}),[c.id,e,S,C]),E=i.useCallback((()=>k?(j(void 0),T(void 0),z(void 0),void _(void 0)):S?(j(void 0),T(void 0),void z(void 0)):x?(j(void 0),T(void 0),z(void 0),void b(void 0)):"error"===C||"loading"===C?(j(void 0),T(void 0),void z(void 0)):void n?.()),[k,S,x,C,n]),q=i.useMemo((()=>S?.connector===A&&k&&l.isMobile&&S?.name?h("connectWallet.goToWallet",{walletName:S.name}):S?.connector===A&&k&&S?.name?h("connectWallet.scanToConnect",{walletName:S.name}):k&&S?.name?l.isMobile?h("connectWallet.goToWallet",{walletName:S.name}):h("connectWallet.scanToConnect",{walletName:S.name}):"string"==typeof S?.connector?h("connectWallet.openOrInstall",{walletName:S.name}):x&&!S?h("connectWallet.selectNetwork"):S?null:h("connectWallet.selectYourWallet")),[S,k,x,A,h]);return{selected:x,setSelected:b,qrUrl:k,setQrUrl:_,connecting:S,uiState:C,errorCode:W,search:f,setSearch:v,wallets:y,walletCount:w,wc:A,isInitialConnectView:L,showSearchBar:I,title:q,handleConnect:N,handleBack:E,onClose:t,onConnect:e,app:s}}({...b,walletList:L,walletChainType:T}),re=W.find((e=>"wallet_connect_v2"===e.connectorType)),se=W.find((e=>"walletconnect_solana"===e.walletBranding.id)),ce=i.useRef(null),de=t.useVirtualizer({count:X.length,getScrollElement:()=>ce.current,estimateSize:()=>56,overscan:6,gap:5}),he=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=n=>{let t=_.normalize(e.id);return W.find((e=>_.normalize(e.walletClientType)===t&&e.chainType===n&&!("ethereum"===e.chainType&&e instanceof m.EthereumNullConnector||"solana"===e.chainType&&e instanceof m.SolanaNullConnector)))},a=async()=>{if(!re||!e.listing)return!1;let n=k[e.listing.slug]?{...e.listing,...k[e.listing.slug]}:e.listing;return re.setWalletEntry(n,V),await re.resetConnection(e.id),await ee(re,{name:e.label,icon:e.icon}),!0},o=async()=>!!se&&!!e.listing&&(await se.disconnect(),se.wallet.setWalletEntry(e.listing,V),await new Promise((e=>setTimeout(e,100))),await ee(se,{name:e.label,icon:e.icon}),!0),r=async n=>{let t=(n=>{let t=m.mobileWalletsConfig[e.id];if(t)return t.getMobileRedirect({isSolana:n,connectOnly:!!s,useUniversalLink:!1})})(n);return!!t&&(await ee(t,{name:e.label,icon:e.icon}),!0)};if(n&&t)H(e);else{if(n&&!t){let n=i("ethereum");if(n&&!M(n))return void await ee(n,{name:e.label,icon:e.icon});if(l.isMobile&&"phantom"===e.id){if(await r(!1)||await a())return}else if(await a()||await r(!1))return}if(t&&!n){let n=i("solana");if(n&&!M(n))return void await ee(n,{name:e.label,icon:e.icon});if(l.isMobile){if(await r(!0)||await o())return}else if(await o()||await r(!0))return}if(!M(e.connector)){if(re&&"wallet_connect_v2"===e.connector?.connectorType)if(await re.resetConnection(e.id),"wallet_connect_qr"!==e.id&&e.listing){let n=k[e.listing.slug]?{...e.listing,...k[e.listing.slug]}:e.listing;re.setWalletEntry(n,V)}else re.setWalletEntry({id:"wallet_connect_qr",name:"WalletConnect",rdns:"",slug:"wallet-connect",homepage:"",chains:["eip155"],mobile:{native:"",universal:void 0}},V);return se&&"walletconnect_solana"===e.connector?.walletBranding.id&&(await se.disconnect(),"wallet_connect_qr_solana"!==e.id&&e.listing?se.wallet.setWalletEntry(e.listing,V):se.wallet.setWalletEntry({id:"wallet_connect_solana_qr",name:"WalletConnect",rdns:"",slug:"wallet-connect-solana",homepage:"",chains:["solana"],mobile:{native:"",universal:void 0}},V),await new Promise((e=>setTimeout(e,100)))),void await ee(e.connector,{name:e.label,icon:e.icon})}e.url&&await ee(e.url,{name:e.label,icon:e.icon})}}),[re,se,ee,H,V,T,s,W]);return i.useEffect((()=>{if(!v)return;let e=X.find((({id:e})=>e===v));e&&he(e).catch(console.error)}),[v]),/*#__PURE__*/e.jsxs(f.Screen,{className:a,children:[/*#__PURE__*/e.jsx(f.Screen.Header,{icon:x&&ie?void 0:Y&&!G||G&&l.isMobile&&Y?.icon?Y.icon:Y?void 0:y.WalletCards,iconVariant:Y&&!G||G&&l.isMobile?"loading":void 0,iconLoadingStatus:Y&&!G||G&&l.isMobile?{success:"success"===J,fail:"error"===J}:void 0,title:x&&ie?void 0:Y&&!G?j("connectWallet.waitingForWallet",{walletName:Y.name}):G&&l.isMobile?j("connectWallet.waitingForWallet",{walletName:Y?.name??"connection"}):le,subtitle:x&&ie?void 0:Y&&!G&&"string"==typeof Y.connector?j("connectWallet.installAndConnect",{walletName:Y.name}):Y&&!G&&"string"!=typeof Y.connector?"error"===J?K===g.PrivyErrorCode.NO_SOLANA_ACCOUNTS?`The connected wallet has no Solana accounts. Please add a Solana account in ${Y.name} and try again.`:j("connectWallet.tryConnectingAgain"):j("connectionStatus.connectOneWallet"):ie?r??(E?j("connectWallet.connectToAccount",{appName:E.name}):null):null,showBack:!!I||!ie,showClose:!0,onBack:I||ne,onClose:A}),/*#__PURE__*/e.jsxs(f.Screen.Body,{ref:ce,$colorScheme:C.appearance.palette.colorScheme,style:{marginBottom:G?"0.5rem":void 0},children:[te&&/*#__PURE__*/e.jsx(F,{children:/*#__PURE__*/e.jsxs(h.EmailUpdateForm,{style:{background:"transparent"},children:[/*#__PURE__*/e.jsx(m.LoginMethodIconWrapper,{children:/*#__PURE__*/e.jsx(n.MagnifyingGlassIcon,{})}),/*#__PURE__*/e.jsx("input",{className:"login-method-button",type:"text",placeholder:j("connectWallet.searchPlaceholder",{count:String(Z)}),onChange:e=>oe(e.target.value),value:ae})]})}),G&&l.isMobile&&"loading"===J&&/*#__PURE__*/e.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"1rem"},children:[/*#__PURE__*/e.jsx(o.Button,{variant:"primary",onClick:()=>window.open(G.universal??G.native,"_blank"),style:{width:"100%"},children:j("connectWallet.openInApp")}),/*#__PURE__*/e.jsx(Q,{value:G.universal??G.native,iconOnly:!0,children:"Copy link"})]}),G&&!l.isMobile&&"loading"===J&&/*#__PURE__*/e.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"1rem"},children:/*#__PURE__*/e.jsx(Q,{value:G.universal??G.native,iconOnly:!0,children:j("connectWallet.copyLink")})}),G&&!l.isMobile&&/*#__PURE__*/e.jsx(d.QrCode,{size:280,url:G.universal??G.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:w.WalletConnect}),/*#__PURE__*/e.jsxs(U,{children:[Y&&!G&&"string"==typeof Y.connector&&/*#__PURE__*/e.jsxs(P,{onClick:()=>window.open(Y.connector,"_blank"),children:[Y.icon&&("string"==typeof Y.icon?/*#__PURE__*/e.jsx(N,{src:Y.icon}):/*#__PURE__*/e.jsx(Y.icon,{})),/*#__PURE__*/e.jsx($,{children:Y.name})]}),q?.chains.some((e=>e.startsWith("eip155")))&&!Y&&/*#__PURE__*/e.jsxs(P,{onClick:()=>he({...q,chains:q.chains.filter((e=>e.startsWith("eip155")))}),children:[q.icon&&("string"==typeof q.icon?/*#__PURE__*/e.jsx(N,{src:q.icon}):/*#__PURE__*/e.jsx(q.icon,{})),/*#__PURE__*/e.jsx($,{children:q.label}),/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsx(S,{})})]}),q?.chains.some((e=>e.startsWith("solana")))&&!Y&&/*#__PURE__*/e.jsxs(P,{onClick:()=>he({...q,chains:q.chains.filter((e=>e.startsWith("solana")))}),children:[q.icon&&("string"==typeof q.icon?/*#__PURE__*/e.jsx(N,{src:q.icon}):/*#__PURE__*/e.jsx(q.icon,{})),/*#__PURE__*/e.jsx($,{children:q.label}),/*#__PURE__*/e.jsx(R,{children:/*#__PURE__*/e.jsx(z,{})})]}),ie&&/*#__PURE__*/e.jsxs(e.Fragment,{children:[!(Z>0)&&/*#__PURE__*/e.jsx(D,{children:j("connectWallet.noWalletsFound")}),Z>0&&!G&&/*#__PURE__*/e.jsx("div",{style:{maxHeight:56*Math.min(X.length,5)+5,width:"100%"},children:/*#__PURE__*/e.jsx("div",{style:{height:`${de.getTotalSize()}px`,width:"100%",position:"relative"},children:de.getVirtualItems().map((n=>/*#__PURE__*/e.jsx(O,{index:n.index,style:{position:"absolute",top:0,left:0,height:`${n.size}px`,transform:`translateY(${n.start}px)`},data:{wallets:X,walletChainType:T,handleWalletClick:he}},n.key)))})})]})]})]}),/*#__PURE__*/e.jsxs(f.Screen.Footer,{children:[Y&&!G&&"string"!=typeof Y.connector&&"error"===J&&/*#__PURE__*/e.jsx(f.Screen.Actions,{children:/*#__PURE__*/e.jsx(o.Button,{style:{width:"100%",alignItems:"center"},variant:"error",onClick:()=>ee(Y.connector,{name:Y.name,icon:Y.icon}),children:j("connectWallet.retry")})}),!!(E&&E.legal.privacyPolicyUrl&&E.legal.termsAndConditionsUrl)&&/*#__PURE__*/e.jsx(c.TermsAndConditions,{app:E,alwaysShowImplicitConsent:!0}),/*#__PURE__*/e.jsx(f.Screen.Watermark,{})]})]})},exports.useWalletsListController=B;