[bug] fix #1784 db fields passed from one account to the other

This commit is contained in:
Eric Dvorsak 2017-11-08 15:00:22 +01:00 committed by Oskar Thorén
parent 80f9d018f2
commit 2ff2bfacf0
5 changed files with 44 additions and 42 deletions

View File

@ -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))))

View File

@ -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))))

View File

@ -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

View File

@ -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

View File

@ -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"]