UNPKG

@dynamic-labs/sdk-react-core

Version:

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

38 lines (35 loc) 1.84 kB
'use client' import { jsx } from 'react/jsx-runtime'; import { createContext, useContext, useState, useCallback, useMemo } from 'react'; const VerificationContext = createContext(undefined); // Context used to hold verificationUUID & email between views. const VerificationProvider = ({ children }) => { const [displayedDestination, setDisplayedDestination] = useState(undefined); const [verificationUUID, setVerificationUUID] = useState(undefined); const [retryData, setRetryData] = useState(undefined); /** Update retryData state only if the new data is different from the current retryData */ const externalSetRetryData = 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 = useMemo(() => ({ displayedDestination, retryData, setDisplayedDestination, setRetryData: externalSetRetryData, setVerificationUUID, verificationUUID, }), [displayedDestination, retryData, verificationUUID, externalSetRetryData]); return (jsx(VerificationContext.Provider, { value: value, children: children })); }; const useVerification = () => { const context = useContext(VerificationContext); if (context === undefined) { throw new Error('usage of useVerification not wrapped in `VerificationProvider`.'); } return context; }; export { VerificationContext, VerificationProvider, useVerification };