replace all register-event-db by fx and remove trim-v interceptor

Signed-off-by: yenda <eric@status.im>
This commit is contained in:
yenda 2018-09-20 12:05:44 +02:00
parent 8913dee762
commit b71005d2fa
No known key found for this signature in database
GPG Key ID: 0095623C0069DCE6
27 changed files with 191 additions and 231 deletions

View File

@ -58,6 +58,8 @@ These guidelines make db.cljs namespaces the place to go when making changes to
# Events
- all events must be defined in the single `status-im.events` namespace which can be considered as an index of everything going on in the app
- events must always be declared with `register-handler-fx`, no `register-handler-db`
- events must never use the `trim-v` interceptor
- events must only contain a function call defined in a module
```clojure
(handlers/register-handler-fx

View File

@ -155,8 +155,7 @@
(handlers/register-handler-fx
:load-commands
[re-frame/trim-v]
(fn [cofx [commands]]
(fn [cofx [_ commands]]
(load-commands commands cofx)))
(defn chat-commands

View File

@ -30,30 +30,31 @@
;;;; Handlers
(handlers/register-handler-db
(handlers/register-handler-fx
:set-chat-ui-props
[re-frame/trim-v]
(fn [db [kvs]]
(models/set-chat-ui-props db kvs)))
(fn [{:keys [db]} [_ kvs]]
{:db (models/set-chat-ui-props db kvs)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:toggle-chat-ui-props
(fn [{:keys [db]} [_ ui-element]]
{:db (models/toggle-chat-ui-prop db ui-element)}))
(handlers/register-handler-fx
:show-message-details
[re-frame/trim-v]
(fn [db [details]]
(models/set-chat-ui-props db {:show-bottom-info? true
:bottom-info details})))
(fn [{:keys [db]} [_ details]]
{:db (models/set-chat-ui-props db {:show-bottom-info? true
:bottom-info details})}))
(handlers/register-handler-db
(handlers/register-handler-fx
:show-message-options
[re-frame/trim-v]
(fn [db [options]]
(models/set-chat-ui-props db {:show-message-options? true
:message-options options})))
(fn [{:keys [db]} [_ options]]
{:db (models/set-chat-ui-props db {:show-message-options? true
:message-options options})}))
(handlers/register-handler-fx
:update-message-status
[re-frame/trim-v]
(fn [{:keys [db]} [chat-id message-id user-id status]]
(fn [{:keys [db]} [_ chat-id message-id user-id status]]
(let [new-status {:chat-id chat-id
:message-id message-id
:whisper-identity user-id
@ -65,8 +66,7 @@
(handlers/register-handler-fx
:navigate-to-chat
[re-frame/trim-v]
(fn [cofx [chat-id opts]]
(fn [cofx [_ chat-id opts]]
(models/navigate-to-chat chat-id opts cofx)))
(handlers/register-handler-fx
@ -78,24 +78,21 @@
(handlers/register-handler-fx
:start-chat
[re-frame/trim-v]
(fn [cofx [contact-id opts]]
(fn [cofx [_ contact-id opts]]
(models/start-chat contact-id opts cofx)))
(defn remove-chat-and-navigate-home [cofx [chat-id]]
(defn remove-chat-and-navigate-home [cofx [_ chat-id]]
(handlers-macro/merge-fx cofx
(models/remove-chat chat-id)
(navigation/replace-view :home)))
(handlers/register-handler-fx
:remove-chat-and-navigate-home
[re-frame/trim-v]
remove-chat-and-navigate-home)
(handlers/register-handler-fx
:remove-chat-and-navigate-home?
[re-frame/trim-v]
(fn [_ [chat-id group?]]
(fn [_ [_ chat-id group?]]
{:ui/show-confirmation {:title (i18n/label :t/delete-confirmation)
:content (i18n/label :t/delete-chat-confirmation)
:confirm-button-text (i18n/label :t/delete)
@ -122,8 +119,7 @@
(handlers/register-handler-fx
:create-new-public-chat
[re-frame/trim-v]
(fn [cofx [topic]]
(fn [cofx [_ topic]]
(create-new-public-chat topic cofx)))
(defn- group-name-from-contacts [selected-contacts all-contacts username]
@ -134,8 +130,8 @@
(handlers/register-handler-fx
:create-new-group-chat-and-open
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [{:keys [db random-id] :as cofx} [group-name]]
[(re-frame/inject-cofx :random-id)]
(fn [{:keys [db random-id] :as cofx} [_ group-name]]
(let [selected-contacts (:group/selected-contacts db)
chat-name (if-not (string/blank? group-name)
group-name
@ -155,24 +151,20 @@
(handlers/register-handler-fx
:show-profile
[re-frame/trim-v]
(fn [cofx [identity]]
(fn [cofx [_ identity]]
(show-profile identity cofx)))
(handlers/register-handler-fx
:resend-message
[re-frame/trim-v]
(fn [cofx [chat-id message-id]]
(fn [cofx [_ chat-id message-id]]
(models.message/resend-message chat-id message-id cofx)))
(handlers/register-handler-fx
:delete-message
[re-frame/trim-v]
(fn [cofx [chat-id message-id]]
(fn [cofx [_ chat-id message-id]]
(models.message/delete-message chat-id message-id cofx)))
(handlers/register-handler-db
(handlers/register-handler-fx
:disable-cooldown
[re-frame/trim-v]
(fn [db]
(assoc db :chat/cooldown-enabled? false)))
(fn [{:keys [db]}]
{:db (assoc db :chat/cooldown-enabled? false)}))

View File

@ -54,14 +54,12 @@
(handlers/register-handler-fx
:set-chat-input-text
[re-frame/trim-v]
(fn [cofx [text]]
(fn [cofx [_ text]]
(input-model/set-chat-input-text text cofx)))
(handlers/register-handler-fx
:select-chat-input-command
[re-frame/trim-v]
(fn [{:keys [db] :as cofx} [command params metadata]]
(fn [{:keys [db] :as cofx} [_ command params metadata]]
(handlers-macro/merge-fx cofx
(input-model/set-chat-input-metadata metadata)
(commands-input/select-chat-input-command command params)
@ -69,20 +67,17 @@
(handlers/register-handler-fx
:set-command-parameter
[re-frame/trim-v]
(fn [cofx [last-param? index value]]
(fn [cofx [_ last-param? index value]]
(commands-input/set-command-parameter last-param? index value cofx)))
(handlers/register-handler-fx
:chat-input-focus
[re-frame/trim-v]
(fn [cofx [ref]]
(fn [cofx [_ ref]]
(chat-input-focus ref cofx)))
(handlers/register-handler-fx
:chat-input-blur
[re-frame/trim-v]
(fn [{{:keys [current-chat-id chat-ui-props]} :db} [ref]]
(fn [{{:keys [current-chat-id chat-ui-props]} :db} [_ ref]]
(when-let [cmp-ref (get-in chat-ui-props [current-chat-id ref])]
{::blur-rn-component cmp-ref})))
@ -131,15 +126,14 @@
(command-not-complete-fx input-text current-chat-id cofx))
(plain-text-message-fx input-text current-chat-id cofx))))))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-text-selection
[re-frame/trim-v]
(fn [db [selection]]
(model/set-chat-ui-props db {:selection selection})))
(fn [{:keys [db]} [_ selection]]
{:db (model/set-chat-ui-props db {:selection selection})}))
(handlers/register-handler-db
(handlers/register-handler-fx
:show-suggestions
(fn [db _]
(-> db
(model/toggle-chat-ui-prop :show-suggestions?)
(model/set-chat-ui-props {:validation-messages nil}))))
(fn [{:keys [db]} _]
{:db (-> db
(model/toggle-chat-ui-prop :show-suggestions?)
(model/set-chat-ui-props {:validation-messages nil}))}))

View File

@ -29,6 +29,5 @@
(handlers/register-handler-fx
:chat-received-message/add
message-model/receive-interceptors
(fn [cofx [messages]]
(fn [cofx [_ messages]]
(message-model/receive-many (filter-messages messages cofx) cofx)))

View File

@ -22,8 +22,7 @@
[clojure.string :as string]))
(def receive-interceptors
[(re-frame/inject-cofx :random-id)
re-frame/trim-v])
[(re-frame/inject-cofx :random-id)])
(defn- emoji-only-content?
[content]
@ -213,8 +212,7 @@
(def send-interceptors
[(re-frame/inject-cofx :random-id)
(re-frame/inject-cofx :random-id-seq)
re-frame/trim-v])
(re-frame/inject-cofx :random-id-seq)])
(defn- send
[chat-id message-id send-record {{:keys [network-status current-public-key]} :db :as cofx}]

View File

@ -26,12 +26,12 @@
(handlers/register-handler-fx
:process-http-request
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [cofx [url type data]]
[(re-frame/inject-cofx :random-id)]
(fn [cofx [_ url type data]]
(try
(models.dev-server/process-request! {:cofx cofx
:url (rest (string/split url "/"))
:type (keyword type)
:data data})
(catch js/Error e
{:dev-server/respond [400 {:message (str "Unsupported operation: " e)}]}))))
{:dev-server/respond [400 {:message (str "Unsupported operation: " e)}]}))))

View File

@ -461,7 +461,7 @@
;; web3 module
(handlers/register-handler-db
(handlers/register-handler-fx
:web3.callback/get-syncing-success
(fn [cofx [_ error sync]]
(protocol/update-sync-state cofx error sync)))
@ -478,10 +478,10 @@
(fn [cofx _]
(accounts.login/user-login cofx)))
(handlers/register-handler-db
(handlers/register-handler-fx
:notifications.callback/get-fcm-token-success
(fn [db [_ fcm-token]]
(assoc-in db [:notifications :fcm-token] fcm-token)))
(fn [{:keys [db]} [_ fcm-token]]
{:db (assoc-in db [:notifications :fcm-token] fcm-token)}))
(handlers/register-handler-fx
:notifications.callback/request-notifications-permissions-granted

View File

@ -9,7 +9,7 @@
[status-im.utils.utils :as utils]))
(defn update-sync-state
[{:keys [sync-state sync-data] :as db} error sync]
[{{:keys [sync-state sync-data] :as db} :db} error sync]
(let [{:keys [highestBlock currentBlock] :as state}
(js->clj sync :keywordize-keys true)
syncing? (> (- highestBlock currentBlock) constants/blocks-per-hour)
@ -22,11 +22,11 @@
(= sync-state :pending))
:done
:synced))]
(cond-> db
(and (not= sync-data state) (= :in-progress new-state))
(assoc :sync-data state)
(not= sync-state new-state)
(assoc :sync-state new-state))))
{:db (cond-> db
(and (not= sync-data state) (= :in-progress new-state))
(assoc :sync-data state)
(not= sync-state new-state)
(assoc :sync-state new-state))}))
(defn check-sync-state
[{{:keys [web3] :as db} :db :as cofx}]

View File

@ -36,11 +36,10 @@
(re-frame/dispatch [:protocol/receive-whisper-message js-error js-message chat-id])))]
(re-frame/dispatch [::filter-added chat-id filter]))))
(handlers/register-handler-db
(handlers/register-handler-fx
::filter-added
[re-frame/trim-v]
(fn [db [chat-id filter]]
(assoc-in db [:transport/chats chat-id :filter] filter)))
(fn [{:keys [db]} [_ chat-id filter]]
{:db (assoc-in db [:transport/chats chat-id :filter] filter)}))
(re-frame/reg-fx
:shh/add-discovery-filter
@ -52,11 +51,10 @@
(re-frame/dispatch [:protocol/receive-whisper-message js-error js-message])))]
(re-frame/dispatch [::discovery-filter-added filter]))))
(handlers/register-handler-db
(handlers/register-handler-fx
::discovery-filter-added
[re-frame/trim-v]
(fn [db [filter]]
(assoc db :transport/discovery-filter filter)))
(fn [{:keys [db]} [filter]]
{:db (assoc db :transport/discovery-filter filter)}))
(re-frame/reg-fx
:shh/remove-filter

View File

@ -38,7 +38,7 @@
(for [i (range (.-length array))]
(aget array i)))
(defn receive-whisper-messages [{:keys [now] :as cofx} [js-error js-messages chat-id]]
(defn receive-whisper-messages [{:keys [now] :as cofx} [_ js-error js-messages chat-id]]
(if (and (not js-error)
js-messages)
(let [now-in-s (quot now 1000)]
@ -51,21 +51,13 @@
(handlers/register-handler-fx
:protocol/receive-whisper-message
[re-frame/trim-v
handlers/logged-in
[handlers/logged-in
(re-frame/inject-cofx :random-id)]
receive-whisper-messages)
(handlers/register-handler-fx
:protocol/send-status-message-success
[re-frame/trim-v]
(fn [{:keys [db] :as cofx} [_ resp]]
(log/debug :send-status-message-success resp)))
(handlers/register-handler-fx
:protocol/send-status-message-error
[re-frame/trim-v]
(fn [{:keys [db] :as cofx} [err]]
(fn [{:keys [db] :as cofx} [_ err]]
(log/error :send-status-message-error err)))
(handlers/register-handler-fx
@ -124,16 +116,14 @@
(handlers/register-handler-fx
:group/unsubscribe-from-chat
[re-frame/trim-v]
(fn [cofx [chat-id]]
(fn [cofx [_ chat-id]]
(transport.utils/unsubscribe-from-chat chat-id cofx)))
(handlers/register-handler-fx
:group/send-new-sym-key
[re-frame/trim-v]
;; this is the event that is called when we want to send a message that required first
;; some async operations
(fn [{:keys [db] :as cofx} [{:keys [chat-id message sym-key sym-key-id]}]]
(fn [{:keys [db] :as cofx} [_ {:keys [chat-id message sym-key sym-key-id]}]]
(let [{:keys [web3]} db]
(handlers-macro/merge-fx cofx
{:db (update-in db [:transport/chats chat-id]

View File

@ -52,13 +52,13 @@
fx
(add-contact-and-open-chat contact-identity))))))
(handlers/register-handler-db
(handlers/register-handler-fx
:open-contact-toggle-list
(fn [db _]
(-> (assoc db
:group/selected-contacts #{}
:new-chat-name "")
(navigation/navigate-to :contact-toggle-list))))
(fn [{:keys [db]} _]
{:db (-> (assoc db
:group/selected-contacts #{}
:new-chat-name "")
(navigation/navigate-to :contact-toggle-list))}))
(handlers/register-handler-fx
:open-chat-with-contact

View File

@ -12,6 +12,5 @@
(handlers/register-handler-fx
:show-profile-desktop
[re-frame/trim-v]
(fn [cofx [identity]]
(show-profile-desktop identity cofx)))
(fn [cofx [_ identity]]
(show-profile-desktop identity cofx)))

View File

@ -100,15 +100,15 @@
(fn [state]
(status/app-state-change state)))
(handlers/register-handler-db
(handlers/register-handler-fx
:set
(fn [db [_ k v]]
(assoc db k v)))
(fn [{:keys [db]} [_ k v]]
{:db (assoc db k v)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:set-in
(fn [db [_ path v]]
(assoc-in db path v)))
(fn [{:keys [db]} [_ path v]]
{:db (assoc-in db path v)}))
(defn app-state-change [state {:keys [db] :as cofx}]
(let [app-coming-from-background? (= state "active")]
@ -128,22 +128,22 @@
(fn [_ [_ options]]
{:request-permissions-fx options}))
(handlers/register-handler-db
(handlers/register-handler-fx
:set-swipe-position
(fn [db [_ item-id value]]
(assoc-in db [:chat-animations item-id :delete-swiped] value)))
(fn [{:keys [db]} [_ item-id value]]
{:db (assoc-in db [:chat-animations item-id :delete-swiped] value)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:show-tab-bar
(fn [db _]
(assoc db :tab-bar-visible? true)))
(fn [{:keys [db]} _]
{:db (assoc db :tab-bar-visible? true)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:hide-tab-bar
(fn [db _]
(assoc db :tab-bar-visible? false)))
(fn [{:keys [db]} _]
{:db (assoc db :tab-bar-visible? false)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-window-dimensions
(fn [db [_ dimensions]]
(assoc db :dimensions/window (dimensions/window dimensions))))
(fn [{:keys [db]} [_ dimensions]]
{:db (assoc db :dimensions/window (dimensions/window dimensions))}))

View File

@ -24,17 +24,17 @@
(registry/add extension-data)
(registry/activate extension-key)))))
(handlers/register-handler-db
(handlers/register-handler-fx
:extension/edit-address
(fn [db [_ address]]
(assoc db :extension-url address)))
(fn [{:keys [db]} [_ address]]
{:db (assoc db :extension-url address)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:extension/stage
(fn [db [_ extension-data]]
(-> db
(assoc :staged-extension extension-data)
(navigation/navigate-to :show-extension))))
(fn [{:keys [db]} [_ extension-data]]
{:db (-> db
(assoc :staged-extension extension-data)
(navigation/navigate-to :show-extension))}))
(handlers/register-handler-fx
:extension/show

View File

@ -4,7 +4,7 @@
[status-im.utils.handlers :as handlers]
status-im.ui.screens.extensions.add.events))
(handlers/register-handler-db
(handlers/register-handler-fx
:extensions/toggle-activation
(fn [db [_ id m]]
(fn [{:keys [db]} [_ id m]]
nil))

View File

@ -11,8 +11,7 @@
(handlers/register-handler-fx
:show-group-chat-profile
[re-frame/trim-v]
(fn [{:keys [db]} [chat-id]]
(fn [{:keys [db]} [_ chat-id]]
{:db (-> db
(assoc :new-chat-name (get-in db [:chats chat-id :name])
:group/group-type :chat-group)
@ -37,8 +36,8 @@
(handlers/register-handler-fx
:remove-group-chat-participants
[re-frame/trim-v (re-frame/inject-cofx :random-id)]
(fn [{{:keys [current-chat-id] :as db} :db now :now message-id :random-id :as cofx} [removed-participants]]
[(re-frame/inject-cofx :random-id)]
(fn [{{:keys [current-chat-id] :as db} :db now :now message-id :random-id :as cofx} [_ removed-participants]]
(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)]

View File

@ -2,22 +2,22 @@
(:require [status-im.utils.handlers :as handlers]
[status-im.ui.screens.group.navigation]))
(handlers/register-handler-db
(handlers/register-handler-fx
:deselect-contact
(fn [db [_ id]]
(update db :group/selected-contacts disj id)))
(fn [{:keys [db]} [_ id]]
{:db (update db :group/selected-contacts disj id)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:select-contact
(fn [db [_ id]]
(update db :group/selected-contacts conj id)))
(fn [{:keys [db]} [_ id]]
{:db (update db :group/selected-contacts conj id)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:deselect-participant
(fn [db [_ id]]
(update db :selected-participants disj id)))
(fn [{:keys [db]} [_ id]]
{:db (update db :selected-participants disj id)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:select-participant
(fn [db [_ id]]
(update db :selected-participants conj id)))
(fn [{:keys [db]} [_ id]]
{:db (update db :selected-participants conj id)}))

View File

@ -129,11 +129,11 @@
(fn [cofx [_ & [go-to-view-id screen-params]]]
(navigate-to-cofx go-to-view-id screen-params cofx)))
(handlers/register-handler-db
(handlers/register-handler-fx
:navigate-to-modal
navigation-interceptors
(fn [db [_ modal-view]]
(assoc db :modal modal-view)))
(fn [{:keys [db]} [_ modal-view]]
{:db (assoc db :modal modal-view)}))
(handlers/register-handler-fx
:navigation-replace

View File

@ -8,12 +8,12 @@
[status-im.utils.ethereum.ens :as ens]
[re-frame.core :as re-frame]))
(handlers/register-handler-db
(handlers/register-handler-fx
:wallet/toggle-flashlight
(fn [db]
(fn [{:keys [db]}]
(let [flashlight-state (get-in db [:wallet :send-transaction :camera-flashlight])
toggled-state (if (= :on flashlight-state) :off :on)]
(assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state))))
{:db (assoc-in db [:wallet :send-transaction :camera-flashlight] toggled-state)})))
(defn- fill-request-details [db {:keys [address name value symbol gas gasPrice whisper-identity from-chat?]}]
{:pre [(not (nil? address))]}

View File

@ -49,24 +49,20 @@
(handlers/register-handler-fx
:load-collectible-success
[re-frame/trim-v]
(fn [{db :db} [symbol collectibles]]
(fn [{db :db} [_ symbol collectibles]]
{:db (update-in db [:collectibles symbol] merge collectibles)}))
(handlers/register-handler-fx
:load-collectibles-failure
[re-frame/trim-v]
(fn [{db :db} [reason]]
(fn [{db :db} [_ reason]]
{:db (update-in db [:collectibles symbol :errors] merge reason)}))
(handlers/register-handler-fx
:load-collectible-failure
[re-frame/trim-v]
(fn [{db :db} [_]]
{:db db}))
(handlers/register-handler-fx
:open-collectible-in-browser
[re-frame/trim-v]
(fn [_ [data]]
(fn [_ [_ data]]
{:dispatch [:open-url-in-browser data]}))

View File

@ -134,39 +134,39 @@
(and (= :outbound type) (= normalized (ethereum/normalized-address from)))
(and (= :failed type) (= normalized (ethereum/normalized-address from))))))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-transactions-success
(fn [db [_ transactions address]]
(fn [{:keys [db]} [_ transactions address]]
;; NOTE(goranjovic): we want to only show transactions that belong to the current account
;; this filter is to prevent any late transaction updates initated from another account on the same
;; device from being applied in the current account.
(let [own-transactions (into {} (filter #(own-transaction? address %) transactions))]
(-> db
(update-in [:wallet :transactions] #(merge-with dedupe-transactions % own-transactions))
(assoc-in [:wallet :transactions-loading?] false)))))
{:db (-> db
(update-in [:wallet :transactions] #(merge-with dedupe-transactions % own-transactions))
(assoc-in [:wallet :transactions-loading?] false))})))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-transactions-fail
(fn [db [_ err]]
(fn [{:keys [db]} [_ err]]
(log/debug "Unable to get transactions: " err)
(-> db
(assoc-error-message :transactions-update :error-unable-to-get-transactions)
(assoc-in [:wallet :transactions-loading?] false))))
{:db (-> db
(assoc-error-message :transactions-update :error-unable-to-get-transactions)
(assoc-in [:wallet :transactions-loading?] false))}))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-balance-success
(fn [db [_ balance]]
(-> db
(assoc-in [:wallet :balance :ETH] balance)
(assoc-in [:wallet :balance-loading?] false))))
(fn [{:keys [db]} [_ balance]]
{:db (-> db
(assoc-in [:wallet :balance :ETH] balance)
(assoc-in [:wallet :balance-loading?] false))}))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-balance-fail
(fn [db [_ err]]
(fn [{:keys [db]} [_ err]]
(log/debug "Unable to get balance: " err)
(-> db
(assoc-error-message :balance-update :error-unable-to-get-balance)
(assoc-in [:wallet :balance-loading?] false))))
{:db (-> db
(assoc-error-message :balance-update :error-unable-to-get-balance)
(assoc-in [:wallet :balance-loading?] false))}))
(defn update-token-balance-success [symbol balance {:keys [db]}]
{:db (-> db
@ -178,28 +178,28 @@
(fn [cofx [_ symbol balance]]
(update-token-balance-success symbol balance cofx)))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-token-balance-fail
(fn [db [_ symbol err]]
(fn [{:keys [db]} [_ symbol err]]
(log/debug "Unable to get token " symbol "balance: " err)
(-> db
(assoc-error-message :balance-update :error-unable-to-get-token-balance)
(assoc-in [:wallet :balance-loading?] false))))
{:db (-> db
(assoc-error-message :balance-update :error-unable-to-get-token-balance)
(assoc-in [:wallet :balance-loading?] false))}))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-prices-success
(fn [db [_ prices]]
(assoc db
:prices prices
:prices-loading? false)))
(fn [{:keys [db]} [_ prices]]
{:db (assoc db
:prices prices
:prices-loading? false)}))
(handlers/register-handler-db
(handlers/register-handler-fx
:update-prices-fail
(fn [db [_ err]]
(fn [{:keys [db]} [_ err]]
(log/debug "Unable to get prices: " err)
(-> db
(assoc-error-message :prices-update :error-unable-to-get-prices)
(assoc :prices-loading? false))))
{:db (-> db
(assoc-error-message :prices-update :error-unable-to-get-prices)
(assoc :prices-loading? false))}))
(handlers/register-handler-fx
:show-transaction-details
@ -215,16 +215,16 @@
:from-chat? from-chat?})
:dispatch [:navigate-to-clean :wallet-send-transaction-modal]}))
(handlers/register-handler-db
(handlers/register-handler-fx
:wallet/update-gas-price-success
(fn [db [_ price edit?]]
(fn [{:keys [db] :as cofx} [_ price edit?]]
(if edit?
(:db (models/edit-value
:gas-price
(money/to-fixed
(money/wei-> :gwei price))
{:db db}))
(assoc-in db [:wallet :send-transaction :gas-price] price))))
(models/edit-value
:gas-price
(money/to-fixed
(money/wei-> :gwei price))
cofx)
{:db (assoc-in db [:wallet :send-transaction :gas-price] price)})))
(handlers/register-handler-fx
:wallet/update-estimated-gas
@ -233,12 +233,11 @@
:obj obj
:success-event :wallet/update-estimated-gas-success}}))
(handlers/register-handler-db
(handlers/register-handler-fx
:wallet/update-estimated-gas-success
(fn [db [_ gas]]
(if gas
(assoc-in db [:wallet :send-transaction :gas] (money/bignumber (int (* gas 1.2))))
db)))
(fn [{:keys [db]} [_ gas]]
(when gas
{:db (assoc-in db [:wallet :send-transaction :gas] (money/bignumber (int (* gas 1.2))))})))
(handlers/register-handler-fx
:wallet-setup-navigate-back

View File

@ -158,7 +158,7 @@
:send-transaction-message
(concat models.message/send-interceptors
navigation/navigation-interceptors)
(fn [{:keys [db] :as cofx} [chat-id params]]
(fn [{:keys [db] :as cofx} [_ chat-id params]]
;;NOTE(goranjovic): we want to send the payment message only when we have a whisper id
;; for the recipient, we always redirect to `:wallet-transaction-sent` even when we don't
(if-let [send-command (and chat-id (get-in db [:id->command ["send" #{:personal-chats}]]))]

View File

@ -10,12 +10,12 @@
(defn- update-filters [db f]
(update-in db [:wallet.transactions :filters] f))
(handlers/register-handler-db
(handlers/register-handler-fx
:wallet.transactions/filter
(fn [db [_ path checked?]]
(update-filters db #(mark-checked % path checked?))))
(fn [{:keys [db]} [_ path checked?]]
{:db (update-filters db #(mark-checked % path checked?))}))
(handlers/register-handler-db
(handlers/register-handler-fx
:wallet.transactions/filter-all
(fn [db]
(update-filters db mark-all-checked)))
(fn [{:keys [db]} _]
{:db (update-filters db mark-all-checked)}))

View File

@ -102,11 +102,6 @@
(when js/goog.DEBUG check-spec)
(re-frame/inject-cofx :now)])
(defn register-handler-db
([name handler] (register-handler-db name nil handler))
([name interceptors handler]
(reg-event-db name [default-interceptors interceptors] handler)))
(defn register-handler-fx
([name handler] (register-handler-fx name nil handler))
([name interceptors handler]

View File

@ -43,7 +43,7 @@
:initialize-test
(fn [cofx [_]]
(handlers-macro/merge-fx cofx
(init/initialize-db)
(init/initialize-app-db)
(browser/initialize-browsers)
(browser/initialize-dapp-permissions)))))

View File

@ -13,10 +13,10 @@
(deftest receive-whisper-messages-test
(testing "an error is reported"
(is (nil? (handlers/receive-whisper-messages {} ["error" #js [] nil]))))
(is (nil? (handlers/receive-whisper-messages {} [_ "error" #js [] nil]))))
(testing "messages is undefined"
(is (nil? (handlers/receive-whisper-messages {} [nil js/undefined nil]))))
(is (nil? (handlers/receive-whisper-messages {} [_ nil js/undefined nil]))))
(testing "happy path"
(let [actual (handlers/receive-whisper-messages {} [nil messages "1"])]
(let [actual (handlers/receive-whisper-messages {} [_ nil messages "1"])]
(testing "it add an fx for the message"
(is (:chat-received-message/add-fx actual))))))