From 9a60fc160070f76f9e02062344d07b616876a0ea Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Tue, 17 Jan 2023 19:52:12 -0300 Subject: [PATCH] Fix all type hint warnings (#14810) --- src/quo2/components/tags/tags.cljs | 6 +- src/status_im/audio/core.cljs | 55 +++++++++++-------- src/status_im/contact/block.cljs | 7 ++- src/status_im/group_chats/core.cljs | 13 +++-- src/status_im/transport/message/core.cljs | 6 +- .../ui/components/bottom_panel/views.cljs | 2 +- .../ui/screens/chat/message/message.cljs | 2 +- src/status_im/ui/screens/status/views.cljs | 2 +- .../ui2/screens/chat/composer/input.cljs | 2 +- .../ui2/screens/chat/messages/message.cljs | 2 +- src/status_im/utils/money.cljs | 2 +- src/status_im/wallet_connect/core.cljs | 4 +- src/status_im/wallet_connect_legacy/core.cljs | 2 +- 13 files changed, 59 insertions(+), 46 deletions(-) diff --git a/src/quo2/components/tags/tags.cljs b/src/quo2/components/tags/tags.cljs index d513c031a8..5bfb85f1d7 100644 --- a/src/quo2/components/tags/tags.cljs +++ b/src/quo2/components/tags/tags.cljs @@ -25,7 +25,7 @@ :component tag/tab :size 32/24 :on-press fn - :blurred? true/false + :blurred? true/false :labelled? true/false :disabled? true/false :scroll-on-press? true @@ -36,7 +36,7 @@ :data [{:id :label \"\" :resource \"url\"} {:id :label \"\" :resource \"url\"}]} Opts: - - `component` this is to determine which component is to be rendered since the + - `component` this is to determine which component is to be rendered since the logic in this view is shared between tab and tag component - `blurred` boolean: use to determine border color if the background is blurred - `type` can be icon or emoji with or without a tag label @@ -142,7 +142,7 @@ :on-press (fn [id] (reset! active-tab-id id) (when scroll-on-press? - (.scrollToIndex @flat-list-ref + (.scrollToIndex ^js @flat-list-ref #js {:animated true :index index diff --git a/src/status_im/audio/core.cljs b/src/status_im/audio/core.cljs index 8dad5bcc09..04dfc3c390 100644 --- a/src/status_im/audio/core.cljs +++ b/src/status_im/audio/core.cljs @@ -46,15 +46,16 @@ [player on-prepared on-error] (when (and player (.-canPrepare ^js player)) (.prepare ^js player - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-prepared))))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-prepared)))))) (defn prepare-recorder [recorder on-prepared on-error] (when (and recorder (.-canPrepare ^js recorder)) (.prepare ^js recorder - (fn [err _] + (fn [^js err] (if err (on-error {:error (.-err err) :message (.-message err)}) (on-prepared)))))) @@ -66,42 +67,47 @@ (.-canRecord ^js recorder) (.-canPrepare ^js recorder))) (.record ^js recorder - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-start))))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-start)))))) (defn stop-recording [recorder on-stop on-error] (if (and recorder (#{RECORDING PAUSED} (get-state recorder))) (.stop ^js recorder - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-stop))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-stop)))) (on-stop))) (defn pause-recording [recorder on-pause on-error] (when (and recorder (.-isRecording ^js recorder)) (.pause ^js recorder - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-pause))))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-pause)))))) (defn start-playing [player on-start on-error] (when (and player (.-canPlay ^js player)) (.play ^js player - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-start))))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-start)))))) (defn stop-playing [player on-stop on-error] (if (and player (.-isPlaying ^js player)) (.stop ^js player - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-stop))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-stop)))) (on-stop))) (defn get-recorder-file-path @@ -123,7 +129,7 @@ [player on-play on-pause on-error] (when (and player (.-canPlay ^js player)) (.playPause ^js player - (fn [error pause?] + (fn [^js error pause?] (if error (on-error {:error (.-err error) :message (.-message error)}) (if pause? @@ -135,9 +141,10 @@ (when (and player (.-canPlay ^js player)) (.seek ^js player value - #(if % - (on-error {:error (.-err %) :message (.-message %)}) - (on-seek))))) + (fn [^js err] + (if err + (on-error {:error (.-err err) :message (.-message err)}) + (on-seek)))))) (defn can-play? [player] @@ -155,4 +162,4 @@ (stop-playing player #(when (and player (not= (get-state player) IDLE)) (.destroy ^js player)) - #())) \ No newline at end of file + #())) diff --git a/src/status_im/contact/block.cljs b/src/status_im/contact/block.cljs index 423200f0f6..fa664b1fd1 100644 --- a/src/status_im/contact/block.cljs +++ b/src/status_im/contact/block.cljs @@ -70,9 +70,10 @@ (assoc-in [:contacts/contacts public-key] contact))} (contacts-store/block public-key - #(do (re-frame/dispatch [::contact-blocked contact (.-chats %)]) - (re-frame/dispatch [:sanitize-messages-and-process-response %]) - (re-frame/dispatch [:hide-popover]))) + (fn [^js block-contact] + (re-frame/dispatch [::contact-blocked contact (.-chats block-contact)]) + (re-frame/dispatch [:sanitize-messages-and-process-response block-contact]) + (re-frame/dispatch [:hide-popover]))) ;; reset navigation to avoid going back to non existing one to one chat (if from-one-to-one-chat? (navigation/pop-to-root-tab :chat-stack) diff --git a/src/status_im/group_chats/core.cljs b/src/status_im/group_chats/core.cljs index 3826729640..8b75abe994 100644 --- a/src/status_im/group_chats/core.cljs +++ b/src/status_im/group_chats/core.cljs @@ -2,13 +2,14 @@ (:refer-clojure :exclude [remove]) (:require [clojure.spec.alpha :as spec] [clojure.string :as string] + [i18n.i18n :as i18n] + [oops.core :as oops] [re-frame.core :as re-frame] [status-im.chat.models :as models.chat] [status-im.constants :as constants] - [utils.re-frame :as rf] - [i18n.i18n :as i18n] [status-im2.contexts.activity-center.events :as activity-center] - [status-im2.navigation.events :as navigation])) + [status-im2.navigation.events :as navigation] + [utils.re-frame :as rf])) (rf/defn navigate-chat-updated {:events [:navigate-chat-updated]} @@ -30,7 +31,11 @@ [_ response do-not-navigate?] {:dispatch-n [[:sanitize-messages-and-process-response response] (when-not do-not-navigate? - [:navigate-chat-updated (.-id (aget (.-chats response) 0))])]}) + [:navigate-chat-updated + (-> response + (oops/oget :chats) + first + (oops/oget :id))])]}) (rf/defn remove-member "Format group update message and sign membership" diff --git a/src/status_im/transport/message/core.cljs b/src/status_im/transport/message/core.cljs index 19761ee8e0..930c9382ef 100644 --- a/src/status_im/transport/message/core.cljs +++ b/src/status_im/transport/message/core.cljs @@ -235,11 +235,11 @@ (defn sort-js-messages! "sort messages, so we can start process latest first,in that case we only need to process frist 20 and drop others" - [response-js messages] + [^js response-js messages] (if (seq messages) (set! (.-messages response-js) (.sort (to-array messages) - (fn [a b] + (fn [^js a ^js b] (- (.-clock b) (.-clock a))))) (js-delete response-js "messages"))) @@ -334,7 +334,7 @@ (rf/defn transport-message-sent {:events [:transport/message-sent]} - [cofx response-js] + [cofx ^js response-js] (let [set-hash-fxs (map (fn [{:keys [localChatId id messageType]}] (set-message-envelope-hash localChatId id messageType)) (types/js->clj (.-messages response-js)))] diff --git a/src/status_im/ui/components/bottom_panel/views.cljs b/src/status_im/ui/components/bottom_panel/views.cljs index 0c149315a6..18406d83c1 100644 --- a/src/status_im/ui/components/bottom_panel/views.cljs +++ b/src/status_im/ui/components/bottom_panel/views.cljs @@ -57,7 +57,7 @@ update? (atom nil) current-obj (reagent/atom nil)] (reagent/create-class - {:UNSAFE_componentWillMount (fn [args] + {:UNSAFE_componentWillMount (fn [^js args] (let [[_ obj _ _] (.-argv (.-props args))] (when @clear-timeout (js/clearTimeout @clear-timeout)) (when (or (not= obj @current-obj) @update?) diff --git a/src/status_im/ui/screens/chat/message/message.cljs b/src/status_im/ui/screens/chat/message/message.cljs index bec7d03d0a..6268f18079 100644 --- a/src/status_im/ui/screens/chat/message/message.cljs +++ b/src/status_im/ui/screens/chat/message/message.cljs @@ -404,7 +404,7 @@ (defn image-set-size [dimensions] - (fn [evt] + (fn [^js evt] (let [width (.-width (.-nativeEvent evt)) height (.-height (.-nativeEvent evt))] (if (< width height) diff --git a/src/status_im/ui/screens/status/views.cljs b/src/status_im/ui/screens/status/views.cljs index fa1323bf84..87939b9268 100644 --- a/src/status_im/ui/screens/status/views.cljs +++ b/src/status_im/ui/screens/status/views.cljs @@ -26,7 +26,7 @@ (defn image-set-size [width] - (fn [evt] + (fn [^js evt] (reset! width (/ (.-width (.-nativeEvent evt)) (/ (.-height (.-nativeEvent evt)) image-max-dimension))))) diff --git a/src/status_im/ui2/screens/chat/composer/input.cljs b/src/status_im/ui2/screens/chat/composer/input.cljs index a9e4877558..1d139a3816 100644 --- a/src/status_im/ui2/screens/chat/composer/input.cljs +++ b/src/status_im/ui2/screens/chat/composer/input.cljs @@ -374,7 +374,7 @@ (update-selection text-input-handle start end) (reset! selection-event nil)))) on-selection - (fn [event] + (fn [^js event] (let [native-event (.-nativeEvent event) native-event (transforms/js->clj native-event) {:keys [eventType content selectionStart selectionEnd]} native-event diff --git a/src/status_im/ui2/screens/chat/messages/message.cljs b/src/status_im/ui2/screens/chat/messages/message.cljs index 02870f16c3..371b494f86 100644 --- a/src/status_im/ui2/screens/chat/messages/message.cljs +++ b/src/status_im/ui2/screens/chat/messages/message.cljs @@ -253,7 +253,7 @@ (defn image-set-size [dimensions] - (fn [evt] + (fn [^js evt] (let [width (.-width (.-nativeEvent evt)) height (.-height (.-nativeEvent evt))] (if (< width height) diff --git a/src/status_im/utils/money.cljs b/src/status_im/utils/money.cljs index a49316f864..c35f228125 100644 --- a/src/status_im/utils/money.cljs +++ b/src/status_im/utils/money.cljs @@ -36,7 +36,7 @@ (catch :default _ nil)))) (defn greater-than-or-equals - [bn1 bn2] + [^js bn1 ^js bn2] (.greaterThanOrEqualTo bn1 bn2)) (defn greater-than diff --git a/src/status_im/wallet_connect/core.cljs b/src/status_im/wallet_connect/core.cljs index aff7909f1e..66a40133b2 100644 --- a/src/status_im/wallet_connect/core.cljs +++ b/src/status_im/wallet_connect/core.cljs @@ -63,7 +63,7 @@ {:show-wallet-connect-sheet nil}) (defn subscribe-to-events - [wallet-connect-client] + [^js wallet-connect-client] (.on wallet-connect-client (wallet-connect/session-request-event) #(re-frame/dispatch [:wallet-connect/request %])) @@ -209,7 +209,7 @@ (rf/defn wallet-connect-client-initate {:events [:wallet-connect/client-init]} - [{:keys [db] :as cofx} client] + [{:keys [db] :as cofx} ^js client] {:db (assoc db :wallet-connect/client client :wallet-connect/sessions (types/js->clj (.-values (.-session diff --git a/src/status_im/wallet_connect_legacy/core.cljs b/src/status_im/wallet_connect_legacy/core.cljs index ef3049ca0b..bdaf453b49 100644 --- a/src/status_im/wallet_connect_legacy/core.cljs +++ b/src/status_im/wallet_connect_legacy/core.cljs @@ -127,7 +127,7 @@ (fn [^js connectors] (log/debug "Kill wc sessions") (doseq [connector connectors] - (.killSession connector)))) + (.killSession ^js connector)))) (re-frame/reg-fx :wc-1-approve-request