diff --git a/src/legacy/status_im/browser/core.cljs b/src/legacy/status_im/browser/core.cljs index 53f0de22ec..b17e8c89c8 100644 --- a/src/legacy/status_im/browser/core.cljs +++ b/src/legacy/status_im/browser/core.cljs @@ -15,6 +15,7 @@ [native-module.core :as native-module] [re-frame.core :as re-frame] [react-native.platform :as platform] + [status-im.common.json-rpc.events :as json-rpc] [status-im.common.universal-links :as links] [status-im.constants :as constants] [status-im.contexts.chat.events :as chat.events] @@ -654,12 +655,11 @@ stored-bookmarks)] {:db (assoc db :bookmarks/bookmarks bookmarks)})) -(rf/defn initialize-browser - [_] - {:json-rpc/call - [{:method "wakuext_getBrowsers" - :on-success #(re-frame/dispatch [::initialize-browsers %])} - {:method "browsers_getBookmarks" - :on-success #(re-frame/dispatch [::initialize-bookmarks %])} - {:method "permissions_getDappPermissions" - :on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]}) +(re-frame/reg-fx :browser/initialize-browser + (fn [] + (json-rpc/call {:method "wakuext_getBrowsers" + :on-success [::initialize-browsers]}) + (json-rpc/call {:method "browsers_getBookmarks" + :on-success [::initialize-bookmarks]}) + (json-rpc/call {:method "permissions_getDappPermissions" + :on-success [::initialize-dapp-permissions]}))) diff --git a/src/legacy/status_im/communities/core.cljs b/src/legacy/status_im/communities/core.cljs index 24c69dac6e..1cd710bdbb 100644 --- a/src/legacy/status_im/communities/core.cljs +++ b/src/legacy/status_im/communities/core.cljs @@ -4,7 +4,6 @@ [legacy.status-im.bottom-sheet.events :as bottom-sheet] legacy.status-im.communities.e2e [re-frame.core :as re-frame] - [status-im.contexts.shell.activity-center.events :as activity-center] [status-im.navigation.events :as navigation] [taoensso.timbre :as log] [utils.re-frame :as rf])) @@ -84,13 +83,12 @@ (navigation/navigate-back) (handle-response response-js))) -(rf/defn member-banned - {:events [::member-banned]} - [cofx response-js] - (rf/merge cofx - (bottom-sheet/hide-bottom-sheet-old) - (handle-response response-js) - (activity-center/notifications-fetch-unread-count))) +(re-frame/reg-event-fx ::member-banned + (fn [{:keys [db]} [response-js]] + {:db (assoc db :bottom-sheet/show? false) + :fx [[:dismiss-bottom-sheet-overlay-old] + [:sanitize-messages-and-process-response response-js] + [:activity-center.notifications/fetch-unread-count]]})) (rf/defn member-ban {:events [::member-ban]} diff --git a/src/legacy/status_im/contact/block.cljs b/src/legacy/status_im/contact/block.cljs index 7b130377cf..ba8479b72a 100644 --- a/src/legacy/status_im/contact/block.cljs +++ b/src/legacy/status_im/contact/block.cljs @@ -6,7 +6,6 @@ [re-frame.core :as re-frame] [status-im.contexts.chat.contacts.events :as contacts-store] [status-im.contexts.chat.messenger.messages.list.events :as message-list] - [status-im.contexts.shell.activity-center.events :as activity-center] [status-im.navigation.events :as navigation] [utils.re-frame :as rf])) @@ -45,16 +44,16 @@ (apply rf/merge cofx - {:db (-> - db - (update :chats dissoc public-key) - (update :chats-home-list disj public-key) - (assoc-in [:contacts/contacts public-key - :added?] - false)) - :dispatch [:shell/close-switcher-card public-key] - :effects/push-notifications-clear-message-notifications [public-key]} - (activity-center/notifications-fetch-unread-count) + {:db (-> + db + (update :chats dissoc public-key) + (update :chats-home-list disj public-key) + (assoc-in [:contacts/contacts public-key + :added?] + false)) + :fx [[:activity-center.notifications/fetch-unread-count] + [:effects/push-notifications-clear-message-notifications [public-key]] + [:dispatch [:shell/close-switcher-card public-key]]]} fxs))) (rf/defn block-contact diff --git a/src/legacy/status_im/data_store/chats.cljs b/src/legacy/status_im/data_store/chats.cljs index b422c4c249..79f59d66da 100644 --- a/src/legacy/status_im/data_store/chats.cljs +++ b/src/legacy/status_im/data_store/chats.cljs @@ -3,9 +3,10 @@ [clojure.set :as set] [legacy.status-im.data-store.messages :as messages] [legacy.status-im.utils.deprecated-types :as types] + [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.constants :as constants] - [taoensso.timbre :as log] - [utils.re-frame :as rf])) + [taoensso.timbre :as log])) (defn rpc->type [{:keys [chat-type name] :as chat}] @@ -117,10 +118,10 @@ rpc->type unmarshal-members)) -(rf/defn fetch-chats-preview - [_ {:keys [on-success]}] - {:json-rpc/call [{:method "wakuext_chatsPreview" - :params [] - :js-response true - :on-success #(on-success ^js %) - :on-error #(log/error "failed to fetch chats" 0 -1 %)}]}) +(re-frame/reg-fx :fetch-chats-preview + (fn [{:keys [on-success]}] + (json-rpc/call {:method "wakuext_chatsPreview" + :params [] + :js-response true + :on-success #(on-success ^js %) + :on-error #(log/error "failed to fetch chats" 0 -1 %)}))) diff --git a/src/legacy/status_im/data_store/switcher_cards.cljs b/src/legacy/status_im/data_store/switcher_cards.cljs index 61c89fa376..7d2f2221f4 100644 --- a/src/legacy/status_im/data_store/switcher_cards.cljs +++ b/src/legacy/status_im/data_store/switcher_cards.cljs @@ -2,6 +2,8 @@ (:require [clojure.set :as set] [clojure.walk :as walk] + [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [taoensso.timbre :as log] [utils.re-frame :as rf])) @@ -32,11 +34,11 @@ :on-success #() :on-error #()}]}) -(rf/defn fetch-switcher-cards-rpc - [_] - {:json-rpc/call [{:method "wakuext_switcherCards" - :params [] - :on-success #(rf/dispatch - [:shell/switcher-cards-loaded - (:switcherCards ^js %)]) - :on-error #(log/error "Failed to fetch switcher cards" %)}]}) +(re-frame/reg-fx :switcher-cards/fetch + (fn [] + (json-rpc/call {:method "wakuext_switcherCards" + :params [] + :on-success #(rf/dispatch + [:shell/switcher-cards-loaded + (:switcherCards ^js %)]) + :on-error #(log/error "Failed to fetch switcher cards" %)}))) diff --git a/src/legacy/status_im/data_store/visibility_status_updates.cljs b/src/legacy/status_im/data_store/visibility_status_updates.cljs index 0a4f2ad6f2..e537664c97 100644 --- a/src/legacy/status_im/data_store/visibility_status_updates.cljs +++ b/src/legacy/status_im/data_store/visibility_status_updates.cljs @@ -2,8 +2,8 @@ (:require [clojure.set :as set] [re-frame.core :as re-frame] - [taoensso.timbre :as log] - [utils.re-frame :as rf])) + [status-im.common.json-rpc.events :as json-rpc] + [taoensso.timbre :as log])) (defn <-rpc [visibility-status-update] @@ -18,13 +18,13 @@ {:current-user-status :current-user-visibility-status}) (update :current-user-visibility-status <-rpc))) -(rf/defn fetch-visibility-status-updates-rpc - [_] - {:json-rpc/call [{:method "wakuext_statusUpdates" - :params [] - :on-success #(re-frame/dispatch - [:visibility-status-updates/visibility-status-updates-loaded - (:statusUpdates ^js %)]) - :on-error #(log/error - "failed to fetch visibility-status-updates" - %)}]}) +(re-frame/reg-fx :visibility-status-updates/fetch + (fn [] + (json-rpc/call {:method "wakuext_statusUpdates" + :params [] + :on-success #(re-frame/dispatch + [:visibility-status-updates/visibility-status-updates-loaded + (:statusUpdates ^js %)]) + :on-error #(log/error + "failed to fetch visibility-status-updates" + %)}))) diff --git a/src/legacy/status_im/ethereum/transactions/core.cljs b/src/legacy/status_im/ethereum/transactions/core.cljs index 7fe7018bde..631fc44f8a 100644 --- a/src/legacy/status_im/ethereum/transactions/core.cljs +++ b/src/legacy/status_im/ethereum/transactions/core.cljs @@ -239,7 +239,7 @@ (rf/defn tx-history-end-reached [{:keys [db] :as cofx} address] - (let [syncing-allowed? (utils.mobile-sync/syncing-allowed? cofx)] + (let [syncing-allowed? (utils.mobile-sync/syncing-allowed? db)] {:db (assoc-in db [:wallet-legacy :fetching address :all-fetched?] (if syncing-allowed? @@ -327,7 +327,7 @@ {:chain-tokens (:wallet-legacy/all-tokens db) :addresses [address] :before-block min-known-block - :fetch-more? (utils.mobile-sync/syncing-allowed? cofx) + :fetch-more? (utils.mobile-sync/syncing-allowed? db) ;; Transfers are requested before and including `min-known-block` because there is no ;; guarantee that all transfers from that block are shown already. To make sure that we fetch ;; the whole `default-transfers-limit` of transfers the number of transfers already received diff --git a/src/legacy/status_im/events.cljs b/src/legacy/status_im/events.cljs index cff8a9a4a8..7d993ce830 100644 --- a/src/legacy/status_im/events.cljs +++ b/src/legacy/status_im/events.cljs @@ -8,11 +8,16 @@ legacy.status-im.chat.models.loading legacy.status-im.contact.block legacy.status-im.currency.core + legacy.status-im.data-store.chats + legacy.status-im.data-store.switcher-cards + legacy.status-im.data-store.visibility-status-updates legacy.status-im.fleet.core + legacy.status-im.group-chats.core [legacy.status-im.keycard.core :as keycard] legacy.status-im.log-level.core legacy.status-im.mailserver.constants [legacy.status-im.mailserver.core :as mailserver] + legacy.status-im.mobile-sync-settings.core legacy.status-im.multiaccounts.login.core legacy.status-im.multiaccounts.logout.core [legacy.status-im.multiaccounts.model :as multiaccounts.model] diff --git a/src/legacy/status_im/group_chats/core.cljs b/src/legacy/status_im/group_chats/core.cljs index 6387f6e794..20002d7272 100644 --- a/src/legacy/status_im/group_chats/core.cljs +++ b/src/legacy/status_im/group_chats/core.cljs @@ -6,9 +6,9 @@ [legacy.status-im.data-store.invitations :as data-store.invitations] [oops.core :as oops] [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.constants :as constants] [status-im.contexts.chat.events :as chat.events] - [status-im.contexts.shell.activity-center.events :as activity-center] [status-im.navigation.events :as navigation] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -19,15 +19,13 @@ (when (get-in cofx [:db :chats chat-id]) (chat.events/pop-to-root-and-navigate-to-chat cofx chat-id nil))) -(rf/defn handle-chat-removed - {:events [:chat-removed]} - [cofx response chat-id] - (rf/merge cofx - {:db (dissoc (:db cofx) :current-chat-id) - :dispatch-n [[:shell/close-switcher-card chat-id] - [:sanitize-messages-and-process-response response] - [:pop-to-root :shell-stack]]} - (activity-center/notifications-fetch-unread-count))) +(re-frame/reg-event-fx :chat-removed + (fn [{:keys [db]} [response chat-id]] + {:db (dissoc db :current-chat-id) + :fx [[:dispatch [:shell/close-switcher-card chat-id]] + [:dispatch [:sanitize-messages-and-process-response response]] + [:dispatch [:pop-to-root :shell-stack]] + [:activity-center.notifications/fetch-unread-count]]})) (rf/defn handle-chat-update {:events [:chat-updated]} @@ -264,8 +262,7 @@ {} invitations))}) -(rf/defn get-group-chat-invitations - [_] - {:json-rpc/call - [{:method "wakuext_getGroupChatInvitations" - :on-success #(re-frame/dispatch [::initialize-invitations %])}]}) +(re-frame/reg-fx :group-chats/get-group-chat-invitations + (fn [] + (json-rpc/call {:method "wakuext_getGroupChatInvitations" + :on-success [::initialize-invitations]}))) diff --git a/src/legacy/status_im/mailserver/core.cljs b/src/legacy/status_im/mailserver/core.cljs index 11e006d963..d7f721e976 100644 --- a/src/legacy/status_im/mailserver/core.cljs +++ b/src/legacy/status_im/mailserver/core.cljs @@ -5,6 +5,7 @@ [legacy.status-im.node.core :as node] [legacy.status-im.utils.mobile-sync :as mobile-network-utils] [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.navigation.events :as navigation] [taoensso.timbre :as log] [utils.i18n :as i18n] @@ -61,7 +62,7 @@ (dissoc :mailserver/current-request :mailserver/fetching-gaps-in-progress))}) (defn fetch-use-mailservers? - [{:keys [db]}] + [db] (get-in db [:profile/profile :use-mailservers?])) (defonce showing-connection-error-popup? (atom false)) @@ -117,24 +118,32 @@ [{:keys [db] :as cofx}] {:db (dissoc db :mailserver/current-request)}) +(defn needs-to-fetch-historic-messages? + [db] + (and + (:messenger/started? db) + (mobile-network-utils/syncing-allowed? db) + (fetch-use-mailservers? db) + (not (:mailserver/current-request db)))) + (rf/defn process-next-messages-request {:events [::request-messages]} - [{:keys [db now] :as cofx}] - (when (and - (:messenger/started? db) - (mobile-network-utils/syncing-allowed? cofx) - (fetch-use-mailservers? cofx) - (not (:mailserver/current-request db))) - {:db (assoc db :mailserver/current-request true) - :json-rpc/call [{:method "wakuext_requestAllHistoricMessagesWithRetries" - :params [false] - :js-response true - :on-success #(do - (log/info "fetched historical messages") - (re-frame/dispatch [::request-success %])) - :on-error #(do - (log/error "failed retrieve historical messages" %) - (re-frame/dispatch [::request-error]))}]})) + [{:keys [db]}] + (when (needs-to-fetch-historic-messages? db) + {:db (assoc db :mailserver/current-request true) + :mailserver/request-all-historic-messages nil})) + +(re-frame/reg-fx :mailserver/request-all-historic-messages + (fn [] + (json-rpc/call {:method "wakuext_requestAllHistoricMessagesWithRetries" + :params [false] + :js-response true + :on-success #(do + (log/info "fetched historical messages") + (re-frame/dispatch [::request-success %])) + :on-error #(do + (log/error "failed retrieve historical messages" %) + (re-frame/dispatch [::request-error]))}))) (rf/defn handle-mailserver-changed [{:keys [db] :as cofx} ms] diff --git a/src/legacy/status_im/mobile_sync_settings/core.cljs b/src/legacy/status_im/mobile_sync_settings/core.cljs index ab0e88f5b1..dfb7faeb13 100644 --- a/src/legacy/status_im/mobile_sync_settings/core.cljs +++ b/src/legacy/status_im/mobile_sync_settings/core.cljs @@ -5,7 +5,7 @@ [legacy.status-im.multiaccounts.model :as multiaccounts.model] [legacy.status-im.multiaccounts.update.core :as multiaccounts.update] [legacy.status-im.utils.mobile-sync :as utils] - [status-im.contexts.chat.home.add-new-contact.events :as add-new-contact] + [re-frame.core :as re-frame] [status-im.navigation.events :as navigation] [taoensso.timbre :as log] [utils.re-frame :as rf])) @@ -18,27 +18,24 @@ (or (nil? remember-choice?) remember-choice?))})) -(rf/defn on-network-status-change - [{:keys [db] :as cofx}] - (let [initialized? (get db :network-status/initialized?) - logged-in? (multiaccounts.model/logged-in? db) - {:keys [remember-syncing-choice?]} (:profile/profile db)] - (apply - rf/merge - cofx - {:db (assoc db :network-status/initialized? true)} - (cond - ;; NOTE(rasom): When we log into account on-network-status-change is - ;; dispatched, but that doesn't mean there was a status change, thus - ;; no reason to restart wallet. - (and logged-in? initialized?) - [(mailserver/process-next-messages-request) - (bottom-sheet/hide-bottom-sheet-old) - #(add-new-contact/set-new-identity-reconnected %)] - - logged-in? - [(mailserver/process-next-messages-request) - (bottom-sheet/hide-bottom-sheet-old)])))) +(re-frame/reg-event-fx :mobile-network/on-network-status-change + (fn [{:keys [db]}] + (let [previously-initialized? (get db :network-status/initialized?) + logged-in? (multiaccounts.model/logged-in? db) + fetch-historic-messages? (mailserver/needs-to-fetch-historic-messages? db)] + (if logged-in? + {:db (cond-> (-> db + (assoc :network-status/initialized? true) + (assoc :bottom-sheet/show? false)) + fetch-historic-messages? + (assoc :mailserver/current-request true)) + :fx [(when fetch-historic-messages? + [:mailserver/request-all-historic-messages]) + [:dismiss-bottom-sheet-overlay-old] + (when previously-initialized? + (let [new-identity-input (get-in db [:contacts/new-identity :input])] + [:dispatch [:contacts/set-new-identity {:input new-identity-input}]]))]} + {:db (assoc db :network-status/initialized? true)})))) (defn apply-settings ([sync?] (apply-settings sync? :default)) diff --git a/src/legacy/status_im/network/net_info.cljs b/src/legacy/status_im/network/net_info.cljs index 6c85cf04d7..6c78b23485 100644 --- a/src/legacy/status_im/network/net_info.cljs +++ b/src/legacy/status_im/network/net_info.cljs @@ -1,7 +1,6 @@ (ns legacy.status-im.network.net-info (:require ["@react-native-community/netinfo" :default net-info] - [legacy.status-im.mobile-sync-settings.core :as mobile-network] [native-module.core :as native-module] [re-frame.core :as re-frame] [taoensso.timbre :as log] @@ -13,11 +12,11 @@ {:db (assoc db :network-status (if is-connected? :online :offline))})) (rf/defn change-network-type - [{:keys [db] :as cofx} old-network-type network-type expensive?] + [{:keys [db] :as cofx} network-type expensive?] (rf/merge cofx {:db (assoc db :network/type network-type) - :network/notify-status-go [network-type expensive?]} - (mobile-network/on-network-status-change))) + :network/notify-status-go [network-type expensive?] + :dispatch [:mobile-network/on-network-status-change]})) (rf/defn handle-network-info-change {:events [::network-info-changed]} @@ -37,7 +36,7 @@ (when-not status-changed? (change-network-status isConnected)) (when-not type-changed? - (change-network-type old-network-type type (:is-connection-expensive details)))))) + (change-network-type type (:is-connection-expensive details)))))) (defn add-net-info-listener [] diff --git a/src/legacy/status_im/stickers/core.cljs b/src/legacy/status_im/stickers/core.cljs index ed1f67bae4..c6f7ae54fa 100644 --- a/src/legacy/status_im/stickers/core.cljs +++ b/src/legacy/status_im/stickers/core.cljs @@ -2,6 +2,7 @@ (:require [legacy.status-im.utils.utils :as utils] [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.constants :as constants] [utils.ethereum.chain :as chain] [utils.re-frame :as rf])) @@ -22,6 +23,21 @@ :params [(chain/chain-id db) id] :on-success #()}]})) +(re-frame/reg-fx :stickers/load-packs + (fn [chain-id] + (json-rpc/call {:method "stickers_market" + :params [chain-id] + :on-success [:stickers/stickers-market-success]}) + (json-rpc/call {:method "stickers_installed" + :params [] + :on-success [:stickers/stickers-installed-success]}) + (json-rpc/call {:method "stickers_pending" + :params [] + :on-success [:stickers/stickers-pending-success]}) + (json-rpc/call {:method "stickers_recent" + :params [] + :on-success [:stickers/stickers-recent-success]}))) + (rf/defn load-packs {:events [:stickers/load-packs]} [{:keys [db]}] diff --git a/src/legacy/status_im/subs/mailservers.cljs b/src/legacy/status_im/subs/mailservers.cljs index 33251ae5d4..a796e1b3c7 100644 --- a/src/legacy/status_im/subs/mailservers.cljs +++ b/src/legacy/status_im/subs/mailservers.cljs @@ -61,7 +61,7 @@ (re-frame/reg-sub :mailserver/use-status-nodes? (fn [db _] - (boolean (mailserver/fetch-use-mailservers? {:db db})))) + (boolean (mailserver/fetch-use-mailservers? db)))) (re-frame/reg-sub :mailserver.edit/validation-errors diff --git a/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs b/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs index 4b2819f334..02df232fb6 100644 --- a/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs +++ b/src/legacy/status_im/ui/screens/default_sync_period_settings/view.cljs @@ -21,7 +21,7 @@ {:active (= value id) :accessory :radio :title (get titles id) - :on-press #(re-frame/dispatch [:profile.settings/update-value :default-sync-period id])}]) + :on-press #(re-frame/dispatch [:profile.settings/profile-update :default-sync-period id])}]) (views/defview default-sync-period-settings [] diff --git a/src/legacy/status_im/ui/screens/privacy_and_security_settings/views.cljs b/src/legacy/status_im/ui/screens/privacy_and_security_settings/views.cljs index d5af3fb316..da555a1706 100644 --- a/src/legacy/status_im/ui/screens/privacy_and_security_settings/views.cljs +++ b/src/legacy/status_im/ui/screens/privacy_and_security_settings/views.cljs @@ -111,7 +111,7 @@ :subtitle (i18n/label :t/webview-camera-permission-requests-subtitle) :subtitle-max-lines 2 :on-press #(re-frame/dispatch - [:profile.settings/update-value + [:profile.settings/profile-update :webview-allow-permission-requests? ((complement boolean) webview-allow-permission-requests?)])}]) [separator] @@ -169,8 +169,7 @@ {:active (= value id) :accessory :radio :title (get titles id) - :on-press #(re-frame/dispatch [:profile.settings/update-value :profile-pictures-visibility - id])}]) + :on-press #(re-frame/dispatch [:profile.settings/profile-update :profile-pictures-visibility id])}]) (views/defview profile-pic [] diff --git a/src/legacy/status_im/ui/screens/profile/user/edit_picture.cljs b/src/legacy/status_im/ui/screens/profile/user/edit_picture.cljs index 3605a02be3..500aacb826 100644 --- a/src/legacy/status_im/ui/screens/profile/user/edit_picture.cljs +++ b/src/legacy/status_im/ui/screens/profile/user/edit_picture.cljs @@ -51,4 +51,4 @@ :icon :main-icons/delete :theme :accent :title (i18n/label :t/profile-pic-remove) - :on-press #(re-frame/dispatch [:profile.settings/delete-profile-picture nil])}])])) + :on-press #(re-frame/dispatch [:profile.settings/delete-profile-picture])}])])) diff --git a/src/legacy/status_im/utils/logging/core.cljs b/src/legacy/status_im/utils/logging/core.cljs index 4ee13a662b..105a8d24b3 100644 --- a/src/legacy/status_im/utils/logging/core.cljs +++ b/src/legacy/status_im/utils/logging/core.cljs @@ -10,6 +10,7 @@ [re-frame.core :as re-frame] [react-native.mail :as react-native-mail] [react-native.platform :as platform] + [status-im.common.json-rpc.events :as json-rpc] [status-im.common.log :as log] [status-im.config :as config] [utils.datetime :as datetime] @@ -31,11 +32,10 @@ [{:keys [db]} node-version] {:db (assoc db :web3-node-version node-version)}) -(rf/defn initialize-web3-client-version - {:events [:logging/initialize-web3-client-version]} - [_] - {:json-rpc/call [{:method "web3_clientVersion" - :on-success #(re-frame/dispatch [:logging/store-web3-client-version %])}]}) +(re-frame/reg-fx :logging/initialize-web3-client-version + (fn [] + (json-rpc/call {:method "web3_clientVersion" + :on-success [:logging/store-web3-client-version]}))) (defn extract-url-components [address] diff --git a/src/legacy/status_im/utils/mobile_sync.cljs b/src/legacy/status_im/utils/mobile_sync.cljs index 18e6f13ac2..2a4cfc89a0 100644 --- a/src/legacy/status_im/utils/mobile_sync.cljs +++ b/src/legacy/status_im/utils/mobile_sync.cljs @@ -5,7 +5,7 @@ (= network-type "cellular")) (defn syncing-allowed? - [{:keys [db]}] + [db] (let [network (:network/type db) {:keys [syncing-on-mobile-network?]} (:profile/profile db)] (or (= network "wifi") diff --git a/src/status_im/common/log.cljs b/src/status_im/common/log.cljs index 29e620a7a4..8489c764e7 100644 --- a/src/status_im/common/log.cljs +++ b/src/status_im/common/log.cljs @@ -4,9 +4,7 @@ [clojure.string :as string] [native-module.core :as native-module] [re-frame.core :as re-frame] - [status-im.config :as config] [taoensso.timbre :as log] - [utils.re-frame :as rf] [utils.transforms :as transforms])) (def logs-queue (atom #queue [])) @@ -52,9 +50,3 @@ :logs/set-level (fn [level] (setup level))) - -(rf/defn set-log-level - [{:keys [db]} log-level] - (let [log-level (or log-level config/log-level)] - {:db (assoc-in db [:profile/profile :log-level] log-level) - :logs/set-level log-level})) diff --git a/src/status_im/common/signals/events.cljs b/src/status_im/common/signals/events.cljs index 66e3f05499..3f1f3b9bf7 100644 --- a/src/status_im/common/signals/events.cljs +++ b/src/status_im/common/signals/events.cljs @@ -7,7 +7,6 @@ [status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview] [status-im.contexts.chat.messenger.messages.transport.events :as messages.transport] [status-im.contexts.communities.discover.events] - [status-im.contexts.profile.login.events :as profile.login] [status-im.contexts.profile.push-notifications.local.events :as local-notifications] [taoensso.timbre :as log] [utils.re-frame :as rf] @@ -37,7 +36,9 @@ ^js event-js (.-event data) type (.-type data)] (case type - "node.login" (profile.login/login-node-signal cofx (transforms/js->clj event-js)) + "node.login" {:fx [[:dispatch + [:profile.login/login-node-signal + (transforms/js->clj event-js)]]]} "backup.performed" {:db (assoc-in db [:profile/profile :last-backup] (.-lastBackup event-js))} diff --git a/src/status_im/contexts/chat/contacts/events.cljs b/src/status_im/contexts/chat/contacts/events.cljs index d050b7ee58..5048db9a17 100644 --- a/src/status_im/contexts/chat/contacts/events.cljs +++ b/src/status_im/contexts/chat/contacts/events.cljs @@ -1,6 +1,8 @@ (ns status-im.contexts.chat.contacts.events (:require [oops.core :as oops] + [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.constants :as constants] [taoensso.timbre :as log] [utils.i18n :as i18n] @@ -64,18 +66,21 @@ (when (> (count events) 1) {:dispatch-n events})))) -(rf/defn initialize-contacts - [_] - {:json-rpc/call [{:method "wakuext_contacts" - :params [] - :js-response true - :on-success #(rf/dispatch [:contacts/contacts-loaded (map <-rpc-js %)]) - :on-error #(log/error "failed to fetch contacts" %)}]}) +(re-frame/reg-event-fx :contacts/contacts-loaded + (fn [{:keys [db]} [loaded-contacts]] + (let [contacts (->> loaded-contacts + (map <-rpc-js) + (mapv (fn [{:keys [public-key] :as contact}] [public-key contact])) + (into {}))] + {:db (assoc db :contacts/contacts contacts)}))) -(rf/defn contacts-loaded - {:events [:contacts/contacts-loaded]} - [{:keys [db]} contacts] - {:db (assoc db :contacts/contacts (into {} (map #(vector (:public-key %) %) contacts)))}) +(re-frame/reg-fx :contacts/initialize-contacts + (fn [] + (json-rpc/call {:method "wakuext_contacts" + :params [] + :js-response true + :on-success [:contacts/contacts-loaded] + :on-error #(log/error "failed to fetch contacts" %)}))) (defn send-contact-request [{:keys [db]} [id message]] diff --git a/src/status_im/contexts/chat/home/add_new_contact/events.cljs b/src/status_im/contexts/chat/home/add_new_contact/events.cljs index dca1add368..043d7153ee 100644 --- a/src/status_im/contexts/chat/home/add_new_contact/events.cljs +++ b/src/status_im/contexts/chat/home/add_new_contact/events.cljs @@ -186,9 +186,3 @@ {:db (dissoc db :contacts/new-identity)}) (re-frame/reg-event-fx :contacts/clear-new-identity clear-new-identity) - -(defn set-new-identity-reconnected - [{:keys [db]}] - (let [input (get-in db [:contacts/new-identity :input])] - (re-frame/dispatch [:contacts/set-new-identity {:input input}]))) - diff --git a/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs b/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs index 894c4f6e29..fbf7b60986 100644 --- a/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs +++ b/src/status_im/contexts/chat/messenger/messages/link_preview/events.cljs @@ -1,79 +1,65 @@ (ns status-im.contexts.chat.messenger.messages.link-preview.events - (:require - [camel-snake-kebab.core :as csk] - [status-im.contexts.profile.settings.events :as profile.settings.events] - [taoensso.timbre :as log] - [utils.collection] - [utils.re-frame :as rf])) + (:require [camel-snake-kebab.core :as csk] + [status-im.common.json-rpc.events :as json-rpc] + [taoensso.timbre :as log] + [utils.collection] + [utils.re-frame :as rf])) (defn community-link [id] (str "https://status.app/c#" id)) -(rf/defn cache-link-preview-data - {:events [:chat.ui/cache-link-preview-data]} - [{{:profile/keys [profile]} :db :as cofx} site data] - (let [link-previews-cache (get profile :link-previews-cache {})] - (profile.settings.events/optimistic-profile-update - cofx - :link-previews-cache - (assoc link-previews-cache site (utils.collection/map-keys csk/->kebab-case-keyword data))))) +(rf/reg-event-fx :chat.ui/cache-link-preview-data + (fn [{:keys [db]} [site data]] + (let [{:profile/keys [profile]} db + link-previews-cache (-> profile + (get :link-previews-cache {}) + (assoc site + (utils.collection/map-keys csk/->kebab-case-keyword + data)))] + {:db (assoc-in db [:profile/profile :link-previews-cache] link-previews-cache)}))) -(rf/defn load-link-preview-data - {:events [:chat.ui/load-link-preview-data]} - [{{:profile/keys [profile] :as db} :db} link] - (let [{:keys [error] :as cache-data} (get-in profile [:link-previews-cache link])] - (if (or (not cache-data) error) - {:json-rpc/call [{:method "wakuext_getLinkPreviewData" - :params [link] - :on-success #(rf/dispatch [:chat.ui/cache-link-preview-data link %]) - :on-error #(rf/dispatch [:chat.ui/cache-link-preview-data link - {:error (str "Can't get preview data for " link)}])}]} - {:db db}))) +(rf/reg-event-fx :chat.ui/load-link-preview-data + (fn [{{:profile/keys [profile]} :db} [link]] + (let [{:keys [error] :as cache-data} (get-in profile [:link-previews-cache link])] + (when (or (not cache-data) error) + {:fx [[:json-rpc/call + [{:method "wakuext_getLinkPreviewData" + :params [link] + :on-success [:chat.ui/cache-link-preview-data link] + :on-error [:chat.ui/cache-link-preview-data link + {:error (str "Can't get preview data for " link)}]}]]]})))) -(rf/defn should-suggest-link-preview - {:events [:chat.ui/should-suggest-link-preview]} - [{:keys [db] :as cofx} enabled?] - (profile.settings.events/profile-update - cofx - :link-preview-request-enabled - (boolean enabled?) - {})) +(rf/reg-event-fx :chat.ui/should-suggest-link-preview + (fn [_ [enabled?]] + {:fx [[:dispatch + [:profile.settings/profile-update :link-preview-request-enabled (boolean enabled?)]]]})) -(rf/defn save-link-preview-whitelist - {:events [:chat.ui/link-preview-whitelist-received]} - [{:keys [db]} whitelist] - {:db (assoc db :link-previews-whitelist whitelist)}) +(rf/reg-event-fx :chat.ui/link-preview-whitelist-received + (fn [{:keys [db]} [whitelist]] + {:db (assoc db :link-previews-whitelist whitelist)})) -(rf/defn request-link-preview-whitelist - [_] - {:json-rpc/call [{:method "wakuext_getLinkPreviewWhitelist" - :params [] - :on-success #(rf/dispatch [:chat.ui/link-preview-whitelist-received %]) - :on-error #(log/error "Failed to get link preview whitelist")}]}) +(rf/reg-fx :chat.ui/request-link-preview-whitelist + (fn [] + (json-rpc/call {:method "wakuext_getLinkPreviewWhitelist" + :params [] + :on-success [:chat.ui/link-preview-whitelist-received] + :on-error #(log/error "Failed to get link preview whitelist")}))) (defn cache-community-preview-data [{:keys [id] :as community}] (rf/dispatch [:chat.ui/cache-link-preview-data (community-link id) community])) -(rf/defn enable - {:events [:chat.ui/enable-link-previews]} - [{{:profile/keys [profile]} :db :as cofx} site enabled?] - (profile.settings.events/profile-update - cofx - :link-previews-enabled-sites - (if enabled? - (conj (get profile :link-previews-enabled-sites #{}) site) - (disj (get profile :link-previews-enabled-sites #{}) site)) - {})) +(rf/reg-event-fx :chat.ui/enable-link-previews + (fn [{{:profile/keys [profile]} :db} [site enabled?]] + (let [enabled-sites (if enabled? + (conj (get profile :link-previews-enabled-sites #{}) site) + (disj (get profile :link-previews-enabled-sites #{}) site))] + {:fx [[:dispatch [:profile.settings/profile-update :link-previews-enabled-sites enabled-sites]]]}))) -(rf/defn enable-all - {:events [:chat.ui/enable-all-link-previews]} - [cofx link-previews-whitelist enabled?] - (profile.settings.events/profile-update - cofx - :link-previews-enabled-sites - (if enabled? - (into #{} (map :title link-previews-whitelist)) - #{}) - {})) +(rf/reg-event-fx :chat.ui/enable-all-link-previews + (fn [_ [link-previews-whitelist enabled?]] + (let [enabled-sites (if enabled? + (into #{} (map :title link-previews-whitelist)) + #{})] + {:fx [[:dispatch [:profile.settings/profile-update :link-previews-enabled-sites enabled-sites]]]}))) diff --git a/src/status_im/contexts/profile/config.cljs b/src/status_im/contexts/profile/config.cljs index 2a42f954a0..e97bc291d5 100644 --- a/src/status_im/contexts/profile/config.cljs +++ b/src/status_im/contexts/profile/config.cljs @@ -2,8 +2,8 @@ (:require [clojure.string :as string] [native-module.core :as native-module] + [re-frame.core :as re-frame] [status-im.config :as config] - [utils.re-frame :as rf] [utils.transforms :as transforms])) (defn login @@ -51,14 +51,14 @@ (when path (string/replace-first path "file://" ""))) -(rf/defn get-node-config-callback - {:events [:profile.config/get-node-config-callback]} - [{:keys [db]} node-config-json] - (let [node-config (transforms/json->clj node-config-json)] - {:db (assoc-in db - [:profile/profile :wakuv2-config] - (get node-config :WakuV2Config))})) +(re-frame/reg-event-fx :profile.config/get-node-config-callback + (fn [{:keys [db]} [node-config-json]] + (let [node-config (transforms/json->clj node-config-json)] + {:db (assoc-in db + [:profile/profile :wakuv2-config] + (get node-config :WakuV2Config))}))) -(rf/defn get-node-config - [_] - (native-module/get-node-config #(rf/dispatch [:profile.config/get-node-config-callback %]))) +(re-frame/reg-fx :profile.config/get-node-config + (fn [] + (native-module/get-node-config + #(re-frame/dispatch [:profile.config/get-node-config-callback %])))) diff --git a/src/status_im/contexts/profile/events.cljs b/src/status_im/contexts/profile/events.cljs index 7938be6738..78884bb733 100644 --- a/src/status_im/contexts/profile/events.cljs +++ b/src/status_im/contexts/profile/events.cljs @@ -2,37 +2,21 @@ (:require [legacy.status-im.data-store.settings :as data-store.settings] [native-module.core :as native-module] - [re-frame.core :as re-frame] [status-im.contexts.profile.edit.accent-colour.events] [status-im.contexts.profile.edit.bio.events] [status-im.contexts.profile.edit.header.events] [status-im.contexts.profile.edit.name.events] - [status-im.contexts.profile.login.events :as profile.login] + status-im.contexts.profile.login.events [status-im.contexts.profile.rpc :as profile.rpc] - [status-im.navigation.events :as navigation] [utils.re-frame :as rf])) -(re-frame/reg-fx - :profile/get-profiles-overview - (fn [callback] - (native-module/open-accounts callback))) +(defn- select-profile + [profile key-uid] + (-> profile + (assoc :key-uid key-uid) + (dissoc :error :password))) -(rf/defn profile-selected - {:events [:profile/profile-selected]} - [{:keys [db]} key-uid] - {:db (update db - :profile/login - #(-> % - (assoc :key-uid key-uid) - (dissoc :error :password)))}) - -(rf/defn init-profiles-overview - [{:keys [db] :as cofx} profiles key-uid] - (rf/merge cofx - {:db (assoc db :profile/profiles-overview profiles)} - (profile-selected key-uid))) - -(defn reduce-profiles +(defn- reduce-profiles [profiles] (reduce (fn [acc {:keys [key-uid] :as profile}] @@ -40,28 +24,44 @@ {} profiles)) -(rf/defn get-profiles-overview-success - {:events [:profile/get-profiles-overview-success]} - [cofx profiles-overview] - (if (seq profiles-overview) - (let [profiles (reduce-profiles profiles-overview) - {:keys [key-uid]} (first (sort-by :timestamp > (vals profiles)))] - (rf/merge cofx - (navigation/init-root :profiles) - (when key-uid (init-profiles-overview profiles key-uid)) - ;;we check if biometric is available, and try to login with it, - ;;if succeed "node.login" signal will be triggered - (when key-uid (profile.login/login-with-biometric-if-available key-uid)))) - (navigation/init-root cofx :intro))) +(rf/reg-fx + :profile/get-profiles-overview + (fn [callback] + (native-module/open-accounts callback))) -(rf/defn update-setting-from-backup - {:events [:profile/update-setting-from-backup]} - [{:keys [db]} {:keys [backedUpSettings]}] - (let [setting (update backedUpSettings :name keyword) - {:keys [name value]} (data-store.settings/rpc->setting-value setting)] - {:db (assoc-in db [:profile/profile name] value)})) +(rf/reg-event-fx + :profile/profile-selected + (fn [{:keys [db]} [key-uid]] + {:db (update db :profile/login #(select-profile % key-uid))})) -(rf/defn update-profile-from-backup - {:events [:profile/update-profile-from-backup]} - [_ {{:keys [ensUsernameDetails]} :backedUpProfile}] - {:dispatch [:ens/update-usernames ensUsernameDetails]}) +(rf/reg-event-fx + :profile/get-profiles-overview-success + (fn [{:keys [db]} [profiles-overview]] + (if (seq profiles-overview) + (let [profiles (reduce-profiles profiles-overview) + {:keys [key-uid]} (first (sort-by :timestamp > (vals profiles)))] + {:db (if key-uid + (-> db + (assoc :profile/profiles-overview profiles) + (update :profile/login #(select-profile % key-uid))) + db) + :fx [[:set-root :profiles] + (when key-uid + [:effects.biometric/check-if-available + {:key-uid key-uid + :on-success (fn [auth-method] + (rf/dispatch [:profile.login/check-biometric-success key-uid + auth-method]))}])]}) + {:fx [[:set-root :intro]]}))) + +(rf/reg-event-fx + :profile/update-setting-from-backup + (fn [{:keys [db]} [{:keys [backedUpSettings]}]] + (let [setting (update backedUpSettings :name keyword) + {:keys [name value]} (data-store.settings/rpc->setting-value setting)] + {:db (assoc-in db [:profile/profile name] value)}))) + +(rf/reg-event-fx + :profile/update-profile-from-backup + (fn [_ [{{:keys [ensUsernameDetails]} :backedUpProfile}]] + {:fx [[:dispatch [:ens/update-usernames ensUsernameDetails]]]})) diff --git a/src/status_im/contexts/profile/login/events.cljs b/src/status_im/contexts/profile/login/events.cljs index 29e2b4cf03..a2338d8acb 100644 --- a/src/status_im/contexts/profile/login/events.cljs +++ b/src/status_im/contexts/profile/login/events.cljs @@ -1,210 +1,188 @@ (ns status-im.contexts.profile.login.events (:require - [legacy.status-im.browser.core :as browser] - [legacy.status-im.data-store.chats :as data-store.chats] [legacy.status-im.data-store.settings :as data-store.settings] - [legacy.status-im.data-store.switcher-cards :as switcher-cards-store] - [legacy.status-im.data-store.visibility-status-updates :as visibility-status-updates-store] - [legacy.status-im.group-chats.core :as group-chats] [legacy.status-im.mailserver.core :as mailserver] - [legacy.status-im.mobile-sync-settings.core :as mobile-network] - [legacy.status-im.pairing.core :as pairing] - [legacy.status-im.stickers.core :as stickers] [native-module.core :as native-module] - [re-frame.core :as re-frame] [status-im.common.keychain.events :as keychain] - [status-im.common.log :as logging] - [status-im.common.universal-links :as universal-links] [status-im.config :as config] - [status-im.contexts.chat.contacts.events :as contacts] - [status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview] - [status-im.contexts.profile.config :as profile.config] + [status-im.constants :as constants] status-im.contexts.profile.login.effects - [status-im.contexts.profile.push-notifications.events :as notifications] [status-im.contexts.profile.rpc :as profile.rpc] - [status-im.contexts.profile.settings.events :as profile.settings.events] - [status-im.contexts.shell.activity-center.events :as activity-center] - [status-im.navigation.events :as navigation] [taoensso.timbre :as log] + [utils.ethereum.chain :as chain] [utils.re-frame :as rf] [utils.security.core :as security])) -(rf/defn login - {:events [:profile.login/login]} - [{:keys [db]}] - (let [{:keys [key-uid password]} (:profile/login db) - login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] - {:db (-> db - (assoc-in [:profile/login :processing] true) - (assoc-in [:syncing :login-sha3-password] login-sha3-password)) - :effects.profile/login [key-uid login-sha3-password]})) +(rf/reg-event-fx :profile.login/login + (fn [{:keys [db]}] + (let [{:keys [key-uid password]} (:profile/login db) + login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] + {:db (-> db + (assoc-in [:profile/login :processing] true) + (assoc-in [:syncing :login-sha3-password] login-sha3-password)) + :fx [[:effects.profile/login [key-uid login-sha3-password]]]}))) -(rf/defn biometrics-login - {:events [:profile.login/biometrics-login]} - [{:keys [db]}] - (let [{:keys [key-uid password]} (:profile/login db)] - {:db (assoc-in db [:profile/login :processing] true) - :effects.profile/login [key-uid (security/safe-unmask-data password)]})) +(rf/reg-event-fx :profile.login/local-paired-user + (fn [{:keys [db]}] + (let [{:keys [key-uid password]} (get-in db [:syncing :profile]) + login-sha3-password (get-in db [:syncing :login-sha3-password]) + password (if-not (nil? login-sha3-password) ;; already logged in + login-sha3-password + password) + masked-password (security/mask-data password)] + {:db (-> db + (assoc-in [:onboarding/profile :password] masked-password) + (assoc-in [:onboarding/profile :syncing?] true)) + :effects.profile/login [key-uid password]}))) -(rf/defn login-local-paired-user - {:events [:profile.login/local-paired-user]} - [{:keys [db]}] - (let [{:keys [key-uid password]} (get-in db [:syncing :profile]) - login-sha3-password (get-in db [:syncing :login-sha3-password]) - password (if-not (nil? login-sha3-password) ;; already logged in - login-sha3-password - password) - masked-password (security/mask-data password)] - {:db (-> db - (assoc-in [:onboarding/profile :password] masked-password) - (assoc-in [:onboarding/profile :syncing?] true)) - :effects.profile/login [key-uid password]})) +;; login phase 1: we want to load and show chats faster, so we split login into 2 phases +(rf/reg-event-fx :profile.login/login-existing-profile + (fn [{:keys [db]} [settings account]] + (let [{:networks/keys [current-network networks] + :as settings} + (data-store.settings/rpc->settings settings) + profile-overview (profile.rpc/rpc->profiles-overview account) + log-level (or (:log-level settings) config/log-level) + pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed)] + {:db (cond-> (-> db + (assoc :chats/loading? true + :networks/current-network current-network + :networks/networks (merge networks config/default-networks-by-id) + :profile/profile (merge profile-overview + settings + {:log-level log-level})) + (assoc-in [:activity-center :loading?] true)) + pairing-completed? + (dissoc :syncing)) + :fx (into [[:dispatch [:universal-links/generate-profile-url]] + [:dispatch [:community/fetch]] + [:dispatch [:wallet/initialize]] + [:push-notifications/load-preferences] + [:fetch-chats-preview + {:on-success (fn [result] + (rf/dispatch [:chats-list/load-success result]) + (rf/dispatch [:communities/get-user-requests-to-join]) + (rf/dispatch [:profile.login/get-chats-callback]))}] + [:profile.config/get-node-config] + [:logs/set-level log-level] + [:activity-center.notifications/fetch-pending-contact-requests-fx] + [:activity-center/update-seen-state] + [:activity-center.notifications/fetch-unread-count]] -(rf/defn redirect-to-root - [{:keys [db] :as cofx}] - (let [pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed)] - (cond - pairing-completed? - {:db (dissoc db :syncing) - :dispatch [:init-root :syncing-results]} + (cond + pairing-completed? + [[:set-root :syncing-results]] - (get db :onboarding/new-account?) - {:dispatch [:onboarding/finalize-setup]} + (get db :onboarding/new-account?) + [[:dispatch [:onboarding/finalize-setup]]] - :else - (rf/merge - cofx - (profile.settings.events/switch-theme nil :shell-stack) - (navigation/init-root :shell-stack))))) + :else + [[:profile.settings/switch-theme-fx + [(or (get-in db [:profile/profile :appearance]) + constants/theme-type-dark) + :shell-stack + false]] + [:set-root :shell-stack]]))}))) -;; login phase 1, we want to load and show chats faster so we split login into 2 phases -(rf/defn login-existing-profile - [{:keys [db] :as cofx} settings account] - (let [{:networks/keys [current-network networks] - :as settings} - (data-store.settings/rpc->settings settings) - profile-overview (profile.rpc/rpc->profiles-overview account)] - (rf/merge cofx - {:db (-> db - (assoc :chats/loading? true - :networks/current-network current-network - :networks/networks (merge networks config/default-networks-by-id) - :profile/profile (merge profile-overview settings))) - :fx [[:dispatch [:universal-links/generate-profile-url]] - [:dispatch [:community/fetch]] - [:dispatch [:wallet/initialize]]]} - (notifications/load-preferences) - (data-store.chats/fetch-chats-preview - {:on-success - #(do (re-frame/dispatch [:chats-list/load-success %]) - (rf/dispatch [:communities/get-user-requests-to-join]) - (re-frame/dispatch [:profile.login/get-chats-callback]))}) - (profile.config/get-node-config) - (logging/set-log-level (:log-level settings)) - (activity-center/notifications-fetch-pending-contact-requests) - (activity-center/update-seen-state) - (activity-center/notifications-fetch-unread-count) - (redirect-to-root)))) +;; login phase 2: we want to load and show chats faster, so we split login into 2 phases +(rf/reg-event-fx :profile.login/get-chats-callback + (fn [{:keys [db]}] + (let [{:networks/keys [current-network networks]} db + {:keys [notifications-enabled? key-uid + preview-privacy?]} (:profile/profile db) + network-id (str (get-in networks + [current-network :config :NetworkId]))] + {:db db + :fx [[:json-rpc/call + [{:method "wakuext_startMessenger" + :on-success [:profile.login/messenger-started] + :on-error #(log/error + "failed to start messenger")}]] + [:check-eip1559-activation {:network-id network-id}] + [:effects.profile/enable-local-notifications] + [:contacts/initialize-contacts] + [:browser/initialize-browser] + [:dispatch [:mobile-network/on-network-status-change]] + [:group-chats/get-group-chat-invitations] + [:profile.settings/get-profile-picture key-uid] + [:profile.settings/blank-preview-flag-changed preview-privacy?] + [:chat.ui/request-link-preview-whitelist] + [:visibility-status-updates/fetch] + [:switcher-cards/fetch] + (when-not (:universal-links/handling db) + [:effects.chat/open-last-chat key-uid]) + (when notifications-enabled? + [:effects/push-notifications-enable])]}))) -;; login phase 2, we want to load and show chats faster so we split login into 2 phases -(rf/defn get-chats-callback - {:events [:profile.login/get-chats-callback]} - [{:keys [db] :as cofx}] - (let [{:networks/keys [current-network networks]} db - {:keys [notifications-enabled?]} (:profile/profile db) - current-network-config (get networks current-network) - network-id (str (get-in networks - [current-network :config :NetworkId]))] - (rf/merge - cofx - (cond-> {:json-rpc/call [{:method "wakuext_startMessenger" - :on-success #(re-frame/dispatch - [:messenger-started %]) - :on-error #(log/error - "failed to start messenger")}] - :check-eip1559-activation {:network-id network-id} - :effects.profile/enable-local-notifications nil} - (not (:universal-links/handling db)) - (assoc :effects.chat/open-last-chat (get-in db [:profile/profile :key-uid])) - notifications-enabled? - (assoc :effects/push-notifications-enable nil)) - (contacts/initialize-contacts) - (browser/initialize-browser) - (mobile-network/on-network-status-change) - (group-chats/get-group-chat-invitations) - (profile.settings.events/get-profile-picture) - (profile.settings.events/change-preview-privacy) - (link-preview/request-link-preview-whitelist) - (visibility-status-updates-store/fetch-visibility-status-updates-rpc) - (switcher-cards-store/fetch-switcher-cards-rpc)))) +(rf/reg-event-fx :profile.login/messenger-started + (fn [{:keys [db]} [{:keys [mailservers]}]] + (let [chain-id (chain/chain-id db) + new-account? (get db :onboarding/new-account?)] + {:db (-> db + (assoc :messenger/started? true) + (mailserver/add-mailservers mailservers)) + :fx [[:json-rpc/call + [{:method "admin_nodeInfo" + :on-success [:profile.login/node-info-fetched] + :on-error #(log/error "node-info: failed error" %)}]] + [:pairing/get-our-installations] + [:stickers/load-packs chain-id] + (when-not new-account? + [:dispatch [:universal-links/process-stored-event]])]}))) -(rf/defn messenger-started - {:events [:messenger-started]} - [{:keys [db] :as cofx} {:keys [mailservers] :as response}] - (log/info "Messenger started") - (let [new-account? (get db :onboarding/new-account?)] - (rf/merge cofx - {:db (-> db - (assoc :messenger/started? true) - (mailserver/add-mailservers mailservers)) - :json-rpc/call [{:method "admin_nodeInfo" - :on-success #(re-frame/dispatch [:node-info-fetched %]) - :on-error #(log/error "node-info: failed error" %)}]} - (pairing/init) - (stickers/load-packs) - (when-not new-account? - (universal-links/process-stored-event))))) +(rf/reg-event-fx :profile.login/node-info-fetched + (fn [{:keys [db]} [node-info]] + {:db (assoc db :node-info node-info)})) -(rf/defn set-node-info - {:events [:node-info-fetched]} - [{:keys [db]} node-info] - {:db (assoc db :node-info node-info)}) +(rf/reg-event-fx + :profile.login/login-node-signal + (fn [{{:onboarding/keys [recovered-account? new-account?] :as db} :db} + [{:keys [settings account ensUsernames error]}]] + (log/debug "[signals] node.login" "error" error) + (if error + {:db (update db :profile/login #(-> % (dissoc :processing) (assoc :error error)))} + {:db (dissoc db :profile/login) + :fx [[:logging/initialize-web3-client-version] + (when (and new-account? (not recovered-account?)) + [:dispatch [:wallet-legacy/set-initial-blocks-range]]) + [:dispatch [:ens/update-usernames ensUsernames]] + [:dispatch [:profile.login/login-existing-profile settings account]]]}))) -(rf/defn login-node-signal - [{{:onboarding/keys [recovered-account? new-account?] :as db} :db :as cofx} - {:keys [settings account ensUsernames error]}] - (log/debug "[signals] node.login" "error" error) - (if error - {:db (update db :profile/login #(-> % (dissoc :processing) (assoc :error error)))} - (rf/merge cofx - {:db (dissoc db :profile/login) - :dispatch-n [[:logging/initialize-web3-client-version] - (when (and new-account? (not recovered-account?)) - [:wallet-legacy/set-initial-blocks-range]) - [:ens/update-usernames ensUsernames]]} - (login-existing-profile settings account)))) +(rf/reg-event-fx + :profile.login/login-with-biometric-if-available + (fn [_ [key-uid]] + {:fx [[:effects.biometric/check-if-available + {:key-uid key-uid + :on-success (fn [auth-method] + (rf/dispatch + [:profile.login/check-biometric-success + key-uid auth-method]))}]]})) -(rf/defn login-with-biometric-if-available - {:events [:profile.login/login-with-biometric-if-available]} - [_ key-uid] - {:effects.biometric/check-if-available {:key-uid key-uid - :on-success (fn [auth-method] - (rf/dispatch - [:profile.login/check-biometric-success - key-uid auth-method]))}}) - -(rf/defn check-biometric-success - {:events [:profile.login/check-biometric-success]} - [{:keys [db]} key-uid auth-method] - (merge {:db (assoc db :auth-method auth-method)} - (when (= auth-method keychain/auth-method-biometric) - {:keychain/password-hash-migration +(rf/reg-event-fx + :profile.login/check-biometric-success + (fn [{:keys [db]} [key-uid auth-method]] + {:db (assoc db :auth-method auth-method) + :fx [(when (= auth-method keychain/auth-method-biometric) + [:keychain/password-hash-migration {:key-uid key-uid :callback (fn [] - (rf/dispatch [:biometric/authenticate - {:on-success #(rf/dispatch [:profile.login/biometric-success]) - :on-fail #(rf/dispatch - [:profile.login/biometric-auth-fail %])}]))}}))) + (rf/dispatch + [:biometric/authenticate + {:on-success #(rf/dispatch + [:profile.login/biometric-success]) + :on-fail #(rf/dispatch + [:profile.login/biometric-auth-fail %])}]))}])]})) -(rf/defn get-user-password-success - {:events [:profile.login/get-user-password-success]} - [{:keys [db] :as cofx} password] - (when password - (rf/merge - cofx - {:db (assoc-in db [:profile/login :password] password)} - (navigation/init-root :progress) - (biometrics-login)))) +(rf/reg-event-fx + :profile.login/get-user-password-success + (fn [{:keys [db]} [password]] + (when password + (let [{:keys [key-uid password]} (:profile/login db)] + {:db (-> db + (assoc-in [:profile/login :password] password) + (assoc-in [:profile/login :processing] true)) + :fx [[:set-root :progress] + [:effects.profile/login [key-uid (security/safe-unmask-data password)]]]})))) (rf/reg-event-fx :profile.login/biometric-success @@ -223,35 +201,35 @@ :event :profile.login/biometric-auth-fail))) {:dispatch [:biometric/show-message (ex-cause error)]})) -(rf/defn verify-database-password - {:events [:profile.login/verify-database-password]} - [_ entered-password cb] - (let [hashed-password (-> entered-password - security/safe-unmask-data - native-module/sha3)] - {:json-rpc/call [{:method "accounts_verifyPassword" - :params [hashed-password] - :on-success #(rf/dispatch [:profile.login/verified-database-password % cb]) - :on-error #(log/error "accounts_verifyPassword error" %)}]})) +(rf/reg-event-fx + :profile.login/verify-database-password + (fn [_ [entered-password cb]] + (let [hashed-password (-> entered-password + security/safe-unmask-data + native-module/sha3)] + {:json-rpc/call [{:method "accounts_verifyPassword" + :params [hashed-password] + :on-success #(rf/dispatch [:profile.login/verified-database-password % cb]) + :on-error #(log/error "accounts_verifyPassword error" %)}]}))) -(rf/defn verify-database-password-success - {:events [:profile.login/verified-database-password]} - [{:keys [db]} valid? callback] - (if valid? - (do - (when (fn? callback) - (callback)) - {:db (update db - :profile/login - dissoc - :processing :error)}) - {:db (update db - :profile/login - #(-> % - (dissoc :processing) - (assoc :error "Invalid password")))})) +(rf/reg-event-fx + :profile.login/verified-database-password + (fn [{:keys [db]} [valid? callback]] + (if valid? + (do + (when (fn? callback) + (callback)) + {:db (update db + :profile/login + dissoc + :processing :error)}) + {:db (update db + :profile/login + #(-> % + (dissoc :processing) + (assoc :error "Invalid password")))}))) -(re-frame/reg-event-fx +(rf/reg-event-fx :profile/on-password-input-changed (fn [{:keys [db]} [{:keys [password error]}]] {:db (update db :profile/login assoc :password password :error error)})) diff --git a/src/status_im/contexts/profile/push_notifications/events.cljs b/src/status_im/contexts/profile/push_notifications/events.cljs index 7ff8c2261c..f527b862db 100644 --- a/src/status_im/contexts/profile/push_notifications/events.cljs +++ b/src/status_im/contexts/profile/push_notifications/events.cljs @@ -2,9 +2,11 @@ (:require [cljs-bean.core :as bean] [native-module.push-notifications :as native-module.pn] + [re-frame.core :as re-frame] [react-native.async-storage :as async-storage] [react-native.platform :as platform] [react-native.push-notification-ios :as pn-ios] + [status-im.common.json-rpc.events :as json-rpc] [status-im.config :as config] status-im.contexts.profile.push-notifications.effects [taoensso.timbre :as log] @@ -55,8 +57,8 @@ [{:keys [db]} preferences] {:db (assoc db :push-notifications/preferences preferences)}) -(rf/defn load-preferences - [_] - {:json-rpc/call [{:method "localnotifications_notificationPreferences" - :params [] - :on-success #(rf/dispatch [:push-notifications/preferences-loaded %])}]}) +(re-frame/reg-fx :push-notifications/load-preferences + (fn [] + (json-rpc/call {:method "localnotifications_notificationPreferences" + :params [] + :on-success [:push-notifications/preferences-loaded]}))) diff --git a/src/status_im/contexts/profile/settings/events.cljs b/src/status_im/contexts/profile/settings/events.cljs index a5fffaf5f7..9f6eb0d4ed 100644 --- a/src/status_im/contexts/profile/settings/events.cljs +++ b/src/status_im/contexts/profile/settings/events.cljs @@ -1,63 +1,47 @@ (ns status-im.contexts.profile.settings.events (:require [clojure.string :as string] - [legacy.status-im.bottom-sheet.events :as bottom-sheet.events] - [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.constants :as constants] status-im.contexts.profile.settings.effects [taoensso.timbre :as log] [utils.i18n :as i18n] [utils.re-frame :as rf])) -(rf/defn send-contact-update - [{:keys [db]}] - (let [{:keys [name preferred-name display-name]} (:profile/profile db)] - {:json-rpc/call [{:method "wakuext_sendContactUpdates" - :params [(or preferred-name display-name name) ""] - :on-success #(log/debug "sent contact update")}]})) +(defn- set-setting-value + [db setting setting-value] + (if setting-value + (assoc-in db [:profile/profile setting] setting-value) + (update db :profile/profile dissoc setting))) -(rf/defn profile-update - {:events [:profile.settings/profile-update]} - [{:keys [db] :as cofx} - setting setting-value - {:keys [dont-sync? on-success] :or {on-success #()}}] - (rf/merge - cofx - {:db (if setting-value - (assoc-in db [:profile/profile setting] setting-value) - (update db :profile/profile dissoc setting)) - :json-rpc/call - [{:method "settings_saveSetting" - :params [setting setting-value] - :on-success on-success}]} +(rf/reg-event-fx :profile.settings/profile-update + (fn [{:keys [db]} [setting setting-value {:keys [dont-sync? on-success]}]] + {:db (-> db + (set-setting-value setting setting-value)) + :fx [[:json-rpc/call + [{:method "settings_saveSetting" + :params [setting setting-value] + :on-success on-success}]] - (when (#{:name :preferred-name} setting) - (constantly {:profile/get-profiles-overview #(rf/dispatch [:multiaccounts.ui/update-name %])})) + (when (#{:name :preferred-name} setting) + [:profile/get-profiles-overview #(rf/dispatch [:multiaccounts.ui/update-name %])]) - (when (and (not dont-sync?) (#{:name :preferred-name} setting)) - (send-contact-update)))) + (when (and (not dont-sync?) (#{:name :preferred-name} setting)) + (let [{:keys [name preferred-name display-name]} (:profile/profile db)] + [:json-rpc/call + [{:method "wakuext_sendContactUpdates" + :params [(or preferred-name display-name name) ""] + :on-success #(log/debug "sent contact update")}]]))]})) -(rf/defn optimistic-profile-update - [{:keys [db]} setting setting-value] - {:db (if setting-value - (assoc-in db [:profile/profile setting] setting-value) - (update db :profile/profile dissoc setting))}) +(rf/reg-event-fx :profile.settings/change-preview-privacy + (fn [{:keys [db]}] + (let [private? (get-in db [:profile/profile :preview-privacy?])] + {:fx [[:profile.settings/blank-preview-flag-changed private?]]}))) -(rf/defn change-preview-privacy - [{:keys [db]}] - (let [private? (get-in db [:profile/profile :preview-privacy?])] - {:profile.settings/blank-preview-flag-changed private?})) - -(rf/defn update-value - {:events [:profile.settings/update-value]} - [cofx key value] - (profile-update cofx key value {})) - -(rf/defn change-webview-debug - {:events [:profile.settings/change-webview-debug]} - [{:keys [db] :as cofx} value] - (rf/merge cofx - {:profile.settings/webview-debug-changed value} - (profile-update :webview-debug (boolean value) {}))) +(rf/reg-event-fx :profile.settings/change-webview-debug + (fn [_ [value]] + (let [value' (boolean value)] + {:fx [[:dispatch [:profile.settings/profile-update :webview-debug value']] + [:profile.settings/webview-debug-changed value']]}))) (rf/reg-event-fx :profile.settings/toggle-test-networks (fn [{:keys [db]}] @@ -82,17 +66,22 @@ {:on-success on-success}]) :on-cancel nil}]]}))) -(rf/defn change-preview-privacy-flag - {:events [:profile.settings/change-preview-privacy]} - [{:keys [db] :as cofx} private?] - (rf/merge cofx - {:profile.settings/blank-preview-flag-changed private?} - (profile-update - :preview-privacy? - (boolean private?) - {}))) +(rf/reg-event-fx :profile.settings/change-preview-privacy + (fn [_ [private?]] + (let [private?' (boolean private?)] + {:fx [[:dispatch [:profile.settings/profile-update :preview-privacy? private?']] + [:profile.settings/blank-preview-flag-changed private?']]}))) -(re-frame/reg-event-fx :profile.settings/toggle-peer-syncing +(rf/reg-event-fx :profile.settings/change-profile-pictures-show-to + (fn [{:keys [db]} [id]] + {:db (-> db + (assoc-in [:profile/profile :profile-pictures-show-to] id)) + :fx [[:json-rpc/call + [{:method "wakuext_changeIdentityImageShowTo" + :params [id] + :on-success #(log/debug "picture settings changed successfully")}]]]})) + +(rf/reg-event-fx :profile.settings/toggle-peer-syncing (fn [{:keys [db]}] (let [value (get-in db [:profile/profile :peer-syncing-enabled?]) new-value (not value)] @@ -102,81 +91,69 @@ :params [{:enabled new-value}] :on-error #(log/error "failed to toggle peer syncing" new-value %)}]]]}))) -(rf/defn change-profile-pictures-show-to - {:events [:profile.settings/change-profile-pictures-show-to]} - [cofx id] - (rf/merge cofx - {:json-rpc/call [{:method "wakuext_changeIdentityImageShowTo" - :params [id] - :on-success #(log/debug "picture settings changed successfully")}]} - (optimistic-profile-update :profile-pictures-show-to id))) +(rf/reg-event-fx :profile.settings/change-appearance + (fn [_ [theme]] + {:fx [[:dispatch [:profile.settings/profile-update :appearance theme]] + [:profile.settings/switch-theme-fx [theme :appearance true]]]})) -(rf/defn change-appearance - {:events [:profile.settings/change-appearance]} - [cofx theme] - (rf/merge cofx - {:profile.settings/switch-theme-fx [theme :appearance true]} - (profile-update :appearance theme {}))) +(rf/reg-event-fx :profile.settings/switch-theme + (fn [{:keys [db]} [theme view-id]] + (let [theme (or theme + (get-in db [:profile/profile :appearance]) + constants/theme-type-dark)] + {:fx [[:profile.settings/switch-theme-fx [theme view-id false]]]}))) -(rf/defn switch-theme - {:events [:profile.settings/switch-theme]} - [cofx theme view-id] - (let [theme (or theme - (get-in cofx [:db :profile/profile :appearance]) - constants/theme-type-dark)] - {:profile.settings/switch-theme-fx [theme view-id false]})) +(rf/reg-fx :profile.settings/get-profile-picture + (fn [key-uid] + (json-rpc/call {:method "multiaccounts_getIdentityImages" + :params [key-uid] + :on-success [:profile.settings/update-local-picture]}))) -(rf/defn get-profile-picture - {:events [:profile.settings/get-profile-picture]} - [cofx] - (let [key-uid (get-in cofx [:db :profile/profile :key-uid])] - {:json-rpc/call [{:method "multiaccounts_getIdentityImages" - :params [key-uid] - :on-success [:profile.settings/update-local-picture]}]})) +(rf/reg-event-fx :profile.settings/save-profile-picture + (fn [{:keys [db]} [path ax ay bx by]] + (let [key-uid (get-in db [:profile/profile :key-uid])] + {:db (-> db + (assoc :bottom-sheet/show? false)) + :fx [[:json-rpc/call + [{:method "multiaccounts_storeIdentityImage" + :params [key-uid (string/replace-first path #"file://" "") ax ay bx + by] + :on-success [:profile.settings/update-local-picture]}]] + [:dismiss-bottom-sheet-overlay-old]]}))) -(rf/defn save-profile-picture - {:events [:profile.settings/save-profile-picture]} - [cofx path ax ay bx by] - (let [key-uid (get-in cofx [:db :profile/profile :key-uid])] - (rf/merge cofx - {:json-rpc/call [{:method "multiaccounts_storeIdentityImage" - :params [key-uid (string/replace-first path #"file://" "") ax ay bx - by] - :on-success [:profile.settings/update-local-picture]}]} - (bottom-sheet.events/hide-bottom-sheet-old)))) +(rf/reg-event-fx :profile.settings/save-profile-picture-from-url + (fn [{:keys [db]} [url]] + (let [key-uid (get-in db [:profile/profile :key-uid])] + {:db (-> db + (assoc :bottom-sheet/show? false)) + :fx [[:json-rpc/call + [{:method "multiaccounts_storeIdentityImageFromURL" + :params [key-uid url] + :on-error #(log/error "::save-profile-picture-from-url error" %) + :on-success [:profile.settings/update-local-picture]}]] + [:dismiss-bottom-sheet-overlay-old]]}))) -(rf/defn save-profile-picture-from-url - {:events [:profile.settings/save-profile-picture-from-url]} - [cofx url] - (let [key-uid (get-in cofx [:db :profile/profile :key-uid])] - (rf/merge cofx - {:json-rpc/call [{:method "multiaccounts_storeIdentityImageFromURL" - :params [key-uid url] - :on-error #(log/error "::save-profile-picture-from-url error" %) - :on-success [:profile.settings/update-local-picture]}]} - (bottom-sheet.events/hide-bottom-sheet-old)))) +(rf/reg-event-fx :profile.settings/delete-profile-picture + (fn [{:keys [db]}] + (let [key-uid (get-in db [:profile/profile :key-uid])] + {:db (-> db + (update :profile/profile dissoc :images) + (assoc :bottom-sheet/show? false)) + :fx [[:json-rpc/call + [{:method "multiaccounts_deleteIdentityImage" + :params [key-uid] + ;; NOTE: In case of an error we could fallback to previous image in + ;; UI with a toast error + :on-success #(log/info "[profile] Delete profile image" %)}]] + [:dismiss-bottom-sheet-overlay-old]]}))) -(rf/defn delete-profile-picture - {:events [:profile.settings/delete-profile-picture]} - [cofx name] - (let [key-uid (get-in cofx [:db :profile/profile :key-uid])] - (rf/merge cofx - {:json-rpc/call [{:method "multiaccounts_deleteIdentityImage" - :params [key-uid] - ;; NOTE: In case of an error we could fallback to previous image in - ;; UI with a toast error - :on-success #(log/info "[profile] Delete profile image" %)}]} - (optimistic-profile-update :images nil) - (bottom-sheet.events/hide-bottom-sheet-old)))) +(rf/reg-event-fx :profile.settings/update-local-picture + (fn [{:keys [db]} [images]] + {:db (assoc-in db [:profile/profile :images] images)})) -(rf/defn store-profile-picture - {:events [:profile.settings/update-local-picture]} - [cofx pics] - (optimistic-profile-update cofx :images pics)) - -(rf/defn mark-mnemonic-as-shown - {:events [:profile.settings/mnemonic-was-shown]} - [cofx] - {:json-rpc/call [{:method "settings_mnemonicWasShown" - :on-success #(log/debug "mnemonic was marked as shown") - :on-error #(log/error "mnemonic was not marked as shown" %)}]}) +(rf/reg-event-fx :profile.settings/mnemonic-was-shown + (fn [_] + {:fx [[:json-rpc/call + [{:method "settings_mnemonicWasShown" + :on-success #(log/debug "mnemonic was marked as shown") + :on-error #(log/error "mnemonic was not marked as shown" %)}]]]})) diff --git a/src/status_im/contexts/shell/activity_center/events.cljs b/src/status_im/contexts/shell/activity_center/events.cljs index 60b5220d8d..b0093915a2 100644 --- a/src/status_im/contexts/shell/activity_center/events.cljs +++ b/src/status_im/contexts/shell/activity_center/events.cljs @@ -4,6 +4,7 @@ [legacy.status-im.data-store.chats :as data-store.chats] [quo.foundations.colors :as colors] [re-frame.core :as re-frame] + [status-im.common.json-rpc.events :as json-rpc] [status-im.common.toasts.events :as toasts] [status-im.constants :as constants] [status-im.contexts.shell.activity-center.notification-types :as types] @@ -408,6 +409,17 @@ (constantly processed) #(concat % processed))))})) +(re-frame/reg-fx :activity-center.notifications/fetch-pending-contact-requests-fx + (fn [] + (json-rpc/call {:method "wakuext_activityCenterNotifications" + :params [{:cursor start-or-end-cursor + :limit 20 + :activityTypes [types/contact-request] + :readType (->rpc-read-type :unread)}] + :on-success [:activity-center.notifications/fetch-pending-contact-requests-success] + :on-error [:activity-center.notifications/fetch-error types/contact-request + :unread]}))) + (rf/defn notifications-fetch-pending-contact-requests "Unread contact requests are, in practical terms, the same as pending contact requests in the Activity Center, because pending contact requests are always @@ -419,14 +431,7 @@ {:events [:activity-center.notifications/fetch-pending-contact-requests]} [{:keys [db]}] {:db (assoc-in db [:activity-center :loading?] true) - :json-rpc/call - [{:method "wakuext_activityCenterNotifications" - :params [{:cursor start-or-end-cursor - :limit 20 - :activityTypes [types/contact-request] - :readType (->rpc-read-type :unread)}] - :on-success [:activity-center.notifications/fetch-pending-contact-requests-success] - :on-error [:activity-center.notifications/fetch-error types/contact-request :unread]}]}) + :fx [[:activity-center.notifications/fetch-pending-contact-requests-fx]]}) (rf/defn notifications-fetch-pending-contact-requests-success {:events [:activity-center.notifications/fetch-pending-contact-requests-success]} @@ -448,14 +453,12 @@ ;;;; Unread counters -(rf/defn update-seen-state - {:events [:activity-center/update-seen-state]} - [_] - {:json-rpc/call - [{:method "wakuext_hasUnseenActivityCenterNotifications" - :params [] - :on-success [:activity-center/update-seen-state-success] - :on-error [:activity-center/update-seen-state-error]}]}) +(re-frame/reg-fx :activity-center/update-seen-state + (fn [] + (json-rpc/call [{:method "wakuext_hasUnseenActivityCenterNotifications" + :params [] + :on-success [:activity-center/update-seen-state-success] + :on-error [:activity-center/update-seen-state-error]}]))) (rf/defn update-seen-state-success {:events [:activity-center/update-seen-state-success]} @@ -492,6 +495,14 @@ {:error error :event :activity-center/mark-as-seen})) +(re-frame/reg-fx :activity-center.notifications/fetch-unread-count + (fn [] + (json-rpc/call {:method "wakuext_activityCenterNotificationsCount" + :params [{:activityTypes types/all-supported + :readType (->rpc-read-type :unread)}] + :on-success [:activity-center.notifications/fetch-unread-count-success] + :on-error [:activity-center.notifications/fetch-unread-count-error]}))) + (rf/defn notifications-fetch-unread-count {:events [:activity-center.notifications/fetch-unread-count]} [_] diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index c2cafe0883..64614ddb02 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -8,13 +8,17 @@ status-im.common.emoji-picker.events status-im.common.font.events [status-im.common.json-rpc.events] + status-im.common.log status-im.common.password-authentication.events status-im.common.signals.events status-im.common.theme.events [status-im.common.toasts.events] + status-im.common.universal-links + status-im.contexts.chat.contacts.events status-im.contexts.chat.events [status-im.contexts.chat.home.add-new-contact.events] status-im.contexts.chat.messenger.composer.events + status-im.contexts.chat.messenger.messages.link-preview.events status-im.contexts.chat.messenger.photo-selector.events status-im.contexts.communities.events status-im.contexts.communities.overview.events @@ -29,6 +33,7 @@ status-im.contexts.wallet.send.events status-im.contexts.wallet.signals [status-im.db :as db] + status-im.navigation.events [utils.re-frame :as rf])) (rf/defn start-app diff --git a/src/test_helpers/integration.cljs b/src/test_helpers/integration.cljs index 2e1754b3cd..49ca801352 100644 --- a/src/test_helpers/integration.cljs +++ b/src/test_helpers/integration.cljs @@ -151,7 +151,7 @@ (p/resolved ::messenger-started) (do (create-multiaccount!) - (-> (wait-for [:messenger-started]) + (-> (wait-for [:profile.login/messenger-started]) (.then #(assert-messenger-started)))))) (defn test-async