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

fix(@cockpit/dashboard): "Deployed Contracts" should auto-update after deployment #2020

Merged
merged 1 commit into from
Nov 5, 2019

Conversation

michaelsbradleyjr
Copy link
Contributor

No description provided.

@michaelsbradleyjr michaelsbradleyjr requested a review from a team November 4, 2019 04:50
@ghost
Copy link

ghost commented Nov 4, 2019

DeepCode Report (#634c13)

DeepCode analyzed this pull request.
There are no new issues. 1 warning was fixed.

Copy link
Contributor

@0x-r4bbit 0x-r4bbit left a comment

Choose a reason for hiding this comment

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

Minor comment inlined

return '';
.map((contract, key) => {
if (!contract) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm sure there exists a good reason for this, but I find it unexpected that contract can be null here. contracts should IMO only hold valid objects so that the view doesn't have to worry about this kind of logic and simply render data.

Do you think we can maybe put a filter(contract => !!contract) on contracts inside the component before we iterate over it here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that it's weird that a contract in the array would be falsey, but in the end doing the check here is not the end of the world, because using filter would be an additional loop that is not 100% needed

Copy link
Contributor Author

@michaelsbradleyjr michaelsbradleyjr Nov 4, 2019

Choose a reason for hiding this comment

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

Prior to the changes in this PR, the null check took place after the call to formatContractForDisplay. However, that function always returns an object, so the null check didn't make sense; also formatContractForDisplay isn't written to handle possibly falsy values. To be on the safe side, I simply moved the check up a bit, but I wasn't and am not sure if it's really possible that the contracts array might contain falsy values. It's definitely something we can investigate/refactor further, and I agree that contracts should hold only valid objects, but perhaps that's better left for future refactor PR/s.

return '';
.map((contract, key) => {
if (!contract) {
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree that it's weird that a contract in the array would be falsey, but in the end doing the check here is not the end of the world, because using filter would be an additional loop that is not 100% needed

@@ -2,7 +2,8 @@ import isToday from 'date-fns/isToday';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';

export function formatContractForDisplay(contract) {
let address = (contract.deployedAddress || contract.deployedAddress);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wow, this condition was very useful.
I'm guessing the wanted line was (contract.deployedAddress || contract.address);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what it used to be, according to git blame; it was changed in a big refactor PR, but based on the other changes in that PR it looked to me like it's okay to just check contract.deployedAddress rather than reintroduce || contract.address.

@iurimatias iurimatias merged commit 1a43dca into master Nov 5, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix/cockpit-dashboard-autoupdate branch November 5, 2019 17:08
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