@gluwa/connect-kit 0.2.0-next.1 → 0.2.0-next.3

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 (89) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/assets/creditwallet.png +0 -0
  3. package/assets/fonts/Inter-Medium.ttf +0 -0
  4. package/assets/fonts/Inter-Medium.woff2 +0 -0
  5. package/assets/fonts/Inter-Regular.ttf +0 -0
  6. package/assets/fonts/Inter-Regular.woff2 +0 -0
  7. package/assets/fonts/Inter-SemiBold.ttf +0 -0
  8. package/assets/fonts/Inter-SemiBold.woff2 +0 -0
  9. package/assets/graphic.png +0 -0
  10. package/assets/metamask.png +0 -0
  11. package/assets/wc-logo.svg +3 -0
  12. package/assets/wc-search.png +0 -0
  13. package/dist/chunk-EDNRW47A.js +401 -0
  14. package/dist/credit-connect.js +2 -409
  15. package/dist/index.css +1903 -390
  16. package/dist/index.d.ts +16 -10
  17. package/dist/index.js +1110 -870
  18. package/dist/package.json +7 -6
  19. package/package.json +8 -8
  20. package/src/ConnectKitProvider.tsx +90 -65
  21. package/src/assets.d.ts +5 -0
  22. package/src/components/actionItem/index.tsx +50 -0
  23. package/src/components/actionItem/style.scss +47 -0
  24. package/src/components/copyLink/index.tsx +16 -0
  25. package/src/components/copyLink/style.scss +16 -0
  26. package/src/components/qrArea/index.tsx +70 -0
  27. package/src/components/qrArea/style.scss +130 -0
  28. package/src/components/searchBar/asset/Search.tsx +20 -0
  29. package/src/components/searchBar/asset/XMarkCircle.tsx +24 -0
  30. package/src/components/searchBar/index.tsx +44 -0
  31. package/src/components/searchBar/style.scss +58 -0
  32. package/src/components/snackbar/index.tsx +25 -0
  33. package/src/components/snackbar/style.scss +51 -0
  34. package/src/components/toggle/index.tsx +27 -0
  35. package/src/components/toggle/style.scss +53 -0
  36. package/src/components/walletGrid/index.tsx +64 -0
  37. package/src/components/walletGrid/style.scss +108 -0
  38. package/src/components/walletItem/index.tsx +49 -0
  39. package/src/components/walletItem/style.scss +70 -0
  40. package/src/connector-meta.ts +12 -7
  41. package/src/core/config.ts +20 -1
  42. package/src/creditConnectConnector.ts +17 -25
  43. package/src/hooks/useWCState.ts +22 -5
  44. package/src/hooks/useWagmiConnect.ts +0 -1
  45. package/src/index.ts +2 -2
  46. package/src/layout/allWallets/index.tsx +52 -0
  47. package/src/layout/allWallets/style.scss +62 -0
  48. package/src/layout/connectDialog/asset/backIcon.tsx +24 -0
  49. package/src/layout/connectDialog/asset/checkIcon.tsx +28 -0
  50. package/src/layout/connectDialog/asset/closeIcon.tsx +21 -0
  51. package/src/layout/connectDialog/asset/copyIcon.tsx +28 -0
  52. package/src/layout/connectDialog/asset/linkIcon.tsx +24 -0
  53. package/src/layout/connectDialog/asset/spinner.tsx +21 -0
  54. package/src/layout/connectDialog/idle/index.tsx +32 -0
  55. package/src/layout/connectDialog/idle/style.scss +61 -0
  56. package/src/layout/connectDialog/index.tsx +286 -0
  57. package/src/layout/connectDialog/loading/index.tsx +13 -0
  58. package/src/layout/connectDialog/loading/style.scss +19 -0
  59. package/src/layout/connectDialog/metaMask/index.tsx +61 -0
  60. package/src/layout/connectDialog/metaMask/style.scss +65 -0
  61. package/src/layout/connectDialog/qr/index.tsx +33 -0
  62. package/src/layout/connectDialog/style.scss +95 -0
  63. package/src/layout/connectDialog/timeout/index.tsx +31 -0
  64. package/src/layout/connectDialog/timeout/style.scss +64 -0
  65. package/src/layout/connectDialog/walletConnect/index.tsx +45 -0
  66. package/src/layout/connectDialog/walletConnect/style.scss +48 -0
  67. package/src/layout/connectDialog/walletQR/index.tsx +37 -0
  68. package/src/layout/detailPanel/index.tsx +147 -0
  69. package/src/layout/detailPanel/style.scss +64 -0
  70. package/src/layout/selectorPanel/index.tsx +100 -0
  71. package/src/layout/selectorPanel/style.scss +113 -0
  72. package/src/style/color.scss +417 -0
  73. package/src/style/font.scss +28 -0
  74. package/src/style/index.scss +5 -0
  75. package/src/style/mixin.scss +217 -0
  76. package/src/style/reset.scss +110 -0
  77. package/src/style/variables.scss +13 -0
  78. package/src/types.ts +11 -8
  79. package/src/utils/platform.ts +6 -0
  80. package/tsup.config.ts +32 -2
  81. package/dist/chunk-DDA6FP6U.js +0 -7
  82. package/src/ConnectModal.scss +0 -665
  83. package/src/ConnectModal.tsx +0 -573
  84. package/src/components/QRFrame.tsx +0 -43
  85. package/src/views/CreditWalletView.tsx +0 -58
  86. package/src/views/IdleView.tsx +0 -10
  87. package/src/views/MetaMaskView.tsx +0 -66
  88. package/src/views/SwitchChainView.tsx +0 -72
  89. package/src/views/WalletConnectView.tsx +0 -206
@@ -1,66 +0,0 @@
1
- import { type FC, useEffect, useMemo, useRef } from 'react';
2
- import { isMobileDevice, tryOpenDeepLink } from '../utils/platform';
3
- import { CONNECTOR_META } from '../connector-meta';
4
- import { QRFrame, CopyLinkButton } from '../components/QRFrame';
5
-
6
- const { downloadUrl, deepLinkBase } = CONNECTOR_META.METAMASK;
7
-
8
- interface MetaMaskViewProps {
9
- qrUri: string | null;
10
- hasExtension: boolean;
11
- logoUrl?: string;
12
- }
13
-
14
- export const MetaMaskView: FC<MetaMaskViewProps> = ({ qrUri, hasExtension, logoUrl }) => {
15
- const isMobile = useMemo(() => isMobileDevice(), []);
16
- const hasRedirectedRef = useRef(false);
17
-
18
- useEffect(() => {
19
- if (isMobile && qrUri && deepLinkBase && !hasRedirectedRef.current) {
20
- hasRedirectedRef.current = true;
21
- tryOpenDeepLink(qrUri, deepLinkBase);
22
- }
23
- }, [isMobile, qrUri]);
24
-
25
- if (isMobile && deepLinkBase) {
26
- return (
27
- <div className="ck-view ck-view--mobile-redirect">
28
- <p>Opening MetaMask...</p>
29
- </div>
30
- );
31
- }
32
-
33
- if (hasExtension) {
34
- return (
35
- <div className="ck-view ck-view--extension">
36
- <span className="ck-view__wallet-icon ck-view__wallet-icon--metamask" aria-hidden="true" />
37
- <h4 className="ck-view__title">Open MetaMask</h4>
38
- <p className="ck-view__description">Check the connection in your extension</p>
39
- <span className="ck-spinner" aria-label="Connecting" />
40
- </div>
41
- );
42
- }
43
-
44
- return (
45
- <div className="ck-view ck-view--qr">
46
- <QRFrame qrUri={qrUri} logoUrl={logoUrl} />
47
- <CopyLinkButton qrUri={qrUri} />
48
-
49
- {downloadUrl && (
50
- <div className="ck-download-card">
51
- <div className="ck-download-card__text">
52
- <p className="ck-download-card__title">Don&apos;t have MetaMask Wallet?</p>
53
- </div>
54
- <a
55
- href={downloadUrl}
56
- target="_blank"
57
- rel="nofollow noopener noreferrer"
58
- className="ck-btn-primary"
59
- >
60
- Download
61
- </a>
62
- </div>
63
- )}
64
- </div>
65
- );
66
- };
@@ -1,72 +0,0 @@
1
- import { useEffect, useRef, useState, type FC } from 'react';
2
- import { useSwitchChain } from 'wagmi';
3
-
4
- interface SwitchChainViewProps {
5
- currentChainId: number | undefined;
6
- requiredChainId: number;
7
- requiredChainName?: string;
8
- onDisconnect: () => void;
9
- onLog?: (message: string, error?: Error) => void;
10
- }
11
-
12
- export const SwitchChainView: FC<SwitchChainViewProps> = ({
13
- currentChainId,
14
- requiredChainId,
15
- requiredChainName,
16
- onDisconnect,
17
- onLog,
18
- }) => {
19
- const { switchChainAsync, isPending } = useSwitchChain();
20
- const [error, setError] = useState<Error | null>(null);
21
- const isMountedRef = useRef(true);
22
- useEffect(() => {
23
- isMountedRef.current = true;
24
- return () => {
25
- isMountedRef.current = false;
26
- };
27
- }, []);
28
-
29
- const targetLabel = requiredChainName ?? `chain ${requiredChainId}`;
30
-
31
- const handleSwitch = (): void => {
32
- setError(null);
33
- switchChainAsync({ chainId: requiredChainId }).catch((err: unknown) => {
34
- const normalized = err instanceof Error ? err : new Error(String(err));
35
- const code =
36
- typeof err === 'object' && err !== null && 'code' in err
37
- ? (err as { code: unknown }).code
38
- : undefined;
39
- if (code === 4902) {
40
- onLog?.('[connect-kit] chain not registered in wallet (4902)', normalized);
41
- } else {
42
- onLog?.(`[connect-kit] switch chain failed: ${normalized.message}`, normalized);
43
- }
44
- if (isMountedRef.current) setError(normalized);
45
- });
46
- };
47
-
48
- return (
49
- <div className="ck-view ck-view--switch-chain">
50
- <h4 className="ck-view__title">Wrong network</h4>
51
- <p className="ck-view__description">
52
- {currentChainId != null
53
- ? `Connected to chain ${currentChainId}. Please switch to ${targetLabel} to continue.`
54
- : `Please switch to ${targetLabel} to continue.`}
55
- </p>
56
- <div className="ck-view__actions">
57
- <button
58
- type="button"
59
- className="ck-btn-primary"
60
- onClick={handleSwitch}
61
- disabled={isPending}
62
- >
63
- {isPending ? 'Waiting for wallet…' : `Switch to ${targetLabel}`}
64
- </button>
65
- <button type="button" className="ck-btn-secondary" onClick={onDisconnect}>
66
- Disconnect
67
- </button>
68
- </div>
69
- {error && <p className="ck-view__caption ck-view__caption--error">{error.message}</p>}
70
- </div>
71
- );
72
- };
@@ -1,206 +0,0 @@
1
- import { type FC, useMemo } from 'react';
2
- import { isMobileDevice, tryOpenDeepLink } from '../utils/platform';
3
- import { type WCWallet, type WCSubView } from '../types';
4
- import deeplink from '../../assets/deeplink.png';
5
- import { QRFrame, CopyLinkButton } from '../components/QRFrame';
6
- import { CONNECTOR_META } from '../connector-meta';
7
-
8
- interface WalletConnectViewProps {
9
- subView: WCSubView;
10
- qrUri: string | null;
11
- logoUrl?: string;
12
- walletList: WCWallet[];
13
- walletListLoading: boolean;
14
- walletListSearch: string;
15
- walletListFilterActive: boolean;
16
- selectedWallet: WCWallet | null;
17
- onShowList: () => void;
18
- onSelectWallet: (wallet: WCWallet) => void;
19
- onSearchChange: (q: string) => void;
20
- onFilterToggle: () => void;
21
- }
22
-
23
- export const WalletConnectView: FC<WalletConnectViewProps> = (props) => {
24
- const { subView, selectedWallet } = props;
25
-
26
- if (subView === 'list') return <WalletListView {...props} />;
27
- if (subView === 'wallet' && selectedWallet)
28
- return <WalletQRView wallet={selectedWallet} qrUri={props.qrUri} />;
29
- return <WCQRView {...props} />;
30
- };
31
-
32
- const WCQRView: FC<WalletConnectViewProps> = ({ qrUri, logoUrl, walletList, onShowList }) => (
33
- <div className="ck-view ck-view--qr">
34
- <QRFrame qrUri={qrUri} logoUrl={logoUrl} />
35
-
36
- <p className="ck-view__caption">Scan this QR Code with your phone</p>
37
-
38
- <CopyLinkButton qrUri={qrUri} />
39
-
40
- <button type="button" className="ck-all-wallets-btn" onClick={onShowList}>
41
- <span className="ck-all-wallets-btn__icon" aria-hidden="true" />
42
- <span className="ck-all-wallets-btn__label">All Wallets</span>
43
- {walletList.length > 0 && (
44
- <span className="ck-all-wallets-btn__count">{walletList.length}+</span>
45
- )}
46
- </button>
47
- </div>
48
- );
49
-
50
- const CREDIT_WALLET_NAME = CONNECTOR_META.CREDIT_WALLET.label;
51
-
52
- const WalletListView: FC<WalletConnectViewProps> = ({
53
- walletList,
54
- walletListLoading,
55
- walletListSearch,
56
- walletListFilterActive,
57
- logoUrl,
58
- qrUri,
59
- onSelectWallet,
60
- onSearchChange,
61
- onFilterToggle,
62
- }) => {
63
- const isMobile = useMemo(() => isMobileDevice(), []);
64
-
65
- const filtered = useMemo(() => {
66
- const q = walletListSearch.trim().toLowerCase();
67
- let list = walletList;
68
- if (walletListFilterActive) {
69
- list = list.filter(
70
- (w) => w.mobileNative || w.mobileUniversal || w.desktopNative || w.desktopUniversal,
71
- );
72
- }
73
- if (q) {
74
- list = list.filter((w) => w.name.toLowerCase().includes(q));
75
- }
76
- return [...list].sort((a, b) => {
77
- if (a.name === CREDIT_WALLET_NAME) return -1;
78
- if (b.name === CREDIT_WALLET_NAME) return 1;
79
- return 0;
80
- });
81
- }, [walletList, walletListSearch, walletListFilterActive]);
82
-
83
- const handleClickWallet = (wallet: WCWallet): void => {
84
- if (isMobile && qrUri) {
85
- const target = wallet.mobileNative || wallet.mobileUniversal;
86
- if (target) {
87
- tryOpenDeepLink(qrUri, target);
88
- return;
89
- }
90
- }
91
- onSelectWallet(wallet);
92
- };
93
-
94
- return (
95
- <div className="ck-view ck-view--wallet-list">
96
- <div className="ck-wallet-search">
97
- <input
98
- type="text"
99
- className="ck-wallet-search__input"
100
- placeholder="Search wallet"
101
- value={walletListSearch}
102
- onChange={(e) => {
103
- onSearchChange(e.target.value);
104
- }}
105
- />
106
- <button
107
- type="button"
108
- className={`ck-wc-filter${walletListFilterActive ? ' is-active' : ''}`}
109
- onClick={onFilterToggle}
110
- aria-pressed={walletListFilterActive}
111
- aria-label="Show WalletConnect wallets only"
112
- title="WalletConnect wallets only"
113
- >
114
- {logoUrl && (
115
- <img src={logoUrl} alt="" className="ck-wc-filter__icon" aria-hidden="true" />
116
- )}
117
- <span className="ck-wc-filter__track">
118
- <span className="ck-wc-filter__thumb" />
119
- </span>
120
- </button>
121
- </div>
122
-
123
- {walletListLoading && walletList.length === 0 && (
124
- <div className="ck-wallet-list-loading">
125
- <span className="ck-spinner" aria-label="Loading wallets" />
126
- </div>
127
- )}
128
-
129
- {!walletListLoading && filtered.length === 0 && walletList.length > 0 && (
130
- <p className="ck-wallet-list-empty">No wallets found.</p>
131
- )}
132
-
133
- <div className="ck-wallet-grid-scroll">
134
- <ul className="ck-wallet-grid">
135
- {filtered.map((wallet) => {
136
- const hasDeeplink = !!(
137
- wallet.mobileNative ||
138
- wallet.mobileUniversal ||
139
- wallet.desktopNative ||
140
- wallet.desktopUniversal
141
- );
142
- return (
143
- <li key={wallet.id}>
144
- <button
145
- type="button"
146
- className="ck-wallet-grid__item"
147
- onClick={() => {
148
- handleClickWallet(wallet);
149
- }}
150
- >
151
- {wallet.imageUrl ? (
152
- <img className="ck-wallet-grid__icon" src={wallet.imageUrl} alt="" />
153
- ) : (
154
- <span className="ck-wallet-grid__icon-placeholder" aria-hidden="true" />
155
- )}
156
- <span className="ck-wallet-grid__name">
157
- <span className="ck-wallet-grid__name-text">{wallet.name}</span>
158
- {hasDeeplink && (
159
- <img
160
- src={deeplink}
161
- alt=""
162
- className="ck-wallet-grid__wc-badge"
163
- aria-hidden="true"
164
- />
165
- )}
166
- </span>
167
- </button>
168
- </li>
169
- );
170
- })}
171
- </ul>
172
- </div>
173
- </div>
174
- );
175
- };
176
-
177
- const WalletQRView: FC<{ wallet: WCWallet; qrUri: string | null }> = ({ wallet, qrUri }) => {
178
- const downloadUrl = wallet.appIos || wallet.appAndroid || wallet.homepage;
179
- const logoSrc = wallet.imageUrl;
180
-
181
- return (
182
- <div className="ck-view ck-view--qr">
183
- <QRFrame qrUri={qrUri} logoUrl={logoSrc} />
184
-
185
- <p className="ck-view__caption">Scan this QR Code with your phone</p>
186
-
187
- <CopyLinkButton qrUri={qrUri} />
188
-
189
- {downloadUrl && (
190
- <div className="ck-download-card">
191
- <div className="ck-download-card__text">
192
- <p className="ck-download-card__title">Don&apos;t have {wallet.name}?</p>
193
- </div>
194
- <a
195
- href={downloadUrl}
196
- target="_blank"
197
- rel="nofollow noopener noreferrer"
198
- className="ck-btn-primary"
199
- >
200
- Download
201
- </a>
202
- </div>
203
- )}
204
- </div>
205
- );
206
- };