Skip to content

Commit 0df4d0d

Browse files
committed
Refactor format_msat, fix formatting bug
1 parent ffa9994 commit 0df4d0d

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

templates/completed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
Lightning rhash: <strong><?php echo $invoice->rhash ?></strong>
88
</li>
99
<li>
10-
Invoice amount: <strong><?php echo rtrim(number_format($invoice->msatoshi/100000000, 8), "0.") ?> mBTC</strong>
10+
Invoice amount: <strong><?php echo self::format_msat($invoice->msatoshi) ?></strong>
1111
</li>
1212
<li>
1313
Payment request: <strong><?php echo $invoice->payreq ?></strong>

templates/payment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<h1>Pay with Lightning</h1>
88
<h3>
99
<?php if ($order->get_currency() !== 'BTC'): ?> <?php echo $order->get_total() ?> <?php echo $order->get_currency() ?> = <?php endif ?>
10-
<?php echo rtrim(number_format($invoice->msatoshi/100000000, 8), "0.") ?> mBTC
10+
<?php echo self::format_msat($invoice->msatoshi) ?>
1111
</h3>
1212
<img class="qr" src="<?php echo $qr_uri ?>">
1313
<code class="payreq"><?php echo $invoice->payreq ?></code>

woocommerce-gateway-lightning.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,10 @@ protected static function make_desc($order) {
246246
if (count($products)) $desc = substr($desc, 0, -2) . ' and ' . count($products) . ' more items';
247247
return str_replace('"', '', $desc); // c-lightning's json parser doesn't like these, should eventually be fixed
248248
}
249+
250+
protected static function format_msat($msat) {
251+
return rtrim(rtrim(number_format($msat/100000000, 8), '0'), '.') . ' mBTC';
252+
}
249253
}
250254

251255
new WC_Gateway_Lightning();

0 commit comments

Comments
 (0)