diff --git a/src/status_im/ui/screens/accounts/events.cljs b/src/status_im/ui/screens/accounts/events.cljs index e9973c87d6..9cab6c38f4 100644 --- a/src/status_im/ui/screens/accounts/events.cljs +++ b/src/status_im/ui/screens/accounts/events.cljs @@ -189,11 +189,3 @@ ;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update ;; account with network update when last update was more then week ago (account-update {:db db} nil))))) - -(handlers/register-handler-db - :set-current-account - (fn [{:accounts/keys [accounts] :as db} [_ address]] - (let [key (:public-key (accounts address))] - (assoc db - :accounts/current-account-id address - :current-public-key key)))) diff --git a/src/status_im/ui/screens/accounts/login/events.cljs b/src/status_im/ui/screens/accounts/login/events.cljs index 7959ba79a2..469c097b0e 100644 --- a/src/status_im/ui/screens/accounts/login/events.cljs +++ b/src/status_im/ui/screens/accounts/login/events.cljs @@ -84,7 +84,6 @@ [_ address password account-creation?]] (let [{account-network :network} (get-network-by-address db address) db' (-> db - (dissoc :db) (assoc :accounts/account-creation? account-creation?) (assoc-in [:accounts/login :processing] true)) wrap-fn (cond (not status-node-started?) @@ -118,14 +117,11 @@ :change-account-handler (fn [{db :db} [_ error address new-account?]] (if (nil? error) - {:db (assoc db :accounts/login {}) - :dispatch-n (concat - [[:stop-debugging] - [:set-current-account address] - [:initialize-account address]] - (if new-account? - [[:navigate-to-clean :chat-list] - [:navigate-to-chat console-chat-id]] - [[:navigate-to-clean :chat-list] - [:navigate-to :chat-list]]))} + {:db (dissoc db :accounts/login) + :dispatch-n [[:stop-debugging] + [:initialize-account address] + [:navigate-to-clean :chat-list] + (if new-account? + [:navigate-to-chat console-chat-id] + [:navigate-to :chat-list])]} (log/debug "Error changing acount: " error)))) diff --git a/src/status_im/ui/screens/contacts/events.cljs b/src/status_im/ui/screens/contacts/events.cljs index 10117135d3..94665b5bbf 100644 --- a/src/status_im/ui/screens/contacts/events.cljs +++ b/src/status_im/ui/screens/contacts/events.cljs @@ -274,7 +274,10 @@ (let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts) contacts (into {} contacts-list)] {:db (assoc db :contacts/contacts contacts) - :dispatch-n (mapv (fn [_ contact] [:watch-contact contact]) contacts)}))) + ;; TODO (yenda) this mapv was dispatching useless events, fixed but is it necessary if + ;; it was dispatching useless events before with nil + ;;:dispatch-n (mapv (fn [[_ contact]] [:watch-contact contact]) contacts) + }))) (register-handler-fx :add-contacts diff --git a/src/status_im/ui/screens/events.cljs b/src/status_im/ui/screens/events.cljs index 4810614ea5..a953541a99 100644 --- a/src/status_im/ui/screens/events.cljs +++ b/src/status_im/ui/screens/events.cljs @@ -213,31 +213,43 @@ :initialize-db (fn [{{:keys [status-module-initialized? status-node-started? network-status network _] - :networks/keys [networks]} :db} _] - (let [network' (or network (get app-db :network))] - {::init-store nil - :db (assoc app-db - :accounts/current-account-id nil - :contacts/contacts {} - :network-status network-status - :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) - :status-node-started? status-node-started? - :network network')}))) + :networks/keys [networks] + :or {network (get app-db :network)}} :db} _] + {::init-store nil + :db (assoc app-db + :accounts/current-account-id nil + :contacts/contacts {} + :network-status network-status + :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) + :status-node-started? status-node-started? + :network network)})) (register-handler-db :initialize-account-db - (fn [db _] - (-> db - (assoc :current-chat-id console-chat-id) - (dissoc :transactions - :transactions-queue - :wallet - :contacts/new-identity)))) + (fn [{:keys [accounts/accounts networks/networks network view-id navigation-stack + status-module-initialized? status-node-started?] + :or [network (get app-db :network)] + :as db} [_ address]] + (-> app-db + (assoc :current-chat-id console-chat-id + :accounts/current-account-id address + ;; TODO (yenda) bad, this is derived data and shouldn't be stored in the db + ;; the cost of retrieving public key from db with a function taking using + ;; current-account-id is negligeable + :current-public-key (:public-key (accounts address)) + :view-id view-id + :navigation-stack navigation-stack + :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) + :status-node-started? status-node-started? + :accounts/accounts accounts + :accounts/creating-account? false + :networks/networks networks + :network network)))) (register-handler-fx :initialize-account (fn [_ [_ address]] - {:dispatch-n [[:initialize-account-db] + {:dispatch-n [[:initialize-account-db address] [:load-processed-messages] [:initialize-protocol address] [:initialize-sync-listener] @@ -250,7 +262,6 @@ [:send-account-update-if-needed] [:start-requesting-discoveries] [:remove-old-discoveries!] - [:set :accounts/creating-account? false] [:update-wallet] [:update-transactions] [:get-fcm-token]]})) @@ -349,8 +360,8 @@ (register-handler-fx :app-state-change (fn [_ [_ state]])) - ;; TODO(rasom): let's not remove this handler, it will be used for - ;; pausing node on entering background on android +;; TODO(rasom): let's not remove this handler, it will be used for +;; pausing node on entering background on android (register-handler-fx diff --git a/test/cljs/status_im/test/profile/events.cljs b/test/cljs/status_im/test/profile/events.cljs index 42f6a55e75..33513aab32 100644 --- a/test/cljs/status_im/test/profile/events.cljs +++ b/test/cljs/status_im/test/profile/events.cljs @@ -31,7 +31,7 @@ address (:address new-account)] (rf/dispatch [:initialize-db]) (rf/dispatch [:add-account new-account]) - (rf/dispatch [:set-current-account address]) + (rf/dispatch [:initialize-account-db address]) (testing "Setting status from edit profile screen" (let [new-status "New edit profile status"]