devlucem's picture
Add JS functionality to all buttons
f5f2bc2 verified
Raw History Blame Contribute Delete
9.34 kB
document.addEventListener('DOMContentLoaded', function() {
// Button event handlers
document.addEventListener('click', function(e) {
// Handle export button
if (e.target.closest('.export-btn')) {
alert('Exporting data... This would trigger a CSV download in a real application.');
}
// Handle filter button
if (e.target.closest('.filter-btn')) {
alert('Opening filters... This would show filter options in a real application.');
}
// Handle pagination buttons
if (e.target.closest('.pagination-btn')) {
const btn = e.target.closest('.pagination-btn');
if (!btn.classList.contains('bg-blue-600')) {
alert(`Loading page ${btn.textContent}... This would load new data in a real application.`);
}
}
// Handle time period selector
if (e.target.closest('.time-period-select')) {
const select = e.target.closest('.time-period-select');
alert(`Changed time period to ${select.value}. This would reload data with new time range in a real application.`);
}
// Handle view transaction button
if (e.target.closest('.view-btn')) {
alert('Viewing transaction details... This would open a modal in a real application.');
}
// Handle more options button
if (e.target.closest('.options-btn')) {
alert('Showing more options... This would open a dropdown menu in a real application.');
}
});
// Network selector handler
document.addEventListener('change', function(e) {
if (e.target.classList.contains('asset-select')) {
alert(`Changed asset to ${e.target.value}. This would update the chart in a real application.`);
}
});
// Sample transaction data (would be replaced with actual data in a real app)
const transactions = [
{
date: '2025-01-02 16:07:48 UTC',
type: 'Product Checkout',
product: 'Activation Upgrade',
network: 'Base',
asset: 'ETH',
amount: '$17.97',
status: 'Completed'
},
{
date: '2025-01-04 18:28:43 UTC',
type: 'Product Checkout',
product: 'Activation Upgrade',
network: 'Polygon',
asset: 'MATIC',
amount: '$5.99',
status: 'Completed'
},
{
date: '2025-01-05 07:30:34 UTC',
type: 'Product Checkout',
product: 'Activation Upgrade',
network: 'Base',
asset: 'ETH',
amount: '$17.97',
status: 'Completed'
},
{
date: '2025-01-05 13:00:08 UTC',
type: 'Product Checkout',
product: 'Activation Upgrade',
network: 'Polygon',
asset: 'USDC',
amount: '$5.99',
status: 'Completed'
},
{
date: '2025-01-06 05:21:18 UTC',
type: 'Product Checkout',
product: 'Activation Upgrade',
network: 'Polygon',
asset: 'MATIC',
amount: '$5.99',
status: 'Completed'
}
];
// Populate transaction table
const tableBody = document.getElementById('transactionTableBody');
transactions.forEach(tx => {
const row = document.createElement('tr');
const statusClass = tx.status === 'Completed' ?
'bg-green-100 text-green-800' :
'bg-yellow-100 text-yellow-800';
row.innerHTML = `
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${formatDate(tx.date)}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${tx.type}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-blue-100 text-blue-800">${tx.network}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">${tx.asset}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">${tx.amount}</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${statusClass}">${tx.status}</span>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
<button class="text-blue-600 hover:text-blue-900 mr-2 view-btn">
<i data-feather="eye" class="w-4 h-4"></i>
</button>
<button class="text-gray-600 hover:text-gray-900 options-btn">
<i data-feather="more-horizontal" class="w-4 h-4"></i>
</button>
</td>
`;
tableBody.appendChild(row);
});
// Initialize charts
initCharts();
// Refresh feather icons after dynamic content is added
feather.replace();
});
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleDateString() + ' ' + date.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
}
function initCharts() {
// Network Volume Chart
const networkCtx = document.getElementById('networkChart').getContext('2d');
new Chart(networkCtx, {
type: 'doughnut',
data: {
labels: ['Polygon', 'Base', 'Ethereum'],
datasets: [{
data: [856.42, 348.45, 0],
backgroundColor: [
'#8247e5',
'#0052ff',
'#627eea'
],
borderWidth: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
cutout: '70%',
plugins: {
legend: {
position: 'right',
labels: {
boxWidth: 12,
padding: 20,
usePointStyle: true,
pointStyle: 'circle'
}
}
}
}
});
// Timeline Chart
const timelineCtx = document.getElementById('timelineChart').getContext('2d');
new Chart(timelineCtx, {
type: 'line',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct'],
datasets: [
{
label: 'Transactions',
data: [12, 19, 15, 25, 22, 18, 24, 28, 16, 20],
borderColor: '#3b82f6',
backgroundColor: 'rgba(59, 130, 246, 0.05)',
borderWidth: 2,
tension: 0.3,
fill: true,
pointBackgroundColor: '#ffffff',
pointBorderColor: '#3b82f6',
pointBorderWidth: 2,
pointRadius: 4,
pointHoverRadius: 6
},
{
label: 'Volume (USD)',
data: [85, 120, 95, 150, 130, 110, 160, 180, 105, 145],
borderColor: '#8b5cf6',
backgroundColor: 'rgba(139, 92, 246, 0.05)',
borderWidth: 2,
tension: 0.3,
fill: true,
pointBackgroundColor: '#ffffff',
pointBorderColor: '#8b5cf6',
pointBorderWidth: 2,
pointRadius: 4,
pointHoverRadius: 6
}
]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: true,
grid: {
drawBorder: false
}
},
x: {
grid: {
display: false
}
}
},
plugins: {
legend: {
position: 'top',
align: 'end',
labels: {
boxWidth: 12,
padding: 16,
usePointStyle: true,
pointStyle: 'circle'
}
},
tooltip: {
backgroundColor: '#1e293b',
titleFont: {
size: 14,
weight: 'bold'
},
bodyFont: {
size: 12
},
padding: 12,
usePointStyle: true,
callbacks: {
labelColor: function(context) {
return {
borderColor: 'transparent',
backgroundColor: context.dataset.borderColor,
borderRadius: 2
};
}
}
}
}
}
});
}