Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
OmarBasem committed May 8, 2024
1 parent 0a57b49 commit 2a22cf3
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/status_im/contexts/wallet/account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[status-im.contexts.wallet.account.tabs.view :as tabs]
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
[status-im.feature-flags :as ff]
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

Expand Down
19 changes: 9 additions & 10 deletions src/status_im/subs/wallet/activities.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
:<- [:wallet]
:-> :activities)

(rf/reg-sub
:wallet/activities-for-current-viewing-account
(rf/reg-sub :wallet/activities-for-current-viewing-account
:<- [:wallet/all-activities]
:<- [:wallet/current-viewing-account-address]
(fn [[activities current-viewing-account-address]]
(let [account-activities (filter (fn [{:keys [sender recipient]}]
(or (= sender current-viewing-account-address)
(= recipient current-viewing-account-address)))
activities)
grouped-by-day (group-by (fn [{:keys [timestamp]}]
(datetime/timestamp->relative-short-date (* timestamp 1000)))
account-activities)]
(map (fn [[date acts]] {:title date :data acts}) grouped-by-day))))
(->> activities
(filter (fn [{:keys [sender recipient]}]
(or (= sender current-viewing-account-address)
(= recipient current-viewing-account-address))))
(group-by (fn [{:keys [timestamp]}]
(datetime/timestamp->relative-short-date (* timestamp 1000))))
(map (fn [[date activities]]
{:title date :data activities})))))
19 changes: 6 additions & 13 deletions src/status_im/subs/wallet/activities_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,21 @@

(h/deftest-sub :wallet/all-activities
[sub-name]
(testing
"Return the activities list from wallet data"
(testing "Return the activities list from wallet data"
(swap! rf-db/app-db assoc-in
[:wallet :activities]
[{:id 1 :name "Transaction1"}
{:id 2 :name "Transaction2"}])
(let [result (rf/sub [sub-name])]
(is (= [{:id 1 :name "Transaction1"} {:id 2 :name "Transaction2"}] @result)))))
(is (= [{:id 1 :name "Transaction1"} {:id 2 :name "Transaction2"}] (rf/sub [sub-name])))))

(h/deftest-sub :wallet/activities-for-current-viewing-account
[sub-name]
(testing
"Return activities filtered and grouped by account and dates"
(testing "Return activities filtered and grouped by account and dates"
(swap! rf-db/app-db assoc
{:wallet/all-activities [{:sender "acc1" :recipient "acc2" :timestamp 1588291200}
{:sender "acc2" :recipient "acc1" :timestamp 1588377600}
{:sender "acc3" :recipient "acc4" :timestamp 1588464000}]
:wallet/current-viewing-account-address "acc1"})
(let [result (rf/sub [sub-name])]
(is (= [{:title "May 1" :data [{:sender "acc1" :recipient "acc2" :timestamp 1588291200}]}
{:title "May 2" :data [{:sender "acc2" :recipient "acc1" :timestamp 1588377600}]}]
@result)))))



(is (= [{:title "May 1" :data [{:sender "acc1" :recipient "acc2" :timestamp 1588291200}]}
{:title "May 2" :data [{:sender "acc2" :recipient "acc1" :timestamp 1588377600}]}]
(rf/sub [sub-name])))))
7 changes: 5 additions & 2 deletions src/utils/datetime.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,11 @@

(defn full-date->short-date
[s]
(let [words (string/split s #"\s+")]
(string/join " " (take (- (count words) 2) words))))
(let [words (string/split s #"\s+")
last-word (last words)]
(if (or (= "AM" last-word) (= "PM" last-word))
(string/join " " (take (- (count words) 2) words))
s)))

(defn timestamp->relative-short-date
[ms]
Expand Down
30 changes: 30 additions & 0 deletions src/utils/datetime_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,36 @@
(is (= "Today 12:00 PM" (datetime/timestamp->relative 163684800000)))
(is (= "Today 12:00 AM" (datetime/timestamp->relative 163641600000))))))

(deftest timestamp->relative-short-date-test
(with-redefs [t/*ms-fn* (constantly 163696545000)
datetime/time-zone-offset (t/period :hours 0)
datetime/is-24-hour (constantly false)]
(testing "short date format for previous years"
(is (= "Dec 31, 1974" (datetime/timestamp->relative-short-date 157766399000)))
(is (= "Jan 1, 1973" (datetime/timestamp->relative-short-date 94694400000))))

(testing "short date format for dates 7 days ago or older, but in the current year"
(is (= "03 Mar" (datetime/timestamp->relative-short-date 163091745000)))
(is (= "02 Mar" (datetime/timestamp->relative-short-date 163004400000)))
(is (= "01 Jan" (datetime/timestamp->relative-short-date 157820400000))))

(testing "short date format for dates within the last 6 days"
(is (= "Sat" (datetime/timestamp->relative-short-date 163523745000)))
(is (= "Fri" (datetime/timestamp->relative-short-date 163437345000)))
(is (= "Thu" (datetime/timestamp->relative-short-date 163350945000)))
(is (= "Wed" (datetime/timestamp->relative-short-date 163264545000)))
(is (= "Tue" (datetime/timestamp->relative-short-date 163178145000))))

(testing "short date format for yesterday"
(is (= "Yesterday" (datetime/timestamp->relative-short-date 163610145000)))
(is (= "Yesterday" (datetime/timestamp->relative-short-date 163641599000))))

(testing "short date format for today, at various timestamps"
(is (= "Today" (datetime/timestamp->relative-short-date 163696545000)))
(is (= "Today" (datetime/timestamp->relative-short-date 163684800000)))
(is (= "Today" (datetime/timestamp->relative-short-date 163641600000))))))


#_((deftest day-relative-before-yesterday-force-24H-test
(with-redefs [t/*ms-fn* (constantly epoch-plus-3d)
datetime/is-24-hour (constantly true)
Expand Down

0 comments on commit 2a22cf3

Please sign in to comment.