Fixing fx arguments and event dispatches

Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
This commit is contained in:
Eric Dvorsak 2018-03-03 20:09:12 +01:00
parent 7efcdcb150
commit e9e1456afc
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
3 changed files with 38 additions and 39 deletions

View File

@ -83,7 +83,7 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:create-account :create-account
(fn [{{:accounts/keys [create] :as db} :db}] (fn [{{:accounts/keys [create] :as db} :db} _]
{:db (update db :accounts/create assoc :step :account-creating :error nil) {:db (update db :accounts/create assoc :step :account-creating :error nil)
::create-account (:password create)})) ::create-account (:password create)}))
@ -123,7 +123,7 @@
(log/debug "account-created") (log/debug "account-created")
(when-not (str/blank? pubkey) (when-not (str/blank? pubkey)
(-> (add-account db account) (-> (add-account db account)
(assoc :dispatch [:login-account normalized-address password true])))))) (assoc :dispatch [:login-account normalized-address password]))))))
(handlers/register-handler-fx (handlers/register-handler-fx
:load-accounts :load-accounts
@ -209,4 +209,4 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:reset-account-creation :reset-account-creation
(fn [{db :db} _] (fn [{db :db} _]
{:db (update db :accounts/create assoc :step :enter-password :password nil :password-confirm nil :error nil)})) {:db (update db :accounts/create assoc :step :enter-password :password nil :password-confirm nil :error nil)}))

View File

@ -26,17 +26,16 @@
(reg-fx (reg-fx
::change-account ::change-account
(fn [[address new-account?]] (fn [[address]]
;; if we don't add delay when running app without status-go ;; if we don't add delay when running app without status-go
;; "null is not an object (evaluating 'realm.schema')" error appears ;; "null is not an object (evaluating 'realm.schema')" error appears
(if config/stub-status-go? (let [change-account-fn (fn [] (data-store/change-account address
(utils/set-timeout false
(fn [] #(dispatch [:change-account-handler % address])))]
(data-store/change-account address new-account? (if config/stub-status-go?
#(dispatch [:change-account-handler % address]))) (utils/set-timeout change-account-fn
300) 300)
(data-store/change-account address new-account? (change-account-fn)))))
#(dispatch [:change-account-handler % address])))))
;;;; Handlers ;;;; Handlers
@ -90,8 +89,7 @@
(register-handler-fx (register-handler-fx
:login-account :login-account
(fn [{{:keys [network status-node-started?] :as db} :db} (fn [{{:keys [network status-node-started?] :as db} :db} [_ address password]]
[_ address password]]
(let [{account-network :network} (get-network-by-address db address) (let [{account-network :network} (get-network-by-address db address)
wnode (get-wnode-by-address db address) wnode (get-wnode-by-address db address)
db' (-> db db' (-> db

View File

@ -293,12 +293,11 @@
[:update-transactions] [:update-transactions]
[:get-fcm-token] [:get-fcm-token]
[:update-sign-in-time]] [:update-sign-in-time]]
(seq events-after) (seq events-after) (into events-after))}))
(into events-after))}))
(handlers/register-handler-fx (handlers/register-handler-fx
:initialize-views :initialize-views
(fn [{{:accounts/keys [accounts] :as db} :db}] (fn [{{:accounts/keys [accounts] :as db} :db} _]
{:db (if (empty? accounts) {:db (if (empty? accounts)
(assoc db :view-id :intro :navigation-stack (list :intro)) (assoc db :view-id :intro :navigation-stack (list :intro))
(let [{:keys [address photo-path name]} (first (sort-by :last-sign-in > (vals accounts)))] (let [{:keys [address photo-path name]} (first (sort-by :last-sign-in > (vals accounts)))]
@ -348,17 +347,17 @@
(defn handle-jail-signal [{:keys [chat_id data]}] (defn handle-jail-signal [{:keys [chat_id data]}]
(let [{:keys [event data]} (types/json->clj data)] (let [{:keys [event data]} (types/json->clj data)]
(case event (case event
"local-storage" (re-frame/dispatch [:set-local-storage {:chat-id chat_id "local-storage" [:set-local-storage {:chat-id chat_id
:data data}]) :data data}]
"show-suggestions" (re-frame/dispatch [:show-suggestions-from-jail {:chat-id chat_id "show-suggestions" [:show-suggestions-from-jail {:chat-id chat_id
:markup data}]) :markup data}]
"send-message" (re-frame/dispatch [:chat-send-message/from-jail {:chat-id chat_id "send-message" [:chat-send-message/from-jail {:chat-id chat_id
:message data}]) :message data}]
"handler-result" (let [orig-params (:origParams data)] "handler-result" (let [orig-params (:origParams data)]
;; TODO(janherich): figure out and fix chat_id from event ;; TODO(janherich): figure out and fix chat_id from event
(re-frame/dispatch [:command-handler! (:chat-id orig-params) [:command-handler! (:chat-id orig-params)
(restore-command-ref-keyword orig-params) (restore-command-ref-keyword orig-params)
{:result {:returned (dissoc data :origParams)}}])) {:result {:returned (dissoc data :origParams)}}])
(log/debug "Unknown jail signal " event)))) (log/debug "Unknown jail signal " event))))
(handlers/register-handler-fx (handlers/register-handler-fx
@ -366,15 +365,17 @@
(fn [_ [_ event-str]] (fn [_ [_ event-str]]
(log/debug :event-str event-str) (log/debug :event-str event-str)
(inst/log (str "Signal event: " event-str)) (inst/log (str "Signal event: " event-str))
(let [{:keys [type event]} (types/json->clj event-str)] (let [{:keys [type event]} (types/json->clj event-str)
(case type to-dispatch (case type
"transaction.queued" (re-frame/dispatch [:transaction-queued event]) "transaction.queued" [:transaction-queued event]
"transaction.failed" (re-frame/dispatch [:transaction-failed event]) "transaction.failed" [:transaction-failed event]
"node.started" (re-frame/dispatch [:status-node-started]) "node.started" [:status-node-started]
"node.stopped" (re-frame/dispatch [:status-node-stopped]) "node.stopped" [:status-node-stopped]
"module.initialized" (re-frame/dispatch [:status-module-initialized]) "module.initialized" [:status-module-initialized]
"jail.signal" (handle-jail-signal event) "jail.signal" (handle-jail-signal event)
(log/debug "Event " type " not handled"))))) (log/debug "Event " type " not handled"))]
(when to-dispatch
{:dispatch to-dispatch}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:status-module-initialized :status-module-initialized
@ -384,13 +385,13 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:status-node-started :status-node-started
(fn [{{:node/keys [after-start] :as db} :db}] (fn [{{:node/keys [after-start] :as db} :db} _]
(merge {:db (assoc db :status-node-started? true)} (merge {:db (assoc db :status-node-started? true)}
(when after-start {:dispatch-n [after-start]})))) (when after-start {:dispatch-n [after-start]}))))
(handlers/register-handler-fx (handlers/register-handler-fx
:status-node-stopped :status-node-stopped
(fn [{{:node/keys [after-stop]} :db}] (fn [{{:node/keys [after-stop]} :db} _]
(when after-stop {:dispatch-n [after-stop]}))) (when after-stop {:dispatch-n [after-stop]})))
(handlers/register-handler-fx (handlers/register-handler-fx