|
1 | 1 | import React, { useEffect, useState } from 'react'; |
2 | | -import { Button, notification, Dropdown, Menu } from 'antd'; |
| 2 | +import { Button, notification, Dropdown } from 'antd'; |
3 | 3 | import { WalletOutlined, DisconnectOutlined, CopyOutlined, HomeOutlined } from '@ant-design/icons'; |
4 | 4 | import styled from 'styled-components'; |
5 | 5 | import { useWeb3, disconnectWallet as disconnectFromContext } from '../context/Web3Context'; |
@@ -263,26 +263,38 @@ const Header: React.FC = () => { |
263 | 263 | window.location.href = '#'; |
264 | 264 | }; |
265 | 265 |
|
266 | | - const walletMenu = ( |
267 | | - <Menu> |
268 | | - {selectedWalletName && ( |
269 | | - <> |
270 | | - <Menu.Item key="wallet" disabled style={{ cursor: 'default' }}> |
271 | | - <span style={{ color: '#667eea', fontWeight: 600 }}> |
272 | | - {selectedWalletName} |
273 | | - </span> |
274 | | - </Menu.Item> |
275 | | - <Menu.Divider /> |
276 | | - </> |
277 | | - )} |
278 | | - <Menu.Item key="copy" onClick={copyAddress} icon={<CopyOutlined />}> |
279 | | - Copy Address |
280 | | - </Menu.Item> |
281 | | - <Menu.Item key="disconnect" onClick={handleDisconnect} icon={<DisconnectOutlined />}> |
282 | | - Disconnect |
283 | | - </Menu.Item> |
284 | | - </Menu> |
285 | | - ); |
| 266 | + const getMenuItems = () => { |
| 267 | + const items: any[] = []; |
| 268 | + |
| 269 | + if (selectedWalletName) { |
| 270 | + items.push({ |
| 271 | + key: 'wallet', |
| 272 | + disabled: true, |
| 273 | + label: ( |
| 274 | + <span style={{ color: '#667eea', fontWeight: 600 }}> |
| 275 | + {selectedWalletName} |
| 276 | + </span> |
| 277 | + ), |
| 278 | + }); |
| 279 | + items.push({ type: 'divider' }); |
| 280 | + } |
| 281 | + |
| 282 | + items.push({ |
| 283 | + key: 'copy', |
| 284 | + icon: <CopyOutlined />, |
| 285 | + label: 'Copy Address', |
| 286 | + onClick: copyAddress, |
| 287 | + }); |
| 288 | + |
| 289 | + items.push({ |
| 290 | + key: 'disconnect', |
| 291 | + icon: <DisconnectOutlined />, |
| 292 | + label: 'Disconnect', |
| 293 | + onClick: handleDisconnect, |
| 294 | + }); |
| 295 | + |
| 296 | + return items; |
| 297 | + }; |
286 | 298 |
|
287 | 299 | return ( |
288 | 300 | <> |
@@ -310,7 +322,7 @@ const Header: React.FC = () => { |
310 | 322 | Connect Wallet |
311 | 323 | </Button> |
312 | 324 | ) : ( |
313 | | - <Dropdown overlay={walletMenu} trigger={['click']}> |
| 325 | + <Dropdown menu={{ items: getMenuItems() }} trigger={['click']}> |
314 | 326 | <AccountDisplay> |
315 | 327 | {networkName && ( |
316 | 328 | <NetworkBadge color={networkColor}> |
|
0 commit comments