| … | … | @@ -1625,8 +1625,14 @@ function updateWalletView() { |
| 1625 | 1625 | } |
| 1626 | 1626 | |
| 1627 | 1627 | // Load wallet addresses into the selector dropdown |
| 1628 | // Flag to prevent onchange cascade when programmatically updating selector |
| 1629 | let isUpdatingAddressSelector = false |
| 1630 | |
| 1628 | 1631 | async function loadWalletAddressSelector() { |
| 1629 | 1632 | const select = document.getElementById('wallet-address-select') |
| 1633 | |
| 1634 | // Set flag to prevent onchange from firing during programmatic update |
| 1635 | isUpdatingAddressSelector = true |
| 1630 | 1636 | select.innerHTML = '<option value="">Loading...</option>' |
| 1631 | 1637 | |
| 1632 | 1638 | try { |
| … | … | @@ -1637,11 +1643,13 @@ async function loadWalletAddressSelector() { |
| 1637 | 1643 | |
| 1638 | 1644 | if (data.error) { |
| 1639 | 1645 | select.innerHTML = '<option value="">Error loading addresses</option>' |
| 1646 | isUpdatingAddressSelector = false |
| 1640 | 1647 | return |
| 1641 | 1648 | } |
| 1642 | 1649 | |
| 1643 | 1650 | if (data.addresses.length === 0) { |
| 1644 | 1651 | select.innerHTML = '<option value="">No addresses yet</option>' |
| 1652 | isUpdatingAddressSelector = false |
| 1645 | 1653 | return |
| 1646 | 1654 | } |
| 1647 | 1655 | |
| … | … | @@ -1661,10 +1669,16 @@ async function loadWalletAddressSelector() { |
| 1661 | 1669 | console.error('Load address selector error:', err) |
| 1662 | 1670 | select.innerHTML = '<option value="">Failed to load</option>' |
| 1663 | 1671 | } |
| 1672 | |
| 1673 | // Clear flag after a tick to allow DOM to settle |
| 1674 | setTimeout(() => { isUpdatingAddressSelector = false }, 0) |
| 1664 | 1675 | } |
| 1665 | 1676 | |
| 1666 | 1677 | // Handle wallet address selector change |
| 1667 | 1678 | async function onWalletAddressChange() { |
| 1679 | // Ignore programmatic updates to prevent cascade |
| 1680 | if (isUpdatingAddressSelector) return |
| 1681 | |
| 1668 | 1682 | const select = document.getElementById('wallet-address-select') |
| 1669 | 1683 | const selectedIndex = parseInt(select.value) |
| 1670 | 1684 | |
| … | … | @@ -1686,8 +1700,12 @@ async function onWalletAddressChange() { |
| 1686 | 1700 | |
| 1687 | 1701 | showSuccess('Wallet address changed!') |
| 1688 | 1702 | |
| 1689 | | // Reload balance, QR code, and transactions |
| 1690 | | await loadCurrentBalance() |
| 1703 | // Reload balance - use unified view for Ethereum, standard for others |
| 1704 | if (selectedChain === 'ethereum') { |
| 1705 | await loadEthereumBalances() |
| 1706 | } else { |
| 1707 | await loadCurrentBalance() |
| 1708 | } |
| 1691 | 1709 | await loadCurrentQRCode() |
| 1692 | 1710 | await loadTransactions() |
| 1693 | 1711 | |