mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-12-03 04:13:57 +01:00
add backup scripts and improve docs and .env.example
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
Reference in New Issue
Block a user