sort completed-transactions by timestamp
This commit is contained in:
parent
8c044d9991
commit
c22060542a
|
@ -78,8 +78,8 @@
|
||||||
(defn- empty-text [s] [react/text {:style history.styles/empty-text} s])
|
(defn- empty-text [s] [react/text {:style history.styles/empty-text} s])
|
||||||
|
|
||||||
(defview history-list []
|
(defview history-list []
|
||||||
(letsubs [transactions-history-list [:wallet/transactions-history-list]
|
(letsubs [transactions-history-list [:wallet.transactions/transactions-history-list]
|
||||||
transactions-loading? [:wallet/transactions-loading?]
|
transactions-loading? [:wallet.transactions/transactions-loading?]
|
||||||
error-message [:wallet.transactions/error-message?]]
|
error-message [:wallet.transactions/error-message?]]
|
||||||
[react/scroll-view {:style styles/flex}
|
[react/scroll-view {:style styles/flex}
|
||||||
(when error-message [wallet.views/error-message-view history.styles/error-container history.styles/error-message])
|
(when error-message [wallet.views/error-message-view history.styles/error-container history.styles/error-message])
|
||||||
|
@ -180,7 +180,7 @@
|
||||||
;; TODO(yenda) must reflect selected wallet
|
;; TODO(yenda) must reflect selected wallet
|
||||||
|
|
||||||
(defview transactions []
|
(defview transactions []
|
||||||
[unsigned-transactions [:wallet/unsigned-transactions]]
|
[unsigned-transactions [:wallet.transactions/unsigned-transactions]]
|
||||||
(let [tabs (tab-list unsigned-transactions)
|
(let [tabs (tab-list unsigned-transactions)
|
||||||
default-view (get-in tabs [0 :view-id])
|
default-view (get-in tabs [0 :view-id])
|
||||||
view-id (reagent/atom default-view)]
|
view-id (reagent/atom default-view)]
|
||||||
|
|
|
@ -60,40 +60,54 @@
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(get-in db [:wallet :balance-loading?])))
|
(get-in db [:wallet :balance-loading?])))
|
||||||
|
|
||||||
(reg-sub :wallet/transactions-loading?
|
(reg-sub :wallet.transactions/transactions-loading?
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(get-in db [:wallet :transactions-loading?])))
|
(get-in db [:wallet :transactions-loading?])))
|
||||||
|
|
||||||
(reg-sub :wallet/transactions
|
(reg-sub :wallet.transactions/transactions
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(get-in db [:wallet :transactions])))
|
(group-by :type (get-in db [:wallet :transactions]))))
|
||||||
|
|
||||||
(defn filter-transactions [type transactions]
|
(reg-sub :wallet.transactions/unsigned-transactions
|
||||||
(filter #(= (:type %) type) transactions))
|
:<- [:wallet.transactions/transactions]
|
||||||
|
|
||||||
(reg-sub :wallet/unsigned-transactions
|
|
||||||
:<- [:wallet/transactions]
|
|
||||||
(fn [transactions]
|
(fn [transactions]
|
||||||
(filter-transactions :unsigned transactions)))
|
(:unsigned transactions)))
|
||||||
|
|
||||||
(defn mini-str-date->keyword [mini-str-date]
|
(reg-sub :wallet.transactions/postponed-transactions-list
|
||||||
(keyword (str "sent-" (string/replace mini-str-date #" " "-"))))
|
:<- [:wallet.transactions/transactions]
|
||||||
|
(fn [{:keys [postponed]}]
|
||||||
|
(when postponed
|
||||||
|
{:title "Postponed"
|
||||||
|
:key :postponed
|
||||||
|
:data postponed})))
|
||||||
|
|
||||||
(reg-sub :wallet/transactions-history-list
|
(reg-sub :wallet.transactions/pending-transactions-list
|
||||||
:<- [:wallet/transactions]
|
:<- [:wallet.transactions/transactions]
|
||||||
(fn [transactions]
|
(fn [{:keys [pending]}]
|
||||||
(let [{:keys [postponed pending inbound outbound]} (group-by :type transactions)
|
(when pending
|
||||||
transaction-history-list [(if postponed
|
{:title "Pending"
|
||||||
{:title "Postponed"
|
:key :pending
|
||||||
:key :postponed
|
:data pending})))
|
||||||
:data postponed})
|
|
||||||
(if pending
|
(reg-sub :wallet.transactions/completed-transactions-list
|
||||||
{:title "Pending"
|
:<- [:wallet.transactions/transactions]
|
||||||
:key :pending
|
(fn [{:keys [inbound outbound]}]
|
||||||
:data pending})]
|
(->> (into inbound outbound)
|
||||||
completed-transactions (->> (into inbound outbound)
|
(group-by #(datetime/timestamp->date-key (:timestamp %)))
|
||||||
(group-by #(datetime/date->mini-str-date (:timestamp %)))
|
(sort-by key)
|
||||||
(map (fn [[k v]] {:title k
|
reverse
|
||||||
:key (mini-str-date->keyword k)
|
(map (fn [[k v]]
|
||||||
:data v})))]
|
{:title (datetime/timestamp->mini-date (:timestamp (first v)))
|
||||||
(into (filterv (complement nil?) transaction-history-list) (or completed-transactions [])))))
|
:key k
|
||||||
|
;; TODO (yenda investigate wether this sort-by is necessary or not)
|
||||||
|
:data (sort-by :timestamp v)})))))
|
||||||
|
|
||||||
|
(reg-sub :wallet.transactions/transactions-history-list
|
||||||
|
:<- [:wallet.transactions/postponed-transactions-list]
|
||||||
|
:<- [:wallet.transactions/pending-transactions-list]
|
||||||
|
:<- [:wallet.transactions/completed-transactions-list]
|
||||||
|
(fn [[postponed pending completed]]
|
||||||
|
(cond-> []
|
||||||
|
postponed (into postponed)
|
||||||
|
pending (into pending)
|
||||||
|
completed (into completed))))
|
||||||
|
|
|
@ -34,11 +34,16 @@
|
||||||
(before? date today) (label :t/datetime-yesterday)
|
(before? date today) (label :t/datetime-yesterday)
|
||||||
:else (today-format-fn local)))))
|
:else (today-format-fn local)))))
|
||||||
|
|
||||||
(defn date->mini-str-date [ms]
|
(defn timestamp->mini-date [ms]
|
||||||
(unparse (formatter "dd MMM") (-> ms
|
(unparse (formatter "dd MMM") (-> ms
|
||||||
from-long
|
from-long
|
||||||
(plus time-zone-offset))))
|
(plus time-zone-offset))))
|
||||||
|
|
||||||
|
(defn timestamp->date-key [ms]
|
||||||
|
(keyword (unparse (formatter "YYYYMMDD") (-> ms
|
||||||
|
from-long
|
||||||
|
(plus time-zone-offset)))))
|
||||||
|
|
||||||
(defn day-relative [ms]
|
(defn day-relative [ms]
|
||||||
(when (pos? ms)
|
(when (pos? ms)
|
||||||
(to-short-str ms #(label :t/datetime-today))))
|
(to-short-str ms #(label :t/datetime-today))))
|
||||||
|
|
Loading…
Reference in New Issue