mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-12-01 19:33:55 +01:00
add address modal and try to fix payout
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
<!-- Other modules -->
|
||||
<script src="js/ui/ui.js"></script>
|
||||
<script src="js/ui/audioAlerts.js"></script>
|
||||
<script src="js/ui/addressModal.js"></script>
|
||||
<script src="js/network/socketHandlers.js"></script>
|
||||
<script src="js/input/inputHandler.js"></script>
|
||||
</head>
|
||||
@@ -65,6 +66,7 @@
|
||||
<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;">⚙️ Manage Payout Address</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -133,6 +135,24 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Address management modal -->
|
||||
<div id="addressModal" class="modal-overlay hidden" role="dialog" aria-modal="true" aria-labelledby="addressModalTitle">
|
||||
<div class="modal-content">
|
||||
<button type="button" class="modal-close" id="addressModalClose" aria-label="Close">✕</button>
|
||||
<h2 id="addressModalTitle">Manage Payout Address</h2>
|
||||
<p class="modal-description">Enter your Wownero (WOW) or Monero (XMR) address below. This will be used for payouts when you escape.</p>
|
||||
<form id="addressModalForm">
|
||||
<label for="addressModalInput" class="modal-label">Payout Address</label>
|
||||
<textarea id="addressModalInput" autocomplete="off" spellcheck="false" rows="3" placeholder="Paste your payout address here"></textarea>
|
||||
<div class="modal-actions">
|
||||
<button type="submit" id="addressModalSave">Save Address</button>
|
||||
<button type="button" id="addressModalCancel">Cancel</button>
|
||||
</div>
|
||||
<div id="addressModalFeedback" class="modal-feedback" aria-live="polite"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Browser info panel -->
|
||||
<div id="browser-info" style="position: fixed; right: 10px; top: 40px; background: rgba(0,0,0,0.7); color: #0f0; padding: 5px; font-family: monospace; font-size: 12px; z-index: 1000; display: none;">
|
||||
<div>Browser: <span id="browser-name">checking...</span></div>
|
||||
|
||||
@@ -176,6 +176,17 @@ const InputHandler = {
|
||||
$('#messages').append($('<li style="color: #aa0;">').text(`🎬 Animation ${status}`));
|
||||
UI.scrollChat();
|
||||
});
|
||||
|
||||
// Address management button
|
||||
$('#manageAddressButton').click(function(e) {
|
||||
e.preventDefault();
|
||||
if (window.socket) {
|
||||
socket.emit('address:prompt');
|
||||
}
|
||||
if (typeof AddressModal !== 'undefined') {
|
||||
AddressModal.show();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setupModeToggle: function() {
|
||||
|
||||
@@ -49,8 +49,10 @@ const SocketHandlers = {
|
||||
socket.on('queue_cancelled', this.onQueueCancelled);
|
||||
|
||||
// Payment/Address handlers
|
||||
socket.on('address_detected', this.onAddressDetected);
|
||||
socket.on('address_confirmed', this.onAddressConfirmed);
|
||||
socket.on('address_detected', this.onAddressDetected);
|
||||
socket.on('address_confirmed', this.onAddressConfirmed);
|
||||
socket.on('address_update_error', this.onAddressUpdateError);
|
||||
socket.on('address_prompt', this.onAddressPrompt);
|
||||
socket.on('payment_created', this.onPaymentCreated);
|
||||
socket.on('payment_confirmed', this.onPaymentConfirmed);
|
||||
socket.on('payment_detected', this.onPaymentDetected);
|
||||
@@ -100,6 +102,9 @@ const SocketHandlers = {
|
||||
if (data && data.payoutAddress) {
|
||||
$('#messages').append($('<li class="address-confirmed" style="color:#0f0;">').text('Payout address restored.'));
|
||||
UI.scrollChat();
|
||||
if (typeof AddressModal !== 'undefined') {
|
||||
AddressModal.setCurrentAddress(data.payoutAddress);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -298,6 +303,24 @@ const SocketHandlers = {
|
||||
console.log('Address confirmed:', data);
|
||||
$('#messages').append($('<li class="address-confirmed" style="color: #0f0; white-space: pre-line;">').text(data.message));
|
||||
UI.scrollChat();
|
||||
if (typeof AddressModal !== 'undefined') {
|
||||
AddressModal.onConfirmed(data);
|
||||
}
|
||||
},
|
||||
|
||||
onAddressPrompt: function(data) {
|
||||
if (typeof AddressModal !== 'undefined') {
|
||||
AddressModal.show({
|
||||
existingAddress: data?.existingAddress || null,
|
||||
message: data?.message || null
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onAddressUpdateError: function(data) {
|
||||
if (typeof AddressModal !== 'undefined') {
|
||||
AddressModal.handleError(data?.message || 'Failed to update address.');
|
||||
}
|
||||
},
|
||||
|
||||
onPaymentCreated: function(data) {
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
(function(window, $) {
|
||||
const AddressModal = {
|
||||
_initialized: false,
|
||||
_isVisible: false,
|
||||
_pending: false,
|
||||
_currentAddress: null,
|
||||
_elements: {},
|
||||
|
||||
init() {
|
||||
if (this._initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
this._elements.overlay = $('#addressModal');
|
||||
this._elements.input = $('#addressModalInput');
|
||||
this._elements.form = $('#addressModalForm');
|
||||
this._elements.close = $('#addressModalClose');
|
||||
this._elements.cancel = $('#addressModalCancel');
|
||||
this._elements.feedback = $('#addressModalFeedback');
|
||||
this._elements.saveButton = $('#addressModalSave');
|
||||
|
||||
if (!this._elements.overlay.length) {
|
||||
console.warn('AddressModal: modal markup not found.');
|
||||
return;
|
||||
}
|
||||
|
||||
this._elements.close.on('click', (evt) => {
|
||||
evt.preventDefault();
|
||||
this.hide();
|
||||
});
|
||||
this._elements.cancel.on('click', (evt) => {
|
||||
evt.preventDefault();
|
||||
this.hide();
|
||||
});
|
||||
this._elements.overlay.on('click', (evt) => {
|
||||
if (evt.target === this._elements.overlay[0]) {
|
||||
this.hide();
|
||||
}
|
||||
});
|
||||
|
||||
this._elements.form.on('submit', (evt) => {
|
||||
evt.preventDefault();
|
||||
this.handleSubmit();
|
||||
});
|
||||
|
||||
this._initialized = true;
|
||||
},
|
||||
|
||||
ensureInit() {
|
||||
if (!this._initialized) {
|
||||
this.init();
|
||||
}
|
||||
},
|
||||
|
||||
show({ existingAddress = null, message = null } = {}) {
|
||||
this.ensureInit();
|
||||
if (!this._elements.overlay.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof existingAddress === 'string' && existingAddress.trim().length > 0) {
|
||||
this._currentAddress = existingAddress.trim();
|
||||
}
|
||||
|
||||
const value = this._currentAddress || existingAddress || '';
|
||||
this._elements.input.val(value);
|
||||
this._elements.input.trigger('focus');
|
||||
|
||||
if (message) {
|
||||
this.setFeedback(message, 'info');
|
||||
} else {
|
||||
this.clearFeedback();
|
||||
}
|
||||
|
||||
this.setPending(false);
|
||||
this._elements.overlay.removeClass('hidden');
|
||||
this._isVisible = true;
|
||||
},
|
||||
|
||||
hide() {
|
||||
if (!this._isVisible) {
|
||||
return;
|
||||
}
|
||||
this._elements.overlay.addClass('hidden');
|
||||
this._isVisible = false;
|
||||
this.setPending(false);
|
||||
this.clearFeedback();
|
||||
},
|
||||
|
||||
setFeedback(text, type = 'info') {
|
||||
if (!this._elements.feedback.length) return;
|
||||
this._elements.feedback.text(text || '');
|
||||
this._elements.feedback.removeClass('error success info');
|
||||
this._elements.feedback.addClass(type);
|
||||
},
|
||||
|
||||
clearFeedback() {
|
||||
if (!this._elements.feedback.length) return;
|
||||
this._elements.feedback.text('');
|
||||
this._elements.feedback.removeClass('error success info');
|
||||
},
|
||||
|
||||
setCurrentAddress(address) {
|
||||
if (typeof address === 'string' && address.trim()) {
|
||||
this._currentAddress = address.trim();
|
||||
if (this._isVisible && !this._pending) {
|
||||
this._elements.input.val(this._currentAddress);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
setPending(state) {
|
||||
this._pending = Boolean(state);
|
||||
if (!this._elements.saveButton?.length) {
|
||||
return;
|
||||
}
|
||||
if (!this._pending && this._isVisible) {
|
||||
this._elements.saveButton.prop('disabled', false).text('Save Address');
|
||||
} else if (this._pending) {
|
||||
this._elements.saveButton.prop('disabled', true).text('Saving…');
|
||||
} else {
|
||||
this._elements.saveButton.prop('disabled', false);
|
||||
}
|
||||
},
|
||||
|
||||
handleError(message) {
|
||||
this.setPending(false);
|
||||
if (message) {
|
||||
this.setFeedback(message, 'error');
|
||||
}
|
||||
},
|
||||
|
||||
onConfirmed({ address, message }) {
|
||||
if (address) {
|
||||
this.setCurrentAddress(address);
|
||||
}
|
||||
if (this._isVisible) {
|
||||
if (message) {
|
||||
this.setFeedback(message, 'success');
|
||||
}
|
||||
this.setPending(false);
|
||||
this.hide();
|
||||
}
|
||||
},
|
||||
|
||||
handleSubmit() {
|
||||
if (this._pending) {
|
||||
return;
|
||||
}
|
||||
const value = (this._elements.input.val() || '').trim();
|
||||
if (!value) {
|
||||
this.setFeedback('Please enter a payout address.', 'error');
|
||||
this._elements.input.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
if (value.length < 80 || value.length > 128) {
|
||||
this.setFeedback('That address length looks off. Please double-check and try again.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!window.socket) {
|
||||
this.setFeedback('Socket connection not ready. Try again shortly.', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
this.setPending(true);
|
||||
this.setFeedback('Saving address…', 'info');
|
||||
window.socket.emit('address:update', { address: value });
|
||||
}
|
||||
};
|
||||
|
||||
$(function() {
|
||||
AddressModal.init();
|
||||
});
|
||||
|
||||
window.AddressModal = AddressModal;
|
||||
})(window, jQuery);
|
||||
+40
-13
@@ -13,6 +13,8 @@ const AudioAlerts = {
|
||||
_lastPlay: 0,
|
||||
_cooldownMs: 1500,
|
||||
_audioTags: {}, // cache HTMLAudioElements
|
||||
_gameStartHoldUntil: 0,
|
||||
_pendingGameStartTimer: null,
|
||||
_fileMap: {
|
||||
request_coin: 'audio/Pleasesendcoin.m4a',
|
||||
payment_detected: 'audio/Paymentdetected.m4a',
|
||||
@@ -58,7 +60,7 @@ const AudioAlerts = {
|
||||
const origQueueJoined = SocketHandlers.onQueueJoined;
|
||||
SocketHandlers.onPaymentConfirmed = function(data) {
|
||||
if (origPaymentConfirmed) origPaymentConfirmed.call(SocketHandlers, data);
|
||||
AudioAlerts.playFile('payment_confirmed');
|
||||
AudioAlerts.playPaymentConfirmed();
|
||||
};
|
||||
SocketHandlers.onPaymentDetected = function(data) {
|
||||
if (origPaymentDetected) origPaymentDetected.call(SocketHandlers, data);
|
||||
@@ -66,14 +68,7 @@ const AudioAlerts = {
|
||||
};
|
||||
SocketHandlers.onGameStart = function(data) {
|
||||
if (origGameStart) origGameStart.call(SocketHandlers, data);
|
||||
// Add delay to prevent overlap with payment_confirmed audio
|
||||
const lastPaymentConfirmed = AudioAlerts._audioTagTimes && AudioAlerts._audioTagTimes['payment_confirmed'];
|
||||
if (lastPaymentConfirmed && (Date.now() - lastPaymentConfirmed < 2000)) {
|
||||
// Delay game_start audio if payment_confirmed played recently
|
||||
setTimeout(() => AudioAlerts.playFile('game_start'), 1500);
|
||||
} else {
|
||||
AudioAlerts.playFile('game_start');
|
||||
}
|
||||
AudioAlerts.playGameStart();
|
||||
};
|
||||
SocketHandlers.onGameOver = function(data) {
|
||||
if (origGameOver) origGameOver.call(SocketHandlers, data);
|
||||
@@ -140,19 +135,51 @@ const AudioAlerts = {
|
||||
return this._audioTags[tag];
|
||||
},
|
||||
playFile(tag) {
|
||||
if (!this._enabled) return;
|
||||
if (!this._enabled) return null;
|
||||
const now = Date.now();
|
||||
// Per-tag cooldown so different event types can fire back-to-back (e.g. payment_confirmed -> game_start)
|
||||
if (!this._audioTagTimes) this._audioTagTimes = {}; // tag -> last play timestamp
|
||||
const lastForTag = this._audioTagTimes[tag] || 0;
|
||||
const elapsed = now - lastForTag;
|
||||
const allow = elapsed >= this._cooldownMs || (tag === 'game_start' && this._lastTag !== 'game_start');
|
||||
if (!allow) return;
|
||||
if (!allow) return null;
|
||||
this._audioTagTimes[tag] = now;
|
||||
this._lastTag = tag;
|
||||
const el = this._getAudio(tag);
|
||||
if (!el) return;
|
||||
try { el.currentTime = 0; el.play().catch(()=>{}); } catch(_) {}
|
||||
if (!el) return null;
|
||||
try {
|
||||
el.currentTime = 0;
|
||||
el.play().catch(()=>{});
|
||||
} catch(_) {}
|
||||
return el;
|
||||
},
|
||||
playPaymentConfirmed() {
|
||||
if (!this._enabled) return;
|
||||
const el = this.playFile('payment_confirmed');
|
||||
const fallback = 2200;
|
||||
let holdMs = fallback;
|
||||
if (el && isFinite(el.duration) && el.duration > 0.2) {
|
||||
holdMs = Math.ceil(el.duration * 1000);
|
||||
}
|
||||
this._gameStartHoldUntil = Date.now() + holdMs;
|
||||
},
|
||||
playGameStart() {
|
||||
if (!this._enabled) return;
|
||||
const now = Date.now();
|
||||
if (this._pendingGameStartTimer) {
|
||||
clearTimeout(this._pendingGameStartTimer);
|
||||
this._pendingGameStartTimer = null;
|
||||
}
|
||||
const holdUntil = this._gameStartHoldUntil || 0;
|
||||
if (holdUntil && now < holdUntil) {
|
||||
const delay = Math.max(0, holdUntil - now);
|
||||
this._pendingGameStartTimer = setTimeout(() => {
|
||||
this._pendingGameStartTimer = null;
|
||||
this.playFile('game_start');
|
||||
}, delay);
|
||||
return;
|
||||
}
|
||||
this.playFile('game_start');
|
||||
},
|
||||
playGameOverSound(gameOverData) {
|
||||
if (!this._enabled) return;
|
||||
|
||||
@@ -206,3 +206,122 @@ li.debug {
|
||||
border-left: 2px solid #0ff;
|
||||
}
|
||||
|
||||
/* Utility */
|
||||
.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* Modal styling */
|
||||
.modal-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.85);
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
z-index: 10000;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
background: #0a0a0f;
|
||||
border: 2px solid #0ff;
|
||||
border-radius: 6px;
|
||||
width: min(480px, 90vw);
|
||||
padding: 20px;
|
||||
color: #0ff;
|
||||
font-family: 'PixelOperator', monospace;
|
||||
position: relative;
|
||||
box-shadow: 0 0 18px rgba(0, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.modal-content h2 {
|
||||
margin-top: 0;
|
||||
margin-bottom: 8px;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.modal-description {
|
||||
margin-top: 0;
|
||||
margin-bottom: 16px;
|
||||
font-size: 12px;
|
||||
color: #9cf;
|
||||
}
|
||||
|
||||
.modal-label {
|
||||
display: block;
|
||||
margin-bottom: 6px;
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
#addressModalInput {
|
||||
width: 100%;
|
||||
background: #020205;
|
||||
border: 1px solid #0ff;
|
||||
border-radius: 4px;
|
||||
color: #0ff;
|
||||
padding: 10px;
|
||||
font-family: monospace;
|
||||
resize: vertical;
|
||||
min-height: 100px;
|
||||
box-shadow: inset 0 0 6px rgba(0, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
margin-top: 16px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.modal-actions button {
|
||||
padding: 8px 16px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid #0ff;
|
||||
background: #031c28;
|
||||
color: #0ff;
|
||||
cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.modal-actions button#addressModalSave {
|
||||
background: #013d2a;
|
||||
border-color: #0f7;
|
||||
color: #0f7;
|
||||
}
|
||||
|
||||
.modal-actions button:hover {
|
||||
box-shadow: 0 0 10px rgba(0, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
.modal-close {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 10px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
color: #0ff;
|
||||
font-size: 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.modal-feedback {
|
||||
margin-top: 12px;
|
||||
font-size: 12px;
|
||||
min-height: 16px;
|
||||
}
|
||||
|
||||
.modal-feedback.error {
|
||||
color: #ff6b6b;
|
||||
}
|
||||
|
||||
.modal-feedback.success {
|
||||
color: #5dff9c;
|
||||
}
|
||||
|
||||
.modal-feedback.info {
|
||||
color: #9cf6ff;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user