UNPKG

@dynamic-labs/sdk-react-core

Version:

A React SDK for implementing wallet web3 authentication and authorization to your website.

44 lines (39 loc) 2 kB
'use client' 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var React = require('react'); const VerificationContext = React.createContext(undefined); // Context used to hold verificationUUID & email between views. const VerificationProvider = ({ children }) => { const [displayedDestination, setDisplayedDestination] = React.useState(undefined); const [verificationUUID, setVerificationUUID] = React.useState(undefined); const [retryData, setRetryData] = React.useState(undefined); /** Update retryData state only if the new data is different from the current retryData */ const externalSetRetryData = React.useCallback((data) => { setRetryData((prev) => (data === null || data === void 0 ? void 0 : data.phone) === (prev === null || prev === void 0 ? void 0 : prev.phone) && (data === null || data === void 0 ? void 0 : data.iso2) === (prev === null || prev === void 0 ? void 0 : prev.iso2) && (data === null || data === void 0 ? void 0 : data.dialCode) === (prev === null || prev === void 0 ? void 0 : prev.dialCode) ? prev : data); }, []); const value = React.useMemo(() => ({ displayedDestination, retryData, setDisplayedDestination, setRetryData: externalSetRetryData, setVerificationUUID, verificationUUID, }), [displayedDestination, retryData, verificationUUID, externalSetRetryData]); return (jsxRuntime.jsx(VerificationContext.Provider, { value: value, children: children })); }; const useVerification = () => { const context = React.useContext(VerificationContext); if (context === undefined) { throw new Error('usage of useVerification not wrapped in `VerificationProvider`.'); } return context; }; exports.VerificationContext = VerificationContext; exports.VerificationProvider = VerificationProvider; exports.useVerification = useVerification;