UNPKG

@privy-io/react-auth

Version:

React client for the Privy Auth API

186 lines (170 loc) • 27.2 kB
"use strict";var e=require("react"),t=require("zustand"),n=require("./context-Cg3IEi80.js"),r=require("styled-components"),o=require("react/jsx-runtime"),i=require("react-device-detect"),l=require("./use-export-wallet-_EIyxyle.js"),a=require("./events-context-Di6--rDg.js"),s=require("viem"),c=require("viem/utils"),d=require("./internal-context-BJv4f_bO.js"),h=require("./privy-context-CrM9_s6G.js"),p=require("./useWallets-dikDynAG.js");function u(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 r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var w=/*#__PURE__*/u(i);const m=t.create((()=>({listings:[],loading:!1}))),g=m.setState,y=(t=!0)=>{let r=n.useAppConfig(),o=m((e=>e.listings)),i=m((e=>e.loading)),l=!!o.length;return e.useEffect((()=>{t&&!l&&(g({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."))}`),[])})(r.walletConnectCloudProjectId).then((e=>g({listings:e,loading:!1}))).catch((e=>{console.error(e),g({listings:[],loading:!1})})))}),[t,l,r.walletConnectCloudProjectId]),{listings:o,loading:i}};function f(e){return"cryptocom"===e?"cryptocom-defi":"binance"===e?"binance-defi":e.replace(/[-_]wallet$/,"")}function b(e){return"ethereum"===e.type}function v(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){let r=e[n],o=t[n];if(r?.address!==o?.address||r&&o&&b(r)&&b(o)&&r?.chainId!==o?.chainId||r?.connectorType!==o?.connectorType||r?.connectedAt!==o?.connectedAt||r?.walletClientType!==o?.walletClientType||r?.isConnected!==o?.isConnected||r?.linked!==o?.linked)return!1}return!0}const x=(e,t)=>e.rpcTimeouts&&e.rpcTimeouts[t]||n.DEFAULT_RPC_TIMEOUT;class C extends l.WalletConnector{buildConnectedWallet(e,t,n,r){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:r,switchChain:async n=>{let r,i;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?(r=`0x${n.toString(16)}`,i=n):(r=n,i=Number(n)),a===l.formatChainIdToCAIP2(r))return;let s=this.chains.find((e=>e.id===i));if(!s)throw new d.PrivyConnectorError(`Unsupported chainId: ${n}`);let h=async()=>{await this.proxyProvider.request({method:"wallet_switchEthereumChain",params:[{chainId:r}]})};try{return await h()}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 l.sleep(300),await this.proxyProvider.request({method:"wallet_addEthereumChain",params:[{chainId:r,chainName:s.name,nativeCurrency:s.nativeCurrency,rpcUrls:[s.rpcUrls.default?.http[0]??""],blockExplorerUrls:[s.blockExplorers?.default.url??""]}]}),h();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;l.connectorLogger.debug("Syncing accounts",{wallet:this.walletClientType});let r=e;try{if(void 0===r){l.connectorLogger.rpcRequest("eth_accounts",this.walletClientType);let e=await l.invokeUntilSettled((()=>this.proxyProvider.request({method:"eth_accounts"})),{maxAttempts:10,delayMs:500});l.connectorLogger.rpcResponse("eth_accounts",this.walletClientType),Array.isArray(e)&&(r=e)}}catch(e){l.connectorLogger.warn("Wallet did not respond to eth_accounts, using prefetched accounts",{wallet:this.walletClientType})}if(!r||!Array.isArray(r)||r.length<=0||!r[0])return void l.connectorLogger.debug("No accounts found",{wallet:this.walletClientType});let o=r[0];if(!s.isAddress(o))return;let i=c.getAddress(o),a=[];if("privy"===this.walletClientType){let e=l.s.get(n.getPrivyWalletKey(i));this.chains.find((t=>t.id===Number(e)))||(l.s.del(n.getPrivyWalletKey(i)),e=null),t=e||`0x${this.defaultChain.id.toString(16)}`;try{await this.proxyProvider.request({method:"wallet_switchEthereumChain",params:[{chainId:t}]})}catch(e){l.connectorLogger.warn("Unable to switch embedded wallet chain on initialization",{wallet:this.walletClientType,chainId:t})}}else try{l.connectorLogger.rpcRequest("eth_chainId",this.walletClientType);let e=await l.invokeUntilSettled((()=>this.proxyProvider.request({method:"eth_chainId"})),{maxAttempts:10,delayMs:500});if(l.connectorLogger.rpcResponse("eth_chainId",this.walletClientType),"string"==typeof e)t=e;else{if("number"!=typeof e)throw Error("Invalid chainId returned from provider");t=`0x${e.toString(16)}`}}catch(e){l.connectorLogger.warn("Failed to get chainId from provider, using default",{wallet:this.walletClientType,defaultChainId:n.DEFAULT_NETWORK}),t=n.DEFAULT_NETWORK}let d=l.formatChainIdToCAIP2(t);if(!a.find((e=>c.getAddress(e.address)===i))){let e={name:this.walletBranding.name,icon:"string"==typeof this.walletBranding.icon?this.walletBranding.icon:void 0,id:this.walletBranding.id};a.push(this.buildConnectedWallet(c.getAddress(o),d,e,"embedded_imported"===this.connectorType))}v(a,this.wallets)||(l.connectorLogger.debug("Wallets updated",{wallet:this.walletClientType,address:i,chainId:d}),this.wallets=a,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,r,o){super(e),this.chainType="ethereum",this.onAccountsChanged=e=>{l.connectorLogger.providerEvent("accountsChanged",this.walletClientType,{accountsCount:e.length}),0===e.length?this.onDisconnect():this.syncAccounts(e)},this.onChainChanged=e=>{l.connectorLogger.providerEvent("chainChanged",this.walletClientType,{chainId:e}),this.wallets.forEach((t=>{t.chainId=l.formatChainIdToCAIP2(e),"privy"===this.walletClientType&&l.s.put(n.getPrivyWalletKey(t.address),e)})),this.emit("walletsUpdated")},this.onDisconnect=()=>{l.connectorLogger.providerEvent("disconnect",this.walletClientType),this.connected=!1,this.wallets=[],this.emit("walletsUpdated")},this.onConnect=async()=>{l.connectorLogger.providerEvent("connect",this.walletClientType),"base_account"===this.connectorType&&this.connected||(this.connected=!0,"coinbase_wallet"===this.connectorType&&await l.sleep(500),this.syncAccounts())},this.wallets=[],this.walletClientType=e,this.chains=t,this.defaultChain=r,this.rpcConfig=o,this.rpcTimeoutDuration=x(o,e),this.connected=!1,this.initialized=!1}}class k{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 l.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 l.WalletTimeoutError,t=this.rpcTimeoutDuration)=>new Promise(((n,r)=>setTimeout((()=>{r(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 T=r.styled.div` text-align: left; flex-grow: 1; `,_=r.styled.div` display: flex; flex-direction: column; justify-content: flex-end; flex-grow: 1; `,P=r.styled.div` display: flex; flex-direction: column; gap: 8px; /* for Internet Explorer, Edge */ -ms-overflow-style: none; /* for Firefox */ scrollbar-width: none; /* for Chrome, Safari, and Opera */ &::-webkit-scrollbar { display: none; } `,E=r.styled(P)` ${e=>"light"===e.$colorScheme?"background: linear-gradient(var(--privy-color-background), var(--privy-color-background) 70%) bottom, linear-gradient(rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0.06)) bottom;":"dark"===e.$colorScheme?"background: linear-gradient(var(--privy-color-background), var(--privy-color-background) 70%) bottom, linear-gradient(rgba(255, 255, 255, 0) 20%, rgba(255, 255, 255, 0.06)) bottom;":void 0} background-repeat: no-repeat; background-size: 100% 32px, 100% 16px; background-attachment: local, scroll; max-height: 400px; overflow-y: auto; scrollbar-width: none; padding: 3px; `;let j=r.css` && { width: 100%; font-size: 16px; line-height: 24px; min-height: 56px; /* Tablet and Up */ @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 z=r.styled.div` text-align: center; font-size: 14px; margin-bottom: 24px; `,S=r.styled.button.attrs({className:"login-method-button"})` ${j} `;r.styled.a` ${j} `;const L=r.styled.div` width: 32px; height: 32px; border-radius: ${e=>e.$fullSize?"0":"4px"}; background: ${e=>e.$fullSize?"transparent":"var(--privy-color-background-2)"}; display: flex; align-items: center; justify-content: center; flex-shrink: 0; svg { width: ${e=>e.$fullSize?"32px":"18px"}; height: ${e=>e.$fullSize?"32px":"18px"}; color: ${e=>e.$fullSize?"inherit":"var(--privy-color-icon-muted)"}; } `,A=r.styled.div` width: 100%; height: 100%; min-height: inherit; display: flex; flex-direction: column; ${e=>e.$if?"display: none;":""} `,I=r.styled.div` width: 100%; height: 100%; padding: ${e=>e.$withPadding?"64px 0px":"0px"}; `,W=r.styled.div` 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 $=r.styled.span` && { position: absolute; top: 0; left: 0; z-index: 2; } `,U=r.styled.span` position: relative; width: 82px; height: 82px; display: inline-block; `;const O=r.styled.span` && { width: 82px; height: 82px; border-width: 4px; border-style: solid; border-color: ${e=>e.color??"var(--privy-color-icon-subtle)"}; 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); } `,N=r.styled(O)` && { border-bottom-color: ${e=>e.color??"var(--privy-color-border-default)"}; border-color: ${e=>e.color??"var(--privy-color-border-default)"}; animation: none; opacity: 0.5; } `;let M=r.styled(O)` && { height: 1rem; width: 1rem; margin: 2px 0; border-width: 1.5px; /* Override default Loader to match button transitions */ transition: border-color 200ms ease; } `;const q=["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"],R=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 r=B({client:this.client,isSolana:t,connectOnly:n});return`${e?"phantom://":"https://phantom.app/ul/"}browse/${r}?ref=${r}`}},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 r=B({client:this.client,isSolana:t,connectOnly:n});return`${e?"solflare://ul/v1/":"https://solflare.com/ul/v1/"}browse/${r}?ref=${r}`}},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=B({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 r=B({client:this.client,isSolana:t,connectOnly:n});return`${e?"backpack://ul/v1/":"https://backpack.app/ul/v1/"}browse/${r}?ref=${r}`}},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=${B({client:this.client,isSolana:e,connectOnly:t})}`}}});function B({client:e,isSolana:t,connectOnly:n}){let r=new URL(window.location.href);return r.searchParams.set("privy_connector",t?"solana_adapter":"injected"),r.searchParams.set("privy_wallet_client",e),r.searchParams.set("privy_connect_only",String(n)),encodeURIComponent(r.href.replace(/\/$/g,""))}class D extends l.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:r}){super({name:t},!1),this.connectorType="null",this.proxyProvider=new k(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=r}}function F(e){return"solana"===e.chainType}let K=/*#__PURE__*/e.createContext({});let H=e=>`privy:${e}:recent-login-method`,J=e=>`privy:${e}:recent-login-wallet-client`,G=e=>`privy:${e}:recent-login-chain-type`;const X=t.create((()=>({isModalOpen:!1,resolvers:null})));let Q=t.create((()=>({})));const V=async()=>{let e,t,n=new Promise(((n,r)=>{e=n,t=r}));return Q.setState({}),X.setState({isModalOpen:!0,resolvers:{resolve:e,reject:t}}),await n},Y=({address:e,client:t,appId:n})=>{let r=`${t}:${e}`;n&&l.s.put(Z(n),r),X.setState({wallet:r})},Z=e=>`privy:${e}:active-wallet-connection`;exports.AlignBottom=_,exports.ButtonLoader=e=>/*#__PURE__*/o.jsx(M,{color:e.color||"var(--privy-color-foreground-3)"}),exports.ConnectionLoader=({success:e,fail:t})=>/*#__PURE__*/o.jsxs(U,{children:[/*#__PURE__*/o.jsx($,{children:/*#__PURE__*/o.jsx(N,{className:e?"success":t?"fail":""})}),/*#__PURE__*/o.jsx($,{children:/*#__PURE__*/o.jsx(O,{className:e?"success":t?"fail":""})})]}),exports.EmptyWalletState=I,exports.EthereumNullConnector=class extends C{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:r,walletClientType:o,defaultChain:i}){super(o,[],i,{}),this.connectorType="null",this.proxyProvider=new k(void 0,n.DEFAULT_RPC_TIMEOUT),this.id=e,this.name=t,this.icon=r}},exports.EthereumWalletConnector=C,exports.Grow=T,exports.Header=W,exports.Hide=A,exports.Loader=O,exports.LoaderFaint=N,exports.LoginMethodButton=S,exports.LoginMethodContainer=P,exports.LoginMethodContainerWithScrollShadows=E,exports.LoginMethodIconWrapper=L,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=k,exports.RecentlyUsedAccountProvider=({children:t})=>{let r=n.useAppConfig(),[i,s]=e.useState({});return a.usePrivyEventSubscription("login",{onComplete:({loginAccount:e})=>{e&&"passkey"!==e.type&&"cross_app"!==e.type&&("wallet"!==e.type||"privy"!==e.walletClientType)&&(l.s.put(H(r.id),e.type),"wallet"===e.type?(l.s.put(J(r.id),e.walletClientType),l.s.put(G(r.id),e.chainType),s({accountType:e.type,walletClientType:e.walletClientType,chainType:e.chainType})):(l.s.del(J(r.id)),l.s.del(G(r.id)),s({accountType:e.type})))}}),e.useEffect((()=>{if(!r.id)return;let e=l.s.get(H(r.id)),t=l.s.get(J(r.id)),n=l.s.get(G(r.id));e&&s("wallet"===e?{accountType:e,walletClientType:t,chainType:n}:{accountType:e})}),[r.id]),/*#__PURE__*/o.jsx(K.Provider,{value:i,children:t})},exports.SolanaNullConnector=D,exports.Subtitle=z,exports.areWalletArraysEqual=v,exports.close=()=>{let e=X.getState().resolvers;e||console.warn("useActiveWalletStore: Called close while modal was not open"),X.setState({isModalOpen:!1}),e?.resolve({wallet:X.getState().wallet})},exports.getExternalWalletData=e=>m.getState().listings.find((({slug:t})=>f(t)===f(e))),exports.getExternalWalletDataByUrl=e=>{let t;try{t=new URL(e).hostname}catch(e){return}return m.getState().listings.find((({homepage:e})=>{let n;try{n=new URL(e).hostname}catch(e){return!1}return t.includes(n)}))},exports.getRpcTimeout=x,exports.getWalletConfigForConnector=function({connectorType:e,walletClientType:t}){for(let n of q)if(e===n||t===n)return R[n]},exports.isBaseConnectedEthereumWallet=b,exports.isBaseConnectedSolanaWallet=function(e){return"solana"===e.type},exports.isEthereumWalletConnector=function(e){return"ethereum"===e.chainType},exports.isSolanaWalletConnector=F,exports.mobileWalletsConfig=R,exports.setActiveWallet=Y,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.updateBalance=(e,t,n)=>{Q.setState((r=>({[e]:{...r[e],[t]:n}})))},exports.useActiveWallet=()=>{let t=n.useAppConfig(),{wallets:r}=p.useWallets(),{connectors:o}=d.usePrivyInternal(),i=e.useMemo((()=>o.filter(F).flatMap((e=>e.wallets))),[o]),a=X((e=>e.wallet));e.useEffect((()=>{if(!t.id)return;let e=l.s.get(Z(t.id));X.setState({wallet:e})}),[t.id]);let s=e.useMemo((()=>{if(!a)return;let[,e]=a.split(":");return r.find((t=>t.address===e))||i.find((t=>t.address===e))}),[a,r,i]),c=e.useMemo((()=>s?"ethereum"===s.type?s.chainId:"solana":void 0),[s]);return{connect:async e=>{e?.reset&&(l.s.del(Z(t.id)),X.setState({wallet:void 0}));let{wallet:n}=await V();if(!n)return{};let[,o]=n.split(":"),a=r.find((e=>e.address===o));if(a)return{wallet:a,network:a.chainId};let s=i.find((e=>e.address===o));return s?{wallet:s,network:"solana"}:{}},setActiveWallet:e.useCallback((e=>{Y({address:e.address,client:e.walletClientType,appId:t.id})}),[t.id]),wallet:s,network:c}},exports.useBalance=(e,t)=>Q((n=>n[e]?.[t])),exports.useConnectWallet=function(t){let{connectWallet:n}=e.useContext(h.PrivyContext);return a.usePrivyEventSubscription("connectWallet",t),{connectWallet:n}},exports.useElementHeight=t=>{let[n,r]=e.useState("auto");return e.useEffect((()=>{let e=new ResizeObserver((e=>{r(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}=y();return t.find((({slug:t})=>f(t)===f(e)))},exports.useExternalWalletListings=y,exports.useFundWallet=e=>{a.usePrivyEventSubscription("fundWallet",e);let{fundWallet:t}=d.usePrivyInternal();return{fundWallet:({address:e,options:n})=>t(e,n)}},exports.useIsModalOpen=()=>X((e=>e.isModalOpen)),exports.useLogin=function(t){let{login:n}=e.useContext(h.PrivyContext);return a.usePrivyEventSubscription("login",t),{login:n}},exports.useLogout=function(t){let{logout:n}=e.useContext(h.PrivyContext);return a.usePrivyEventSubscription("logout",t),{logout:n}},exports.useRecentlyUsedLogin=()=>e.useContext(K);