From 3eaf0731205856b7575e82136c423ab38d85761f Mon Sep 17 00:00:00 2001 From: malik1004x Date: Sat, 13 Jun 2026 11:19:47 +0200 Subject: [PATCH] fix lnurl from scan button (#3332) --- cw_core/lib/lnurl.dart | 13 +++++++---- .../action_row/coin_action_row.dart | 22 +++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/cw_core/lib/lnurl.dart b/cw_core/lib/lnurl.dart index c04bfc684..03be284d5 100644 --- a/cw_core/lib/lnurl.dart +++ b/cw_core/lib/lnurl.dart @@ -7,12 +7,17 @@ const _BOLT_PREFIXES = ["lnbcrt", "lntbs", "lnbc", "lntb"]; const _LUD17_PREFIXES = ['lnurlw', 'lnurlc', 'lnurlp', 'keyauth']; bool isBolt11ZeroInvoice(String invoice) { - final request = Bech32Codec().decode(invoice.replaceFirst("lightning:", ""), invoice.length); + try { + final request = Bech32Codec().decode(invoice.replaceFirst("lightning:", ""), invoice.length); - final prefix = _BOLT_PREFIXES - .firstWhere((prefix) => request.hrp.startsWith(prefix), orElse: () => ""); - return request.hrp.length == prefix.length; + final prefix = _BOLT_PREFIXES + .firstWhere((prefix) => request.hrp.startsWith(prefix), orElse: () => ""); + + return request.hrp.length == prefix.length; + } catch(e) { + return false; + } } /// Get the amount of a Bolt 11 Invoice in diff --git a/lib/new-ui/widgets/coins_page/action_row/coin_action_row.dart b/lib/new-ui/widgets/coins_page/action_row/coin_action_row.dart index db877e1e2..5613132bc 100644 --- a/lib/new-ui/widgets/coins_page/action_row/coin_action_row.dart +++ b/lib/new-ui/widgets/coins_page/action_row/coin_action_row.dart @@ -163,17 +163,17 @@ class CoinActionRow extends StatelessWidget { late final PaymentRequest req; var unspentCoinType = UnspentCoinType.any; - // if (false && SendViewModelBase.isNonZeroAmountLightningInvoice(code)) { - // unspentCoinType = UnspentCoinType.lightning; - // final amount = CryptoCurrency.btcln.formatAmount(BigInt.from(getBolt11Amount(code) ?? 0)); - // req = PaymentRequest(code, amount, "", "", ""); - // } else if (false && SendViewModelBase.isLnurlInvoice(code)) { - // unspentCoinType = UnspentCoinType.lightning; - // final amount = CryptoCurrency.btcln.formatAmount(BigInt.from(await LNURL.getPayRequestAmount(code) ?? 0)); - // req = PaymentRequest(code, amount, "", "", ""); - // } else if (false &&OpenCryptoPayService.isOpenCryptoPayQR(code)) { - // req = PaymentRequest(code, "", "", "", ""); - // } else + if (SendViewModelBase.isNonZeroAmountLightningInvoice(code)) { + unspentCoinType = UnspentCoinType.lightning; + final amount = CryptoCurrency.btcln.formatAmount(BigInt.from(getBolt11Amount(code) ?? 0)); + req = PaymentRequest(code, amount, "", "", ""); + } else if (SendViewModelBase.isLnurlInvoice(code)) { + unspentCoinType = UnspentCoinType.lightning; + final amount = CryptoCurrency.btcln.formatAmount(BigInt.from(await LNURL.getPayRequestAmount(code) ?? 0)); + req = PaymentRequest(code, amount, "", "", ""); + } else if (OpenCryptoPayService.isOpenCryptoPayQR(code)) { + req = PaymentRequest(code, "", "", "", ""); + } else if (Uri.tryParse(code)?.scheme == "wc") { if (!isWalletConnectCompatibleChain(walletType)) { showPopUp(