From c81dd8e3e30ec08791baed043f052619ffef8ce7 Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Tue, 16 Apr 2024 14:48:28 -0300 Subject: [PATCH] Don't treat dynamic data as a function (#19672) Sometimes an integration test was throwing "TypeError: Cannot read properties of null (reading 'call')" because a value was nil in the app-db, but the code was treating it as if it was always a map and could be called as a function. The original code wasn't respecting Clojure's nil punning good practices. In Clojure, it's often recommended to not use dynamic data as functions, because if they're nil, in CLJS we'll get an exception and as usual in CLJS, the stacktrace won't be very readable. We should prefer contains? or get, which will work just fine with nil values, and only use data as a function if it's static, e.g. a map defined in a def. --- src/status_im/contexts/wallet/events.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 1865ce38ac..54d05d546d 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -148,7 +148,7 @@ (let [tokens (data-store/rpc->tokens raw-tokens-data) add-tokens (fn [stored-accounts tokens-per-account] (reduce-kv (fn [accounts address tokens-data] - (if (accounts address) + (if (contains? accounts address) (update accounts address assoc :tokens tokens-data) accounts)) stored-accounts