Skip to content

Commit 23e1eb9

Browse files
chore: trim redundant comments
1 parent fac7352 commit 23e1eb9

7 files changed

Lines changed: 111 additions & 453 deletions

File tree

assets/js/monero-checkout.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
// Live payment progress on the order-received page. Real on-chain state polled
2-
// server-side: order status, confirmations, chain tip. Steps: Watching → Detected
3-
// → Confirming N/M → Confirmed.
1+
// Live Monero payment status for the order page.
42
(function () {
53
var host = document.getElementById('monero-gateway-status');
64
if (!host) return;
75
var url = host.getAttribute('data-poll');
86
var already = host.getAttribute('data-paid') === '1';
97
var rawRedirect = host.getAttribute('data-redirect') || '';
10-
// Only follow absolute http(s) or same-origin relative path — never javascript:/data:/protocol-relative.
8+
// Restrict redirects to HTTP(S) or same-origin relative paths.
119
var redirect = (/^https?:\/\//i.test(rawRedirect) || /^\/[^/]/.test(rawRedirect)) ? rawRedirect : '';
1210
if (!url) return;
1311

1412
var L = window.monero_gatewayL10n || {};
1513
var STEPS = [L.watching || 'Watching', L.detected || 'Detected', L.confirming || 'Confirming', L.confirmed || 'Confirmed'];
1614

1715
var wrap = document.createElement('div'); wrap.className = 'mg-prog';
18-
// Visual stepper is decorative; live status is announced via .mg-msg (avoids double-speak).
16+
// The message, not the decorative stepper, announces live status.
1917
var steps = document.createElement('div'); steps.className = 'mg-steps'; steps.setAttribute('aria-hidden', 'true');
2018
var dots = [];
2119
for (var i = 0; i < STEPS.length; i++) {
@@ -35,20 +33,18 @@
3533

3634
function fmt(n) { return String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ','); }
3735

38-
// Original expected amount/label from the monero-pay element before any mutation.
3936
function findPay() {
4037
return document.querySelector('.monero-gateway-panel monero-pay') || document.querySelector('monero-pay');
4138
}
4239
var payInit = findPay();
4340
var originalAmount = payInit ? payInit.getAttribute('amount') : null;
4441
var originalLabel = payInit ? payInit.getAttribute('label') : null;
4542

46-
// Drive QR amount from server state on every paint (two-way; no sticky shortfall).
4743
function syncPayWidget(d) {
4844
var el = findPay();
4945
if (!el) return;
5046
var st = d && d.status;
51-
// Payment in flight or finished: hide QR/URI so the buyer cannot overpay.
47+
// Hide payment instructions once funds are in flight.
5248
if (d.terminal || d.paid || st === 'mempool' || st === 'unconfirmed' || st === 'locked' || st === 'confirming') {
5349
el.style.display = 'none';
5450
return;
@@ -109,7 +105,6 @@
109105
else {
110106
msg.style.color = '#b45309';
111107
if (d.status === 'mempool') text = L.mMempool || 'Payment detected — waiting for the first confirmation.';
112-
// unconfirmed + confirming share the same l10n string (c/m confirmations).
113108
else if (d.status === 'unconfirmed' || d.status === 'confirming') text = (L.mConfirming || 'Confirming — {c}/{m} confirmations.').replace('{c}', d.confirmations != null ? d.confirmations : 0).replace('{m}', d.minConfirmations != null ? d.minConfirmations : 1);
114109
else if (d.status === 'partial') text = (L.mPartial || 'Received {r} XMR — send {s} more (QR updated).').replace('{r}', d.receivedXmr != null ? d.receivedXmr : '?').replace('{s}', d.shortfallXmr || '?');
115110
else if (d.status === 'locked') text = L.mLocked || 'Funds received — maturing on-chain…';
@@ -125,8 +120,7 @@
125120
if (already) { paint({ paid: true }); return; }
126121
paint({ status: 'pending' });
127122

128-
// Poll politely: (a) never poll a hidden tab, (b) ramp interval as wait grows,
129-
// (c) hard-stop after ~6h (unless payment in flight), (d) stop on terminal state.
123+
// Back off while waiting, pause when hidden, and stop on terminal states.
130124
var stopped = false, timer = null, started = Date.now(), lastStatus = null;
131125
var MAX_MS = 6 * 60 * 60 * 1000;
132126
function interval() {
@@ -145,7 +139,7 @@
145139
function run() {
146140
if (stopped) return;
147141
if (Date.now() - started > MAX_MS) {
148-
// Keep polling while a payment is in flight (incl. locked / confirming).
142+
// Keep polling while a payment is in flight.
149143
if (lastStatus !== 'partial' && lastStatus !== 'mempool' && lastStatus !== 'unconfirmed' &&
150144
lastStatus !== 'locked' && lastStatus !== 'confirming') {
151145
hardStop();

includes/class-monero-admin-payments.php

Lines changed: 17 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
<?php
2-
/**
3-
* Monero payments admin list.
4-
*
5-
* @package Monero_Gateway
6-
*/
2+
/** WooCommerce admin list for Monero payments. */
73

84
if ( ! defined( 'ABSPATH' ) ) {
95
exit;
@@ -15,9 +11,7 @@
1511
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
1612
}
1713

18-
/**
19-
* Lists orders using the Monero gateway.
20-
*/
14+
/** List-table implementation for Monero orders. */
2115
class Monero_Gateway_Admin_Payments_List extends WP_List_Table {
2216
private const VIEWS = array(
2317
'pending' => array( 'watching', 'partial', 'underpaid', 'mempool', 'unconfirmed', 'confirming', 'locked' ),
@@ -26,9 +20,7 @@ class Monero_Gateway_Admin_Payments_List extends WP_List_Table {
2620
'expired' => array( 'expired' ),
2721
);
2822

29-
/**
30-
* Number of orders displayed per page.
31-
*/
23+
/** Orders displayed per page. */
3224
const PER_PAGE = 20;
3325

3426
public static function status_values_for_view( $view ) {
@@ -56,9 +48,7 @@ private function query_args_for_view( $view ) {
5648
return $args;
5749
}
5850

59-
/**
60-
* Set up the list table.
61-
*/
51+
/** Configure the list table. */
6252
public function __construct() {
6353
parent::__construct(
6454
array(
@@ -69,11 +59,7 @@ public function __construct() {
6959
);
7060
}
7161

72-
/**
73-
* Get the table columns.
74-
*
75-
* @return array<string, string>
76-
*/
62+
/** Return table columns. */
7763
public function get_columns() {
7864
return array(
7965
'order' => __( 'Order', 'monero_gateway' ),
@@ -87,9 +73,7 @@ public function get_columns() {
8773
);
8874
}
8975

90-
/**
91-
* Prepare the current page of orders.
92-
*/
76+
/** Prepare the current page of orders. */
9377
public function prepare_items() {
9478
$current_page = max( 1, $this->get_pagenum() );
9579
$results = wc_get_orders(
@@ -129,13 +113,7 @@ public function get_views() {
129113
return $views;
130114
}
131115

132-
/**
133-
* Render a column value.
134-
*
135-
* @param WC_Order $order Order being displayed.
136-
* @param string $column_name Column name.
137-
* @return void
138-
*/
116+
/** Render a column value. */
139117
public function column_default( $order, $column_name ) {
140118
switch ( $column_name ) {
141119
case 'order':
@@ -177,11 +155,7 @@ public function column_default( $order, $column_name ) {
177155
}
178156
}
179157

180-
/**
181-
* Render the order and payment statuses.
182-
*
183-
* @param WC_Order $order Order being displayed.
184-
*/
158+
/** Render order and payment statuses. */
185159
private function render_status( $order ) {
186160
$order_status = wc_get_order_status_name( $order->get_status() );
187161
$payment_status = $this->get_meta_string( $order, '_monero_payment_status' );
@@ -192,11 +166,7 @@ private function render_status( $order ) {
192166
}
193167
}
194168

195-
/**
196-
* Render a shortened payment address.
197-
*
198-
* @param string $address Payment address.
199-
*/
169+
/** Render a shortened payment address. */
200170
private function render_address( $address ) {
201171
if ( '' === $address ) {
202172
echo esc_html( '' );
@@ -214,20 +184,12 @@ private function render_address( $address ) {
214184
);
215185
}
216186

217-
/**
218-
* Render a scalar value or a placeholder.
219-
*
220-
* @param string $value Value to render.
221-
*/
187+
/** Render a scalar value or placeholder. */
222188
private function render_value( $value ) {
223189
echo '' !== $value ? esc_html( $value ) : esc_html( '' );
224190
}
225191

226-
/**
227-
* Render transaction IDs stored as JSON or comma-separated text.
228-
*
229-
* @param mixed $stored_txids Stored transaction IDs.
230-
*/
192+
/** Render stored transaction IDs. */
231193
private function render_txids( $stored_txids ) {
232194
$txids = $this->parse_txids( $stored_txids );
233195

@@ -244,12 +206,7 @@ private function render_txids( $stored_txids ) {
244206
}
245207
}
246208

247-
/**
248-
* Parse transaction IDs from order meta.
249-
*
250-
* @param mixed $stored_txids Stored transaction IDs.
251-
* @return string[]
252-
*/
209+
/** Parse transaction IDs from order metadata. */
253210
private function parse_txids( $stored_txids ) {
254211
if ( is_array( $stored_txids ) ) {
255212
$txids = $stored_txids;
@@ -267,35 +224,23 @@ private function parse_txids( $stored_txids ) {
267224
return array_values( array_filter( $txids, 'strlen' ) );
268225
}
269226

270-
/**
271-
* Get scalar order meta as a string.
272-
*
273-
* @param WC_Order $order Order being displayed.
274-
* @param string $key Meta key.
275-
* @return string
276-
*/
227+
/** Read scalar order metadata. */
277228
private function get_meta_string( $order, $key ) {
278229
$value = $order->get_meta( $key );
279230

280231
return is_scalar( $value ) ? (string) $value : '';
281232
}
282233

283-
/**
284-
* Message shown when no orders match.
285-
*/
234+
/** Render the empty-list message. */
286235
public function no_items() {
287236
esc_html_e( 'No Monero payments found.', 'monero_gateway' );
288237
}
289238
}
290239

291-
/**
292-
* Register and render the Monero payments page.
293-
*/
240+
/** Register and render the Monero payments page. */
294241
class Monero_Gateway_Admin_Payments {
295242

296-
/**
297-
* Register the WooCommerce submenu page.
298-
*/
243+
/** Register the WooCommerce submenu. */
299244
public static function register_menu() {
300245
add_submenu_page(
301246
'woocommerce',
@@ -307,9 +252,7 @@ public static function register_menu() {
307252
);
308253
}
309254

310-
/**
311-
* Render the payments page.
312-
*/
255+
/** Render the payments page. */
313256
public static function render_page() {
314257
if ( ! current_user_can( 'manage_woocommerce' ) ) {
315258
return;

includes/class-monero-blocks.php

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
11
<?php
2-
/**
3-
* WooCommerce Blocks checkout integration for the Monero gateway.
4-
*/
2+
/** WooCommerce Blocks checkout integration for Monero. */
53

64
if ( ! defined( 'ABSPATH' ) ) {
75
exit;
86
}
97

108
use Automattic\WooCommerce\Blocks\Payments\Integrations\AbstractPaymentMethodType;
119

12-
/**
13-
* Registers monero_gateway as a Blocks payment method type.
14-
*/
10+
/** Register Monero as a Blocks payment method. */
1511
final class Monero_Blocks_Support extends AbstractPaymentMethodType {
1612

17-
/** @var string Payment method name (must match gateway id). */
13+
/** Payment method name. */
1814
protected $name = 'monero_gateway';
1915

20-
/**
21-
* Load gateway settings.
22-
*/
16+
/** Load gateway settings. */
2317
public function initialize() {
2418
$this->settings = get_option( 'woocommerce_monero_gateway_settings', array() );
2519
}
2620

27-
/**
28-
* Whether the method is available at Blocks checkout.
29-
* Uses the same runtime checks as the classic checkout.
30-
*/
21+
/** Mirror classic-checkout availability. */
3122
public function is_active() {
3223
$gateways = WC()->payment_gateways()->payment_gateways();
3324
return isset( $gateways[ $this->name ] ) && $gateways[ $this->name ]->can_accept_payments();
3425
}
3526

36-
/**
37-
* Register and return the Blocks payment method script handle.
38-
*
39-
* @return string[]
40-
*/
27+
/** Register and return the Blocks script handle. */
4128
public function get_payment_method_script_handles() {
4229
wp_register_script(
4330
'monero-gateway-blocks',
@@ -49,11 +36,7 @@ public function get_payment_method_script_handles() {
4936
return array( 'monero-gateway-blocks' );
5037
}
5138

52-
/**
53-
* Data exposed to the Blocks script as monero_gateway_data.
54-
*
55-
* @return array
56-
*/
39+
/** Return settings exposed to the Blocks script. */
5740
public function get_payment_method_data() {
5841
return array(
5942
'title' => $this->settings['title'] ?? __( 'Monero (XMR)', 'monero_gateway' ),

0 commit comments

Comments
 (0)