Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: dev-friendly payment status name #2322

Merged
merged 4 commits into from
Mar 13, 2024
Merged

Conversation

motorina0
Copy link
Collaborator

@motorina0 motorina0 commented Mar 12, 2024

The first parameter of PaymentStatus indicates the actual state (success=True, failed=False, pending=None).

This is hard to read and remember.

This PR uses 3 new explicit subclasses:

class PaymentSuccessStatus(PaymentStatus):
    paid = True


class PaymentFailedStatus(PaymentStatus):
    paid = False


class PaymentPendingStatus(PaymentStatus):
    paid = None

Copy link

codecov bot commented Mar 12, 2024

Codecov Report

Attention: Patch coverage is 32.46753% with 52 lines in your changes are missing coverage. Please review.

Project coverage is 58.55%. Comparing base (65b8868) to head (0a67999).

Files Patch % Lines
lnbits/wallets/spark.py 0.00% 11 Missing ⚠️
lnbits/wallets/corelightning.py 46.66% 8 Missing ⚠️
lnbits/wallets/lndgrpc.py 37.50% 5 Missing ⚠️
lnbits/wallets/lndrest.py 28.57% 5 Missing ⚠️
lnbits/wallets/lnbits.py 50.00% 4 Missing ⚠️
lnbits/wallets/cliche.py 0.00% 2 Missing ⚠️
lnbits/wallets/corelightningrest.py 0.00% 2 Missing ⚠️
lnbits/wallets/eclair.py 0.00% 2 Missing ⚠️
lnbits/wallets/lntips.py 0.00% 2 Missing ⚠️
lnbits/wallets/opennode.py 0.00% 2 Missing ⚠️
... and 7 more
Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #2322   +/-   ##
=======================================
  Coverage   58.55%   58.55%           
=======================================
  Files          61       61           
  Lines        9204     9210    +6     
=======================================
+ Hits         5389     5393    +4     
- Misses       3815     3817    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

lnbits/core/services.py Outdated Show resolved Hide resolved
@motorina0 motorina0 marked this pull request as ready for review March 12, 2024 12:21
@motorina0 motorina0 added this to the 0.12.3 milestone Mar 12, 2024
@prusnak
Copy link
Collaborator

prusnak commented Mar 12, 2024

There are still lots of places like these used in almost all wallet implementations.

Examples:

(cliche.py)

        statuses = {"pending": None, "complete": True, "failed": False}
        return PaymentStatus(statuses[data["result"]["status"]])

(alby.py)

        statuses = {
            "CREATED": None,
            "SETTLED": True,
        }
        return PaymentStatus(statuses[data.get("state")], fee_msat=None, preimage=None)

These deserve to be refactored too because readability of such constructs is horrible.

@motorina0 motorina0 force-pushed the refactor_payment_status_names branch from 575bc51 to c902073 Compare March 12, 2024 13:34
@motorina0
Copy link
Collaborator Author

There are still lots of places like these used in almost all wallet implementations.

This is a good idea, but it is a bit more work. I want to keep this PR easy to review and merge.
I have started on extracting statuses from funding sources in this WIP PR: #2323
Lets continue the status topic on the #2323 PR and move forward to merge this (simple) one.

@prusnak
Copy link
Collaborator

prusnak commented Mar 13, 2024

Fair enough 👍

One nitpick though:

I find PaymentStatusPending, PaymentStatusFailed and PaymentStatusSuccess better than PaymentPendingStatus, PaymentFailedStatus and PaymentSuccessStatus. Any thoughts?

@motorina0
Copy link
Collaborator Author

I find PaymentStatusPending, PaymentStatusFailed and PaymentStatusSuccess better than PaymentPendingStatus, PaymentFailedStatus and PaymentSuccessStatus. Any thoughts?

I agree, will be added to the #2323 together with PaymentResponse changes.

Copy link
Collaborator

@prusnak prusnak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@dni dni merged commit 352fd23 into dev Mar 13, 2024
23 checks passed
@dni dni deleted the refactor_payment_status_names branch March 13, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants