@miden-sdk/miden-wallet-adapter-reactui 0.16.2 → 0.17.0-rc.2

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.
Files changed (45) hide show
  1. package/dist/Button.js.map +1 -1
  2. package/dist/Collapse.js.map +1 -1
  3. package/dist/DiscoverMidenMessage.js.map +1 -1
  4. package/dist/MidenSVG.js.map +1 -1
  5. package/dist/WalletConnectButton.js.map +1 -1
  6. package/dist/WalletDisconnectButton.js.map +1 -1
  7. package/dist/WalletIcon.js.map +1 -1
  8. package/dist/WalletListItem.js.map +1 -1
  9. package/dist/WalletModal.js.map +1 -1
  10. package/dist/WalletModalButton.js.map +1 -1
  11. package/dist/WalletModalProvider.js.map +1 -1
  12. package/dist/WalletMultiButton.js.map +1 -1
  13. package/dist/index.js.map +1 -1
  14. package/dist/useWalletModal.js.map +1 -1
  15. package/package.json +9 -4
  16. package/docs/README.md +0 -27
  17. package/docs/functions/useWalletModal.md +0 -13
  18. package/docs/interfaces/WalletIconProps.md +0 -3222
  19. package/docs/interfaces/WalletModalContextState.md +0 -29
  20. package/docs/interfaces/WalletModalProps.md +0 -41
  21. package/docs/interfaces/WalletModalProviderProps.md +0 -67
  22. package/docs/variables/WalletConnectButton.md +0 -9
  23. package/docs/variables/WalletDisconnectButton.md +0 -9
  24. package/docs/variables/WalletIcon.md +0 -9
  25. package/docs/variables/WalletModal.md +0 -9
  26. package/docs/variables/WalletModalButton.md +0 -9
  27. package/docs/variables/WalletModalContext.md +0 -9
  28. package/docs/variables/WalletModalProvider.md +0 -9
  29. package/docs/variables/WalletMultiButton.md +0 -9
  30. package/src/Button.tsx +0 -46
  31. package/src/Collapse.tsx +0 -90
  32. package/src/DiscoverMidenMessage.tsx +0 -15
  33. package/src/MidenSVG.tsx +0 -42
  34. package/src/WalletConnectButton.tsx +0 -57
  35. package/src/WalletDisconnectButton.tsx +0 -43
  36. package/src/WalletIcon.tsx +0 -21
  37. package/src/WalletListItem.tsx +0 -47
  38. package/src/WalletModal.tsx +0 -266
  39. package/src/WalletModalButton.tsx +0 -31
  40. package/src/WalletModalProvider.tsx +0 -28
  41. package/src/WalletMultiButton.tsx +0 -124
  42. package/src/aleo.svg +0 -250
  43. package/src/index.ts +0 -8
  44. package/src/useWalletModal.tsx +0 -41
  45. package/tsconfig.json +0 -32
@@ -1,266 +0,0 @@
1
- import type { FC, MouseEvent } from "react";
2
- import { useCallback, useLayoutEffect, useMemo, useRef, useState } from "react";
3
- import { createPortal } from "react-dom";
4
- import {
5
- AllowedPrivateData,
6
- PrivateDataPermission,
7
- WalletAdapterNetwork,
8
- WalletName,
9
- WalletReadyState,
10
- } from "@miden-sdk/miden-wallet-adapter-base";
11
- import { useWallet, Wallet } from "@miden-sdk/miden-wallet-adapter-react";
12
- import { MidenWalletName } from "@miden-sdk/miden-wallet-adapter-miden";
13
- import { useWalletModal } from "./useWalletModal";
14
- import { WalletListItem } from "./WalletListItem";
15
- import { DiscoverMidenMessage } from "./DiscoverMidenMessage";
16
-
17
- export interface WalletModalProps {
18
- className?: string;
19
- container?: string;
20
- privateDataPermission?: PrivateDataPermission;
21
- network?: WalletAdapterNetwork;
22
- allowedPrivateData?: AllowedPrivateData;
23
- }
24
-
25
- export const WalletModal: FC<WalletModalProps> = ({
26
- className = "",
27
- container = "body",
28
- privateDataPermission,
29
- network,
30
- allowedPrivateData,
31
- }) => {
32
- const ref = useRef<HTMLDivElement>(null);
33
- const { wallets, select, connect, wallet } = useWallet();
34
- const { setVisible } = useWalletModal();
35
- const [fadeIn, setFadeIn] = useState(false);
36
- const [portal, setPortal] = useState<Element | null>(null);
37
-
38
- const [installedWallets, otherWallets] = useMemo(() => {
39
- const installed: Wallet[] = [];
40
- const notDetected: Wallet[] = [];
41
- const loadable: Wallet[] = [];
42
-
43
- for (const wallet of wallets) {
44
- if (wallet.readyState === WalletReadyState.NotDetected) {
45
- notDetected.push(wallet);
46
- } else if (wallet.readyState === WalletReadyState.Loadable) {
47
- loadable.push(wallet);
48
- } else if (wallet.readyState === WalletReadyState.Installed) {
49
- installed.push(wallet);
50
- }
51
- }
52
-
53
- return [installed, [...loadable, ...notDetected]];
54
- }, [wallets]);
55
-
56
- const getStartedWallet = useMemo(() => {
57
- return installedWallets.length
58
- ? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
59
- installedWallets[0]!
60
- : wallets.find(
61
- (wallet: { adapter: { name: WalletName } }) =>
62
- wallet.adapter.name === MidenWalletName
63
- ) ||
64
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
65
- otherWallets[0]!;
66
- }, [installedWallets, wallets, otherWallets]);
67
-
68
- const otherInstalledWallets = useMemo(() => {
69
- return installedWallets.filter(
70
- (wallet) => wallet.adapter.name !== getStartedWallet.adapter.name
71
- );
72
- }, [installedWallets, getStartedWallet]);
73
-
74
- const hideModal = useCallback(() => {
75
- setFadeIn(false);
76
- setTimeout(() => setVisible(false), 150);
77
- }, [setVisible]);
78
-
79
- const handleClose = useCallback(
80
- (event: MouseEvent) => {
81
- event.preventDefault();
82
- hideModal();
83
- },
84
- [hideModal]
85
- );
86
-
87
- const handleWalletClick = useCallback(
88
- (event: MouseEvent, walletName: WalletName) => {
89
- select(walletName);
90
- handleClose(event);
91
- },
92
- [select, handleClose]
93
- );
94
-
95
- const handleTabKey = useCallback(
96
- (event: KeyboardEvent) => {
97
- const node = ref.current;
98
- if (!node) return;
99
-
100
- // here we query all focusable elements
101
- const focusableElements = node.querySelectorAll("button");
102
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
103
- const firstElement = focusableElements[0]!;
104
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
105
- const lastElement = focusableElements[focusableElements.length - 1]!;
106
-
107
- if (event.shiftKey) {
108
- // if going backward by pressing tab and firstElement is active, shift focus to last focusable element
109
- if (document.activeElement === firstElement) {
110
- lastElement.focus();
111
- event.preventDefault();
112
- }
113
- } else {
114
- // if going forward by pressing tab and lastElement is active, shift focus to first focusable element
115
- if (document.activeElement === lastElement) {
116
- firstElement.focus();
117
- event.preventDefault();
118
- }
119
- }
120
- },
121
- [ref]
122
- );
123
-
124
- useLayoutEffect(() => {
125
- const handleKeyDown = (event: KeyboardEvent) => {
126
- if (event.key === "Escape") {
127
- hideModal();
128
- } else if (event.key === "Tab") {
129
- handleTabKey(event);
130
- }
131
- };
132
-
133
- // Get original overflow
134
- const { overflow } = window.getComputedStyle(document.body);
135
- // Hack to enable fade in animation after mount
136
- setTimeout(() => setFadeIn(true), 0);
137
- // Prevent scrolling on mount
138
- document.body.style.overflow = "hidden";
139
- // Listen for keydown events
140
- window.addEventListener("keydown", handleKeyDown, false);
141
-
142
- return () => {
143
- // Re-enable scrolling when component unmounts
144
- document.body.style.overflow = overflow;
145
- window.removeEventListener("keydown", handleKeyDown, false);
146
- };
147
- }, [hideModal, handleTabKey]);
148
-
149
- useLayoutEffect(
150
- () => setPortal(document.querySelector(container)),
151
- [container]
152
- );
153
-
154
- useLayoutEffect(() => {
155
- if (wallet) {
156
- connect(
157
- privateDataPermission || PrivateDataPermission.UponRequest,
158
- network || WalletAdapterNetwork.Testnet,
159
- allowedPrivateData ?? AllowedPrivateData.None
160
- ).catch((e) => {
161
- console.log({ e });
162
- });
163
- }
164
- }, [wallet, privateDataPermission, network, allowedPrivateData, connect]);
165
-
166
- return (
167
- portal &&
168
- createPortal(
169
- <div
170
- aria-labelledby="wallet-adapter-modal-title"
171
- aria-modal="true"
172
- className={`wallet-adapter-modal ${
173
- fadeIn && "wallet-adapter-modal-fade-in"
174
- } ${className}`}
175
- ref={ref}
176
- role="dialog"
177
- >
178
- <div className="wallet-adapter-modal-container">
179
- <div className="wallet-adapter-modal-wrapper">
180
- <div className="wallet-adapter-modal-title">
181
- Connect a Wallet
182
- <button
183
- onClick={handleClose}
184
- className="wallet-adapter-modal-button-close"
185
- >
186
- <svg width="14" height="14">
187
- <path d="M14 12.461 8.3 6.772l5.234-5.233L12.006 0 6.772 5.234 1.54 0 0 1.539l5.234 5.233L0 12.006l1.539 1.528L6.772 8.3l5.69 5.7L14 12.461z" />
188
- </svg>
189
- </button>
190
- </div>
191
- {installedWallets.length ? (
192
- <>
193
- <div className="wallet-adapter-modal-content">
194
- Connect your Bread Wallet and start exploring its powerful
195
- features now!
196
- <hr />
197
- </div>
198
- <ul className="wallet-adapter-modal-list">
199
- <span className="wallet-adapter-modal-list-section-title">
200
- Recommended
201
- </span>
202
- <WalletListItem
203
- key={getStartedWallet.adapter.name}
204
- handleClick={(event) =>
205
- handleWalletClick(event, getStartedWallet.adapter.name)
206
- }
207
- wallet={getStartedWallet}
208
- />
209
- {(otherInstalledWallets.length > 0 ||
210
- otherWallets.length > 0) && (
211
- <>
212
- <hr />
213
- <span className="wallet-adapter-modal-list-section-title">
214
- Other wallets
215
- </span>
216
- {otherInstalledWallets.map((wallet) => (
217
- <WalletListItem
218
- key={wallet.adapter.name}
219
- handleClick={(event) =>
220
- handleWalletClick(event, wallet.adapter.name)
221
- }
222
- wallet={wallet}
223
- />
224
- ))}
225
- {otherWallets.map((wallet) => (
226
- <WalletListItem
227
- key={wallet.adapter.name}
228
- handleClick={(event) =>
229
- handleWalletClick(event, wallet.adapter.name)
230
- }
231
- wallet={wallet}
232
- />
233
- ))}
234
- </>
235
- )}
236
- </ul>
237
- </>
238
- ) : (
239
- <>
240
- <div className="wallet-adapter-modal-middle">
241
- <DiscoverMidenMessage />
242
- <a
243
- href={getStartedWallet.adapter.url}
244
- target="_blank"
245
- rel="noopener noreferrer"
246
- className="wallet-adapter-modal-chrome-badge"
247
- >
248
- <img
249
- src="https://developer.chrome.com/static/docs/webstore/branding/image/HRs9MPufa1J1h5glNhut.png"
250
- alt="Available in the Chrome Web Store"
251
- />
252
- </a>
253
- </div>
254
- </>
255
- )}
256
- </div>
257
- </div>
258
- <div
259
- className="wallet-adapter-modal-overlay"
260
- onMouseDown={handleClose}
261
- />
262
- </div>,
263
- portal
264
- )
265
- );
266
- };
@@ -1,31 +0,0 @@
1
- import type { FC, MouseEvent } from "react";
2
- import { useCallback } from "react";
3
- import type { ButtonProps } from "./Button";
4
- import { Button } from "./Button";
5
- import { useWalletModal } from "./useWalletModal";
6
-
7
- export const WalletModalButton: FC<ButtonProps> = ({
8
- children = "Select Wallet",
9
- onClick,
10
- ...props
11
- }) => {
12
- const { visible, setVisible } = useWalletModal();
13
-
14
- const handleClick = useCallback(
15
- (event: MouseEvent<HTMLButtonElement>) => {
16
- if (onClick) onClick(event);
17
- if (!event.defaultPrevented) setVisible(!visible);
18
- },
19
- [onClick, setVisible, visible]
20
- );
21
-
22
- return (
23
- <Button
24
- className="wallet-adapter-button-trigger"
25
- onClick={handleClick}
26
- {...props}
27
- >
28
- {children}
29
- </Button>
30
- );
31
- };
@@ -1,28 +0,0 @@
1
- import type { FC, ReactNode } from "react";
2
- import React, { useState } from "react";
3
- import { WalletModalContext } from "./useWalletModal";
4
- import type { WalletModalProps } from "./WalletModal";
5
- import { WalletModal } from "./WalletModal";
6
-
7
- export interface WalletModalProviderProps extends WalletModalProps {
8
- children: ReactNode;
9
- }
10
-
11
- export const WalletModalProvider: FC<WalletModalProviderProps> = ({
12
- children,
13
- ...props
14
- }) => {
15
- const [visible, setVisible] = useState(false);
16
-
17
- return (
18
- <WalletModalContext.Provider
19
- value={{
20
- visible,
21
- setVisible,
22
- }}
23
- >
24
- {children}
25
- {visible && <WalletModal {...props} />}
26
- </WalletModalContext.Provider>
27
- );
28
- };
@@ -1,124 +0,0 @@
1
- import type { FC } from "react";
2
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
- import { useWallet } from "@miden-sdk/miden-wallet-adapter-react";
4
- import type { ButtonProps } from "./Button";
5
- import { Button } from "./Button";
6
- import { useWalletModal } from "./useWalletModal";
7
- import { WalletConnectButton } from "./WalletConnectButton";
8
- import { WalletIcon } from "./WalletIcon";
9
- import { WalletModalButton } from "./WalletModalButton";
10
-
11
- export const WalletMultiButton: FC<ButtonProps> = ({ children, ...props }) => {
12
- const { address, wallet, disconnect } = useWallet();
13
- const { setVisible } = useWalletModal();
14
- const [copied, setCopied] = useState(false);
15
- const [active, setActive] = useState(false);
16
- const ref = useRef<HTMLUListElement>(null);
17
-
18
- const content = useMemo(() => {
19
- if (children) return children;
20
- if (!wallet || !address) return null;
21
-
22
- const underscoreIndex = address.indexOf("_");
23
- const frontPart = address.slice(0, 6);
24
- const middlePart = address.slice(underscoreIndex - 4, underscoreIndex);
25
- return `${frontPart}...${middlePart}`;
26
- }, [children, wallet, address]);
27
-
28
- const copyAddress = useCallback(async () => {
29
- if (address) {
30
- await navigator.clipboard.writeText(address);
31
- setCopied(true);
32
- setTimeout(() => setCopied(false), 400);
33
- }
34
- }, [address]);
35
-
36
- const openDropdown = useCallback(() => {
37
- setActive(true);
38
- }, []);
39
-
40
- const closeDropdown = useCallback(() => {
41
- setActive(false);
42
- }, []);
43
-
44
- const openModal = useCallback(() => {
45
- setVisible(true);
46
- closeDropdown();
47
- }, [setVisible, closeDropdown]);
48
-
49
- useEffect(() => {
50
- const listener = (event: MouseEvent | TouchEvent) => {
51
- const node = ref.current;
52
-
53
- // Do nothing if clicking dropdown or its descendants
54
- if (!node || node.contains(event.target as Node)) return;
55
-
56
- closeDropdown();
57
- };
58
-
59
- document.addEventListener("mousedown", listener);
60
- document.addEventListener("touchstart", listener);
61
-
62
- return () => {
63
- document.removeEventListener("mousedown", listener);
64
- document.removeEventListener("touchstart", listener);
65
- };
66
- }, [ref, closeDropdown]);
67
-
68
- if (!wallet)
69
- return <WalletModalButton {...props}>{children}</WalletModalButton>;
70
- if (!address)
71
- return <WalletConnectButton {...props}>{children}</WalletConnectButton>;
72
-
73
- return (
74
- <div className="wallet-adapter-dropdown">
75
- <Button
76
- aria-expanded={active}
77
- className="wallet-adapter-button-trigger"
78
- style={{
79
- pointerEvents: active ? "none" : "auto",
80
- width: "100%",
81
- backgroundColor: "#FFFFFF",
82
- border: "1px solid #D7D7D7",
83
- color: "black",
84
- ...props.style,
85
- }}
86
- onClick={openDropdown}
87
- startIcon={<WalletIcon wallet={wallet} />}
88
- {...props}
89
- >
90
- {content}
91
- </Button>
92
- <ul
93
- aria-label="dropdown-list"
94
- className={`wallet-adapter-dropdown-list ${
95
- active && "wallet-adapter-dropdown-list-active"
96
- }`}
97
- ref={ref}
98
- role="menu"
99
- >
100
- <li
101
- onClick={copyAddress}
102
- className="wallet-adapter-dropdown-list-item"
103
- role="menuitem"
104
- >
105
- {copied ? "Copied" : "Copy address"}
106
- </li>
107
- <li
108
- onClick={openModal}
109
- className="wallet-adapter-dropdown-list-item"
110
- role="menuitem"
111
- >
112
- Change wallet
113
- </li>
114
- <li
115
- onClick={disconnect}
116
- className="wallet-adapter-dropdown-list-item"
117
- role="menuitem"
118
- >
119
- Disconnect
120
- </li>
121
- </ul>
122
- </div>
123
- );
124
- };