@lifi/wallet-management
Version:
LI.FI Wallet Management solution.
34 lines • 1.63 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback, useMemo, useRef, useState } from 'react';
import { WalletMenuContent } from '../../components/WalletMenuContent.js';
import { WalletMenuModal } from '../../components/WalletMenuModal.js';
import { I18nProvider } from '../I18nProvider/I18nProvider.js';
import { useWalletManagementConfig } from '../WalletManagementProvider/WalletManagementContext.js';
import { WalletMenuContext } from './WalletMenuContext.js';
export const WalletMenuProvider = ({ children, }) => {
const { locale } = useWalletManagementConfig();
const openRef = useRef(false);
const [open, setOpen] = useState(false);
const toggleWalletMenu = useCallback(() => {
setOpen((open) => {
openRef.current = !open;
return openRef.current;
});
}, []);
const openWalletMenu = useCallback(() => {
setOpen(true);
openRef.current = true;
}, []);
const closeWalletMenu = useCallback(() => {
setOpen(false);
openRef.current = false;
}, []);
const context = useMemo(() => ({
isWalletMenuOpen: () => openRef.current,
toggleWalletMenu,
openWalletMenu,
closeWalletMenu,
}), [closeWalletMenu, openWalletMenu, toggleWalletMenu]);
return (_jsxs(WalletMenuContext.Provider, { value: context, children: [children, _jsx(I18nProvider, { locale: locale, children: _jsx(WalletMenuModal, { open: open, onClose: closeWalletMenu, children: _jsx(WalletMenuContent, { onClose: closeWalletMenu }) }) })] }));
};
//# sourceMappingURL=WalletMenuProvider.js.map