add backup scripts and improve docs and .env.example

This commit is contained in:
jwinterm
2025-12-22 16:29:32 -05:00
parent 7f91d83308
commit 7d701fe01b
14 changed files with 1335 additions and 702 deletions
+45 -1
View File
@@ -56,6 +56,7 @@
<script src="js/ui/paymentUI.js"></script>
<script src="js/ui/audioAlerts.js"></script>
<script src="js/ui/addressModal.js"></script>
<script src="js/ui/transactionHistory.js"></script>
<script src="js/network/socketHandlers.js"></script>
<script src="js/input/inputHandler.js"></script>
</head>
@@ -88,7 +89,8 @@
<label style="cursor:pointer; display:flex; align-items:center; gap:4px;">
<input type="checkbox" id="audioAlertsToggle" style="cursor:pointer;"> Audio Alerts
</label>
<button id="manageAddressButton" style="margin-left:auto; background:#053655; color:#0ff; border:1px solid #0ff; padding:4px 10px; font-size:11px; cursor:pointer; border-radius:3px;" title="Your payout address and credits are tied to a browser session token. Clearing cookies/localStorage or using incognito mode will lose your session.">⚙️ Manage Payout Address</button>
<button id="historyButton" style="margin-left:auto; background:#1a1a4d; color:#c4b5fd; border:1px solid #8b5cf6; padding:4px 10px; font-size:11px; cursor:pointer; border-radius:3px;" title="View your payment and payout history">📜 History</button>
<button id="manageAddressButton" style="background:#053655; color:#0ff; border:1px solid #0ff; padding:4px 10px; font-size:11px; cursor:pointer; border-radius:3px;" title="Your payout address and credits are tied to a browser session token. Clearing cookies/localStorage or using incognito mode will lose your session.">⚙️ Manage Payout Address</button>
<span id="sessionWarning" style="display:none; color:#f59e0b; font-size:10px; margin-left:6px;" title="Private browsing or localStorage blocked - your session won't persist">⚠️ Session not saved</span>
</div>
</div>
@@ -132,6 +134,48 @@
</div>
</div>
<!-- Transaction History Panel -->
<div id="history-panel" style="display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 2000; background: rgba(10,10,30,0.98); border: 2px solid #8b5cf6; padding: 20px; color: #e0e0e0; min-width: 500px; max-width: 600px; max-height: 80vh; overflow-y: auto; box-shadow: 0 0 20px rgba(139,92,246,0.3); border-radius: 8px;">
<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:15px; border-bottom:1px solid #444; padding-bottom:10px;">
<strong style="font-size:1.2em; color:#c4b5fd;">📜 Transaction History</strong>
<button id="close-history" style="background: #500; color: #f00; border: 1px solid #f00; padding: 4px 8px; cursor: pointer; border-radius:3px;">✕</button>
</div>
<!-- Summary Section -->
<div id="history-summary" style="display:grid; grid-template-columns:1fr 1fr; gap:15px; margin-bottom:20px;">
<div style="background:#1a1a3d; padding:12px; border-radius:6px; border:1px solid #4c1d95;">
<div style="color:#888; font-size:0.85em;">Total Received</div>
<div id="total-received" style="color:#4ade80; font-size:1.3em; font-weight:bold;">0 WOW</div>
</div>
<div style="background:#1a1a3d; padding:12px; border-radius:6px; border:1px solid #4c1d95;">
<div style="color:#888; font-size:0.85em;">Total Payments</div>
<div id="total-payments" style="color:#60a5fa; font-size:1.3em; font-weight:bold;">0</div>
</div>
</div>
<!-- Tabs -->
<div style="display:flex; gap:10px; margin-bottom:15px;">
<button class="history-tab active" data-tab="payouts" style="flex:1; padding:8px; background:#4c1d95; color:#fff; border:none; cursor:pointer; border-radius:4px;">💰 Payouts</button>
<button class="history-tab" data-tab="payments" style="flex:1; padding:8px; background:#333; color:#aaa; border:none; cursor:pointer; border-radius:4px;">💳 Payments</button>
</div>
<!-- Payouts Tab Content -->
<div id="payouts-content" class="history-content">
<div id="payouts-list" style="max-height:300px; overflow-y:auto;"></div>
<div id="payouts-empty" style="text-align:center; color:#666; padding:20px;">No payouts yet</div>
</div>
<!-- Payments Tab Content -->
<div id="payments-content" class="history-content" style="display:none;">
<div id="payments-list" style="max-height:300px; overflow-y:auto;"></div>
<div id="payments-empty" style="text-align:center; color:#666; padding:20px;">No payments yet</div>
</div>
<div style="margin-top:15px; font-size:0.8em; color:#666; text-align:center;">
History is tied to your browser session
</div>
</div>
<!-- Game display -->
<div id="game-display" class="rotdis"></div>
+25 -2
View File
@@ -157,7 +157,15 @@ const SocketHandlers = {
}
},
_updateCreditsDisplay: function(balance) {
// Default credits per game (overridden by game_mode_info)
_creditsPerGame: 1,
_updateCreditsDisplay: function(balance, creditsPerGame) {
// Update stored creditsPerGame if provided
if (creditsPerGame && creditsPerGame > 0) {
SocketHandlers._creditsPerGame = creditsPerGame;
}
let el = document.getElementById('creditsDisplay');
if (!el) {
// Create a small unobtrusive badge in header if not present
@@ -167,7 +175,17 @@ const SocketHandlers = {
el.style.cssText = 'position:absolute;top:4px;right:8px;font-size:12px;font-family:monospace;color:#0af;background:#111;padding:2px 6px;border:1px solid #044;border-radius:4px;';
header.appendChild(el);
}
el.textContent = 'Credits: ' + balance;
// Calculate games remaining
const perGame = SocketHandlers._creditsPerGame || 1;
const gamesRemaining = Math.floor(balance / perGame);
// Show credits and games remaining
if (gamesRemaining > 0) {
el.textContent = 'Credits: ' + balance + ' (' + gamesRemaining + ' game' + (gamesRemaining !== 1 ? 's' : '') + ')';
} else {
el.textContent = 'Credits: ' + balance;
}
},
onWelcome: function(msg) {
@@ -438,6 +456,11 @@ const SocketHandlers = {
onGameModeInfo: function(data) {
console.log('Game mode info received:', data);
// Store creditsPerGame for calculating games remaining
if (data.creditsPerGame) {
SocketHandlers._creditsPerGame = data.creditsPerGame;
}
if (typeof UI !== 'undefined' && UI.updateGameTitle) {
UI.updateGameTitle(data.cryptoType);
}
+231
View File
@@ -0,0 +1,231 @@
/**
* Transaction History Panel
* Displays payment and payout history for the user
*/
const TransactionHistory = {
_isLoading: false,
_paymentsData: null,
_payoutsData: null,
init: function() {
// Bind close button
$('#close-history').on('click', function() {
$('#history-panel').hide();
});
// Bind history button
$('#historyButton').on('click', function() {
TransactionHistory.show();
});
// Bind tab switching
$('.history-tab').on('click', function() {
const tab = $(this).data('tab');
TransactionHistory._switchTab(tab);
});
},
_switchTab: function(tab) {
// Update tab button styles
$('.history-tab').each(function() {
if ($(this).data('tab') === tab) {
$(this).css({ background: '#4c1d95', color: '#fff' });
$(this).addClass('active');
} else {
$(this).css({ background: '#333', color: '#aaa' });
$(this).removeClass('active');
}
});
// Show/hide content
if (tab === 'payouts') {
$('#payouts-content').show();
$('#payments-content').hide();
} else {
$('#payouts-content').hide();
$('#payments-content').show();
}
},
show: function() {
$('#history-panel').show();
this._loadData();
},
hide: function() {
$('#history-panel').hide();
},
_loadData: function() {
if (this._isLoading) return;
this._isLoading = true;
const socketId = window.socket?.id;
if (!socketId) {
this._showError('Not connected to server');
this._isLoading = false;
return;
}
// Load both endpoints in parallel
Promise.all([
this._fetchPayments(socketId),
this._fetchPayouts(socketId)
]).then(([payments, payouts]) => {
this._paymentsData = payments;
this._payoutsData = payouts;
this._render();
}).catch(err => {
console.error('Failed to load transaction history:', err);
this._showError('Failed to load history');
}).finally(() => {
this._isLoading = false;
});
},
_fetchPayments: function(socketId) {
return fetch(`/api/user/${encodeURIComponent(socketId)}/payments?limit=50`)
.then(res => res.json())
.catch(() => ({ payments: [], total: 0 }));
},
_fetchPayouts: function(socketId) {
return fetch(`/api/user/${encodeURIComponent(socketId)}/payouts?limit=50`)
.then(res => res.json())
.catch(() => ({ payouts: [], total: 0, totalReceived: 0 }));
},
_render: function() {
this._renderSummary();
this._renderPayouts();
this._renderPayments();
},
_renderSummary: function() {
const payouts = this._payoutsData || {};
const payments = this._paymentsData || {};
const currency = payouts.currency || payments.currency || 'WOW';
const totalReceived = payouts.totalReceivedFormatted || '0';
const totalPayments = payments.total || 0;
$('#total-received').text(totalReceived + ' ' + currency);
$('#total-payments').text(totalPayments);
},
_renderPayouts: function() {
const $list = $('#payouts-list');
const $empty = $('#payouts-empty');
const data = this._payoutsData || {};
const payouts = data.payouts || [];
const currency = data.currency || 'WOW';
$list.empty();
if (payouts.length === 0) {
$empty.show();
return;
}
$empty.hide();
payouts.forEach(payout => {
const statusColor = this._getStatusColor(payout.status);
const date = new Date(payout.createdAt).toLocaleDateString();
const multiplierText = payout.multiplier ? ` (${payout.multiplier}x)` : '';
const $item = $(`
<div style="background:#1a1a2e; padding:12px; margin-bottom:8px; border-radius:6px; border-left:3px solid ${statusColor};">
<div style="display:flex; justify-content:space-between; align-items:center;">
<span style="color:#4ade80; font-weight:bold;">${payout.amountFormatted} ${currency}${multiplierText}</span>
<span style="color:${statusColor}; font-size:0.85em; text-transform:uppercase;">${payout.status}</span>
</div>
<div style="color:#888; font-size:0.85em; margin-top:4px;">
${payout.reason || 'Game reward'} • ${date}
</div>
${payout.txHash ? `<div style="color:#60a5fa; font-size:0.75em; margin-top:4px; word-break:break-all;">TX: ${payout.txHash.substring(0, 16)}...</div>` : ''}
</div>
`);
$list.append($item);
});
},
_renderPayments: function() {
const $list = $('#payments-list');
const $empty = $('#payments-empty');
const data = this._paymentsData || {};
const payments = data.payments || [];
const currency = data.currency || 'WOW';
$list.empty();
if (payments.length === 0) {
$empty.show();
return;
}
$empty.hide();
payments.forEach(payment => {
const statusColor = this._getStatusColor(payment.status);
const date = new Date(payment.createdAt).toLocaleDateString();
const typeLabel = this._getPaymentTypeLabel(payment.type);
const creditsText = payment.creditsReceived > 0 ? ` → +${payment.creditsReceived} credits` : '';
const $item = $(`
<div style="background:#1a1a2e; padding:12px; margin-bottom:8px; border-radius:6px; border-left:3px solid ${statusColor};">
<div style="display:flex; justify-content:space-between; align-items:center;">
<span style="color:#60a5fa; font-weight:bold;">${payment.amountFormatted} ${currency}</span>
<span style="color:${statusColor}; font-size:0.85em; text-transform:uppercase;">${payment.status}</span>
</div>
<div style="color:#888; font-size:0.85em; margin-top:4px;">
${typeLabel}${creditsText} • ${date}
</div>
</div>
`);
$list.append($item);
});
},
_getStatusColor: function(status) {
switch (status) {
case 'confirmed':
case 'completed':
return '#4ade80';
case 'pending':
return '#f59e0b';
case 'failed':
case 'expired':
return '#ef4444';
default:
return '#888';
}
},
_getPaymentTypeLabel: function(type) {
switch (type) {
case 'single_game':
return '💰 Single Game';
case 'credits_package':
return '🎫 Credits Package';
default:
return type || 'Payment';
}
},
_showError: function(message) {
$('#payouts-list').html(`<div style="color:#ef4444; text-align:center; padding:20px;">${message}</div>`);
$('#payments-list').html(`<div style="color:#ef4444; text-align:center; padding:20px;">${message}</div>`);
$('#payouts-empty, #payments-empty').hide();
}
};
// Expose globally
window.TransactionHistory = TransactionHistory;
// Initialize when DOM is ready
$(document).ready(function() {
TransactionHistory.init();
});