| … | … | @@ -1299,19 +1299,22 @@ async function sendToContact(contactId) { |
| 1299 | 1299 | return |
| 1300 | 1300 | } |
| 1301 | 1301 | |
| 1302 | | // Get first available address |
| 1303 | | let chain = null |
| 1302 | // Get first available address ID |
| 1303 | let addressId = null |
| 1304 | 1304 | if (contact.addresses && Array.isArray(contact.addresses) && contact.addresses.length > 0) { |
| 1305 | | chain = contact.addresses[0].chain |
| 1306 | | } else if (contact.chain) { |
| 1307 | | chain = contact.chain |
| 1305 | addressId = contact.addresses[0].id |
| 1308 | 1306 | } else { |
| 1307 | // Old format: no ID, pass null and let sendToContactAddress handle it |
| 1308 | addressId = null |
| 1309 | } |
| 1310 | |
| 1311 | if (!addressId && !contact.address) { |
| 1309 | 1312 | showError('Contact has no addresses') |
| 1310 | 1313 | return |
| 1311 | 1314 | } |
| 1312 | 1315 | |
| 1313 | | // Use the chain-specific function |
| 1314 | | await sendToContactAddress(contactId, chain) |
| 1316 | // Use the address-specific function |
| 1317 | await sendToContactAddress(contactId, addressId) |
| 1315 | 1318 | } |
| 1316 | 1319 | |
| 1317 | 1320 | function escapeHtml(text) { |
| … | … | @@ -1608,9 +1611,10 @@ async function onWalletAddressChange() { |
| 1608 | 1611 | |
| 1609 | 1612 | showSuccess('Wallet address changed!') |
| 1610 | 1613 | |
| 1611 | | // Reload balance and QR code |
| 1614 | // Reload balance, QR code, and transactions |
| 1612 | 1615 | await loadCurrentBalance() |
| 1613 | 1616 | await loadCurrentQRCode() |
| 1617 | await loadTransactions() |
| 1614 | 1618 | |
| 1615 | 1619 | // Reload the selector to update the star marker |
| 1616 | 1620 | await loadWalletAddressSelector() |
| … | … | @@ -1885,14 +1889,16 @@ async function loadTransactions() { |
| 1885 | 1889 | list.innerHTML = '<div class="spinner"></div>' |
| 1886 | 1890 | |
| 1887 | 1891 | try { |
| 1888 | | // Load transactions and contacts in parallel |
| 1889 | | const [txRes, contactsRes] = await Promise.all([ |
| 1892 | // Load transactions, contacts, and current address in parallel |
| 1893 | const [txRes, contactsRes, currentAddrRes] = await Promise.all([ |
| 1890 | 1894 | authFetch(`${API_BASE}/transactions/all`), |
| 1891 | | authFetch(`${API_BASE}/contacts`) |
| 1895 | authFetch(`${API_BASE}/contacts`), |
| 1896 | authFetch(`${API_BASE}/address/${selectedNetwork}-${selectedCurrency}`) |
| 1892 | 1897 | ]) |
| 1893 | 1898 | |
| 1894 | 1899 | const data = await txRes.json() |
| 1895 | 1900 | const contactsData = await contactsRes.json() |
| 1901 | const currentAddrData = await currentAddrRes.json() |
| 1896 | 1902 | |
| 1897 | 1903 | if (data.error) { |
| 1898 | 1904 | list.innerHTML = '<div class="empty-state">Error loading transactions</div>' |
| … | … | @@ -1904,6 +1910,9 @@ async function loadTransactions() { |
| 1904 | 1910 | return |
| 1905 | 1911 | } |
| 1906 | 1912 | |
| 1913 | // Get the currently selected address |
| 1914 | const currentAddress = currentAddrData.address ? currentAddrData.address.toLowerCase() : null |
| 1915 | |
| 1907 | 1916 | // Build address-to-contact lookup |
| 1908 | 1917 | const contacts = contactsData.contacts || [] |
| 1909 | 1918 | const addressToContact = {} |
| … | … | @@ -1920,9 +1929,22 @@ async function loadTransactions() { |
| 1920 | 1929 | } |
| 1921 | 1930 | } |
| 1922 | 1931 | |
| 1923 | | // Filter by selected network AND selected currency |
| 1932 | // Filter by selected network, selected currency, AND current wallet address |
| 1924 | 1933 | const filtered = data.transactions.filter(tx => { |
| 1925 | | return tx.network === selectedNetwork && tx.chain === selectedCurrency |
| 1934 | // Must match network and chain |
| 1935 | if (tx.network !== selectedNetwork || tx.chain !== selectedCurrency) { |
| 1936 | return false |
| 1937 | } |
| 1938 | |
| 1939 | // Must involve the currently selected address (either as sender or receiver) |
| 1940 | if (currentAddress) { |
| 1941 | const fromAddr = tx.from.toLowerCase() |
| 1942 | const toAddr = tx.to.toLowerCase() |
| 1943 | return fromAddr === currentAddress || toAddr === currentAddress |
| 1944 | } |
| 1945 | |
| 1946 | // If no current address, show all for this chain (fallback) |
| 1947 | return true |
| 1926 | 1948 | }) |
| 1927 | 1949 | |
| 1928 | 1950 | if (filtered.length === 0) { |