@pushchain/ui-kit
Version:
Push Chain is a true universal L1 that is 100% EVM compatible. It allows developers to deploy once and make their apps instantly compatible with users from all other L1s (Ethereum, Solana, etc) with zero on-chain code change.
91 lines • 3.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PushUniversalWalletProvider = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
/* eslint-disable @typescript-eslint/ban-ts-comment */
const react_1 = require("react");
const WalletContext_1 = require("../context/WalletContext");
const constants_1 = require("../constants");
const styled_components_1 = require("styled-components");
const token_1 = require("../styles/token");
const theme_1 = require("../utils/theme");
const eip6963_1 = require("./walletProviders/utils/eip6963");
const initWaap_1 = require("./waap/initWaap");
const loginDefaultConfig = {
email: true,
google: true,
phone: true,
socials: {
discord: true,
github: true,
x: true,
bluesky: true,
},
wallet: {
enabled: true,
},
};
const PushWalletConfigDefault = {
uid: 'default',
login: loginDefaultConfig,
network: constants_1.PushUI.CONSTANTS.PUSH_NETWORK.TESTNET_DONUT,
modal: {
loginLayout: constants_1.PushUI.CONSTANTS.LOGIN.LAYOUT.SIMPLE,
appPreview: false,
connectedInteraction: constants_1.PushUI.CONSTANTS.CONNECTED.INTERACTION.BLUR,
connectedLayout: constants_1.PushUI.CONSTANTS.CONNECTED.LAYOUT.HOVER,
},
};
const GlobalStyle = (0, styled_components_1.createGlobalStyle) `
w3m-modal {
z-index: 1000000000 !important;
}
`;
const buildCssVars = (themeMode, themeOverrides) => {
const isLightMode = themeMode === constants_1.PushUI.CONSTANTS.THEME.LIGHT;
const { dark, light, ...globalOverrides } = themeOverrides;
const newOverrides = {
...token_1.themeDefault,
...token_1.buttonThemeDefault,
...(isLightMode ? token_1.lightThemeDefault : token_1.darkThemeDefault),
...(0, theme_1.mapCoreToInt)(globalOverrides),
...(0, theme_1.mapCoreToInt)((isLightMode ? light : dark) ?? {}),
};
const cssVars = {};
for (const [key, value] of Object.entries(newOverrides)) {
if (value !== undefined && value !== null && value !== '') {
cssVars[key] = String(value);
}
}
return cssVars;
};
const PushUniversalWalletProvider = ({ config, app, themeMode = constants_1.PushUI.CONSTANTS.THEME.LIGHT, themeOverrides = {}, children, }) => {
const mergedConfig = {
...PushWalletConfigDefault,
...config,
login: {
...loginDefaultConfig,
...(config?.login || {}),
socials: {
...loginDefaultConfig.socials,
...(config?.login?.socials || {}),
},
wallet: {
...loginDefaultConfig.wallet,
...(config?.login?.wallet || {}),
},
},
modal: {
...PushWalletConfigDefault.modal,
...config.modal,
},
};
(0, react_1.useEffect)(() => {
(0, eip6963_1.startEIP6963Listener)();
(0, initWaap_1.ensureWaapInit)(themeMode === constants_1.PushUI.CONSTANTS.THEME.DARK, mergedConfig.login || {});
}, []);
const wrapperStyle = (0, react_1.useMemo)(() => buildCssVars(themeMode, themeOverrides), [themeMode, themeOverrides]);
return ((0, jsx_runtime_1.jsxs)(styled_components_1.ThemeProvider, { theme: { themeMode, themeOverrides }, children: [(0, jsx_runtime_1.jsx)(GlobalStyle, { uid: mergedConfig.uid }), (0, jsx_runtime_1.jsx)("div", { "data-pw-wrapper": mergedConfig.uid, style: wrapperStyle, children: (0, jsx_runtime_1.jsx)(WalletContext_1.WalletContextProvider, { config: mergedConfig, app: app, themeMode: themeMode, themeOverrides: themeOverrides, children: children }) })] }));
};
exports.PushUniversalWalletProvider = PushUniversalWalletProvider;
//# sourceMappingURL=PushWalletProvider.js.map