Changeset 3470355
- Timestamp:
- 02/26/2026 02:11:31 PM (5 weeks ago)
- Location:
- kaspa-payments-gateway-woocommerce/trunk
- Files:
-
- 2 edited
-
assets/kaspa-checkout.js (modified) (6 diffs)
-
includes/kaspa-frontend-assets.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
kaspa-payments-gateway-woocommerce/trunk/assets/kaspa-checkout.js
r3470345 r3470355 65 65 if (btn) { 66 66 btn.addEventListener('click', handleKasWarePay); 67 68 // Disable button until address is ready 69 if (!getPaymentAddress()) { 70 btn.disabled = true; 71 btn.textContent = 'Waiting for address...'; 72 const addressPoll = setInterval(function () { 73 if (getPaymentAddress()) { 74 clearInterval(addressPoll); 75 btn.disabled = false; 76 btn.textContent = 'Pay ' + expectedAmount + ' KAS with KasWare'; 77 } 78 }, 500); 79 } 67 80 } 68 81 } … … 129 142 if (statusEl) statusEl.textContent = 'Please confirm the transaction in the KasWare popup.'; 130 143 131 var txid = await window.kasware.sendKaspa(address, sompiAmount, { priorityFee: 0 }); 132 133 if (!txid || typeof txid !== 'string' || txid.length < 10) { 144 var txResult = await window.kasware.sendKaspa(address, sompiAmount, { priorityFee: 0 }); 145 146 // KasWare may return a JSON string of the full tx, an object, or just the txid 147 var txid; 148 if (typeof txResult === 'string') { 149 try { 150 var parsed = JSON.parse(txResult); 151 txid = parsed.id || txResult; 152 } catch (e) { 153 txid = txResult; 154 } 155 } else if (txResult && typeof txResult === 'object' && txResult.id) { 156 txid = txResult.id; 157 } 158 159 if (!txid || typeof txid !== 'string' || !/^[a-f0-9]{64}$/i.test(txid)) { 134 160 throw new Error('Invalid transaction ID returned from KasWare'); 135 161 } 136 162 137 163 // Step 3: Payment sent — start fast verification 138 console.log('[KaspaWoo] tx broadcast at ' + new Date().toISOString() + ' txid: ' + txid);139 164 kaswareTxid = txid; 140 165 btn.className = 'kaspa-kasware-btn success'; … … 185 210 attempt = attempt || 1; 186 211 var maxAttempts = 5; 187 console.log('[KaspaWoo] notify attempt ' + attempt + ' at ' + new Date().toISOString());188 212 189 213 var xhr = new XMLHttpRequest(); … … 192 216 xhr.onreadystatechange = function () { 193 217 if (xhr.readyState === 4) { 194 console.log('[KaspaWoo] notify response: ' + xhr.status + ' at ' + new Date().toISOString());195 218 if (xhr.status === 200) { 196 219 try { 197 220 var response = JSON.parse(xhr.responseText); 198 console.log('[KaspaWoo] notify result: ' + JSON.stringify(response.data));199 221 if (response.success && response.data.status === 'completed') { 200 222 serverVerified = true; … … 251 273 function fastCheckTxid() { 252 274 if (serverVerified) return; 253 console.log('[KaspaWoo] fast poll at ' + new Date().toISOString());254 275 var xhr = new XMLHttpRequest(); 255 276 xhr.open('POST', ajaxUrl, true); … … 259 280 try { 260 281 var response = JSON.parse(xhr.responseText); 261 console.log('[KaspaWoo] fast poll result: ' + response.data.status);262 282 if (response.success && response.data.status === 'completed') { 263 283 serverVerified = true; -
kaspa-payments-gateway-woocommerce/trunk/includes/kaspa-frontend-assets.php
r3470345 r3470355 365 365 plugin_dir_url(__DIR__) . 'assets/kaspa-checkout.js', 366 366 array(), 367 '2. 3.0',367 '2.5.0', 368 368 true 369 369 );
Note: See TracChangeset
for help on using the changeset viewer.