2016-10-04 14:49:59 +03:00
|
|
|
(ns status-im.data-store.accounts
|
2018-04-02 18:17:15 +02:00
|
|
|
(:require [cljs.core.async :as async]
|
|
|
|
[re-frame.core :as re-frame]
|
|
|
|
[status-im.data-store.realm.core :as core]
|
|
|
|
[status-im.data-store.realm.accounts :as data-store]))
|
2016-10-04 14:49:59 +03:00
|
|
|
|
2018-04-02 18:17:15 +02:00
|
|
|
;; TODO janherich: define as cofx once debug handlers are refactored
|
2016-10-04 14:49:59 +03:00
|
|
|
(defn get-by-address [address]
|
|
|
|
(data-store/get-by-address address))
|
|
|
|
|
2018-04-02 18:17:15 +02:00
|
|
|
(re-frame/reg-cofx
|
2018-05-07 17:09:06 +03:00
|
|
|
:data-store/get-all-accounts
|
|
|
|
(fn [coeffects _]
|
|
|
|
(assoc coeffects :all-accounts (data-store/get-all-as-list))))
|
2018-04-02 18:17:15 +02:00
|
|
|
|
|
|
|
(re-frame/reg-fx
|
2018-05-07 17:09:06 +03:00
|
|
|
:data-store/save-account
|
|
|
|
(fn [{:keys [after-update-event] :as account}]
|
|
|
|
(let [account-to-save (dissoc account :after-update-event)]
|
|
|
|
(async/go (async/>! core/realm-queue #(if after-update-event
|
|
|
|
(do (data-store/save account-to-save true)
|
|
|
|
(re-frame/dispatch after-update-event))
|
|
|
|
(data-store/save account-to-save true)))))))
|
2018-04-02 18:17:15 +02:00
|
|
|
|