Skip to content

Conversation

@jvsena42
Copy link
Member

@jvsena42 jvsena42 commented Apr 24, 2025

This PR improves the Wallet and LDK-node business logic handling, preventing crashes due to LDK-node / channels not initialized.

I tried to separate in two PRs but it wasn't possible due to coupling in the WalletViewModel.

  • Create the LightningRepository
  • Create the WalletRepository
  • Wrap the business logic in the repositories in try catch and return Result stats
  • Move the busniess logic from WalletViewModel to WalletRepository and implement the WalletRepository
  • Replace the LightningService direct acess with LightningRepository

Related to #50

@jvsena42 jvsena42 self-assigned this Apr 24, 2025
@jvsena42 jvsena42 mentioned this pull request Apr 25, 2025
2 tasks
@jvsena42 jvsena42 mentioned this pull request Apr 25, 2025
@jvsena42
Copy link
Member Author

I tried to make the refactor as specific as possible, I'm open to suggestions to this PR and further refactors

@jvsena42 jvsena42 marked this pull request as ready for review April 28, 2025 10:44
@jvsena42 jvsena42 requested a review from ovitrif April 28, 2025 10:44
@jvsena42 jvsena42 changed the title Wallet and LDK node business logic handling Improve Wallet and LDK node business logic handling Apr 28, 2025
Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

Almost ready IMHO, super nice work, thank you!

Please check review comments & address.


tests refactor:

  • launch with existing wallet - 🟢
  • wipe wallet - 🟠 UI freeze while wiping for a little while
  • create new wallet - 🟢
  • deposit sats & mine - check balance & empty views - 🟢
  • restore wallet - check UI & restore functionality - 🟢
  • cjit - scan & pay while app is in bg - bg receive - 🟢
  • try to break app with quick minimise + restore - 🟠 discussed in Slack
  • send LN & onchain, receive LN & onchain - 🟢

Comment on lines +169 to +172
lightningRepo.getPayments().onSuccess {
coreService.activity.syncLdkNodePayments(it)
syncState()
}.onFailure { e ->
Copy link
Collaborator

@ovitrif ovitrif Apr 28, 2025

Choose a reason for hiding this comment

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

This wasn't and isn't working correctly on app returning to FG, but at least now we know, thanks to the error logging 👍🏻

The actual issue is in the timing, it gets called before the node is ready.

<just info, can resolve comment>

Copy link
Member Author

Choose a reason for hiding this comment

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

I can improve this in the next refactor. I'll probably wrap most lightningRepo in a waitForTheNodeStart(callback: () -> Unit) method

@jvsena42 jvsena42 marked this pull request as draft April 28, 2025 15:49
@jvsena42
Copy link
Member Author

jvsena42 commented Apr 28, 2025

Thanks for the good points in the review!

@jvsena42 jvsena42 marked this pull request as ready for review April 28, 2025 17:09
@jvsena42 jvsena42 requested a review from ovitrif April 28, 2025 17:13
Copy link
Collaborator

@ovitrif ovitrif left a comment

Choose a reason for hiding this comment

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

Thanks a lot for addressing all review comments 🫡

Looks good, very nice refactoring I must say, it was long due 🥇

Ran a few sanity checks again, everything still works, I'm merging this 🚀

@ovitrif ovitrif merged commit ca35f76 into master Apr 28, 2025
1 check passed
@ovitrif ovitrif deleted the refactor/lightning-repository branch April 28, 2025 17:38
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.

3 participants