@privy-io/react-auth 1.14.1-beta.5 → 1.14.1-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +31 -31
- package/dist/index.js +68 -68
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{useEffect as Pi,useState as se}from"react";import Zt from"axios";import Si from"axios";var z=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Pe=class extends z{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},u=class extends z{constructor(o,r){super(o,r);this.type="client_error"}};var W=class extends z{constructor(o,r){super(o,r);this.type="connector_error"}},S=t=>{if(t instanceof z)return t;if(!Si.isAxiosError(t))return V(t);if(!t.response)return new Pe("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new Pe(e||"ApiError",t.response.status,o||r,t)},V=t=>t instanceof z?t:t instanceof Error?new u(t.message,t):new u(`Internal error: ${t}`);var ko="1.14.1-beta.
|
|
1
|
+
import{useEffect as Pi,useState as se}from"react";import Zt from"axios";import Si from"axios";var z=class extends Error{constructor(o,r){super(o);r instanceof Error&&(this.cause=r)}toString(){return`${this.type}: ${this.message}${this.cause?` [cause: ${this.cause}]`:""}`}},Pe=class extends z{constructor(o,r,i,n){super(i,n);this.type=o;this.status=r}},u=class extends z{constructor(o,r){super(o,r);this.type="client_error"}};var W=class extends z{constructor(o,r){super(o,r);this.type="connector_error"}},S=t=>{if(t instanceof z)return t;if(!Si.isAxiosError(t))return V(t);if(!t.response)return new Pe("api_error",null,t.message,t);let{type:e,message:o,error:r}=t.response.data;return new Pe(e||"ApiError",t.response.status,o||r,t)},V=t=>t instanceof z?t:t instanceof Error?new u(t.message,t):new u(`Internal error: ${t}`);var ko="1.14.1-beta.7";var _o="https://api.privy.io/v0",Po=process.env.NEXT_PUBLIC_PRIVY_AUTH_URL||"https://auth.privy.io",ze="4df5e2316331463a9130964bd6078dfa",So=1e4,Se=1400,jt=ko;var Te="privy:token",nt="privy:refresh_token",st="privy:connectors",To="walletconnect";var at=class{constructor(e,o,r){this.appId=e,this.sdkVersion=jt,this.client=o,this.defaults=r}async get(e,o){try{return await Zt.get(e,await this.buildConfig({headers:{"Cache-Control":"no-cache"},...o}))}catch(r){throw S(r)}}async post(e,o,r){try{return await Zt.post(e,o,await this.buildConfig(r))}catch(i){throw S(i)}}async delete(e,o){try{return await Zt.delete(e,await this.buildConfig(o))}catch(r){throw S(r)}}async buildConfig(e){if(e=e||{},e.headers=e.headers||{},e.headers["privy-app-id"]=this.appId,e.headers["privy-client"]=`react-auth:${this.sdkVersion}`,!e.headers.authorization){let o=await this.client.getAccessToken();o!==null&&(e.headers.authorization=`Bearer ${o}`)}return{...this.defaults,...e}}};import*as Wo from"jose";var Y=class{static parse(e){try{return new Y(e)}catch{return null}}constructor(e){this.value=e,this._decoded=Wo.decodeJwt(e)}get subject(){return this._decoded.sub}get expiration(){return this._decoded.exp}get issuer(){return this._decoded.iss}get audience(){return this._decoded.aud}isExpired(e=0){let o=Date.now(),r=(this.expiration-e)*1e3;return o>=r}};var ce=class{constructor(e){this.promise=null;this.fn=e}execute(e){return this.promise===null&&(this.promise=(async()=>{try{return await this.fn(e)}finally{this.promise=null}})()),this.promise}};var Kt=class{constructor(){this._cache={}}get(e){return this._cache[e]}put(e,o){o!==void 0?this._cache[e]=o:this.del(e)}del(e){delete this._cache[e]}getKeys(){return Object.keys(this._cache)}},qt=class{get(e){let o=localStorage.getItem(e);return o===null?void 0:JSON.parse(o)}put(e,o){o!==void 0?localStorage.setItem(e,JSON.stringify(o)):this.del(e)}del(e){localStorage.removeItem(e)}getKeys(){return Object.entries(localStorage).map(([e])=>e)}};function Wi(){return typeof window<"u"&&window.localStorage?new qt:new Kt}var M=Wi();import{ErrorCode as Ii}from"@ethersproject/logger";var We=class extends W{constructor(){super("Wallet timeout");this.type="wallet_error"}},de=t=>{if(t instanceof W)return t;if((t==null?void 0:t.code)&&(t==null?void 0:t.reason)){let e=new Ie(t);return t.code===Ii.ACTION_REJECTED&&(e.details=Ce.E4001_USER_REJECTED_REQUEST),e}return t!=null&&t.code?new Ie(t):new W("Unknown connector error",t)},Jt=class extends z{constructor(o,r,i){super(o);this.type="provider_error";this.code=r,this.data=i}},Ie=class extends Jt{constructor(o){var n,a,d;let r=o;super(r.message,r.code,r.data);let i=Object.values(Ce).find(m=>m.eipCode===r.code);this.details=i||Ce.UNKNOWN_ERROR,r.code===-32002&&((n=r.message)!=null&&n.includes("already pending for origin")?(a=r.message)!=null&&a.includes("wallet_requestPermissions")?this.details=Ce.E32002_CONNECTION_ALREADY_PENDING:this.details=Ce.E32002_REQUEST_ALREADY_PENDING:(d=r.message)!=null&&d.includes("Already processing")&&r.message.includes("eth_requestAccounts")&&(this.details=Ce.E32002_WALLET_LOCKED))}},Ri={ERROR_USER_EXISTS:{message:"User already exists for this address",detail:"Try another address!",retryable:!1},ERROR_TIMED_OUT:{message:"Wallet request timed out",detail:"Please try connecting again.",retryable:!0},ERROR_WALLET_CONNECTION:{message:"Could not log in with wallet",detail:"Please try connecting again.",retryable:!0}},Mi={E32002_CONNECTION_ALREADY_PENDING:{eipCode:-32002,message:"Connection request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_REQUEST_ALREADY_PENDING:{eipCode:-32002,message:"Resource request already pending",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E32002_WALLET_LOCKED:{eipCode:-32002,message:"Wallet might be locked",detail:"Don\u2019t see your wallet modal? Check your other browser windows.",retryable:!1},E4001_USER_REJECTED_REQUEST:{eipCode:4001,message:"Signature rejected",detail:"Please try signing again.",retryable:!0}},Ni={E4001_DEFAULT_USER_REJECTED_REQUEST:{eipCode:4001,message:"User Rejected Request",detail:"The user rejected the request.",default:!0,retryable:!0},E4100_DEFAULT_UNAUTHORIZED:{eipCode:4100,message:"Unauthorized",detail:"The requested method and/or account has not been authorized by the user.",default:!0,retryable:!1},E4200_DEFAULT_UNSUPPORTED_METHOD:{eipCode:4200,message:"Unsupported Method",detail:"The Provider does not support the requested method.",default:!0,retryable:!1},E4900_DEFAULT_DISCONNECTED:{eipCode:4900,message:"Disconnected",detail:"The Provider is disconnected from all chains.",default:!0,retryable:!0},E4901_DEFAULT_CHAIN_DISCONNECTED:{eipCode:4901,message:"Chain Disconnected",detail:"The Provider is not connected to the requested chain.",default:!0,retryable:!0},E32700_DEFAULT_PARSE_ERROR:{eipCode:-32700,message:"Parse error",detail:"Invalid JSON",default:!0,retryable:!1},E32600_DEFAULT_INVALID_REQUEST:{eipCode:-32600,message:"Invalid request",detail:"JSON is not a valid request object",default:!0,retryable:!1},E32601_DEFAULT_METHOD_NOT_FOUND:{eipCode:-32601,message:"Method not found",detail:"Method does not exist",default:!0,retryable:!1},E32602_DEFAULT_INVALID_PARAMS:{eipCode:-32602,message:"Invalid params",detail:"Invalid method parameters",default:!0,retryable:!1},E32603_DEFAULT_INTERNAL_ERROR:{eipCode:-32603,message:"Internal error",detail:"Internal JSON-RPC error",default:!0,retryable:!0},E32000_DEFAULT_INVALID_INPUT:{eipCode:-32e3,message:"Invalid input",detail:"Missing or invalid parameters",default:!0,retryable:!1},E32001_DEFAULT_RESOURCE_NOT_FOUND:{eipCode:-32001,message:"Resource not found",detail:"Requested resource not found",default:!0,retryable:!1},E32002_DEFAULT_RESOURCE_UNAVAILABLE:{eipCode:-32002,message:"Resource unavailable",detail:"Requested resource not available",default:!0,retryable:!0},E32003_DEFAULT_TRANSACTION_REJECTED:{eipCode:-32003,message:"Transaction rejected",detail:"Transaction creation failed",default:!0,retryable:!0},E32004_DEFAULT_METHOD_NOT_SUPPORTED:{eipCode:-32004,message:"Method not supported",detail:"Method is not implemented",default:!0,retryable:!1},E32005_DEFAULT_LIMIT_EXCEEDED:{eipCode:-32005,message:"Limit exceeded",detail:"Request exceeds defined limit",default:!0,retryable:!1},E32006_DEFAULT_JSON_RPC_VERSION_NOT_SUPPORTED:{eipCode:-32006,message:"JSON-RPC version not supported",detail:"Version of JSON-RPC protocol is not supported",default:!0,retryable:!1}},Ce={UNKNOWN_ERROR:{eipCode:0,message:"Unknown error",detail:"Unknown error",retryable:!0},...Ni,...Mi},lt={...Ri,...Ce};var Oi=12e4,Yt=(t=new We,e=Oi)=>new Promise((o,r)=>setTimeout(()=>{r(t)},e)),Z=class{constructor(e){this.removeListener=(e,o)=>{if(this.walletProvider)return this.walletProvider.removeListener(e,o)};this.setProvider=e=>{this.walletProvider=e,this._subscriptions.forEach(o=>{var r;(r=this.walletProvider)==null||r.on(o.eventName,o.listener)})};this.walletProvider=e,this._subscriptions=[]}on(e,o){if(this.walletProvider)return this.walletProvider.on(e,o);this._subscriptions.push({eventName:e,listener:o})}request(e){if(!this.walletProvider)throw new W(`A wallet request of type ${e.method} was made before setting a wallet provider.`);return Promise.race([this.walletProvider.request(e),Yt()]).catch(o=>{throw de(o)})}},ve=class extends Z{constructor(o){super(o)}},ct=class extends Z{constructor(e){super(e)}sendAsync(e,o){throw new Error("sendAsync is no longer supported by EIP-1193. Use the request method instead.")}};import{getAddress as Di}from"@ethersproject/address";import{getAddress as Ui}from"@ethersproject/address";import{Web3Provider as Fi}from"@ethersproject/providers";var Q=class{constructor(e,o,r){this.createSiweMessage=(e,o,r,i,n,a,d)=>`${r} wants you to sign in with your Ethereum account:
|
|
2
2
|
${o}
|
|
3
3
|
|
|
4
4
|
${d}
|
|
@@ -9,7 +9,7 @@ Chain ID: ${e}
|
|
|
9
9
|
Nonce: ${a}
|
|
10
10
|
Issued At: ${n}
|
|
11
11
|
Resources:
|
|
12
|
-
- https://privy.io`;this.provider=o,this.walletType=e,this.address=r,this.chain=null,this.connected=!1}async fetchAddress(){if(!this.address){let e=await this.provider.request({method:"eth_accounts"});Array.isArray(e)&&e.length>0&&(this.address=Ui(e[0]))}return this.address}async fetchChainId(){if(!this.chain){let e=await this.provider.request({method:"eth_chainId"}),o=Number(e);this.chain=String(o)}return this.chain}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.fetchAddress(),r=await this.fetchChainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async sign(e){return new Fi(new ve(this.provider)).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,a="By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",d=new Date().toISOString();return this.createSiweMessage(e,o,i,n,d,r,a)}};import{isMobile as Gi}from"react-device-detect";var dt=class extends Q{constructor(e,o){super("metamask",e,o)}async connect(e){var o;return this.provider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.provider.setProvider(r)}),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}disconnect(){console.warn("Metamask does not support programmetic disconnect.")}async promptConnection(){try{let e="";Gi||await this.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]});let o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Di(o[0])),!e||e==="")throw new W("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw de(e)}}};import{getAddress as Hi}from"@ethersproject/address";import Vi from"@coinbase/wallet-sdk";var Bi=t=>{let e=`https://mainnet.infura.io/v3/${ze}`,o=1;return t.makeWeb3Provider(e,o)},ut,pt=class extends Q{constructor(e,o){super("coinbase_wallet",e,o),ut||(ut=new Vi({appName:"Privy",darkMode:!1,headlessMode:!1}))}async connect(e){return this.provider.setProvider(Bi(ut)),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}disconnect(){ut.disconnect()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="",o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Hi(o[0])),!e||e==="")throw new W("Unable to retrieve address");this.connected=!0}catch(e){throw de(e)}}};import Io from"@walletconnect/web3-provider";var Qt=class extends Q{constructor(o,r,i){super("wallet_connect",r,i);this._globalConnector=o,this._provider=this._globalConnector.getProviderForAddress(i)}async connect(o){return this.provider.setProvider(this._provider),(!await this.isConnected()||o.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let o="";this.provider.setProvider(this._provider);let r=await Promise.race([this._provider.enable(),Yt()]);if(r.length>0&&(o=r[0]),this._globalConnector.indexProvider(this._provider),!o||o==="")throw new W("Unable to retrieve address");this.connected=!0}catch(o){throw de(o)}}disconnect(){}},ht=class{constructor(){this._storageIdToProvider={},this._addressToStorageId={},M.getKeys().forEach(e=>{if(e.startsWith("walletconnect")){let o=new Io({infuraId:ze,storageId:e});o.enable(),this._storageIdToProvider[e]=o;for(let r of o.accounts)this._addressToStorageId[r]=e}})}build(e,o){return new Qt(this,e,o)}async disconnect(){Object.values(this._storageIdToProvider).forEach(async e=>{await e.disconnect()})}getProviderForAddress(e){let o=To,r=()=>`walletconnect:${Math.random().toString(36).slice(2)}`;e===null?o=r():o=this._addressToStorageId[e]||r();let i=new Io({infuraId:ze,storageId:o});return this._storageIdToProvider[o]=i,i}indexProvider(e){this._storageIdToProvider[e.storageId]=e;for(let o of e.accounts)this._addressToStorageId[o]=e.storageId}};import{getAddress as zi}from"@ethersproject/address";var Xt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isMetaMask)return!0}return!1},mt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isCoinbaseWallet)return!0}return!1},ft=t=>{let e=localStorage.getItem("-walletlink:https://www.walletlink.org:Addresses");return e?!!(t==null?void 0:t.linkedAccounts.filter(r=>r.type=="wallet"&&r.address===zi(e)).length):!1},Ro=()=>{var e;let t=M.get(st);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},$e=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new Z};this.walletConnectors=[],this.walletConnectGlobalWalletConnector=new ht}initialize(){this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1})}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(M.get(st)||[]).forEach(o=>{let r=this.createWalletConnector(o.walletType,o.address);this.addWalletConnector(r),o.active&&(this.activeWalletConnector=r)})}save(){let e=this.walletConnectors.map(o=>{var r;return{address:o.address,walletType:o.walletType,active:o.address===((r=this.activeWalletConnector)==null?void 0:r.address)}});M.put(st,e)}addWalletConnector(e){this.walletConnectors.find(r=>r.address===e.address&&r.walletType===e.walletType)||this.walletConnectors.push(e)}removeWallet(e){var r;if(this.walletConnectors=this.walletConnectors.filter(i=>i.address!==e),e===((r=this.activeWalletConnector)==null?void 0:r.address))if(this.walletConnectors.length>0){let i=this.walletConnectors[this.walletConnectors.length-1];this.setActiveWallet(i.address)}else this.activeWalletConnector=void 0;this.save()}async activeWalletSign(e){if(!this.activeWalletConnector)throw new W("Cannot sign, no wallet is active. Is a wallet connected?");if(!await this.activeWalletConnector.connect({showPrompt:!1}))throw new W("Cannot sign - unable to connect to wallet.");return this.activeWalletConnector.sign(e)}setActiveWallet(e){let o=this.walletConnectors.find(r=>r.address===e);return o?(this.activeWalletConnector=o,this.save(),!0):!1}createWalletConnector(e,o){switch(e){case"metamask":return new dt(new Z,o);case"coinbase_wallet":return new pt(new Z,o);case"wallet_connect":return this.walletConnectGlobalWalletConnector.build(new Z,o)}}};function ue(t){return new Date(t*1e3)}function $i(t){let e=[];for(let o of t){let r=o.type;switch(o.type){case"wallet":e.push({address:o.address,type:o.type,verifiedAt:ue(o.verified_at),chainType:o.chain_type});break;case"email":e.push({address:o.address,type:o.type,verifiedAt:ue(o.verified_at)});break;case"phone":e.push({number:o.phoneNumber,type:o.type,verifiedAt:ue(o.verified_at)});break;case"google_oauth":e.push({subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:ue(o.verified_at)});break;case"twitter_oauth":e.push({subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:ue(o.verified_at)});break;case"discord_oauth":e.push({subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:ue(o.verified_at)});break;case"github_oauth":e.push({subject:o.subject,username:o.username,name:o.name,email:o.email,type:o.type,verifiedAt:ue(o.verified_at)});break;default:console.warn(`Unrecognized account type: ${r}. Please consider upgrading the Privy SDK.`)}}return e}function be(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function je(t){let e=Ro();if(!e)return t.wallet&&console.warn("[Privy] User has linked wallets but no active wallet"),t;let o=t.linkedAccounts.find(i=>i.type==="wallet"&&i.address===e),r=Object.assign({},t);return r.wallet=o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},r}function X(t){if(!t)return null;let e=$i(t.linked_accounts),o=be(e,"wallet"),r=be(e,"email"),i=be(e,"phone"),n=be(e,"google_oauth"),a=be(e,"twitter_oauth"),d=be(e,"discord_oauth"),m=be(e,"github_oauth"),p={id:t.id,createdAt:ue(t.created_at),linkedAccounts:e,email:r&&{address:r==null?void 0:r.address},phone:i&&{number:i==null?void 0:i.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:n&&{subject:n.subject,email:n.email,name:n.name},twitter:a&&{subject:a.subject,username:a.username,name:a.name},discord:d&&{subject:d.subject,username:d.username,email:d.email},github:m&&{subject:m.subject,username:m.username,name:m.name,email:m.email}};return je(p)}var Mo=()=>"/api/v1/sessions",No=()=>"/api/v1/sessions/logout",Oo=()=>"/api/v1/sessions/fork",Uo=()=>"/api/v1/siwe/init",Fo=()=>"/api/v1/siwe/authenticate",Do=()=>"/api/v1/siwe/link",Go=()=>"/api/v1/passwordless/init",Ho=()=>"/api/v1/passwordless/authenticate",Vo=()=>"/api/v1/passwordless/link",Bo=()=>"/api/v1/passwordless_sms/init",zo=()=>"/api/v1/passwordless_sms/authenticate",$o=()=>"/api/v1/passwordless_sms/link",jo=()=>"/api/v1/oauth/init",Zo=()=>"/api/v1/oauth/authenticate",Ko=()=>"/api/v1/oauth/link",qo=()=>"/api/v1/siwe/unlink",Jo=()=>"/api/v1/passwordless/unlink",Yo=()=>"/api/v1/passwordless_sms/unlink",Qo=()=>"/api/v1/oauth/unlink";var ji=30,gt=class{constructor(){this.authenticateOnce=new ce(async e=>this._authenticate(e)),this.linkOnce=new ce(async e=>this._link(e)),this.refreshOnce=new ce(this._refresh.bind(this)),this.destroyOnce=new ce(this._destroy.bind(this)),this.forkSessionOnce=new ce(this._forkSession.bind(this))}get token(){try{let e=M.get(Te);return typeof e=="string"?new Y(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=M.get(nt);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=Y.parse(this.token);return e!==null&&!e.isExpired(ji)}authenticate(e){return this.authenticateOnce.execute(e)}link(e){return this.linkOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:r,user:i,is_new_user:n}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(r),{user:X(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),V(o)}}async _link(e){try{let o=await e.link();return X(o)}catch(o){throw console.warn("Error linking account"),V(o)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");if(!this.client)throw new u("Session has no PrivyClient instance");await this.client.getAccessToken({disableAutoRefresh:!0});let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Mo(),{refresh_token:o},{headers:{authorization:`Bearer ${e}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),X(r.data.user)}catch(r){if(r instanceof Pe&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw V(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(No(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new u("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(Oo(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw V(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?M.put(Te,e):M.del(Te)}storeRefreshToken(e){typeof e=="string"?M.put(nt,e):M.del(nt)}};var eo,Ze=class{constructor(e){let o=e.apiURL||_o,r=e.timeout||So;this.appId=e.appId,this.connectors=new $e,eo||(eo=new gt),this.session=eo,this.api=new at(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(Jo(),{address:e});return X(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(Yo(),{phoneNumber:e});return X(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(qo(),{address:e});return X(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(Qo(),{provider:e,subject:o});return X(r.data)}catch(r){throw V(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=Y.parse(this.session.token))==null?void 0:o.audience)!==this.appId?(await this.logout(),null):this.session.token:!(e!=null&&e.disableAutoRefresh)&&this.session.hasRefreshCredentials()?(await this.session.refresh(),this.session.token):null}async getAppSettings(){try{let e=await this.api.get(`/api/v1/apps/${this.appId}`);return{id:e.data.id,name:e.data.name,verificationKey:e.data.verification_key,logoUrl:e.data.logo_url||void 0,theme:e.data.theme,accentColor:e.data.accent_color||void 0,showWalletLoginFirst:e.data.show_wallet_login_first,allowlistConfig:{errorTitle:e.data.allowlist_config.error_title,errorDetail:e.data.allowlist_config.error_detail,errorCtaText:e.data.allowlist_config.cta_text,errorCtaLink:e.data.allowlist_config.cta_link},walletAuth:e.data.wallet_auth,emailAuth:e.data.email_auth,smsAuth:e.data.sms_auth,googleOAuth:e.data.google_oauth,twitterOAuth:e.data.twitter_oauth,discordOAuth:e.data.discord_oauth,githubOAuth:e.data.github_oauth,termsAndConditionsUrl:e.data.terms_and_conditions_url,privacyPolicyUrl:e.data.privacy_policy_url,createdAt:new Date(e.data.created_at*1e3),updatedAt:new Date(e.data.updated_at*1e3)}}catch(e){throw V(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(n=>n.type==="wallet"?n.address:null).includes(e))throw new u("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new u("Error setting the active wallet.");return je(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as na}from"@ethersproject/providers";import{createContext as Zi,useContext as Ki}from"react";var f=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var to=Zi({ready:!1,authenticated:!1,user:null,walletConnectors:null,login:f,linkEmail:f,linkPhone:f,linkWallet:f,linkGoogle:f,linkTwitter:f,linkDiscord:f,linkGithub:f,logout:f,getAccessToken:f,getEthereumProvider:f,getEthersProvider:f,getWeb3jsProvider:f,unlinkEmail:f,unlinkPhone:f,unlinkWallet:f,unlinkGoogle:f,unlinkTwitter:f,unlinkDiscord:f,unlinkGithub:f,setActiveWallet:f,forkSession:f}),I=()=>Ki(to);var Ke=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Fo(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Do(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw S(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Uo(),{address:r}),a=this.walletConnector.prepareMessage(i,r,n.data.nonce),d=await this.walletConnector.sign(a);return{message:a,signature:d}}};var qe=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Ho(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Vo();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw S(e)}}async sendCodeEmail(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new u("Email must be set when initialzing authentication.");try{let o=Go();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw S(o)}}};var Je=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=zo(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=$o();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw S(e)}}async sendSmsCode(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new u("phone nNumber must be set when initialzing authentication.");try{let o=Bo();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw S(o)}}};var Re=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=Zo(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=Ko();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw S(e)}}async getAuthorizationUrl(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.provider)throw new u("Provider must be set when initialzing OAuth authentication.");try{let e=jo();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw S(e)}}};import"wicg-inert";import Xs from"react-dom";import Lo from"styled-components";import{createContext as Ji,useContext as Yi,useEffect as er,useState as tr}from"react";import{jsx as qi}from"react/jsx-runtime";function Xo(t){return qi("link",{rel:"prefetch",href:t.src})}import{jsx as Qi,jsxs as Xi}from"react/jsx-runtime";var or=Ji({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1,github:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:f,navigateBack:f}),rr=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=tr("LANDING"),[a,d]=tr("LANDING");er(()=>{o||n("LANDING")},[o]),er(()=>{r||(d("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:a,navigate:p=>{d(i),n(p)},navigateBack:()=>{n(a)}};return Xi(or.Provider,{value:m,children:[e&&e.logoUrl&&Qi(Xo,{src:e.logoUrl}),t.children]})},g=()=>Yi(or);import{useEffect as Kn,useState as qn}from"react";import Ue from"styled-components";import on from"styled-components";import{jsx as ir}from"react/jsx-runtime";var nr=({style:t,...e})=>ir("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:ir("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as sr}from"react/jsx-runtime";var ar=({style:t,...e})=>sr("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:sr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as en,useContext as tn}from"react";var oo=en({isLinking:!1,linkingHint:null,getAuthMeta:f,getAuthFlow:f,closePrivyModal:f,initLoginWithWallet:f,loginWithWallet:f,loginWithCode:f,initLoginWithEmail:f,initLoginWithSms:f,resendEmailCode:f,resendSmsCode:f,initLoginWithOAuth:f,loginWithOAuth:f}),E=()=>tn(oo);import{jsx as te,jsxs as ln}from"react/jsx-runtime";var rn=()=>te("div",{}),nn=({backFn:t})=>te("div",{children:te(ar,{onClick:t})}),sn=t=>te("div",{children:te("div",{children:te(nr,{onClick:t.onClose})})});var L=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=E();return ln(an,{children:[t?te(nn,{backFn:t}):te(rn,{}),te(sn,{onClose:e||o})]})},an=on.div`
|
|
12
|
+
- https://privy.io`;this.provider=o,this.walletType=e,this.address=r,this.chain=null,this.connected=!1}async fetchAddress(){if(!this.address){let e=await this.provider.request({method:"eth_accounts"});Array.isArray(e)&&e.length>0&&(this.address=Ui(e[0]))}return this.address}async fetchChainId(){if(!this.chain){let e=await this.provider.request({method:"eth_chainId"}),o=Number(e);this.chain=String(o)}return this.chain}async getConnectedWallet(){let e=this.walletType;if(!e||!await this.isConnected())return null;let o=await this.fetchAddress(),r=await this.fetchChainId();return{address:o,chainId:r,chainType:"ethereum",walletType:e}}async sign(e){return new Fi(new ve(this.provider)).getSigner().signMessage(e)}prepareMessage(e,o,r){let i=window.location.host,n=window.location.origin,a="By signing, you are proving you own this wallet and logging in. This does not initiate a transaction or cost any fees.",d=new Date().toISOString();return this.createSiweMessage(e,o,i,n,d,r,a)}};import{isMobile as Gi}from"react-device-detect";var dt=class extends Q{constructor(e,o){super("metamask",e,o)}async connect(e){var o;return this.provider.setProvider(window.ethereum),(o=window.ethereum.providers)==null||o.forEach(async r=>{r.isMetaMask&&this.provider.setProvider(r)}),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return await this.fetchAddress()!==null}disconnect(){console.warn("Metamask does not support programmetic disconnect.")}async promptConnection(){try{let e="";Gi||await this.provider.request({method:"wallet_requestPermissions",params:[{eth_accounts:{}}]});let o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Di(o[0])),!e||e==="")throw new W("Unable to retrieve address");this.connected=!0,this.address=e}catch(e){throw de(e)}}};import{getAddress as Hi}from"@ethersproject/address";import Vi from"@coinbase/wallet-sdk";var Bi=t=>{let e=`https://mainnet.infura.io/v3/${ze}`,o=1;return t.makeWeb3Provider(e,o)},ut,pt=class extends Q{constructor(e,o){super("coinbase_wallet",e,o),ut||(ut=new Vi({appName:"Privy",darkMode:!1,headlessMode:!1}))}async connect(e){return this.provider.setProvider(Bi(ut)),(!await this.isConnected()||e.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}disconnect(){ut.disconnect()}async isConnected(){return await this.fetchAddress()!==null}async promptConnection(){try{let e="",o=await this.provider.request({method:"eth_requestAccounts"});if(o.length>0&&(e=Hi(o[0])),!e||e==="")throw new W("Unable to retrieve address");this.connected=!0}catch(e){throw de(e)}}};import Io from"@walletconnect/web3-provider";var Qt=class extends Q{constructor(o,r,i){super("wallet_connect",r,i);this._globalConnector=o,this._provider=this._globalConnector.getProviderForAddress(i)}async connect(o){return this.provider.setProvider(this._provider),(!await this.isConnected()||o.showPrompt)&&await this.promptConnection(),this.getConnectedWallet()}async isConnected(){return this.provider.walletProvider.connected}async promptConnection(){try{let o="";this.provider.setProvider(this._provider);let r=await Promise.race([this._provider.enable(),Yt()]);if(r.length>0&&(o=r[0]),this._globalConnector.indexProvider(this._provider),!o||o==="")throw new W("Unable to retrieve address");this.connected=!0}catch(o){throw de(o)}}disconnect(){}},ht=class{constructor(){this._storageIdToProvider={},this._addressToStorageId={},M.getKeys().forEach(e=>{if(e.startsWith("walletconnect")){let o=new Io({infuraId:ze,storageId:e});o.enable(),this._storageIdToProvider[e]=o;for(let r of o.accounts)this._addressToStorageId[r]=e}})}build(e,o){return new Qt(this,e,o)}async disconnect(){Object.values(this._storageIdToProvider).forEach(async e=>{await e.disconnect()})}getProviderForAddress(e){let o=To,r=()=>`walletconnect:${Math.random().toString(36).slice(2)}`;e===null?o=r():o=this._addressToStorageId[e]||r();let i=new Io({infuraId:ze,storageId:o});return this._storageIdToProvider[o]=i,i}indexProvider(e){this._storageIdToProvider[e.storageId]=e;for(let o of e.accounts)this._addressToStorageId[o]=e.storageId}};import{getAddress as zi}from"@ethersproject/address";var Xt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isMetaMask)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isMetaMask)return!0}return!1},mt=()=>{if(!window.ethereum)return!1;if(window.ethereum.isCoinbaseWallet)return!0;if(window.ethereum.providers){for(let t of window.ethereum.providers)if(t.isCoinbaseWallet)return!0}return!1},ft=t=>{let e=localStorage.getItem("-walletlink:https://www.walletlink.org:Addresses");return e?!!(t==null?void 0:t.linkedAccounts.filter(r=>r.type=="wallet"&&r.address===zi(e)).length):!1},Ro=()=>{var e;let t=M.get(st);return t?(e=t.find(o=>o.active))==null?void 0:e.address:null},$e=class{constructor(){this.getEthereumProvider=()=>{var e;return((e=this.activeWalletConnector)==null?void 0:e.provider)||new Z};this.walletConnectors=[],this.walletConnectGlobalWalletConnector=new ht}initialize(){this.load(),this.activeWalletConnector&&this.activeWalletConnector.connect({showPrompt:!1})}initializeLinkedWallets(e){e.linkedAccounts.forEach(()=>{})}load(){(M.get(st)||[]).forEach(o=>{let r=this.createWalletConnector(o.walletType,o.address);this.addWalletConnector(r),o.active&&(this.activeWalletConnector=r)})}save(){let e=this.walletConnectors.map(o=>{var r;return{address:o.address,walletType:o.walletType,active:o.address===((r=this.activeWalletConnector)==null?void 0:r.address)}});M.put(st,e)}addWalletConnector(e){this.walletConnectors.find(r=>r.address===e.address&&r.walletType===e.walletType)||this.walletConnectors.push(e)}removeWallet(e){var r;if(this.walletConnectors=this.walletConnectors.filter(i=>i.address!==e),e===((r=this.activeWalletConnector)==null?void 0:r.address))if(this.walletConnectors.length>0){let i=this.walletConnectors[this.walletConnectors.length-1];this.setActiveWallet(i.address)}else this.activeWalletConnector=void 0;this.save()}async activeWalletSign(e){if(!this.activeWalletConnector)throw new W("Cannot sign, no wallet is active. Is a wallet connected?");if(!await this.activeWalletConnector.connect({showPrompt:!1}))throw new W("Cannot sign - unable to connect to wallet.");return this.activeWalletConnector.sign(e)}setActiveWallet(e){let o=this.walletConnectors.find(r=>r.address===e);return o?(this.activeWalletConnector=o,this.save(),!0):!1}createWalletConnector(e,o){switch(e){case"metamask":return new dt(new Z,o);case"coinbase_wallet":return new pt(new Z,o);case"wallet_connect":return this.walletConnectGlobalWalletConnector.build(new Z,o)}}};function ue(t){return new Date(t*1e3)}function $i(t){let e=[];for(let o of t){let r=o.type;switch(o.type){case"wallet":e.push({address:o.address,type:o.type,verifiedAt:ue(o.verified_at),chainType:o.chain_type});break;case"email":e.push({address:o.address,type:o.type,verifiedAt:ue(o.verified_at)});break;case"phone":e.push({number:o.phoneNumber,type:o.type,verifiedAt:ue(o.verified_at)});break;case"google_oauth":e.push({subject:o.subject,email:o.email,name:o.name,type:o.type,verifiedAt:ue(o.verified_at)});break;case"twitter_oauth":e.push({subject:o.subject,username:o.username,name:o.name,type:o.type,verifiedAt:ue(o.verified_at)});break;case"discord_oauth":e.push({subject:o.subject,username:o.username,email:o.email,type:o.type,verifiedAt:ue(o.verified_at)});break;case"github_oauth":e.push({subject:o.subject,username:o.username,name:o.name,email:o.email,type:o.type,verifiedAt:ue(o.verified_at)});break;default:console.warn(`Unrecognized account type: ${r}. Please consider upgrading the Privy SDK.`)}}return e}function be(t,e){return t.sort((o,r)=>r.verifiedAt.getTime()-o.verifiedAt.getTime()),t.find(o=>o.type===e)}function je(t){let e=Ro();if(!e)return t.wallet&&console.warn("[Privy] User has linked wallets but no active wallet"),t;let o=t.linkedAccounts.find(i=>i.type==="wallet"&&i.address===e),r=Object.assign({},t);return r.wallet=o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},r}function X(t){if(!t)return null;let e=$i(t.linked_accounts),o=be(e,"wallet"),r=be(e,"email"),i=be(e,"phone"),n=be(e,"google_oauth"),a=be(e,"twitter_oauth"),d=be(e,"discord_oauth"),m=be(e,"github_oauth"),p={id:t.id,createdAt:ue(t.created_at),linkedAccounts:e,email:r&&{address:r==null?void 0:r.address},phone:i&&{number:i==null?void 0:i.number},wallet:o&&{address:o.address,chainType:o.chainType,chainId:o.chainId,walletType:o.walletType},google:n&&{subject:n.subject,email:n.email,name:n.name},twitter:a&&{subject:a.subject,username:a.username,name:a.name},discord:d&&{subject:d.subject,username:d.username,email:d.email},github:m&&{subject:m.subject,username:m.username,name:m.name,email:m.email}};return je(p)}var Mo=()=>"/api/v1/sessions",No=()=>"/api/v1/sessions/logout",Oo=()=>"/api/v1/sessions/fork",Uo=()=>"/api/v1/siwe/init",Fo=()=>"/api/v1/siwe/authenticate",Do=()=>"/api/v1/siwe/link",Go=()=>"/api/v1/passwordless/init",Ho=()=>"/api/v1/passwordless/authenticate",Vo=()=>"/api/v1/passwordless/link",Bo=()=>"/api/v1/passwordless_sms/init",zo=()=>"/api/v1/passwordless_sms/authenticate",$o=()=>"/api/v1/passwordless_sms/link",jo=()=>"/api/v1/oauth/init",Zo=()=>"/api/v1/oauth/authenticate",Ko=()=>"/api/v1/oauth/link",qo=()=>"/api/v1/siwe/unlink",Jo=()=>"/api/v1/passwordless/unlink",Yo=()=>"/api/v1/passwordless_sms/unlink",Qo=()=>"/api/v1/oauth/unlink";var ji=30,gt=class{constructor(){this.authenticateOnce=new ce(async e=>this._authenticate(e)),this.linkOnce=new ce(async e=>this._link(e)),this.refreshOnce=new ce(this._refresh.bind(this)),this.destroyOnce=new ce(this._destroy.bind(this)),this.forkSessionOnce=new ce(this._forkSession.bind(this))}get token(){try{let e=M.get(Te);return typeof e=="string"?new Y(e).value:null}catch(e){return console.error(e),this.destroyLocalState(),null}}get refreshToken(){try{let e=M.get(nt);return typeof e=="string"?e:null}catch(e){return console.error(e),this.destroyLocalState(),null}}hasRefreshCredentials(){return typeof this.token=="string"&&typeof this.refreshToken=="string"}hasActiveToken(){let e=Y.parse(this.token);return e!==null&&!e.isExpired(ji)}authenticate(e){return this.authenticateOnce.execute(e)}link(e){return this.linkOnce.execute(e)}refresh(){return this.refreshOnce.execute()}forkSession(){return this.forkSessionOnce.execute()}destroy(){return this.destroyOnce.execute()}async _authenticate(e){try{let{token:o,refresh_token:r,user:i,is_new_user:n}=await e.authenticate();return this.storeToken(o),this.storeRefreshToken(r),{user:X(i),isNewUser:n}}catch(o){throw console.warn("Error authenticating session"),V(o)}}async _link(e){try{let o=await e.link();return X(o)}catch(o){throw console.warn("Error linking account"),V(o)}}async _refresh(){if(!this.api)throw new u("Session has no API instance");if(!this.client)throw new u("Session has no PrivyClient instance");await this.client.getAccessToken({disableAutoRefresh:!0});let e=this.token,o=this.refreshToken;if(!e||!o)return null;try{let r=await this.api.post(Mo(),{refresh_token:o},{headers:{authorization:`Bearer ${e}`}});return this.storeToken(r.data.token),this.storeRefreshToken(r.data.refresh_token),X(r.data.user)}catch(r){if(r instanceof Pe&&r.status===400&&r.message==="Invalid auth token")return this.destroyLocalState(),null;throw V(r)}}async _destroy(){var e;try{await((e=this.api)==null?void 0:e.post(No(),{refresh_token:this.refreshToken}))}catch{console.warn("Error destroying session")}this.destroyLocalState()}async _forkSession(){if(!this.api)throw new u("Session has no API instance");let e=this.refreshToken;try{let o=await this.api.post(Oo(),{refresh_token:e});return this.storeToken(o.data.token),this.storeRefreshToken(o.data.refresh_token),o.data.new_session_refresh_token}catch(o){throw V(o)}}destroyLocalState(){this.storeToken(null),this.storeRefreshToken(null)}storeToken(e){typeof e=="string"?M.put(Te,e):M.del(Te)}storeRefreshToken(e){typeof e=="string"?M.put(nt,e):M.del(nt)}};var eo,Ze=class{constructor(e){let o=e.apiURL||_o,r=e.timeout||So;this.appId=e.appId,this.connectors=new $e,eo||(eo=new gt),this.session=eo,this.api=new at(e.appId,this,{baseURL:o,timeout:r}),this.session.api=this.api,this.session.client=this}authenticate(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.authenticate(this.authFlow)}link(){if(!this.authFlow)throw new u("No auth flow in progress.");return this.session.link(this.authFlow)}async logout(){await this.session.destroy(),this.authFlow=void 0}startAuthFlow(e){e.api=this.api,this.authFlow=e}async unlinkEmail(e){try{let o=await this.api.post(Jo(),{address:e});return X(o.data)}catch(o){throw V(o)}}async unlinkPhone(e){try{let o=await this.api.post(Yo(),{phoneNumber:e});return X(o.data)}catch(o){throw V(o)}}async unlinkWallet(e){try{let o=await this.api.post(qo(),{address:e});return X(o.data)}catch(o){throw V(o)}}async unlinkOAuth(e,o){try{let r=await this.api.post(Qo(),{provider:e,subject:o});return X(r.data)}catch(r){throw V(r)}}async getAuthenticatedUser(){return this.session.hasRefreshCredentials()?this.session.refresh():null}async getAccessToken(e){var o;return this.session.hasActiveToken()?((o=Y.parse(this.session.token))==null?void 0:o.audience)!==this.appId?(await this.logout(),null):this.session.token:!(e!=null&&e.disableAutoRefresh)&&this.session.hasRefreshCredentials()?(await this.session.refresh(),this.session.token):null}async getAppSettings(){try{let e=await this.api.get(`/api/v1/apps/${this.appId}`);return{id:e.data.id,name:e.data.name,verificationKey:e.data.verification_key,logoUrl:e.data.logo_url||void 0,theme:e.data.theme,accentColor:e.data.accent_color||void 0,showWalletLoginFirst:e.data.show_wallet_login_first,allowlistConfig:{errorTitle:e.data.allowlist_config.error_title,errorDetail:e.data.allowlist_config.error_detail,errorCtaText:e.data.allowlist_config.cta_text,errorCtaLink:e.data.allowlist_config.cta_link},walletAuth:e.data.wallet_auth,emailAuth:e.data.email_auth,smsAuth:e.data.sms_auth,googleOAuth:e.data.google_oauth,twitterOAuth:e.data.twitter_oauth,discordOAuth:e.data.discord_oauth,githubOAuth:e.data.github_oauth,termsAndConditionsUrl:e.data.terms_and_conditions_url,privacyPolicyUrl:e.data.privacy_policy_url,createdAt:new Date(e.data.created_at*1e3),updatedAt:new Date(e.data.updated_at*1e3)}}catch(e){throw V(e)}}setActiveWallet(e,o){if(!o.linkedAccounts.map(n=>n.type==="wallet"?n.address:null).includes(e))throw new u("Cannot set an unlinked address as active.");if(!this.connectors.setActiveWallet(e))throw new u("Error setting the active wallet.");return je(o)}async forkSession(){return await this.session.forkSession()}};import{Web3Provider as sa}from"@ethersproject/providers";import{createContext as Zi,useContext as Ki}from"react";var f=()=>{throw new Error("You need to wrap your application with the <PrivyProvider> initialized with your app id.")};var to=Zi({ready:!1,authenticated:!1,user:null,walletConnectors:null,login:f,linkEmail:f,linkPhone:f,linkWallet:f,linkGoogle:f,linkTwitter:f,linkDiscord:f,linkGithub:f,logout:f,getAccessToken:f,getEthereumProvider:f,getEthersProvider:f,getWeb3jsProvider:f,unlinkEmail:f,unlinkPhone:f,unlinkWallet:f,unlinkGoogle:f,unlinkTwitter:f,unlinkDiscord:f,unlinkGithub:f,setActiveWallet:f,forkSession:f}),I=()=>Ki(to);var Ke=class{constructor(e,o){this.meta={walletType:o},this.connectors=e,this.walletConnector=this.connectors.createWalletConnector(o,null)}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Fo(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),{user:r.data.user,token:r.data.token,refresh_token:r.data.refresh_token,is_new_user:r.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");try{let{message:e,signature:o}=await this.promptConnectAndSign(this.api),r=await this.api.post(Do(),{message:e,signature:o});return this.connectors.addWalletConnector(this.walletConnector),this.connectors.setActiveWallet(this.walletConnector.address)||console.warn("Failed to set active wallet"),r.data}catch(e){throw S(e)}}async promptConnectAndSign(e){let o=await this.walletConnector.connect({showPrompt:!0}),r=o.address,i=o.chainId,n=await e.post(Uo(),{address:r}),a=this.walletConnector.prepareMessage(i,r,n.data.nonce),d=await this.walletConnector.sign(a);return{message:a,signature:d}}};var qe=class{constructor(e){this.meta={email:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Ho(),o=await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.email||!this.meta.emailCode)throw new u("Email and email code must be set prior to calling authenticate.");try{let e=Vo();return(await this.api.post(e,{email:this.meta.email,code:this.meta.emailCode})).data}catch(e){throw S(e)}}async sendCodeEmail(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.email=e),!this.meta.email)throw new u("Email must be set when initialzing authentication.");try{let o=Go();return(await this.api.post(o,{email:this.meta.email})).data}catch(o){throw S(o)}}};var Je=class{constructor(e){this.meta={phoneNumber:e}}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=zo(),o=await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.phoneNumber||!this.meta.smsCode)throw new u("phone number and sms code must be set prior to calling authenticate.");try{let e=$o();return(await this.api.post(e,{phoneNumber:this.meta.phoneNumber,code:this.meta.smsCode})).data}catch(e){throw S(e)}}async sendSmsCode(e){if(!this.api)throw new u("Auth flow has no API instance");if(e&&(this.meta.phoneNumber=e),!this.meta.phoneNumber)throw new u("phone nNumber must be set when initialzing authentication.");try{let o=Bo();return(await this.api.post(o,{phoneNumber:this.meta.phoneNumber})).data}catch(o){throw S(o)}}};var Re=class{constructor(e,o,r){this.meta={provider:e},this.meta.authorizationCode=o,this.meta.stateCode=r}isActive(){return!!(this.meta.authorizationCode&&this.meta.stateCode&&this.meta.provider)}async authenticate(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling authenticate.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=Zo(),o=await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode});return{user:o.data.user,token:o.data.token,refresh_token:o.data.refresh_token,is_new_user:o.data.is_new_user}}catch(e){throw S(e)}}async link(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.authorizationCode||!this.meta.stateCode)throw new u("[OAuth AuthFlow] Authorization and state codes code must be set prior to calling link.");if(this.meta.authorizationCode==="undefined")throw new u("User denied confirmation during OAuth flow");try{let e=Ko();return(await this.api.post(e,{authorization_code:this.meta.authorizationCode,state_code:this.meta.stateCode})).data}catch(e){throw S(e)}}async getAuthorizationUrl(){if(!this.api)throw new u("Auth flow has no API instance");if(!this.meta.provider)throw new u("Provider must be set when initialzing OAuth authentication.");try{let e=jo();return(await this.api.post(e,{provider:this.meta.provider,redirect_to:window.location.href})).data}catch(e){throw S(e)}}};import"wicg-inert";import ea from"react-dom";import Lo from"styled-components";import{createContext as Ji,useContext as Yi,useEffect as er,useState as tr}from"react";import{jsx as qi}from"react/jsx-runtime";function Xo(t){return qi("link",{rel:"prefetch",href:t.src})}import{jsx as Qi,jsxs as Xi}from"react/jsx-runtime";var or=Ji({ready:!1,app:null,options:{email:!0,sms:!1,wallet:!0,google:!1,twitter:!1,discord:!1,github:!1},currentScreen:"LANDING",lastScreen:"LANDING",navigate:f,navigateBack:f}),rr=t=>{let e=t.appSettings,o=t.authenticated,r=t.visible,[i,n]=tr("LANDING"),[a,d]=tr("LANDING");er(()=>{o||n("LANDING")},[o]),er(()=>{r||(d("LANDING"),n("LANDING"))},[r]);let m={ready:!!(e!=null&&e.id),app:e,options:t.options,currentScreen:i,lastScreen:a,navigate:p=>{d(i),n(p)},navigateBack:()=>{n(a)}};return Xi(or.Provider,{value:m,children:[e&&e.logoUrl&&Qi(Xo,{src:e.logoUrl}),t.children]})},g=()=>Yi(or);import{useEffect as Kn,useState as qn}from"react";import Ue from"styled-components";import on from"styled-components";import{jsx as ir}from"react/jsx-runtime";var nr=({style:t,...e})=>ir("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:ir("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})});import{jsx as sr}from"react/jsx-runtime";var ar=({style:t,...e})=>sr("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:sr("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M10.5 19.5L3 12m0 0l7.5-7.5M3 12h18"})});import{createContext as en,useContext as tn}from"react";var oo=en({isLinking:!1,linkingHint:null,getAuthMeta:f,getAuthFlow:f,closePrivyModal:f,initLoginWithWallet:f,loginWithWallet:f,loginWithCode:f,initLoginWithEmail:f,initLoginWithSms:f,resendEmailCode:f,resendSmsCode:f,initLoginWithOAuth:f,loginWithOAuth:f}),E=()=>tn(oo);import{jsx as te,jsxs as ln}from"react/jsx-runtime";var rn=()=>te("div",{}),nn=({backFn:t})=>te("div",{children:te(ar,{onClick:t})}),sn=t=>te("div",{children:te("div",{children:te(nr,{onClick:t.onClose})})});var L=({backFn:t,onClose:e})=>{let{closePrivyModal:o}=E();return ln(an,{children:[t?te(nn,{backFn:t}):te(rn,{}),te(sn,{onClose:e||o})]})},an=on.div`
|
|
13
13
|
height: 30px;
|
|
14
14
|
display: flex;
|
|
15
15
|
align-items: center;
|
|
@@ -633,14 +633,14 @@ Resources:
|
|
|
633
633
|
border-color: var(--light-theme-bg-3);
|
|
634
634
|
border-width: 1px;
|
|
635
635
|
}
|
|
636
|
-
`;import{Fragment as uo,jsx as B,jsxs as De}from"react/jsx-runtime";var po=6,Hr=new Array(po).fill(""),
|
|
636
|
+
`;import{isMobile as is}from"react-device-detect";import{Fragment as uo,jsx as B,jsxs as De}from"react/jsx-runtime";var po=6,Hr=new Array(po).fill(""),ns=1400;var Vr=()=>{var J,le,U;let{app:t}=g(),{closePrivyModal:e,resendEmailCode:o,resendSmsCode:r,getAuthMeta:i,loginWithCode:n}=E(),{authenticated:a,user:d}=I(),[m,p]=It(Hr),[P,k]=It(!1),[C,b]=It(null),[l,v]=It(null),x=(J=i())!=null&&J.email?0:1;Gr(()=>{if(a&&P){let y=setTimeout(e,Se);return()=>clearTimeout(y)}},[a,P,d]),Gr(()=>{if(C&&l===0){let y=setTimeout(()=>{p(Hr),b(null);let A=document.querySelector("input[name=code-0]");A==null||A.focus()},ns);return()=>clearTimeout(y)}},[C]);let G=y=>{var Eo;let A=y.currentTarget.value.replace(" ","");if(A==="")return;if(isNaN(Number(A))){b("Code should be numeric"),v(1);return}b(null),v(null);let s=Number((Eo=y.currentTarget.name)==null?void 0:Eo.charAt(5)),c=[...A||[""]].slice(0,po-s),H=[...m.slice(0,s),...c,...m.slice(s+c.length)];p(H);let Be=c.length,Ao=Math.min(Math.max(s+Be,0),po-1);if(!isNaN(Number(y.currentTarget.value))){let j=document.querySelector(`input[name=code-${Ao}]`);j==null||j.focus()}if(H.every(j=>j&&!isNaN(+j))){let j=document.querySelector(`input[name=code-${Ao}]`);j==null||j.blur(),n(H.join("")).then(()=>k(!0)).catch($t=>{($t==null?void 0:$t.status)===422?b("Invalid or expired verification code"):b("Issue verifying code"),v(0)})}y.preventDefault()},ye=y=>{l===1&&(b(null),v(null));let A=[...m.slice(0,y),"",...m.slice(y+1)];if(p(A),y>0){let s=document.querySelector(`input[name=code-${y-1}]`);s==null||s.focus()}},ae=`Verify your ${x==0?"email":"phone"}`,O=x==0?`Please check ${(le=i())==null?void 0:le.email} for an email from privy.io and enter your code below.`:`Please check ${(U=i())==null?void 0:U.phoneNumber} for a message from ${(t==null?void 0:t.name)||"privy.io"} and enter your code below.`;return De(uo,{children:[B(L,{},"header"),De(ss,{children:[B(Ee,{title:ae,description:O}),De(Cr,{children:[De(as,{children:[B(ls,{fail:!!C,success:P,children:B("span",{children:C||(P?"Success!":"")})}),B("div",{children:m.map((y,A)=>B("input",{name:`code-${A}`,type:"text",value:m[A],onChange:G,onKeyUp:s=>{s.key==="Backspace"&&ye(A)},inputMode:"numeric",autoFocus:A===0,pattern:"[0-9]",className:`${P?"success":""} ${C?"fail":""}`,autoComplete:is?"one-time-code":"off"},A))})]}),B(cs,{children:x==0?De(uo,{children:[B("span",{children:"Didn't get an email?"}),B("button",{onClick:o,children:"Resend Code"})]}):De(uo,{children:[B("span",{children:"Didn't get a message?"}),B("button",{onClick:r,children:"Resend Code"})]})})]})]}),B(K,{protectedByPrivy:!0})]})},ss=Rt.div`
|
|
637
637
|
display: flex;
|
|
638
638
|
flex-direction: column;
|
|
639
639
|
align-items: flex-start;
|
|
640
640
|
justify-content: flex-end;
|
|
641
641
|
margin: auto;
|
|
642
642
|
gap: 16px;
|
|
643
|
-
`,
|
|
643
|
+
`,as=Rt.div`
|
|
644
644
|
display: flex;
|
|
645
645
|
flex-direction: column;
|
|
646
646
|
width: 100%;
|
|
@@ -708,7 +708,7 @@ Resources:
|
|
|
708
708
|
transform: translate(1px, 0px);
|
|
709
709
|
}
|
|
710
710
|
}
|
|
711
|
-
`,
|
|
711
|
+
`,ls=Rt.div`
|
|
712
712
|
line-height: 20px;
|
|
713
713
|
height: 20px;
|
|
714
714
|
font-size: 13px;
|
|
@@ -716,7 +716,7 @@ Resources:
|
|
|
716
716
|
display: flex;
|
|
717
717
|
justify-content: flex-end;
|
|
718
718
|
width: 100%;
|
|
719
|
-
`,
|
|
719
|
+
`,cs=Rt.div`
|
|
720
720
|
font-size: 13px;
|
|
721
721
|
color: var(--light-theme-fg-3);
|
|
722
722
|
display: flex;
|
|
@@ -730,7 +730,7 @@ Resources:
|
|
|
730
730
|
> button {
|
|
731
731
|
text-decoration: underline;
|
|
732
732
|
}
|
|
733
|
-
`;import Ot from"styled-components";import
|
|
733
|
+
`;import Ot from"styled-components";import ds from"styled-components";var Br=ds.span`
|
|
734
734
|
&& {
|
|
735
735
|
width: 82px;
|
|
736
736
|
height: 82px;
|
|
@@ -746,7 +746,7 @@ Resources:
|
|
|
746
746
|
border-color: var(--primary-color);
|
|
747
747
|
border-bottom-color: var(--primary-color);
|
|
748
748
|
}
|
|
749
|
-
`;import{jsx as zr}from"react/jsx-runtime";var $r=({style:t,...e})=>zr("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:zr("path",{"fill-rule":"evenodd",d:"M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z","clip-rule":"evenodd"})});import{Fragment as ho,jsx as q,jsxs as Nt}from"react/jsx-runtime";var Zr=()=>{let{navigate:t,app:e}=g(),o=(e==null?void 0:e.allowlistConfig.errorTitle)||"You don't have access to this app",r=(e==null?void 0:e.allowlistConfig.errorDetail)||"Have you been invited?",i=(e==null?void 0:e.allowlistConfig.errorCtaText)||"Try another account";return Nt(ho,{children:[q(L,{}),Nt(
|
|
749
|
+
`;import{jsx as zr}from"react/jsx-runtime";var $r=({style:t,...e})=>zr("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:"1.5",stroke:"currentColor",style:{height:"1.5rem",width:"1.5rem",...t},...e,children:zr("path",{"fill-rule":"evenodd",d:"M12 1.5a5.25 5.25 0 00-5.25 5.25v3a3 3 0 00-3 3v6.75a3 3 0 003 3h10.5a3 3 0 003-3v-6.75a3 3 0 00-3-3v-3c0-2.9-2.35-5.25-5.25-5.25zm3.75 8.25v-3a3.75 3.75 0 10-7.5 0v3h7.5z","clip-rule":"evenodd"})});import{Fragment as ho,jsx as q,jsxs as Nt}from"react/jsx-runtime";var Zr=()=>{let{navigate:t,app:e}=g(),o=(e==null?void 0:e.allowlistConfig.errorTitle)||"You don't have access to this app",r=(e==null?void 0:e.allowlistConfig.errorDetail)||"Have you been invited?",i=(e==null?void 0:e.allowlistConfig.errorCtaText)||"Try another account";return Nt(ho,{children:[q(L,{}),Nt(us,{children:[q(hs,{children:Nt("div",{children:[q(Br,{}),q($r,{style:{width:"38px",height:"38px",strokeWidth:"1",stroke:"var(--primary-color)",fill:"var(--primary-color)"}})]})}),Nt(ps,{children:[typeof o=="string"?q("h3",{children:o}):q(ho,{children:o}),typeof r=="string"?q("p",{children:r}):q(ho,{children:r})]}),e!=null&&e.allowlistConfig.errorCtaLink?q(jr,{as:"a",href:e.allowlistConfig.errorCtaLink,visible:!0,children:i}):q(jr,{onClick:()=>{t("LANDING")},visible:!0,children:i})]})]})},us=Ot.div`
|
|
750
750
|
display: flex;
|
|
751
751
|
flex-direction: column;
|
|
752
752
|
align-items: center;
|
|
@@ -754,11 +754,11 @@ Resources:
|
|
|
754
754
|
margin-left: 27px;
|
|
755
755
|
margin-right: 27px;
|
|
756
756
|
gap: 24px;
|
|
757
|
-
`,
|
|
757
|
+
`,ps=Ot.div`
|
|
758
758
|
display: flex;
|
|
759
759
|
flex-direction: column;
|
|
760
760
|
gap: 8px;
|
|
761
|
-
`,
|
|
761
|
+
`,hs=Ot.div`
|
|
762
762
|
display: flex;
|
|
763
763
|
flex-direction: column;
|
|
764
764
|
justify-content: center;
|
|
@@ -797,7 +797,7 @@ Resources:
|
|
|
797
797
|
background-color: var(--primary-color-bg-2);
|
|
798
798
|
}
|
|
799
799
|
}
|
|
800
|
-
`;import{useState as
|
|
800
|
+
`;import{useState as _s}from"react";import $ from"styled-components";import ms from"qrcode";import fs from"styled-components";import{Fragment as Ge,jsx as N,jsxs as Jr}from"react/jsx-runtime";var D=7,mo=(t,e,o,r,i)=>{for(let n=e;n<e+r;n++)for(let a=o;a<o+i;a++){let d=t==null?void 0:t[a];d&&d[n]&&(d[n]=0)}return t},gs=t=>{let e=ms.create(t,{errorCorrectionLevel:"high"}).modules,o=kr(Array.from(e.data),e.size);return o=mo(o,0,0,D,D),o=mo(o,o.length-D,0,D,D),o=mo(o,0,o.length-D,D,D),o},ws=({x:t,y:e,cellSize:o,bgColor:r,fgColor:i})=>N(Ge,{children:[0,1,2].map(n=>N("circle",{r:o*(D-n*2)/2,cx:t+o*D/2,cy:e+o*D/2,fill:n%2!==0?r:i},`finder-${t}-${e}-${n}`))}),ys=({cellSize:t,matrixSize:e,bgColor:o,fgColor:r})=>{let i=[[0,0],[(e-D)*t,0],[0,(e-D)*t]];return N(Ge,{children:i.map(([n,a])=>N(ws,{x:n,y:a,cellSize:t,bgColor:o,fgColor:r}))})},Cs=({matrix:t,cellSize:e,color:o})=>N(Ge,{children:t.map((r,i)=>r.map((n,a)=>n?N("circle",{r:e/2.5,cx:i*e+e/2,cy:a*e+e/2,fill:o},`circle-${i}-${a}`):N(Ge,{})))}),Kr=(t,e)=>t-t%e,vs=({outputSize:t,cellSize:e,element:o,size:r,padding:i,bgColor:n})=>{if(!o)return N(Ge,{});let a=r||40,d=i||4,m=o,p=t/2-a/2-d;return Jr(Ge,{children:[N("rect",{x:Kr(p,e),y:Kr(p,e),width:a+d*2+(p%e?e+.5:.5),height:a+d*2+(p%e?e+.5:.5),fill:n}),N(m,{x:t/2-a/2,y:t/2-a/2,height:a,width:a})]})},bs=t=>{var i;let e=t.outputSize,o=gs(t.url),r=e/o.length;return Jr("svg",{height:t.outputSize,width:t.outputSize,viewBox:`0 0 ${t.outputSize} ${t.outputSize}`,style:{height:"100%",width:"100%"},children:[N(Cs,{matrix:o,cellSize:r,color:t.fgColor}),N(ys,{cellSize:r,matrixSize:o.length,fgColor:t.fgColor,bgColor:t.bgColor}),N(vs,{outputSize:t.outputSize,cellSize:r,element:(i=t.logo)==null?void 0:i.element,bgColor:t.bgColor})]})},xs=fs.div`
|
|
801
801
|
display: flex;
|
|
802
802
|
justify-content: center;
|
|
803
803
|
align-items: center;
|
|
@@ -812,7 +812,7 @@ Resources:
|
|
|
812
812
|
border-color: ${t=>t.fgColor};
|
|
813
813
|
border-radius: 12px;
|
|
814
814
|
}
|
|
815
|
-
`,qr=t=>{let e=t.bgColor||"#FFFFFF",o=t.fgColor||"#000000",r=t.size||160;return N(
|
|
815
|
+
`,qr=t=>{let e=t.bgColor||"#FFFFFF",o=t.fgColor||"#000000",r=t.size||160;return N(xs,{size:r,bgColor:e,fgColor:o,children:N(bs,{url:t.url,logo:{element:t.squareLogoElement},outputSize:r,bgColor:e,fgColor:o})})};import{jsx as Ls}from"react/jsx-runtime";var Yr=({size:t})=>Ls(qr,{url:"https://coinbase-wallet.onelink.me/q5Sx/fdb9b250",squareLogoElement:pe,size:t,fgColor:"#1F1F1F"});import fo from"styled-components";import{jsx as Qr}from"react/jsx-runtime";var Xr=({style:t,...e})=>Qr("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",width:"17",height:"17",viewBox:"0 0 17 17",style:{height:"1.25rem",width:"1.25rem",...t},...e,children:Qr("path",{strokeLinecap:"round",strokeLinejoin:"round",fillRule:"evenodd",clipRule:"evenodd",d:"M16.5 8.67993C16.5 9.82986 15.853 10.8287 14.9032 11.3322C15.2188 12.3599 14.97 13.5237 14.1569 14.3368C13.3437 15.1499 12.18 15.3987 11.1523 15.0831C10.6488 16.0329 9.64993 16.6799 8.5 16.6799C7.35007 16.6799 6.35126 16.0329 5.84771 15.0831C4.82003 15.3987 3.65627 15.1499 2.84314 14.3368C2.03001 13.5237 1.78124 12.3599 2.09681 11.3322C1.14699 10.8287 0.5 9.82986 0.5 8.67993C0.5 7.53 1.14699 6.53119 2.0968 6.02764C1.78125 4.99996 2.03003 3.83621 2.84315 3.02309C3.65627 2.20997 4.82002 1.96119 5.8477 2.27675C6.35125 1.32692 7.35007 0.679932 8.5 0.679932C9.64992 0.679932 10.6487 1.32691 11.1523 2.27672C12.18 1.96115 13.3437 2.20993 14.1569 3.02305C14.97 3.83618 15.2188 4.99996 14.9032 6.02764C15.853 6.53119 16.5 7.53 16.5 8.67993ZM12.2659 6.68856C12.5654 6.40238 12.5761 5.92763 12.29 5.62818C12.0038 5.32873 11.529 5.31797 11.2296 5.60416C9.73022 7.03711 8.40877 8.65489 7.3018 10.4211L5.78033 8.89963C5.48744 8.60673 5.01256 8.60673 4.71967 8.89963C4.42678 9.19252 4.42678 9.66739 4.71967 9.96029L6.92031 12.1609C7.08544 12.3261 7.31807 12.4048 7.54957 12.374C7.78106 12.3432 7.98499 12.2064 8.1012 12.0038C9.23027 10.0356 10.6362 8.24613 12.2659 6.68856Z",fill:"var(--primary-color)"})});import{jsx as Es,jsxs as ks}from"react/jsx-runtime";var go=fo.div`
|
|
816
816
|
display: flex;
|
|
817
817
|
flex-direction: column;
|
|
818
818
|
justify-content: flex-start;
|
|
@@ -823,7 +823,7 @@ Resources:
|
|
|
823
823
|
border-left: 2px solid var(--border-color-2);
|
|
824
824
|
height: 12px;
|
|
825
825
|
}
|
|
826
|
-
`,ke=({children:t})=>
|
|
826
|
+
`,ke=({children:t})=>ks(As,{children:[Es(Xr,{style:{width:"16px",height:"16px"}}),t]}),As=fo.div`
|
|
827
827
|
display: flex;
|
|
828
828
|
justify-content: flex-start;
|
|
829
829
|
justify-items: center;
|
|
@@ -867,12 +867,12 @@ Resources:
|
|
|
867
867
|
background-color: var(--primary-color);
|
|
868
868
|
color: var(--light-theme-bg-1);
|
|
869
869
|
}
|
|
870
|
-
`,
|
|
870
|
+
`,du=wo(ti)`
|
|
871
871
|
&& {
|
|
872
872
|
border: 1px solid var(--light-theme-bg-3);
|
|
873
873
|
color: var(--light-theme-fg-1);
|
|
874
874
|
}
|
|
875
|
-
`;import{Fragment as yo,jsx as h,jsxs as R}from"react/jsx-runtime";var Co=()=>{let{navigate:t}=g(),e="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en";return ge.isFirefox&&(e="https://addons.mozilla.org/en-US/firefox/addon/ether-metamask/"),R(si,{children:[h(Ee,{title:"Create a Metamask wallet",description:"Follow the instructions below to get started."}),h(ai,{children:h(xe,{style:{width:"152px",height:"152px"}})}),R(go,{children:[h(ke,{children:R("div",{children:[h("span",{children:"Install the "}),h("a",{href:e,target:"_blank",children:"MetaMask browser extension"})]})}),h(tt,{}),h(ke,{children:"Set up your first wallet"}),h(tt,{}),h(ke,{children:"Store your recovery phrase in a safe place!"})]}),h(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},vo=()=>{let{navigate:t}=g();return R(si,{children:[h(Ee,{title:"Create a Coinbase wallet",description:"Follow the instructions below to get started."}),h(ai,{style:{marginTop:"-24px"},children:h(Yr,{size:200})}),R(go,{children:[h(ke,{children:"Scan the QR code with your camera"}),h(tt,{}),h(ke,{children:"Set up your first wallet"}),h(tt,{}),h(ke,{children:"Store your seed phrase in a safe place!"})]}),h(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},ni=()=>{let[t,e]=
|
|
875
|
+
`;import{Fragment as yo,jsx as h,jsxs as R}from"react/jsx-runtime";var Co=()=>{let{navigate:t}=g(),e="https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn?hl=en";return ge.isFirefox&&(e="https://addons.mozilla.org/en-US/firefox/addon/ether-metamask/"),R(si,{children:[h(Ee,{title:"Create a Metamask wallet",description:"Follow the instructions below to get started."}),h(ai,{children:h(xe,{style:{width:"152px",height:"152px"}})}),R(go,{children:[h(ke,{children:R("div",{children:[h("span",{children:"Install the "}),h("a",{href:e,target:"_blank",children:"MetaMask browser extension"})]})}),h(tt,{}),h(ke,{children:"Set up your first wallet"}),h(tt,{}),h(ke,{children:"Store your recovery phrase in a safe place!"})]}),h(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},vo=()=>{let{navigate:t}=g();return R(si,{children:[h(Ee,{title:"Create a Coinbase wallet",description:"Follow the instructions below to get started."}),h(ai,{style:{marginTop:"-24px"},children:h(Yr,{size:200})}),R(go,{children:[h(ke,{children:"Scan the QR code with your camera"}),h(tt,{}),h(ke,{children:"Set up your first wallet"}),h(tt,{}),h(ke,{children:"Store your seed phrase in a safe place!"})]}),h(li,{onClick:()=>t("LANDING"),children:"Done! I have my wallet"})]})},ni=()=>{let[t,e]=_s("WHAT_IS_A_WALLET"),{navigateBack:o}=g();return R(yo,{children:[h(L,{backFn:t==="WHAT_IS_A_WALLET"?o:t==="PICK_A_NEW_WALLET"?()=>e("WHAT_IS_A_WALLET"):()=>e("PICK_A_NEW_WALLET")},"header"),R(Ps,{children:[t==="WHAT_IS_A_WALLET"&&R(yo,{children:[h(Rs,{children:h(ei,{style:{width:"240px",height:"auto",borderRadius:"var(--border-radius-sm)",marginBottom:"32px"}})}),R(Fe,{title:"Get started with a new wallet",children:[h("p",{children:"Wallets help you store, send, and receive digital assets and collectibles. They are also a new\xA0way\xA0to\xA0log\xA0in."}),h("p",{children:"Instead of creating new accounts and passwords for every app, you just connect your wallet and bring your\xA0data\xA0with\xA0you."})]}),h(Ws,{children:h(Is,{onClick:()=>{e("PICK_A_NEW_WALLET")},children:"Create a wallet"})})]}),t==="PICK_A_NEW_WALLET"&&h(yo,{children:R(Ss,{children:[h(Ee,{title:"Create a new wallet",description:"Select one the wallet providers below to get started on your web3 adventure."}),R(Ts,{children:[R(ri,{onClick:()=>{ge.isIOS?window.location.href="https://apps.apple.com/us/app/metamask-blockchain-wallet/id1438144202":ge.isAndroid?window.location.href="https://play.google.com/store/apps/details?id=io.metamask":e("CREATE_METAMASK_WALLET")},children:[h(xe,{}),R(ii,{children:[h("h4",{children:"MetaMask"}),h("p",{children:"Get a browser-based wallet"})]}),h("div",{children:h("span",{children:"Set up"})})]}),R(ri,{onClick:()=>{ge.isIOS?window.location.href="https://apps.apple.com/us/app/coinbase-wallet-nfts-crypto/id1278383455":ge.isAndroid?window.location.href="https://play.google.com/store/apps/details?id=org.toshi":e("CREATE_COINBASE_WALLET")},children:[h(pe,{}),R(ii,{children:[h("h4",{children:"Coinbase Wallet"}),h("p",{children:"Get a mobile app wallet"})]}),h("div",{children:h("span",{children:"Set up"})})]})]})]})}),t==="CREATE_COINBASE_WALLET"&&h(vo,{}),t==="CREATE_METAMASK_WALLET"&&h(Co,{})]}),R(re,{children:[h("span",{children:"Still not sure? "}),h("a",{target:"_blank",href:"https://join.tell.ie/blog/explaining-web3-wallets",children:"Learn more"}),"."]})]})},Ps=$.div`
|
|
876
876
|
display: flex;
|
|
877
877
|
flex-direction: column;
|
|
878
878
|
height: 100%;
|
|
@@ -882,14 +882,14 @@ Resources:
|
|
|
882
882
|
display: none;
|
|
883
883
|
}
|
|
884
884
|
}
|
|
885
|
-
`,
|
|
885
|
+
`,Ss=$.div`
|
|
886
886
|
display: flex;
|
|
887
887
|
flex-direction: column;
|
|
888
888
|
align-items: flex-start;
|
|
889
889
|
justify-content: flex-start;
|
|
890
890
|
text-align: left;
|
|
891
891
|
gap: 20px;
|
|
892
|
-
`,
|
|
892
|
+
`,Ts=$.div`
|
|
893
893
|
display: flex;
|
|
894
894
|
flex-direction: column;
|
|
895
895
|
width: 100%;
|
|
@@ -958,13 +958,13 @@ Resources:
|
|
|
958
958
|
font-style: italic;
|
|
959
959
|
font-size: 12px;
|
|
960
960
|
}
|
|
961
|
-
`,
|
|
961
|
+
`,Ws=$.div`
|
|
962
962
|
margin-top: auto;
|
|
963
963
|
display: flex;
|
|
964
964
|
align-items: flex-end;
|
|
965
965
|
flex-grow: 1;
|
|
966
966
|
width: 100%;
|
|
967
|
-
`,
|
|
967
|
+
`,Is=$(oi)`
|
|
968
968
|
&& {
|
|
969
969
|
margin-top: 14px;
|
|
970
970
|
}
|
|
@@ -994,10 +994,10 @@ Resources:
|
|
|
994
994
|
background-color: var(--primary-color-bg-1);
|
|
995
995
|
border-radius: var(--border-radius-sm);
|
|
996
996
|
}
|
|
997
|
-
`,
|
|
997
|
+
`,Rs=$.div`
|
|
998
998
|
display: flex;
|
|
999
999
|
justify-content: center;
|
|
1000
|
-
`;import{useEffect as ci,useState as ot}from"react";import Dt from"styled-components";import{Fragment as
|
|
1000
|
+
`;import{useEffect as ci,useState as ot}from"react";import Dt from"styled-components";import{Fragment as Us,jsx as we,jsxs as Ft}from"react/jsx-runtime";var bo=2,di={metamask:{name:"MetaMask",component:xe},coinbase_wallet:{name:"Coinbase Wallet",component:pe},wallet_connect:{name:"WalletConnect",component:wt}},pi=()=>{var le;let[t,e]=ot(!1),[o,r]=ot("metamask"),[i,n]=ot(void 0),{navigate:a,navigateBack:d}=g(),{getAuthMeta:m,closePrivyModal:p,loginWithWallet:P}=E(),{walletConnectors:k}=I(),[C,b]=ot(0),{user:l}=I(),[v,x]=ot((l==null?void 0:l.linkedAccounts.length)||0);ci(()=>{var U;r(((U=m())==null?void 0:U.walletType)||"metamask"),n(void 0),P().then(()=>e(!0)).catch(y=>{y instanceof z?console.error(y.cause):console.error(y);let A=(y==null?void 0:y.status)===401&&(y==null?void 0:y.message)==="User is not allowed to login to this app.";(y==null?void 0:y.status)===422?n(lt.ERROR_USER_EXISTS):A?a("ALLOWLIST_REJECTION_SCREEN"):y instanceof Ie&&!y.details.default?n(y.details):y instanceof We?n(lt.ERROR_TIMED_OUT):n(lt.ERROR_WALLET_CONNECTION)})},[C]),ci(()=>{if(t){let U=setTimeout(p,Se);return()=>clearTimeout(U)}},[l]);let G=di[o].name,ye=di[o].component,ae=t?`Successfully connected with ${G}`:i?i.message:`Waiting for ${G}`,O="";if(t){let U=(l==null?void 0:l.linkedAccounts.length)||0;v===U?O="Wallet was already linked.":O="You\u2019re good to go!"}else if(C>=bo&&i)O="Unable to connect wallet";else if(i)O=i.detail;else switch(O="Don\u2019t see your wallet modal? Check your other browser windows.",o){case"metamask":O="For the best experience, connect only one wallet at a time.";break;case"wallet_connect":O="Open your mobile wallet app to continue";break;case"coinbase_wallet":mt()||(ft(l)?O="Continue with the Coinbase app. Not the right wallet? Reset your connection below.":O="Open the Coinbase app on your phone to continue.");break}let J=ft(l)?(le=k==null?void 0:k.walletConnectors)==null?void 0:le.find(U=>U.walletType==="coinbase_wallet"):null;return Ft(Us,{children:[we(L,{backFn:d}),Ft(Ms,{children:[we(Os,{children:Ft("div",{children:[we(kt,{success:t,fail:!!i}),we(ye,{style:{width:"38px",height:"38px"}})]})}),Ft(Ns,{children:[we("h3",{children:ae}),we("p",{children:O})]}),ft(l)?we(ui,{onClick:()=>J&&(J==null?void 0:J.disconnect()),visible:!t,disabled:t,children:"Use a different wallet"}):we(ui,{onClick:()=>{b(C+1),n(void 0)},visible:!t&&(i==null?void 0:i.retryable)&&C<bo,disabled:!t&&(!(i!=null&&i.retryable)||C>=bo),children:"Retry"})]})]})},Ms=Dt.div`
|
|
1001
1001
|
display: flex;
|
|
1002
1002
|
flex-direction: column;
|
|
1003
1003
|
align-items: center;
|
|
@@ -1005,11 +1005,11 @@ Resources:
|
|
|
1005
1005
|
margin-left: 27px;
|
|
1006
1006
|
margin-right: 27px;
|
|
1007
1007
|
gap: 24px;
|
|
1008
|
-
`,
|
|
1008
|
+
`,Ns=Dt.div`
|
|
1009
1009
|
display: flex;
|
|
1010
1010
|
flex-direction: column;
|
|
1011
1011
|
gap: 8px;
|
|
1012
|
-
`,
|
|
1012
|
+
`,Os=Dt.div`
|
|
1013
1013
|
display: flex;
|
|
1014
1014
|
flex-direction: column;
|
|
1015
1015
|
justify-content: center;
|
|
@@ -1044,7 +1044,7 @@ Resources:
|
|
|
1044
1044
|
opacity: ${t=>t.visible?"1":"0"};
|
|
1045
1045
|
transition: opacity 200ms;
|
|
1046
1046
|
}
|
|
1047
|
-
`;import{Fragment as
|
|
1047
|
+
`;import{Fragment as Fs,jsx as Gt,jsxs as hi}from"react/jsx-runtime";var mi=()=>{let{navigateBack:t}=g();return hi(Fs,{children:[Gt(L,{backFn:t},"header"),Gt(Co,{}),hi(re,{children:[Gt("span",{children:"Still not sure? "}),Gt("a",{target:"_blank",href:"https://join.tell.ie/blog/explaining-web3-wallets",children:"Learn more"})]})]})};import{Fragment as Ds,jsx as Ht,jsxs as fi}from"react/jsx-runtime";var gi=()=>{let{navigateBack:t}=g();return fi(Ds,{children:[Ht(L,{backFn:t},"header"),Ht(vo,{}),fi(re,{children:[Ht("span",{children:"Still not sure? "}),Ht("a",{target:"_blank",href:"https://join.tell.ie/blog/explaining-web3-wallets",children:"Learn more"})]})]})};import Gs from"styled-components";import{jsx as Vs}from"react/jsx-runtime";var wi=t=>{let e=t.accentColor||"#696ffd";return Vs(Hs,{accentColor:e,children:t.children})},Hs=Gs.div`
|
|
1048
1048
|
/*! Modified from https://unpkg.com/tailwindcss@3.2.3/src/css/preflight.css */
|
|
1049
1049
|
|
|
1050
1050
|
*,
|
|
@@ -1356,7 +1356,7 @@ Resources:
|
|
|
1356
1356
|
display: none;
|
|
1357
1357
|
}
|
|
1358
1358
|
}
|
|
1359
|
-
`;import{useEffect as
|
|
1359
|
+
`;import{useEffect as ta}from"react";import{useEffect as yi,useState as Ci}from"react";import Bt from"styled-components";import{Fragment as Ks,jsx as _e,jsxs as Vt}from"react/jsx-runtime";var vi={google:{name:"Google",component:At},discord:{name:"Discord",component:bt},github:{name:"Github",component:xt},twitter:{name:"Twitter",component:vt}},Bs=t=>t.charAt(0).toUpperCase()+t.slice(1),xo=()=>{let t=new URL(window.location.href);t.searchParams.delete("privy_oauth_code"),t.searchParams.delete("privy_oauth_provider"),t.searchParams.delete("privy_oauth_state"),window.history.pushState({},"",t)},bi=()=>{var l;let[t,e]=Ci(!1),[o,r]=Ci(void 0),{getAuthMeta:i,initLoginWithOAuth:n,loginWithOAuth:a,closePrivyModal:d}=E(),{ready:m}=I(),p=((l=i())==null?void 0:l.provider)||"google",P=vi[p].name,k=vi[p].component;yi(()=>{!m||a().then(()=>{xo(),e(!0)}).catch(v=>{let x={retryable:!1,message:"Authentication failed."};v.message.includes("Another user has already linked this")?x.detail="This account has already been linked to another user.":v.message==="Invalid code during oauth flow."?(x.retryable=!0,x.detail="Something went wrong. Try again."):v.message==="User denied confirmation during OAuth flow"&&(x.detail=`Retry and check ${Bs(p)} to finish connecting your account.`,x.retryable=!0),xo(),r(x)})},[m]),yi(()=>{if(!t)return;let v=setTimeout(d,Se);return()=>clearTimeout(v)},[t]);let C=t?`Successfully connected with ${P}`:o?o.message:`Verifying connection to ${P}`,b="";return t?b="You\u2019re good to go!":o?b=o.detail:b="Just a few moments more",Vt(Ks,{children:[_e(L,{}),Vt(zs,{children:[_e(js,{children:Vt("div",{children:[_e(kt,{success:t,fail:!!o}),_e(k,{style:{width:"38px",height:"38px"},logoFill:"primary"})]})}),Vt($s,{children:[_e("h3",{children:C}),_e("p",{children:b})]}),_e(Zs,{onClick:()=>{xo(),n(p),r(void 0)},visible:!t&&(o==null?void 0:o.retryable),disabled:!t&&!(o!=null&&o.retryable),children:"Retry"})]})]})},zs=Bt.div`
|
|
1360
1360
|
display: flex;
|
|
1361
1361
|
flex-direction: column;
|
|
1362
1362
|
align-items: center;
|
|
@@ -1364,11 +1364,11 @@ Resources:
|
|
|
1364
1364
|
margin-left: 27px;
|
|
1365
1365
|
margin-right: 27px;
|
|
1366
1366
|
gap: 24px;
|
|
1367
|
-
|
|
1367
|
+
`,$s=Bt.div`
|
|
1368
1368
|
display: flex;
|
|
1369
1369
|
flex-direction: column;
|
|
1370
1370
|
gap: 8px;
|
|
1371
|
-
|
|
1371
|
+
`,js=Bt.div`
|
|
1372
1372
|
display: flex;
|
|
1373
1373
|
flex-direction: column;
|
|
1374
1374
|
justify-content: center;
|
|
@@ -1391,7 +1391,7 @@ Resources:
|
|
|
1391
1391
|
left: -19px;
|
|
1392
1392
|
top: -19px;
|
|
1393
1393
|
}
|
|
1394
|
-
`,
|
|
1394
|
+
`,Zs=Bt.button`
|
|
1395
1395
|
&& {
|
|
1396
1396
|
padding: 12px 16px;
|
|
1397
1397
|
font-weight: 500;
|
|
@@ -1403,7 +1403,7 @@ Resources:
|
|
|
1403
1403
|
opacity: ${t=>t.visible?"1":"0"};
|
|
1404
1404
|
transition: opacity 200ms;
|
|
1405
1405
|
}
|
|
1406
|
-
`;import{Fragment as
|
|
1406
|
+
`;import{Fragment as qs,jsx as He,jsxs as Js}from"react/jsx-runtime";var xi=()=>{let{app:t}=g();return Js(qs,{children:[He(L,{},"header"),He(Fe,{title:"Connect your email",description:`Add your email to your ${t==null?void 0:t.name} account`,icon:He(Et,{})}),He(he,{children:He(Pt,{stacked:!0})}),He(K,{protectedByPrivy:!0})]})};import{Fragment as Ys,jsx as Ve,jsxs as Qs}from"react/jsx-runtime";var Li=()=>{let{app:t}=g();return Qs(Ys,{children:[Ve(L,{},"header"),Ve(Fe,{title:"Connect your phone",description:`Add your number to your ${t==null?void 0:t.name} account`,icon:Ve(St,{})}),Ve(he,{children:Ve(Tt,{stacked:!0})}),Ve(K,{protectedByPrivy:!0})]})};import{Fragment as Xs,jsx as rt,jsxs as Ai}from"react/jsx-runtime";var Ei=()=>{let{linkingHint:t}=E(),{app:e}=g(),o=t?`Select the wallet with ${_r(t)} and follow the instructions to reconnect your wallet${e!=null&&e.name?` to ${e.name}.`:"."}`:`Link a wallet to your ${e==null?void 0:e.name} account`;return Ai(Xs,{children:[rt(L,{},"header"),rt(Ur,{title:`${t?"Reconnect":"Connect"} your wallet`,description:o}),Ai(he,{children:[rt(yt,{}),rt(Ct,{})]}),rt(K,{protectedByPrivy:!0})]})};import{jsx as T,jsxs as ki}from"react/jsx-runtime";var oa=()=>{let{ready:t}=I(),{isLinking:e}=E(),{ready:o,currentScreen:r}=g(),i;return["AWAITING_CONNECTION","AWAITING_OAUTH_SCREEN","ALLOWLIST_REJECTION_SCREEN"].includes(r)?i="compact":"WALLET_EDUCATION"===r?i="full":e?i="medium":i="full",!t||!o?ki(Mt,{"data-height":i,children:[T(L,{}),T(na,{children:T(fe,{})}),T(re,{})]}):ki(Mt,{"data-height":i,children:[r==="LANDING"&&T(Mr,{}),r==="AWAITING_PASSWORDLESS_CODE"&&T(Vr,{}),r==="WALLET_EDUCATION"&&T(ni,{}),r==="AWAITING_CONNECTION"&&T(pi,{}),r==="AWAITING_OAUTH_SCREEN"&&T(bi,{}),r==="ALLOWLIST_REJECTION_SCREEN"&&T(Zr,{}),r==="INSTALL_METAMASK_SCREEN"&&T(mi,{}),r==="INSTALL_COINBASE_WALLET_SCREEN"&&T(gi,{}),r==="LINK_EMAIL_SCREEN"&&T(xi,{}),r==="LINK_PHONE_SCREEN"&&T(Li,{}),r==="LINK_WALLET_SCREEN"&&T(Ei,{})]})},_i=()=>{let{app:t}=g();return ea.createPortal(T(ia,{id:"privy-dialog",children:T(wi,{accentColor:t==null?void 0:t.accentColor,children:T(oa,{})})}),document.body)},ra=({children:t,...e})=>(ta(()=>{var r;(r=document==null?void 0:document.activeElement)==null||r.blur();let o=(document==null?void 0:document.getElementById("root"))||(document==null?void 0:document.getElementById("__next"));if(!!o)return o.setAttribute("inert","true"),()=>{let i=(document==null?void 0:document.getElementById("root"))||(document==null?void 0:document.getElementById("__next"));!i||i.removeAttribute("inert")}},[e.open,e.onClose]),T("dialog",{open:!0,role:"dialog",...e,children:t})),ia=Lo(ra)`
|
|
1407
1407
|
position: fixed;
|
|
1408
1408
|
top: 0;
|
|
1409
1409
|
left: 0;
|
|
@@ -1456,10 +1456,10 @@ Resources:
|
|
|
1456
1456
|
min-height: 0;
|
|
1457
1457
|
}
|
|
1458
1458
|
}
|
|
1459
|
-
`,
|
|
1459
|
+
`,na=Lo.div`
|
|
1460
1460
|
display: flex;
|
|
1461
1461
|
flex-direction: column;
|
|
1462
1462
|
align-items: center;
|
|
1463
1463
|
justify-content: center;
|
|
1464
1464
|
height: 100%;
|
|
1465
|
-
`;import{jsx as zt,jsxs as
|
|
1465
|
+
`;import{jsx as zt,jsxs as pa}from"react/jsx-runtime";function aa(t){return typeof t=="string"&&t.length===25}var it;function la(){if(!it){let t=M.get(Te);return Promise.resolve(t||null)}return it.getAccessToken()}var ca=t=>{if(!aa(t.appId))throw new u("Cannot initialize the Privy provider with an invalid Privy app ID");return it||(it=new Ze({appId:t.appId,apiURL:Po})),zt(ua,{...t,client:it})},da=(t,e)=>{if(e)return{email:!1,sms:!1,wallet:!1,google:!1,twitter:!1,discord:!1,github:!1,[e]:!0};let o=!!(t!=null&&t.emailAuth),r=!!(t!=null&&t.smsAuth);return o&&r&&(console.warn("Enabling both email and SMS passwordless is not currently supported. Disabling SMS."),r=!1),{email:o,sms:r,wallet:!!(t!=null&&t.walletAuth),google:!!(t!=null&&t.googleOAuth),twitter:!!(t!=null&&t.twitterOAuth),discord:!!(t!=null&&t.discordOAuth),github:!!(t!=null&&t.githubOAuth)}},ua=t=>{let e=t.client,[o,r]=se(!1),[i,n]=se(!1),[a,d]=se(!1),[m,p]=se(null),[P,k]=se(!1),[C,b]=se({accentColor:"#696ffd",theme:"System",showWalletLoginFirst:!0,allowlistConfig:{errorTitle:null,errorDetail:null,errorCtaText:null,errorCtaLink:null},walletAuth:!0,emailAuth:!0,smsAuth:!1,googleOAuth:!1,twitterOAuth:!1,discordOAuth:!1,githubOAuth:!1,termsAndConditionsUrl:null,privacyPolicyUrl:null}),[l,v]=se(null),[x,G]=se(!1),[ye,ae]=se(null),O=da(C,l);Pi(()=>{async function s(){let c=await e.getAppSettings();b(c),e.connectors.initialize(),J();let H=await e.getAuthenticatedUser();d(!!H),p(H),n(!0)}s()},[e]);let J=()=>{let s=new URLSearchParams(window.location.search),c=s.get("privy_oauth_code"),H=s.get("privy_oauth_state"),Be=s.get("privy_oauth_provider");c&&H&&Be&&(e.startAuthFlow(new Re(Be,c,H)),v(Be),r(!0))};Pi(()=>{i&&a&&m===null&&e.getAuthenticatedUser().then(p)},[i,a,m,e]);let le=()=>{v("wallet"),G(!0),r(!0)},U={ready:i,authenticated:a,user:m,walletConnectors:e.connectors,linkWallet:le,linkEmail:()=>{v("email"),G(!0),r(!0)},linkPhone:()=>{v("sms"),G(!0),r(!0)},linkGoogle:async()=>{await A.initLoginWithOAuth("google")},linkTwitter:async()=>{await A.initLoginWithOAuth("twitter")},linkDiscord:async()=>{await A.initLoginWithOAuth("discord")},linkGithub:async()=>{await A.initLoginWithOAuth("github")},login:()=>{if(i&&a){console.warn("Attempted to log in, but user is already logged in. Use a `link` helper instead.");return}r(!0)},logout:async()=>{await e.logout(),p(null),d(!1),v(null),G(!1),r(!1)},getAccessToken:()=>e.getAccessToken(),getEthereumProvider:()=>e.connectors.getEthereumProvider(),getEthersProvider:()=>new sa(new ve(e.connectors.getEthereumProvider())),getWeb3jsProvider:()=>new ct(e.connectors.getEthereumProvider()),unlinkWallet:async s=>{let c=await e.unlinkWallet(s);return p(c),c},unlinkEmail:async s=>{let c=await e.unlinkEmail(s);return p(c),c},unlinkPhone:async s=>{let c=await e.unlinkPhone(s);return p(c),c},unlinkGoogle:async s=>{let c=await e.unlinkOAuth("google",s);return p(c),c},unlinkTwitter:async s=>{let c=await e.unlinkOAuth("twitter",s);return p(c),c},unlinkDiscord:async s=>{let c=await e.unlinkOAuth("discord",s);return p(c),c},unlinkGithub:async s=>{let c=await e.unlinkOAuth("github",s);return p(c),c},setActiveWallet:s=>{if(!!m)try{let c=e.setActiveWallet(s,m);p(c)}catch(c){c instanceof u&&c.message==="Error setting the active wallet."&&(ae(s),le())}},forkSession:()=>e.forkSession()},A=(()=>({isLinking:x,linkingHint:ye,getAuthFlow:()=>e.authFlow,getAuthMeta:()=>{var s;return(s=e.authFlow)==null?void 0:s.meta},closePrivyModal:()=>{var s;i&&a&&m&&((s=t.onSuccess)==null||s.call(t,m,P)),e.authFlow=void 0,v(null),ae(null),G(!1),k(!1),r(!1)},initLoginWithWallet:s=>{if(!e.connectors)throw new u("Connector not initialized");s||(s="metamask"),e.startAuthFlow(new Ke(e.connectors,s))},loginWithWallet:async()=>{if(!(e.authFlow instanceof Ke))throw new u("Must initialize SIWE flow first.");let s,c;x?(s=await e.link(),s&&(s=je(s))):{user:s,isNewUser:c}=await e.authenticate(),p(s||m||null),k(c||!1),d(!0)},initLoginWithOAuth:async s=>{e.startAuthFlow(new Re(s));let c=await e.authFlow.getAuthorizationUrl();c&&c.url&&window.location.assign(c.url)},loginWithOAuth:async()=>{if(!(e.authFlow instanceof Re))throw new u("Must initialize OAuth flow before calling loginWithOAuth");let s,c;i&&a?s=await e.link():{user:s,isNewUser:c}=await e.authenticate(),p(s),k(c||!1),d(!0)},initLoginWithEmail:async s=>{let c=new qe(s);e.startAuthFlow(c),await c.sendCodeEmail()},initLoginWithSms:async s=>{let c=new Je(s);e.startAuthFlow(c),await c.sendSmsCode()},resendEmailCode:async()=>{var s;await((s=e.authFlow)==null?void 0:s.sendCodeEmail())},resendSmsCode:async()=>{var s;await((s=e.authFlow)==null?void 0:s.sendSmsCode())},loginWithCode:async s=>{if(e.authFlow instanceof qe)e.authFlow.meta.emailCode=s.trim();else if(e.authFlow instanceof Je)e.authFlow.meta.smsCode=s.trim();else throw new u("Must initialize a passwordless code flow first");let c,H;x?c=await e.link():{user:c,isNewUser:H}=await e.authenticate(),p(c||m||null),k(H||!1),d(!0)}}))();return pa(to.Provider,{value:U,children:[t.children,zt(oo.Provider,{value:A,children:zt(rr,{appSettings:C,options:O,visible:o,authenticated:a,children:o&&zt(_i,{})})})]})};export{ve as AsExternalProvider,$e as ConnectorManager,Ze as PrivyClient,ca as PrivyProvider,Z as PrivyProxyProvider,jt as VERSION,Q as WalletConnector,la as getAccessToken,I as usePrivy};
|