@algobright/solana-connector 0.1.1 → 0.1.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.
- package/dist/{Button.module-HQNNX6IB.module.css → Button.module-QCTUNBHA.module.css} +1 -0
- package/dist/ConnectButton.d.mts +28 -0
- package/dist/ConnectButton.d.ts +28 -0
- package/dist/ConnectButton.js +191 -89
- package/dist/ConnectButton.js.map +1 -1
- package/dist/ConnectButton.mjs +164 -62
- package/dist/ConnectButton.mjs.map +1 -1
- package/dist/{ConnectButton.module-O3M32YJK.module.css → ConnectButton.module-AR6WQXQS.module.css} +0 -3
- package/dist/WalletDropdown.d.mts +23 -4
- package/dist/WalletDropdown.d.ts +23 -4
- package/dist/WalletDropdown.js +148 -41
- package/dist/WalletDropdown.js.map +1 -1
- package/dist/WalletDropdown.mjs +136 -29
- package/dist/WalletDropdown.mjs.map +1 -1
- package/dist/{WalletDropdown.module-A6KHWKGK.module.css → WalletDropdown.module-DOK7CUOQ.module.css} +1 -0
- package/dist/WalletModal.d.mts +13 -2
- package/dist/WalletModal.d.ts +13 -2
- package/dist/WalletModal.js +28 -30
- package/dist/WalletModal.js.map +1 -1
- package/dist/WalletModal.mjs +15 -17
- package/dist/WalletModal.mjs.map +1 -1
- package/package.json +8 -1
package/dist/ConnectButton.d.mts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
3
|
interface ConnectButtonProps {
|
|
4
|
+
/** * The visual theme for the button and modals.
|
|
5
|
+
* @default 'light'
|
|
6
|
+
*/
|
|
4
7
|
theme?: 'light' | 'dark';
|
|
8
|
+
/** * Custom Tailwind or CSS class for the main button element.
|
|
9
|
+
* If not passed, standard kit styling is applied.
|
|
10
|
+
*/
|
|
5
11
|
CN_ConnectButton?: string;
|
|
12
|
+
/** * Custom CSS class for the dropdown menu.
|
|
13
|
+
* If not passed, it defaults to the standard dropdown layout.
|
|
14
|
+
*/
|
|
6
15
|
CN_DropdownMenu?: string;
|
|
16
|
+
/** * Custom CSS class for the connection modal.
|
|
17
|
+
* This modal displays all wallet options and the QR code for mobile linking.
|
|
18
|
+
*/
|
|
7
19
|
CN_Modal?: string;
|
|
20
|
+
/** * Initial text shown when the wallet is disconnected.
|
|
21
|
+
* @default "Connect Wallet"
|
|
22
|
+
*/
|
|
8
23
|
connectText?: string;
|
|
24
|
+
/** * Text displayed while the wallet is in the 'connecting' state.
|
|
25
|
+
* @default "Connecting..."
|
|
26
|
+
*/
|
|
9
27
|
connectingText?: string;
|
|
28
|
+
/** * If true, fetches and displays the native SOL balance.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
10
31
|
showSolBalance?: boolean;
|
|
32
|
+
/** * If provided, displays a specific SPL token balance (e.g., USDC).
|
|
33
|
+
* If null/undefined, only SOL or no balance is shown.
|
|
34
|
+
*/
|
|
35
|
+
showDefaultToken?: {
|
|
36
|
+
address: string;
|
|
37
|
+
symbol: string;
|
|
38
|
+
};
|
|
11
39
|
}
|
|
12
40
|
declare function ConnectButton(props: ConnectButtonProps): react_jsx_runtime.JSX.Element;
|
|
13
41
|
|
package/dist/ConnectButton.d.ts
CHANGED
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
|
|
3
3
|
interface ConnectButtonProps {
|
|
4
|
+
/** * The visual theme for the button and modals.
|
|
5
|
+
* @default 'light'
|
|
6
|
+
*/
|
|
4
7
|
theme?: 'light' | 'dark';
|
|
8
|
+
/** * Custom Tailwind or CSS class for the main button element.
|
|
9
|
+
* If not passed, standard kit styling is applied.
|
|
10
|
+
*/
|
|
5
11
|
CN_ConnectButton?: string;
|
|
12
|
+
/** * Custom CSS class for the dropdown menu.
|
|
13
|
+
* If not passed, it defaults to the standard dropdown layout.
|
|
14
|
+
*/
|
|
6
15
|
CN_DropdownMenu?: string;
|
|
16
|
+
/** * Custom CSS class for the connection modal.
|
|
17
|
+
* This modal displays all wallet options and the QR code for mobile linking.
|
|
18
|
+
*/
|
|
7
19
|
CN_Modal?: string;
|
|
20
|
+
/** * Initial text shown when the wallet is disconnected.
|
|
21
|
+
* @default "Connect Wallet"
|
|
22
|
+
*/
|
|
8
23
|
connectText?: string;
|
|
24
|
+
/** * Text displayed while the wallet is in the 'connecting' state.
|
|
25
|
+
* @default "Connecting..."
|
|
26
|
+
*/
|
|
9
27
|
connectingText?: string;
|
|
28
|
+
/** * If true, fetches and displays the native SOL balance.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
10
31
|
showSolBalance?: boolean;
|
|
32
|
+
/** * If provided, displays a specific SPL token balance (e.g., USDC).
|
|
33
|
+
* If null/undefined, only SOL or no balance is shown.
|
|
34
|
+
*/
|
|
35
|
+
showDefaultToken?: {
|
|
36
|
+
address: string;
|
|
37
|
+
symbol: string;
|
|
38
|
+
};
|
|
11
39
|
}
|
|
12
40
|
declare function ConnectButton(props: ConnectButtonProps): react_jsx_runtime.JSX.Element;
|
|
13
41
|
|
package/dist/ConnectButton.js
CHANGED
|
@@ -36,16 +36,16 @@ __export(ConnectButton_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(ConnectButton_exports);
|
|
37
37
|
|
|
38
38
|
// src/components/ConnectButton/ConnectButton.tsx
|
|
39
|
-
var
|
|
40
|
-
var import_ConnectButton = __toESM(require("./ConnectButton.module-
|
|
41
|
-
var
|
|
39
|
+
var import_react10 = require("react");
|
|
40
|
+
var import_ConnectButton = __toESM(require("./ConnectButton.module-AR6WQXQS.module.css"));
|
|
41
|
+
var import_connector4 = require("@solana/connector");
|
|
42
42
|
|
|
43
43
|
// src/components/shared/Button/Button.tsx
|
|
44
|
-
var
|
|
44
|
+
var import_react = require("react");
|
|
45
45
|
var import_button = require("@base-ui/react/button");
|
|
46
|
-
var import_Button = __toESM(require("./Button.module-
|
|
46
|
+
var import_Button = __toESM(require("./Button.module-QCTUNBHA.module.css"));
|
|
47
47
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
48
|
-
var Button =
|
|
48
|
+
var Button = (0, import_react.forwardRef)(
|
|
49
49
|
({ className, variant = "default", size = "default", ...props }, ref) => {
|
|
50
50
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
51
51
|
import_button.Button,
|
|
@@ -79,21 +79,21 @@ var Spinner_default2 = Spinner_default;
|
|
|
79
79
|
// src/components/WalletModal/WalletModal.tsx
|
|
80
80
|
var import_connector = require("@solana/connector");
|
|
81
81
|
var import_lucide_react3 = require("lucide-react");
|
|
82
|
-
var
|
|
82
|
+
var import_react6 = require("react");
|
|
83
83
|
var import_WalletModal = __toESM(require("./WalletModal.module-ZRTJGOQY.module.css"));
|
|
84
84
|
|
|
85
85
|
// src/components/shared/Dialog/Dialog.tsx
|
|
86
|
-
var React2 = __toESM(require("react"));
|
|
87
86
|
var import_dialog = require("@base-ui/react/dialog");
|
|
88
87
|
var import_lucide_react = require("lucide-react");
|
|
89
88
|
var import_Dialog = __toESM(require("./Dialog.module-AYJTMDAD.module.css"));
|
|
90
89
|
var import_clsx = __toESM(require("clsx"));
|
|
90
|
+
var import_react2 = require("react");
|
|
91
91
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
92
92
|
var Dialog = import_dialog.Dialog.Root;
|
|
93
93
|
var DialogTrigger = import_dialog.Dialog.Trigger;
|
|
94
94
|
var DialogPortal = import_dialog.Dialog.Portal;
|
|
95
95
|
var DialogClose = import_dialog.Dialog.Close;
|
|
96
|
-
var DialogBackdrop =
|
|
96
|
+
var DialogBackdrop = (0, import_react2.forwardRef)(
|
|
97
97
|
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
98
98
|
import_dialog.Dialog.Backdrop,
|
|
99
99
|
{
|
|
@@ -104,7 +104,7 @@ var DialogBackdrop = React2.forwardRef(
|
|
|
104
104
|
)
|
|
105
105
|
);
|
|
106
106
|
DialogBackdrop.displayName = "DialogBackdrop";
|
|
107
|
-
var DialogContent =
|
|
107
|
+
var DialogContent = (0, import_react2.forwardRef)(
|
|
108
108
|
({ className, children, theme, showCloseButton = true, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(DialogPortal, { children: [
|
|
109
109
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DialogBackdrop, { "data-theme": theme }),
|
|
110
110
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
@@ -127,7 +127,7 @@ var DialogHeader = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_r
|
|
|
127
127
|
DialogHeader.displayName = "DialogHeader";
|
|
128
128
|
var DialogFooter = ({ className, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: `${import_Dialog.default.footer} ${className || ""}`, ...props });
|
|
129
129
|
DialogFooter.displayName = "DialogFooter";
|
|
130
|
-
var DialogTitle =
|
|
130
|
+
var DialogTitle = (0, import_react2.forwardRef)(
|
|
131
131
|
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
132
132
|
import_dialog.Dialog.Title,
|
|
133
133
|
{
|
|
@@ -138,7 +138,7 @@ var DialogTitle = React2.forwardRef(
|
|
|
138
138
|
)
|
|
139
139
|
);
|
|
140
140
|
DialogTitle.displayName = "DialogTitle";
|
|
141
|
-
var DialogDescription =
|
|
141
|
+
var DialogDescription = (0, import_react2.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
142
142
|
import_dialog.Dialog.Description,
|
|
143
143
|
{
|
|
144
144
|
ref,
|
|
@@ -149,7 +149,7 @@ var DialogDescription = React2.forwardRef(({ className, ...props }, ref) => /* @
|
|
|
149
149
|
DialogDescription.displayName = "DialogDescription";
|
|
150
150
|
|
|
151
151
|
// src/components/shared/CustomQRCode/CustomQRCode.tsx
|
|
152
|
-
var
|
|
152
|
+
var import_react3 = require("react");
|
|
153
153
|
var import_qrcode = __toESM(require("qrcode"));
|
|
154
154
|
var import_CustomQRCode = __toESM(require("./CustomQRCode.module-JW3JU3FX.module.css"));
|
|
155
155
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
@@ -171,7 +171,7 @@ function QRCodeSVG({
|
|
|
171
171
|
}) {
|
|
172
172
|
const logoSize = clearArea ? 76 : 0;
|
|
173
173
|
const size = sizeProp - 10 * 2;
|
|
174
|
-
const dots = (0,
|
|
174
|
+
const dots = (0, import_react3.useMemo)(() => {
|
|
175
175
|
const dots2 = [];
|
|
176
176
|
const matrix = generateMatrix(value, ecl);
|
|
177
177
|
const cellSize = size / matrix.length;
|
|
@@ -402,12 +402,12 @@ var CustomQRCode_default = CustomQRCode;
|
|
|
402
402
|
var import_si = require("react-icons/si");
|
|
403
403
|
|
|
404
404
|
// src/components/shared/Collapsible/Collapsible.tsx
|
|
405
|
-
var React3 = __toESM(require("react"));
|
|
406
405
|
var import_collapsible = require("@base-ui/react/collapsible");
|
|
407
406
|
var import_Collapsible = __toESM(require("./Collapsible.module-F4VIL5FH.module.css"));
|
|
407
|
+
var import_react4 = require("react");
|
|
408
408
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
409
409
|
var Collapsible = import_collapsible.Collapsible.Root;
|
|
410
|
-
var CollapsibleTrigger =
|
|
410
|
+
var CollapsibleTrigger = (0, import_react4.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
411
411
|
import_collapsible.Collapsible.Trigger,
|
|
412
412
|
{
|
|
413
413
|
ref,
|
|
@@ -416,7 +416,7 @@ var CollapsibleTrigger = React3.forwardRef(({ className, ...props }, ref) => /*
|
|
|
416
416
|
}
|
|
417
417
|
));
|
|
418
418
|
CollapsibleTrigger.displayName = "CollapsibleTrigger";
|
|
419
|
-
var CollapsibleContent =
|
|
419
|
+
var CollapsibleContent = (0, import_react4.forwardRef)(({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
420
420
|
import_collapsible.Collapsible.Panel,
|
|
421
421
|
{
|
|
422
422
|
ref,
|
|
@@ -427,7 +427,7 @@ var CollapsibleContent = React3.forwardRef(({ className, ...props }, ref) => /*
|
|
|
427
427
|
CollapsibleContent.displayName = "CollapsibleContent";
|
|
428
428
|
|
|
429
429
|
// src/components/shared/Avatar/Avatar.tsx
|
|
430
|
-
var
|
|
430
|
+
var import_react5 = require("react");
|
|
431
431
|
var import_Avatar = __toESM(require("./Avatar.module-AACAT34D.module.css"));
|
|
432
432
|
var import_lucide_react2 = require("lucide-react");
|
|
433
433
|
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
@@ -438,7 +438,7 @@ function Avatar({
|
|
|
438
438
|
alt,
|
|
439
439
|
theme = "light"
|
|
440
440
|
}) {
|
|
441
|
-
const [hasError, setHasError] = (0,
|
|
441
|
+
const [hasError, setHasError] = (0, import_react5.useState)(false);
|
|
442
442
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: import_Avatar.default.avatar, "data-theme": theme, children: src && !hasError ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
443
443
|
"img",
|
|
444
444
|
{
|
|
@@ -463,29 +463,27 @@ function WalletModal(props) {
|
|
|
463
463
|
CN_Modal,
|
|
464
464
|
theme = "light",
|
|
465
465
|
open,
|
|
466
|
-
onOpenChange
|
|
467
|
-
walletConnectUri,
|
|
468
|
-
onClearWalletConnectUri
|
|
466
|
+
onOpenChange
|
|
469
467
|
} = props;
|
|
470
|
-
const { walletStatus: { status }, isConnecting, connectorId, connectors, connectWallet, disconnectWallet } = (0, import_connector.useConnector)();
|
|
471
|
-
const [connectingConnectorId, setConnectingConnectorId] = (0,
|
|
472
|
-
const [isOtherWalletsOpen, setIsOtherWalletsOpen] = (0,
|
|
473
|
-
const [errorConnectorId, setErrorConnectorId] = (0,
|
|
474
|
-
const [errorMessage, setErrorMessage] = (0,
|
|
475
|
-
const [copied, setCopied] = (0,
|
|
476
|
-
const isClient = (0,
|
|
468
|
+
const { walletConnectUri, clearWalletConnectUri, walletStatus: { status }, isConnecting, connectorId, connectors, connectWallet, disconnectWallet } = (0, import_connector.useConnector)();
|
|
469
|
+
const [connectingConnectorId, setConnectingConnectorId] = (0, import_react6.useState)(null);
|
|
470
|
+
const [isOtherWalletsOpen, setIsOtherWalletsOpen] = (0, import_react6.useState)(false);
|
|
471
|
+
const [errorConnectorId, setErrorConnectorId] = (0, import_react6.useState)(null);
|
|
472
|
+
const [errorMessage, setErrorMessage] = (0, import_react6.useState)(null);
|
|
473
|
+
const [copied, setCopied] = (0, import_react6.useState)(false);
|
|
474
|
+
const isClient = (0, import_react6.useSyncExternalStore)(
|
|
477
475
|
() => () => {
|
|
478
476
|
},
|
|
479
477
|
() => true,
|
|
480
478
|
() => false
|
|
481
479
|
);
|
|
482
|
-
const recentlyConnectedConnectorId = (0,
|
|
480
|
+
const recentlyConnectedConnectorId = (0, import_react6.useSyncExternalStore)(
|
|
483
481
|
() => () => {
|
|
484
482
|
},
|
|
485
483
|
() => localStorage.getItem("recentlyConnectedConnectorId"),
|
|
486
484
|
() => null
|
|
487
485
|
);
|
|
488
|
-
(0,
|
|
486
|
+
(0, import_react6.useEffect)(() => {
|
|
489
487
|
if (status === "connected" && connectorId) {
|
|
490
488
|
localStorage.setItem("recentlyConnectedConnectorId", connectorId);
|
|
491
489
|
}
|
|
@@ -493,7 +491,7 @@ function WalletModal(props) {
|
|
|
493
491
|
const walletConnectConnector = (_a = connectors.find((c) => c.name === "WalletConnect")) != null ? _a : null;
|
|
494
492
|
const isWalletConnectFlow = !!walletConnectConnector && (connectingConnectorId === walletConnectConnector.id || status === "connecting" && connectorId === walletConnectConnector.id) || !!walletConnectUri;
|
|
495
493
|
function cancelConnection() {
|
|
496
|
-
|
|
494
|
+
clearWalletConnectUri == null ? void 0 : clearWalletConnectUri();
|
|
497
495
|
setConnectingConnectorId(null);
|
|
498
496
|
disconnectWallet().catch(() => {
|
|
499
497
|
});
|
|
@@ -507,7 +505,7 @@ function WalletModal(props) {
|
|
|
507
505
|
setConnectingConnectorId(connector.id);
|
|
508
506
|
try {
|
|
509
507
|
if (connector.name === "WalletConnect") {
|
|
510
|
-
|
|
508
|
+
clearWalletConnectUri == null ? void 0 : clearWalletConnectUri();
|
|
511
509
|
}
|
|
512
510
|
await connectWallet(connector.id);
|
|
513
511
|
localStorage.setItem("recentlyConnectedConnectorId", connector.id);
|
|
@@ -845,14 +843,14 @@ var WalletModal_default2 = WalletModal_default;
|
|
|
845
843
|
var import_clsx4 = __toESM(require("clsx"));
|
|
846
844
|
|
|
847
845
|
// src/components/shared/Menu/Menu.tsx
|
|
848
|
-
var React4 = __toESM(require("react"));
|
|
849
846
|
var import_menu = require("@base-ui/react/menu");
|
|
850
847
|
var import_Menu = __toESM(require("./Menu.module-6ATSLATI.module.css"));
|
|
848
|
+
var import_react7 = require("react");
|
|
851
849
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
852
850
|
var Menu = import_menu.Menu.Root;
|
|
853
851
|
var MenuPortal = import_menu.Menu.Portal;
|
|
854
852
|
var MenuGroup = import_menu.Menu.Group;
|
|
855
|
-
var MenuTrigger =
|
|
853
|
+
var MenuTrigger = (0, import_react7.forwardRef)(
|
|
856
854
|
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
857
855
|
import_menu.Menu.Trigger,
|
|
858
856
|
{
|
|
@@ -863,11 +861,11 @@ var MenuTrigger = React4.forwardRef(
|
|
|
863
861
|
)
|
|
864
862
|
);
|
|
865
863
|
MenuTrigger.displayName = "MenuTrigger";
|
|
866
|
-
var MenuPositioner =
|
|
864
|
+
var MenuPositioner = (0, import_react7.forwardRef)(
|
|
867
865
|
({ sideOffset = 8, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_menu.Menu.Positioner, { ref, sideOffset, ...props })
|
|
868
866
|
);
|
|
869
867
|
MenuPositioner.displayName = "MenuPositioner";
|
|
870
|
-
var MenuPopup =
|
|
868
|
+
var MenuPopup = (0, import_react7.forwardRef)(
|
|
871
869
|
({ className, theme, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
872
870
|
import_menu.Menu.Popup,
|
|
873
871
|
{
|
|
@@ -879,7 +877,7 @@ var MenuPopup = React4.forwardRef(
|
|
|
879
877
|
)
|
|
880
878
|
);
|
|
881
879
|
MenuPopup.displayName = "MenuPopup";
|
|
882
|
-
var MenuItem =
|
|
880
|
+
var MenuItem = (0, import_react7.forwardRef)(
|
|
883
881
|
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
884
882
|
import_menu.Menu.Item,
|
|
885
883
|
{
|
|
@@ -890,11 +888,11 @@ var MenuItem = React4.forwardRef(
|
|
|
890
888
|
)
|
|
891
889
|
);
|
|
892
890
|
MenuItem.displayName = "MenuItem";
|
|
893
|
-
var MenuSeparator =
|
|
891
|
+
var MenuSeparator = (0, import_react7.forwardRef)(
|
|
894
892
|
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_menu.Menu.Separator, { ref, className: `${import_Menu.default.separator} ${className || ""}`, ...props })
|
|
895
893
|
);
|
|
896
894
|
MenuSeparator.displayName = "MenuSeparator";
|
|
897
|
-
var MenuGroupLabel =
|
|
895
|
+
var MenuGroupLabel = (0, import_react7.forwardRef)(
|
|
898
896
|
({ className, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_menu.Menu.GroupLabel, { ref, className: `${import_Menu.default.groupLabel} ${className || ""}`, ...props })
|
|
899
897
|
);
|
|
900
898
|
MenuGroupLabel.displayName = "MenuGroupLabel";
|
|
@@ -903,13 +901,73 @@ MenuGroupLabel.displayName = "MenuGroupLabel";
|
|
|
903
901
|
var import_lucide_react5 = require("lucide-react");
|
|
904
902
|
|
|
905
903
|
// src/components/WalletDropdown/WalletDropdown.tsx
|
|
906
|
-
var
|
|
907
|
-
var
|
|
908
|
-
var
|
|
904
|
+
var import_react8 = require("react");
|
|
905
|
+
var import_kit2 = require("@solana/kit");
|
|
906
|
+
var import_WalletDropdown = __toESM(require("./WalletDropdown.module-DOK7CUOQ.module.css"));
|
|
907
|
+
var import_react9 = require("motion/react");
|
|
909
908
|
var import_lucide_react4 = require("lucide-react");
|
|
909
|
+
var import_connector3 = require("@solana/connector");
|
|
910
|
+
var import_clsx3 = require("clsx");
|
|
911
|
+
|
|
912
|
+
// src/utils/fetchBalance.tsx
|
|
913
|
+
var import_token = require("@solana-program/token");
|
|
910
914
|
var import_connector2 = require("@solana/connector");
|
|
911
915
|
var import_kit = require("@solana/kit");
|
|
912
|
-
|
|
916
|
+
async function getSolBalance(client, pubkey) {
|
|
917
|
+
let balance = 0;
|
|
918
|
+
try {
|
|
919
|
+
const rpcUrl = client.getRpcUrl();
|
|
920
|
+
if (!rpcUrl) {
|
|
921
|
+
console.error("RPC URL is not available from the ConnectorClient.");
|
|
922
|
+
return 0;
|
|
923
|
+
}
|
|
924
|
+
const pubkeyAddress = (0, import_connector2.address)(pubkey);
|
|
925
|
+
const rpc = (0, import_kit.createSolanaRpc)(rpcUrl);
|
|
926
|
+
const balanceResponse = await rpc.getBalance(pubkeyAddress).send();
|
|
927
|
+
balance = (0, import_connector2.lamportsToSol)(balanceResponse.value);
|
|
928
|
+
} catch (error) {
|
|
929
|
+
console.error("Error fetching SOL balance:", error);
|
|
930
|
+
} finally {
|
|
931
|
+
return balance;
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
async function getTokenBalance(client, pubkey, mintAddress) {
|
|
935
|
+
var _a;
|
|
936
|
+
let balance = 0;
|
|
937
|
+
try {
|
|
938
|
+
const rpcUrl = client.getRpcUrl();
|
|
939
|
+
if (!rpcUrl) {
|
|
940
|
+
console.error("RPC URL is not available from the ConnectorClient.");
|
|
941
|
+
return 0;
|
|
942
|
+
}
|
|
943
|
+
const pubkeyAddress = (0, import_connector2.address)(pubkey);
|
|
944
|
+
const mintPubkey = (0, import_connector2.address)(mintAddress);
|
|
945
|
+
const rpc = (0, import_kit.createSolanaRpc)(rpcUrl);
|
|
946
|
+
const mintInfo = await rpc.getAccountInfo(
|
|
947
|
+
mintPubkey,
|
|
948
|
+
{ encoding: "base64" }
|
|
949
|
+
).send();
|
|
950
|
+
const ownerProgram = (_a = mintInfo.value) == null ? void 0 : _a.owner;
|
|
951
|
+
if (!ownerProgram) {
|
|
952
|
+
throw new Error("Failed to fetch mint account info");
|
|
953
|
+
}
|
|
954
|
+
const tokenProgram = (0, import_connector2.address)(ownerProgram);
|
|
955
|
+
const [tokenPDA] = await (0, import_token.findAssociatedTokenPda)({
|
|
956
|
+
mint: mintPubkey,
|
|
957
|
+
owner: pubkeyAddress,
|
|
958
|
+
tokenProgram
|
|
959
|
+
});
|
|
960
|
+
const tokenBalance = await rpc.getTokenAccountBalance(tokenPDA).send();
|
|
961
|
+
if (tokenBalance.value) {
|
|
962
|
+
balance = parseFloat(tokenBalance.value.uiAmountString);
|
|
963
|
+
}
|
|
964
|
+
} catch (error) {
|
|
965
|
+
} finally {
|
|
966
|
+
return balance;
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
// src/components/WalletDropdown/WalletDropdown.tsx
|
|
913
971
|
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
914
972
|
var networkColor = {
|
|
915
973
|
"solana:mainnet": "#00c950",
|
|
@@ -918,13 +976,26 @@ var networkColor = {
|
|
|
918
976
|
"solana:localnet": "#ff3b3b"
|
|
919
977
|
};
|
|
920
978
|
function WalletDropdown(props) {
|
|
921
|
-
const client = (0,
|
|
922
|
-
const {
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
979
|
+
const client = (0, import_connector3.useConnectorClient)();
|
|
980
|
+
const {
|
|
981
|
+
CN_DropdownMenu,
|
|
982
|
+
theme = "light",
|
|
983
|
+
allowNetworkSwitch = true,
|
|
984
|
+
showSolBalance = true,
|
|
985
|
+
showDefaultToken
|
|
986
|
+
} = props;
|
|
987
|
+
const [view, setView] = (0, import_react8.useState)("wallet");
|
|
988
|
+
const [copied, setCopied] = (0, import_react8.useState)(false);
|
|
989
|
+
const { account, connector } = (0, import_connector3.useConnector)();
|
|
990
|
+
const fetchingSolBalance = (0, import_react8.useRef)(false);
|
|
991
|
+
const [isFetchingBalance, setIsFetchingBalance] = (0, import_react8.useState)(false);
|
|
992
|
+
const fetchingDefaultToken = (0, import_react8.useRef)(false);
|
|
993
|
+
const [isFetchingDefaultTokenBalance, setIsFetchingDefaultTokenBalance] = (0, import_react8.useState)(false);
|
|
994
|
+
const [solBalance, setSolBalance] = (0, import_react8.useState)(null);
|
|
995
|
+
const [defaultTokenBalance, setDefaultTokenBalance] = (0, import_react8.useState)(null);
|
|
996
|
+
const selectedAccount = account || "";
|
|
997
|
+
const walletName = (connector == null ? void 0 : connector.name) || "Unknown Wallet";
|
|
998
|
+
const walletIcon = (connector == null ? void 0 : connector.icon) || void 0;
|
|
928
999
|
const shortAddress = `${selectedAccount.slice(0, 4)}...${selectedAccount.slice(-4)}`;
|
|
929
1000
|
async function handleCopy() {
|
|
930
1001
|
try {
|
|
@@ -937,38 +1008,45 @@ function WalletDropdown(props) {
|
|
|
937
1008
|
}
|
|
938
1009
|
}
|
|
939
1010
|
async function fetchSolBalance() {
|
|
940
|
-
if (!client ||
|
|
1011
|
+
if (!client || fetchingSolBalance.current) return;
|
|
941
1012
|
setIsFetchingBalance(true);
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
setIsFetchingBalance(false);
|
|
955
|
-
fetching.current = false;
|
|
1013
|
+
fetchingSolBalance.current = true;
|
|
1014
|
+
const solBalance2 = await getSolBalance(client, selectedAccount);
|
|
1015
|
+
setSolBalance(solBalance2);
|
|
1016
|
+
setIsFetchingBalance(false);
|
|
1017
|
+
fetchingSolBalance.current = false;
|
|
1018
|
+
}
|
|
1019
|
+
async function fetchDefaultTokenBalance() {
|
|
1020
|
+
if (!showDefaultToken || !showDefaultToken.address || !client || fetchingDefaultToken.current) return;
|
|
1021
|
+
const isValidAddress = (0, import_kit2.isAddress)(showDefaultToken.address);
|
|
1022
|
+
if (!isValidAddress) {
|
|
1023
|
+
console.error("Invalid default token address:", showDefaultToken);
|
|
1024
|
+
return;
|
|
956
1025
|
}
|
|
1026
|
+
setIsFetchingDefaultTokenBalance(true);
|
|
1027
|
+
fetchingDefaultToken.current = true;
|
|
1028
|
+
const tokenBalance = await getTokenBalance(client, selectedAccount, showDefaultToken.address);
|
|
1029
|
+
setDefaultTokenBalance(tokenBalance);
|
|
1030
|
+
setIsFetchingDefaultTokenBalance(false);
|
|
1031
|
+
fetchingDefaultToken.current = false;
|
|
957
1032
|
}
|
|
958
|
-
(0,
|
|
1033
|
+
(0, import_react8.useEffect)(() => {
|
|
959
1034
|
if (showSolBalance && selectedAccount && client) {
|
|
960
1035
|
fetchSolBalance();
|
|
961
1036
|
}
|
|
962
|
-
|
|
1037
|
+
if (showDefaultToken && selectedAccount && client) {
|
|
1038
|
+
fetchDefaultTokenBalance();
|
|
1039
|
+
}
|
|
1040
|
+
}, [selectedAccount, client, showSolBalance, showDefaultToken]);
|
|
963
1041
|
if (view === "wallet") {
|
|
964
1042
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
965
|
-
|
|
1043
|
+
import_react9.motion.div,
|
|
966
1044
|
{
|
|
967
1045
|
initial: { opacity: 0 },
|
|
968
1046
|
animate: { opacity: 1 },
|
|
969
1047
|
exit: { opacity: 0 },
|
|
970
1048
|
transition: { duration: 0.2 },
|
|
971
|
-
className: (0, import_clsx3.clsx)(import_WalletDropdown.default.WalletDropdown,
|
|
1049
|
+
className: (0, import_clsx3.clsx)(import_WalletDropdown.default.WalletDropdown, CN_DropdownMenu),
|
|
972
1050
|
"data-theme": theme,
|
|
973
1051
|
children: [
|
|
974
1052
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: import_WalletDropdown.default.Header, children: [
|
|
@@ -1001,7 +1079,7 @@ function WalletDropdown(props) {
|
|
|
1001
1079
|
}
|
|
1002
1080
|
),
|
|
1003
1081
|
allowNetworkSwitch && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1004
|
-
|
|
1082
|
+
import_connector3.ClusterElement,
|
|
1005
1083
|
{
|
|
1006
1084
|
render: ({ cluster }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1007
1085
|
Button_default2,
|
|
@@ -1053,10 +1131,38 @@ function WalletDropdown(props) {
|
|
|
1053
1131
|
]
|
|
1054
1132
|
}
|
|
1055
1133
|
),
|
|
1056
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.balanceValue, children: isFetchingBalance ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.balanceLoading }) : solBalance !== null ? `${solBalance.toFixed(4)} SOL` : "-- SOL" })
|
|
1134
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.balanceValue, title: String(solBalance) || "0", children: isFetchingBalance ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.balanceLoading }) : solBalance !== null ? `${solBalance.toFixed(4)} SOL` : "-- SOL" })
|
|
1135
|
+
] }),
|
|
1136
|
+
showDefaultToken && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: import_WalletDropdown.default.balanceSection, children: [
|
|
1137
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1138
|
+
"div",
|
|
1139
|
+
{
|
|
1140
|
+
className: import_WalletDropdown.default.balanceHeader,
|
|
1141
|
+
children: [
|
|
1142
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: import_WalletDropdown.default.balanceLabel, children: "Balance" }),
|
|
1143
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1144
|
+
"button",
|
|
1145
|
+
{
|
|
1146
|
+
onClick: () => fetchDefaultTokenBalance(),
|
|
1147
|
+
disabled: isFetchingDefaultTokenBalance,
|
|
1148
|
+
title: "Refresh balance",
|
|
1149
|
+
className: import_WalletDropdown.default.refreshButton,
|
|
1150
|
+
"data-loading": isFetchingDefaultTokenBalance,
|
|
1151
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1152
|
+
import_lucide_react4.RefreshCw,
|
|
1153
|
+
{
|
|
1154
|
+
className: import_WalletDropdown.default.refreshIcon
|
|
1155
|
+
}
|
|
1156
|
+
)
|
|
1157
|
+
}
|
|
1158
|
+
)
|
|
1159
|
+
]
|
|
1160
|
+
}
|
|
1161
|
+
),
|
|
1162
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.balanceValue, title: String(defaultTokenBalance) || "0", children: isFetchingDefaultTokenBalance ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.balanceLoading }) : defaultTokenBalance !== null ? `${defaultTokenBalance.toFixed(4)} ${(showDefaultToken == null ? void 0 : showDefaultToken.symbol) || ""}` : `-- ${(showDefaultToken == null ? void 0 : showDefaultToken.symbol) || ""}` })
|
|
1057
1163
|
] }),
|
|
1058
1164
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1059
|
-
|
|
1165
|
+
import_connector3.DisconnectElement,
|
|
1060
1166
|
{
|
|
1061
1167
|
render: ({ disconnect, disconnecting }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1062
1168
|
Button_default2,
|
|
@@ -1078,15 +1184,14 @@ function WalletDropdown(props) {
|
|
|
1078
1184
|
);
|
|
1079
1185
|
}
|
|
1080
1186
|
if (view === "network") {
|
|
1081
|
-
console.count("Network view rendered");
|
|
1082
1187
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1083
|
-
|
|
1188
|
+
import_react9.motion.div,
|
|
1084
1189
|
{
|
|
1085
1190
|
initial: { opacity: 0 },
|
|
1086
1191
|
animate: { opacity: 1 },
|
|
1087
1192
|
exit: { opacity: 0 },
|
|
1088
1193
|
transition: { duration: 0.2 },
|
|
1089
|
-
className: (0, import_clsx3.clsx)(import_WalletDropdown.default.WalletDropdown,
|
|
1194
|
+
className: (0, import_clsx3.clsx)(import_WalletDropdown.default.WalletDropdown, CN_DropdownMenu),
|
|
1090
1195
|
"data-theme": theme,
|
|
1091
1196
|
children: [
|
|
1092
1197
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: import_WalletDropdown.default.NetworkHeader, children: [
|
|
@@ -1105,11 +1210,11 @@ function WalletDropdown(props) {
|
|
|
1105
1210
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: "Network Settings" })
|
|
1106
1211
|
] }),
|
|
1107
1212
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1108
|
-
|
|
1213
|
+
import_connector3.ClusterElement,
|
|
1109
1214
|
{
|
|
1110
1215
|
render: ({ cluster, clusters, setCluster }) => {
|
|
1111
1216
|
const currentClusterId = (cluster == null ? void 0 : cluster.id) || "solana:mainnet";
|
|
1112
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.networkOptions, children: clusters.map((network
|
|
1217
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: import_WalletDropdown.default.networkOptions, children: clusters.map((network) => {
|
|
1113
1218
|
const isSelected = currentClusterId === network.id;
|
|
1114
1219
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1115
1220
|
"div",
|
|
@@ -1163,10 +1268,11 @@ function ConnectButton(props) {
|
|
|
1163
1268
|
CN_ConnectButton,
|
|
1164
1269
|
connectText = "Connect Wallet",
|
|
1165
1270
|
connectingText = "Connecting...",
|
|
1166
|
-
showSolBalance = false
|
|
1271
|
+
showSolBalance = false,
|
|
1272
|
+
showDefaultToken
|
|
1167
1273
|
} = props;
|
|
1168
|
-
const [isModalOpen, setIsModalOpen] = (0,
|
|
1169
|
-
const { isConnected, isConnecting, account, connector, walletConnectUri, clearWalletConnectUri } = (0,
|
|
1274
|
+
const [isModalOpen, setIsModalOpen] = (0, import_react10.useState)(false);
|
|
1275
|
+
const { isConnected, isConnecting, account, connector, walletConnectUri, clearWalletConnectUri } = (0, import_connector4.useConnector)();
|
|
1170
1276
|
if (isConnected && account && connector) {
|
|
1171
1277
|
const shortAddress = `${account.slice(0, 4)}...${account.slice(-4)}`;
|
|
1172
1278
|
const walletIcon = connector.icon || void 0;
|
|
@@ -1197,13 +1303,11 @@ function ConnectButton(props) {
|
|
|
1197
1303
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MenuPortal, { children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MenuPositioner, { sideOffset: 8, align: "end", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(MenuPopup, { theme, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
1198
1304
|
WalletDropdown_default2,
|
|
1199
1305
|
{
|
|
1200
|
-
|
|
1201
|
-
selectedAccount: account,
|
|
1202
|
-
walletIcon,
|
|
1203
|
-
walletName: connector.name,
|
|
1306
|
+
CN_DropdownMenu,
|
|
1204
1307
|
allowNetworkSwitch: true,
|
|
1205
1308
|
theme,
|
|
1206
|
-
showSolBalance
|
|
1309
|
+
showSolBalance,
|
|
1310
|
+
showDefaultToken
|
|
1207
1311
|
}
|
|
1208
1312
|
) }) }) })
|
|
1209
1313
|
] });
|
|
@@ -1234,9 +1338,7 @@ function ConnectButton(props) {
|
|
|
1234
1338
|
{
|
|
1235
1339
|
theme,
|
|
1236
1340
|
open: isModalOpen,
|
|
1237
|
-
onOpenChange
|
|
1238
|
-
walletConnectUri,
|
|
1239
|
-
onClearWalletConnectUri: clearWalletConnectUri
|
|
1341
|
+
onOpenChange
|
|
1240
1342
|
}
|
|
1241
1343
|
)
|
|
1242
1344
|
] });
|