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

chore: latest timestamp get status #105

Merged
merged 1 commit into from
Jun 22, 2024
Merged

chore: latest timestamp get status #105

merged 1 commit into from
Jun 22, 2024

Conversation

reez
Copy link
Owner

@reez reez commented Jun 22, 2024

Description

Not sure what the best way to handle this is, but when calling getStatus .onAppear the values of latest timestamps are not available yet (nil), but then after a few seconds they are not nil anymore (like when a user might pull to refresh). I'm not sure the best way to handle it, I played around with a few animations, delaying getStatus call for 5 seconds, and none felt quite right for now.

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

Copy link

coderabbitai bot commented Jun 22, 2024

Walkthrough

The BitcoinView struct in LDKNodeMonday/View/Home/BitcoinView.swift has been updated to enhance its date formatting logic. Now, it conditionally processes and displays the date only when both viewModel.status and latestOnchainWalletSyncTimestamp are available, improving its information presentation.

Changes

Files Change Summary
LDKNodeMonday/.../BitcoinView.swift Added conditional logic to handle date formatting based on viewModel.status and latestOnchainWalletSyncTimestamp.

Sequence Diagram

sequenceDiagram
    participant User
    participant BitcoinView
    participant ViewModel

    User->>BitcoinView: Access BitcoinView
    BitcoinView->>ViewModel: Fetch status and latestOnchainWalletSyncTimestamp
    alt Both data available
        ViewModel-->>BitcoinView: Provide status and timestamp
        BitcoinView->>BitcoinView: Format and display date
    else Any data missing
        ViewModel-->>BitcoinView: Provide available data
        BitcoinView->>BitcoinView: Skip date formatting
    end
Loading

Poem

Amidst the code of Bitcoin's view,
A change was made, both wise and true.
Conditional dates now shine so bright,
Only when data aligns just right.
Happy dances in the code tonight,
For logic's flow is out of sight!
🎉🐇📅


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 Configration 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.

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 e54d26c and 01bab25.

Files selected for processing (1)
  • LDKNodeMonday/View/Home/BitcoinView.swift (2 hunks)
Additional context used
SwiftLint
LDKNodeMonday/View/Home/BitcoinView.swift

[Warning] 231-231: Unused parameter in a closure should be replaced with _ (unused_closure_parameter)


[Warning] 231-231: Unused parameter in a closure should be replaced with _ (unused_closure_parameter)

Additional comments not posted (2)
LDKNodeMonday/View/Home/BitcoinView.swift (2)

62-76: Ensure Timezone Handling in Date Formatting

The new logic for date formatting correctly checks if both viewModel.status and latestOnchainWalletSyncTimestamp are available before formatting the date. However, the code does not specify a timezone for the date conversion which may lead to incorrect display times depending on the user's locale.

Consider specifying a timezone or ensuring the UI communicates the timezone used for clarity.

let date = Date(timeIntervalSince1970: TimeInterval(timestamp))
// Suggest using a specific timezone or UTC
let dateFormatter = DateFormatter()
dateFormatter.timeZone = TimeZone(abbreviation: "UTC") // or any other specific timezone
let formattedDate = dateFormatter.string(from: date)
Text(formattedDate)

104-118: Duplicate Code for Date Formatting

The conditional logic for date formatting is duplicated in the file. This occurs twice for different sections of the view. To improve maintainability, consider refactoring this logic into a separate method or view component that can be reused.

This will make the code cleaner and easier to maintain, especially if changes are needed in the future.
[REFACTOR_SUGGESTion]

// Suggested refactoring into a method
extension BitcoinView {
    func formattedDateText(timestamp: Int) -> some View {
        let date = Date(timeIntervalSince1970: TimeInterval(timestamp))
        let dateFormatter = DateFormatter()
        dateFormatter.timeZone = TimeZone(abbreviation: "UTC") // or any other specific timezone
        let formattedDate = dateFormatter.string(from: date)

        return Text(formattedDate)
            .lineLimit(1)
            .font(.caption2)
            .foregroundColor(.secondary)
            .padding(.bottom, 20.0)
            .minimumScaleFactor(0.5)
    }
}

@reez reez merged commit e776152 into main Jun 22, 2024
1 check passed
@reez reez deleted the refr branch June 22, 2024 00:35
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