mirror of
https://github.com/Such-Software/wownerogue.git
synced 2026-12-05 13:23:59 +01:00
add address modal and try to fix payout
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user