Commit Graph

114 Commits

Author SHA1 Message Date
Sander van Grieken 91efb3e1f4 common_qt: move QtEventListener and qt_event_listener decorator to common_qt 2026-03-03 13:03:46 +01:00
SomberNight ca597942fd qml: (trivial) qeinvoice: add type hint 2026-01-14 16:13:00 +00:00
f321x b599ae7d4a qml: fix invalid QEInvoiceParser state
Fixes the issue described in #10406.
When scanning a lightning invoice we would pass it to
`QEInvoiceParser.fromResolvedPaymentIdentifier()`, however
`fromResolvedPaymentIdentifier()` doesn't reset the state of
`QEInvoiceParser._lnurlData` which is used in QML to evaluate
`payImmediately: invoiceParser.isLnurlPay` in the `onValidationSuccess`
connection.

This change calls `clear()` in `fromResolvedPaymentIdentifier()` to
ensure that `QEInvoiceParser` state gets reset when loading a new invoice.
However when retrieving a bolt11 from a lnurl-pay callback we don't
wan't to reset `QEInvoiceParser._lnurlData` so that `payImmediately` is
true when confirming the lnurl pay dialog, for that I skip calling
`fromResolvedPaymentIdentifier()` and instead call `validateRecipient()`
directly so the `QEInvoiceParser` state doesn't get reset in this case.
2026-01-14 11:42:55 +01:00
SomberNight 1006e8092f lnworker: split LNWallet and LNWorker: LNWallet "has an" LNWorker
- LNWallet no longer "is-an" LNWorker, instead LNWallet "has-an" LNWorker
- the motivation is to make the unit tests nicer, and allow writing unit tests for more things
  - I hope this makes it possible to e.g. test lnsweep in the unit tests
  - some stuff we would previously have to write a regtest for, maybe we can write a unit test for, now
- in unit tests, MockLNWallet now
  - inherits LNWallet
  - the Wallet is no longer being mocked
2026-01-05 15:55:31 +00:00
SomberNight 49430e9722 qml: fix: paying to openalias
regression from in https://github.com/spesmilo/electrum/pull/9993
    7d0ac64d06
2025-12-05 16:12:04 +00:00
Sander van Grieken c519083b9b qml: show lightning invoice amounts with msat precision, allow msat precision entry for no-amount lightning invoices 2025-11-27 12:38:57 +01:00
Sander van Grieken 93c9dd9d12 qml: refactor invoice amount checks, msat precision for lightning.
add qeconfig unit tests for conversion methods.
2025-11-27 12:38:49 +01:00
Sander van Grieken 81c83f8318 qeinvoice: query self.status once in update_userinfo() and determine_can_pay() 2025-11-13 12:40:37 +01:00
f321x b90090e2dd qml: separate PI resolving from QEInvoiceParser
separates the resolving step from the QEInvoiceParser so the 'recipient'
can be resolved first and then either an QEInvoiceParser can be used if
it is a sending request that has been resolved (invoice, address,
lnurlp, ...), or RequestDetails can be used if the resolved 'recipient'
turns out to be a voucher/LNURLW string.

# Conflicts:
#	electrum/gui/qml/qeinvoice.py
2025-08-27 15:35:03 +02:00
f321x fdeada3f51 lnurl: implement LNURL-withdraw
adds handling of lnurl-withdraw payment identifiers which allow users to
withdraw bitcoin from a service by scanning a qr code or pasting the
lnurl-w code as "sending" address.
2025-08-27 15:31:43 +02:00
Sander van Grieken 43c6f45040 qml: handle invoice validation errors on save 2025-08-12 20:27:58 +02:00
SomberNight 10e3bad884 qml: qeinvoice: don't use wallet.get_balance() for NotEnoughFunds checks
related https://github.com/spesmilo/electrum/issues/8835
2025-06-29 22:59:30 +00:00
SomberNight 71627b91c4 qml: set BtcField.textAsSats initial value to match its text
textAsSats was being set to 0 initially, regardless of actual text, only healing after onTextChanged.

fixes https://github.com/spesmilo/electrum/issues/9974
2025-06-24 09:19:13 +00:00
Sander van Grieken 7ba335a409 qml: also update userinfo text on channel events. fixes #9884 2025-06-03 10:41:55 +02:00
f321x 61492d361e Use async dnspython methods for openalias/dnssec 2025-05-16 17:09:41 +02:00
Sander van Grieken a45ca41268 qml: fix storing override amount too soon, while user is allowed to set a new override amount which was silently ignored.
lightning: implicit save of lightning invoice with override amount deferred until actual payment is accepted.
on-chain: for now, invoice is implicitly saved when override amount is passed to ConfirmTxDialog. (this is sooner
than current desktop client, which saves - and only saves - when Pay is clicked from ConfirmTxDialog)
2025-05-14 10:57:57 +02:00
Sander van Grieken 7391a1039d qml: don't confuse second payment to same address with previous unconfirmed payment to that address
QEInvoiceParser creates a zero amount output invoice when pasting an address, which would return the
wrong status when calling wallet.get_invoice_status() (there is some address heuristic in
wallet._is_onchain_invoice_paid which is associating with the previous payment)
2025-04-09 13:19:46 +02:00
Sander van Grieken 71801de7ea qml: show insufficient balance text for lightning invoice without fallback and insufficient ln send capacity 2025-04-07 10:02:25 +02:00
ThomasV 26910ef81d Merge pull request #9620 from accumulator/lightning_pass_invoice_not_bolt11
refactor lnworker.pay_invoice to accept Invoice object instead of bolt11 string
2025-03-18 20:09:01 +01:00
Sander van Grieken 083b32be3b qt,qml: more regression fixes 2025-03-10 19:42:37 +01:00
Sander van Grieken 6fdb6c93f7 refactor lnworker.pay_invoice to accept Invoice object instead of bolt11 string
rename lnworker._check_invoice to lnworker._check_bolt11_invoice
2025-03-09 14:47:34 +01:00
Sander van Grieken 37f0069f2a qml: calculate max amount when max toggle is enabled 2025-01-23 16:00:01 +01:00
SomberNight 30028520e0 qml/qeinvoice.py: show error details when scanning e.g. lnurl-withdraw
saying the lnurl type is not supported is more informative than "could not resolve"
2025-01-09 16:10:46 +00:00
SomberNight c84664617d qml: qeinvoice: fix regression in update_userinfo
follow-up 3b0cdef871

```
 29.60 | E | lnworker.LNWallet.[test_segwit_2] | Exception in pay_invoice: TypeError("unhashable type: 'list'")
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/util.py", line 1153, in wrapper
    return await func(*args, **kwargs)
  File "/home/user/wspace/electrum/electrum/lnworker.py", line 1518, in pay_invoice
    self.set_invoice_status(key, PR_INFLIGHT)
  File "/home/user/wspace/electrum/electrum/lnworker.py", line 2404, in set_invoice_status
    util.trigger_callback('invoice_status', self.wallet, key, status)
  File "/home/user/wspace/electrum/electrum/util.py", line 1796, in trigger_callback
    callback(*args)
  File "/home/user/wspace/electrum/electrum/gui/qml/qeinvoice.py", line 90, in on_event_invoice_status
    self.update_userinfo()
  File "/home/user/wspace/electrum/electrum/gui/qml/qeinvoice.py", line 327, in update_userinfo
    self.userinfo = userinfo_for_invoice_status([self.status])
  File "/home/user/wspace/electrum/electrum/gui/qml/qeinvoice.py", line 305, in userinfo_for_invoice_status
    return {
TypeError: unhashable type: 'list'
```
2024-05-06 18:11:31 +00:00
Sander van Grieken 3b0cdef871 qml: lightning invoice status can be one of onchain invoice states when using fallback address. (fixes #9018) 2024-04-24 13:37:33 +02:00
Sander van Grieken e2bb7df54a qml: invert, more strict check in determine_can_pay for invoice types,
also disable paste button while PI is being evaluated
2024-01-17 14:09:57 +01:00
Sander van Grieken 4469e9989d qml: LNURLp has no bolt11 to query until later. fixes #8822 2024-01-17 13:52:01 +01:00
Sander van Grieken cb34bbee7e qml: don't enable save button for already saved invoices 2023-12-21 13:29:37 +01:00
Sander van Grieken 03dd38bfb8 qml: add support for ln address and openalias, fix lnurl finalize step,
avoid overloading invoiceParser with new payment identifiers while potentially long-running
resolve/finalize steps are ongoing, show errors inresolve/finalize steps to user.
2023-11-20 17:16:22 +01:00
Sander van Grieken 6270eae5c9 qml: port PyQt5 to PyQt6 2023-11-07 10:16:18 +01:00
Sander van Grieken 6c51927576 qml: emit error when bip21 contains neither an address nor a lightning invoice (fixes #8662) 2023-11-01 02:54:19 +01:00
Sander van Grieken 941f425ff5 qml: update invoice.canPay on channel state changes
This re-evaluates invoice.canPay when channels get connected/disconnected (enables/disables Pay button)
2023-10-12 15:53:15 +02:00
Sander van Grieken 190c19d48c whitespace, imports, code style 2023-09-22 16:38:37 +02:00
Sander van Grieken 0a804607a4 qml: properly suggest paying bolt11 invoice onchain if insufficient LN balance.
Also, if fallback address is present, don't warn on bolt11 and no ln channels.
2023-09-01 15:03:44 +02:00
SomberNight ffa3acc013 invoices: don't modify .amount_msat directly 2023-08-22 18:12:15 +00:00
SomberNight 612a8e6424 qt: fix: bip70 pay reqs need x509 verification
regression from https://github.com/spesmilo/electrum/pull/8462

- pr.verify() was called in qml, but not in qt gui
- we now call pr.verify() in get_payment_request(), to make the API less error-prone
- it is now ok to call pr.verify() multiple times, the result is cached
2023-07-10 17:50:53 +00:00
Sander van Grieken f980bd97b5 payment_identifier: factor out bip21 functions to bip21.py to break cyclic dependencies,
parse bolt11 only once, store invoice internally instead of bolt11 string
add is_onchain method to indicate if payment identifier can be paid onchain
2023-07-08 12:18:37 +02:00
Sander van Grieken eed016bd7e qt: move setting frozen styling to edit components themselves, fix re-enabling Clear button after finalize 2023-06-28 16:49:28 +02:00
Sander van Grieken ca283a75d0 qml: exclude non-address SPK from supported payment identifiers 2023-06-28 16:49:28 +02:00
Sander van Grieken 74a1f38a8b payment identifier types as enum 2023-06-28 16:49:28 +02:00
Sander van Grieken fc141c0182 payment_identfier: refactor qml and tests 2023-06-28 16:49:28 +02:00
SomberNight 24980feab7 config: introduce ConfigVars
A new config API is introduced, and ~all of the codebase is adapted to it.
The old API is kept but mainly only for dynamic usage where its extra flexibility is needed.

Using examples, the old config API looked this:
```
>>> config.get("request_expiry", 86400)
604800
>>> config.set_key("request_expiry", 86400)
>>>
```

The new config API instead:
```
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS
604800
>>> config.WALLET_PAYREQ_EXPIRY_SECONDS = 86400
>>>
```

The old API operated on arbitrary string keys, the new one uses
a static ~enum-like list of variables.

With the new API:
- there is a single centralised list of config variables, as opposed to
  these being scattered all over
- no more duplication of default values (in the getters)
- there is now some (minimal for now) type-validation/conversion for
  the config values

closes https://github.com/spesmilo/electrum/pull/5640
closes https://github.com/spesmilo/electrum/pull/5649

Note: there is yet a third API added here, for certain niche/abstract use-cases,
where we need a reference to the config variable itself.
It should only be used when needed:
```
>>> var = config.cv.WALLET_PAYREQ_EXPIRY_SECONDS
>>> var
<ConfigVarWithConfig key='request_expiry'>
>>> var.get()
604800
>>> var.set(3600)
>>> var.get_default_value()
86400
>>> var.is_set()
True
>>> var.is_modifiable()
True
```
2023-05-25 17:39:48 +00:00
SomberNight 312e50e9a9 qml: send screen: bip21: fallback to onchain addr if no LN channels
given a bip21 uri that has both onchain addr and bolt11,
if we have LN enabled but no LN channels, auto-fallback to paying onchain

we will have to clean up and unify this logic between GUIs. becoming spaghetti :/
rumour has it, Thomas has a branch? :P
2023-04-25 22:23:24 +00:00
Sander van Grieken a23457f48d qml: consistency camelcase pyqtProperties 2023-04-25 14:15:13 +02:00
Sander van Grieken 264540e12b qml: consistency camelcase public slots qedaemon, qeinvoice, qewizard 2023-04-25 13:40:16 +02:00
SomberNight 312f2641e7 don't use bare except
use "except Exception", or if really needed explicitly "except BaseException"
2023-04-24 12:58:01 +00:00
SomberNight a8623f63bb qml: fix send "flow with LN but not LN enabled AND having bip21 uri"
closes https://github.com/spesmilo/electrum/issues/8334
2023-04-23 16:42:08 +00:00
SomberNight 7907eb1f86 qml/qeinvoice.py: turn _bip21 field into local var 2023-04-23 16:36:32 +00:00
ThomasV a03f4769ca auth_protect: pass authMessage in the auth_protect decorator,
instead of relying on side-effects

This is probably safer, and also more self-contained.
2023-04-17 18:17:29 +02:00
ThomasV 85291b2de3 follow-up 5b6a16e097 2023-04-17 16:54:26 +02:00