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

[trello.com/c/qDelB45V] Add the height and the version to IPFS #657

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

VeretennikovSV
Copy link
Collaborator

@VeretennikovSV VeretennikovSV commented Jan 20, 2025

Added mapping of timestamp to a height and version of IPFS

let timestamp = try container.decode(UInt64.self, forKey: .timestamp)
let timeStampInSeconds = String(timestamp / 1000)
let subString = timeStampInSeconds[
timeStampInSeconds.index(timeStampInSeconds.startIndex, offsetBy: 2)..<timeStampInSeconds.endIndex
Copy link
Collaborator

@ChrisBenua ChrisBenua Jan 20, 2025

Choose a reason for hiding this comment

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

You can easily have crash here if startIndex + 2 >= endIndex. Please add guard check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Not easily, closer to never, but yeah, just for safety it should be added

@ChrisBenua
Copy link
Collaborator

Please add PR description

@VeretennikovSV
Copy link
Collaborator Author

Please add PR description

Is there any reasons to duplicate a descriptions if we pin task to a PR

Copy link
Collaborator

@ChrisBenua ChrisBenua left a comment

Choose a reason for hiding this comment

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

lgtm

height = Int(string) ?? .zero
} else {
height = .zero
}
Copy link
Member

Choose a reason for hiding this comment

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

Don't use custom decoding. Use DTOs (even though custom decoding is used in legacy)

  • DTO (Date Transfer Object) — the representation of the JSON without any app-related logics.
  • Model — the model that is generated out of the DTO.

Check out NodesKeychainDTO

Copy link
Member

Choose a reason for hiding this comment

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

In this simple case you don't even need a model, you can use DTO only

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think there is no need to use DTO in our case because this model are already used to create a DTO from itself in func getStatusInfo(origin: NodeOrigin) async -> ApiServiceResult<NodeStatusInfo> and maps into a NodeStatusInfo. I've made this mapping in decoding to prevent these logics in the function above to prevent extra logic in it.

Copy link
Member

@just-software-dev just-software-dev left a comment

Choose a reason for hiding this comment

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

...

)
}
}

private func getHeightFrom(timestamp: UInt64) -> Int {
let timeStampInSeconds = String(timestamp / 1000)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is not "timestamp" one word?
if one word - we need to make camel case in a right way.
If not - we need to make other properties to follow your case

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

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.

4 participants