@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 1.53 kB
JavaScript
;var e=require("react");const o=/*#__PURE__*/e.createContext(void 0);let n=()=>e.useContext(o);function t(e,o,n,...t){for(let r of e.current[o][n])r(...t)}exports.PrivyEventsContext=o,exports.emitPrivyEvent=t,exports.privyEventsDefault={login:{onComplete:[],onError:[]},logout:{onSuccess:[]},connectWallet:{onSuccess:[],onError:[]},connectOrCreateWallet:{onSuccess:[],onError:[]},createWallet:{onSuccess:[],onError:[]},linkAccount:{onSuccess:[],onError:[]},update:{onSuccess:[],onError:[]},configureMfa:{onMfaRequired:[]},setWalletPassword:{onSuccess:[],onError:[]},setWalletRecovery:{onSuccess:[],onError:[]},signMessage:{onSuccess:[],onError:[]},signTypedData:{onSuccess:[],onError:[]},sendTransaction:{onSuccess:[],onError:[]},signTransaction:{onSuccess:[],onError:[]},accessToken:{onAccessTokenGranted:[],onAccessTokenRemoved:[]},oAuthAuthorization:{onOAuthTokenGrant:[]},fundWallet:{onUserExited:[]},fundSolanaWallet:{onUserExited:[]},customAuth:{onAuthenticated:[],onUnauthenticated:[]}},exports.useEmitPrivyEvent=function(){let e=n();return(o,n,...r)=>t(e,o,n,...r)},exports.usePrivyEventSubscription=function(o,t){if(!t)return;let r=n().current[o];return e.useEffect((()=>{for(let[e,n]of Object.entries(t))Object.prototype.hasOwnProperty.call(r,e)||console.warn(`Invalid event type "${e}" for action "${o}"`),r[e]?.push(n);return()=>{for(let[e,n]of Object.entries(t))Object.prototype.hasOwnProperty.call(r,e)||console.warn(`Invalid event type "${e}" for action "${o}"`),r[e]=r[e]?.filter((e=>e!==n))}}),[t])};