From e72e25c342d3c6f487d9e63c6f5f163704b5ce0e Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Tue, 14 May 2024 15:36:38 +0200 Subject: [PATCH] feat(wallet): add recent recipients tab (#19942) --- .../contexts/wallet/account/tabs/view.cljs | 2 +- .../contexts/wallet/account/view.cljs | 3 --- .../contexts/wallet/common/temp.cljs | 2 -- src/status_im/contexts/wallet/events.cljs | 3 ++- .../wallet/send/select_address/tabs/view.cljs | 27 ++++++++++++++----- src/status_im/feature_flags.cljs | 1 - src/status_im/subs/wallet/send.cljs | 10 +++++++ src/status_im/subs/wallet/send_test.cljs | 13 +++++++++ 8 files changed, 47 insertions(+), 14 deletions(-) diff --git a/src/status_im/contexts/wallet/account/tabs/view.cljs b/src/status_im/contexts/wallet/account/tabs/view.cljs index 7728c25041..fd06ce5cad 100644 --- a/src/status_im/contexts/wallet/account/tabs/view.cljs +++ b/src/status_im/contexts/wallet/account/tabs/view.cljs @@ -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) diff --git a/src/status_im/contexts/wallet/account/view.cljs b/src/status_im/contexts/wallet/account/view.cljs index 79457cfc19..89d5149d1c 100644 --- a/src/status_im/contexts/wallet/account/view.cljs +++ b/src/status_im/contexts/wallet/account/view.cljs @@ -64,9 +64,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}] diff --git a/src/status_im/contexts/wallet/common/temp.cljs b/src/status_im/contexts/wallet/common/temp.cljs index 2ed1df5fa9..96d2b2397a 100644 --- a/src/status_im/contexts/wallet/common/temp.cljs +++ b/src/status_im/contexts/wallet/common/temp.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 107b31a427..3f31e47b7f 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -31,7 +31,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]] diff --git a/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs b/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs index bf54d0567e..809e81c4ae 100644 --- a/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs +++ b/src/status_im/contexts/wallet/send/select_address/tabs/view.cljs @@ -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)) @@ -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) diff --git a/src/status_im/feature_flags.cljs b/src/status_im/feature_flags.cljs index 19d9db6bb4..da6be9ae2d 100644 --- a/src/status_im/feature_flags.cljs +++ b/src/status_im/feature_flags.cljs @@ -14,7 +14,6 @@ ::settings.wallet-settings (enabled-in-env? :FLAG_WALLET_SETTINGS_ENABLED) ::settings.keypairs-and-accounts (enabled-in-env? :FLAG_WALLET_SETTINGS_KEYPAIRS_AND_ACCOUNTS_ENABLED) - ::wallet.activities (enabled-in-env? :FLAG_WALLET_ACTIVITY_ENABLED) ::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) diff --git a/src/status_im/subs/wallet/send.cljs b/src/status_im/subs/wallet/send.cljs index 74b3e7ccfe..d12797eeaa 100644 --- a/src/status_im/subs/wallet/send.cljs +++ b/src/status_im/subs/wallet/send.cljs @@ -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))))) diff --git a/src/status_im/subs/wallet/send_test.cljs b/src/status_im/subs/wallet/send_test.cljs index 622b904881..328b62159a 100644 --- a/src/status_im/subs/wallet/send_test.cljs +++ b/src/status_im/subs/wallet/send_test.cljs @@ -53,3 +53,16 @@ :id 100 :chain-id 5}} (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])))))