From b73ac6b1071ab9ee4b30ec84aa6fa11941d8469a Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Thu, 5 Oct 2023 18:50:57 +0000 Subject: [PATCH] Upgrade clj-kondo and configure new linters (#17543) - Upgrade clj-kondo to latest version to take advantage of new linters. From version 2023.04.14 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230414 to 2023.09.07 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230907 - Use new linter ":unused-alias" and set at WARN level for the moment, because otherwise the PR would increase a bit too much, but it did catch many unused "require" aliases. Added in version 2023.09.07 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230907 - Use new linter ":case-symbol-test" and fix the reported errors, added in version 2023.07.13 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230713 - Use new linters ":equals-true", ":plus-one", and ":minus-one" and fix reported errors, added in version 2023.05.18 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230518 - Raise level from WARN to ERROR for linter "uninitialized-var". - Explicitly add ":case-duplicate-test" to clj-kondo config, renamed in version 2023.07.13 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230713 - Explicitly add ":case-quoted-test" to clj-kondo config, renamed in version 2023.07.13 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230713 - Explicitly add ":deprecated-namespace" to clj-kondo config, added in version 2023.07.13 https://github.com/clj-kondo/clj-kondo/blob/master/CHANGELOG.md#20230713 Fixes https://github.com/status-im/status-mobile/issues/17287 --- .clj-kondo/config.edn | 12 ++++- nix/overlay.nix | 13 +++++ .../buttons/composer_button/style.cljs | 4 +- .../buttons/wallet_button/style.cljs | 2 +- .../components/calendar/calendar/utils.cljs | 2 +- .../components/graph/wallet_graph/view.cljs | 2 +- .../settings/reorder_item/view.cljs | 2 +- src/status_im/data_store/activities.cljs | 2 +- .../ui/screens/chat/message/legacy_view.cljs | 5 +- .../screens/chat/styles/message/message.cljs | 5 +- .../ui/screens/wallet/transactions/views.cljs | 2 +- src/status_im/wallet/db_test.cljs | 24 +++++----- src/status_im2/constants.cljs | 10 ++-- .../contexts/chat/composer/reply/view.cljs | 2 +- .../chat/home/chat_list_item/view.cljs | 27 ++++++----- .../chat/lightbox/zoomable_image/utils.cljs | 5 +- .../chat/messages/content/album/view.cljs | 5 +- .../contexts/chat/messages/content/view.cljs | 3 +- .../contexts/communities/overview/view.cljs | 6 +-- .../contexts/emoji_picker/constants.cljs | 6 ++- .../onboarding/common/carousel/animation.cljs | 4 +- .../contexts/profile/profiles/view.cljs | 2 +- .../quo_preview/switcher/switcher_cards.cljs | 15 +++--- .../notification/admin/view.cljs | 2 +- .../notification/contact_requests/view.cljs | 5 +- .../notification/reply/view.cljs | 17 ++++--- .../contexts/shell/activity_center/view.cljs | 5 +- .../components/switcher_cards/view.cljs | 47 ++++++++++--------- .../contexts/shell/jump_to/events.cljs | 2 +- src/utils/datetime_test.cljs | 6 +-- src/utils/ethereum/eip/eip55_test.cljs | 22 ++++----- 31 files changed, 150 insertions(+), 116 deletions(-) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index b1d628bbfd..596db9b42d 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -9,23 +9,29 @@ status-im.utils.styles/defn clojure.core/defn test-helpers.unit/deftest-sub clojure.core/defn taoensso.tufte/defnp clojure.core/defn} - :linters {:clj-kondo-config {:level :error} + :linters {:case-duplicate-test {:level :error} + :case-quoted-test {:level :error} + :case-symbol-test {:level :error} + :clj-kondo-config {:level :error} :cond-else {:level :error} :consistent-alias {:level :error :aliases {clojure.string string clojure.set set clojure.walk walk taoensso.timbre log}} + :deprecated-namespace {:level :warning} :docstring-blank {:level :error} + :equals-true {:level :error} :inline-def {:level :error} :invalid-arity {:skip-args [status-im.utils.fx/defn utils.re-frame/defn]} :loop-without-recur {:level :error} + :minus-one {:level :error} :misplaced-docstring {:level :error} :missing-body-in-when {:level :error} :missing-clause-in-try {:level :error} :missing-else-branch {:level :error} :not-empty? {:level :error} - :quoted-case-test-constant {:level :error} + :plus-one {:level :error} :redundant-do {:level :error} :redundant-let {:level :error} :refer-all {:level :error} @@ -48,6 +54,8 @@ number status-im.test-helpers/restore-app-db]} :unresolved-var {:level :error} + :uninitialized-var {:level :error} + :unused-alias {:level :warning} :unused-binding {:level :error} :unused-import {:level :error} :unused-namespace {:level :error} diff --git a/nix/overlay.nix b/nix/overlay.nix index 97ae908810..982cc7392c 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -38,6 +38,19 @@ in { }; }); + # Clojure's linter receives frequent upgrades, and we want to take advantage + # of the latest available rules. + clj-kondo = super.clj-kondo.override rec { + buildGraalvmNativeImage = args: super.buildGraalvmNativeImage (args // rec { + inherit (args) pname; + version = "2023.09.07"; + src = super.fetchurl { + url = "https://github.com/clj-kondo/${pname}/releases/download/v${version}/${pname}-${version}-standalone.jar"; + sha256 = "sha256-F7ePdITYKkGB6nsR3EFJ7zLDCUoT0g3i+AAjXzBd624="; + }; + }); + }; + # Checks fail on darwin. git-lfs = super.git-lfs.overrideAttrs (old: { doCheck = false; diff --git a/src/quo2/components/buttons/composer_button/style.cljs b/src/quo2/components/buttons/composer_button/style.cljs index d5c7c15d7d..0ca70fd821 100644 --- a/src/quo2/components/buttons/composer_button/style.cljs +++ b/src/quo2/components/buttons/composer_button/style.cljs @@ -5,8 +5,8 @@ [{:keys [pressed? blur? theme]}] (cond (and pressed? blur?) (colors/theme-colors colors/neutral-80-opa-20 colors/white-opa-20 theme) - (= pressed? true) (colors/theme-colors colors/neutral-40 colors/neutral-60 theme) - (= blur? true) (colors/theme-colors colors/neutral-80-opa-10 colors/white-opa-10 theme) + pressed? (colors/theme-colors colors/neutral-40 colors/neutral-60 theme) + blur? (colors/theme-colors colors/neutral-80-opa-10 colors/white-opa-10 theme) :else (colors/theme-colors colors/neutral-30 colors/neutral-70 theme))) (defn get-label-color diff --git a/src/quo2/components/buttons/wallet_button/style.cljs b/src/quo2/components/buttons/wallet_button/style.cljs index 29b6980445..4a0dafc5d3 100644 --- a/src/quo2/components/buttons/wallet_button/style.cljs +++ b/src/quo2/components/buttons/wallet_button/style.cljs @@ -3,7 +3,7 @@ (defn get-border-color [{:keys [pressed? theme]}] - (if (= pressed? true) + (if pressed? (colors/theme-colors colors/neutral-40 colors/neutral-60 theme) (colors/theme-colors colors/neutral-30 colors/neutral-70 theme))) diff --git a/src/quo2/components/calendar/calendar/utils.cljs b/src/quo2/components/calendar/calendar/utils.cljs index ae88cab264..b5852e12ea 100644 --- a/src/quo2/components/calendar/calendar/utils.cljs +++ b/src/quo2/components/calendar/calendar/utils.cljs @@ -6,7 +6,7 @@ (defn generate-years [current-year] (let [current-year current-year] - (reverse (vec (range (- current-year 100) (+ current-year 1)))))) + (reverse (vec (range (- current-year 100) (inc current-year)))))) (defn current-year [] diff --git a/src/quo2/components/graph/wallet_graph/view.cljs b/src/quo2/components/graph/wallet_graph/view.cljs index d57e51850f..9943ba3d50 100644 --- a/src/quo2/components/graph/wallet_graph/view.cljs +++ b/src/quo2/components/graph/wallet_graph/view.cljs @@ -55,7 +55,7 @@ [rn/view {:accessibility-label :line-chart} [charts/line-chart {:height 96 - :width (+ width 1) + :width (inc width) :max-value max-value :min-value 0 :adjust-to-width true diff --git a/src/quo2/components/settings/reorder_item/view.cljs b/src/quo2/components/settings/reorder_item/view.cljs index 3e2fa77c4d..4dfcb146ac 100644 --- a/src/quo2/components/settings/reorder_item/view.cljs +++ b/src/quo2/components/settings/reorder_item/view.cljs @@ -8,7 +8,7 @@ (defn reorder-item [item type {:keys [blur? drag]}] - (case type + (condp = type types/item [item/view item blur? drag] types/placeholder [placeholder/view item] types/skeleton [skeleton/view] diff --git a/src/status_im/data_store/activities.cljs b/src/status_im/data_store/activities.cljs index 4a2e70f53d..068f829d65 100644 --- a/src/status_im/data_store/activities.cljs +++ b/src/status_im/data_store/activities.cljs @@ -25,7 +25,7 @@ (defn- rpc->type [{:keys [type name] :as chat}] - (case type + (condp = type notification-types/reply (assoc chat :chat-name name diff --git a/src/status_im/ui/screens/chat/message/legacy_view.cljs b/src/status_im/ui/screens/chat/message/legacy_view.cljs index 3119f57df8..3ad367cd01 100644 --- a/src/status_im/ui/screens/chat/message/legacy_view.cljs +++ b/src/status_im/ui/screens/chat/message/legacy_view.cljs @@ -199,10 +199,11 @@ (defn contact-request-status-label [state] [rn/view {:style (style/contact-request-status-label state)} - (case state + (condp = state constants/contact-request-message-state-pending [contact-request-status-pending] constants/contact-request-message-state-accepted [contact-request-status-accepted] - constants/contact-request-message-state-declined [contact-request-status-declined])]) + constants/contact-request-message-state-declined [contact-request-status-declined] + nil)]) ;;;; SYSTEM diff --git a/src/status_im/ui/screens/chat/styles/message/message.cljs b/src/status_im/ui/screens/chat/styles/message/message.cljs index 9517651286..490578b2ec 100644 --- a/src/status_im/ui/screens/chat/styles/message/message.cljs +++ b/src/status_im/ui/screens/chat/styles/message/message.cljs @@ -389,10 +389,11 @@ :background-color (when (= :retry state) colors/blue-light) :border-width 1 - :border-color (case state + :border-color (condp = state constants/contact-request-message-state-accepted colors/green-transparent-10 constants/contact-request-message-state-declined colors/red-light - constants/contact-request-message-state-pending colors/gray-lighter) + constants/contact-request-message-state-pending colors/gray-lighter + nil) :padding-vertical 10 :padding-horizontal 16}) diff --git a/src/status_im/ui/screens/wallet/transactions/views.cljs b/src/status_im/ui/screens/wallet/transactions/views.cljs index 430a50dfab..f56556d8f9 100644 --- a/src/status_im/ui/screens/wallet/transactions/views.cljs +++ b/src/status_im/ui/screens/wallet/transactions/views.cljs @@ -34,7 +34,7 @@ :pending (transaction-icon :main-icons/arrow-right colors/black-transparent colors/gray) - (throw (str "Unknown transaction type: " k)))) + (throw (js/Error. (str "Unknown transaction type: " k))))) (defn render-transaction [{:keys [label contact address contact-accessibility-label diff --git a/src/status_im/wallet/db_test.cljs b/src/status_im/wallet/db_test.cljs index ad7c3e27db..307c0c7e46 100644 --- a/src/status_im/wallet/db_test.cljs +++ b/src/status_im/wallet/db_test.cljs @@ -6,18 +6,18 @@ (deftest test-too-precise-amount? (testing "try both decimal and scientific or hex format" - (is (= false (#'status-im.wallet.db/too-precise-amount? "100" 2))) - (is (= false (#'status-im.wallet.db/too-precise-amount? "100" 0))) - (is (= true (#'status-im.wallet.db/too-precise-amount? "100.1" 0))) - (is (= false (#'status-im.wallet.db/too-precise-amount? "100.23" 2))) - (is (= true (#'status-im.wallet.db/too-precise-amount? "100.233" 2))) - (is (= true (#'status-im.wallet.db/too-precise-amount? "100.0000000000000000001" 18))) - (is (= false (#'status-im.wallet.db/too-precise-amount? "100.000000000000000001" 18))) - (is (= false (#'status-im.wallet.db/too-precise-amount? "1e-18" 18))) - (is (= true (#'status-im.wallet.db/too-precise-amount? "1e-19" 18))) - (is (= true (#'status-im.wallet.db/too-precise-amount? "0xa.a" 2))) ;; 0xa.a is 10.625 - (is (= false (#'status-im.wallet.db/too-precise-amount? "0xa.a" 3))) - (is (= false (#'status-im.wallet.db/too-precise-amount? "1000" 3))))) + (is (false? (#'status-im.wallet.db/too-precise-amount? "100" 2))) + (is (false? (#'status-im.wallet.db/too-precise-amount? "100" 0))) + (is (true? (#'status-im.wallet.db/too-precise-amount? "100.1" 0))) + (is (false? (#'status-im.wallet.db/too-precise-amount? "100.23" 2))) + (is (true? (#'status-im.wallet.db/too-precise-amount? "100.233" 2))) + (is (true? (#'status-im.wallet.db/too-precise-amount? "100.0000000000000000001" 18))) + (is (false? (#'status-im.wallet.db/too-precise-amount? "100.000000000000000001" 18))) + (is (false? (#'status-im.wallet.db/too-precise-amount? "1e-18" 18))) + (is (true? (#'status-im.wallet.db/too-precise-amount? "1e-19" 18))) + (is (true? (#'status-im.wallet.db/too-precise-amount? "0xa.a" 2))) ;; 0xa.a is 10.625 + (is (false? (#'status-im.wallet.db/too-precise-amount? "0xa.a" 3))) + (is (false? (#'status-im.wallet.db/too-precise-amount? "1000" 3))))) (defn- equal-results? [a b] diff --git a/src/status_im2/constants.cljs b/src/status_im2/constants.cljs index eba3baafad..93f437019e 100644 --- a/src/status_im2/constants.cljs +++ b/src/status_im2/constants.cljs @@ -236,17 +236,17 @@ {2 {0 image-size 1 image-size} 3 {0 [(* image-size 2) (* image-size 1.25)] - 1 [(- image-size 0.5) (- (* image-size 0.75) 1)] - 2 [(- image-size 0.5) (- (* image-size 0.75) 1)]} + 1 [(- image-size 0.5) (dec (* image-size 0.75))] + 2 [(- image-size 0.5) (dec (* image-size 0.75))]} 4 {0 image-size 1 image-size 2 image-size 3 image-size} 5 {0 image-size 1 image-size - 2 (- (* image-size 0.67) 1) - 3 (- (* image-size 0.67) 1) - 4 (- (* image-size 0.67) 1)} + 2 (dec (* image-size 0.67)) + 3 (dec (* image-size 0.67)) + 4 (dec (* image-size 0.67))} :default {0 image-size 1 image-size 2 (- (* image-size 0.5) 0.5) diff --git a/src/status_im2/contexts/chat/composer/reply/view.cljs b/src/status_im2/contexts/chat/composer/reply/view.cljs index c5457e4aea..e09e3ef91f 100644 --- a/src/status_im2/contexts/chat/composer/reply/view.cljs +++ b/src/status_im2/contexts/chat/composer/reply/view.cljs @@ -122,7 +122,7 @@ :style {:color (colors/theme-colors colors/neutral-50 colors/neutral-40) :margin-top 2}} (str " " - (case (or content-type contentType) + (condp = (or content-type contentType) constant/content-type-image (if (pos? album-images-count) (i18n/label :t/album-images-count {:album-images-count album-images-count}) diff --git a/src/status_im2/contexts/chat/home/chat_list_item/view.cljs b/src/status_im2/contexts/chat/home/chat_list_item/view.cljs index ddefe234bb..5b4235ba4c 100644 --- a/src/status_im2/contexts/chat/home/chat_list_item/view.cljs +++ b/src/status_im2/contexts/chat/home/chat_list_item/view.cljs @@ -60,8 +60,8 @@ :other-person :dont-show)) preview-text - (case content-type - constants/content-type-text + (cond + (= content-type constants/content-type-text) (if reply? (case author :you (str (i18n/label :t/you-replied) ": " content-text) @@ -74,33 +74,34 @@ :dont-show content-text content-text)) - constants/content-type-emoji + (= content-type constants/content-type-emoji) (case author :you (str (i18n/label :t/You) ": " content-text) :other-person (str primary-name ": " content-text) :dont-show content-text content-text) - constants/content-type-system-text + (= content-type constants/content-type-system-text) (case author :you (i18n/label :t/you-pinned-a-message) :other-person (i18n/label :t/user-pinned-a-message {:user primary-name}) :dont-show (i18n/label :t/Pinned-a-message) (i18n/label :t/Pinned-a-message)) - (constants/content-type-contact-request - constants/content-type-system-message-mutual-event-removed - constants/content-type-system-message-mutual-event-accepted) + (#{constants/content-type-contact-request + constants/content-type-system-message-mutual-event-removed + constants/content-type-system-message-mutual-event-accepted} + content-type) (i18n/label :t/contact-request) - constants/content-type-sticker + (= content-type constants/content-type-sticker) (case author :you (i18n/label :t/you-sent-a-sticker) :other-person (i18n/label :t/user-sent-a-sticker {:user primary-name}) :dont-show (i18n/label :t/sent-a-sticker) (i18n/label :t/sent-a-sticker)) - constants/content-type-image + (= content-type constants/content-type-image) (let [sent-photos (if album-images-count (case author :you (i18n/label :t/you-sent-n-photos @@ -119,31 +120,31 @@ (str sent-photos ": " content-text) sent-photos)) - constants/content-type-audio + (= content-type constants/content-type-audio) (case author :you (i18n/label :t/you-sent-audio-message) :other-person (i18n/label :t/user-sent-audio-message {:user primary-name}) :dont-show (i18n/label :t/sent-audio-message) (i18n/label :t/sent-audio-message)) - constants/content-type-gif + (= content-type constants/content-type-gif) (case author :you (i18n/label :t/you-sent-a-gif) :other-person (i18n/label :t/user-sent-audio-message {:user primary-name}) :dont-show (i18n/label :t/sent-a-gif) (i18n/label :t/sent-a-gif)) - constants/content-type-community + (= content-type constants/content-type-community) (case author :you (i18n/label :t/you-shared-a-community) :other-person (i18n/label :t/user-shared-a-community {:user primary-name}) :dont-show (i18n/label :t/shared-a-community) (i18n/label :t/shared-a-community)) + :else "")] (subs preview-text 0 (min (count preview-text) max-subheader-length)))) - (defn last-message-preview "Render the preview of a last message to a maximum of max-subheader-length characters" [group-chat {:keys [deleted? outgoing from deleted-for-me?] :as message}] diff --git a/src/status_im2/contexts/chat/lightbox/zoomable_image/utils.cljs b/src/status_im2/contexts/chat/lightbox/zoomable_image/utils.cljs index 323acfc167..80cf34e26d 100644 --- a/src/status_im2/contexts/chat/lightbox/zoomable_image/utils.cljs +++ b/src/status_im2/contexts/chat/lightbox/zoomable_image/utils.cljs @@ -110,9 +110,8 @@ [index {:keys [opacity-value border-value full-screen-scale transparent? props]} portrait?] (let [{:keys [small-list-ref timers text-sheet-lock?]} props opacity (reanimated/get-shared-value opacity-value) - scale-value (+ 1 - (/ constants/margin - (:width (rn/get-window))))] + scale-value (inc (/ constants/margin + (:width (rn/get-window))))] (if (= opacity 1) (do (js/clearTimeout (:show-0 @timers)) diff --git a/src/status_im2/contexts/chat/messages/content/album/view.cljs b/src/status_im2/contexts/chat/messages/content/album/view.cljs index f6c7da84e0..f903a97d50 100644 --- a/src/status_im2/contexts/chat/messages/content/album/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/album/view.cljs @@ -26,7 +26,8 @@ :landscape :portrait) images-count (count (:album message)) - ;; album images are always square, except when we have 3 images, then they must be rectangular + ;; album images are always square, except when we have 3 images, then they must be + ;; rectangular ;; (portrait or landscape) portrait? (and (= images-count rectangular-style-count) (= album-style :portrait))] (if (and albumize? (> images-count 1)) @@ -61,7 +62,7 @@ (< index constants/max-album-photos)) :shared-element)}] (when (and (> images-count constants/max-album-photos) - (= index (- constants/max-album-photos 1))) + (= index (dec constants/max-album-photos))) [rn/view {:style style/overlay} [quo/text diff --git a/src/status_im2/contexts/chat/messages/content/view.cljs b/src/status_im2/contexts/chat/messages/content/view.cljs index 010dcfa35e..10ce8a1fd6 100644 --- a/src/status_im2/contexts/chat/messages/content/view.cljs +++ b/src/status_im2/contexts/chat/messages/content/view.cljs @@ -173,8 +173,7 @@ :max-height (when-not show-reactions? (* 0.4 height))}} [author message-data show-reactions? show-user-info?] - (case content-type - + (condp = content-type constants/content-type-text [content.text/text-content message-data context] diff --git a/src/status_im2/contexts/communities/overview/view.cljs b/src/status_im2/contexts/communities/overview/view.cljs index ac50ce6976..1303ac8552 100644 --- a/src/status_im2/contexts/communities/overview/view.cljs +++ b/src/status_im2/contexts/communities/overview/view.cljs @@ -101,7 +101,7 @@ (defn get-access-type [access] - (case access + (condp = access constants/community-no-membership-access :open constants/community-invitation-only-access :invite-only constants/community-on-request-access :request-access @@ -339,8 +339,8 @@ {:on-category-layout (partial add-category-height categories-heights) :collapsed? collapsed? :on-first-channel-height-changed - ;; Here we set the height of the component and we filter out the categories, as some might - ;; have been removed. + ;; Here we set the height of the component and we filter out the categories, as some + ;; might have been removed. (fn [height categories] (swap! categories-heights select-keys categories) (reset! first-channel-height height))}]])))) diff --git a/src/status_im2/contexts/emoji_picker/constants.cljs b/src/status_im2/contexts/emoji_picker/constants.cljs index 822e6cbd62..0a2db5bd4f 100644 --- a/src/status_im2/contexts/emoji_picker/constants.cljs +++ b/src/status_im2/contexts/emoji_picker/constants.cljs @@ -16,7 +16,9 @@ (def ^:const emoji-row-separator-height 16) (def ^:const emoji-item-margin-right - (/ (- (:width (rn/get-window)) (* emoji-row-padding-horizontal 2) (* emoji-size emojis-per-row)) - (- emojis-per-row 1))) + (/ (- (:width (rn/get-window)) + (* emoji-row-padding-horizontal 2) + (* emoji-size emojis-per-row)) + (dec emojis-per-row))) (def ^:const item-height (+ emoji-size emoji-row-separator-height)) diff --git a/src/status_im2/contexts/onboarding/common/carousel/animation.cljs b/src/status_im2/contexts/onboarding/common/carousel/animation.cljs index 2f4cc2ed45..04523195b6 100644 --- a/src/status_im2/contexts/onboarding/common/carousel/animation.cljs +++ b/src/status_im2/contexts/onboarding/common/carousel/animation.cljs @@ -61,7 +61,7 @@ (if (>= current-progress drag-limit) drag-limit (-> (quot current-progress progress-threshold) - (+ 1) + inc (* progress-threshold))))) (defn get-previous-progress @@ -70,7 +70,7 @@ (if (< current-progress progress-threshold) 0 (-> (quot current-progress progress-threshold) - (- 1) + dec (* progress-threshold))))) (defn use-initialize-animation diff --git a/src/status_im2/contexts/profile/profiles/view.cljs b/src/status_im2/contexts/profile/profiles/view.cljs index 77c2c6485d..7825a09ac9 100644 --- a/src/status_im2/contexts/profile/profiles/view.cljs +++ b/src/status_im2/contexts/profile/profiles/view.cljs @@ -156,7 +156,7 @@ {:data (sort-by :timestamp > profiles) :key-fn :key-uid :content-container-style {:padding-bottom 20} - :render-data {:last-index (- (count profiles) 1) + :render-data {:last-index (dec (count profiles)) :set-hide-profiles set-hide-profiles} :render-fn profile-card}]])) diff --git a/src/status_im2/contexts/quo_preview/switcher/switcher_cards.cljs b/src/status_im2/contexts/quo_preview/switcher/switcher_cards.cljs index aa6d44dd0f..03ff8de506 100644 --- a/src/status_im2/contexts/quo_preview/switcher/switcher_cards.cljs +++ b/src/status_im2/contexts/quo_preview/switcher/switcher_cards.cljs @@ -99,7 +99,7 @@ (defn get-mock-content [data] - (case (:content-type data) + (condp = (:content-type data) constants/content-type-text (:last-message data) @@ -135,16 +135,19 @@ :community-channel {:emoji "🍑" :channel-name "# random"} :community-info {:type :kicked} :data (get-mock-content data)}} - (case type - shell.constants/one-to-one-chat-card + (cond + (= type shell.constants/one-to-one-chat-card) {:avatar-params {:full-name (:title data)}} - shell.constants/private-group-chat-card + (= type shell.constants/private-group-chat-card) {} - (shell.constants/community-card - shell.constants/community-channel-card) + (#{shell.constants/community-card + shell.constants/community-channel-card} + type) {:avatar-params community-avatar} + + :else {}))) (defn preview-switcher-cards diff --git a/src/status_im2/contexts/shell/activity_center/notification/admin/view.cljs b/src/status_im2/contexts/shell/activity_center/notification/admin/view.cljs index c1582ff832..2c752f54f4 100644 --- a/src/status_im2/contexts/shell/activity_center/notification/admin/view.cljs +++ b/src/status_im2/contexts/shell/activity_center/notification/admin/view.cljs @@ -74,7 +74,7 @@ :blur? true :community-logo community-image :community-name community-name}]] - :items (case membership-status + :items (condp = membership-status constants/activity-center-membership-status-accepted [{:type :status :subtype :positive diff --git a/src/status_im2/contexts/shell/activity_center/notification/contact_requests/view.cljs b/src/status_im2/contexts/shell/activity_center/notification/contact_requests/view.cljs index ed10215c01..fa7c4d40b7 100644 --- a/src/status_im2/contexts/shell/activity_center/notification/contact_requests/view.cljs +++ b/src/status_im2/contexts/shell/activity_center/notification/contact_requests/view.cljs @@ -83,7 +83,7 @@ :context [(i18n/label :t/contact-request-outgoing) [common/user-avatar-tag chat-id]] :message {:body (get-in message [:content :text])} - :items (case contact-request-state + :items (condp = contact-request-state constants/contact-request-message-state-pending [{:type :status :subtype :pending @@ -115,7 +115,7 @@ (i18n/label :t/contact-request-sent)] :message {:body (get-in message [:content :text])} :items - (case (:contact-request-state message) + (condp = (:contact-request-state message) constants/contact-request-message-state-accepted [{:type :status :subtype :positive @@ -143,6 +143,7 @@ :label (i18n/label :t/accept) :accessibility-label :accept-contact-request :on-press #(rf/dispatch [:activity-center.contact-requests/accept id])}] + nil)}])) (defn view diff --git a/src/status_im2/contexts/shell/activity_center/notification/reply/view.cljs b/src/status_im2/contexts/shell/activity_center/notification/reply/view.cljs index d362bba3b3..5136d64dbc 100644 --- a/src/status_im2/contexts/shell/activity_center/notification/reply/view.cljs +++ b/src/status_im2/contexts/shell/activity_center/notification/reply/view.cljs @@ -15,9 +15,10 @@ ;; NOTE: Replies support text, image and stickers only. (defn- get-message-content [{:keys [content-type] :as message} album-messages media-server-port] - (case content-type - constants/content-type-text [quo/text {:style style/tag-text} - (get-in message [:content :text])] + (condp = content-type + constants/content-type-text + [quo/text {:style style/tag-text} + (get-in message [:content :text])] constants/content-type-image (let [images (or album-messages message) @@ -31,7 +32,8 @@ {:photos image-local-urls :message-text (get-in message [:content :text])}]) - constants/content-type-sticker [old-message/sticker message] + constants/content-type-sticker + [old-message/sticker message] constants/content-type-system-pinned-message [not-implemented/not-implemented @@ -40,9 +42,10 @@ ;; NOTE: The following type (system-text) doesn't have a design yet. ;; https://github.com/status-im/status-mobile/issues/14915 - constants/content-type-system-text [not-implemented/not-implemented - [quo/text {:style style/tag-text} - (get-in message [:content :text])]] + constants/content-type-system-text + [not-implemented/not-implemented + [quo/text {:style style/tag-text} + (get-in message [:content :text])]] nil)) diff --git a/src/status_im2/contexts/shell/activity_center/view.cljs b/src/status_im2/contexts/shell/activity_center/view.cljs index 7ad9185877..eb8ff56c9a 100644 --- a/src/status_im2/contexts/shell/activity_center/view.cljs +++ b/src/status_im2/contexts/shell/activity_center/view.cljs @@ -50,13 +50,10 @@ [admin/view props] (some types/membership [type]) - (case type + (condp = type types/private-group-chat [membership/view props] - types/community-request [community-request/view props] - types/community-kicked [community-kicked/view props] - nil) :else diff --git a/src/status_im2/contexts/shell/jump_to/components/switcher_cards/view.cljs b/src/status_im2/contexts/shell/jump_to/components/switcher_cards/view.cljs index 8e4ca907dc..a99e47468e 100644 --- a/src/status_im2/contexts/shell/jump_to/components/switcher_cards/view.cljs +++ b/src/status_im2/contexts/shell/jump_to/components/switcher_cards/view.cljs @@ -35,7 +35,7 @@ community-info community-channel] {:keys [text parsed-text source]} :data}] [rn/view {:style (style/content-container new-notifications?)} - (case type + (condp = type shell.constants/community-card (case (:type community-info) :pending [quo/status-tag @@ -52,7 +52,7 @@ shell.constants/community-channel-card [channel-card (assoc community-channel :customization-color color-50)] - (case content-type + (condp = content-type constants/content-type-text [quo/text {:size :paragraph-2 @@ -90,7 +90,7 @@ :community-logo (:avatar data) :community-name (:community-name data)}] - (constants/content-type-link) ;; Components not available + constants/content-type-link ;; Components not available ;; Code snippet content type is not supported yet [:<>] @@ -114,21 +114,22 @@ (defn avatar [avatar-params type customization-color] - (case type - shell.constants/one-to-one-chat-card + (cond + (= type shell.constants/one-to-one-chat-card) [quo/user-avatar (merge {:size :medium :status-indicator? false} avatar-params)] - shell.constants/private-group-chat-card + (= type shell.constants/private-group-chat-card) [quo/group-avatar {:customization-color customization-color :size :size-48 :override-theme :dark}] - (shell.constants/community-card - shell.constants/community-channel-card) + (#{shell.constants/community-card + shell.constants/community-channel-card} + type) (cond (:source avatar-params) [fast-image/fast-image @@ -144,18 +145,19 @@ :style {:color colors/white-opa-70}} (string/upper-case (first (:name avatar-params)))]]) + :else nil)) (defn subtitle [type {:keys [content-type data]}] - (case type + (condp = type shell.constants/community-card (i18n/label :t/community) shell.constants/community-channel-card (i18n/label :t/community-channel) - (case content-type + (condp = content-type constants/content-type-text (i18n/label :t/message) @@ -298,29 +300,32 @@ (defn card [{:keys [type] :as data}] - (case type - shell.constants/empty-card ;; Placeholder + (cond + (= type shell.constants/empty-card) ; Placeholder [empty-card] - (shell.constants/one-to-one-chat-card ;; Screens Card - shell.constants/private-group-chat-card - shell.constants/community-card - shell.constants/community-channel-card) + ;; Screens Card + (#{shell.constants/one-to-one-chat-card + shell.constants/private-group-chat-card + shell.constants/community-card + shell.constants/community-channel-card} + type) [screens-card data] - shell.constants/browser-card ;; Browser Card + (= type shell.constants/browser-card) ; Browser Card [browser-card data] - shell.constants/wallet-card ;; Wallet Card + (= type shell.constants/wallet-card) ; Wallet Card [wallet-card data] - shell.constants/wallet-collectible ;; Wallet Card + (= type shell.constants/wallet-collectible) ; Wallet Card [wallet-collectible data] - shell.constants/wallet-graph ;; Wallet Card + (= type shell.constants/wallet-graph) ; Wallet Card [wallet-graph data] - shell.constants/communities-discover ;; Home Card + (= type shell.constants/communities-discover) ; Home Card [communities-discover data] + :else nil)) diff --git a/src/status_im2/contexts/shell/jump_to/events.cljs b/src/status_im2/contexts/shell/jump_to/events.cljs index 479f805b63..13c734b048 100644 --- a/src/status_im2/contexts/shell/jump_to/events.cljs +++ b/src/status_im2/contexts/shell/jump_to/events.cljs @@ -57,7 +57,7 @@ (case view-id :chat (let [chat (get-in db [:chats id])] - (case (:chat-type chat) + (condp = (:chat-type chat) constants/one-to-one-chat-type {:card-id id :switcher-card {:type shell.constants/one-to-one-chat-card diff --git a/src/utils/datetime_test.cljs b/src/utils/datetime_test.cljs index aa013459bc..3a85883b78 100644 --- a/src/utils/datetime_test.cljs +++ b/src/utils/datetime_test.cljs @@ -26,13 +26,13 @@ (def mock-current-time-epoch 1655731506000) (deftest is-24-hour-locale-en-test - (is (= (#'utils.datetime/is-24-hour-locsym (i18n-goog/locale-symbols "en")) false))) + (is (false? (#'utils.datetime/is-24-hour-locsym (i18n-goog/locale-symbols "en"))))) (deftest is-24-hour-locale-it-test - (is (= (#'utils.datetime/is-24-hour-locsym (i18n-goog/locale-symbols "it")) true))) + (is (true? (#'utils.datetime/is-24-hour-locsym (i18n-goog/locale-symbols "it"))))) (deftest is-24-hour-locale-nb-test - (is (= (#'utils.datetime/is-24-hour-locsym (i18n-goog/locale-symbols "nb-NO")) true))) + (is (true? (#'utils.datetime/is-24-hour-locsym (i18n-goog/locale-symbols "nb-NO"))))) (deftest to-short-str-today-test (with-redefs [t/*ms-fn* (constantly epoch-plus-3d) diff --git a/src/utils/ethereum/eip/eip55_test.cljs b/src/utils/ethereum/eip/eip55_test.cljs index 67167378ad..289eaac189 100644 --- a/src/utils/ethereum/eip/eip55_test.cljs +++ b/src/utils/ethereum/eip/eip55_test.cljs @@ -3,14 +3,14 @@ [utils.ethereum.eip.eip55 :as eip55])) (deftest valid-address-checksum? - (is (= true (eip55/valid-address-checksum? "0x52908400098527886E0F7030069857D2E4169EE7"))) - (is (= true (eip55/valid-address-checksum? "0x8617E340B3D01FA5F11F306F4090FD50E238070D"))) - (is (= true (eip55/valid-address-checksum? "0xde709f2102306220921060314715629080e2fb77"))) - (is (= true (eip55/valid-address-checksum? "0x27b1fdb04752bbc536007a920d24acb045561c26"))) - (is (= true (eip55/valid-address-checksum? "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"))) - (is (= true (eip55/valid-address-checksum? "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"))) - (is (= true (eip55/valid-address-checksum? "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"))) - (is (= true (eip55/valid-address-checksum? "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"))) - (is (= false (eip55/valid-address-checksum? "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9adB"))) - (is (= false (eip55/valid-address-checksum? "0x8617e340b3d01fa5f11f306f4090fd50e238070d"))) - (is (= false (eip55/valid-address-checksum? "0xDE709F2102306220921060314715629080E2fB77")))) + (is (true? (eip55/valid-address-checksum? "0x52908400098527886E0F7030069857D2E4169EE7"))) + (is (true? (eip55/valid-address-checksum? "0x8617E340B3D01FA5F11F306F4090FD50E238070D"))) + (is (true? (eip55/valid-address-checksum? "0xde709f2102306220921060314715629080e2fb77"))) + (is (true? (eip55/valid-address-checksum? "0x27b1fdb04752bbc536007a920d24acb045561c26"))) + (is (true? (eip55/valid-address-checksum? "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"))) + (is (true? (eip55/valid-address-checksum? "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359"))) + (is (true? (eip55/valid-address-checksum? "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB"))) + (is (true? (eip55/valid-address-checksum? "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb"))) + (is (false? (eip55/valid-address-checksum? "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9adB"))) + (is (false? (eip55/valid-address-checksum? "0x8617e340b3d01fa5f11f306f4090fd50e238070d"))) + (is (false? (eip55/valid-address-checksum? "0xDE709F2102306220921060314715629080E2fB77"))))