From e66ae8b388ccf074cedecdfcf788dedeffee3961 Mon Sep 17 00:00:00 2001 From: Eric Dvorsak Date: Thu, 5 Oct 2017 02:00:35 +0200 Subject: [PATCH] [bug] fix order of transactions in sections of transactions history order should be latest transaction first --- .../ui/screens/wallet/transactions/subs.cljs | 22 +++++++------- test/cljs/status_im/test/runner.cljs | 2 ++ .../test/wallet/transactions/subs.cljs | 29 +++++++++++++++++++ 3 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 test/cljs/status_im/test/wallet/transactions/subs.cljs diff --git a/src/status_im/ui/screens/wallet/transactions/subs.cljs b/src/status_im/ui/screens/wallet/transactions/subs.cljs index dcea4d838e..e38c0f8d98 100644 --- a/src/status_im/ui/screens/wallet/transactions/subs.cljs +++ b/src/status_im/ui/screens/wallet/transactions/subs.cljs @@ -66,18 +66,20 @@ :key :pending :data pending}))) +(defn group-transactions-by-date [transactions] + (->> transactions + (group-by #(datetime/timestamp->date-key (:timestamp %))) + (sort-by key) + reverse + (map (fn [[date-key transactions]] + {:title (datetime/timestamp->mini-date (:timestamp (first transactions))) + :key date-key + :data (sort-by :timestamp > transactions)})))) + (reg-sub :wallet.transactions/completed-transactions-list :<- [:wallet.transactions/grouped-transactions] (fn [{:keys [inbound outbound]}] - (->> (into inbound outbound) - (group-by #(datetime/timestamp->date-key (:timestamp %))) - (sort-by key) - reverse - (map (fn [[k v]] - {:title (datetime/timestamp->mini-date (:timestamp (first v))) - :key k - ;; TODO (yenda investigate wether this sort-by is necessary or not) - :data (sort-by :timestamp v)}))))) + (group-transactions-by-date (into inbound outbound)))) (reg-sub :wallet.transactions/transactions-history-list :<- [:wallet.transactions/postponed-transactions-list] @@ -114,7 +116,7 @@ :nonce (i18n/label :not-applicable)} {:cost (money/wei->str :eth (money/fee-value gas-used gas-price)) :url (transactions/get-transaction-details-url network hash)}) - ;; TODO (yenda) proper wallet logic when wallet switching is impletmented + ;; TODO (yenda) proper wallet logic when wallet switching is implemented (if (= type :inbound) {:to-wallet "Main wallet"} {:from-wallet "Main wallet"}))))) diff --git a/test/cljs/status_im/test/runner.cljs b/test/cljs/status_im/test/runner.cljs index 9923006cd2..480eed40de 100644 --- a/test/cljs/status_im/test/runner.cljs +++ b/test/cljs/status_im/test/runner.cljs @@ -4,6 +4,7 @@ [status-im.test.contacts.events] [status-im.test.accounts.events] [status-im.test.wallet.events] + [status-im.test.wallet.transactions.subs] [status-im.test.profile.events] [status-im.test.chat.models.input] [status-im.test.components.main-tabs] @@ -30,6 +31,7 @@ 'status-im.test.contacts.events 'status-im.test.profile.events 'status-im.test.wallet.events + 'status-im.test.wallet.transactions.subs 'status-im.test.chat.models.input 'status-im.test.components.main-tabs 'status-im.test.handlers diff --git a/test/cljs/status_im/test/wallet/transactions/subs.cljs b/test/cljs/status_im/test/wallet/transactions/subs.cljs new file mode 100644 index 0000000000..4c0909d7e8 --- /dev/null +++ b/test/cljs/status_im/test/wallet/transactions/subs.cljs @@ -0,0 +1,29 @@ +(ns status-im.test.wallet.transactions.subs + (:require [cljs.test :refer [deftest is testing]] + reagent.core + [re-frame.core :as re-frame] + [day8.re-frame.test :refer [run-test-sync]] + status-im.ui.screens.db + status-im.ui.screens.subs + [status-im.ui.screens.events :as events] + [status-im.ui.screens.wallet.transactions.subs :as transactions-subs])) + +(def transactions [{:timestamp "1505912551000"} + {:timestamp "1505764322000"} + {:timestamp "1505750000000"}]) + +(def grouped-transactions '({:title "20 Sep" + :key :20170920 + :data + ({:timestamp "1505912551000"})} + {:title "18 Sep" + :key :20170918 + :data + ({:timestamp "1505764322000"} + {:timestamp "1505750000000"})})) + + +(deftest group-transactions-by-date + "Check if transactions are sorted by date" + (is (= (transactions-subs/group-transactions-by-date transactions) + grouped-transactions)))