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

bip21 #110

Merged
merged 10 commits into from
Aug 25, 2024
Merged

bip21 #110

merged 10 commits into from
Aug 25, 2024

Conversation

reez
Copy link
Owner

@reez reez commented Jul 19, 2024

Description

Adding BIP21 support per lightningdevkit/ldk-node#302

Using locally generated bindings of ldk-node for now

[x] Receive
[x] Send
[x] Remove Bolt11
[x] Remove Bolt12
[x] Remove OnChain
[x] Add QRCodeView back once BitcoinUI updated for bip21 reez/BitcoinUI#101

Notes to the reviewers

Changelog notice

Checklists

All Submissions:

  • I've signed all my commits
  • I have formatted my code with swift-format per .swift-format file

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

Summary by CodeRabbit

  • New Features

    • Introduced support for BIP21 payment requests with a user-friendly interface for invoice creation and management.
    • Enhanced functionality for generating and managing payment requests through BIP21 and BOLT standards.
    • Added methods for parsing unified QR codes and copying payment details to the clipboard.
  • Bug Fixes

    • Improved error reporting clarity with new error cases.
  • Chores

    • Updated project file references and package dependencies.

Copy link

coderabbitai bot commented Jul 19, 2024

Warning

Rate limit exceeded

@reez has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 0 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 25d3b0f and aa80193.

Walkthrough

The recent updates to the LDKNodeMonday project enhance its capability to manage BIP21 payment requests, streamline project dependencies, and improve error handling. New Swift files for BIP21 functionality have been added, while redundant references have been removed and existing structures updated. These modifications refine the overall architecture for payment processing.

Changes

File Path Change Summary
LDKNodeMonday.xcodeproj/.../project.pbxproj Updated objectVersion, replaced LDKNode references, removed old ldk-node package reference, and added new Swift files.
LDKNodeMonday.xcodeproj/.../Package.resolved Removed ldk-node dependency entry and updated originHash.
LDKNodeMonday/Model/ReceiveOption.swift Commented out several cases in ReceiveOption, retaining only bip21.
LDKNodeMonday/Service/.../LightningNodeService.swift Introduced new async functions for processing BOLT11 and BIP21 payments.
LDKNodeMonday/Service/.../LightningServiceError.swift Added error handling for new error cases.
LDKNodeMonday/View/Home/Receive/.../BIP21View.swift New SwiftUI view for BIP21 payment requests, utilizing BIP21ViewModel.
LDKNodeMonday/View/Home/Receive/ReceiveView.swift Updated default selected option to bip21, modifying view logic accordingly.
LDKNodeMonday/View Model/.../BIP21ViewModel.swift New BIP21ViewModel class for managing BIP21 payment requests.

Poem

🐇 In fields of code where rabbits play,
New features bloom, bright as the day.
BIP21 hops in, with joy and cheer,
Payment paths paved, no need to fear.
With each new line, our hopes take flight,
In the world of Swift, everything feels right! 🌼✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@reez reez mentioned this pull request Jul 19, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (1)
LDKNodeMonday.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (1)

3-3: Removal of ldk-node dependency.

The ldk-node dependency has been removed, but it is still actively imported and used in multiple files. Ensure that all functionality relying on this dependency is updated or replaced accordingly before removing it.

  • LDKNodeMonday/View Model/Profile/Peer/PeersListViewModel.swift
  • LDKNodeMonday/View Model/Profile/Peer/DisconnectViewModel.swift
  • LDKNodeMonday/View Model/Home/StartViewModel.swift
  • LDKNodeMonday/View Model/Home/OnboardingViewModel.swift
  • LDKNodeMonday/View Model/Home/BitcoinViewModel.swift
  • LDKNodeMonday/View Model/Home/AmountViewModel.swift
  • LDKNodeMonday/View Model/Home/Payments/PaymentsViewModel.swift
  • LDKNodeMonday/View Model/Profile/NodeIDViewModel.swift
  • LDKNodeMonday/View Model/Profile/Peer/PeerViewModel.swift
  • LDKNodeMonday/View Model/Profile/Danger/SeedViewModel.swift
  • LDKNodeMonday/View Model/Profile/Channel/ChannelsListViewModel.swift
  • LDKNodeMonday/View/Profile/Channel/ChannelDetailView.swift
  • LDKNodeMonday/View Model/Profile/Channel/ChannelDetailViewModel.swift
  • LDKNodeMonday/View Model/Profile/Channel/ChannelAddViewModel.swift
  • LDKNodeMonday/Service/EventService/EventService.swift
  • LDKNodeMonday/Service/Lightning Service/LightningServiceError.swift
  • LDKNodeMonday/Service/KeyService/KeyService.swift
  • LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift
  • LDKNodeMonday/Extensions/PaymentKind+Extensions.swift
  • LDKNodeMonday/View/Profile/Danger/SeedView.swift
  • LDKNodeMonday/View Model/Home/Receive/ZeroAmountViewModel.swift
  • LDKNodeMonday/View Model/Home/Receive/JITInvoiceViewModel.swift
  • LDKNodeMonday/View Model/Home/Receive/Bolt12ZeroInvoiceViewModel.swift
  • LDKNodeMonday/View Model/Home/Receive/Bolt12InvoiceViewModel.swift
  • LDKNodeMonday/View Model/Home/Receive/AmountInvoiceViewModel.swift
  • LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift
  • LDKNodeMonday/Extensions/Event+Extensions.swift
  • LDKNodeMonday/View Model/Home/Receive/BIP21ViewModel.swift
  • LDKNodeMonday/Extensions/Network+Extensions.swift
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift
  • LDKNodeMonday/View/Home/Receive/ZeroInvoiceView.swift
  • LDKNodeMonday/View/Home/Receive/JITInvoiceView.swift
  • LDKNodeMonday/View/Home/Receive/Bolt12ZeroInvoiceView.swift
  • LDKNodeMonday/View/Home/Payments/PaymentsListView.swift
  • LDKNodeMonday/View/Home/Receive/Bolt12InvoiceView.swift
  • LDKNodeMonday/View/Home/Receive/AmountInvoiceView.swift
  • LDKNodeMonday/View/Home/OnboardingView.swift
  • LDKNodeMonday/Extensions/ChannelDetails+Extensions.swift
  • LDKNodeMonday/Model/LightningPaymentStatus.swift
  • LDKNodeMonday/View/Home/StartView.swift
Analysis chain

Removal of ldk-node dependency.

The ldk-node dependency has been removed. Ensure that all functionality relying on this dependency has been updated or replaced accordingly.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the removal of `ldk-node` dependency.

# Test: Search for the usage of `ldk-node` in the codebase. Expect: No remaining usages.
rg --type swift 'import LDKNode'

Length of output: 2941


Script:

#!/bin/bash
# Description: Verify the actual usage of `LDKNode` in the identified files.

# List of files where `LDKNode` is imported
files=(
  "LDKNodeMonday/View Model/Profile/Peer/PeersListViewModel.swift"
  "LDKNodeMonday/View Model/Profile/Peer/DisconnectViewModel.swift"
  "LDKNodeMonday/View Model/Home/StartViewModel.swift"
  "LDKNodeMonday/View Model/Home/OnboardingViewModel.swift"
  "LDKNodeMonday/View Model/Home/BitcoinViewModel.swift"
  "LDKNodeMonday/View Model/Home/AmountViewModel.swift"
  "LDKNodeMonday/View Model/Home/Payments/PaymentsViewModel.swift"
  "LDKNodeMonday/View Model/Profile/NodeIDViewModel.swift"
  "LDKNodeMonday/View Model/Profile/Peer/PeerViewModel.swift"
  "LDKNodeMonday/View Model/Profile/Danger/SeedViewModel.swift"
  "LDKNodeMonday/View Model/Profile/Channel/ChannelsListViewModel.swift"
  "LDKNodeMonday/View/Profile/Channel/ChannelDetailView.swift"
  "LDKNodeMonday/View Model/Profile/Channel/ChannelDetailViewModel.swift"
  "LDKNodeMonday/View Model/Profile/Channel/ChannelAddViewModel.swift"
  "LDKNodeMonday/Service/EventService/EventService.swift"
  "LDKNodeMonday/Service/Lightning Service/LightningServiceError.swift"
  "LDKNodeMonday/Service/KeyService/KeyService.swift"
  "LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift"
  "LDKNodeMonday/Extensions/PaymentKind+Extensions.swift"
  "LDKNodeMonday/View/Profile/Danger/SeedView.swift"
  "LDKNodeMonday/View Model/Home/Receive/ZeroAmountViewModel.swift"
  "LDKNodeMonday/View Model/Home/Receive/JITInvoiceViewModel.swift"
  "LDKNodeMonday/View Model/Home/Receive/Bolt12ZeroInvoiceViewModel.swift"
  "LDKNodeMonday/View Model/Home/Receive/Bolt12InvoiceViewModel.swift"
  "LDKNodeMonday/View Model/Home/Receive/AmountInvoiceViewModel.swift"
  "LDKNodeMonday/View Model/Home/Receive/AddressViewModel.swift"
  "LDKNodeMonday/Extensions/Event+Extensions.swift"
  "LDKNodeMonday/View Model/Home/Receive/BIP21ViewModel.swift"
  "LDKNodeMonday/Extensions/Network+Extensions.swift"
  "LDKNodeMonday/View/Home/Receive/BIP21View.swift"
  "LDKNodeMonday/View/Home/Receive/ZeroInvoiceView.swift"
  "LDKNodeMonday/View/Home/Receive/JITInvoiceView.swift"
  "LDKNodeMonday/View/Home/Receive/Bolt12ZeroInvoiceView.swift"
  "LDKNodeMonday/View/Home/Payments/PaymentsListView.swift"
  "LDKNodeMonday/View/Home/Receive/Bolt12InvoiceView.swift"
  "LDKNodeMonday/View/Home/Receive/AmountInvoiceView.swift"
  "LDKNodeMonday/View/Home/OnboardingView.swift"
  "LDKNodeMonday/Extensions/ChannelDetails+Extensions.swift"
  "LDKNodeMonday/Model/LightningPaymentStatus.swift"
  "LDKNodeMonday/View/Home/StartView.swift"
)

# Search for usage of LDKNode in the identified files
for file in "${files[@]}"; do
  echo "Checking usage in $file"
  rg 'LDKNode' "$file"
done

Length of output: 14210

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 74dceb8 and 037359e.

Files selected for processing (8)
  • LDKNodeMonday.xcodeproj/project.pbxproj (15 hunks)
  • LDKNodeMonday.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (2 hunks)
  • LDKNodeMonday/Model/ReceiveOption.swift (1 hunks)
  • LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift (2 hunks)
  • LDKNodeMonday/Service/Lightning Service/LightningServiceError.swift (1 hunks)
  • LDKNodeMonday/View Model/Home/Receive/BIP21ViewModel.swift (1 hunks)
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift (1 hunks)
  • LDKNodeMonday/View/Home/Receive/ReceiveView.swift (1 hunks)
Additional comments not posted (20)
LDKNodeMonday/Model/ReceiveOption.swift (1)

17-17: Addition of new case bip21 to ReceiveOption enum.

The new case bip21 is consistent with the existing cases and correctly expands the enum to support BIP21.

LDKNodeMonday.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (1)

2-2: Update of originHash value.

The originHash value has been updated, reflecting a new state of the package dependencies.

LDKNodeMonday/View Model/Home/Receive/BIP21ViewModel.swift (4)

13-15: Good use of @Published properties in BIP21ViewModel.

The use of @Published properties ensures that the UI will be updated when these properties change.


19-42: Proper error handling in receivePayment method.

The receivePayment method correctly handles errors and updates the UI accordingly. Ensure that LightningNodeService.shared.receive handles all necessary cases.


44-46: Clear invoice functionality.

The clearInvoice method correctly resets the unified property.


48-53: Efficient use of DispatchQueue.main.async in getColor method.

The getColor method efficiently updates the networkColor property on the main thread.

LDKNodeMonday/View/Home/Receive/ReceiveView.swift (1)

34-35: LGTM! The new case for handling bip21 is well integrated.

The addition of the bip21 case enhances the functionality of the ReceiveView by supporting BIP21 invoices.

LDKNodeMonday/Service/Lightning Service/LightningServiceError.swift (1)

158-163: LGTM! The new error cases are well handled.

The addition of UriParameterParsingFailed and InvalidUri cases enhances the robustness of the error handling in the handleNodeError function.

LDKNodeMonday/View/Home/Receive/BIP21View.swift (3)

12-17: LGTM! The state variables are well-defined.

The state variables isCopied, showCheckmark, showingReceiveViewErrorAlert, and isKeyboardVisible are appropriately defined for managing the view's state.


19-167: LGTM! The body property is well-structured.

The body property of the BIP21View struct is well-structured and follows SwiftUI best practices. The view correctly handles different states and user interactions.


173-175: LGTM! The preview provider is correctly defined.

The preview provider for the BIP21View struct is correctly defined, allowing for easy previewing of the view in Xcode.

LDKNodeMonday.xcodeproj/project.pbxproj (9)

6-6: Verify compatibility with Xcode version.

The objectVersion has been updated from 56 to 60. Ensure that this change is compatible with the current Xcode version used in the project.


72-72: Verify integration and inclusion of BIP21View.swift.

Ensure that the new file BIP21View.swift is correctly integrated into the project and included in the build process.


73-73: Verify integration and inclusion of BIP21ViewModel.swift.

Ensure that the new file BIP21ViewModel.swift is correctly integrated into the project and included in the build process.


74-74: Verify integration and replacement of LDKNode reference.

Ensure that the new reference for LDKNode is correctly integrated into the project and that it replaces the old reference.


599-599: Verify integration and replacement of ldk-node package reference.

Ensure that the new local package reference for ldk-node is correctly integrated into the project and that it replaces the old remote package reference.


983-983: Verify integration and replacement of LDKNode reference.

Ensure that the new reference for LDKNode is correctly integrated into the project and that it replaces the old reference.


635-635: Verify integration and inclusion of BIP21View.swift.

Ensure that the new file BIP21View.swift is correctly integrated into the project and included in the build process.


695-695: Verify integration and inclusion of BIP21ViewModel.swift.

Ensure that the new file BIP21ViewModel.swift is correctly integrated into the project and included in the build process.


918-921: Verify integration and replacement of ldk-node package reference.

Ensure that the new local package reference for ldk-node is correctly integrated into the project and that it replaces the old remote package reference.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 6

Outside diff range, codebase verification and nitpick comments (1)
LDKNodeMonday/View/Home/Receive/BIP21View.swift (1)

78-78: Add a TODO comment or remove commented-out code.

The commented-out QRCodeView should be either removed or annotated with a TODO comment explaining why it is commented out.

// TODO: Re-enable QRCodeView once BitcoinUI is updated to support BIP21
// QRCodeView(qrCodeType: .lightning(viewModel.invoice))
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 037359e and 375a7a8.

Files selected for processing (1)
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift (1 hunks)
Additional comments not posted (6)
LDKNodeMonday/View/Home/Receive/BIP21View.swift (6)

1-11: LGTM!

The header comments and import statements are appropriate and necessary for the file.


226-232: LGTM!

The clear invoice button implementation is well-structured and follows SwiftUI conventions.


239-261: LGTM!

The onAppear and onReceive modifiers are well-implemented and follow SwiftUI conventions.


262-270: LGTM!

The alert presentation is well-implemented and follows SwiftUI conventions.


276-280: LGTM!

The UnifiedQRComponents struct is well-implemented and follows Swift conventions.


316-318: LGTM!

The SwiftUI preview is well-implemented and follows SwiftUI conventions.

LDKNodeMonday/View/Home/Receive/BIP21View.swift Outdated Show resolved Hide resolved
Comment on lines 82 to 125
HStack(alignment: .center) {

VStack(alignment: .leading, spacing: 5.0) {
Text("On Chain")
.font(.caption)
.bold()
if let components = parseUnifiedQR(viewModel.unified) {
Text(components.onchain)
.font(.caption)
.truncationMode(.middle)
.lineLimit(1)
.foregroundColor(.secondary)
.redacted(
reason: viewModel.unified.isEmpty ? .placeholder : []
)
}
}

Spacer()

if let components = parseUnifiedQR(viewModel.unified) {
Button {
UIPasteboard.general.string = components.onchain
onchainIsCopied = true
onchainShowCheckmark = true
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
onchainIsCopied = false
onchainShowCheckmark = false
}
} label: {
HStack {
withAnimation {
Image(
systemName: onchainShowCheckmark
? "checkmark" : "doc.on.doc"
)
.font(.title2)
.minimumScaleFactor(0.5)
}
}
.bold()
.foregroundColor(viewModel.networkColor)
}
}
Copy link

Choose a reason for hiding this comment

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

Consider extracting on-chain address view into a separate function.

Extracting the on-chain address view into a separate function can improve readability and maintainability.

@ViewBuilder
private func onchainAddressView(components: UnifiedQRComponents) -> some View {
    HStack(alignment: .center) {
        VStack(alignment: .leading, spacing: 5.0) {
            Text("On Chain")
                .font(.caption)
                .bold()
            Text(components.onchain)
                .font(.caption)
                .truncationMode(.middle)
                .lineLimit(1)
                .foregroundColor(.secondary)
                .redacted(
                    reason: viewModel.unified.isEmpty ? .placeholder : []
                )
        }

        Spacer()

        Button {
            UIPasteboard.general.string = components.onchain
            onchainCopyState.isCopied = true
            onchainCopyState.showCheckmark = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                onchainCopyState.isCopied = false
                onchainCopyState.showCheckmark = false
            }
        } label: {
            HStack {
                withAnimation {
                    Image(
                        systemName: onchainCopyState.showCheckmark
                            ? "checkmark" : "doc.on.doc"
                    )
                    .font(.title2)
                    .minimumScaleFactor(0.5)
                }
            }
            .bold()
            .foregroundColor(viewModel.networkColor)
        }
    }
    .padding()
}

var body: some View {
    // Existing code
    if let components = parseUnifiedQR(viewModel.unified) {
        onchainAddressView(components: components)
    }
    // Existing code
}

LDKNodeMonday/View/Home/Receive/BIP21View.swift Outdated Show resolved Hide resolved
LDKNodeMonday/View/Home/Receive/BIP21View.swift Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
LDKNodeMonday/View/Home/Receive/ReceiveView.swift (1)

22-35: Verify the impact of commenting out cases in the switch statement.

Several cases in the switch statement have been commented out. The commented-out cases for .bolt12 and .bitcoin are referenced in other parts of the codebase, which might lead to broken functionality. Please ensure that these cases are handled properly to avoid any issues.

  • .bolt12 is referenced in LDKNodeMonday/Extensions/PaymentKind+Extensions.swift.
  • .bitcoin is referenced in multiple files including:
    • LDKNodeMonday/Utilities/Constants.swift
    • LDKNodeMonday/Service/Lightning Service/LightningNodeService.swift
    • LDKNodeMonday/View Model/Home/OnboardingViewModel.swift
    • LDKNodeMonday/Extensions/Network+Extensions.swift
Analysis chain

Verify the impact of commenting out cases in the switch statement.

Several cases in the switch statement have been commented out. Ensure that these changes do not break any functionality in the UI.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of commenting out cases in the switch statement.

# Test: Search for the usage of commented-out cases in the switch statement. Expect: No broken references.
rg --type swift -A 5 $'case .bolt11Zero'
rg --type swift -A 5 $'case .bolt11'
rg --type swift -A 5 $'case .bolt12'
rg --type swift -A 5 $'case .bitcoin'

Length of output: 8023

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 375a7a8 and 4356edf.

Files selected for processing (2)
  • LDKNodeMonday/Model/ReceiveOption.swift (1 hunks)
  • LDKNodeMonday/View/Home/Receive/ReceiveView.swift (4 hunks)
Additional context used
SwiftLint
LDKNodeMonday/View/Home/Receive/ReceiveView.swift

[Warning] 57-57: Prefer at least one space after slashes for comments

(comment_spacing)


[Warning] 59-59: Prefer at least one space after slashes for comments

(comment_spacing)

Additional comments not posted (5)
LDKNodeMonday/Model/ReceiveOption.swift (2)

25-28: LGTM!

The changes in the systemImageName property align with the commented-out enum cases.


11-17: Verify the impact of commenting out enum cases.

Several cases in the ReceiveOption enum have been commented out. Ensure that these changes do not break any functionality elsewhere in the codebase.

Verification successful

No impact found from commenting out enum cases.

The commented-out enum cases in ReceiveOption do not appear to be referenced elsewhere in the codebase, indicating that these changes should not break any functionality.

  • ReceiveOption.bolt11Zero
  • ReceiveOption.bolt11
  • ReceiveOption.bolt12
  • ReceiveOption.bitcoin
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of commenting out enum cases in `ReceiveOption`.

# Test: Search for the usage of commented-out enum cases. Expect: No broken references.
rg --type swift -A 5 $'ReceiveOption.bolt11Zero'
rg --type swift -A 5 $'ReceiveOption.bolt11'
rg --type swift -A 5 $'ReceiveOption.bolt12'
rg --type swift -A 5 $'ReceiveOption.bitcoin'

Length of output: 180


Script:

#!/bin/bash
# Description: Verify the impact of commenting out enum cases in `ReceiveOption`.

# Test: Search for the usage of commented-out enum cases across all file types with more context lines.
rg 'ReceiveOption.bolt11Zero' -A 10
rg 'ReceiveOption.bolt11' -A 10
rg 'ReceiveOption.bolt12' -A 10
rg 'ReceiveOption.bitcoin' -A 10

Length of output: 132

LDKNodeMonday/View/Home/Receive/ReceiveView.swift (3)

79-79: LGTM!

The changes in the #Preview section align with the shift towards prioritizing BIP21.


11-11: Verify the impact of changing the default value of selectedOption.

The default value of selectedOption has been changed from .bolt11Zero to .bip21. Ensure that this change does not break any functionality elsewhere in the codebase.


57-59: Verify the impact of commenting out font size settings.

The font size settings for images and text have been commented out. Ensure that these changes do not affect the UI appearance negatively.

Tools
SwiftLint

[Warning] 57-57: Prefer at least one space after slashes for comments

(comment_spacing)


[Warning] 59-59: Prefer at least one space after slashes for comments

(comment_spacing)

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4356edf and 46fcf58.

Files selected for processing (3)
  • LDKNodeMonday/Extensions/String+Extensions.swift (3 hunks)
  • LDKNodeMonday/Model/ReceiveOption.swift (1 hunks)
  • LDKNodeMonday/View/Home/Receive/ReceiveView.swift (4 hunks)
Additional comments not posted (6)
LDKNodeMonday/Model/ReceiveOption.swift (2)

11-17: Verify the rationale for commenting out enum cases.

Several cases in the ReceiveOption enum are commented out. Ensure this aligns with the intended functionality and consider documenting the reason for future reference.


25-28: Verify the impact of default case change in systemImageName.

The default case now returns "qrcode" for all unmatched cases. Ensure this change aligns with the intended visual representation of options in the UI.

LDKNodeMonday/View/Home/Receive/ReceiveView.swift (2)

11-11: Verify the impact of changing the default selectedOption.

The default state for selectedOption is now .bip21. Ensure this change does not negatively impact other parts of the application that rely on the previous default.


79-79: Verify the accuracy of CustomSegmentedPicker preview.

The preview now uses selectedOption: .constant(.bip21). Ensure this accurately reflects the intended functionality and appearance.

LDKNodeMonday/Extensions/String+Extensions.swift (2)

178-182: Verify the correctness of BIP21 amount validation.

The processBitcoinAddress function now validates the amount against the spendable balance. Ensure this logic is correct and robust to prevent incorrect transaction processing.


203-207: Verify the correctness of BIP21 URI handling.

The extractBitcoinAddress function now handles query parameters in BIP21 URIs. Ensure this logic correctly handles all possible BIP21 URI formats and edge cases.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 46fcf58 and c3dedd8.

Files selected for processing (3)
  • LDKNodeMonday.xcodeproj/project.pbxproj (15 hunks)
  • LDKNodeMonday.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (2 hunks)
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift (1 hunks)
Additional comments not posted (17)
LDKNodeMonday.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved (2)

2-2: Verify the impact of the updated originHash.

The originHash has been updated, which may affect the state of the package dependencies. Ensure that this change aligns with the intended updates and does not introduce any inconsistencies.


9-10: Ensure compatibility with the updated bitcoinui branch and revision.

The bitcoinui dependency has been updated to track the main branch with a new revision. Verify that this change is compatible with the rest of the project and does not introduce breaking changes.

LDKNodeMonday/View/Home/Receive/BIP21View.swift (7)

8-13: Imports and struct declaration look good.

The necessary modules are imported, and the BIP21View struct is properly declared.


14-23: Consider consolidating state variables.

The state variables for copying and showing checkmarks can be consolidated into a single struct to improve readability and maintainability.

struct CopyState {
    var isCopied = false
    var showCheckmark = false
}

@State private var onchainCopyState = CopyState()
@State private var bolt11CopyState = CopyState()
@State private var bolt12CopyState = CopyState()

24-72: Refactor nested conditionals and repetitive code.

The nested conditionals and repetitive code for handling text fields and buttons can be refactored into separate functions or views to improve readability.

@ViewBuilder
private func amountInputView() -> some View {
    VStack(alignment: .leading) {
        Text("Sats")
            .bold()
            .padding(.horizontal)

        ZStack {
            TextField(
                "0",
                text: $viewModel.amountSat
            )
            .keyboardType(.numberPad)
            .submitLabel(.done)
            .padding(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 32))

            if !viewModel.amountSat.isEmpty {
                HStack {
                    Spacer()
                    Button {
                        self.viewModel.amountSat = ""
                    } label: {
                        Image(systemName: "xmark.circle.fill")
                            .foregroundColor(.secondary)
                    }
                    .padding(.trailing, 8)
                }
            }
        }
        .padding(.horizontal)
    }
    .padding()
}

var body: some View {
    VStack {
        if viewModel.unified == "" {
            amountInputView()

            Button {
                Task {
                    let amountSat = (UInt64(viewModel.amountSat) ?? 0)
                    await viewModel.receivePayment(
                        amountSat: amountSat,
                        message: "Monday Wallet",
                        expirySecs: UInt32(3600)
                    )
                }
            } label: {
                Text("Create Amount Invoice")
            }
        } else {
            // Existing code for handling non-empty viewModel.unified
        }
    }
}

82-125: Consider extracting on-chain address view into a separate function.

Extracting the on-chain address view into a separate function can improve readability and maintainability.

@ViewBuilder
private func onchainAddressView(components: UnifiedQRComponents) -> some View {
    HStack(alignment: .center) {
        VStack(alignment: .leading, spacing: 5.0) {
            Text("On Chain")
                .font(.caption)
                .bold()
            Text(components.onchain)
                .font(.caption)
                .truncationMode(.middle)
                .lineLimit(1)
                .foregroundColor(.secondary)
                .redacted(
                    reason: viewModel.unified.isEmpty ? .placeholder : []
                )
        }

        Spacer()

        Button {
            UIPasteboard.general.string = components.onchain
            onchainCopyState.isCopied = true
            onchainCopyState.showCheckmark = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                onchainCopyState.isCopied = false
                onchainCopyState.showCheckmark = false
            }
        } label: {
            HStack {
                withAnimation {
                    Image(
                        systemName: onchainCopyState.showCheckmark
                            ? "checkmark" : "doc.on.doc"
                    )
                    .font(.title2)
                    .minimumScaleFactor(0.5)
                }
            }
            .bold()
            .foregroundColor(viewModel.networkColor)
        }
    }
    .padding()
}

var body: some View {
    // Existing code
    if let components = parseUnifiedQR(viewModel.unified) {
        onchainAddressView(components: components)
    }
    // Existing code
}

130-173: Consider extracting Bolt11 address view into a separate function.

Extracting the Bolt11 address view into a separate function can improve readability and maintainability.

@ViewBuilder
private func bolt11AddressView(components: UnifiedQRComponents) -> some View {
    HStack(alignment: .center) {
        VStack(alignment: .leading, spacing: 5.0) {
            Text("Bolt 11")
                .font(.caption)
                .bold()
            Text(components.bolt11)
                .font(.caption)
                .truncationMode(.middle)
                .lineLimit(1)
                .foregroundColor(.secondary)
                .redacted(
                    reason: viewModel.unified.isEmpty ? .placeholder : []
                )
        }

        Spacer()

        Button {
            UIPasteboard.general.string = components.bolt11
            bolt11CopyState.isCopied = true
            bolt11CopyState.showCheckmark = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                bolt11CopyState.isCopied = false
                bolt11CopyState.showCheckmark = false
            }
        } label: {
            HStack {
                withAnimation {
                    Image(
                        systemName: bolt11CopyState.showCheckmark
                            ? "checkmark" : "doc.on.doc"
                    )
                    .font(.title2)
                    .minimumScaleFactor(0.5)
                }
            }
            .bold()
            .foregroundColor(viewModel.networkColor)
        }
    }
    .padding()
}

var body: some View {
    // Existing code
    if let components = parseUnifiedQR(viewModel.unified) {
        bolt11AddressView(components: components)
    }
    // Existing code
}

178-221: Consider extracting Bolt12 address view into a separate function.

Extracting the Bolt12 address view into a separate function can improve readability and maintainability.

@ViewBuilder
private func bolt12AddressView(components: UnifiedQRComponents) -> some View {
    HStack(alignment: .center) {
        VStack(alignment: .leading, spacing: 5.0) {
            Text("Bolt 12")
                .font(.caption)
                .bold()
            Text(components.bolt12)
                .font(.caption)
                .truncationMode(.middle)
                .lineLimit(1)
                .foregroundColor(.secondary)
                .redacted(
                    reason: viewModel.unified.isEmpty ? .placeholder : []
                )
        }

        Spacer()

        Button {
            UIPasteboard.general.string = components.bolt12
            bolt12CopyState.isCopied = true
            bolt12CopyState.showCheckmark = true
            DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
                bolt12CopyState.isCopied = false
                bolt12CopyState.showCheckmark = false
            }
        } label: {
            HStack {
                withAnimation {
                    Image(
                        systemName: bolt12CopyState.showCheckmark
                            ? "checkmark" : "doc.on.doc"
                    )
                    .font(.title2)
                    .minimumScaleFactor(0.5)
                }
            }
            .bold()
            .foregroundColor(viewModel.networkColor)
        }
    }
    .padding()
}

var body: some View {
    // Existing code
    if let components = parseUnifiedQR(viewModel.unified) {
        bolt12AddressView(components: components)
    }
    // Existing code
}

282-314: Improve readability and error handling in parseUnifiedQR function.

The parseUnifiedQR function can be refactored for better readability and error handling.

func parseUnifiedQR(_ unifiedQR: String) -> UnifiedQRComponents? {
    // Split the string by '?'
    let components = unifiedQR.components(separatedBy: "?")

    guard components.count > 1 else { return nil }

    // Extract onchain (everything before the first '?') and remove the "BITCOIN:" prefix
    var onchain = components[0]
    if onchain.lowercased().hasPrefix("bitcoin:") {
        onchain = String(onchain.dropFirst(8))  // Remove "BITCOIN:"
    }

    // Join the rest of the components back together
    let remainingString = components.dropFirst().joined(separator: "?")

    // Split the remaining string by '&'
    let params = remainingString.components(separatedBy: "&")

    var bolt11: String?
    var bolt12: String?

    for param in params {
        if param.starts(with: "lightning=") {
            bolt11 = String(param.dropFirst("lightning=".count))
        } else if param.starts(with: "lno=") {
            bolt12 = String(param.dropFirst("lno=".count))
        }
    }

    guard let bolt11 = bolt11, let bolt12 = bolt12 else { return nil }

    return UnifiedQRComponents(onchain: onchain, bolt11: bolt11, bolt12: bolt12)
}
LDKNodeMonday.xcodeproj/project.pbxproj (8)

6-6: Verify compatibility with Xcode version.

The objectVersion has been updated from 56 to 60. Ensure this change is compatible with the Xcode version used for this project.


72-73: Addition of BIP21 files is aligned with PR objectives.

The new file references for BIP21View.swift and BIP21ViewModel.swift are correctly added to the project. Ensure these files are implemented and tested.

Also applies to: 159-160, 290-290, 386-386, 635-635, 695-695


74-74: Ensure correct integration of LDKNode.

The reference for LDKNode has been updated. Verify that the integration is correct and aligns with the project's requirements.

Also applies to: 196-196, 564-564, 983-985


917-921: Verify local package path for ldk-node/bindings/swift.

The project now uses a local package reference for ldk-node/bindings/swift. Ensure the path is correct and accessible during the build process.


599-599: Ensure no dependencies on removed remote package reference.

The remote package reference for ldk-node has been removed. Verify that all dependencies are correctly managed with the new local reference.


937-937: Verify stability of BitcoinUI main branch.

The branch for BitcoinUI is specified as main. Ensure this branch is stable and intended for use in the project.


983-985: Ensure consistency with local package reference for LDKNode.

The XCSwiftPackageProductDependency for LDKNode has been updated. Ensure consistency with the local package reference.


Line range hint 6-986: Overall project structure changes approved.

The project structure has been updated with new files and dependencies. Ensure thorough testing of the build process to verify that no issues have been introduced.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
LDKNodeMonday/View Model/Home/AmountViewModel.swift (1)

107-107: Ensure consistent error handling across methods.

While logging unexpected errors is good, consider standardizing error messages or handling mechanisms across different payment methods for consistency.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c3dedd8 and 6be02aa.

Files selected for processing (3)
  • LDKNodeMonday/Extensions/String+Extensions.swift (5 hunks)
  • LDKNodeMonday/View Model/Home/AmountViewModel.swift (3 hunks)
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift
Additional comments not posted (6)
LDKNodeMonday/View Model/Home/AmountViewModel.swift (3)

93-94: Logging of successful payment ID is a good practice.

Logging the payment ID upon successful transaction enhances traceability and debugging capabilities.


96-96: Improved error visibility with specific logging.

Logging the localized description of NodeError directly helps in identifying node-related issues more quickly.


124-124: Case-insensitive check enhances flexibility.

Modifying the condition to be case-insensitive by using lowercased() allows for more flexible input handling which is beneficial in environments with variable input formats.

LDKNodeMonday/Extensions/String+Extensions.swift (3)

13-74: Enhanced regex handling and detailed logging in bolt11amount.

The updated regex pattern allows for more flexibility in parsing Bolt11 amounts, and the detailed logging at each step aids in debugging. Ensure that the regex is tested thoroughly to handle all expected formats.

Tools
SwiftLint

[Error] 16-16: Force tries should be avoided

(force_try)


286-288: Proper handling of query parameters in Bitcoin addresses.

The update to handle query parameters when extracting Bitcoin addresses from BIP21 URIs is a necessary improvement for accurate address processing.


183-225: Comprehensive handling of BIP21 URIs in processBIP21.

The function systematically processes BIP21 URIs, extracting relevant payment information. It prioritizes different payment types and handles query parameters effectively.

However, ensure that all edge cases and potential error scenarios are covered by unit tests, especially for malformed URIs and unexpected query parameters.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6be02aa and 25d3b0f.

Files selected for processing (5)
  • LDKNodeMonday/Extensions/String+Extensions.swift (4 hunks)
  • LDKNodeMonday/Model/ReceiveOption.swift (1 hunks)
  • LDKNodeMonday/View Model/Home/AmountViewModel.swift (2 hunks)
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift (1 hunks)
  • LDKNodeMonday/View/Home/Receive/ReceiveView.swift (4 hunks)
Files skipped from review as they are similar to previous changes (4)
  • LDKNodeMonday/Model/ReceiveOption.swift
  • LDKNodeMonday/View Model/Home/AmountViewModel.swift
  • LDKNodeMonday/View/Home/Receive/BIP21View.swift
  • LDKNodeMonday/View/Home/Receive/ReceiveView.swift
Additional comments not posted (3)
LDKNodeMonday/Extensions/String+Extensions.swift (3)

37-53: Logic for amount conversion approved.

The logic to convert the amount based on the multiplier is correctly implemented and aligns with Bitcoin denomination standards.


164-198: Logic for processing BIP21 URIs approved.

The function correctly handles different query parameters and prioritizes Bolt 12 offers over Bolt 11 invoices. The use of String(format:) for formatting the Bitcoin amount is appropriate and consistent with the overall handling of Bitcoin denominations.


245-247: Logic for extracting Bitcoin addresses approved.

The function correctly handles the extraction of the Bitcoin address from a BIP21 URI, ensuring that only the address portion is returned. The use of uppercased() to normalize the address is appropriate and aligns with common practices for address handling.

@reez reez merged commit 041a10a into main Aug 25, 2024
1 check passed
@reez reez deleted the bip-21 branch August 25, 2024 01:12
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.

1 participant