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] Crash on onboarding due to nil value #16884

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions src/status_im2/contexts/onboarding/new_to_status/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,20 @@
:icon-background :blur
:icon :i/arrow-left
:on-press navigate-back}
:right-section-buttons [(when config/quo-preview-enabled?
{:type :grey
:icon :i/reveal-whitelist
:icon-background :blur
:on-press #(rf/dispatch [:navigate-to
:quo2-preview])})
{:type :grey
:icon :i/info
:icon-background :blur
:on-press #(rf/dispatch
[:show-bottom-sheet
{:content getting-started-doc
:shell? true}])}]}]])
:right-section-buttons (cond-> [{:type :grey
Copy link
Contributor

Choose a reason for hiding this comment

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

The more future proof solution is to change right-section-buttons to deal with nils (just filter them out), since it's quite common to use when to build up vectors. For example, re-frame even mentions this as one of the features of its :fx effect.

if any element of :fx is nil, it will be ignored. This allows effects to be conditionally included via a when (an example is given above)

-- https://day8.github.io/re-frame/releases/2020/

Although cond-> is just fine, the better fix imo is to make page-nav more resilient.

Copy link
Member Author

Choose a reason for hiding this comment

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

if any element of :fx is nil, it will be ignored. This allows effects to be conditionally included via a when (an > example is given above)

This is really helpful. Thanks for sharing!

I agree @ilmotta. We should this filter in all the component which receives a vector to prevent these types of crashes.

I faced this same issue when I was refactoring the action-drawer component, I added a filter to prevent it.

(let [filtered-actions (filter some? actions)]

the better fix imo is to make page-nav more resilient

I will add the filter in a separate PR 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

@ulisesmac is looking into that component I believe :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I will improve our page-nav component 👍

:icon :i/info
:icon-background :blur
:on-press #(rf/dispatch
[:show-bottom-sheet
{:content getting-started-doc
:shell? true}])}]

config/quo-preview-enabled?
(conj {:type :grey
:icon :i/reveal-whitelist
:icon-background :blur
:on-press #(rf/dispatch [:navigate-to
:quo2-preview])}))}]])

(defn new-to-status
[]
Expand Down