UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

2 lines (1 loc) • 32.6 kB
"use strict";var e=require("react"),t=require("zustand"),n=require("./context-DFq1obBO.js"),i=require("styled-components"),o=require("react/jsx-runtime"),r=require("react-device-detect"),a=require("./prepareFundingModalData-Cnd6rhhJ.js"),l=require("./events-context-Di6--rDg.js"),s=require("viem"),c=require("viem/utils"),d=require("./internal-context-NWsAL807.js"),p=require("./getPublicClient-CGlodIp_.js"),u=require("./get-is-unified-wallet-D4ouXJpi.js"),h=require("./useWallets-BLFNjTwC.js");function m(e){if(e&&"object"==typeof e&&"default"in e)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var i=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,i.get?i:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var w=/*#__PURE__*/m(r);const f=t.create((()=>({listings:[],loading:!1}))),y=f.setState,g=(t=!0)=>{let i=n.useAppConfig(),o=f((e=>e.listings)),r=f((e=>e.loading)),a=!!o.length;return e.useEffect((()=>{t&&!a&&(y({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."))}`),[])})(i.walletConnectCloudProjectId).then((e=>y({listings:e,loading:!1}))).catch((e=>{console.error(e),y({listings:[],loading:!1})})))}),[t,a,i.walletConnectCloudProjectId]),{listings:o,loading:r}};function b(e){return"cryptocom"===e?"cryptocom-defi":"binance"===e?"binance-defi":e.replace(/[-_]wallet$/,"")}const x=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,v=(e,t)=>{if(!e.isMetaMask)return!1;if(e.isMetaMask&&!t)return!0;if(e.isBraveWallet&&!e._events&&!e._state||"MetaMask"!==x(e))return!1;if(e.providers)for(let t of e.providers)if(!v(t))return!1;return!0},C=(e,t=3,n=4,i="ethereum")=>{if(!e)return"";let o="ethereum"===i?2:0;return t+n+o+3>=e.length?e:`${e.slice(0,o+t)}...${e.slice(e.length-n,e.length)}`},k=e=>new Promise((t=>setTimeout(t,e)));const W=(e,t={})=>{let n=t.delayMs||150,i=t.maxAttempts||270;return new Promise((async(o,r)=>{let a=!1,l=0;for(;!a&&l<i;){if(t.abortSignal?.aborted)return;e().then((e=>{a=!0,o(e)}),((...e)=>{a=!0,r(...e)})),l+=1,await k(n)}a||r(Error("Exceeded max attempts before resolving function"))}))};function P(e){return`eip155:${String(Number(e))}`}function T(e){return"ethereum"===e.type}function _(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let i=e[n],o=t[n];if(i?.address!==o?.address||i&&o&&T(i)&&T(o)&&i?.chainId!==o?.chainId||i?.connectorType!==o?.connectorType||i?.connectedAt!==o?.connectedAt||i?.walletClientType!==o?.walletClientType||i?.isConnected!==o?.isConnected||i?.linked!==o?.linked)return!1}return!0}const E=(e,t)=>e.rpcTimeouts&&e.rpcTimeouts[t]||n.DEFAULT_RPC_TIMEOUT;class I extends a.WalletConnector{buildConnectedWallet(e,t,n,i){let o=async()=>!!this.wallets.find((t=>c.getAddress(t.address)===c.getAddress(e)));return{type:"ethereum",address:c.getAddress(e),chainId:t,meta:n,imported:i,switchChain:async n=>{let i,r;if(!o)throw new d.PrivyConnectorError("Wallet is not currently connected.");let a=this.wallets.find((t=>c.getAddress(t.address)===c.getAddress(e)))?.chainId;if(!a)throw new d.PrivyConnectorError("Unable to determine current chainId.");if("number"==typeof n?(i=`0x${n.toString(16)}`,r=n):(i=n,r=Number(n)),a===P(i))return;let l=this.chains.find((e=>e.id===r));if(!l)throw new d.PrivyConnectorError(`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:l.name,nativeCurrency:l.nativeCurrency,rpcUrls:[l.rpcUrls.default?.http[0]??""],blockExplorerUrls:[l.blockExplorers?.default.url??""]}]}),s();if("rainbow"===this.walletClientType&&e.message?.includes("wallet_switchEthereumChain"))throw new d.PrivyConnectorError(`Rainbow does not support the chainId ${t}`);throw e}},connectedAt:Date.now(),walletClientType:this.walletClientType,connectorType:this.connectorType,isConnected:o,getEthereumProvider:async()=>{if(!await o())throw new d.PrivyConnectorError("Wallet is not currently connected.");return this.proxyProvider},sign:async e=>{if(!await o())throw new d.PrivyConnectorError("Wallet is not currently connected.");return await this.sign(e)},disconnect:()=>{this.disconnect()}}}async syncAccounts(e){let t,i=e;try{if(void 0===i){let e=await W((()=>this.proxyProvider.request({method:"eth_accounts"})),{maxAttempts:10,delayMs:500});console.debug(`eth_accounts for ${this.walletClientType}:`,e),Array.isArray(e)&&(i=e)}}catch(e){console.debug("Wallet did not respond to eth_accounts. Defaulting to prefetched accounts.",e)}if(!i||!Array.isArray(i)||i.length<=0||!i[0])return;let o=i[0];if(!s.isAddress(o))return void console.warn(`Invalid ethereum address reported by ${this.walletClientType}: ${o}`);let r=c.getAddress(o),l=[];if("privy"===this.walletClientType){let e=a.u.get(n.getPrivyWalletKey(r));this.chains.find((t=>t.id===Number(e)))||(a.u.del(n.getPrivyWalletKey(r)),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 W((()=>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 ${n.DEFAULT_NETWORK}`,e),t=n.DEFAULT_NETWORK}let d=P(t);if(!l.find((e=>c.getAddress(e.address)===r))){let e={name:this.walletBranding.name,icon:"string"==typeof this.walletBranding.icon?this.walletBranding.icon:void 0,id:this.walletBranding.id};l.push(this.buildConnectedWallet(c.getAddress(o),d,e,"embedded_imported"===this.connectorType))}_(l,this.wallets)||(this.wallets=l,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.getAddress(e)===c.getAddress(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:[c.toHex(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,i,o){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=P(e),"privy"===this.walletClientType&&a.u.put(n.getPrivyWalletKey(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=i,this.rpcConfig=o,this.rpcTimeoutDuration=E(o,e),this.connected=!1,this.initialized=!1}}class j{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 d.PrivyConnectorError(`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 a.formatConnectorError(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 a.WalletTimeoutError,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||n.DEFAULT_RPC_TIMEOUT,this._subscriptions=[]}}const S=/*#__PURE__*/i.styled.div.withConfig({displayName:"Grow",componentId:"sc-681ff332-0"})(["text-align:left;flex-grow:1;"]),z=/*#__PURE__*/i.styled.div.withConfig({displayName:"AlignBottom",componentId:"sc-681ff332-1"})(["display:flex;flex-direction:column;justify-content:flex-end;flex-grow:1;"]),A=/*#__PURE__*/i.styled.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;}"]),L=/*#__PURE__*/i.styled(A).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 N=/*#__PURE__*/i.css(["&&{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 M=/*#__PURE__*/i.styled.div.withConfig({displayName:"Subtitle",componentId:"sc-681ff332-4"})(["text-align:center;font-size:14px;margin-bottom:24px;"]),$=/*#__PURE__*/i.styled.button.attrs({className:"login-method-button"}).withConfig({displayName:"LoginMethodButton",componentId:"sc-681ff332-5"})(["",""],N),D=/*#__PURE__*/i.styled.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)")),O=/*#__PURE__*/i.styled.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;":"")),F=/*#__PURE__*/i.styled.div.withConfig({displayName:"EmptyWalletState",componentId:"sc-681ff332-9"})(["width:100%;height:100%;padding:",";"],(e=>e.$withPadding?"64px 0px":"0px")),U=/*#__PURE__*/i.styled.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;}"]);let B=/*#__PURE__*/i.styled.span.withConfig({displayName:"PositionedAbsoluteLoader",componentId:"sc-aba6339d-0"})(["&&{position:absolute;top:0;left:0;z-index:2;}"]),R=/*#__PURE__*/i.styled.span.withConfig({displayName:"ConnectionLoaderContainer",componentId:"sc-aba6339d-1"})(["position:relative;width:82px;height:82px;display:inline-block;"]);const q=/*#__PURE__*/i.styled.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)")),K=/*#__PURE__*/i.styled(q).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)"));let H=/*#__PURE__*/i.styled(q).withConfig({displayName:"StyledButtonLoader",componentId:"sc-aba6339d-4"})(["&&{height:1rem;width:1rem;margin:2px 0;border-width:1.5px;transition:border-color 200ms ease;}"]);const Z=["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"],G=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=J({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=J({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=J({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=J({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"https://www.okx.com/download?deeplink="+encodeURIComponent("okx://wallet/dapp/url?dappUrl="+J({client:this.client,isSolana:e,connectOnly:t}))}}});function J({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 X extends a.SolanaWalletConnector{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:i}){super({name:t},!1),this.connectorType="null",this.proxyProvider=new j(void 0,n.DEFAULT_RPC_TIMEOUT),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=i}}function Q(e){return"solana"===e.chainType}let V=/*#__PURE__*/e.createContext({});let Y=e=>`privy:${e}:recent-login-method`,ee=e=>`privy:${e}:recent-login-wallet-client`,te=e=>`privy:${e}:recent-login-chain-type`;const ne=t.create((()=>({isModalOpen:!1,resolvers:null})));let ie=t.create((()=>({})));const oe=async()=>{let e,t,n=new Promise(((n,i)=>{e=n,t=i}));return ie.setState({}),ne.setState({isModalOpen:!0,resolvers:{resolve:e,reject:t}}),await n},re=({address:e,client:t,appId:n})=>{let i=`${t}:${e}`;n&&a.u.put(ae(n),i),ne.setState({wallet:i})},ae=e=>`privy:${e}:active-wallet-connection`;exports.AlignBottom=z,exports.ButtonLoader=e=>/*#__PURE__*/o.jsx(H,{color:e.color||"var(--privy-color-foreground-3)"}),exports.ConnectionLoader=({success:e,fail:t})=>/*#__PURE__*/o.jsxs(R,{children:[/*#__PURE__*/o.jsx(B,{children:/*#__PURE__*/o.jsx(K,{className:e?"success":t?"fail":""})}),/*#__PURE__*/o.jsx(B,{children:/*#__PURE__*/o.jsx(q,{className:e?"success":t?"fail":""})})]}),exports.EmptyWalletState=F,exports.EthereumNullConnector=class extends I{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:i,walletClientType:o,defaultChain:r}){super(o,[],r,{}),this.connectorType="null",this.proxyProvider=new j(void 0,n.DEFAULT_RPC_TIMEOUT),this.id=e,this.name=t,this.icon=i}},exports.EthereumWalletConnector=I,exports.Grow=S,exports.Header=U,exports.Hide=O,exports.Loader=q,exports.LoaderFaint=K,exports.LoginMethodButton=$,exports.LoginMethodContainer=A,exports.LoginMethodContainerWithScrollShadows=L,exports.LoginMethodIconWrapper=D,exports.Metamask=({...e})=>/*#__PURE__*/o.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"32",height:"32",viewBox:"0 0 32 32",fill:"none",...e,children:[/*#__PURE__*/o.jsx("rect",{width:"32",height:"32",rx:"6",fill:"#121314"}),/*#__PURE__*/o.jsx("g",{transform:"translate(4, 4)",children:/*#__PURE__*/o.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 318.6 318.6",children:[/*#__PURE__*/o.jsx("style",{children:".s1{stroke-linecap:round;stroke-linejoin:round}.s2{fill:#e4761b;stroke:#e4761b}.s3{fill:#f6851b;stroke:#f6851b}"}),/*#__PURE__*/o.jsx("path",{fill:"#e2761b",stroke:"#e2761b",className:"s1",d:"m274.1 35.5-99.5 73.9L193 65.8z"}),/*#__PURE__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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__*/o.jsx("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"})]})})]}),exports.PrivyProxyProvider=j,exports.RecentlyUsedAccountProvider=({children:t})=>{let i=n.useAppConfig(),[r,s]=e.useState({});return l.usePrivyEventSubscription("login",{onComplete:({loginAccount:e})=>{e&&"passkey"!==e.type&&"cross_app"!==e.type&&("wallet"!==e.type||"privy"!==e.walletClientType)&&(a.u.put(Y(i.id),e.type),"wallet"===e.type?(a.u.put(ee(i.id),e.walletClientType),a.u.put(te(i.id),e.chainType),s({accountType:e.type,walletClientType:e.walletClientType,chainType:e.chainType})):(a.u.del(ee(i.id)),a.u.del(te(i.id)),s({accountType:e.type})))}}),e.useEffect((()=>{if(!i.id)return;let e=a.u.get(Y(i.id)),t=a.u.get(ee(i.id)),n=a.u.get(te(i.id));e&&s("wallet"===e?{accountType:e,walletClientType:t,chainType:n}:{accountType:e})}),[i.id]),/*#__PURE__*/o.jsx(V.Provider,{value:r,children:t})},exports.SolanaNullConnector=X,exports.Subtitle=M,exports.areWalletArraysEqual=_,exports.clamp=function(e,{min:t,max:n}){return Math.min(Math.max(e,t),n)},exports.close=()=>{let e=ne.getState().resolvers;e||console.warn("useActiveWalletStore: Called close while modal was not open"),ne.setState({isModalOpen:!1}),e?.resolve({wallet:ne.getState().wallet})},exports.convert1dTo2dArray=(e,t)=>{let n=e.slice(0),i=[];for(;n.length;)i.push(n.splice(0,t));return i},exports.detectInjectedConnectors=async function({store:e,walletList:t,externalWalletConfig:n,walletChainType:i,timeout:o=3e3}){let r=!1,a=window;return new Promise((l=>{function s(){if(r)return;r=!0,window.removeEventListener("ethereum#initialized",s);let o=e.getProviders();console.debug("Detected injected providers:",o.map((e=>e.info)));let a=[];for(let e of o)t.includes("coinbase_wallet")&&"com.coinbase.wallet"===e.info.rdns||"solana-only"===i&&"app.phantom"===e.info.rdns||a.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=x(e);if(!o.some((e=>e.info.name===t))){if(v(e,!0)&&!a.find((e=>"metamask"===e.type))){a.push({type:"metamask",legacyInjectedProvider:e});continue}if("Phantom"===t&&!a.find((e=>"phantom"===e.type))){a.push({type:"phantom",legacyInjectedProvider:e});continue}if("Coinbase Wallet"===t&&!a.find((e=>"coinbase_wallet"===e.type&&"smartWalletOnly"!==n.coinbaseWallet?.config?.preference?.options))){a.push({type:"coinbase_wallet",legacyInjectedProvider:e});continue}a.find((e=>"unknown_browser_extension"===e.type))||a.push({type:"unknown_browser_extension",legacyInjectedProvider:e})}}l(a)}a.ethereum?s():(window.addEventListener("ethereum#initialized",s,{once:!0}),setTimeout((()=>{s()}),o))}))},exports.formatChainIdToCAIP2=P,exports.formatSolanaWalletAddress=(e,t=3,n=4)=>C(e,t,n,"solana"),exports.formatWalletAddress=C,exports.generateTypedDataWithDomainType=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}}},exports.getBlockExplorer=(e,t)=>{let n=Number(e),i=t.find((e=>e.id===n));if(!i)throw new d.PrivyConnectorError(`Unsupported chainId ${e}`,4901);return i.blockExplorers?.default.url},exports.getExternalWalletData=e=>f.getState().listings.find((({slug:t})=>b(t)===b(e))),exports.getExternalWalletDataByUrl=e=>{let t;try{t=new URL(e).hostname}catch(e){return}return f.getState().listings.find((({homepage:e})=>{let n;try{n=new URL(e).hostname}catch(e){return!1}return t.includes(n)}))},exports.getJsonRpcEndpoint=(e,t,n,i)=>{let o=Number(e),r=t.find((e=>e.id===o));if(!r)throw new d.PrivyConnectorError(`Unsupported chainId ${e}`,4901);return p.getJsonRpcEndpointFromChain(r,n,i)},exports.getRpcTimeout=E,exports.getWalletConfigForConnector=function({connectorType:e,walletClientType:t}){for(let n of Z)if(e===n||t===n)return G[n]},exports.invokeUntilSettled=W,exports.isBaseConnectedEthereumWallet=T,exports.isBaseConnectedSolanaWallet=function(e){return"solana"===e.type},exports.isCoinbaseWalletInstalled=()=>{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},exports.isEthereumWalletConnector=function(e){return"ethereum"===e.chainType},exports.isSolanaWalletConnector=Q,exports.mobileWalletsConfig=G,exports.parseAdditionalSigners=e=>e?.map((e=>({signer_id:e.signerId,override_policy_ids:e.policyIds}))),exports.pollForResult=function(e,{interval:t=100,timeout:n=5e3}={}){return new Promise(((i,o)=>{let r,a=0,l=()=>{a>=n?o("Max attempts reached without result"):(r=e(),a+=t,null==r?setTimeout(l,t):i(r))};l()}))},exports.setActiveWallet=re,exports.shouldFetchWcRegistryListings=function(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)))},exports.sleep=k,exports.splitAtIndex=(e,t)=>{let n=[],i=[];for(let[o,r]of e.entries())o<t?n.push(r):i.push(r);return[n,i]},exports.stripEmoji=e=>e.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,""),exports.toHex=e=>"string"==typeof e?e:"0x"+e.toString(16),exports.updateBalance=(e,t,n)=>{ie.setState((i=>({[e]:{...i[e],[t]:n}})))},exports.useActiveWallet=()=>{let t=n.useAppConfig(),{wallets:i}=h.useWallets(),{connectors:o}=d.usePrivyInternal(),r=e.useMemo((()=>o.filter(Q).flatMap((e=>e.wallets))),[o]),l=ne((e=>e.wallet));e.useEffect((()=>{if(!t.id)return;let e=a.u.get(ae(t.id));ne.setState({wallet:e})}),[t.id]);let s=e.useMemo((()=>{if(!l)return;let[,e]=l.split(":");return i.find((t=>t.address===e))||r.find((t=>t.address===e))}),[l,i,r]),c=e.useMemo((()=>s?"ethereum"===s.type?s.chainId:"solana":void 0),[s]);return{connect:async e=>{e?.reset&&(a.u.del(ae(t.id)),ne.setState({wallet:void 0}));let{wallet:n}=await oe();if(!n)return{};let[,o]=n.split(":"),l=i.find((e=>e.address===o));if(l)return{wallet:l,network:l.chainId};let s=r.find((e=>e.address===o));return s?{wallet:s,network:"solana"}:{}},setActiveWallet:e.useCallback((e=>{re({address:e.address,client:e.walletClientType,appId:t.id})}),[t.id]),wallet:s,network:c}},exports.useBalance=(e,t)=>ie((n=>n[e]?.[t])),exports.useConnectWallet=function(t){let{connectWallet:n}=e.useContext(u.PrivyContext);return l.usePrivyEventSubscription("connectWallet",t),{connectWallet:n}},exports.useElementHeight=t=>{let[n,i]=e.useState("auto");return e.useEffect((()=>{let e=new ResizeObserver((e=>{i(e[0]?.contentRect.height??"auto")}));return t.current&&e.observe(t.current),()=>{t.current&&e.unobserve(t.current)}}),[t.current]),n},exports.useExternalWalletListing=e=>{let{listings:t}=g();return t.find((({slug:t})=>b(t)===b(e)))},exports.useExternalWalletListings=g,exports.useFundWallet=e=>{l.usePrivyEventSubscription("fundWallet",e);let{fundWallet:t}=d.usePrivyInternal();return{fundWallet:({address:e,options:n})=>t(e,n)}},exports.useIsModalOpen=()=>ne((e=>e.isModalOpen)),exports.useLogin=function(t){let{login:n}=e.useContext(u.PrivyContext);return l.usePrivyEventSubscription("login",t),{login:n}},exports.useLogout=function(t){let{logout:n}=e.useContext(u.PrivyContext);return l.usePrivyEventSubscription("logout",t),{logout:n}},exports.useRecentlyUsedLogin=()=>e.useContext(V),exports.validateEmail=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,}))$/);