1// Fetch data from the API 2async function fetchTransactionData() { 3 const query = `{ 4 swapsForToken(token: "kdlaunch.kdswap-token", limit: 50, offset: 1) { 5 id 6 timestamp 7 token0Amount 8 token1Amount 9 intervalStamp 10 token0 { 11 tokenSymbol 12 icon 13 validated 14 } 15 token1 { 16 tokenSymbol 17 icon 18 validated 19 } 20 account 21 } 22 }`; 23 24 try { 25 const response = await fetch('https://api.kdswap.exchange/graphql', { 26 method: 'POST', 27 headers: { 'Content-Type': 'application/json' }, 28 body: JSON.stringify({ 29 query: query 30 }) 31 }); 32 33 const responseData = await response.json(); 34 const transactions = responseData.data.swapsForToken; 35 36 // Update the table with fetched data 37 updateTransactionTable(transactions); 38 } catch (error) { 39 console.error('Error fetching transaction data:', error); 40 } 41} 42 43// Function to format date as relative time 44function formatRelativeTime(timestamp) { 45 const currentDate = new Date(); 46 const transactionDate = new Date(timestamp); 47 const timeDifference = currentDate - transactionDate; 48 const minutesAgo = Math.floor(timeDifference / (1000 * 60)); 49 50 if (minutesAgo < 60) { 51 return `${minutesAgo}m ago`; 52 } else { 53 const hoursAgo = Math.floor(minutesAgo / 60); 54 return `${hoursAgo}h ago`; 55 } 56} 57 58// Update the table with transaction data 59function updateTransactionTable(transactions) { 60 const tableBody = document.getElementById('recordTableBody'); 61 62 // Clear existing rows 63 tableBody.innerHTML = ''; 64 65 // Specify the hash for which you want to replace the account text 66 const targetHash = 'k:f8c01f1b062ebccc7164dd61479a655b9a6373bb2642904b2b1617230cdc51cc'; 67 68 // Populate the table with new data 69 transactions.forEach(transaction => { 70 const row = document.createElement('tr'); 71 72 // Determine the type based on token0 symbol 73 const transactionType = transaction.token0.tokenSymbol === 'KDA' ? 'BUY' : 'SELL'; 74 75 // Display only the first 3 and last 4 characters of the account with dots in the middle 76 const truncatedAccount = `${transaction.account.slice(0, 5)}...`; 77 78 // Check if the account matches the target hash 79 if (transaction.account === targetHash) { 80 // If it matches, set text to 'MW' and apply red color 81 row.innerHTML = ` 82 <td>${formatRelativeTime(transaction.timestamp)}</td> 83 <td class="${transactionType.toLowerCase()}">${transactionType}</td> 84 <td>${formatTokenInfo(transaction.token0, transaction.token0Amount)}</td> 85 <td>${formatTokenInfo(transaction.token1, transaction.token1Amount)}</td> 86 <td><a href="https://kdaexplorer.com/account/${transaction.account}" target="_blank" style="color: red; font-weight: bold;">MW</a></td> 87 `; 88 } else { 89 // If it doesn't match, proceed with the regular display 90 row.innerHTML = ` 91 <td>${formatRelativeTime(transaction.timestamp)}</td> 92 <td class="${transactionType.toLowerCase()}">${transactionType}</td> 93 <td>${formatTokenInfo(transaction.token0, transaction.token0Amount)}</td> 94 <td>${formatTokenInfo(transaction.token1, transaction.token1Amount)}</td> 95 <td><a href="https://kdaexplorer.com/account/${transaction.account}" target="_blank">${truncatedAccount}</a></td> 96 `; 97 } 98 99 tableBody.appendChild(row); 100 }); 101} 102 103 104// Function to format date 105function formatDate(timestamp) { 106 const date = new Date(timestamp); 107 108 const options = { 109 year: 'numeric', 110 month: 'numeric', 111 day: 'numeric', 112 hour: 'numeric', 113 minute: 'numeric', 114 second: 'numeric', 115 hour12: true, 116 }; 117
118 return date.toLocaleString(undefined, options); 119} 120 121// Function to format token information (symbol, icon, and amount) 122function formatTokenInfo(token, amount) { 123 // Round the amount to 2 decimal places 124 const roundedAmount = parseFloat(amount).toFixed(2); 125 126 // Use custom icons for KDA and WIZA 127 const customIcons = { 128 'KDA': 'https://swap.ecko.finance/images/crypto/kda-crypto.svg', 129 'WIZA': 'https://assets.kdlaunch.com/tokens/wiza.jpg' 130 }; 131 132 // Check if the token has a custom icon 133 const customIcon = customIcons[token.tokenSymbol]; 134 135 // If a custom icon exists, use it; otherwise, use the API icon 136 const iconSrc = customIcon ? customIcon : token.icon; 137 138 return `<img src="${iconSrc}" alt="${token.tokenSymbol}" class="token-logo"> ${roundedAmount} $${token.tokenSymbol}`; 139} 140 141// Fetch transaction data on page load 142document.addEventListener("DOMContentLoaded", fetchTransactionData);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.