UNPKG

@particle-network/connectkit

Version:
8 lines (7 loc) 12.1 kB
{ "version": 3, "sources": ["../../../../src/utils/theme.ts", "../../../../src/utils/deepEqual.ts", "../../../../src/context/index.tsx", "../../../../src/hooks/useAppearance.ts", "../../../../src/hooks/useIconColor.ts", "../../../../src/assets/social/phone.tsx"], "sourcesContent": ["export function getSystemMode() {\n if (typeof window !== 'undefined' && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {\n return 'dark';\n } else {\n return 'light';\n }\n}\n", "/** Forked from https://github.com/epoberezkin/fast-deep-equal */\n\nexport function deepEqual(a: any, b: any) {\n if (a === b) return true;\n\n if (a && b && typeof a === 'object' && typeof b === 'object') {\n if (a.constructor !== b.constructor) return false;\n\n let length: number;\n let i: number;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n length = a.length;\n if (length !== b.length) return false;\n for (i = length; i-- !== 0; ) if (!deepEqual(a[i], b[i])) return false;\n return true;\n }\n\n if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();\n if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();\n\n const keys = Object.keys(a);\n length = keys.length;\n if (length !== Object.keys(b).length) return false;\n\n for (i = length; i-- !== 0; ) if (!Object.prototype.hasOwnProperty.call(b, keys[i]!)) return false;\n\n for (i = length; i-- !== 0; ) {\n const key = keys[i];\n\n if (key && !deepEqual(a[key], b[key])) return false;\n }\n\n return true;\n }\n\n // true if both NaN, false otherwise\n // biome-ignore lint/suspicious/noSelfCompare: <explanation>\n return a !== a && b !== b;\n}\n", "import type { AAPlugin } from '@particle-network/aa-plugin';\nimport React, { createContext, useMemo, type ReactNode } from 'react';\nimport ConnectModal from '../components/connectModal';\nimport { type Config } from '../createConfig';\nimport { useAppearance } from '../hooks/useAppearance';\nimport { getAuthCoreTheme } from '../styles';\nimport type { AuthWalletConnectorProperties } from '../types/properties';\nimport { getSystemMode } from '../utils/theme';\nimport { ModalProvider } from './modalProvider';\nimport type { ConnectKitOptions } from './types';\nimport { Web3Provder } from './web3Provider';\n\ntype ContextValue = {\n options: ConnectKitOptions;\n config: Config;\n};\n\nexport const Context = createContext<ContextValue | null>(null);\n\nexport type ConnectKitProviderProps = {\n children?: ReactNode;\n config: Config;\n reconnectOnMount?: boolean | undefined;\n};\n\nexport const ConnectKitProvider = (parameters: ConnectKitProviderProps): React.ReactElement => {\n // Only allow for mounting ConnectKitProvider once, so we avoid weird global\n // state collisions.\n if (React.useContext(Context)) {\n throw new Error('Multiple, nested usages of ConnectKitProvider detected. Please use only one.');\n }\n\n const { children, config, reconnectOnMount = true } = parameters;\n const { appearance } = useAppearance(config);\n\n const { AuthCoreContextProvider, authOptions } = useMemo(() => {\n const authWalletConnector = config.getWalletConnector<AuthWalletConnectorProperties>('particleAuth');\n const aaPlugin = config.plugins.find((plugin) => plugin.id === 'aa') as AAPlugin;\n const erc4337 = aaPlugin ? aaPlugin.erc4337 : undefined;\n\n let theme = appearance?.mode ?? getSystemMode();\n if (theme === 'auto') {\n theme = getSystemMode();\n }\n\n return {\n AuthCoreContextProvider: authWalletConnector?.AuthCoreContextProvider ?? React.Fragment,\n authOptions: authWalletConnector\n ? {\n options: {\n themeType: theme,\n ...authWalletConnector.authOptions,\n customStyle: {\n ...authWalletConnector.authOptions?.customStyle,\n theme: {\n [theme as string]: getAuthCoreTheme(appearance),\n },\n },\n erc4337,\n },\n }\n : undefined,\n };\n }, [config, appearance]);\n\n return (\n <Context.Provider\n value={{\n options: config.options,\n config,\n }}\n >\n <AuthCoreContextProvider {...authOptions}>\n <Web3Provder>\n {children}\n <ModalProvider reconnectOnMount={reconnectOnMount}>\n <ConnectModal />\n </ModalProvider>\n </Web3Provder>\n </AuthCoreContextProvider>\n </Context.Provider>\n );\n};\n\nexport const useContext = () => {\n const context = React.useContext(Context);\n if (!context) throw Error('ConnectKit Hook must be inside a Provider.');\n return context;\n};\n", "import { useCallback, useSyncExternalStore } from 'react';\nimport { useContext } from '../context';\nimport type { Appearance } from '../context/types';\nimport type { Config } from '../createConfig';\nimport { deepEqual } from '../utils/deepEqual';\n\nexport type UseAppearanceReturnType = {\n appearance: Appearance;\n setAppearance: (value?: Appearance) => void;\n};\n\nexport type WatchAppearanceParameters = {\n onChange(appearance: Appearance, prevAppearance: Appearance): void;\n};\n\nlet previousAppearance: Appearance = {};\n\nexport function getAppearance(config: Config) {\n const appearance = { ...config.appearanceStore.getState() };\n if (deepEqual(previousAppearance, appearance)) return previousAppearance;\n\n previousAppearance = appearance;\n return appearance;\n}\n\nexport function useAppearance(config?: Config): UseAppearanceReturnType {\n if (!config) {\n // eslint-disable-next-line react-hooks/rules-of-hooks\n const { config: globalConfig } = useContext();\n config = globalConfig;\n }\n\n const setAppearance = useCallback(\n (value?: Appearance) => {\n config.appearanceStore.setState(value || {}, true);\n },\n [config.appearanceStore]\n );\n\n const appearance = useSyncExternalStore(\n config.appearanceStore.subscribe,\n () => getAppearance(config),\n () => getAppearance(config)\n );\n\n return {\n appearance,\n setAppearance,\n };\n}\n", "import { useEffect, useMemo, useState } from 'react';\nimport { getSystemMode } from '../utils/theme';\nimport { useAppearance } from './useAppearance';\n\nconst useIconColor = () => {\n const [currentMode, setCurrentMode] = useState<'light' | 'dark'>();\n const { appearance } = useAppearance();\n\n useEffect(() => {\n if (appearance?.mode && appearance?.mode !== 'auto') {\n setCurrentMode(appearance?.mode);\n } else {\n setCurrentMode(getSystemMode());\n }\n }, [appearance?.mode]);\n\n const foreground = useMemo(() => {\n if (currentMode === 'dark') {\n return '#000000';\n } else {\n return '#ffffff';\n }\n }, [currentMode]);\n\n const background = useMemo(() => {\n if (currentMode === 'dark') {\n return '#ffffff';\n } else {\n return '#000000';\n }\n }, [currentMode]);\n\n return { foreground, background, currentMode };\n};\n\nexport default useIconColor;\n", "import useIconColor from '../../hooks/useIconColor';\n\nconst Phone = () => {\n const { background } = useIconColor();\n\n return (\n <svg width='24' height='24' viewBox='0 0 24 24' fill='none' xmlns='http://www.w3.org/2000/svg'>\n <path\n d='M19.2575 19.772C19.2575 20.158 19.1785 20.5171 19.0206 20.8492C18.8628 21.1812 18.6458 21.4746 18.3696 21.7294C18.0933 21.9843 17.7697 22.185 17.3987 22.3317C17.0277 22.4785 16.6292 22.5518 16.2029 22.5518H7.79705C7.37086 22.5518 6.97228 22.4785 6.6013 22.3317C6.23035 22.185 5.90674 21.9843 5.6305 21.7294C5.35423 21.4746 5.1372 21.1812 4.97935 20.8492C4.82147 20.5171 4.74255 20.158 4.74255 19.772V4.25124C4.74255 3.86515 4.82147 3.50223 4.97935 3.16248C5.1372 2.82271 5.35423 2.52543 5.6305 2.27061C5.90674 2.01579 6.23035 1.81503 6.6013 1.66831C6.97228 1.5216 7.37086 1.44824 7.79705 1.44824H16.2029C16.6292 1.44824 17.0277 1.5216 17.3987 1.66831C17.7697 1.81503 18.0933 2.01579 18.3696 2.27061C18.6458 2.52543 18.8628 2.82271 19.0206 3.16248C19.1785 3.50223 19.2575 3.86515 19.2575 4.25124V19.772ZM17.3395 5.36317H6.63683V18.6368H17.3395V5.36317ZM11.9882 19.2855C11.6567 19.2855 11.3686 19.4013 11.1239 19.633C10.8792 19.8646 10.7569 20.1504 10.7569 20.4901C10.7569 20.8144 10.8792 21.0963 11.1239 21.3356C11.3686 21.575 11.6567 21.6947 11.9882 21.6947C12.3354 21.6947 12.6275 21.575 12.8643 21.3356C13.101 21.0963 13.2195 20.8144 13.2195 20.4901C13.2195 20.1504 13.101 19.8646 12.8643 19.633C12.6275 19.4013 12.3354 19.2855 11.9882 19.2855ZM13.8824 3.39413C13.8824 3.27058 13.843 3.17406 13.764 3.10455C13.6851 3.03506 13.5983 3.00032 13.5036 3.00032H10.4964C10.4175 3.00032 10.3346 3.03506 10.2478 3.10455C10.161 3.17406 10.1176 3.27058 10.1176 3.39413C10.1176 3.51768 10.157 3.61419 10.236 3.68369C10.3149 3.75318 10.4017 3.78794 10.4964 3.78794H13.5036C13.5983 3.78794 13.6851 3.75318 13.764 3.68369C13.843 3.61419 13.8824 3.51768 13.8824 3.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