@rhinestone/deposit-modal 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,90 @@
1
+ // src/core/reown.tsx
2
+ import { useState } from "react";
3
+ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
4
+ import { WagmiAdapter } from "@reown/appkit-adapter-wagmi";
5
+ import { WagmiProvider } from "wagmi";
6
+ import { createAppKit, useAppKit, useAppKitAccount } from "@reown/appkit/react";
7
+ import {
8
+ mainnet,
9
+ base,
10
+ arbitrum,
11
+ optimism,
12
+ polygon,
13
+ bsc
14
+ } from "@reown/appkit/networks";
15
+ import { useWalletClient, usePublicClient, useSwitchChain } from "wagmi";
16
+ import { jsx } from "react/jsx-runtime";
17
+ var NETWORKS = [
18
+ mainnet,
19
+ base,
20
+ arbitrum,
21
+ optimism,
22
+ polygon,
23
+ bsc
24
+ ];
25
+ var cachedAdapter = null;
26
+ var cachedProjectId = null;
27
+ function mapTheme(theme) {
28
+ const themeMode = theme?.mode === "light" ? "light" : "dark";
29
+ const themeVariables = {};
30
+ if (theme?.ctaColor) {
31
+ themeVariables["--apkt-accent"] = theme.ctaColor;
32
+ }
33
+ return { themeMode, themeVariables };
34
+ }
35
+ function getOrCreateAdapter(projectId, theme) {
36
+ if (cachedAdapter && cachedProjectId === projectId) return cachedAdapter;
37
+ cachedAdapter = new WagmiAdapter({
38
+ networks: NETWORKS,
39
+ projectId
40
+ });
41
+ cachedProjectId = projectId;
42
+ const { themeMode, themeVariables } = mapTheme(theme);
43
+ createAppKit({
44
+ adapters: [cachedAdapter],
45
+ networks: NETWORKS,
46
+ projectId,
47
+ themeMode,
48
+ themeVariables,
49
+ features: {
50
+ connectMethodsOrder: ["wallet"],
51
+ email: false,
52
+ socials: false
53
+ }
54
+ });
55
+ return cachedAdapter;
56
+ }
57
+ function ReownWalletProvider({
58
+ projectId,
59
+ theme,
60
+ children
61
+ }) {
62
+ const [queryClient] = useState(() => new QueryClient());
63
+ const adapter = getOrCreateAdapter(projectId, theme);
64
+ const config = adapter.wagmiConfig;
65
+ return /* @__PURE__ */ jsx(WagmiProvider, { config, children: /* @__PURE__ */ jsx(QueryClientProvider, { client: queryClient, children }) });
66
+ }
67
+ function useReownWallet() {
68
+ const { open } = useAppKit();
69
+ const { address, isConnected } = useAppKitAccount();
70
+ const { data: walletClient } = useWalletClient();
71
+ const publicClient = usePublicClient();
72
+ const { switchChainAsync } = useSwitchChain();
73
+ return {
74
+ walletClient: walletClient ?? void 0,
75
+ publicClient: publicClient ?? void 0,
76
+ address,
77
+ isConnected,
78
+ openConnect: () => {
79
+ void open({ view: isConnected ? "Account" : "Connect" });
80
+ },
81
+ switchChain: async (chainId) => {
82
+ await switchChainAsync({ chainId });
83
+ }
84
+ };
85
+ }
86
+
87
+ export {
88
+ ReownWalletProvider,
89
+ useReownWallet
90
+ };