qt: receive tab: also suggest swap for 0 amnt req
What changed, and why it matters
This commit is a small user-experience improvement in the Electrum Bitcoin wallet's Qt receive tab. It makes the wallet suggest a 'submarine swap' (a way to gain inbound Lightning capacity) even when the user creates a zero-amount Lightning invoice, if they currently have no incoming liquidity. It also tweaks some help messages shown to users. There is no security vulnerability here.
No security action needed. This is a routine UX improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch modifies two files. In wallet.py, it imports MIN_SWAP_AMOUNT_SAT and changes the condition for suggesting a swap so that a zero-amount invoice triggers a swap suggestion when the wallet has zero inbound capacity. It also adjusts help text. In lnworker.py, it only adds a more informative assertion message to suggest_swap_to_receive. The changes are defensive/UX-oriented and do not introduce unsafe behavior.
Changed components
electrum/gui/qt receive tab UXelectrum/wallet.pyelectrum/lnworker.pyInspect captured patch +8 / −6
diff --git a/electrum/lnworker.py b/electrum/lnworker.py
index 0261e3f..bdf96e5 100644
--- a/electrum/lnworker.py
+++ b/electrum/lnworker.py
@@ -3003,7 +3003,7 @@ class LNWallet(LNWorker):
return None
def suggest_swap_to_receive(self, amount_sat):
- assert amount_sat > self.num_sats_can_receive()
+ assert amount_sat > self.num_sats_can_receive(), f"{amount_sat=} | {self.num_sats_can_receive()=}"
try:
suggestions = self._suggest_channels_for_rebalance(RECEIVED, amount_sat)
except NotEnoughFunds:
diff --git a/electrum/wallet.py b/electrum/wallet.py
index e28778a..0b471b7 100644
--- a/electrum/wallet.py
+++ b/electrum/wallet.py
@@ -80,6 +80,7 @@ from .lnutil import MIN_FUNDING_SAT
from .lntransport import extract_nodeid
from .descriptor import Descriptor
from .txbatcher import TxBatcher
+from .submarine_swaps import MIN_SWAP_AMOUNT_SAT
if TYPE_CHECKING:
from .network import Network
@@ -3429,7 +3430,8 @@ class Abstract_Wallet(ABC, Logger, EventListener):
self.lnworker and len([chan for chan in self.lnworker.channels.values() if chan.is_open()]) > 0
)
lightning_online = self.lnworker and self.lnworker.num_peers() > 0
- can_receive_lightning = self.lnworker and amount_sat <= self.lnworker.num_sats_can_receive()
+ can_receive = self.lnworker.num_sats_can_receive()
+ can_receive_lightning = self.lnworker and can_receive > 0 and amount_sat <= can_receive
try:
zeroconf_nodeid = extract_nodeid(self.config.ZEROCONF_TRUSTED_NODE)[0]
except Exception:
@@ -3469,7 +3471,7 @@ class Abstract_Wallet(ABC, Logger, EventListener):
ln_help = _('You must be online to receive Lightning payments.')
elif not can_receive_lightning or (amount_sat <= 0 and not lightning_has_channels):
ln_rebalance_suggestion = self.lnworker.suggest_rebalance_to_receive(amount_sat)
- ln_swap_suggestion = self.lnworker.suggest_swap_to_receive(amount_sat)
+ ln_swap_suggestion = self.lnworker.suggest_swap_to_receive(max(amount_sat, MIN_SWAP_AMOUNT_SAT))
# prefer to use swaps over JIT channels if possible
if can_get_zeroconf_channel and not bool(ln_rebalance_suggestion) and not bool(ln_swap_suggestion):
if amount_sat < MIN_FUNDING_SAT:
@@ -3483,11 +3485,11 @@ class Abstract_Wallet(ABC, Logger, EventListener):
f'service provider. Service fees are deducted from the incoming payment.')
else:
ln_is_error = True
- ln_help = _('You do not have the capacity to receive this amount with Lightning.')
+ ln_help = _('You do not have enough capacity to receive with Lightning.')
if bool(ln_rebalance_suggestion):
- ln_help += '\n\n' + _('You may have that capacity if you rebalance your channels.')
+ ln_help += '\n\n' + _('You may have enough capacity if you rebalance your channels.')
elif bool(ln_swap_suggestion):
- ln_help += '\n\n' + _('You may have that capacity if you swap some of your funds.')
+ ln_help += '\n\n' + _('You may have enough capacity if you swap some of your funds.')
# for URI that has LN part but no onchain part, copy error:
if not addr and ln_is_error:
URI_is_error = ln_is_error
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.