Partial handlers update (re-frame/reg-event-fx instead of rf/defn) (#19005)

* Handlers update (re-frame/reg-event-fx instead of rf/defn)

* Fixes

* Fixes

* Fixes
This commit is contained in:
Alexander 2024-03-14 10:24:37 +01:00 committed by GitHub
parent 614b03d701
commit fa9645d6dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
32 changed files with 607 additions and 634 deletions

View File

@ -15,6 +15,7 @@
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.common.universal-links :as links] [status-im.common.universal-links :as links]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.chat.events :as chat.events] [status-im.contexts.chat.events :as chat.events]
@ -654,12 +655,11 @@
stored-bookmarks)] stored-bookmarks)]
{:db (assoc db :bookmarks/bookmarks bookmarks)})) {:db (assoc db :bookmarks/bookmarks bookmarks)}))
(rf/defn initialize-browser (re-frame/reg-fx :browser/initialize-browser
[_] (fn []
{:json-rpc/call (json-rpc/call {:method "wakuext_getBrowsers"
[{:method "wakuext_getBrowsers" :on-success [::initialize-browsers]})
:on-success #(re-frame/dispatch [::initialize-browsers %])} (json-rpc/call {:method "browsers_getBookmarks"
{:method "browsers_getBookmarks" :on-success [::initialize-bookmarks]})
:on-success #(re-frame/dispatch [::initialize-bookmarks %])} (json-rpc/call {:method "permissions_getDappPermissions"
{:method "permissions_getDappPermissions" :on-success [::initialize-dapp-permissions]})))
:on-success #(re-frame/dispatch [::initialize-dapp-permissions %])}]})

View File

@ -4,7 +4,6 @@
[legacy.status-im.bottom-sheet.events :as bottom-sheet] [legacy.status-im.bottom-sheet.events :as bottom-sheet]
legacy.status-im.communities.e2e legacy.status-im.communities.e2e
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.contexts.shell.activity-center.events :as activity-center]
[status-im.navigation.events :as navigation] [status-im.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -84,13 +83,12 @@
(navigation/navigate-back) (navigation/navigate-back)
(handle-response response-js))) (handle-response response-js)))
(rf/defn member-banned (re-frame/reg-event-fx ::member-banned
{:events [::member-banned]} (fn [{:keys [db]} [response-js]]
[cofx response-js] {:db (assoc db :bottom-sheet/show? false)
(rf/merge cofx :fx [[:dismiss-bottom-sheet-overlay-old]
(bottom-sheet/hide-bottom-sheet-old) [:sanitize-messages-and-process-response response-js]
(handle-response response-js) [:activity-center.notifications/fetch-unread-count]]}))
(activity-center/notifications-fetch-unread-count)))
(rf/defn member-ban (rf/defn member-ban
{:events [::member-ban]} {:events [::member-ban]}

View File

@ -6,7 +6,6 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.contexts.chat.contacts.events :as contacts-store] [status-im.contexts.chat.contacts.events :as contacts-store]
[status-im.contexts.chat.messenger.messages.list.events :as message-list] [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] [status-im.navigation.events :as navigation]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -45,16 +44,16 @@
(apply (apply
rf/merge rf/merge
cofx cofx
{:db (-> {:db (->
db db
(update :chats dissoc public-key) (update :chats dissoc public-key)
(update :chats-home-list disj public-key) (update :chats-home-list disj public-key)
(assoc-in [:contacts/contacts public-key (assoc-in [:contacts/contacts public-key
:added?] :added?]
false)) false))
:dispatch [:shell/close-switcher-card public-key] :fx [[:activity-center.notifications/fetch-unread-count]
:effects/push-notifications-clear-message-notifications [public-key]} [:effects/push-notifications-clear-message-notifications [public-key]]
(activity-center/notifications-fetch-unread-count) [:dispatch [:shell/close-switcher-card public-key]]]}
fxs))) fxs)))
(rf/defn block-contact (rf/defn block-contact

View File

@ -3,9 +3,10 @@
[clojure.set :as set] [clojure.set :as set]
[legacy.status-im.data-store.messages :as messages] [legacy.status-im.data-store.messages :as messages]
[legacy.status-im.utils.deprecated-types :as types] [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] [status-im.constants :as constants]
[taoensso.timbre :as log] [taoensso.timbre :as log]))
[utils.re-frame :as rf]))
(defn rpc->type (defn rpc->type
[{:keys [chat-type name] :as chat}] [{:keys [chat-type name] :as chat}]
@ -117,10 +118,10 @@
rpc->type rpc->type
unmarshal-members)) unmarshal-members))
(rf/defn fetch-chats-preview (re-frame/reg-fx :fetch-chats-preview
[_ {:keys [on-success]}] (fn [{:keys [on-success]}]
{:json-rpc/call [{:method "wakuext_chatsPreview" (json-rpc/call {:method "wakuext_chatsPreview"
:params [] :params []
:js-response true :js-response true
:on-success #(on-success ^js %) :on-success #(on-success ^js %)
:on-error #(log/error "failed to fetch chats" 0 -1 %)}]}) :on-error #(log/error "failed to fetch chats" 0 -1 %)})))

View File

@ -2,6 +2,8 @@
(:require (:require
[clojure.set :as set] [clojure.set :as set]
[clojure.walk :as walk] [clojure.walk :as walk]
[re-frame.core :as re-frame]
[status-im.common.json-rpc.events :as json-rpc]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -32,11 +34,11 @@
:on-success #() :on-success #()
:on-error #()}]}) :on-error #()}]})
(rf/defn fetch-switcher-cards-rpc (re-frame/reg-fx :switcher-cards/fetch
[_] (fn []
{:json-rpc/call [{:method "wakuext_switcherCards" (json-rpc/call {:method "wakuext_switcherCards"
:params [] :params []
:on-success #(rf/dispatch :on-success #(rf/dispatch
[:shell/switcher-cards-loaded [:shell/switcher-cards-loaded
(:switcherCards ^js %)]) (:switcherCards ^js %)])
:on-error #(log/error "Failed to fetch switcher cards" %)}]}) :on-error #(log/error "Failed to fetch switcher cards" %)})))

View File

@ -2,8 +2,8 @@
(:require (:require
[clojure.set :as set] [clojure.set :as set]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[taoensso.timbre :as log] [status-im.common.json-rpc.events :as json-rpc]
[utils.re-frame :as rf])) [taoensso.timbre :as log]))
(defn <-rpc (defn <-rpc
[visibility-status-update] [visibility-status-update]
@ -18,13 +18,13 @@
{:current-user-status :current-user-visibility-status}) {:current-user-status :current-user-visibility-status})
(update :current-user-visibility-status <-rpc))) (update :current-user-visibility-status <-rpc)))
(rf/defn fetch-visibility-status-updates-rpc (re-frame/reg-fx :visibility-status-updates/fetch
[_] (fn []
{:json-rpc/call [{:method "wakuext_statusUpdates" (json-rpc/call {:method "wakuext_statusUpdates"
:params [] :params []
:on-success #(re-frame/dispatch :on-success #(re-frame/dispatch
[:visibility-status-updates/visibility-status-updates-loaded [:visibility-status-updates/visibility-status-updates-loaded
(:statusUpdates ^js %)]) (:statusUpdates ^js %)])
:on-error #(log/error :on-error #(log/error
"failed to fetch visibility-status-updates" "failed to fetch visibility-status-updates"
%)}]}) %)})))

View File

@ -239,7 +239,7 @@
(rf/defn tx-history-end-reached (rf/defn tx-history-end-reached
[{:keys [db] :as cofx} address] [{: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 {:db (assoc-in db
[:wallet-legacy :fetching address :all-fetched?] [:wallet-legacy :fetching address :all-fetched?]
(if syncing-allowed? (if syncing-allowed?
@ -327,7 +327,7 @@
{:chain-tokens (:wallet-legacy/all-tokens db) {:chain-tokens (:wallet-legacy/all-tokens db)
:addresses [address] :addresses [address]
:before-block min-known-block :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 ;; 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 ;; 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 ;; the whole `default-transfers-limit` of transfers the number of transfers already received

View File

@ -8,11 +8,16 @@
legacy.status-im.chat.models.loading legacy.status-im.chat.models.loading
legacy.status-im.contact.block legacy.status-im.contact.block
legacy.status-im.currency.core 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.fleet.core
legacy.status-im.group-chats.core
[legacy.status-im.keycard.core :as keycard] [legacy.status-im.keycard.core :as keycard]
legacy.status-im.log-level.core legacy.status-im.log-level.core
legacy.status-im.mailserver.constants legacy.status-im.mailserver.constants
[legacy.status-im.mailserver.core :as mailserver] [legacy.status-im.mailserver.core :as mailserver]
legacy.status-im.mobile-sync-settings.core
legacy.status-im.multiaccounts.login.core legacy.status-im.multiaccounts.login.core
legacy.status-im.multiaccounts.logout.core legacy.status-im.multiaccounts.logout.core
[legacy.status-im.multiaccounts.model :as multiaccounts.model] [legacy.status-im.multiaccounts.model :as multiaccounts.model]

View File

@ -6,9 +6,9 @@
[legacy.status-im.data-store.invitations :as data-store.invitations] [legacy.status-im.data-store.invitations :as data-store.invitations]
[oops.core :as oops] [oops.core :as oops]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.chat.events :as chat.events] [status-im.contexts.chat.events :as chat.events]
[status-im.contexts.shell.activity-center.events :as activity-center]
[status-im.navigation.events :as navigation] [status-im.navigation.events :as navigation]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -19,15 +19,13 @@
(when (get-in cofx [:db :chats chat-id]) (when (get-in cofx [:db :chats chat-id])
(chat.events/pop-to-root-and-navigate-to-chat cofx chat-id nil))) (chat.events/pop-to-root-and-navigate-to-chat cofx chat-id nil)))
(rf/defn handle-chat-removed (re-frame/reg-event-fx :chat-removed
{:events [:chat-removed]} (fn [{:keys [db]} [response chat-id]]
[cofx response chat-id] {:db (dissoc db :current-chat-id)
(rf/merge cofx :fx [[:dispatch [:shell/close-switcher-card chat-id]]
{:db (dissoc (:db cofx) :current-chat-id) [:dispatch [:sanitize-messages-and-process-response response]]
:dispatch-n [[:shell/close-switcher-card chat-id] [:dispatch [:pop-to-root :shell-stack]]
[:sanitize-messages-and-process-response response] [:activity-center.notifications/fetch-unread-count]]}))
[:pop-to-root :shell-stack]]}
(activity-center/notifications-fetch-unread-count)))
(rf/defn handle-chat-update (rf/defn handle-chat-update
{:events [:chat-updated]} {:events [:chat-updated]}
@ -264,8 +262,7 @@
{} {}
invitations))}) invitations))})
(rf/defn get-group-chat-invitations (re-frame/reg-fx :group-chats/get-group-chat-invitations
[_] (fn []
{:json-rpc/call (json-rpc/call {:method "wakuext_getGroupChatInvitations"
[{:method "wakuext_getGroupChatInvitations" :on-success [::initialize-invitations]})))
:on-success #(re-frame/dispatch [::initialize-invitations %])}]})

View File

@ -5,6 +5,7 @@
[legacy.status-im.node.core :as node] [legacy.status-im.node.core :as node]
[legacy.status-im.utils.mobile-sync :as mobile-network-utils] [legacy.status-im.utils.mobile-sync :as mobile-network-utils]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.navigation.events :as navigation] [status-im.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -61,7 +62,7 @@
(dissoc :mailserver/current-request :mailserver/fetching-gaps-in-progress))}) (dissoc :mailserver/current-request :mailserver/fetching-gaps-in-progress))})
(defn fetch-use-mailservers? (defn fetch-use-mailservers?
[{:keys [db]}] [db]
(get-in db [:profile/profile :use-mailservers?])) (get-in db [:profile/profile :use-mailservers?]))
(defonce showing-connection-error-popup? (atom false)) (defonce showing-connection-error-popup? (atom false))
@ -117,24 +118,32 @@
[{:keys [db] :as cofx}] [{:keys [db] :as cofx}]
{:db (dissoc db :mailserver/current-request)}) {: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 (rf/defn process-next-messages-request
{:events [::request-messages]} {:events [::request-messages]}
[{:keys [db now] :as cofx}] [{:keys [db]}]
(when (and (when (needs-to-fetch-historic-messages? db)
(:messenger/started? db) {:db (assoc db :mailserver/current-request true)
(mobile-network-utils/syncing-allowed? cofx) :mailserver/request-all-historic-messages nil}))
(fetch-use-mailservers? cofx)
(not (:mailserver/current-request db))) (re-frame/reg-fx :mailserver/request-all-historic-messages
{:db (assoc db :mailserver/current-request true) (fn []
:json-rpc/call [{:method "wakuext_requestAllHistoricMessagesWithRetries" (json-rpc/call {:method "wakuext_requestAllHistoricMessagesWithRetries"
:params [false] :params [false]
:js-response true :js-response true
:on-success #(do :on-success #(do
(log/info "fetched historical messages") (log/info "fetched historical messages")
(re-frame/dispatch [::request-success %])) (re-frame/dispatch [::request-success %]))
:on-error #(do :on-error #(do
(log/error "failed retrieve historical messages" %) (log/error "failed retrieve historical messages" %)
(re-frame/dispatch [::request-error]))}]})) (re-frame/dispatch [::request-error]))})))
(rf/defn handle-mailserver-changed (rf/defn handle-mailserver-changed
[{:keys [db] :as cofx} ms] [{:keys [db] :as cofx} ms]

View File

@ -5,7 +5,7 @@
[legacy.status-im.multiaccounts.model :as multiaccounts.model] [legacy.status-im.multiaccounts.model :as multiaccounts.model]
[legacy.status-im.multiaccounts.update.core :as multiaccounts.update] [legacy.status-im.multiaccounts.update.core :as multiaccounts.update]
[legacy.status-im.utils.mobile-sync :as utils] [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] [status-im.navigation.events :as navigation]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -18,27 +18,24 @@
(or (nil? remember-choice?) (or (nil? remember-choice?)
remember-choice?))})) remember-choice?))}))
(rf/defn on-network-status-change (re-frame/reg-event-fx :mobile-network/on-network-status-change
[{:keys [db] :as cofx}] (fn [{:keys [db]}]
(let [initialized? (get db :network-status/initialized?) (let [previously-initialized? (get db :network-status/initialized?)
logged-in? (multiaccounts.model/logged-in? db) logged-in? (multiaccounts.model/logged-in? db)
{:keys [remember-syncing-choice?]} (:profile/profile db)] fetch-historic-messages? (mailserver/needs-to-fetch-historic-messages? db)]
(apply (if logged-in?
rf/merge {:db (cond-> (-> db
cofx (assoc :network-status/initialized? true)
{:db (assoc db :network-status/initialized? true)} (assoc :bottom-sheet/show? false))
(cond fetch-historic-messages?
;; NOTE(rasom): When we log into account on-network-status-change is (assoc :mailserver/current-request true))
;; dispatched, but that doesn't mean there was a status change, thus :fx [(when fetch-historic-messages?
;; no reason to restart wallet. [:mailserver/request-all-historic-messages])
(and logged-in? initialized?) [:dismiss-bottom-sheet-overlay-old]
[(mailserver/process-next-messages-request) (when previously-initialized?
(bottom-sheet/hide-bottom-sheet-old) (let [new-identity-input (get-in db [:contacts/new-identity :input])]
#(add-new-contact/set-new-identity-reconnected %)] [:dispatch [:contacts/set-new-identity {:input new-identity-input}]]))]}
{:db (assoc db :network-status/initialized? true)}))))
logged-in?
[(mailserver/process-next-messages-request)
(bottom-sheet/hide-bottom-sheet-old)]))))
(defn apply-settings (defn apply-settings
([sync?] (apply-settings sync? :default)) ([sync?] (apply-settings sync? :default))

View File

@ -1,7 +1,6 @@
(ns legacy.status-im.network.net-info (ns legacy.status-im.network.net-info
(:require (:require
["@react-native-community/netinfo" :default net-info] ["@react-native-community/netinfo" :default net-info]
[legacy.status-im.mobile-sync-settings.core :as mobile-network]
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -13,11 +12,11 @@
{:db (assoc db :network-status (if is-connected? :online :offline))})) {:db (assoc db :network-status (if is-connected? :online :offline))}))
(rf/defn change-network-type (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 (rf/merge cofx
{:db (assoc db :network/type network-type) {:db (assoc db :network/type network-type)
:network/notify-status-go [network-type expensive?]} :network/notify-status-go [network-type expensive?]
(mobile-network/on-network-status-change))) :dispatch [:mobile-network/on-network-status-change]}))
(rf/defn handle-network-info-change (rf/defn handle-network-info-change
{:events [::network-info-changed]} {:events [::network-info-changed]}
@ -37,7 +36,7 @@
(when-not status-changed? (when-not status-changed?
(change-network-status isConnected)) (change-network-status isConnected))
(when-not type-changed? (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 (defn add-net-info-listener
[] []

View File

@ -2,6 +2,7 @@
(:require (:require
[legacy.status-im.utils.utils :as utils] [legacy.status-im.utils.utils :as utils]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.constants :as constants] [status-im.constants :as constants]
[utils.ethereum.chain :as chain] [utils.ethereum.chain :as chain]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
@ -22,6 +23,21 @@
:params [(chain/chain-id db) id] :params [(chain/chain-id db) id]
:on-success #()}]})) :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 (rf/defn load-packs
{:events [:stickers/load-packs]} {:events [:stickers/load-packs]}
[{:keys [db]}] [{:keys [db]}]

View File

@ -61,7 +61,7 @@
(re-frame/reg-sub (re-frame/reg-sub
:mailserver/use-status-nodes? :mailserver/use-status-nodes?
(fn [db _] (fn [db _]
(boolean (mailserver/fetch-use-mailservers? {:db db})))) (boolean (mailserver/fetch-use-mailservers? db))))
(re-frame/reg-sub (re-frame/reg-sub
:mailserver.edit/validation-errors :mailserver.edit/validation-errors

View File

@ -21,7 +21,7 @@
{:active (= value id) {:active (= value id)
:accessory :radio :accessory :radio
:title (get titles id) :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 (views/defview default-sync-period-settings
[] []

View File

@ -111,7 +111,7 @@
:subtitle (i18n/label :t/webview-camera-permission-requests-subtitle) :subtitle (i18n/label :t/webview-camera-permission-requests-subtitle)
:subtitle-max-lines 2 :subtitle-max-lines 2
:on-press #(re-frame/dispatch :on-press #(re-frame/dispatch
[:profile.settings/update-value [:profile.settings/profile-update
:webview-allow-permission-requests? :webview-allow-permission-requests?
((complement boolean) webview-allow-permission-requests?)])}]) ((complement boolean) webview-allow-permission-requests?)])}])
[separator] [separator]
@ -169,8 +169,7 @@
{:active (= value id) {:active (= value id)
:accessory :radio :accessory :radio
:title (get titles id) :title (get titles id)
:on-press #(re-frame/dispatch [:profile.settings/update-value :profile-pictures-visibility :on-press #(re-frame/dispatch [:profile.settings/profile-update :profile-pictures-visibility id])}])
id])}])
(views/defview profile-pic (views/defview profile-pic
[] []

View File

@ -51,4 +51,4 @@
:icon :main-icons/delete :icon :main-icons/delete
:theme :accent :theme :accent
:title (i18n/label :t/profile-pic-remove) :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])}])]))

View File

@ -10,6 +10,7 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[react-native.mail :as react-native-mail] [react-native.mail :as react-native-mail]
[react-native.platform :as platform] [react-native.platform :as platform]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.common.log :as log] [status-im.common.log :as log]
[status-im.config :as config] [status-im.config :as config]
[utils.datetime :as datetime] [utils.datetime :as datetime]
@ -31,11 +32,10 @@
[{:keys [db]} node-version] [{:keys [db]} node-version]
{:db (assoc db :web3-node-version node-version)}) {:db (assoc db :web3-node-version node-version)})
(rf/defn initialize-web3-client-version (re-frame/reg-fx :logging/initialize-web3-client-version
{:events [:logging/initialize-web3-client-version]} (fn []
[_] (json-rpc/call {:method "web3_clientVersion"
{:json-rpc/call [{:method "web3_clientVersion" :on-success [:logging/store-web3-client-version]})))
:on-success #(re-frame/dispatch [:logging/store-web3-client-version %])}]})
(defn extract-url-components (defn extract-url-components
[address] [address]

View File

@ -5,7 +5,7 @@
(= network-type "cellular")) (= network-type "cellular"))
(defn syncing-allowed? (defn syncing-allowed?
[{:keys [db]}] [db]
(let [network (:network/type db) (let [network (:network/type db)
{:keys [syncing-on-mobile-network?]} (:profile/profile db)] {:keys [syncing-on-mobile-network?]} (:profile/profile db)]
(or (= network "wifi") (or (= network "wifi")

View File

@ -4,9 +4,7 @@
[clojure.string :as string] [clojure.string :as string]
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.config :as config]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.re-frame :as rf]
[utils.transforms :as transforms])) [utils.transforms :as transforms]))
(def logs-queue (atom #queue [])) (def logs-queue (atom #queue []))
@ -52,9 +50,3 @@
:logs/set-level :logs/set-level
(fn [level] (fn [level]
(setup 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}))

View File

@ -7,7 +7,6 @@
[status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview] [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.chat.messenger.messages.transport.events :as messages.transport]
[status-im.contexts.communities.discover.events] [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] [status-im.contexts.profile.push-notifications.local.events :as local-notifications]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.re-frame :as rf] [utils.re-frame :as rf]
@ -37,7 +36,9 @@
^js event-js (.-event data) ^js event-js (.-event data)
type (.-type data)] type (.-type data)]
(case type (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 "backup.performed" {:db (assoc-in db
[:profile/profile :last-backup] [:profile/profile :last-backup]
(.-lastBackup event-js))} (.-lastBackup event-js))}

View File

@ -1,6 +1,8 @@
(ns status-im.contexts.chat.contacts.events (ns status-im.contexts.chat.contacts.events
(:require (:require
[oops.core :as oops] [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.constants :as constants]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.i18n :as i18n] [utils.i18n :as i18n]
@ -64,18 +66,21 @@
(when (> (count events) 1) (when (> (count events) 1)
{:dispatch-n events})))) {:dispatch-n events}))))
(rf/defn initialize-contacts (re-frame/reg-event-fx :contacts/contacts-loaded
[_] (fn [{:keys [db]} [loaded-contacts]]
{:json-rpc/call [{:method "wakuext_contacts" (let [contacts (->> loaded-contacts
:params [] (map <-rpc-js)
:js-response true (mapv (fn [{:keys [public-key] :as contact}] [public-key contact]))
:on-success #(rf/dispatch [:contacts/contacts-loaded (map <-rpc-js %)]) (into {}))]
:on-error #(log/error "failed to fetch contacts" %)}]}) {:db (assoc db :contacts/contacts contacts)})))
(rf/defn contacts-loaded (re-frame/reg-fx :contacts/initialize-contacts
{:events [:contacts/contacts-loaded]} (fn []
[{:keys [db]} contacts] (json-rpc/call {:method "wakuext_contacts"
{:db (assoc db :contacts/contacts (into {} (map #(vector (:public-key %) %) contacts)))}) :params []
:js-response true
:on-success [:contacts/contacts-loaded]
:on-error #(log/error "failed to fetch contacts" %)})))
(defn send-contact-request (defn send-contact-request
[{:keys [db]} [id message]] [{:keys [db]} [id message]]

View File

@ -186,9 +186,3 @@
{:db (dissoc db :contacts/new-identity)}) {:db (dissoc db :contacts/new-identity)})
(re-frame/reg-event-fx :contacts/clear-new-identity clear-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}])))

View File

@ -1,79 +1,65 @@
(ns status-im.contexts.chat.messenger.messages.link-preview.events (ns status-im.contexts.chat.messenger.messages.link-preview.events
(:require (:require [camel-snake-kebab.core :as csk]
[camel-snake-kebab.core :as csk] [status-im.common.json-rpc.events :as json-rpc]
[status-im.contexts.profile.settings.events :as profile.settings.events] [taoensso.timbre :as log]
[taoensso.timbre :as log] [utils.collection]
[utils.collection] [utils.re-frame :as rf]))
[utils.re-frame :as rf]))
(defn community-link (defn community-link
[id] [id]
(str "https://status.app/c#" id)) (str "https://status.app/c#" id))
(rf/defn cache-link-preview-data (rf/reg-event-fx :chat.ui/cache-link-preview-data
{:events [:chat.ui/cache-link-preview-data]} (fn [{:keys [db]} [site data]]
[{{:profile/keys [profile]} :db :as cofx} site data] (let [{:profile/keys [profile]} db
(let [link-previews-cache (get profile :link-previews-cache {})] link-previews-cache (-> profile
(profile.settings.events/optimistic-profile-update (get :link-previews-cache {})
cofx (assoc site
:link-previews-cache (utils.collection/map-keys csk/->kebab-case-keyword
(assoc link-previews-cache site (utils.collection/map-keys csk/->kebab-case-keyword data))))) data)))]
{:db (assoc-in db [:profile/profile :link-previews-cache] link-previews-cache)})))
(rf/defn load-link-preview-data (rf/reg-event-fx :chat.ui/load-link-preview-data
{:events [:chat.ui/load-link-preview-data]} (fn [{{:profile/keys [profile]} :db} [link]]
[{{:profile/keys [profile] :as db} :db} link] (let [{:keys [error] :as cache-data} (get-in profile [:link-previews-cache link])]
(let [{:keys [error] :as cache-data} (get-in profile [:link-previews-cache link])] (when (or (not cache-data) error)
(if (or (not cache-data) error) {:fx [[:json-rpc/call
{:json-rpc/call [{:method "wakuext_getLinkPreviewData" [{:method "wakuext_getLinkPreviewData"
:params [link] :params [link]
:on-success #(rf/dispatch [:chat.ui/cache-link-preview-data link %]) :on-success [:chat.ui/cache-link-preview-data link]
:on-error #(rf/dispatch [: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)}])}]} {:error (str "Can't get preview data for " link)}]}]]]}))))
{:db db})))
(rf/defn should-suggest-link-preview (rf/reg-event-fx :chat.ui/should-suggest-link-preview
{:events [:chat.ui/should-suggest-link-preview]} (fn [_ [enabled?]]
[{:keys [db] :as cofx} enabled?] {:fx [[:dispatch
(profile.settings.events/profile-update [:profile.settings/profile-update :link-preview-request-enabled (boolean enabled?)]]]}))
cofx
:link-preview-request-enabled
(boolean enabled?)
{}))
(rf/defn save-link-preview-whitelist (rf/reg-event-fx :chat.ui/link-preview-whitelist-received
{:events [:chat.ui/link-preview-whitelist-received]} (fn [{:keys [db]} [whitelist]]
[{:keys [db]} whitelist] {:db (assoc db :link-previews-whitelist whitelist)}))
{:db (assoc db :link-previews-whitelist whitelist)})
(rf/defn request-link-preview-whitelist (rf/reg-fx :chat.ui/request-link-preview-whitelist
[_] (fn []
{:json-rpc/call [{:method "wakuext_getLinkPreviewWhitelist" (json-rpc/call {:method "wakuext_getLinkPreviewWhitelist"
:params [] :params []
:on-success #(rf/dispatch [:chat.ui/link-preview-whitelist-received %]) :on-success [:chat.ui/link-preview-whitelist-received]
:on-error #(log/error "Failed to get link preview whitelist")}]}) :on-error #(log/error "Failed to get link preview whitelist")})))
(defn cache-community-preview-data (defn cache-community-preview-data
[{:keys [id] :as community}] [{:keys [id] :as community}]
(rf/dispatch [:chat.ui/cache-link-preview-data (community-link id) community])) (rf/dispatch [:chat.ui/cache-link-preview-data (community-link id) community]))
(rf/defn enable (rf/reg-event-fx :chat.ui/enable-link-previews
{:events [:chat.ui/enable-link-previews]} (fn [{{:profile/keys [profile]} :db} [site enabled?]]
[{{:profile/keys [profile]} :db :as cofx} site enabled?] (let [enabled-sites (if enabled?
(profile.settings.events/profile-update (conj (get profile :link-previews-enabled-sites #{}) site)
cofx (disj (get profile :link-previews-enabled-sites #{}) site))]
:link-previews-enabled-sites {:fx [[:dispatch [:profile.settings/profile-update :link-previews-enabled-sites enabled-sites]]]})))
(if enabled?
(conj (get profile :link-previews-enabled-sites #{}) site)
(disj (get profile :link-previews-enabled-sites #{}) site))
{}))
(rf/defn enable-all (rf/reg-event-fx :chat.ui/enable-all-link-previews
{:events [:chat.ui/enable-all-link-previews]} (fn [_ [link-previews-whitelist enabled?]]
[cofx link-previews-whitelist enabled?] (let [enabled-sites (if enabled?
(profile.settings.events/profile-update (into #{} (map :title link-previews-whitelist))
cofx #{})]
:link-previews-enabled-sites {:fx [[:dispatch [:profile.settings/profile-update :link-previews-enabled-sites enabled-sites]]]})))
(if enabled?
(into #{} (map :title link-previews-whitelist))
#{})
{}))

View File

@ -2,8 +2,8 @@
(:require (:require
[clojure.string :as string] [clojure.string :as string]
[native-module.core :as native-module] [native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.config :as config] [status-im.config :as config]
[utils.re-frame :as rf]
[utils.transforms :as transforms])) [utils.transforms :as transforms]))
(defn login (defn login
@ -51,14 +51,14 @@
(when path (when path
(string/replace-first path "file://" ""))) (string/replace-first path "file://" "")))
(rf/defn get-node-config-callback (re-frame/reg-event-fx :profile.config/get-node-config-callback
{:events [:profile.config/get-node-config-callback]} (fn [{:keys [db]} [node-config-json]]
[{:keys [db]} node-config-json] (let [node-config (transforms/json->clj node-config-json)]
(let [node-config (transforms/json->clj node-config-json)] {:db (assoc-in db
{:db (assoc-in db [:profile/profile :wakuv2-config]
[:profile/profile :wakuv2-config] (get node-config :WakuV2Config))})))
(get node-config :WakuV2Config))}))
(rf/defn get-node-config (re-frame/reg-fx :profile.config/get-node-config
[_] (fn []
(native-module/get-node-config #(rf/dispatch [:profile.config/get-node-config-callback %]))) (native-module/get-node-config
#(re-frame/dispatch [:profile.config/get-node-config-callback %]))))

View File

@ -2,37 +2,21 @@
(:require (:require
[legacy.status-im.data-store.settings :as data-store.settings] [legacy.status-im.data-store.settings :as data-store.settings]
[native-module.core :as native-module] [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.accent-colour.events]
[status-im.contexts.profile.edit.bio.events] [status-im.contexts.profile.edit.bio.events]
[status-im.contexts.profile.edit.header.events] [status-im.contexts.profile.edit.header.events]
[status-im.contexts.profile.edit.name.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.contexts.profile.rpc :as profile.rpc]
[status-im.navigation.events :as navigation]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(re-frame/reg-fx (defn- select-profile
:profile/get-profiles-overview [profile key-uid]
(fn [callback] (-> profile
(native-module/open-accounts callback))) (assoc :key-uid key-uid)
(dissoc :error :password)))
(rf/defn profile-selected (defn- reduce-profiles
{: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
[profiles] [profiles]
(reduce (reduce
(fn [acc {:keys [key-uid] :as profile}] (fn [acc {:keys [key-uid] :as profile}]
@ -40,28 +24,44 @@
{} {}
profiles)) profiles))
(rf/defn get-profiles-overview-success (rf/reg-fx
{:events [:profile/get-profiles-overview-success]} :profile/get-profiles-overview
[cofx profiles-overview] (fn [callback]
(if (seq profiles-overview) (native-module/open-accounts callback)))
(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/defn update-setting-from-backup (rf/reg-event-fx
{:events [:profile/update-setting-from-backup]} :profile/profile-selected
[{:keys [db]} {:keys [backedUpSettings]}] (fn [{:keys [db]} [key-uid]]
(let [setting (update backedUpSettings :name keyword) {:db (update db :profile/login #(select-profile % key-uid))}))
{:keys [name value]} (data-store.settings/rpc->setting-value setting)]
{:db (assoc-in db [:profile/profile name] value)}))
(rf/defn update-profile-from-backup (rf/reg-event-fx
{:events [:profile/update-profile-from-backup]} :profile/get-profiles-overview-success
[_ {{:keys [ensUsernameDetails]} :backedUpProfile}] (fn [{:keys [db]} [profiles-overview]]
{:dispatch [:ens/update-usernames ensUsernameDetails]}) (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]]]}))

View File

@ -1,210 +1,188 @@
(ns status-im.contexts.profile.login.events (ns status-im.contexts.profile.login.events
(:require (: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.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.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] [native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.common.keychain.events :as keychain] [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.config :as config]
[status-im.contexts.chat.contacts.events :as contacts] [status-im.constants :as constants]
[status-im.contexts.chat.messenger.messages.link-preview.events :as link-preview]
[status-im.contexts.profile.config :as profile.config]
status-im.contexts.profile.login.effects 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.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] [taoensso.timbre :as log]
[utils.ethereum.chain :as chain]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[utils.security.core :as security])) [utils.security.core :as security]))
(rf/defn login (rf/reg-event-fx :profile.login/login
{:events [:profile.login/login]} (fn [{:keys [db]}]
[{:keys [db]}] (let [{:keys [key-uid password]} (:profile/login db)
(let [{:keys [key-uid password]} (:profile/login db) login-sha3-password (native-module/sha3 (security/safe-unmask-data password))]
login-sha3-password (native-module/sha3 (security/safe-unmask-data password))] {:db (-> db
{:db (-> db (assoc-in [:profile/login :processing] true)
(assoc-in [:profile/login :processing] true) (assoc-in [:syncing :login-sha3-password] login-sha3-password))
(assoc-in [:syncing :login-sha3-password] login-sha3-password)) :fx [[:effects.profile/login [key-uid login-sha3-password]]]})))
:effects.profile/login [key-uid login-sha3-password]}))
(rf/defn biometrics-login (rf/reg-event-fx :profile.login/local-paired-user
{:events [:profile.login/biometrics-login]} (fn [{:keys [db]}]
[{:keys [db]}] (let [{:keys [key-uid password]} (get-in db [:syncing :profile])
(let [{:keys [key-uid password]} (:profile/login db)] login-sha3-password (get-in db [:syncing :login-sha3-password])
{:db (assoc-in db [:profile/login :processing] true) password (if-not (nil? login-sha3-password) ;; already logged in
:effects.profile/login [key-uid (security/safe-unmask-data password)]})) 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 ;; login phase 1: we want to load and show chats faster, so we split login into 2 phases
{:events [:profile.login/local-paired-user]} (rf/reg-event-fx :profile.login/login-existing-profile
[{:keys [db]}] (fn [{:keys [db]} [settings account]]
(let [{:keys [key-uid password]} (get-in db [:syncing :profile]) (let [{:networks/keys [current-network networks]
login-sha3-password (get-in db [:syncing :login-sha3-password]) :as settings}
password (if-not (nil? login-sha3-password) ;; already logged in (data-store.settings/rpc->settings settings)
login-sha3-password profile-overview (profile.rpc/rpc->profiles-overview account)
password) log-level (or (:log-level settings) config/log-level)
masked-password (security/mask-data password)] pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed)]
{:db (-> db {:db (cond-> (-> db
(assoc-in [:onboarding/profile :password] masked-password) (assoc :chats/loading? true
(assoc-in [:onboarding/profile :syncing?] true)) :networks/current-network current-network
:effects.profile/login [key-uid password]})) :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 (cond
[{:keys [db] :as cofx}] pairing-completed?
(let [pairing-completed? (= (get-in db [:syncing :pairing-status]) :completed)] [[:set-root :syncing-results]]
(cond
pairing-completed?
{:db (dissoc db :syncing)
:dispatch [:init-root :syncing-results]}
(get db :onboarding/new-account?) (get db :onboarding/new-account?)
{:dispatch [:onboarding/finalize-setup]} [[:dispatch [:onboarding/finalize-setup]]]
:else :else
(rf/merge [[:profile.settings/switch-theme-fx
cofx [(or (get-in db [:profile/profile :appearance])
(profile.settings.events/switch-theme nil :shell-stack) constants/theme-type-dark)
(navigation/init-root :shell-stack))))) :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 ;; login phase 2: we want to load and show chats faster, so we split login into 2 phases
(rf/defn login-existing-profile (rf/reg-event-fx :profile.login/get-chats-callback
[{:keys [db] :as cofx} settings account] (fn [{:keys [db]}]
(let [{:networks/keys [current-network networks] (let [{:networks/keys [current-network networks]} db
:as settings} {:keys [notifications-enabled? key-uid
(data-store.settings/rpc->settings settings) preview-privacy?]} (:profile/profile db)
profile-overview (profile.rpc/rpc->profiles-overview account)] network-id (str (get-in networks
(rf/merge cofx [current-network :config :NetworkId]))]
{:db (-> db {:db db
(assoc :chats/loading? true :fx [[:json-rpc/call
:networks/current-network current-network [{:method "wakuext_startMessenger"
:networks/networks (merge networks config/default-networks-by-id) :on-success [:profile.login/messenger-started]
:profile/profile (merge profile-overview settings))) :on-error #(log/error
:fx [[:dispatch [:universal-links/generate-profile-url]] "failed to start messenger")}]]
[:dispatch [:community/fetch]] [:check-eip1559-activation {:network-id network-id}]
[:dispatch [:wallet/initialize]]]} [:effects.profile/enable-local-notifications]
(notifications/load-preferences) [:contacts/initialize-contacts]
(data-store.chats/fetch-chats-preview [:browser/initialize-browser]
{:on-success [:dispatch [:mobile-network/on-network-status-change]]
#(do (re-frame/dispatch [:chats-list/load-success %]) [:group-chats/get-group-chat-invitations]
(rf/dispatch [:communities/get-user-requests-to-join]) [:profile.settings/get-profile-picture key-uid]
(re-frame/dispatch [:profile.login/get-chats-callback]))}) [:profile.settings/blank-preview-flag-changed preview-privacy?]
(profile.config/get-node-config) [:chat.ui/request-link-preview-whitelist]
(logging/set-log-level (:log-level settings)) [:visibility-status-updates/fetch]
(activity-center/notifications-fetch-pending-contact-requests) [:switcher-cards/fetch]
(activity-center/update-seen-state) (when-not (:universal-links/handling db)
(activity-center/notifications-fetch-unread-count) [:effects.chat/open-last-chat key-uid])
(redirect-to-root)))) (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/reg-event-fx :profile.login/messenger-started
(rf/defn get-chats-callback (fn [{:keys [db]} [{:keys [mailservers]}]]
{:events [:profile.login/get-chats-callback]} (let [chain-id (chain/chain-id db)
[{:keys [db] :as cofx}] new-account? (get db :onboarding/new-account?)]
(let [{:networks/keys [current-network networks]} db {:db (-> db
{:keys [notifications-enabled?]} (:profile/profile db) (assoc :messenger/started? true)
current-network-config (get networks current-network) (mailserver/add-mailservers mailservers))
network-id (str (get-in networks :fx [[:json-rpc/call
[current-network :config :NetworkId]))] [{:method "admin_nodeInfo"
(rf/merge :on-success [:profile.login/node-info-fetched]
cofx :on-error #(log/error "node-info: failed error" %)}]]
(cond-> {:json-rpc/call [{:method "wakuext_startMessenger" [:pairing/get-our-installations]
:on-success #(re-frame/dispatch [:stickers/load-packs chain-id]
[:messenger-started %]) (when-not new-account?
:on-error #(log/error [:dispatch [:universal-links/process-stored-event]])]})))
"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/defn messenger-started (rf/reg-event-fx :profile.login/node-info-fetched
{:events [:messenger-started]} (fn [{:keys [db]} [node-info]]
[{:keys [db] :as cofx} {:keys [mailservers] :as response}] {:db (assoc db :node-info node-info)}))
(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/defn set-node-info (rf/reg-event-fx
{:events [:node-info-fetched]} :profile.login/login-node-signal
[{:keys [db]} node-info] (fn [{{:onboarding/keys [recovered-account? new-account?] :as db} :db}
{:db (assoc db :node-info node-info)}) [{: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 (rf/reg-event-fx
[{{:onboarding/keys [recovered-account? new-account?] :as db} :db :as cofx} :profile.login/login-with-biometric-if-available
{:keys [settings account ensUsernames error]}] (fn [_ [key-uid]]
(log/debug "[signals] node.login" "error" error) {:fx [[:effects.biometric/check-if-available
(if error {:key-uid key-uid
{:db (update db :profile/login #(-> % (dissoc :processing) (assoc :error error)))} :on-success (fn [auth-method]
(rf/merge cofx (rf/dispatch
{:db (dissoc db :profile/login) [:profile.login/check-biometric-success
:dispatch-n [[:logging/initialize-web3-client-version] key-uid auth-method]))}]]}))
(when (and new-account? (not recovered-account?))
[:wallet-legacy/set-initial-blocks-range])
[:ens/update-usernames ensUsernames]]}
(login-existing-profile settings account))))
(rf/defn login-with-biometric-if-available (rf/reg-event-fx
{:events [:profile.login/login-with-biometric-if-available]} :profile.login/check-biometric-success
[_ key-uid] (fn [{:keys [db]} [key-uid auth-method]]
{:effects.biometric/check-if-available {:key-uid key-uid {:db (assoc db :auth-method auth-method)
:on-success (fn [auth-method] :fx [(when (= auth-method keychain/auth-method-biometric)
(rf/dispatch [:keychain/password-hash-migration
[: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
{:key-uid key-uid {:key-uid key-uid
:callback (fn [] :callback (fn []
(rf/dispatch [:biometric/authenticate (rf/dispatch
{:on-success #(rf/dispatch [:profile.login/biometric-success]) [:biometric/authenticate
:on-fail #(rf/dispatch {:on-success #(rf/dispatch
[:profile.login/biometric-auth-fail %])}]))}}))) [:profile.login/biometric-success])
:on-fail #(rf/dispatch
[:profile.login/biometric-auth-fail %])}]))}])]}))
(rf/defn get-user-password-success (rf/reg-event-fx
{:events [:profile.login/get-user-password-success]} :profile.login/get-user-password-success
[{:keys [db] :as cofx} password] (fn [{:keys [db]} [password]]
(when password (when password
(rf/merge (let [{:keys [key-uid password]} (:profile/login db)]
cofx {:db (-> db
{:db (assoc-in db [:profile/login :password] password)} (assoc-in [:profile/login :password] password)
(navigation/init-root :progress) (assoc-in [:profile/login :processing] true))
(biometrics-login)))) :fx [[:set-root :progress]
[:effects.profile/login [key-uid (security/safe-unmask-data password)]]]}))))
(rf/reg-event-fx (rf/reg-event-fx
:profile.login/biometric-success :profile.login/biometric-success
@ -223,35 +201,35 @@
:event :profile.login/biometric-auth-fail))) :event :profile.login/biometric-auth-fail)))
{:dispatch [:biometric/show-message (ex-cause error)]})) {:dispatch [:biometric/show-message (ex-cause error)]}))
(rf/defn verify-database-password (rf/reg-event-fx
{:events [:profile.login/verify-database-password]} :profile.login/verify-database-password
[_ entered-password cb] (fn [_ [entered-password cb]]
(let [hashed-password (-> entered-password (let [hashed-password (-> entered-password
security/safe-unmask-data security/safe-unmask-data
native-module/sha3)] native-module/sha3)]
{:json-rpc/call [{:method "accounts_verifyPassword" {:json-rpc/call [{:method "accounts_verifyPassword"
:params [hashed-password] :params [hashed-password]
:on-success #(rf/dispatch [:profile.login/verified-database-password % cb]) :on-success #(rf/dispatch [:profile.login/verified-database-password % cb])
:on-error #(log/error "accounts_verifyPassword error" %)}]})) :on-error #(log/error "accounts_verifyPassword error" %)}]})))
(rf/defn verify-database-password-success (rf/reg-event-fx
{:events [:profile.login/verified-database-password]} :profile.login/verified-database-password
[{:keys [db]} valid? callback] (fn [{:keys [db]} [valid? callback]]
(if valid? (if valid?
(do (do
(when (fn? callback) (when (fn? callback)
(callback)) (callback))
{:db (update db {:db (update db
:profile/login :profile/login
dissoc dissoc
:processing :error)}) :processing :error)})
{:db (update db {:db (update db
:profile/login :profile/login
#(-> % #(-> %
(dissoc :processing) (dissoc :processing)
(assoc :error "Invalid password")))})) (assoc :error "Invalid password")))})))
(re-frame/reg-event-fx (rf/reg-event-fx
:profile/on-password-input-changed :profile/on-password-input-changed
(fn [{:keys [db]} [{:keys [password error]}]] (fn [{:keys [db]} [{:keys [password error]}]]
{:db (update db :profile/login assoc :password password :error error)})) {:db (update db :profile/login assoc :password password :error error)}))

View File

@ -2,9 +2,11 @@
(:require (:require
[cljs-bean.core :as bean] [cljs-bean.core :as bean]
[native-module.push-notifications :as native-module.pn] [native-module.push-notifications :as native-module.pn]
[re-frame.core :as re-frame]
[react-native.async-storage :as async-storage] [react-native.async-storage :as async-storage]
[react-native.platform :as platform] [react-native.platform :as platform]
[react-native.push-notification-ios :as pn-ios] [react-native.push-notification-ios :as pn-ios]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.config :as config] [status-im.config :as config]
status-im.contexts.profile.push-notifications.effects status-im.contexts.profile.push-notifications.effects
[taoensso.timbre :as log] [taoensso.timbre :as log]
@ -55,8 +57,8 @@
[{:keys [db]} preferences] [{:keys [db]} preferences]
{:db (assoc db :push-notifications/preferences preferences)}) {:db (assoc db :push-notifications/preferences preferences)})
(rf/defn load-preferences (re-frame/reg-fx :push-notifications/load-preferences
[_] (fn []
{:json-rpc/call [{:method "localnotifications_notificationPreferences" (json-rpc/call {:method "localnotifications_notificationPreferences"
:params [] :params []
:on-success #(rf/dispatch [:push-notifications/preferences-loaded %])}]}) :on-success [:push-notifications/preferences-loaded]})))

View File

@ -1,63 +1,47 @@
(ns status-im.contexts.profile.settings.events (ns status-im.contexts.profile.settings.events
(:require [clojure.string :as string] (:require [clojure.string :as string]
[legacy.status-im.bottom-sheet.events :as bottom-sheet.events] [status-im.common.json-rpc.events :as json-rpc]
[re-frame.core :as re-frame]
[status-im.constants :as constants] [status-im.constants :as constants]
status-im.contexts.profile.settings.effects status-im.contexts.profile.settings.effects
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(rf/defn send-contact-update (defn- set-setting-value
[{:keys [db]}] [db setting setting-value]
(let [{:keys [name preferred-name display-name]} (:profile/profile db)] (if setting-value
{:json-rpc/call [{:method "wakuext_sendContactUpdates" (assoc-in db [:profile/profile setting] setting-value)
:params [(or preferred-name display-name name) ""] (update db :profile/profile dissoc setting)))
:on-success #(log/debug "sent contact update")}]}))
(rf/defn profile-update (rf/reg-event-fx :profile.settings/profile-update
{:events [:profile.settings/profile-update]} (fn [{:keys [db]} [setting setting-value {:keys [dont-sync? on-success]}]]
[{:keys [db] :as cofx} {:db (-> db
setting setting-value (set-setting-value setting setting-value))
{:keys [dont-sync? on-success] :or {on-success #()}}] :fx [[:json-rpc/call
(rf/merge [{:method "settings_saveSetting"
cofx :params [setting setting-value]
{:db (if setting-value :on-success on-success}]]
(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}]}
(when (#{:name :preferred-name} setting) (when (#{:name :preferred-name} setting)
(constantly {:profile/get-profiles-overview #(rf/dispatch [:multiaccounts.ui/update-name %])})) [:profile/get-profiles-overview #(rf/dispatch [:multiaccounts.ui/update-name %])])
(when (and (not dont-sync?) (#{:name :preferred-name} setting)) (when (and (not dont-sync?) (#{:name :preferred-name} setting))
(send-contact-update)))) (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 (rf/reg-event-fx :profile.settings/change-preview-privacy
[{:keys [db]} setting setting-value] (fn [{:keys [db]}]
{:db (if setting-value (let [private? (get-in db [:profile/profile :preview-privacy?])]
(assoc-in db [:profile/profile setting] setting-value) {:fx [[:profile.settings/blank-preview-flag-changed private?]]})))
(update db :profile/profile dissoc setting))})
(rf/defn change-preview-privacy (rf/reg-event-fx :profile.settings/change-webview-debug
[{:keys [db]}] (fn [_ [value]]
(let [private? (get-in db [:profile/profile :preview-privacy?])] (let [value' (boolean value)]
{:profile.settings/blank-preview-flag-changed private?})) {:fx [[:dispatch [:profile.settings/profile-update :webview-debug value']]
[:profile.settings/webview-debug-changed value']]})))
(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/toggle-test-networks (rf/reg-event-fx :profile.settings/toggle-test-networks
(fn [{:keys [db]}] (fn [{:keys [db]}]
@ -82,17 +66,22 @@
{:on-success on-success}]) {:on-success on-success}])
:on-cancel nil}]]}))) :on-cancel nil}]]})))
(rf/defn change-preview-privacy-flag (rf/reg-event-fx :profile.settings/change-preview-privacy
{:events [:profile.settings/change-preview-privacy]} (fn [_ [private?]]
[{:keys [db] :as cofx} private?] (let [private?' (boolean private?)]
(rf/merge cofx {:fx [[:dispatch [:profile.settings/profile-update :preview-privacy? private?']]
{:profile.settings/blank-preview-flag-changed private?} [:profile.settings/blank-preview-flag-changed private?']]})))
(profile-update
:preview-privacy?
(boolean 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]}] (fn [{:keys [db]}]
(let [value (get-in db [:profile/profile :peer-syncing-enabled?]) (let [value (get-in db [:profile/profile :peer-syncing-enabled?])
new-value (not value)] new-value (not value)]
@ -102,81 +91,69 @@
:params [{:enabled new-value}] :params [{:enabled new-value}]
:on-error #(log/error "failed to toggle peer syncing" new-value %)}]]]}))) :on-error #(log/error "failed to toggle peer syncing" new-value %)}]]]})))
(rf/defn change-profile-pictures-show-to (rf/reg-event-fx :profile.settings/change-appearance
{:events [:profile.settings/change-profile-pictures-show-to]} (fn [_ [theme]]
[cofx id] {:fx [[:dispatch [:profile.settings/profile-update :appearance theme]]
(rf/merge cofx [:profile.settings/switch-theme-fx [theme :appearance true]]]}))
{: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/defn change-appearance (rf/reg-event-fx :profile.settings/switch-theme
{:events [:profile.settings/change-appearance]} (fn [{:keys [db]} [theme view-id]]
[cofx theme] (let [theme (or theme
(rf/merge cofx (get-in db [:profile/profile :appearance])
{:profile.settings/switch-theme-fx [theme :appearance true]} constants/theme-type-dark)]
(profile-update :appearance theme {}))) {:fx [[:profile.settings/switch-theme-fx [theme view-id false]]]})))
(rf/defn switch-theme (rf/reg-fx :profile.settings/get-profile-picture
{:events [:profile.settings/switch-theme]} (fn [key-uid]
[cofx theme view-id] (json-rpc/call {:method "multiaccounts_getIdentityImages"
(let [theme (or theme :params [key-uid]
(get-in cofx [:db :profile/profile :appearance]) :on-success [:profile.settings/update-local-picture]})))
constants/theme-type-dark)]
{:profile.settings/switch-theme-fx [theme view-id false]}))
(rf/defn get-profile-picture (rf/reg-event-fx :profile.settings/save-profile-picture
{:events [:profile.settings/get-profile-picture]} (fn [{:keys [db]} [path ax ay bx by]]
[cofx] (let [key-uid (get-in db [:profile/profile :key-uid])]
(let [key-uid (get-in cofx [:db :profile/profile :key-uid])] {:db (-> db
{:json-rpc/call [{:method "multiaccounts_getIdentityImages" (assoc :bottom-sheet/show? false))
:params [key-uid] :fx [[:json-rpc/call
:on-success [:profile.settings/update-local-picture]}]})) [{: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 (rf/reg-event-fx :profile.settings/save-profile-picture-from-url
{:events [:profile.settings/save-profile-picture]} (fn [{:keys [db]} [url]]
[cofx path ax ay bx by] (let [key-uid (get-in db [:profile/profile :key-uid])]
(let [key-uid (get-in cofx [:db :profile/profile :key-uid])] {:db (-> db
(rf/merge cofx (assoc :bottom-sheet/show? false))
{:json-rpc/call [{:method "multiaccounts_storeIdentityImage" :fx [[:json-rpc/call
:params [key-uid (string/replace-first path #"file://" "") ax ay bx [{:method "multiaccounts_storeIdentityImageFromURL"
by] :params [key-uid url]
:on-success [:profile.settings/update-local-picture]}]} :on-error #(log/error "::save-profile-picture-from-url error" %)
(bottom-sheet.events/hide-bottom-sheet-old)))) :on-success [:profile.settings/update-local-picture]}]]
[:dismiss-bottom-sheet-overlay-old]]})))
(rf/defn save-profile-picture-from-url (rf/reg-event-fx :profile.settings/delete-profile-picture
{:events [:profile.settings/save-profile-picture-from-url]} (fn [{:keys [db]}]
[cofx url] (let [key-uid (get-in db [:profile/profile :key-uid])]
(let [key-uid (get-in cofx [:db :profile/profile :key-uid])] {:db (-> db
(rf/merge cofx (update :profile/profile dissoc :images)
{:json-rpc/call [{:method "multiaccounts_storeIdentityImageFromURL" (assoc :bottom-sheet/show? false))
:params [key-uid url] :fx [[:json-rpc/call
:on-error #(log/error "::save-profile-picture-from-url error" %) [{:method "multiaccounts_deleteIdentityImage"
:on-success [:profile.settings/update-local-picture]}]} :params [key-uid]
(bottom-sheet.events/hide-bottom-sheet-old)))) ;; 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 (rf/reg-event-fx :profile.settings/update-local-picture
{:events [:profile.settings/delete-profile-picture]} (fn [{:keys [db]} [images]]
[cofx name] {:db (assoc-in db [:profile/profile :images] images)}))
(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/defn store-profile-picture (rf/reg-event-fx :profile.settings/mnemonic-was-shown
{:events [:profile.settings/update-local-picture]} (fn [_]
[cofx pics] {:fx [[:json-rpc/call
(optimistic-profile-update cofx :images pics)) [{:method "settings_mnemonicWasShown"
:on-success #(log/debug "mnemonic was marked as shown")
(rf/defn mark-mnemonic-as-shown :on-error #(log/error "mnemonic was not marked 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" %)}]})

View File

@ -4,6 +4,7 @@
[legacy.status-im.data-store.chats :as data-store.chats] [legacy.status-im.data-store.chats :as data-store.chats]
[quo.foundations.colors :as colors] [quo.foundations.colors :as colors]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.common.json-rpc.events :as json-rpc]
[status-im.common.toasts.events :as toasts] [status-im.common.toasts.events :as toasts]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.contexts.shell.activity-center.notification-types :as types] [status-im.contexts.shell.activity-center.notification-types :as types]
@ -408,6 +409,17 @@
(constantly processed) (constantly processed)
#(concat % 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 (rf/defn notifications-fetch-pending-contact-requests
"Unread contact requests are, in practical terms, the same as pending contact "Unread contact requests are, in practical terms, the same as pending contact
requests in the Activity Center, because pending contact requests are always requests in the Activity Center, because pending contact requests are always
@ -419,14 +431,7 @@
{:events [:activity-center.notifications/fetch-pending-contact-requests]} {:events [:activity-center.notifications/fetch-pending-contact-requests]}
[{:keys [db]}] [{:keys [db]}]
{:db (assoc-in db [:activity-center :loading?] true) {:db (assoc-in db [:activity-center :loading?] true)
:json-rpc/call :fx [[:activity-center.notifications/fetch-pending-contact-requests-fx]]})
[{: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-success (rf/defn notifications-fetch-pending-contact-requests-success
{:events [:activity-center.notifications/fetch-pending-contact-requests-success]} {:events [:activity-center.notifications/fetch-pending-contact-requests-success]}
@ -448,14 +453,12 @@
;;;; Unread counters ;;;; Unread counters
(rf/defn update-seen-state (re-frame/reg-fx :activity-center/update-seen-state
{:events [:activity-center/update-seen-state]} (fn []
[_] (json-rpc/call [{:method "wakuext_hasUnseenActivityCenterNotifications"
{:json-rpc/call :params []
[{:method "wakuext_hasUnseenActivityCenterNotifications" :on-success [:activity-center/update-seen-state-success]
:params [] :on-error [:activity-center/update-seen-state-error]}])))
:on-success [:activity-center/update-seen-state-success]
:on-error [:activity-center/update-seen-state-error]}]})
(rf/defn update-seen-state-success (rf/defn update-seen-state-success
{:events [:activity-center/update-seen-state-success]} {:events [:activity-center/update-seen-state-success]}
@ -492,6 +495,14 @@
{:error error {:error error
:event :activity-center/mark-as-seen})) :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 (rf/defn notifications-fetch-unread-count
{:events [:activity-center.notifications/fetch-unread-count]} {:events [:activity-center.notifications/fetch-unread-count]}
[_] [_]

View File

@ -8,13 +8,17 @@
status-im.common.emoji-picker.events status-im.common.emoji-picker.events
status-im.common.font.events status-im.common.font.events
[status-im.common.json-rpc.events] [status-im.common.json-rpc.events]
status-im.common.log
status-im.common.password-authentication.events status-im.common.password-authentication.events
status-im.common.signals.events status-im.common.signals.events
status-im.common.theme.events status-im.common.theme.events
[status-im.common.toasts.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.events
[status-im.contexts.chat.home.add-new-contact.events] [status-im.contexts.chat.home.add-new-contact.events]
status-im.contexts.chat.messenger.composer.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.chat.messenger.photo-selector.events
status-im.contexts.communities.events status-im.contexts.communities.events
status-im.contexts.communities.overview.events status-im.contexts.communities.overview.events
@ -29,6 +33,7 @@
status-im.contexts.wallet.send.events status-im.contexts.wallet.send.events
status-im.contexts.wallet.signals status-im.contexts.wallet.signals
[status-im.db :as db] [status-im.db :as db]
status-im.navigation.events
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(rf/defn start-app (rf/defn start-app

View File

@ -151,7 +151,7 @@
(p/resolved ::messenger-started) (p/resolved ::messenger-started)
(do (do
(create-multiaccount!) (create-multiaccount!)
(-> (wait-for [:messenger-started]) (-> (wait-for [:profile.login/messenger-started])
(.then #(assert-messenger-started)))))) (.then #(assert-messenger-started))))))
(defn test-async (defn test-async