Skip to content

Commit 7716eb6

Browse files
xecdevxecdev
andauthored
Add a 'Verification' overlay after login and content unlock (#112)
* Add a 'Verification' overlay after login and content unlock * Responding to the bot's feedback * Reset flags after validation failure --------- Co-authored-by: xecdev <ecashinformer@gmail.com>
1 parent 93351f1 commit 7716eb6

4 files changed

Lines changed: 114 additions & 0 deletions

File tree

assets/css/paywall-styles.css

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,55 @@
3838
font-family: inherit;
3939
font-size: 1.2em;
4040
font-style: italic;
41+
}
42+
43+
/* Verification Overlay Styles */
44+
45+
.paybutton_overlay {
46+
left: 0;
47+
top: 0;
48+
width: 100%;
49+
height: 100%;
50+
position: fixed;
51+
background: rgba(34, 34, 34, 0.8);
52+
text-align: center;
53+
z-index: 999999;
54+
}
55+
56+
.paybutton_overlay_inner {
57+
left: 0;
58+
top: 0;
59+
width: 100%;
60+
height: 100%;
61+
position: absolute;
62+
z-index: 999999;
63+
}
64+
65+
.paybutton_overlay_content {
66+
left: 50%;
67+
top: 50%;
68+
position: absolute;
69+
transform: translate(-50%, -50%);
70+
}
71+
72+
.paybutton_overlay_spinner {
73+
width: 75px;
74+
height: 75px;
75+
display: inline-block;
76+
border-width: 4px;
77+
border-color: rgba(255, 255, 255, 0.05);
78+
border-top-color: #0074C2;
79+
animation: paybutton_spin 1s infinite linear;
80+
border-radius: 100%;
81+
border-style: solid;
82+
}
83+
84+
@keyframes paybutton_spin {
85+
100% { transform: rotate(360deg); }
86+
}
87+
88+
#paybutton_overlay_text {
89+
padding-top: 7px;
90+
color: white;
91+
font-weight: bold;
4192
}

assets/js/paybutton-paywall-cashtab-login.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,20 @@
11
/* File: assets/js/paybutton-paywall-cashtab-login.js */
22
let isLoggedIn = false;
33

4+
/* Show/Hide Verification Overlay*/
5+
function showPBVerificationOverlay(msg = "Processing, please wait!") {
6+
const el = document.getElementById('paybutton_overlay');
7+
if (!el) return;
8+
document.getElementById('paybutton_overlay_text').innerText = msg;
9+
el.style.display = 'block';
10+
}
11+
12+
function hidePBVerificationOverlay() {
13+
const el = document.getElementById('paybutton_overlay');
14+
if (!el) return;
15+
el.style.display = 'none';
16+
}
17+
418
/**
519
* Handle user login:
620
* Called when the PayButton login flow completes successfully.
@@ -64,6 +78,8 @@ function renderLoginPaybutton() {
6478
// Shared state: login address captured in onSuccess, consumed in onClose.
6579
let loginAddr = null;
6680
let loginTx = null;
81+
// Track if a payment was actually initiated
82+
let paymentInitiated = false;
6783

6884
PayButton.render(document.getElementById('loginPaybutton'), {
6985
to: PaywallAjax.defaultAddress,
@@ -75,13 +91,19 @@ function renderLoginPaybutton() {
7591
autoClose: true,
7692
opReturn: 'login',
7793
onSuccess: function (tx) {
94+
paymentInitiated = true;
7895
loginAddr = tx?.inputAddresses?.[0] ?? null;
7996
loginTx = {
8097
hash: tx?.hash ?? '',
8198
timestamp: tx?.timestamp ?? 0
8299
};
83100
},
84101
onClose: function () {
102+
// Show verification overlay immediately
103+
if (paymentInitiated) {
104+
showPBVerificationOverlay("Verifying login...");
105+
}
106+
85107
if (loginAddr && loginTx && loginTx.hash) {
86108
// Make stable copies for the whole retry flow
87109
const addrCopy = loginAddr;
@@ -105,6 +127,8 @@ function renderLoginPaybutton() {
105127
// Retry once again after 3 seconds
106128
setTimeout(() => tryValidateLogin(2), 3000);
107129
} else {
130+
hidePBVerificationOverlay();
131+
paymentInitiated = false;
108132
alert('⚠️ Login failed: Invalid or expired transaction.');
109133
}
110134
}

assets/js/paywalled-content.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@
2020
* the now unlocked content is displayed.
2121
* 3. Finally, the render() method is called on the container to display the button.
2222
*/
23+
24+
/* Show/Hide Verification Overlay*/
25+
function showPBVerificationOverlay(msg = "Verifying Payment...") {
26+
const el = document.getElementById('paybutton_overlay');
27+
if (!el) return;
28+
document.getElementById('paybutton_overlay_text').innerText = msg;
29+
el.style.display = 'block';
30+
}
31+
32+
function hidePBVerificationOverlay() {
33+
const el = document.getElementById('paybutton_overlay');
34+
if (!el) return;
35+
el.style.display = 'none';
36+
}
37+
2338
jQuery(document).ready(function($) {
2439
$('.paybutton-container').each(function() {
2540
var $container = $(this);
@@ -37,6 +52,10 @@ jQuery(document).ready(function($) {
3752
// Shared state: user wallet address + unlock tx captured in onSuccess.
3853
let unlockAddr = null;
3954
let unlockTx = null;
55+
// Check if the unlock flow has completed to avoid showing the verification overlay.
56+
let unlockFlowCompleted = false;
57+
// Track if a payment was actually initiated
58+
let paymentInitiated = false;
4059

4160
// Helper to fetch and inject unlocked content
4261
function fetchUnlocked() {
@@ -108,6 +127,7 @@ jQuery(document).ready(function($) {
108127
autoClose: configData.autoClose,
109128

110129
onSuccess: function (tx) {
130+
paymentInitiated = true;
111131
unlockAddr = (tx.inputAddresses && tx.inputAddresses.length > 0)
112132
? tx.inputAddresses[0]
113133
: '';
@@ -157,6 +177,8 @@ jQuery(document).ready(function($) {
157177
success: function () {
158178
// Finally, fetch and render the unlocked content
159179
fetchUnlocked();
180+
unlockFlowCompleted = true;
181+
hidePBVerificationOverlay();
160182
}
161183
});
162184
} else {
@@ -171,6 +193,9 @@ jQuery(document).ready(function($) {
171193
}, nextDelay);
172194
} else {
173195
alert('⚠️ Payment could not be verified on-chain. Please try again.');
196+
hidePBVerificationOverlay();
197+
paymentInitiated = false;
198+
unlockFlowCompleted = false;
174199
}
175200
}
176201
}
@@ -187,6 +212,11 @@ jQuery(document).ready(function($) {
187212
unlockAddr = null;
188213
unlockTx = null;
189214
},
215+
onClose: function() {
216+
if (paymentInitiated && !unlockFlowCompleted) {
217+
showPBVerificationOverlay();
218+
}
219+
},
190220
});
191221
});
192222
});

templates/public/sticky-header.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,13 @@
6969
</button>
7070
</div>
7171
<?php endif; ?>
72+
</div>
73+
74+
<div id="paybutton_overlay" class="paybutton_overlay" style="display:none;">
75+
<div class="paybutton_overlay_inner">
76+
<div class="paybutton_overlay_content">
77+
<span class="paybutton_overlay_spinner"></span>
78+
<p id="paybutton_overlay_text">Verifying Payment...</p>
79+
</div>
80+
</div>
7281
</div>

0 commit comments

Comments
 (0)