[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 ;; 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 with network update when last update was more then week ago
(account-update {:db db} nil))))) (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?]] [_ address password account-creation?]]
(let [{account-network :network} (get-network-by-address db address) (let [{account-network :network} (get-network-by-address db address)
db' (-> db db' (-> db
(dissoc :db)
(assoc :accounts/account-creation? account-creation?) (assoc :accounts/account-creation? account-creation?)
(assoc-in [:accounts/login :processing] true)) (assoc-in [:accounts/login :processing] true))
wrap-fn (cond (not status-node-started?) wrap-fn (cond (not status-node-started?)
@ -118,14 +117,11 @@
:change-account-handler :change-account-handler
(fn [{db :db} [_ error address new-account?]] (fn [{db :db} [_ error address new-account?]]
(if (nil? error) (if (nil? error)
{:db (assoc db :accounts/login {}) {:db (dissoc db :accounts/login)
:dispatch-n (concat :dispatch-n [[:stop-debugging]
[[:stop-debugging] [:initialize-account address]
[:set-current-account address] [:navigate-to-clean :chat-list]
[:initialize-account address]]
(if new-account? (if new-account?
[[:navigate-to-clean :chat-list] [:navigate-to-chat console-chat-id]
[:navigate-to-chat console-chat-id]] [:navigate-to :chat-list])]}
[[:navigate-to-clean :chat-list]
[:navigate-to :chat-list]]))}
(log/debug "Error changing acount: " error)))) (log/debug "Error changing acount: " error))))

View File

@ -274,7 +274,10 @@
(let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts) (let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts)
contacts (into {} contacts-list)] contacts (into {} contacts-list)]
{:db (assoc db :contacts/contacts contacts) {: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 (register-handler-fx
:add-contacts :add-contacts

View File

@ -213,8 +213,8 @@
:initialize-db :initialize-db
(fn [{{:keys [status-module-initialized? status-node-started? (fn [{{:keys [status-module-initialized? status-node-started?
network-status network _] network-status network _]
:networks/keys [networks]} :db} _] :networks/keys [networks]
(let [network' (or network (get app-db :network))] :or {network (get app-db :network)}} :db} _]
{::init-store nil {::init-store nil
:db (assoc app-db :db (assoc app-db
:accounts/current-account-id nil :accounts/current-account-id nil
@ -222,22 +222,34 @@
:network-status network-status :network-status network-status
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?) :status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
:status-node-started? status-node-started? :status-node-started? status-node-started?
:network network')}))) :network network)}))
(register-handler-db (register-handler-db
:initialize-account-db :initialize-account-db
(fn [db _] (fn [{:keys [accounts/accounts networks/networks network view-id navigation-stack
(-> db status-module-initialized? status-node-started?]
(assoc :current-chat-id console-chat-id) :or [network (get app-db :network)]
(dissoc :transactions :as db} [_ address]]
:transactions-queue (-> app-db
:wallet (assoc :current-chat-id console-chat-id
:contacts/new-identity)))) :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 (register-handler-fx
:initialize-account :initialize-account
(fn [_ [_ address]] (fn [_ [_ address]]
{:dispatch-n [[:initialize-account-db] {:dispatch-n [[:initialize-account-db address]
[:load-processed-messages] [:load-processed-messages]
[:initialize-protocol address] [:initialize-protocol address]
[:initialize-sync-listener] [:initialize-sync-listener]
@ -250,7 +262,6 @@
[:send-account-update-if-needed] [:send-account-update-if-needed]
[:start-requesting-discoveries] [:start-requesting-discoveries]
[:remove-old-discoveries!] [:remove-old-discoveries!]
[:set :accounts/creating-account? false]
[:update-wallet] [:update-wallet]
[:update-transactions] [:update-transactions]
[:get-fcm-token]]})) [:get-fcm-token]]}))

View File

@ -31,7 +31,7 @@
address (:address new-account)] address (:address new-account)]
(rf/dispatch [:initialize-db]) (rf/dispatch [:initialize-db])
(rf/dispatch [:add-account new-account]) (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" (testing "Setting status from edit profile screen"
(let [new-status "New edit profile status"] (let [new-status "New edit profile status"]