Sync wallet accounts

a244d77657...a244d77657
This commit is contained in:
Vitaliy Vlasov 2022-04-27 19:02:07 +03:00
parent b9f7e8758d
commit 95be83756b
2 changed files with 20 additions and 0 deletions

View File

@ -419,6 +419,17 @@
[{:keys [db]}]
{::open-last-chat (get-in db [:multiaccount :key-uid])})
(fx/defn update-wallet-accounts
[{:keys [db]} accounts]
(let [existing-accounts (into {} (map #(vector (:address %1) %1) (:multiaccount/accounts db)))
reduce-fn (fn [existing-accs new-acc]
(let [address (:address new-acc)]
(if (:removed new-acc)
(dissoc existing-accs address)
(assoc existing-accs address new-acc))))
new-accounts (reduce reduce-fn existing-accounts (rpc->accounts accounts))]
{:db (assoc db :multiaccount/accounts (vals new-accounts))}))
(fx/defn get-chats-callback
{:events [::get-chats-callback]}
[{:keys [db] :as cofx}]

View File

@ -19,6 +19,7 @@
[status-im.utils.types :as types]
[status-im.constants :as constants]
[status-im.multiaccounts.model :as multiaccounts.model]
[status-im.multiaccounts.login.core :as multiaccounts.login]
[status-im.notifications-center.core :as notifications-center]
[status-im.visibility-status-updates.core :as models.visibility-status-updates]
[status-im.browser.core :as browser]
@ -51,6 +52,7 @@
^js settings (.-settings response-js)
^js cleared-histories (.-clearedHistories response-js)
^js identity-images (.-identityImages response-js)
^js accounts (.-accounts response-js)
sync-handler (when-not process-async process-response)]
(cond
@ -159,6 +161,13 @@
(models.visibility-status-updates/handle-visibility-status-updates
visibility-status-updates-clj)))
(seq accounts)
(do
(js-delete response-js "accounts")
(fx/merge cofx
(process-next response-js sync-handler)
(multiaccounts.login/update-wallet-accounts (types/js->clj accounts))))
(seq settings)
(do
(js-delete response-js "settings")