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: Fix QA issues #327

Merged
merged 7 commits into from
Sep 26, 2024
Merged

fix: Fix QA issues #327

merged 7 commits into from
Sep 26, 2024

Conversation

pedroferreira1
Copy link
Member

@pedroferreira1 pedroferreira1 commented Sep 23, 2024

Context

After @tuliomir ran the QA, 3 issues were found. They are described here.

  1. The bug in the Transactions list affected all lists, and the cause was that the componentDidUpdate was not triggered when the query parameters changed. I decided to refactor the component to a functional component because this would be done in the future anyway, so I fixed the issue and did the refactor.
  2. This issue affected all Token Detail screens of NFTs. The fix was simple (@tuliomir had already done it) and was just the correct way of setting the state.
  3. This one was caused by a difference in the way we are passing the parameters data to the Network component right now. this.props had match: { peerId: undefined }, so I had to fix the destructuring, so it could correctly get the peerId information.

Note: While refactoring the Transactions component I found a bug that is affecting the mainnet-production explorer. When the user clicks the 'Previous' button in the list, the API returns the data in the reverse order, so we must reverse the data when this happens. In the middle of the refactor, I also fixed it.

Note 2: I also found a new bug in the Network screen. The 'Reload data' button was not working because it stopped binding the this after the upgrades.

Acceptance Criteria

  • Refactor Transactions component to a functional component fixing the bug when the update was not being triggered when the query params changed.
  • Fix order of data when user clicked the 'Previous' button in lists that used the Transactions component.
  • Fix Token Detail screen when the token is an NFT correctly setting the state of metadata.
  • Fix Network screen correctly getting the peerId query param.
  • Fix Network screen Reload data button.

Security Checklist

  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

Comment on lines 36 to 37
// We must use memo here because we were creating a new pagination
// object in every new render, so the useEffect was being called forever
Copy link
Member

Choose a reason for hiding this comment

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

suggestion(non-blocking): Maybe we should change how PaginationURL works.

The PaginationURL use obtainQueryParams to get the params specified in the contructor from the window.location.search, so maybe we should have a way to get ts, hash and page whenever location changes that is more in line with how function components work.

This obviously is outside the scope of this PR, so maybe we should open an issue for this discussion.

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 agree that it should be different from what it is nowadays. Maybe we could have an event thrown when parameters change. I will create an issue to discuss that, the idea of this PR is just to refactor the component to fix the bugs found.

Copy link
Member Author

Choose a reason for hiding this comment

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

function Transactions({ shouldUpdateList, updateData, title }) {
// We must use memo here because we were creating a new pagination
// object in every new render, so the useEffect was being called forever
const pagination = useMemo(
Copy link
Member

Choose a reason for hiding this comment

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

question(if-minor): why not useState?

I like the use of useMemo, but this seems like a useState without a setter, since this does not seem like a memoization and more like a singleton helper to calculate pagination params.
Something like: const [pagination, _] = useState(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

Make sense, done 05f8424

src/components/tx/Transactions.js Show resolved Hide resolved
src/components/tx/Transactions.js Show resolved Hide resolved
src/screens/TokenDetail.js Show resolved Hide resolved
Comment on lines +211 to 213
return () => {
WebSocketHandler.removeListener('network', handleWebsocket);
};

Choose a reason for hiding this comment

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

[question] Is this unmounting really working? I'm asking this because React has probably a bug when dealing with unmounting when more then 1 useEffect is declared in the component. If it is working, all good, otherwise I would solve this issue by declaring this useEffect first.

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 tested and it's working fine when the screen is unmounted. What's this bug that React has with more than one useEffect?

Choose a reason for hiding this comment

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

Maybe this is a thing of React Native. When we use two useEffect with unmounting callbacks only the the first unmounting callback from the first useEffect is called, never the second. This case is little different because the first useEffect didn't register an unmounting, maybe you can make this test latter. However, for this PR it is enough. I'm approving.

@pedroferreira1 pedroferreira1 merged commit aa3a2e9 into dev Sep 26, 2024
1 check passed
@pedroferreira1 pedroferreira1 deleted the fix/qa-issues branch September 26, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants