move merge-fx to separate ns

This commit is contained in:
Roman Volosovskyi 2018-04-23 12:10:57 +02:00
parent baf211e1f3
commit 6b073fe350
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
21 changed files with 101 additions and 84 deletions

View File

@ -12,6 +12,7 @@
[status-im.ui.screens.navigation :as navigation]
[status-im.ui.screens.group.events :as group.events]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.contacts :as utils.contacts]
[status-im.transport.core :as transport]
[status-im.transport.message.core :as transport.message]
@ -114,7 +115,7 @@
existing-contacts (:contacts/contacts db)
contacts-to-add (select-keys new-contacts (set/difference (set (keys new-contacts))
(set (keys existing-contacts))))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (update db :contacts/contacts merge contacts-to-add)
:data-store/save-contacts (vals contacts-to-add)}
(events.loading/load-commands))))
@ -149,7 +150,7 @@
(-> chat-messages keys set))))))
{}
all-stored-chats)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc db :chats chats)}
(init-console-chat)
(group.events/add-default-groups)
@ -192,7 +193,7 @@
(get-in db messages-path))]
(when (or (seq unseen-messages-ids)
(seq unseen-system-messages-ids))
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (-> (reduce (fn [new-db message-id]
(assoc-in new-db (into messages-path [message-id :user-statuses me]) :seen))
db
@ -210,7 +211,7 @@
(defn- preload-chat-data
"Takes chat-id and coeffects map, returns effects necessary when navigating to chat"
[chat-id {:keys [db] :as cofx}]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (-> (assoc db :current-chat-id chat-id)
(models/set-chat-ui-props {:validation-messages nil}))}
(fire-off-chat-loaded-event chat-id)
@ -229,10 +230,10 @@
"Takes coeffects map and chat-id, returns effects necessary for navigation and preloading data"
[chat-id {:keys [navigation-replace?]} {:keys [db] :as cofx}]
(if navigation-replace?
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(navigation/replace-view :chat)
(preload-chat-data chat-id))
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
;; TODO janherich - refactor `navigate-to` so it can be used with `merge-fx` macro
{:db (navigation/navigate-to db :chat)}
(preload-chat-data chat-id))))
@ -248,7 +249,7 @@
[chat-id opts {:keys [db] :as cofx}]
; don't allow to open chat with yourself
(when (not= (:current-public-key db) chat-id)
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models/upsert-chat {:chat-id chat-id
:is-active true})
(navigate-to-chat chat-id opts))))
@ -270,14 +271,14 @@
(let [{:keys [group-chat public?]} (get-in db [:chats chat-id])]
;; if this is private group chat, we have to broadcast leave and unsubscribe after that
(if (and group-chat (not public?))
(handlers/merge-fx cofx (transport.message/send (group-chat/GroupLeave.) chat-id))
(handlers/merge-fx cofx (transport/unsubscribe-from-chat chat-id)))))
(handlers-macro/merge-fx cofx (transport.message/send (group-chat/GroupLeave.) chat-id))
(handlers-macro/merge-fx cofx (transport/unsubscribe-from-chat chat-id)))))
(handlers/register-handler-fx
:leave-chat-and-navigate-home
[re-frame/trim-v]
(fn [cofx [chat-id]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models/remove-chat chat-id)
(navigation/replace-view :home)
(remove-transport chat-id))))
@ -295,7 +296,7 @@
:remove-chat-and-navigate-home
[re-frame/trim-v]
(fn [cofx [chat-id]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models/remove-chat chat-id)
(navigation/replace-view :home))))
@ -312,7 +313,7 @@
:create-new-public-chat
[re-frame/trim-v]
(fn [{:keys [db now] :as cofx} [topic]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models/add-public-chat topic)
(navigation/navigate-to-clean :home)
(navigate-to-chat topic {})
@ -334,7 +335,7 @@
(group-name-from-contacts selected-contacts
(:contacts/contacts db)
(:username db)))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc db :group/selected-contacts #{})}
(models/add-group-chat random-id chat-name (:current-public-key db) selected-contacts)
(navigation/navigate-to-clean :home)
@ -345,6 +346,6 @@
:show-profile
[re-frame/trim-v]
(fn [{:keys [db] :as cofx} [identity]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc db :contacts/identity identity)}
(navigation/navigate-forget :profile))))

View File

@ -7,7 +7,7 @@
[status-im.i18n :as i18n]
[goog.string :as gstring]
goog.string.format
[status-im.utils.handlers :as handlers]))
[status-im.utils.handlers-macro :as handlers-macro]))
;;;; Helper fns
@ -59,7 +59,7 @@
"debug"
(fn [{:keys [db random-id now] :as cofx} {:keys [params]}]
(let [debug? (= "On" (:mode params))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:dispatch-n (if debug?
[[:initialize-debugging {:force-start? true}]
[:chat-received-message/add

View File

@ -7,7 +7,7 @@
[status-im.chat.models :as chat-model]
[status-im.chat.models.commands :as commands-model]
[status-im.utils.clocks :as utils.clocks]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.transport.utils :as transport.utils]
[status-im.transport.message.core :as transport]
[status-im.transport.message.v1.protocol :as protocol]))
@ -73,7 +73,7 @@
command-request? (and (= content-type constants/content-type-command-request)
request-command)
new-timestamp (or timestamp now)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(add-message chat-id
(cond-> (assoc message
:timestamp new-timestamp
@ -95,7 +95,7 @@
(defn receive
[{:keys [chat-id message-id] :as message} {:keys [now] :as cofx}]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(chat-model/upsert-chat {:chat-id chat-id
; We activate a chat again on new messages
:is-active true
@ -175,7 +175,7 @@
(if dapp?
(send-dapp-message! cofx chat-id send-record)
(if fcm-token
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:send-notification {:message "message"
:payload {:title "Status" :body "You have a new message"}
:tokens [fcm-token]}}
@ -208,7 +208,7 @@
(defn- upsert-and-send [{:keys [chat-id] :as message} {:keys [now] :as cofx}]
(let [send-record (protocol/map->Message (select-keys message transport-keys))
message-with-id (assoc message :message-id (transport.utils/message-id send-record))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(chat-model/upsert-chat {:chat-id chat-id
:timestamp now})
(add-message chat-id message-with-id true)
@ -267,7 +267,7 @@
; We send commands to deleted chats as well, i.e. signed later transactions
chat (or (get chats chat-id) {:chat-id chat-id})
request (:request handler-data)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(upsert-and-send (prepare-command-message current-public-key chat now request content))
(add-console-responses command handler-data)
(requests-events/request-answered chat-id to-message))))

View File

@ -7,6 +7,7 @@
[status-im.utils.datetime :as datetime]
[status-im.utils.ethereum.core :as utils]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.web3-provider :as web3-provider]
[status-im.transport.core :as transport]))
@ -37,7 +38,7 @@
(re-frame/inject-cofx ::get-web3)
(re-frame/inject-cofx :data-store/transport)]
(fn [{:data-store/keys [transport] :keys [db web3] :as cofx} [current-account-id ethereum-rpc-url]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc db
:web3 web3
:rpc-url (or ethereum-rpc-url constants/ethereum-rpc-url)

View File

@ -9,6 +9,7 @@
[taoensso.timbre :as log]
[status-im.transport.inbox :as inbox]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.transport.db :as transport.db]))
(defn init-whisper
@ -24,7 +25,7 @@
:sym-key sym-key
:sym-key-id sym-key-id}]))
topic (transport.utils/get-topic constants/contact-discovery)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:shh/add-discovery-filter {:web3 web3
:private-key-id public-key
:topic topic}

View File

@ -5,7 +5,8 @@
[status-im.transport.message.v1.protocol :as protocol]
[status-im.transport.utils :as transport.utils]
[status-im.ui.screens.contacts.core :as contacts]
[status-im.utils.handlers :as handlers]))
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]))
(defrecord NewContactKey [sym-key topic message]
message/StatusMessage
@ -20,7 +21,7 @@
:chat-id chat-id
:topic topic
:message message}]))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:shh/add-new-sym-key {:web3 (get-in cofx [:db :web3])
:sym-key sym-key
:on-success on-success}}
@ -37,7 +38,7 @@
:chat-id chat-id
:topic topic
:message this}]))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:shh/get-new-sym-key {:web3 (:web3 db)
:on-success on-success}}
(protocol/init-chat chat-id topic)
@ -45,7 +46,7 @@
(receive [this chat-id signature {:keys [db] :as cofx}]
(let [message-id (transport.utils/message-id this)]
(when (protocol/is-new? message-id)
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
#_(protocol/ack message-id chat-id)
(contacts/receive-contact-request signature
this))))))
@ -54,14 +55,14 @@
message/StatusMessage
(send [this chat-id cofx]
(let [message-id (transport.utils/message-id this)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
#_(protocol/requires-ack message-id chat-id)
(protocol/send {:chat-id chat-id
:payload this}))))
(receive [this chat-id signature cofx]
(let [message-id (transport.utils/message-id this)]
(when (protocol/is-new? message-id)
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
#_(protocol/ack message-id chat-id)
(contacts/receive-contact-request-confirmation signature
this))))))
@ -71,13 +72,13 @@
(send [this _ {:keys [db] :as cofx}]
(let [message-id (transport.utils/message-id this)
public-keys (remove nil? (map :public-key (vals (:contacts/contacts db))))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(protocol/multi-send-with-pubkey {:public-keys public-keys
:payload this}))))
(receive [this chat-id signature cofx]
(let [message-id (transport.utils/message-id this)]
(when (protocol/is-new? message-id)
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(contacts/receive-contact-update chat-id
signature
this))))))
@ -90,7 +91,7 @@
(assoc :sym-key-id sym-key-id)
;;TODO (yenda) remove once go implements persistence
(assoc :sym-key sym-key))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
:shh/add-filter {:web3 web3
:sym-key-id sym-key-id
@ -109,7 +110,7 @@
(assoc :sym-key-id sym-key-id)
;;TODO (yenda) remove once go implements persistence
(assoc :sym-key sym-key))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
:shh/add-filter {:web3 web3
:sym-key-id sym-key-id
@ -124,7 +125,7 @@
(fn [cofx [this timer chat-id n]]
(if (zero? n)
(println "Time: " (str (- (inst-ms (js/Date.)) @timer)))
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:dispatch [this timer chat-id (dec n)]}
(message/send (protocol/map->Message {:content (str n)
:content-type "text/plain"

View File

@ -3,6 +3,7 @@
(:require [clojure.set :as set]
[re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.transport.message.core :as message]
[status-im.i18n :as i18n]
[status-im.ui.screens.group.core :as group]
@ -27,7 +28,7 @@
:payload this}
cofx)))
(receive [this _ signature {:keys [db] :as cofx}]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:shh/add-new-sym-key {:web3 (:web3 db)
:sym-key sym-key
:on-success (fn [sym-key sym-key-id]
@ -78,7 +79,7 @@
(defrecord GroupAdminUpdate [chat-name participants]
message/StatusMessage
(send [this chat-id cofx]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(init-chat-if-new chat-id)
(send-new-group-key this chat-id)))
(receive [this chat-id signature {:keys [now db random-id] :as cofx}]
@ -92,7 +93,7 @@
admin-name (or (get-in db [:contacts/contacts group-admin :name])
group-admin)]
(if (removed me) ;; we were removed
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models.message/receive
(models.message/system-message chat-id random-id now
(str admin-name " " (i18n/label :t/removed-from-chat))))
@ -100,7 +101,7 @@
:removed-from-at now
:is-active false})
(transport/unsubscribe-from-chat chat-id))
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models.message/receive
(models.message/system-message chat-id random-id now
(prepare-system-message admin-name
@ -125,7 +126,7 @@
participant-leaving-name (or (get-in db [:contacts/contacts signature :name])
signature)]
(when (get-in db [:chats chat-id]) ;; chat is present
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(models.message/receive
(models.message/system-message chat-id random-id now
(str participant-leaving-name " " (i18n/label :t/left))))
@ -145,7 +146,7 @@
;; some async operations
(fn [{:keys [db] :as cofx} [{:keys [chat-id message sym-key sym-key-id]}]]
(let [{:keys [web3]} db]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
:shh/add-filter {:web3 web3
:sym-key-id sym-key-id
@ -175,5 +176,5 @@
(assoc :sym-key sym-key))}}]
;; if new sym-key is wrapping some message, call receive on it as well, if not just update the transport layer
(if message
(handlers/merge-fx cofx fx (message/receive message chat-id signature))
(handlers-macro/merge-fx cofx fx (message/receive message chat-id signature))
fx))))

View File

@ -2,6 +2,7 @@
status-im.transport.message.v1.public-chat
(:require [re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.transport.message.core :as message]
[status-im.transport.message.v1.protocol :as protocol]
[status-im.transport.utils :as transport.utils]))
@ -17,7 +18,7 @@
(re-frame/dispatch [::add-new-sym-key {:chat-id chat-id
:sym-key sym-key
:sym-key-id sym-key-id}]))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:shh/generate-sym-key-from-password {:web3 (:web3 db)
:password chat-id
:on-success on-success}}
@ -27,7 +28,7 @@
::add-new-sym-key
(fn [{:keys [db] :as cofx} [_ {:keys [sym-key-id sym-key chat-id]}]]
(let [{:keys [web3]} db]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc-in db [:transport/chats chat-id :sym-key-id] sym-key-id)
:shh/add-filter {:web3 web3
:sym-key-id sym-key-id

View File

@ -8,6 +8,7 @@
[clojure.string :as str]
[status-im.utils.datetime :as time]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.accounts.statuses :as statuses]
[status-im.utils.signing-phrase.core :as signing-phrase]
[status-im.utils.gfycat.core :refer [generate-gfy]]
@ -124,7 +125,7 @@
:data-store/save-account (assoc new-account :after-update-event after-update-event)}
{:keys [name photo-path]} new-account]
(if (or (:name new-account-fields) (:photo-path new-account-fields))
(handlers/merge-fx cofx fx (transport/send (message.contact/ContactUpdate. name photo-path) nil))
(handlers-macro/merge-fx cofx fx (transport/send (message.contact/ContactUpdate. name photo-path) nil))
fx))))
(handlers/register-handler-fx
@ -141,7 +142,7 @@
(handlers/register-handler-fx
:account-set-name
(fn [{{:accounts/keys [create] :as db} :db :as cofx} _]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc-in db [:accounts/create :show-welcome?] true)
:dispatch [:navigate-to-clean :usage-data [:account-finalized]]}
(account-update {:name (:name create)}))))

View File

@ -1,5 +1,6 @@
(ns status-im.ui.screens.contacts.core
(:require [re-frame.core :as re-frame] [status-im.utils.handlers :as handlers]
(:require [re-frame.core :as re-frame]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.data-store.messages :as data-store.messages]
[status-im.chat.models :as chat.models]
[status-im.constants :as constants]))
@ -19,7 +20,7 @@
chat-props {:name name
:chat-id public-key
:contact-info (prn-str contact-props)}]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (update-in db [:contacts/contacts public-key] merge contact-props)
:data-store/save-contact contact-props}
(chat.models/upsert-chat chat-props)))))
@ -36,7 +37,7 @@
:fcm-token fcm-token}
chat-props {:name name
:chat-id public-key}]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (update-in db [:contacts/contacts public-key] merge contact-props)
:data-store/save-contact contact-props}
(chat.models/upsert-chat chat-props)))))
@ -57,7 +58,7 @@
:photo-path profile-image
:last-updated now}]
(if (chats public-key)
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(update-contact contact)
(chat.models/upsert-chat {:chat-id chat-id
:name name}))

View File

@ -3,6 +3,7 @@
[cljs.reader :as reader]
[re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.contacts :as utils.contacts]
[status-im.constants :as constants]
[status-im.utils.identicon :as identicon]
@ -62,12 +63,12 @@
(defn add-contact [whisper-id {:keys [db] :as cofx}]
(let [contact (build-contact whisper-id cofx)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(add-new-contact contact)
(send-contact-request contact))))
(defn add-contact-and-open-chat [whisper-id cofx]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(navigation/navigate-to-clean :home)
(add-contact whisper-id)
(chat.events/start-chat whisper-id {})))
@ -86,7 +87,7 @@
fx {:db (assoc db :contacts/new-identity contact-identity)}]
(if (new-chat.db/validate-pub-key contact-identity current-account)
fx
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
fx
(add-contact-and-open-chat contact-identity))))))
@ -118,7 +119,7 @@
:open-chat-with-contact
[(re-frame/inject-cofx :random-id)]
(fn [{:keys [db] :as cofx} [_ {:keys [whisper-identity] :as contact}]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(navigation/navigate-to-clean :home)
(add-contact whisper-identity)
(chat.events/start-chat whisper-identity {}))))

View File

@ -40,6 +40,7 @@
[status-im.utils.config :as config]
[status-im.utils.notifications :as notifications]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.http :as http]
[status-im.utils.instabug :as inst]
[status-im.utils.mixpanel :as mixpanel]
@ -214,7 +215,7 @@
(fn [{:keys [db] :as cofx} _]
(let [{:transport/keys [chats] :keys [current-account-id]} db
sharing-usage-data? (get-in db [:accounts/accounts current-account-id :sharing-usage-data?])]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:dispatch-n (concat [[:initialize-db]
[:load-accounts]
[:listen-to-network-status]

View File

@ -5,7 +5,8 @@
[status-im.ui.screens.navigation :as navigation]
[status-im.transport.message.v1.group-chat :as group-chat]
[status-im.transport.message.core :as transport]
[status-im.utils.handlers :as handlers]))
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]))
;;;; Handlers
@ -26,7 +27,7 @@
(let [participants (concat (get-in db [:chats current-chat-id :contacts]) selected-participants)
contacts (:contacts/contacts db)
added-participants-names (map #(get-in contacts [% :name]) selected-participants)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (-> db
(assoc-in [:chats current-chat-id :contacts] participants)
(assoc :selected-participants #{}))
@ -43,7 +44,7 @@
(let [participants (remove removed-participants (get-in db [:chats current-chat-id :contacts]))
contacts (:contacts/contacts db)
removed-participants-names (map #(get-in contacts [% :name]) removed-participants)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (assoc-in db [:chats current-chat-id :contacts] participants)
:data-store/remove-chat-contacts [current-chat-id removed-participants]}
(models.message/receive

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.navigation
(:require [re-frame.core :as re-frame]
[status-im.utils.handlers :as handlers]))
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]))
;; private helper fns
@ -103,7 +104,7 @@
:navigate-to-tab
(re-frame/enrich preload-data!)
(fn [{:keys [db] :as cofx} [_ view-id]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (-> db
(assoc :prev-tab-view-id (:view-id db))
(assoc :prev-view-id (:view-id db)))}

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.network-settings.events
(:require [re-frame.core :refer [dispatch dispatch-sync after] :as re-frame]
[status-im.utils.handlers :refer [register-handler] :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.accounts.events :as accounts-events]
[status-im.i18n :as i18n]
[status-im.utils.ethereum.core :as utils]
@ -29,7 +30,7 @@
(handlers/register-handler-fx
::save-network
(fn [{:keys [db now] :as cofx} [_ network]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(accounts-events/account-update {:network network
:last-updated now}
[::close-application]))))
@ -41,7 +42,7 @@
networks (:networks/networks db)
chats (:transport/chats db)]
(if (utils/network-with-upstream-rpc? networks current-network)
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:dispatch [:navigate-to-clean :accounts]}
(transport/stop-whisper)
(accounts-events/account-update {:network network

View File

@ -1,6 +1,7 @@
(ns status-im.ui.screens.offline-messaging-settings.events
(:require [re-frame.core :refer [dispatch]]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.ui.screens.accounts.events :as accounts-events]
[status-im.i18n :as i18n]
[status-im.transport.core :as transport]
@ -12,7 +13,7 @@
(let [{:accounts/keys [current-account-id accounts]} db
network (ethereum/network->chain-keyword (:network db))
settings (get-in accounts [current-account-id :settings])]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:dispatch [:logout]}
(accounts-events/update-settings (assoc-in settings [:wnode network] wnode))))))

View File

@ -8,6 +8,7 @@
[status-im.chat.events :as chat-events]
[status-im.chat.events.input :as input-events]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.utils.image-processing :refer [img->base64]]
[taoensso.timbre :as log]))
@ -30,7 +31,7 @@
[re-frame/trim-v]
(fn [{{:contacts/keys [contacts]} :db :as cofx} [chat-id]]
(let [send-command (get-in contacts chat-const/send-command-ref)]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(chat-events/start-chat chat-id {:navigation-replace? true})
(input-events/select-chat-input-command send-command nil true)))))
@ -77,7 +78,7 @@
:last-updated now}
(if photo-path
{:photo-path photo-path}))]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
(clear-profile)
(accounts-events/account-update cleaned-edit)))))
@ -109,6 +110,6 @@
(handlers/register-handler-fx
:my-profile/finish
(fn [{:keys [db] :as cofx} _]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:db (update db :my-profile/seed assoc :step :finish :error nil :word nil)}
(accounts-events/account-update {:seed-backed-up? true}))))

View File

@ -2,6 +2,7 @@
(:require [re-frame.core :as re-frame]
[status-im.ui.screens.wallet.db :as wallet-db]
[status-im.utils.handlers :as handlers]
[status-im.utils.handlers-macro :as handlers-macro]
[status-im.chat.constants :as chat-const]
[status-im.chat.events.input :as input-events]
[status-im.utils.money :as money]))
@ -10,7 +11,7 @@
::wallet-send-chat-request
[re-frame/trim-v]
(fn [{{:contacts/keys [contacts]} :db :as cofx} [amount]]
(handlers/merge-fx cofx
(handlers-macro/merge-fx cofx
{:dispatch [:send-current-message]}
(input-events/select-chat-input-command
(assoc (get-in contacts chat-const/request-command-ref) :prefill [amount]) nil true))))

View File

@ -5,8 +5,7 @@
[re-frame.interceptor :refer [->interceptor get-coeffect get-effect]]
[status-im.utils.ethereum.core :as ethereum]
[status-im.utils.mixpanel :as mixpanel]
[taoensso.timbre :as log])
(:require-macros status-im.utils.handlers))
[taoensso.timbre :as log]))
(def pre-event-callback (atom nil))
@ -137,17 +136,3 @@
(remove (fn [{:keys [dapp? pending?]}]
(or pending? dapp?)))
(map :whisper-identity)))
(defn update-db [cofx fx]
(if-let [db (:db fx)]
(assoc cofx :db db)
cofx))
(defn safe-merge [fx new-fx]
(if (:merging-fx-with-common-keys fx)
fx
(let [common-keys (clojure.set/intersection (into #{} (keys fx))
(into #{} (keys new-fx)))]
(if (empty? (disj common-keys :db))
(merge fx new-fx)
{:merging-fx-with-common-keys common-keys}))))

View File

@ -1,4 +1,4 @@
(ns status-im.utils.handlers)
(ns status-im.utils.handlers-macro)
(defmacro merge-fx*
"This macro is called recursively from merge-fx

View File

@ -0,0 +1,16 @@
(ns status-im.utils.handlers-macro
(:require-macros status-im.utils.handlers-macro))
(defn update-db [cofx fx]
(if-let [db (:db fx)]
(assoc cofx :db db)
cofx))
(defn safe-merge [fx new-fx]
(if (:merging-fx-with-common-keys fx)
fx
(let [common-keys (clojure.set/intersection (into #{} (keys fx))
(into #{} (keys new-fx)))]
(if (empty? (disj common-keys :db))
(merge fx new-fx)
{:merging-fx-with-common-keys common-keys}))))