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

site: Check for uninitialized market in certain note handlers #2286

Merged
merged 2 commits into from
Apr 14, 2023

Conversation

ukane-philemon
Copy link
Contributor

@ukane-philemon ukane-philemon commented Apr 3, 2023

This diff uses the JS optional chaining feature to prevent errors caused by attempting to access a null field. If a user losses internet connection and regains it, some js errors will be logged when notes try to access the dex or market field on MarketPage before those fields are initialized. But the changes here are not limited to only note handlers since it is cleaner and less code to use optional chaining to prevent runtime errors.
Screenshot 2023-04-03 at 3 20 20 PM

Copy link
Member

@chappjc chappjc left a comment

Choose a reason for hiding this comment

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

Seems that falling back to return undefined instead of hitting an error is not always better. We'll create incorrect objects, make invalid requests, etc.

@ukane-philemon ukane-philemon force-pushed the fix-js-errors branch 2 times, most recently from fec775a to d0c56ae Compare April 3, 2023 17:24
@chappjc chappjc requested a review from buck54321 April 7, 2023 16:03
Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

It's not exactly clear to me under what conditions we might have no this.market, but be receiving spot and order updates. You mention connection issues. Can you explain what sequence would land us on the markets view, with spot and order updates coming in, but with no connected exchanges? Is it after a login with no available connections?
Regardless, most of these changes are unnecessary, because they require this.market to be populated in order for the requisite page elements to be shown that would lead to the error. Please audit a little deeper to see which are useful.

@@ -690,7 +691,7 @@ export default class MarketsPage extends BasePage {

if (!this.assetsAreSupported().isSupported) return // assets not supported

if (this.market.dex.tier < 1) return // acct suspended or not registered
if (!this.market?.dex || this.market.dex.tier < 1) return // acct suspended or not registered
Copy link
Member

Choose a reason for hiding this comment

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

This also seems like an impossible condition to hit based on how resolveOrderFormVisibility is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, createWallet also calls this method and it could be that there is no dex connection by the time we use resolveOrderFormVisibility.

@ukane-philemon
Copy link
Contributor Author

Please audit a little deeper to see which are useful.

Will do. I agree some use of optional chaining in some methods in this might be redundant since callers might have already checked for such cases.

@ukane-philemon
Copy link
Contributor Author

Can you explain what sequence would land us on the markets view, with spot and order updates coming in, but with no connected exchanges?

While on the markets page, no connection and the page has been refreshed. Turning the internet connection on could result in some notes being sent to the markets page before it is reloaded(i.e after connection to the server has been successful).

It occurs randomly since the markets page might be refreshed before the notes start hitting the FE. I will limit this safety check to only notes handlers.

- This fixes an issue where the `markets` page receives certain notes
  before `this.market` is initialized. These notes are sent when a user
  reconnects to the internet and the market page has not been refreshed.
Signed-off-by: Philemon Ukane <[email protected]>
@ukane-philemon ukane-philemon changed the title site: use javascript optional chaining site: Check for uninitialized market in certain note handlers Apr 10, 2023
@ukane-philemon
Copy link
Contributor Author

In my previous efforts, I exercised excessive caution by proposing the adoption of JavaScript's optional chaining feature. However, following a recent discourse with @buck54321, and after considering our utilization of specific note handlers, I have come to the realization that such precaution is unnecessary, thereby rendering the implementation of js optional chaining superfluous.

Signed-off-by: Philemon Ukane <[email protected]>
@chappjc chappjc merged commit 58c3bf3 into decred:master Apr 14, 2023
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.

3 participants