@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 30.2 kB
JavaScript
import{useEffect as e,useState as t,createContext as n,useContext as i,useMemo as a,useCallback as o}from"react";import{create as l}from"zustand";import{u as r,n as s,o as c,p as d}from"./context-DRLoVlsO.mjs";import{styled as h,css as p}from"styled-components";import{jsx as u,jsxs as m}from"react/jsx-runtime";import*as w from"react-device-detect";import{c as f,u as y,f as g,d as b,S as v}from"./prepareFundingModalData-BVTcQcmw.mjs";import{u as x}from"./events-context-CI0iqAXA.mjs";import{isAddress as k}from"viem";import{getAddress as C,toHex as _}from"viem/utils";import{P as T,u as P}from"./internal-context-e-Eni5bG.mjs";import{a as W}from"./getPublicClient-A9RSftUZ.mjs";import{P as I}from"./get-is-unified-wallet-gMDXpX6C.mjs";import{u as z}from"./useWallets-kObl6ZLS.mjs";const S=l((()=>({listings:[],loading:!1}))),$=S.setState,N=e=>S.getState().listings.find((({slug:t})=>M(t)===M(e))),j=e=>{let t;try{t=new URL(e).hostname}catch(e){return}return S.getState().listings.find((({homepage:e})=>{let n;try{n=new URL(e).hostname}catch(e){return!1}return t.includes(n)}))},E=(t=!0)=>{let n=r(),i=S((e=>e.listings)),a=S((e=>e.loading)),o=!!i.length;return e((()=>{t&&!o&&($({listings:[],loading:!0}),(async e=>{let t=new URL("v3/wallets","https://explorer-api.walletconnect.com");t.searchParams.append("projectId",e);let n=await fetch(t);return n.ok?Object.values((await n.json()).listings).sort((({slug:e},{slug:t})=>"rainbow"===e&&"metamask"===t?1:"metamask"===e||"rainbow"===e?-1:1)):(console.debug(`Failed to fetch WalletConnect listings: ${await n.text().catch((()=>"No response."))}`),[])})(n.walletConnectCloudProjectId).then((e=>$({listings:e,loading:!1}))).catch((e=>{console.error(e),$({listings:[],loading:!1})})))}),[t,o,n.walletConnectCloudProjectId]),{listings:i,loading:a}},L=e=>{let{listings:t}=E();return t.find((({slug:t})=>M(t)===M(e)))};function M(e){return"cryptocom"===e?"cryptocom-defi":"binance"===e?"binance-defi":e.replace(/[-_]wallet$/,"")}function D(e){return["wallet_connect","backpack","binance","binanceus","bitget_wallet","bybit_wallet","cryptocom","haha_wallet","jupiter","metamask","okx_wallet","phantom","rabby_wallet","rainbow","ronin_wallet","safe","solflare","uniswap","zerion","kraken_wallet"].some((t=>e?.includes(t)))}const A=e=>e.isApexWallet?"Apex Wallet":e.isAvalanche?"Core Wallet":e.isBackpack?"Backpack":e.isBifrost?"Bifrost Wallet":e.isBitKeep?"BitKeep":e.isBitski?"Bitski":e.isBlockWallet?"BlockWallet":e.isBraveWallet?"Brave Wallet":e.isClover?"Clover":e.isCoin98?"Coin98 Wallet":e.isCoinbaseWallet?"Coinbase Wallet":e.isDawn?"Dawn Wallet":e.isDefiant?"Defiant":e.isDesig?"Desig Wallet":e.isEnkrypt?"Enkrypt":e.isExodus?"Exodus":e.isFordefi?"Fordefi":e.isFrame?"Frame":e.isFrontier?"Frontier Wallet":e.isGamestop?"GameStop Wallet":e.isHaqqWallet?"HAQQ Wallet":e.isHyperPay?"HyperPay Wallet":e.isImToken?"ImToken":e.isHaloWallet?"Halo Wallet":e.isKuCoinWallet?"KuCoin Wallet":e.isMathWallet?"MathWallet":e.isNovaWallet?"Nova Wallet":e.isOkxWallet||e.isOKExWallet?"OKX Wallet":e.isOneInchIOSWallet||e.isOneInchAndroidWallet?"1inch Wallet":e.isOneKey?"OneKey Wallet":e.isOpera?"Opera":e.isPhantom||"isPhantom"in e?"Phantom":e.isPortal?"Ripio Portal":e.isRabby?"Rabby Wallet":e.isRainbow?"Rainbow":e.isSafePal?"SafePal Wallet":e.isStatus?"Status":e.isSubWallet?"SubWallet":e.isTalisman?"Talisman":e.isTally||e.isTaho?"Taho":e.isTokenPocket?"TokenPocket":e.isTokenary?"Tokenary":e.isTrust||e.isTrustWallet?"Trust Wallet":e.isTTWallet?"TTWallet":e.isXDEFI?"XDEFI Wallet":e.isZeal?"Zeal":e.isZerion?"Zerion":e.isMetaMask?"MetaMask":void 0,O=(e,t)=>{if(!e.isMetaMask)return!1;if(e.isMetaMask&&!t)return!0;if(e.isBraveWallet&&!e._events&&!e._state||"MetaMask"!==A(e))return!1;if(e.providers)for(let t of e.providers)if(!O(t))return!1;return!0},B=()=>{let e=window;if(!e.ethereum)return!1;if(e.ethereum.isCoinbaseWallet)return!0;if(e.ethereum.providers)for(let t of e.ethereum.providers)if(t&&t.isCoinbaseWallet)return!0;return!1},F=(e,t)=>{let n=[],i=[];for(let[a,o]of e.entries())a<t?n.push(o):i.push(o);return[n,i]},U=e=>!!String(e).toLowerCase().match(/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/),R=(e,t)=>{let n=e.slice(0),i=[];for(;n.length;)i.push(n.splice(0,t));return i},q=(e,t=3,n=4,i="ethereum")=>{if(!e)return"";let a="ethereum"===i?2:0;return t+n+a+3>=e.length?e:`${e.slice(0,a+t)}...${e.slice(e.length-n,e.length)}`},H=(e,t=3,n=4)=>q(e,t,n,"solana"),K=e=>new Promise((t=>setTimeout(t,e)));function Z(e,{interval:t=100,timeout:n=5e3}={}){return new Promise(((i,a)=>{let o,l=0,r=()=>{l>=n?a("Max attempts reached without result"):(o=e(),l+=t,null==o?setTimeout(r,t):i(o))};r()}))}const X=(e,t={})=>{let n=t.delayMs||150,i=t.maxAttempts||270;return new Promise((async(a,o)=>{let l=!1,r=0;for(;!l&&r<i;){if(t.abortSignal?.aborted)return;e().then((e=>{l=!0,a(e)}),((...e)=>{l=!0,o(...e)})),r+=1,await K(n)}l||o(Error("Exceeded max attempts before resolving function"))}))},G=e=>e.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,""),J=e=>"string"==typeof e?e:"0x"+e.toString(16);async function Q({store:e,walletList:t,externalWalletConfig:n,walletChainType:i,timeout:a=3e3}){let o=!1,l=window;return new Promise((r=>{function s(){if(o)return;o=!0,window.removeEventListener("ethereum#initialized",s);let a=e.getProviders();console.debug("Detected injected providers:",a.map((e=>e.info)));let l=[];for(let e of a)t.includes("coinbase_wallet")&&"com.coinbase.wallet"===e.info.rdns||"solana-only"===i&&"app.phantom"===e.info.rdns||l.push({type:e.info.name.toLowerCase().replace(/\s/g,"_"),eip6963InjectedProvider:e});if("solana-only"!==i)for(let e of function(){let e=window,t=e.ethereum;if(!t)return[];let n=[];if(t.providers?.length)for(let e of t.providers)e&&n.push(e);return n.push(e.ethereum),n}()){let t=A(e);if(!a.some((e=>e.info.name===t))){if(O(e,!0)&&!l.find((e=>"metamask"===e.type))){l.push({type:"metamask",legacyInjectedProvider:e});continue}if("Phantom"===t&&!l.find((e=>"phantom"===e.type))){l.push({type:"phantom",legacyInjectedProvider:e});continue}if("Coinbase Wallet"===t&&!l.find((e=>"coinbase_wallet"===e.type&&"smartWalletOnly"!==n.coinbaseWallet?.config?.preference?.options))){l.push({type:"coinbase_wallet",legacyInjectedProvider:e});continue}l.find((e=>"unknown_browser_extension"===e.type))||l.push({type:"unknown_browser_extension",legacyInjectedProvider:e})}}r(l)}l.ethereum?s():(window.addEventListener("ethereum#initialized",s,{once:!0}),setTimeout((()=>{s()}),a))}))}function V(e){return`eip155:${String(Number(e))}`}const Y=(e,t,n,i)=>{let a=Number(e),o=t.find((e=>e.id===a));if(!o)throw new T(`Unsupported chainId ${e}`,4901);return W(o,n,i)},ee=(e,t)=>{let n=Number(e),i=t.find((e=>e.id===n));if(!i)throw new T(`Unsupported chainId ${e}`,4901);return i.blockExplorers?.default.url},te=e=>{let t={name:"string",version:"string",chainId:"uint256",verifyingContract:"address",salt:"bytes32"},n=e.types.EIP712Domain??Object.entries(e.domain).map((([e,n])=>{if(null!=n&&"string"==typeof e&&e in t)return{name:e,type:t[e]}})).filter((e=>void 0!==e));return{...e,types:{...e.types,EIP712Domain:n}}};function ne(e,{min:t,max:n}){return Math.min(Math.max(e,t),n)}const ie=e=>e?.map((e=>({signer_id:e.signerId,override_policy_ids:e.policyIds})));function ae(e){return"ethereum"===e.type}function oe(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let i=e[n],a=t[n];if(i?.address!==a?.address||i&&a&&ae(i)&&ae(a)&&i?.chainId!==a?.chainId||i?.connectorType!==a?.connectorType||i?.connectedAt!==a?.connectedAt||i?.walletClientType!==a?.walletClientType||i?.isConnected!==a?.isConnected||i?.linked!==a?.linked)return!1}return!0}const le=(e,t)=>e.rpcTimeouts&&e.rpcTimeouts[t]||s;function re(e){return"ethereum"===e.chainType}class se extends f{buildConnectedWallet(e,t,n,i){let a=async()=>!!this.wallets.find((t=>C(t.address)===C(e)));return{type:"ethereum",address:C(e),chainId:t,meta:n,imported:i,switchChain:async n=>{let i,o;if(!a)throw new T("Wallet is not currently connected.");let l=this.wallets.find((t=>C(t.address)===C(e)))?.chainId;if(!l)throw new T("Unable to determine current chainId.");if("number"==typeof n?(i=`0x${n.toString(16)}`,o=n):(i=n,o=Number(n)),l===V(i))return;let r=this.chains.find((e=>e.id===o));if(!r)throw new T(`Unsupported chainId: ${n}`);let s=async()=>{await this.proxyProvider.request({method:"wallet_switchEthereumChain",params:[{chainId:i}]})};try{return await s()}catch(e){if(((e,t)=>{switch(t){case"coinbase_wallet":case"base_account":return e.message.includes("addEthereumChain");case"rabby_wallet":return e.message.includes("Unrecognized chain ID");default:return 4902===e.code||e.message?.includes("4902")}})(e,this.walletClientType))return"rabby_wallet"===this.walletClientType&&await K(300),await this.proxyProvider.request({method:"wallet_addEthereumChain",params:[{chainId:i,chainName:r.name,nativeCurrency:r.nativeCurrency,rpcUrls:[r.rpcUrls.default?.http[0]??""],blockExplorerUrls:[r.blockExplorers?.default.url??""]}]}),s();if("rainbow"===this.walletClientType&&e.message?.includes("wallet_switchEthereumChain"))throw new T(`Rainbow does not support the chainId ${t}`);throw e}},connectedAt:Date.now(),walletClientType:this.walletClientType,connectorType:this.connectorType,isConnected:a,getEthereumProvider:async()=>{if(!await a())throw new T("Wallet is not currently connected.");return this.proxyProvider},sign:async e=>{if(!await a())throw new T("Wallet is not currently connected.");return await this.sign(e)},disconnect:()=>{this.disconnect()}}}async syncAccounts(e){let t,n=e;try{if(void 0===n){let e=await X((()=>this.proxyProvider.request({method:"eth_accounts"})),{maxAttempts:10,delayMs:500});console.debug(`eth_accounts for ${this.walletClientType}:`,e),Array.isArray(e)&&(n=e)}}catch(e){console.debug("Wallet did not respond to eth_accounts. Defaulting to prefetched accounts.",e)}if(!n||!Array.isArray(n)||n.length<=0||!n[0])return;let i=n[0];if(!k(i))return void console.warn(`Invalid ethereum address reported by ${this.walletClientType}: ${i}`);let a=C(i),o=[];if("privy"===this.walletClientType){let e=y.get(c(a));this.chains.find((t=>t.id===Number(e)))||(y.del(c(a)),e=null),t=e||`0x${this.defaultChain.id.toString(16)}`;try{await this.proxyProvider.request({method:"wallet_switchEthereumChain",params:[{chainId:t}]})}catch(e){console.warn(`Unable to switch embedded wallet to chain ID ${t} on initialization`)}}else try{let e=await X((()=>this.proxyProvider.request({method:"eth_chainId"})),{maxAttempts:10,delayMs:500});if(console.debug(`eth_chainId for ${this.walletClientType}:`,e),"string"==typeof e)t=e;else{if("number"!=typeof e)throw Error("Invalid chainId returned from provider");t=`0x${e.toString(16)}`}}catch(e){console.warn(`Failed to get chainId from provider, defaulting to ${d}`,e),t=d}let l=V(t);if(!o.find((e=>C(e.address)===a))){let e={name:this.walletBranding.name,icon:"string"==typeof this.walletBranding.icon?this.walletBranding.icon:void 0,id:this.walletBranding.id};o.push(this.buildConnectedWallet(C(i),l,e,"embedded_imported"===this.connectorType))}oe(o,this.wallets)||(this.wallets=o,this.emit("walletsUpdated"))}async getConnectedWallet(){let e=await this.proxyProvider.request({method:"eth_accounts"});return this.wallets.sort(((e,t)=>t.connectedAt-e.connectedAt)).find((t=>e.find((e=>C(e)===C(t.address)))))||null}async isConnected(){let e=await this.proxyProvider.request({method:"eth_accounts"});return Array.isArray(e)&&e.length>0}async sign(e){return await this.connect({showPrompt:!1}),this.proxyProvider.request({method:"personal_sign",params:[_(e),this.wallets[0]?.address]})}subscribeListeners(){this.proxyProvider.on("accountsChanged",this.onAccountsChanged),this.proxyProvider.on("chainChanged",this.onChainChanged),this.proxyProvider.on("disconnect",this.onDisconnect),this.proxyProvider.on("connect",this.onConnect)}unsubscribeListeners(){this.proxyProvider.removeListener("accountsChanged",this.onAccountsChanged),this.proxyProvider.removeListener("chainChanged",this.onChainChanged),this.proxyProvider.removeListener("disconnect",this.onDisconnect),this.proxyProvider.removeListener("connect",this.onConnect)}constructor(e,t,n,i){super(e),this.chainType="ethereum",this.onAccountsChanged=e=>{0===e.length?this.onDisconnect():this.syncAccounts(e)},this.onChainChanged=e=>{this.wallets.forEach((t=>{t.chainId=V(e),"privy"===this.walletClientType&&y.put(c(t.address),e)})),this.emit("walletsUpdated")},this.onDisconnect=()=>{this.connected=!1,this.wallets=[],this.emit("walletsUpdated")},this.onConnect=async()=>{"base_account"===this.connectorType&&this.connected||(this.connected=!0,"coinbase_wallet"===this.connectorType&&await K(500),this.syncAccounts())},this.wallets=[],this.walletClientType=e,this.chains=t,this.defaultChain=n,this.rpcConfig=i,this.rpcTimeoutDuration=le(i,e),this.connected=!1,this.initialized=!1}}class ce{on(e,t){if(this.walletProvider)return this.walletProvider.on(e,t);this._subscriptions.push({eventName:e,listener:t})}async request(e){if(!this.walletProvider)throw new T(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),this.walletTimeout()]).catch((e=>{throw g(e)}))}constructor(e,t){this.removeListener=(e,t)=>{if(this.walletProvider)try{return this.walletProvider.removeListener(e,t)}catch(e){console.warn("Unable to remove wallet provider listener")}},this.walletTimeout=(e=new b,t=this.rpcTimeoutDuration)=>new Promise(((n,i)=>setTimeout((()=>{i(e)}),t))),this.setWalletProvider=e=>{this.walletProvider&&this._subscriptions.forEach((e=>{this.removeListener(e.eventName,e.listener)})),this.walletProvider=e,this._subscriptions.forEach((e=>{this.walletProvider?.on(e.eventName,e.listener)}))},this.walletProvider=e,this.rpcTimeoutDuration=t||s,this._subscriptions=[]}}const de=n=>{let[i,a]=t("auto");return e((()=>{let e=new ResizeObserver((e=>{a(e[0]?.contentRect.height??"auto")}));return n.current&&e.observe(n.current),()=>{n.current&&e.unobserve(n.current)}}),[n.current]),i},he=/*#__PURE__*/h.div.withConfig({displayName:"Grow",componentId:"sc-681ff332-0"})(["text-align:left;flex-grow:1;"]),pe=/*#__PURE__*/h.div.withConfig({displayName:"AlignBottom",componentId:"sc-681ff332-1"})(["display:flex;flex-direction:column;justify-content:flex-end;flex-grow:1;"]),ue=/*#__PURE__*/h.div.withConfig({displayName:"LoginMethodContainer",componentId:"sc-681ff332-2"})(["display:flex;flex-direction:column;gap:8px;-ms-overflow-style:none;scrollbar-width:none;&::-webkit-scrollbar{display:none;}"]),me=/*#__PURE__*/h(ue).withConfig({displayName:"LoginMethodContainerWithScrollShadows",componentId:"sc-681ff332-3"})([""," background-repeat:no-repeat;background-size:100% 32px,100% 16px;background-attachment:local,scroll;max-height:400px;overflow-y:auto;scrollbar-width:none;padding:3px;"],(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));let we=/*#__PURE__*/p(["&&{width:100%;font-size:16px;line-height:24px;min-height:56px;@media (min-width:440px){font-size:14px;}display:flex;gap:12px;align-items:center;color:var(--privy-color-foreground);padding:10px 12px;border:1px solid var(--privy-color-foreground-4) !important;border-radius:var(--privy-border-radius-md);transition:background-color 200ms ease;cursor:pointer;&:hover{background-color:var(--privy-color-background-2);}&:disabled{cursor:pointer;background-color:var(--privy-color-background-2);}}"]);const fe=/*#__PURE__*/h.div.withConfig({displayName:"Subtitle",componentId:"sc-681ff332-4"})(["text-align:center;font-size:14px;margin-bottom:24px;"]),ye=/*#__PURE__*/h.button.attrs({className:"login-method-button"}).withConfig({displayName:"LoginMethodButton",componentId:"sc-681ff332-5"})(["",""],we),ge=/*#__PURE__*/h.div.withConfig({displayName:"LoginMethodIconWrapper",componentId:"sc-681ff332-7"})(["width:32px;height:32px;border-radius:",";background:",";display:flex;align-items:center;justify-content:center;flex-shrink:0;svg{width:",";height:",";color:",";}"],(e=>e.$fullSize?"0":"4px"),(e=>e.$fullSize?"transparent":"var(--privy-color-background-2)"),(e=>e.$fullSize?"32px":"18px"),(e=>e.$fullSize?"32px":"18px"),(e=>e.$fullSize?"inherit":"var(--privy-color-icon-muted)")),be=/*#__PURE__*/h.div.withConfig({displayName:"Hide",componentId:"sc-681ff332-8"})(["width:100%;height:100%;min-height:inherit;display:flex;flex-direction:column;",""],(e=>e.$if?"display: none;":"")),ve=/*#__PURE__*/h.div.withConfig({displayName:"EmptyWalletState",componentId:"sc-681ff332-9"})(["width:100%;height:100%;padding:",";"],(e=>e.$withPadding?"64px 0px":"0px")),xe=/*#__PURE__*/h.div.withConfig({displayName:"Header",componentId:"sc-681ff332-10"})(["display:flex;flex-direction:column;align-items:center;justify-content:center;margin-bottom:32px;gap:12px;& h3{font-size:18px;font-style:normal;font-weight:600;line-height:24px;}& p{max-width:300px;font-size:14px;font-style:normal;font-weight:400;line-height:20px;}"]),ke=({success:e,fail:t})=>/*#__PURE__*/m(_e,{children:[/*#__PURE__*/u(Ce,{children:/*#__PURE__*/u(Pe,{className:e?"success":t?"fail":""})}),/*#__PURE__*/u(Ce,{children:/*#__PURE__*/u(Te,{className:e?"success":t?"fail":""})})]});let Ce=/*#__PURE__*/h.span.withConfig({displayName:"PositionedAbsoluteLoader",componentId:"sc-aba6339d-0"})(["&&{position:absolute;top:0;left:0;z-index:2;}"]),_e=/*#__PURE__*/h.span.withConfig({displayName:"ConnectionLoaderContainer",componentId:"sc-aba6339d-1"})(["position:relative;width:82px;height:82px;display:inline-block;"]);const Te=/*#__PURE__*/h.span.withConfig({displayName:"Loader",componentId:"sc-aba6339d-2"})(["&&{width:82px;height:82px;border-width:4px;border-style:solid;border-color:",";border-bottom-color:transparent;border-radius:50%;display:inline-block;box-sizing:border-box;animation:rotation 1.2s linear infinite;transition:border-color 800ms;}@keyframes rotation{0%{transform:rotate(0deg);}100%{transform:rotate(360deg);}}&&&.success{border-color:var(--privy-color-icon-success);border-bottom-color:var(--privy-color-icon-success);}&&&.fail{border-color:var(--privy-color-icon-error);border-bottom-color:var(--privy-color-icon-error);}"],(e=>e.color??"var(--privy-color-icon-subtle)")),Pe=/*#__PURE__*/h(Te).withConfig({displayName:"LoaderFaint",componentId:"sc-aba6339d-3"})(["&&{border-bottom-color:",";border-color:",";animation:none;opacity:0.5;}"],(e=>e.color??"var(--privy-color-border-default)"),(e=>e.color??"var(--privy-color-border-default)")),We=e=>/*#__PURE__*/u(Ie,{color:e.color||"var(--privy-color-foreground-3)"});let Ie=/*#__PURE__*/h(Te).withConfig({displayName:"StyledButtonLoader",componentId:"sc-aba6339d-4"})(["&&{height:1rem;width:1rem;margin:2px 0;border-width:1.5px;transition:border-color 200ms ease;}"]);const ze=["metamask","phantom","brave_wallet","rainbow","uniswap_wallet_extension","uniswap_extension","rabby_wallet","bybit_wallet","ronin_wallet","haha_wallet","crypto.com_wallet_extension","crypto.com_onchain","binance","bitget_wallet","coinbase_wallet","coinbase_smart_wallet","base_account","metamask","trust","safe","rainbow","uniswap","zerion","argent","spot","omni","cryptocom","blockchain","safepal","bitget_wallet","zengo","1inch","binance","exodus","mew_wallet","alphawallet","keyring_pro","mathwallet","unstoppable","obvious","ambire","internet_money_wallet","coin98","abc_wallet","arculus_wallet","haha","cling_wallet","broearn","copiosa","burrito_wallet","enjin_wallet","plasma_wallet","avacus","bee","pitaka","pltwallet","minerva","kryptogo","prema","slingshot","kriptonio","timeless","secux","bitizen","blocto","okx_wallet","safemoon","rabby_wallet","bybit_wallet","ronin_wallet","haha_wallet","privy","unknown","phantom","solflare","glow","backpack","jupiter","mobile_wallet_adapter"],Se=Object.freeze({phantom:{client:"phantom",name:"Phantom",installLink:w.isFirefox?"https://addons.mozilla.org/en-US/firefox/addon/phantom-app/":"https://chrome.google.com/webstore/detail/phantom/bfnaelmomeimhlpmgjnjophhpkkoljpa?hl=en",chainTypes:["ethereum","solana"],get isInstalled(){if("phantom"in window){let e=window;if(e?.phantom?.ethereum?.isPhantom&&e?.phantom?.ethereum?.chainId||e?.phantom?.solana?.isPhantom)return!0}return!1},getMobileRedirect({useUniversalLink:e,isSolana:t,connectOnly:n}){let i=Ne({client:this.client,isSolana:t,connectOnly:n});return`${e?"phantom://":"https://phantom.app/ul/"}browse/${i}?ref=${i}`}},solflare:{client:"solflare",name:"Solflare",installLink:w.isFirefox?"https://addons.mozilla.org/es/firefox/addon/solflare-wallet/":"https://chromewebstore.google.com/detail/solflare-wallet/bhhhlbepdkbapadjdnnojkbgioiodbic",chainTypes:["solana"],get isInstalled(){return"solflare"in window&&!!window?.solflare?.isSolflare},getMobileRedirect({useUniversalLink:e,isSolana:t,connectOnly:n}){let i=Ne({client:this.client,isSolana:t,connectOnly:n});return`${e?"solflare://ul/v1/":"https://solflare.com/ul/v1/"}browse/${i}?ref=${i}`}},jupiter:{client:"jupiter",name:"Jupiter Wallet",installLink:"https://chromewebstore.google.com/detail/jupiter-wallet/iledlaeogohbilgbfhmbgkgmpplbfboh",chainTypes:["solana"],get isInstalled(){return"jupiter"in window&&!!window?.jupiter?.isJupiter},getMobileRedirect({isSolana:e,connectOnly:t}){let n=Ne({client:this.client,isSolana:e,connectOnly:t});return`jupjupjup://jup.ag/browse/${n}?ref=${n}`}},backpack:{client:"backpack",name:"Backpack",installLink:"https://chromewebstore.google.com/detail/backpack/aflkmfhebedbjioipglgcbcmnbpgliof",chainTypes:["ethereum","solana"],get isInstalled(){return!(!("backpack"in window)||!window?.backpack?.ethereum?.isBackpack&&!window?.backpack?.solana?.isBackpack)},getMobileRedirect({useUniversalLink:e,isSolana:t,connectOnly:n}){let i=Ne({client:this.client,isSolana:t,connectOnly:n});return`${e?"backpack://ul/v1/":"https://backpack.app/ul/v1/"}browse/${i}?ref=${i}`}},okx_wallet:{client:"okx_wallet",name:"OKX Wallet",installLink:"https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge",chainTypes:["ethereum","solana"],get isInstalled(){return"okxwallet"in window&&!!window?.okxwallet?.isOkxWallet},getMobileRedirect({isSolana:e,connectOnly:t}){return`okx://wallet/dapp/url?dappUrl=${Ne({client:this.client,isSolana:e,connectOnly:t})}`}}});function $e({connectorType:e,walletClientType:t}){for(let n of ze)if(e===n||t===n)return Se[n]}function Ne({client:e,isSolana:t,connectOnly:n}){let i=new URL(window.location.href);return i.searchParams.set("privy_connector",t?"solana_adapter":"injected"),i.searchParams.set("privy_wallet_client",e),i.searchParams.set("privy_connect_only",String(n)),encodeURIComponent(i.href.replace(/\/$/g,""))}class je extends v{get walletBranding(){return{id:this.id,name:this.name,icon:this.icon}}async initialize(){this.initialized=!0,this.emit("initialized")}async connect(){throw Error("connect called for an uninstalled wallet via the SolanaNullConnector")}constructor({id:e,name:t,icon:n}){super({name:t},!1),this.connectorType="null",this.proxyProvider=new ce(void 0,s),this.disconnect=async()=>{throw Error("disconnect called for an uninstalled wallet via the SolanaNullConnector")},this.promptConnection=async()=>{throw Error("promptConnection called for an uninstalled wallet via the SolanaNullConnector")},this.id=e,this.name=t,this.icon=n}}function Ee(e){return"solana"===e.chainType}function Le(e){return"solana"===e.type}let Me=/*#__PURE__*/n({});const De=({children:n})=>{let i=r(),[a,o]=t({});return x("login",{onComplete:({loginAccount:e})=>{e&&"passkey"!==e.type&&"cross_app"!==e.type&&("wallet"!==e.type||"privy"!==e.walletClientType)&&(y.put(Ae(i.id),e.type),"wallet"===e.type?(y.put(Oe(i.id),e.walletClientType),y.put(Be(i.id),e.chainType),o({accountType:e.type,walletClientType:e.walletClientType,chainType:e.chainType})):(y.del(Oe(i.id)),y.del(Be(i.id)),o({accountType:e.type})))}}),e((()=>{if(!i.id)return;let e=y.get(Ae(i.id)),t=y.get(Oe(i.id)),n=y.get(Be(i.id));e&&o("wallet"===e?{accountType:e,walletClientType:t,chainType:n}:{accountType:e})}),[i.id]),/*#__PURE__*/u(Me.Provider,{value:a,children:n})};let Ae=e=>`privy:${e}:recent-login-method`,Oe=e=>`privy:${e}:recent-login-wallet-client`,Be=e=>`privy:${e}:recent-login-chain-type`;const Fe=()=>i(Me);class Ue extends se{get walletBranding(){return{id:this.id,name:this.name,icon:this.icon}}async initialize(){this.initialized=!0,this.emit("initialized")}async connect(){throw Error("connect called for an uninstalled wallet via the EthereumNullConnector")}disconnect(){throw Error("disconnect called for an uninstalled wallet via the EthereumNullConnector")}promptConnection(e){throw Error(`promptConnection called for an uninstalled wallet via the EthereumNullConnector for ${e}`)}constructor({id:e,name:t,icon:n,walletClientType:i,defaultChain:a}){super(i,[],a,{}),this.connectorType="null",this.proxyProvider=new ce(void 0,s),this.id=e,this.name=t,this.icon=n}}const Re=({...e})=>/*#__PURE__*/m("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",...e,children:[/*#__PURE__*/u("rect",{width:"32",height:"32",rx:"6",fill:"#121314"}),/*#__PURE__*/u("g",{transform:"translate(4, 4)",children:/*#__PURE__*/m("svg",{width:"24",height:"24",viewBox:"0 0 318.6 318.6",children:[/*#__PURE__*/u("style",{children:".s1{stroke-linecap:round;stroke-linejoin:round}.s2{fill:#e4761b;stroke:#e4761b}.s3{fill:#f6851b;stroke:#f6851b}"}),/*#__PURE__*/u("path",{fill:"#e2761b",stroke:"#e2761b",className:"s1",d:"m274.1 35.5-99.5 73.9L193 65.8z"}),/*#__PURE__*/u("path",{d:"m44.4 35.5 98.7 74.6-17.5-44.3zm193.9 171.3-26.5 40.6 56.7 15.6 16.3-55.3zm-204.4.9L50.1 263l56.7-15.6-26.5-40.6z",className:"s1 s2"}),/*#__PURE__*/u("path",{d:"m103.6 138.2-15.8 23.9 56.3 2.5-2-60.5zm111.3 0-39-34.8-1.3 61.2 56.2-2.5zM106.8 247.4l33.8-16.5-29.2-22.8zm71.1-16.5 33.9 16.5-4.7-39.3z",className:"s1 s2"}),/*#__PURE__*/u("path",{fill:"#d7c1b3",stroke:"#d7c1b3",className:"s1",d:"m211.8 247.4-33.9-16.5 2.7 22.1-.3 9.3zm-105 0 31.5 14.9-.2-9.3 2.5-22.1z"}),/*#__PURE__*/u("path",{fill:"#233447",stroke:"#233447",className:"s1",d:"m138.8 193.5-28.2-8.3 19.9-9.1zm40.9 0 8.3-17.4 20 9.1z"}),/*#__PURE__*/u("path",{fill:"#cd6116",stroke:"#cd6116",className:"s1",d:"m106.8 247.4 4.8-40.6-31.3.9zM207 206.8l4.8 40.6 26.5-39.7zm23.8-44.7-56.2 2.5 5.2 28.9 8.3-17.4 20 9.1zm-120.2 23.1 20-9.1 8.2 17.4 5.3-28.9-56.3-2.5z"}),/*#__PURE__*/u("path",{fill:"#e4751f",stroke:"#e4751f",className:"s1",d:"m87.8 162.1 23.6 46-.8-22.9zm120.3 23.1-1 22.9 23.7-46zm-64-20.6-5.3 28.9 6.6 34.1 1.5-44.9zm30.5 0-2.7 18 1.2 45 6.7-34.1z"}),/*#__PURE__*/u("path",{d:"m179.8 193.5-6.7 34.1 4.8 3.3 29.2-22.8 1-22.9zm-69.2-8.3.8 22.9 29.2 22.8 4.8-3.3-6.6-34.1z",className:"s3"}),/*#__PURE__*/u("path",{fill:"#c0ad9e",stroke:"#c0ad9e",className:"s1",d:"m180.3 262.3.3-9.3-2.5-2.2h-37.7l-2.3 2.2.2 9.3-31.5-14.9 11 9 22.3 15.5h38.3l22.4-15.5 11-9z"}),/*#__PURE__*/u("path",{fill:"#161616",stroke:"#161616",className:"s1",d:"m177.9 230.9-4.8-3.3h-27.7l-4.8 3.3-2.5 22.1 2.3-2.2h37.7l2.5 2.2z"}),/*#__PURE__*/u("path",{fill:"#763d16",stroke:"#763d16",className:"s1",d:"m278.3 114.2 8.5-40.8-12.7-37.9-96.2 71.4 37 31.3 52.3 15.3 11.6-13.5-5-3.6 8-7.3-6.2-4.8 8-6.1zM31.8 73.4l8.5 40.8-5.4 4 8 6.1-6.1 4.8 8 7.3-5 3.6 11.5 13.5 52.3-15.3 37-31.3-96.2-71.4z"}),/*#__PURE__*/u("path",{d:"m267.2 153.5-52.3-15.3 15.9 23.9-23.7 46 31.2-.4h46.5zm-163.6-15.3-52.3 15.3-17.4 54.2h46.4l31.1.4-23.6-46zm71 26.4 3.3-57.7 15.2-41.1h-67.5l15 41.1 3.5 57.7 1.2 18.2.1 44.8h27.7l.2-44.8z",className:"s3"})]})})]});function qe(e){let{login:t}=i(I);return x("login",e),{login:t}}function He(e){let{logout:t}=i(I);return x("logout",e),{logout:t}}function Ke(e){let{connectWallet:t}=i(I);return x("connectWallet",e),{connectWallet:t}}const Ze=e=>{x("fundWallet",e);let{fundWallet:t}=P();return{fundWallet:({address:e,options:n})=>t(e,n)}},Xe=l((()=>({isModalOpen:!1,resolvers:null})));let Ge=l((()=>({})));const Je=(e,t)=>Ge((n=>n[e]?.[t])),Qe=(e,t,n)=>{Ge.setState((i=>({[e]:{...i[e],[t]:n}})))},Ve=async()=>{let e,t,n=new Promise(((n,i)=>{e=n,t=i}));return Ge.setState({}),Xe.setState({isModalOpen:!0,resolvers:{resolve:e,reject:t}}),await n},Ye=()=>{let e=Xe.getState().resolvers;e||console.warn("useActiveWalletStore: Called close while modal was not open"),Xe.setState({isModalOpen:!1}),e?.resolve({wallet:Xe.getState().wallet})},et=({address:e,client:t,appId:n})=>{let i=`${t}:${e}`;n&&y.put(nt(n),i),Xe.setState({wallet:i})},tt=()=>Xe((e=>e.isModalOpen)),nt=e=>`privy:${e}:active-wallet-connection`,it=()=>{let t=r(),{wallets:n}=z(),{connectors:i}=P(),l=a((()=>i.filter(Ee).flatMap((e=>e.wallets))),[i]),s=Xe((e=>e.wallet));e((()=>{if(!t.id)return;let e=y.get(nt(t.id));Xe.setState({wallet:e})}),[t.id]);let c=a((()=>{if(!s)return;let[,e]=s.split(":");return n.find((t=>t.address===e))||l.find((t=>t.address===e))}),[s,n,l]),d=a((()=>c?"ethereum"===c.type?c.chainId:"solana":void 0),[c]);return{connect:async e=>{e?.reset&&(y.del(nt(t.id)),Xe.setState({wallet:void 0}));let{wallet:i}=await Ve();if(!i)return{};let[,a]=i.split(":"),o=n.find((e=>e.address===a));if(o)return{wallet:o,network:o.chainId};let r=l.find((e=>e.address===a));return r?{wallet:r,network:"solana"}:{}},setActiveWallet:o((e=>{et({address:e.address,client:e.walletClientType,appId:t.id})}),[t.id]),wallet:c,network:d}};export{fe as $,Ke as A,Ze as B,it as C,q as D,se as E,Fe as F,We as G,be as H,Je as I,Qe as J,et as K,Te as L,Re as M,tt as N,Ye as O,ce as P,L as Q,De as R,je as S,B as T,ye as U,ge as V,ve as W,xe as X,he as Y,me as Z,F as _,Y as a,pe as a0,U as a1,ne as a2,R as a3,ke as a4,ee as a5,H as a6,Pe as a7,ue as a8,N as b,le as c,E as d,D as e,ae as f,j as g,V as h,X as i,oe as j,K as k,Le as l,te as m,$e as n,Q as o,Z as p,Se as q,re as r,G as s,J as t,de as u,Ee as v,Ue as w,ie as x,qe as y,He as z};