From 53874c8343ef173a43a089916aaf4008f0c0fdf4 Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Thu, 28 Mar 2024 16:33:16 +0000 Subject: [PATCH] chore: rename alias of promesa to be more verbose (#19332) --- .clj-kondo/config.edn | 2 +- .../profile/expanded_collectible/view.cljs | 4 +- src/react_native/core.cljs | 12 ++-- src/status_im/common/log.cljs | 5 +- .../messenger/photo_selector/effects.cljs | 34 +++++----- .../actions/accounts_selection/effects.cljs | 24 +++---- src/test_helpers/integration.cljs | 68 +++++++++---------- src/tests/contract_test/profile_test.cljs | 4 +- src/tests/contract_test/utils.cljs | 4 +- .../wallet_recovered_account_test.cljs | 20 +++--- src/tests/contract_test/wallet_test.cljs | 40 +++++------ src/tests/integration_test/chat_test.cljs | 10 +-- src/tests/integration_test/profile_test.cljs | 10 +-- 13 files changed, 120 insertions(+), 117 deletions(-) diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn index cc5945d3aa..48b1188846 100644 --- a/.clj-kondo/config.edn +++ b/.clj-kondo/config.edn @@ -26,7 +26,7 @@ malli.generator malli.generator malli.transform malli.transform malli.util malli.util - promesa.core p + promesa.core promesa schema.core schema status-im.feature-flags ff taoensso.timbre log}} diff --git a/src/quo/components/profile/expanded_collectible/view.cljs b/src/quo/components/profile/expanded_collectible/view.cljs index 01c5e60cd6..308827ad23 100644 --- a/src/quo/components/profile/expanded_collectible/view.cljs +++ b/src/quo/components/profile/expanded_collectible/view.cljs @@ -1,6 +1,6 @@ (ns quo.components.profile.expanded-collectible.view (:require - [promesa.core :as p] + [promesa.core :as promesa] [quo.components.counter.collectible-counter.view :as collectible-counter] [quo.components.icon :as icon] [quo.components.markdown.text :as text] @@ -37,7 +37,7 @@ [image-size set-image-size] (rn/use-state {})] (rn/use-effect (fn [] - (p/let [[image-width image-height] (rn/image-get-size image-src)] + (promesa/let [[image-width image-height] (rn/image-get-size image-src)] (set-image-size {:width image-width :height image-height :aspect-ratio (/ image-width image-height)}))) diff --git a/src/react_native/core.cljs b/src/react_native/core.cljs index e1327f0e2f..5d434a3ee7 100644 --- a/src/react_native/core.cljs +++ b/src/react_native/core.cljs @@ -3,7 +3,7 @@ ["react" :as react] ["react-native" :as react-native] [oops.core :as oops] - [promesa.core :as p] + [promesa.core :as promesa] [react-native.flat-list :as flat-list] [react-native.platform :as platform] [react-native.section-list :as section-list] @@ -37,11 +37,11 @@ (defn image-get-size [uri] - (p/create (fn [res rej] - (.getSize ^js (.-Image ^js react-native) - uri - (fn [width height] (res [width height])) - rej)))) + (promesa/create (fn [res rej] + (.getSize ^js (.-Image ^js react-native) + uri + (fn [width height] (res [width height])) + rej)))) (def text (reagent/adapt-react-class (.-Text ^js react-native))) (def text-input (reagent/adapt-react-class (.-TextInput ^js react-native))) diff --git a/src/status_im/common/log.cljs b/src/status_im/common/log.cljs index 8489c764e7..109cfc9c7b 100644 --- a/src/status_im/common/log.cljs +++ b/src/status_im/common/log.cljs @@ -1,6 +1,6 @@ (ns status-im.common.log (:require - [clojure.pprint :as p] + [clojure.pprint :as promesa] [clojure.string :as string] [native-module.core :as native-module] [re-frame.core :as re-frame] @@ -43,7 +43,8 @@ :middleware [(fn [data] (update data :vargs - (partial mapv #(if (string? %) % (with-out-str (p/pprint %))))))]}) + (partial mapv + #(if (string? %) % (with-out-str (promesa/pprint %))))))]}) (native-module/init-status-go-logging logging-params))))) (re-frame/reg-fx diff --git a/src/status_im/contexts/chat/messenger/photo_selector/effects.cljs b/src/status_im/contexts/chat/messenger/photo_selector/effects.cljs index 2c5d2736de..7068b40d0b 100644 --- a/src/status_im/contexts/chat/messenger/photo_selector/effects.cljs +++ b/src/status_im/contexts/chat/messenger/photo_selector/effects.cljs @@ -1,7 +1,7 @@ (ns status-im.contexts.chat.messenger.photo-selector.effects (:require [clojure.string :as string] - [promesa.core :as p] + [promesa.core :as promesa] [react-native.cameraroll :as cameraroll] [react-native.core :as rn] [react-native.image-resizer :as image-resizer] @@ -31,19 +31,19 @@ (defn- resize-photo [uri] - (p/let [[width height] (rn/image-get-size uri) - resize? (> (max width height) - maximum-image-size-px) - resized-uri (-> (image-resizer/resize - {:max-width (if resize? maximum-image-size-px width) - :max-height (if resize? maximum-image-size-px height) - :path uri - :quality 60}) - (p/then (fn [^js resized-image] - (let [path (.-path resized-image)] - (if (string/starts-with? path "file") - path - (str "file://" path))))))] + (promesa/let [[width height] (rn/image-get-size uri) + resize? (> (max width height) + maximum-image-size-px) + resized-uri (-> (image-resizer/resize + {:max-width (if resize? maximum-image-size-px width) + :max-height (if resize? maximum-image-size-px height) + :path uri + :quality 60}) + (promesa/then (fn [^js resized-image] + (let [path (.-path resized-image)] + (if (string/starts-with? path "file") + path + (str "file://" path))))))] {:resized-uri resized-uri :width width :height height})) @@ -51,9 +51,9 @@ (rf/reg-fx :effects.camera-roll/image-selected (fn [[image chat-id]] (-> (resize-photo (:uri image)) - (p/then #(rf/dispatch - [:photo-selector/image-selected chat-id image %])) - (p/catch #(log/error "could not resize image" %))))) + (promesa/then #(rf/dispatch + [:photo-selector/image-selected chat-id image %])) + (promesa/catch #(log/error "could not resize image" %))))) (defn- get-albums [callback] diff --git a/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs b/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs index d92229ab93..1d153546a0 100644 --- a/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs +++ b/src/status_im/contexts/communities/actions/accounts_selection/effects.cljs @@ -1,13 +1,13 @@ (ns status-im.contexts.communities.actions.accounts-selection.effects (:require - [promesa.core :as p] + [promesa.core :as promesa] [schema.core :as schema] [status-im.common.json-rpc.events :as rpc] [utils.re-frame :as rf])) (defn- generate-requests-for-signing [pub-key community-id addresses-to-reveal] - (p/create + (promesa/create (fn [p-resolve p-reject] (rpc/call {:method :wakuext_generateJoiningCommunityRequestsForSigning @@ -17,7 +17,7 @@ (defn- sign-data [sign-params password] - (p/create + (promesa/create (fn [p-resolve p-reject] (rpc/call {:method :wakuext_signData @@ -27,7 +27,7 @@ (defn- edit-shared-addresses-for-community [community-id signatures addresses-to-reveal airdrop-address] - (p/create + (promesa/create (fn [p-resolve p-reject] (rpc/call {:method :wakuext_editSharedAddressesForCommunity @@ -41,7 +41,7 @@ (defn- request-to-join [community-id signatures addresses-to-reveal airdrop-address] - (p/create + (promesa/create (fn [p-resolve p-reject] (rpc/call {:method :wakuext_requestToJoinCommunity @@ -66,14 +66,14 @@ addresses-to-reveal airdrop-address on-success on-error callback]}] - (-> (p/let [sign-params (generate-requests-for-signing pub-key community-id addresses-to-reveal) - signatures (sign-data sign-params password) - result (callback community-id - signatures - addresses-to-reveal - airdrop-address)] + (-> (promesa/let [sign-params (generate-requests-for-signing pub-key community-id addresses-to-reveal) + signatures (sign-data sign-params password) + result (callback community-id + signatures + addresses-to-reveal + airdrop-address)] (run-callback-or-event on-success result)) - (p/catch #(run-callback-or-event on-error %)))) + (promesa/catch #(run-callback-or-event on-error %)))) (schema/=> sign-and-call-endpoint [:=> diff --git a/src/test_helpers/integration.cljs b/src/test_helpers/integration.cljs index 7cbabefce2..6f150c7e9f 100644 --- a/src/test_helpers/integration.cljs +++ b/src/test_helpers/integration.cljs @@ -5,7 +5,7 @@ [legacy.status-im.multiaccounts.logout.core :as logout] legacy.status-im.subs.root [native-module.core :as native-module] - [promesa.core :as p] + [promesa.core :as promesa] [re-frame.core :as rf] [re-frame.interop :as rf.interop] status-im.events @@ -20,7 +20,7 @@ (defn validate-mnemonic [mnemonic] - (p/create + (promesa/create (fn [p-resolve p-reject] (native-module/validate-mnemonic (security/safe-unmask-data mnemonic) @@ -111,7 +111,7 @@ (wait-for event-ids default-re-frame-wait-for-timeout-ms)) ([event-ids timeout-ms] (let [waiting-ids (atom event-ids)] - (p/create + (promesa/create (fn [promise-resolve promise-reject] (let [cb-id (gensym "post-event-callback") timer-id (js/setTimeout (fn [] @@ -148,18 +148,18 @@ [] (test-utils/init!) (if (app-initialized) - (p/resolved ::app-initialized) - (p/do! + (promesa/resolved ::app-initialized) + (promesa/do! (rf/dispatch [:app-started]) (wait-for [:profile/get-profiles-overview-success])))) (defn setup-account [] (if (messenger-started) - (p/resolved ::messenger-started) - (p/do! + (promesa/resolved ::messenger-started) + (promesa/do! (create-multiaccount!) - (p/then (wait-for [:profile.login/messenger-started]) #(assert-messenger-started))))) + (promesa/then (wait-for [:profile.login/messenger-started]) #(assert-messenger-started))))) (defn- recover-and-login [seed-phrase] @@ -176,8 +176,8 @@ (defn- recover-multiaccount! [] - (p/let [masked-seed-phrase (security/mask-data (:seed-phrase constants/recovery-account)) - [mnemonic key-uid] (validate-mnemonic masked-seed-phrase)] + (promesa/let [masked-seed-phrase (security/mask-data (:seed-phrase constants/recovery-account)) + [mnemonic key-uid] (validate-mnemonic masked-seed-phrase)] (rf/dispatch [:onboarding/seed-phrase-validated (security/mask-data mnemonic) key-uid]) (rf/dispatch [:pop-to-root :screen/profile.profiles]) (rf/dispatch [:profile/profile-selected key-uid]) @@ -186,12 +186,12 @@ (defn setup-recovered-account [] (if (messenger-started) - (p/resolved ::messenger-started) - (p/do! + (promesa/resolved ::messenger-started) + (promesa/do! (recover-multiaccount!) - (p/then (wait-for [:profile.login/messenger-started]) #(assert-messenger-started)) + (promesa/then (wait-for [:profile.login/messenger-started]) #(assert-messenger-started)) (enable-testnet!) - (p/then (wait-for [:wallet/store-wallet-token]) #(assert-wallet-loaded))))) + (promesa/then (wait-for [:wallet/store-wallet-token]) #(assert-wallet-loaded))))) (defn test-async "Runs `f` inside `cljs.test/async` macro in a restorable re-frame checkpoint. @@ -225,21 +225,21 @@ done (let [restore-fn (rf/make-restore-fn)] (log-headline test-name) - (-> (p/do (f done)) - (p/timeout timeout-ms) - (p/catch (fn [error] - (is (nil? error)) - (when fail-fast? - (js/process.exit 1)))) - (p/finally (fn [] - (restore-fn) - (done)))))))) + (-> (promesa/do (f done)) + (promesa/timeout timeout-ms) + (promesa/catch (fn [error] + (is (nil? error)) + (when fail-fast? + (js/process.exit 1)))) + (promesa/finally (fn [] + (restore-fn) + (done)))))))) (defn test-app-initialization [] (test-async ::initialize-app (fn [] - (p/do + (promesa/do (test-utils/init!) (rf/dispatch [:app-started]) ;; Use initialize-view because it has the longest avg. time and is @@ -252,7 +252,7 @@ [] (test-async ::create-account (fn [] - (p/do + (promesa/do (setup-app) (setup-account) (logout) @@ -271,19 +271,19 @@ {:before (if (= :recovered-account type) (fn [] (test/async done - (p/do (setup-app) - (setup-recovered-account) - (done)))) + (promesa/do (setup-app) + (setup-recovered-account) + (done)))) (fn [] (test/async done - (p/do (setup-app) - (setup-account) - (done))))) + (promesa/do (setup-app) + (setup-account) + (done))))) :after (fn [] (test/async done - (p/do (logout) - (wait-for [::logout/logout-method]) - (done))))}) + (promesa/do (logout) + (wait-for [::logout/logout-method]) + (done))))}) ([] (fixture-session [:new-account]))) (defn fixture-silence-reframe diff --git a/src/tests/contract_test/profile_test.cljs b/src/tests/contract_test/profile_test.cljs index 234fe2daf4..4a5832e461 100644 --- a/src/tests/contract_test/profile_test.cljs +++ b/src/tests/contract_test/profile_test.cljs @@ -3,7 +3,7 @@ [cljs.test :refer [deftest is use-fixtures]] legacy.status-im.events legacy.status-im.subs.root - [promesa.core :as p] + [promesa.core :as promesa] status-im.events status-im.navigation.core status-im.subs.root @@ -16,4 +16,4 @@ (h/test-async :contract/wakuext_setBio (fn [] (-> (contract-utils/call-rpc "wakuext_setBio" "new bio") - (p/catch #(is (nil? %) "Set bio RPC call should have succeeded")))))) + (promesa/catch #(is (nil? %) "Set bio RPC call should have succeeded")))))) diff --git a/src/tests/contract_test/utils.cljs b/src/tests/contract_test/utils.cljs index 71e13e4347..1ab9e055cf 100644 --- a/src/tests/contract_test/utils.cljs +++ b/src/tests/contract_test/utils.cljs @@ -1,12 +1,12 @@ (ns tests.contract-test.utils (:require - [promesa.core :as p] + [promesa.core :as promesa] [status-im.common.json-rpc.events :as rpc-events] [utils.number])) (defn call-rpc [method & args] - (p/create + (promesa/create (fn [p-resolve p-reject] (rpc-events/call {:method method :params args diff --git a/src/tests/contract_test/wallet_recovered_account_test.cljs b/src/tests/contract_test/wallet_recovered_account_test.cljs index d9324672bf..777fa313ca 100644 --- a/src/tests/contract_test/wallet_recovered_account_test.cljs +++ b/src/tests/contract_test/wallet_recovered_account_test.cljs @@ -4,7 +4,7 @@ legacy.status-im.events legacy.status-im.subs.root [native-module.core :as native-module] - [promesa.core :as p] + [promesa.core :as promesa] status-im.events status-im.navigation.core status-im.subs.root @@ -24,13 +24,13 @@ (deftest wallet-get-derived-addressess-contract-test (h/test-async :wallet/create-derived-addresses (fn [] - (p/let [sha3-pwd-hash (native-module/sha3 integration-constants/password) - derivation-path [integration-constants/derivation-path] - accounts (contract-utils/call-rpc "accounts_getAccounts") - default-address (contract-utils/get-default-address accounts) - response (contract-utils/call-rpc - "wallet_getDerivedAddresses" - sha3-pwd-hash - default-address - derivation-path)] + (promesa/let [sha3-pwd-hash (native-module/sha3 integration-constants/password) + derivation-path [integration-constants/derivation-path] + accounts (contract-utils/call-rpc "accounts_getAccounts") + default-address (contract-utils/get-default-address accounts) + response (contract-utils/call-rpc + "wallet_getDerivedAddresses" + sha3-pwd-hash + default-address + derivation-path)] (assert-derived-account response))))) diff --git a/src/tests/contract_test/wallet_test.cljs b/src/tests/contract_test/wallet_test.cljs index 3f45b03601..f0f397d943 100644 --- a/src/tests/contract_test/wallet_test.cljs +++ b/src/tests/contract_test/wallet_test.cljs @@ -3,7 +3,7 @@ [cljs.test :refer [deftest is use-fixtures]] legacy.status-im.events legacy.status-im.subs.root - [promesa.core :as p] + [promesa.core :as promesa] [status-im.common.emoji-picker.utils :as emoji-picker.utils] [status-im.constants :as constants] [status-im.contexts.wallet.data-store :as data-store] @@ -26,7 +26,7 @@ (deftest accounts-get-accounts-contract-test (h/test-async :contract/accounts-get-accounts (fn [] - (p/let [result (contract-utils/call-rpc "accounts_getAccounts")] + (promesa/let [result (contract-utils/call-rpc "accounts_getAccounts")] (assert-accounts-get-accounts result))))) (defn check-emoji-is-updated @@ -37,13 +37,13 @@ (deftest accounts-save-accounts-contract (h/test-async :contract/accounts-save-account (fn [] - (p/let [test-emoji (emoji-picker.utils/random-emoji) - account (contract-utils/call-rpc "accounts_getAccounts") - default-account (contract-utils/get-default-account account) - _ (contract-utils/call-rpc - "accounts_saveAccount" - (data-store/<-account (merge default-account {:emoji test-emoji}))) - accounts (contract-utils/call-rpc "accounts_getAccounts")] + (promesa/let [test-emoji (emoji-picker.utils/random-emoji) + account (contract-utils/call-rpc "accounts_getAccounts") + default-account (contract-utils/get-default-account account) + _ (contract-utils/call-rpc + "accounts_saveAccount" + (data-store/<-account (merge default-account {:emoji test-emoji}))) + accounts (contract-utils/call-rpc "accounts_getAccounts")] (check-emoji-is-updated test-emoji accounts))))) (defn assert-ethereum-chains @@ -59,7 +59,7 @@ (deftest accounts-get-chains-contract (h/test-async :contract/wallet_get-ethereum-chains (fn [] - (p/let [response (contract-utils/call-rpc "wallet_getEthereumChains")] + (promesa/let [response (contract-utils/call-rpc "wallet_getEthereumChains")] (assert-ethereum-chains response))))) (defn assert-wallet-tokens @@ -81,11 +81,11 @@ (deftest wallet-get-walet-token-test (h/test-async :wallet/get-wallet-token (fn [] - (p/let [accounts (contract-utils/call-rpc "accounts_getAccounts") - default-address (contract-utils/get-default-address accounts) - response (contract-utils/call-rpc - "wallet_getWalletToken" - [default-address])] + (promesa/let [accounts (contract-utils/call-rpc "accounts_getAccounts") + default-address (contract-utils/get-default-address accounts) + response (contract-utils/call-rpc + "wallet_getWalletToken" + [default-address])] (assert-wallet-tokens response))))) (defn assert-address-details @@ -98,8 +98,10 @@ (deftest wallet-get-address-details-contract-test (h/test-async :wallet/get-address-details (fn [] - (p/let [input "test.eth" - chain-id constants/ethereum-mainnet-chain-id - ens-address (contract-utils/call-rpc "ens_addressOf" chain-id input) - response (contract-utils/call-rpc "wallet_getAddressDetails" chain-id ens-address)] + (promesa/let [input "test.eth" + chain-id constants/ethereum-mainnet-chain-id + ens-address (contract-utils/call-rpc "ens_addressOf" chain-id input) + response (contract-utils/call-rpc "wallet_getAddressDetails" + chain-id + ens-address)] (assert-address-details response))))) diff --git a/src/tests/integration_test/chat_test.cljs b/src/tests/integration_test/chat_test.cljs index 7413652013..639f00498f 100644 --- a/src/tests/integration_test/chat_test.cljs +++ b/src/tests/integration_test/chat_test.cljs @@ -3,7 +3,7 @@ [cljs.test :refer [deftest is use-fixtures]] legacy.status-im.events legacy.status-im.subs.root - [promesa.core :as p] + [promesa.core :as promesa] [re-frame.core :as rf] [status-im.constants :as constants] status-im.events @@ -19,7 +19,7 @@ (deftest one-to-one-chat-test (h/test-async ::one-to-one-chat (fn [] - (p/do + (promesa/do (rf/dispatch-sync [:chat.ui/start-chat chat-id]) (h/wait-for [:chat/one-to-one-chat-created]) (rf/dispatch-sync [:chat/navigate-to-chat chat-id]) @@ -28,7 +28,7 @@ (deftest delete-chat-test (h/test-async ::delete-chat (fn [] - (p/do + (promesa/do (rf/dispatch-sync [:chat.ui/start-chat chat-id]) (h/wait-for [:chat/one-to-one-chat-created]) (rf/dispatch-sync [:chat/navigate-to-chat chat-id]) @@ -40,7 +40,7 @@ (deftest mute-chat-test (h/test-async ::mute-chat (fn [] - (p/do + (promesa/do (rf/dispatch-sync [:chat.ui/start-chat chat-id]) (h/wait-for [:chat/one-to-one-chat-created]) @@ -64,7 +64,7 @@ "ed2a86050325bc8856e26898c17e31dee2602b9429c91" "ecf65a41d62ac1f2f0823c0710dcb536e79af2763c") primary-name "zQ3...pFNErL"] - (p/do + (promesa/do ;; Search for contact using compressed key (rf/dispatch [:contacts/set-new-identity {:input compressed-key}]) (h/wait-for [:contacts/set-new-identity-success]) diff --git a/src/tests/integration_test/profile_test.cljs b/src/tests/integration_test/profile_test.cljs index 0d8fae6456..b15649275e 100644 --- a/src/tests/integration_test/profile_test.cljs +++ b/src/tests/integration_test/profile_test.cljs @@ -1,7 +1,7 @@ (ns tests.integration-test.profile-test (:require [cljs.test :refer [deftest is use-fixtures]] - [promesa.core :as p] + [promesa.core :as promesa] [status-im.contexts.profile.utils :as profile.utils] [test-helpers.integration :as h] [tests.test-utils :as test-utils] @@ -13,7 +13,7 @@ (h/test-async ::edit-profile-name (fn [] (let [new-name "John Doe"] - (p/do + (promesa/do (rf/dispatch [:profile/edit-name new-name]) (h/wait-for [:navigate-back :toasts/upsert]) (let [profile (rf/sub [:profile/profile]) @@ -25,7 +25,7 @@ (fn [] (let [mock-image "resources/images/mock2/monkey.png" absolute-path (.resolve test-utils/path mock-image)] - (p/do + (promesa/do (rf/dispatch [:profile/edit-picture absolute-path 80 80]) (h/wait-for [:profile/update-local-picture :toasts/upsert]) (let [profile (rf/sub [:profile/profile])] @@ -34,7 +34,7 @@ (deftest delete-profile-picture-test (h/test-async ::delete-profile-picture (fn [] - (p/do + (promesa/do (rf/dispatch [:profile/delete-picture]) (h/wait-for [:profile/update-local-picture :toasts/upsert]) (let [profile (rf/sub [:profile/profile])] @@ -44,7 +44,7 @@ (h/test-async ::edit-profile-bio (fn [] (let [new-bio "New bio text"] - (p/do + (promesa/do (rf/dispatch [:profile/edit-bio new-bio]) (h/wait-for [:navigate-back :toasts/upsert]) (let [profile (rf/sub [:profile/profile])