-
Notifications
You must be signed in to change notification settings - Fork 985
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wallet): Activity Items - Sections (#19906)
feat(wallet): Activity Items - Sections (#19906)
- Loading branch information
Showing
7 changed files
with
104 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
(ns status-im.subs.wallet.activities | ||
(:require [re-frame.core :as rf])) | ||
(:require | ||
[re-frame.core :as rf] | ||
[status-im.contexts.wallet.common.activity-tab.constants :as constants] | ||
[utils.datetime :as datetime])) | ||
|
||
(rf/reg-sub | ||
:wallet/all-activities | ||
:<- [: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]] | ||
(filter (fn [{:keys [sender recipient]}] | ||
(or (= sender current-viewing-account-address) | ||
(= recipient current-viewing-account-address))) | ||
activities))) | ||
(->> activities | ||
(filter (fn [{:keys [sender recipient activity-type]}] | ||
(let [receiving-activity? (= activity-type constants/wallet-activity-type-receive) | ||
relevant-address (if receiving-activity? recipient sender)] | ||
(= relevant-address current-viewing-account-address)))) | ||
(distinct) | ||
(group-by (fn [{:keys [timestamp]}] | ||
(datetime/timestamp->relative-short-date (* timestamp 1000)))) | ||
(map (fn [[date activities]] | ||
{:title date :data activities :timestamp (:timestamp (first activities))})) | ||
(sort-by (fn [{:keys [timestamp]}] (- timestamp)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns status-im.subs.wallet.activities-test | ||
(:require | ||
[cljs.test :refer [is testing]] | ||
[re-frame.db :as rf-db] | ||
status-im.subs.root | ||
status-im.subs.wallet.collectibles | ||
[test-helpers.unit :as h] | ||
[utils.re-frame :as rf])) | ||
|
||
(h/deftest-sub :wallet/all-activities | ||
[sub-name] | ||
(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"}]) | ||
(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" | ||
(swap! rf-db/app-db | ||
(fn [db] | ||
(-> db | ||
(assoc-in [:wallet :activities] | ||
[{:sender "acc1" :recipient "acc2" :timestamp 1588291200} | ||
{:sender "acc2" :recipient "acc1" :timestamp 1588377600} | ||
{:sender "acc3" :recipient "acc4" :timestamp 1588464000}]) | ||
(assoc-in [:wallet :current-viewing-account-address] "acc1")))) | ||
(is (= [{:title "May 1, 2020" | ||
:data [{:sender "acc1" :recipient "acc2" :timestamp 1588291200}] | ||
:timestamp 1588291200}] | ||
(rf/sub [sub-name]))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters