added ability to reload the bank balances automatically.

This commit is contained in:
2021-10-29 14:47:27 -07:00
parent 43e0bc682a
commit edeb1b1f2e
5 changed files with 135 additions and 94 deletions

View File

@@ -104,20 +104,37 @@
:user (assoc user :token token)
:is-initial-loading? true)}))
(re-frame/reg-event-db
(re-frame/reg-event-fx
::received-initial
(fn [db [_ {accounts :accounts clients :client vendors :vendor :as x}]]
(fn [{:keys [db]} [_ {accounts :accounts clients :client vendors :vendor :as x}]]
(-> db
(assoc :clients (by :id clients) )
(assoc :vendors (by :id vendors) )
(assoc :is-initial-loading? false)
(assoc :accounts accounts )
(assoc :client (or (when (= 1 (count clients)) (->> clients first :id ))
(->> clients
(map :id)
(filter #(= % (:last-client-id db)))
first))))))
{:db (-> db
(assoc :clients (by :id clients) )
(assoc :vendors (by :id vendors) )
(assoc :is-initial-loading? false)
(assoc :accounts accounts )
(assoc :client (or (when (= 1 (count clients)) (->> clients first :id ))
(->> clients
(map :id)
(filter #(= % (:last-client-id db)))
first))))
:interval {:action :start
:id :refresh-clients
:frequency 600000
:event [::refresh-clients]}}))
(re-frame/reg-event-fx
::refresh-clients
(fn [{:keys [db]}]
(let [token (-> db :user)]
{:graphql {:token token
:query-obj {:venia/queries [[:client (client-query token)]]}
:on-success [::received-refreshed-clients]}})))
(re-frame/reg-event-fx
::received-refreshed-clients
(fn [{:keys [db]} [_ {clients :client}]]
{:db (assoc db :clients (by :id clients))}))
(re-frame/reg-event-db
::failed-initial