Plugin Directory

Changeset 3470355


Ignore:
Timestamp:
02/26/2026 02:11:31 PM (5 weeks ago)
Author:
jacobo1
Message:

Fix KasWare txid parsing, disable button until address ready, remove debug logs

Location:
kaspa-payments-gateway-woocommerce/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kaspa-payments-gateway-woocommerce/trunk/assets/kaspa-checkout.js

    r3470345 r3470355  
    6565        if (btn) {
    6666            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            }
    6780        }
    6881    }
     
    129142            if (statusEl) statusEl.textContent = 'Please confirm the transaction in the KasWare popup.';
    130143
    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)) {
    134160                throw new Error('Invalid transaction ID returned from KasWare');
    135161            }
    136162
    137163            // Step 3: Payment sent — start fast verification
    138             console.log('[KaspaWoo] tx broadcast at ' + new Date().toISOString() + ' txid: ' + txid);
    139164            kaswareTxid = txid;
    140165            btn.className = 'kaspa-kasware-btn success';
     
    185210        attempt = attempt || 1;
    186211        var maxAttempts = 5;
    187         console.log('[KaspaWoo] notify attempt ' + attempt + ' at ' + new Date().toISOString());
    188212
    189213        var xhr = new XMLHttpRequest();
     
    192216        xhr.onreadystatechange = function () {
    193217            if (xhr.readyState === 4) {
    194                 console.log('[KaspaWoo] notify response: ' + xhr.status + ' at ' + new Date().toISOString());
    195218                if (xhr.status === 200) {
    196219                    try {
    197220                        var response = JSON.parse(xhr.responseText);
    198                         console.log('[KaspaWoo] notify result: ' + JSON.stringify(response.data));
    199221                        if (response.success && response.data.status === 'completed') {
    200222                            serverVerified = true;
     
    251273    function fastCheckTxid() {
    252274        if (serverVerified) return;
    253         console.log('[KaspaWoo] fast poll at ' + new Date().toISOString());
    254275        var xhr = new XMLHttpRequest();
    255276        xhr.open('POST', ajaxUrl, true);
     
    259280                try {
    260281                    var response = JSON.parse(xhr.responseText);
    261                     console.log('[KaspaWoo] fast poll result: ' + response.data.status);
    262282                    if (response.success && response.data.status === 'completed') {
    263283                        serverVerified = true;
  • kaspa-payments-gateway-woocommerce/trunk/includes/kaspa-frontend-assets.php

    r3470345 r3470355  
    365365        plugin_dir_url(__DIR__) . 'assets/kaspa-checkout.js',
    366366        array(),
    367         '2.3.0',
     367        '2.5.0',
    368368        true
    369369    );
Note: See TracChangeset for help on using the changeset viewer.