Skip to content

Commit

Permalink
feat(wallet): add recent recipients tab
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Son89 committed May 8, 2024
1 parent 10f5f9e commit 9712190
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/status_im/contexts/wallet/account/tabs/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
[options-drawer/view
{:name (:name collectible-details)
:image (:uri preview-url)}])}]))}]
:activity [activity/view {:activities []}]
:activity [activity/view]
:permissions [empty-tab/view
{:title (i18n/label :t/no-permissions)
:description (i18n/label :t/no-collectibles-description)
Expand Down
3 changes: 0 additions & 3 deletions src/status_im/contexts/wallet/account/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@
:default-active @selected-tab
:data (tabs-data watch-only?)
:on-change (rn/use-callback (fn [tab]
(when (and (= :activity tab)
(ff/enabled? :FLAG_WALLET_ACTIVITY_ENABLED))
(rf/dispatch [:wallet/fetch-activities]))
(reset! selected-tab tab)))
:scrollable? true
:scroll-on-press? true}]
Expand Down
2 changes: 0 additions & 2 deletions src/status_im/contexts/wallet/common/temp.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
[status-im.common.resources :as status.resources]
[utils.i18n :as i18n]))

(def address "0x39cf6E0Ba4C4530735616e1Ee7ff5FbCB726fBd4")

(def buy-tokens-list
[{:title "Ramp"
:description :text
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/contexts/wallet/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
(rf/reg-event-fx :wallet/navigate-to-account
(fn [{:keys [db]} [address]]
{:db (assoc-in db [:wallet :current-viewing-account-address] address)
:fx [[:dispatch [:navigate-to :screen/wallet.accounts address]]]}))
:fx [[:dispatch [:navigate-to :screen/wallet.accounts address]]
[:dispatch [:wallet/fetch-activities]]]}))

(rf/reg-event-fx :wallet/navigate-to-new-account
(fn [{:keys [db]} [address]]
Expand Down
27 changes: 21 additions & 6 deletions src/status_im/contexts/wallet/send/select_address/tabs/view.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[utils.i18n :as i18n]
[utils.re-frame :as rf]))

(defn my-accounts
(defn- my-accounts
[theme]
(let [other-accounts (rf/sub [:wallet/accounts-without-current-viewing-account])]
(if (zero? (count other-accounts))
Expand All @@ -27,15 +27,30 @@
:stack-id :screen/wallet.select-address}])}]))
other-accounts))))

(defn- recent-transactions
[theme]
(let [recent-recipients (rf/sub [:wallet/recent-recipients])]
(if (zero? (count recent-recipients))
[quo/empty-state
{:title (i18n/label :t/no-recent-transactions)
:description (i18n/label :t/make-one-it-is-easy-we-promise)
:image (resources/get-themed-image :angry-man theme)
:container-style style/empty-container-style}]
(into [rn/view {:style style/my-accounts-container}]
(map (fn [address]
[quo/address
{:address address
:on-press #(rf/dispatch [:wallet/select-send-address
{:address address
:recipient address
:stack-id :screen/wallet.select-address}])}]))
recent-recipients))))

(defn view
[{:keys [selected-tab]}]
(let [theme (quo.theme/use-theme)]
(case selected-tab
:tab/recent [quo/empty-state
{:title (i18n/label :t/no-recent-transactions)
:description (i18n/label :t/make-one-it-is-easy-we-promise)
:image (resources/get-themed-image :angry-man theme)
:container-style style/empty-container-style}]
:tab/recent [recent-transactions theme]
:tab/saved [quo/empty-state
{:title (i18n/label :t/no-saved-addresses)
:description (i18n/label :t/you-like-to-type-43-characters)
Expand Down
2 changes: 1 addition & 1 deletion src/status_im/feature_flags.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
(defonce ^:private feature-flags-config
(reagent/atom
{::community.edit-account-selection (enabled-in-env? :FLAG_EDIT_ACCOUNT_SELECTION_ENABLED)
::wallet.activities (enabled-in-env? :FLAG_WALLET_ACTIVITY_ENABLED)
::wallet.activities true
::wallet.assets-modal-hide (enabled-in-env? :FLAG_ASSETS_MODAL_HIDE)
::wallet.assets-modal-manage-tokens (enabled-in-env? :FLAG_ASSETS_MODAL_MANAGE_TOKENS)
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)
Expand Down
10 changes: 10 additions & 0 deletions src/status_im/subs/wallet/send.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@
(let [send-tx-ids (set (keys transactions))]
(select-keys transactions
(filter send-tx-ids tx-ids)))))

(rf/reg-sub
:wallet/recent-recipients
:<- [:wallet/activities-for-current-viewing-account]
:<- [:wallet/current-viewing-account-address]
(fn [[activities current-viewing-account-address]]
(let [users-sent-transactions (filter (fn [{:keys [sender]}]
(= sender current-viewing-account-address))
activities)]
(set (map :recipient users-sent-transactions)))))
15 changes: 14 additions & 1 deletion src/status_im/subs/wallet/send_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@
(is (= {"0x123" {:status :pending
:id 100
:chain-id 5}}
(rf/sub [sub-name])))))
(rf/sub [sub-name]))))

(h/deftest-sub :wallet/recent-recipients
[sub-name]
(testing "returns recent tab for selecting address"
(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 (= ["acc2"] (rf/sub [sub-name]))))))

0 comments on commit 9712190

Please sign in to comment.