|
1 | | -import { useState } from "react"; |
2 | 1 | import { |
3 | | - Button, |
4 | | - Text, |
5 | | - Modal, |
6 | | - Profile, |
7 | | - Icon, |
8 | | - Tooltip, |
9 | | -} from "@stellar/design-system"; |
10 | | -import { useWallet } from "../hooks/useWallet"; |
11 | | -import { connectWallet, disconnectWallet } from "../util/wallet"; |
| 2 | + Button, |
| 3 | + Text, |
| 4 | + Modal, |
| 5 | + Profile, |
| 6 | + Icon, |
| 7 | + Tooltip, |
| 8 | +} from "@stellar/design-system" |
| 9 | +import { useState } from "react" |
| 10 | +import { useWallet } from "../hooks/useWallet" |
| 11 | +import { connectWallet, disconnectWallet } from "../util/wallet" |
12 | 12 |
|
13 | 13 | export const WalletButton = () => { |
14 | | - const [showDisconnectModal, setShowDisconnectModal] = useState(false); |
15 | | - const [isWarningTooltipVisible, setIsWarningTooltipVisible] = useState(false); |
16 | | - const { address, isPending, balances, walletWarnings } = useWallet(); |
17 | | - const buttonLabel = isPending ? "Loading..." : "Connect"; |
| 14 | + const [showDisconnectModal, setShowDisconnectModal] = useState(false) |
| 15 | + const [isWarningTooltipVisible, setIsWarningTooltipVisible] = useState(false) |
| 16 | + const { address, isPending, balances, walletWarnings } = useWallet() |
| 17 | + const buttonLabel = isPending ? "Loading..." : "Connect" |
18 | 18 |
|
19 | | - // Build warning message based on wallet issues |
20 | | - const getWarningMessage = () => { |
21 | | - const warnings: string[] = []; |
22 | | - if (walletWarnings.popupAlways) { |
23 | | - warnings.push("This wallet triggers a popup on every interaction"); |
24 | | - } |
25 | | - if (walletWarnings.noGetNetworkSupport) { |
26 | | - warnings.push("This wallet doesn't support network detection"); |
27 | | - } |
28 | | - return warnings.join(". "); |
29 | | - }; |
| 19 | + // Build warning message based on wallet issues |
| 20 | + const getWarningMessage = () => { |
| 21 | + const warnings: string[] = [] |
| 22 | + if (walletWarnings.popupAlways) { |
| 23 | + warnings.push("This wallet triggers a popup on every interaction") |
| 24 | + } |
| 25 | + if (walletWarnings.noGetNetworkSupport) { |
| 26 | + warnings.push("This wallet doesn't support network detection") |
| 27 | + } |
| 28 | + return warnings.join(". ") |
| 29 | + } |
30 | 30 |
|
31 | | - // Handle click on warning icon - open help URL if available |
32 | | - const handleWarningClick = () => { |
33 | | - if (walletWarnings.helpUrl) { |
34 | | - window.open(walletWarnings.helpUrl, "_blank", "noopener,noreferrer"); |
35 | | - } |
36 | | - }; |
| 31 | + // Handle click on warning icon - open help URL if available |
| 32 | + const handleWarningClick = () => { |
| 33 | + if (walletWarnings.helpUrl) { |
| 34 | + window.open(walletWarnings.helpUrl, "_blank", "noopener,noreferrer") |
| 35 | + } |
| 36 | + } |
37 | 37 |
|
38 | | - if (!address) { |
39 | | - return ( |
40 | | - <Button variant="primary" size="md" onClick={() => void connectWallet()}> |
41 | | - {buttonLabel} |
42 | | - </Button> |
43 | | - ); |
44 | | - } |
| 38 | + if (!address) { |
| 39 | + return ( |
| 40 | + <Button variant="primary" size="md" onClick={() => void connectWallet()}> |
| 41 | + {buttonLabel} |
| 42 | + </Button> |
| 43 | + ) |
| 44 | + } |
45 | 45 |
|
46 | 46 | return ( |
47 | 47 | <div |
@@ -93,61 +93,61 @@ export const WalletButton = () => { |
93 | 93 | </Modal> |
94 | 94 | </div> |
95 | 95 |
|
96 | | - <div style={{ position: "relative" }}> |
97 | | - <Profile |
98 | | - publicAddress={address} |
99 | | - size="md" |
100 | | - isShort |
101 | | - onClick={() => setShowDisconnectModal(true)} |
102 | | - /> |
| 96 | + <div style={{ position: "relative" }}> |
| 97 | + <Profile |
| 98 | + publicAddress={address} |
| 99 | + size="md" |
| 100 | + isShort |
| 101 | + onClick={() => setShowDisconnectModal(true)} |
| 102 | + /> |
103 | 103 |
|
104 | | - {walletWarnings.hasWarnings && ( |
105 | | - <div |
106 | | - onMouseEnter={() => setIsWarningTooltipVisible(true)} |
107 | | - onMouseLeave={() => setIsWarningTooltipVisible(false)} |
108 | | - style={{ |
109 | | - position: "absolute", |
110 | | - top: "-6px", |
111 | | - right: "-6px", |
112 | | - zIndex: 1, |
113 | | - }} |
114 | | - > |
115 | | - <Tooltip |
116 | | - isVisible={isWarningTooltipVisible} |
117 | | - isContrast |
118 | | - placement="bottom" |
119 | | - triggerEl={ |
120 | | - <div |
121 | | - onClick={handleWarningClick} |
122 | | - style={{ |
123 | | - display: "flex", |
124 | | - alignItems: "center", |
125 | | - justifyContent: "center", |
126 | | - cursor: "pointer", |
127 | | - backgroundColor: "var(--color-gray-00, #fff)", |
128 | | - borderRadius: "50%", |
129 | | - padding: "3px", |
130 | | - border: "2px solid var(--color-yellow-60, #f0ad4e)", |
131 | | - boxShadow: "0 1px 3px rgba(0, 0, 0, 0.2)", |
132 | | - }} |
133 | | - > |
134 | | - <Icon.AlertTriangle |
135 | | - style={{ |
136 | | - color: "var(--color-yellow-60, #f0ad4e)", |
137 | | - width: "12px", |
138 | | - height: "12px", |
139 | | - }} |
140 | | - /> |
141 | | - </div> |
142 | | - } |
143 | | - > |
144 | | - <div style={{ maxWidth: "15em" }}> |
145 | | - {getWarningMessage()}. Click to learn more about this issue. |
146 | | - </div> |
147 | | - </Tooltip> |
148 | | - </div> |
149 | | - )} |
150 | | - </div> |
151 | | - </div> |
152 | | - ); |
153 | | -}; |
| 104 | + {walletWarnings.hasWarnings && ( |
| 105 | + <div |
| 106 | + onMouseEnter={() => setIsWarningTooltipVisible(true)} |
| 107 | + onMouseLeave={() => setIsWarningTooltipVisible(false)} |
| 108 | + style={{ |
| 109 | + position: "absolute", |
| 110 | + top: "-6px", |
| 111 | + right: "-6px", |
| 112 | + zIndex: 1, |
| 113 | + }} |
| 114 | + > |
| 115 | + <Tooltip |
| 116 | + isVisible={isWarningTooltipVisible} |
| 117 | + isContrast |
| 118 | + placement="bottom" |
| 119 | + triggerEl={ |
| 120 | + <div |
| 121 | + onClick={handleWarningClick} |
| 122 | + style={{ |
| 123 | + display: "flex", |
| 124 | + alignItems: "center", |
| 125 | + justifyContent: "center", |
| 126 | + cursor: "pointer", |
| 127 | + backgroundColor: "var(--color-gray-00, #fff)", |
| 128 | + borderRadius: "50%", |
| 129 | + padding: "3px", |
| 130 | + border: "2px solid var(--color-yellow-60, #f0ad4e)", |
| 131 | + boxShadow: "0 1px 3px rgba(0, 0, 0, 0.2)", |
| 132 | + }} |
| 133 | + > |
| 134 | + <Icon.AlertTriangle |
| 135 | + style={{ |
| 136 | + color: "var(--color-yellow-60, #f0ad4e)", |
| 137 | + width: "12px", |
| 138 | + height: "12px", |
| 139 | + }} |
| 140 | + /> |
| 141 | + </div> |
| 142 | + } |
| 143 | + > |
| 144 | + <div style={{ maxWidth: "15em" }}> |
| 145 | + {getWarningMessage()}. Click to learn more about this issue. |
| 146 | + </div> |
| 147 | + </Tooltip> |
| 148 | + </div> |
| 149 | + )} |
| 150 | + </div> |
| 151 | + </div> |
| 152 | + ) |
| 153 | +} |
0 commit comments