Add Alt+W shortcut to reset wallet address and chart

Implemented a keyboard event listener for Alt+W to reset the wallet address, clear chart data, and redirect to the configuration page with a confirmation dialog. Added a fallback function for wallet reset if chart data clearing fails. Updated the chart's Y-axis label to 'HASHRATE (TH/S)' and commented out the theme toggle button in the HTML for cleaner implementation.
This commit is contained in:
DJObleezy 2025-04-26 20:44:36 -07:00
parent b4465e5a5c
commit 744ed27279
2 changed files with 95 additions and 3 deletions

View File

@ -2212,6 +2212,98 @@ function resetDashboardChart() {
}
}
// Add keyboard event listener for Alt+W to reset wallet address
$(document).keydown(function (event) {
// Check if Alt+W is pressed (key code 87 is 'W')
if (event.altKey && event.keyCode === 87) {
resetWalletAddress();
// Prevent default browser behavior
event.preventDefault();
}
});
// Function to reset wallet address in configuration and clear chart data
function resetWalletAddress() {
if (confirm("Are you sure you want to reset your wallet address? This will also clear all chart data and redirect you to the configuration page.")) {
// First clear chart data using the existing API endpoint
$.ajax({
url: '/api/reset-chart-data',
method: 'POST',
success: function () {
console.log("Chart data reset successfully");
// Then reset the chart display locally
if (trendChart) {
trendChart.data.labels = [];
trendChart.data.datasets[0].data = [];
trendChart.update('none');
}
// Then reset wallet address
fetch('/api/config')
.then(response => response.json())
.then(config => {
// Reset the wallet address to default
config.wallet = "yourwallethere";
// Save the updated configuration
return fetch('/api/config', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(config)
});
})
.then(response => response.json())
.then(data => {
console.log("Wallet address reset successfully:", data);
// Also clear arrow indicator states
arrowIndicator.clearAll();
// Redirect to the boot page for reconfiguration
window.location.href = window.location.origin + "/";
})
.catch(error => {
console.error("Error resetting wallet address:", error);
alert("There was an error resetting your wallet address. Please try again.");
});
},
error: function (xhr, status, error) {
console.error("Error clearing chart data:", error);
// Continue with wallet reset even if chart reset fails
resetWalletAddressOnly();
}
});
}
}
// Fallback function if chart reset fails
function resetWalletAddressOnly() {
fetch('/api/config')
.then(response => response.json())
.then(config => {
config.wallet = "yourwallethere";
return fetch('/api/config', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(config)
});
})
.then(response => response.json())
.then(data => {
console.log("Wallet address reset successfully (without chart reset):", data);
window.location.href = window.location.origin + "/";
})
.catch(error => {
console.error("Error resetting wallet address:", error);
alert("There was an error resetting your wallet address. Please try again.");
});
}
$(document).ready(function () {
// Apply theme based on stored preference - moved to beginning for better initialization
try {
@ -2309,7 +2401,7 @@ $(document).ready(function () {
y: {
title: {
display: true,
text: 'HASHRATE',
text: 'HASHRATE (TH/S)',
color: theme.PRIMARY,
font: {
family: "'VT323', monospace",

View File

@ -68,9 +68,9 @@
});
</script>
<!-- Theme toggle button (new) -->
<button id="themeToggle" class="theme-toggle-btn">
<!--<button id="themeToggle" class="theme-toggle-btn">
<span>Toggle Theme</span>
</button>
</button>-->
<button id="skip-button">SKIP</button>
<div id="debug-info"></div>
<div id="loading-message">Loading mining data...</div>