mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-11-29 18:33:55 +01:00
add smirk payments and leaderboard and diff tuning
This commit is contained in:
@@ -71,6 +71,7 @@
|
||||
<script src="js/ui/audioAlerts.js"></script>
|
||||
<script src="js/ui/addressModal.js"></script>
|
||||
<script src="js/ui/transactionHistory.js"></script>
|
||||
<script src="js/ui/leaderboard.js"></script>
|
||||
<script src="js/ui/helpModal.js"></script>
|
||||
<script src="js/network/socketHandlers.js"></script>
|
||||
<script src="js/network/smirkAuth.js"></script>
|
||||
@@ -108,6 +109,7 @@
|
||||
</label>
|
||||
<button id="helpButton" style="margin-left:auto; background:#2d2d00; color:#ffd700; border:1px solid #ffd700; padding:4px 10px; font-size:11px; cursor:pointer; border-radius:3px;" title="How to play and payment information">❓ Help</button>
|
||||
<button id="historyButton" style="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="leaderboardButton" style="background:#4a2800; color:#fbbf24; border:1px solid #f59e0b; padding:4px 10px; font-size:11px; cursor:pointer; border-radius:3px;" title="View high scores">🏆 Scores</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>
|
||||
|
||||
@@ -670,7 +670,67 @@ const SocketHandlers = {
|
||||
onPaymentCreated: function(data) {
|
||||
console.log('Payment created:', data);
|
||||
if (typeof AudioAlerts !== 'undefined') { AudioAlerts.playRequestCoin(); }
|
||||
|
||||
|
||||
// Try Smirk native payment if user is connected via Smirk
|
||||
if (typeof SmirkAuth !== 'undefined' && SmirkAuth._isLinked && SmirkAuth.isAvailable() &&
|
||||
typeof window.smirk !== 'undefined' && window.smirk.requestPayment) {
|
||||
SocketHandlers._trySmirkPayment(data);
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal flow: show payment modal + chat message + QR
|
||||
SocketHandlers._showPaymentFlow(data);
|
||||
},
|
||||
|
||||
/**
|
||||
* Attempt payment via Smirk wallet extension.
|
||||
* Falls back to normal address/QR flow on rejection or error.
|
||||
*/
|
||||
_trySmirkPayment: async function(data) {
|
||||
$('#messages').append($('<li class="status">').text('Opening Smirk wallet for payment...'));
|
||||
UI.scrollChat();
|
||||
|
||||
try {
|
||||
await window.smirk.requestPayment({
|
||||
address: data.address,
|
||||
amount: String(data.amount),
|
||||
asset: (SocketHandlers._cryptoType || 'WOW').toLowerCase(),
|
||||
description: data.paymentType === 'credits_package'
|
||||
? 'Buy ' + (data.package ? data.package.credits : '') + ' credits'
|
||||
: 'Single game entry'
|
||||
});
|
||||
|
||||
// User confirmed in Smirk — TX submitted, server monitoring handles the rest
|
||||
$('#messages').append($('<li class="status" style="color:#4ade80;">').text(
|
||||
'Payment sent via Smirk! Waiting for confirmation...'
|
||||
));
|
||||
UI.scrollChat();
|
||||
|
||||
// Show payment UI in "waiting for confirmation" state
|
||||
if (typeof PaymentUI !== 'undefined') {
|
||||
PaymentUI.showPaymentRequest(data);
|
||||
$('#payment-status').html('<span style="color:#4ade80;">Payment sent via Smirk — awaiting confirmation...</span>');
|
||||
}
|
||||
SocketHandlers._setBannerStatus('Pay', '#0af');
|
||||
if (typeof Game !== 'undefined' && Game._paymentRequested) Game._paymentRequested();
|
||||
if (typeof Game !== 'undefined' && Game.drawWaitingScreen) Game.drawWaitingScreen();
|
||||
|
||||
} catch (err) {
|
||||
console.log('Smirk payment declined/failed, falling back to manual:', err);
|
||||
$('#messages').append($('<li class="status">').text(
|
||||
'Smirk payment cancelled. Use the address below.'
|
||||
));
|
||||
UI.scrollChat();
|
||||
|
||||
// Fall back to normal address/QR flow
|
||||
SocketHandlers._showPaymentFlow(data);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Show normal payment flow: modal + chat message + QR code
|
||||
*/
|
||||
_showPaymentFlow: function(data) {
|
||||
if (typeof PaymentUI !== 'undefined') {
|
||||
PaymentUI.showPaymentRequest(data);
|
||||
}
|
||||
@@ -685,11 +745,10 @@ const SocketHandlers = {
|
||||
const shortAddr = data.address.substring(0, 10) + '…' + data.address.slice(-6);
|
||||
parts.push('Address: <span class="pay-address-full" style="cursor:pointer;" title="Click to toggle full address">' + shortAddr + '</span>' +
|
||||
' <button class="copy-pay-address" data-address="' + data.address + '" style="margin-left:4px;padding:1px 4px;font-size:11px;cursor:pointer;">Copy</button>');
|
||||
// (Removed inline QR image to avoid duplication; dedicated pinned sidebar QR is used instead.)
|
||||
const $li = $('<li class="payment-info" style="white-space:normal;">').html(parts.join('<br>'));
|
||||
$('#messages').append($li);
|
||||
|
||||
// Attach copy handler (delegated inside this LI to avoid duplicates)
|
||||
// Attach copy handler
|
||||
const fullAddress = data.address;
|
||||
$li.on('click', '.copy-pay-address', function(e) {
|
||||
e.preventDefault();
|
||||
@@ -699,8 +758,7 @@ const SocketHandlers = {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(addr);
|
||||
} else {
|
||||
// Fallback
|
||||
const ta = document.createElement('textarea');
|
||||
var ta = document.createElement('textarea');
|
||||
ta.value = addr; document.body.appendChild(ta); ta.select();
|
||||
document.execCommand('copy'); document.body.removeChild(ta);
|
||||
}
|
||||
@@ -716,20 +774,19 @@ const SocketHandlers = {
|
||||
});
|
||||
|
||||
// Toggle short/full address on span click
|
||||
let showingFull = false;
|
||||
var showingFull = false;
|
||||
$li.on('click', '.pay-address-full', function() {
|
||||
showingFull = !showingFull;
|
||||
$(this).text(showingFull ? fullAddress : shortAddr);
|
||||
});
|
||||
UI.scrollChat();
|
||||
|
||||
|
||||
setTimeout(function() {
|
||||
$('#chatInput').focus();
|
||||
}, 100);
|
||||
SocketHandlers._setBannerStatus('Pay', '#0af');
|
||||
if (typeof Game !== 'undefined' && Game._paymentRequested) Game._paymentRequested();
|
||||
|
||||
// Show waiting screen (which will now say "Awaiting payment")
|
||||
|
||||
if (typeof Game !== 'undefined' && Game.drawWaitingScreen) {
|
||||
Game.drawWaitingScreen();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
/**
|
||||
* Leaderboard Panel
|
||||
* Displays high scores with period filtering
|
||||
*/
|
||||
const Leaderboard = {
|
||||
_isLoading: false,
|
||||
_currentPeriod: 'all',
|
||||
|
||||
init: function() {
|
||||
$('#leaderboardButton').on('click', function() {
|
||||
Leaderboard.show();
|
||||
});
|
||||
|
||||
// Listen for real-time leaderboard updates
|
||||
if (window.socket) {
|
||||
window.socket.on('leaderboard_update', function(data) {
|
||||
// Refresh if modal is visible
|
||||
if ($('#leaderboard-panel').is(':visible')) {
|
||||
Leaderboard._fetchAndRender();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
show: function() {
|
||||
this._ensurePanel();
|
||||
$('#leaderboard-panel').show();
|
||||
this._fetchAndRender();
|
||||
},
|
||||
|
||||
_ensurePanel: function() {
|
||||
if ($('#leaderboard-panel').length) return;
|
||||
|
||||
var panel = $(
|
||||
'<div id="leaderboard-panel" style="display:none; position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); z-index:2100; background:rgba(10,10,20,0.97); border:2px solid #f59e0b; padding:20px; color:#e0e0e0; min-width:380px; max-width:500px; max-height:80vh; overflow-y:auto; box-shadow:0 0 20px rgba(245,158,11,0.3); border-radius:6px;">' +
|
||||
'<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:12px;">' +
|
||||
'<strong style="color:#fbbf24; font-size:1.1em;">🏆 Leaderboard</strong>' +
|
||||
'<button id="close-leaderboard" style="background:#500; color:#f00; border:1px solid #f00; padding:2px 8px; cursor:pointer; font-size:14px;">✕</button>' +
|
||||
'</div>' +
|
||||
'<div id="leaderboard-tabs" style="display:flex; gap:4px; margin-bottom:12px;">' +
|
||||
'<button class="lb-tab" data-period="all" style="flex:1; padding:6px; font-size:11px; cursor:pointer; border:1px solid #555; border-radius:3px;">All Time</button>' +
|
||||
'<button class="lb-tab" data-period="month" style="flex:1; padding:6px; font-size:11px; cursor:pointer; border:1px solid #555; border-radius:3px;">Month</button>' +
|
||||
'<button class="lb-tab" data-period="week" style="flex:1; padding:6px; font-size:11px; cursor:pointer; border:1px solid #555; border-radius:3px;">Week</button>' +
|
||||
'</div>' +
|
||||
'<div id="leaderboard-content" style="font-size:12px;">Loading...</div>' +
|
||||
'<div style="margin-top:10px; font-size:10px; color:#666; text-align:center;">Set your name: type /nick YourName in chat</div>' +
|
||||
'</div>'
|
||||
);
|
||||
|
||||
$('body').append(panel);
|
||||
|
||||
$('#close-leaderboard').on('click', function() {
|
||||
$('#leaderboard-panel').hide();
|
||||
});
|
||||
|
||||
var self = this;
|
||||
$(document).on('click', '.lb-tab', function() {
|
||||
self._currentPeriod = $(this).data('period');
|
||||
self._updateTabs();
|
||||
self._fetchAndRender();
|
||||
});
|
||||
|
||||
this._updateTabs();
|
||||
},
|
||||
|
||||
_updateTabs: function() {
|
||||
var current = this._currentPeriod;
|
||||
$('.lb-tab').each(function() {
|
||||
if ($(this).data('period') === current) {
|
||||
$(this).css({ background: '#92400e', color: '#fff', borderColor: '#f59e0b' });
|
||||
} else {
|
||||
$(this).css({ background: '#1a1a2e', color: '#aaa', borderColor: '#555' });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
_fetchAndRender: function() {
|
||||
if (this._isLoading) return;
|
||||
this._isLoading = true;
|
||||
$('#leaderboard-content').html('<div style="text-align:center; color:#888;">Loading...</div>');
|
||||
|
||||
var self = this;
|
||||
$.getJSON('/api/leaderboard?period=' + this._currentPeriod + '&limit=20')
|
||||
.done(function(data) {
|
||||
self._render(data.leaderboard || []);
|
||||
})
|
||||
.fail(function() {
|
||||
$('#leaderboard-content').html('<div style="text-align:center; color:#f66;">Failed to load leaderboard</div>');
|
||||
})
|
||||
.always(function() {
|
||||
self._isLoading = false;
|
||||
});
|
||||
},
|
||||
|
||||
_render: function(entries) {
|
||||
if (!entries.length) {
|
||||
$('#leaderboard-content').html('<div style="text-align:center; color:#888; padding:20px;">No scores yet. Play a game to be first!</div>');
|
||||
return;
|
||||
}
|
||||
|
||||
var html = '<table style="width:100%; border-collapse:collapse;">';
|
||||
html += '<thead><tr style="border-bottom:1px solid #444; color:#fbbf24; font-size:11px;">';
|
||||
html += '<th style="text-align:left; padding:4px;">#</th>';
|
||||
html += '<th style="text-align:left; padding:4px;">Player</th>';
|
||||
html += '<th style="text-align:right; padding:4px;">Best</th>';
|
||||
html += '<th style="text-align:right; padding:4px;">Wins</th>';
|
||||
html += '<th style="text-align:right; padding:4px;">Games</th>';
|
||||
html += '</tr></thead><tbody>';
|
||||
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
var e = entries[i];
|
||||
var rankColor = i === 0 ? '#fbbf24' : (i === 1 ? '#c0c0c0' : (i === 2 ? '#cd7f32' : '#888'));
|
||||
var rankIcon = i === 0 ? '🥇' : (i === 1 ? '🥈' : (i === 2 ? '🥉' : (i + 1)));
|
||||
var bgColor = i % 2 === 0 ? 'rgba(255,255,255,0.03)' : 'transparent';
|
||||
|
||||
html += '<tr style="border-bottom:1px solid #222; background:' + bgColor + ';">';
|
||||
html += '<td style="padding:6px 4px; color:' + rankColor + '; font-weight:bold;">' + rankIcon + '</td>';
|
||||
html += '<td style="padding:6px 4px; color:#e0e0e0; max-width:150px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;">' + Leaderboard._escapeHtml(e.name) + '</td>';
|
||||
html += '<td style="padding:6px 4px; text-align:right; color:#4ade80; font-weight:bold;">' + (e.best_score || 0) + '</td>';
|
||||
html += '<td style="padding:6px 4px; text-align:right; color:#60a5fa;">' + (e.wins || 0) + '</td>';
|
||||
html += '<td style="padding:6px 4px; text-align:right; color:#888;">' + (e.games_played || 0) + '</td>';
|
||||
html += '</tr>';
|
||||
}
|
||||
|
||||
html += '</tbody></table>';
|
||||
$('#leaderboard-content').html(html);
|
||||
},
|
||||
|
||||
_escapeHtml: function(str) {
|
||||
if (!str) return '';
|
||||
return String(str)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
};
|
||||
|
||||
// Initialize when DOM is ready
|
||||
$(document).ready(function() {
|
||||
Leaderboard.init();
|
||||
});
|
||||
Reference in New Issue
Block a user