feat(wallet): add recent recipients tab (#19942)

This commit is contained in:
Jamie Caprani 2024-05-14 15:36:38 +02:00 committed by GitHub
parent d658fcf3db
commit e72e25c342
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 14 deletions

View File

@ -33,7 +33,7 @@
[options-drawer/view [options-drawer/view
{:name (:name collectible-details) {:name (:name collectible-details)
:image (:uri preview-url)}])}]))}] :image (:uri preview-url)}])}]))}]
:activity [activity/view {:activities []}] :activity [activity/view]
:permissions [empty-tab/view :permissions [empty-tab/view
{:title (i18n/label :t/no-permissions) {:title (i18n/label :t/no-permissions)
:description (i18n/label :t/no-collectibles-description) :description (i18n/label :t/no-collectibles-description)

View File

@ -64,9 +64,6 @@
:default-active @selected-tab :default-active @selected-tab
:data (tabs-data watch-only?) :data (tabs-data watch-only?)
:on-change (rn/use-callback (fn [tab] :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))) (reset! selected-tab tab)))
:scrollable? true :scrollable? true
:scroll-on-press? true}] :scroll-on-press? true}]

View File

@ -4,8 +4,6 @@
[status-im.common.resources :as status.resources] [status-im.common.resources :as status.resources]
[utils.i18n :as i18n])) [utils.i18n :as i18n]))
(def address "0x39cf6E0Ba4C4530735616e1Ee7ff5FbCB726fBd4")
(def buy-tokens-list (def buy-tokens-list
[{:title "Ramp" [{:title "Ramp"
:description :text :description :text

View File

@ -31,7 +31,8 @@
(rf/reg-event-fx :wallet/navigate-to-account (rf/reg-event-fx :wallet/navigate-to-account
(fn [{:keys [db]} [address]] (fn [{:keys [db]} [address]]
{:db (assoc-in db [:wallet :current-viewing-account-address] 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 (rf/reg-event-fx :wallet/navigate-to-new-account
(fn [{:keys [db]} [address]] (fn [{:keys [db]} [address]]

View File

@ -8,7 +8,7 @@
[utils.i18n :as i18n] [utils.i18n :as i18n]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
(defn my-accounts (defn- my-accounts
[theme] [theme]
(let [other-accounts (rf/sub [:wallet/accounts-without-current-viewing-account])] (let [other-accounts (rf/sub [:wallet/accounts-without-current-viewing-account])]
(if (zero? (count other-accounts)) (if (zero? (count other-accounts))
@ -27,15 +27,30 @@
:stack-id :screen/wallet.select-address}])}])) :stack-id :screen/wallet.select-address}])}]))
other-accounts)))) other-accounts))))
(defn view (defn- recent-transactions
[{:keys [selected-tab]}] [theme]
(let [theme (quo.theme/use-theme)] (let [recent-recipients (rf/sub [:wallet/recent-recipients])]
(case selected-tab (if (zero? (count recent-recipients))
:tab/recent [quo/empty-state [quo/empty-state
{:title (i18n/label :t/no-recent-transactions) {:title (i18n/label :t/no-recent-transactions)
:description (i18n/label :t/make-one-it-is-easy-we-promise) :description (i18n/label :t/make-one-it-is-easy-we-promise)
:image (resources/get-themed-image :angry-man theme) :image (resources/get-themed-image :angry-man theme)
:container-style style/empty-container-style}] :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 [recent-transactions theme]
:tab/saved [quo/empty-state :tab/saved [quo/empty-state
{:title (i18n/label :t/no-saved-addresses) {:title (i18n/label :t/no-saved-addresses)
:description (i18n/label :t/you-like-to-type-43-characters) :description (i18n/label :t/you-like-to-type-43-characters)

View File

@ -14,7 +14,6 @@
::settings.wallet-settings (enabled-in-env? :FLAG_WALLET_SETTINGS_ENABLED) ::settings.wallet-settings (enabled-in-env? :FLAG_WALLET_SETTINGS_ENABLED)
::settings.keypairs-and-accounts (enabled-in-env? ::settings.keypairs-and-accounts (enabled-in-env?
:FLAG_WALLET_SETTINGS_KEYPAIRS_AND_ACCOUNTS_ENABLED) :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-hide (enabled-in-env? :FLAG_ASSETS_MODAL_HIDE)
::wallet.assets-modal-manage-tokens (enabled-in-env? :FLAG_ASSETS_MODAL_MANAGE_TOKENS) ::wallet.assets-modal-manage-tokens (enabled-in-env? :FLAG_ASSETS_MODAL_MANAGE_TOKENS)
::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED) ::wallet.bridge-token (enabled-in-env? :FLAG_BRIDGE_TOKEN_ENABLED)

View File

@ -32,3 +32,13 @@
(let [send-tx-ids (set (keys transactions))] (let [send-tx-ids (set (keys transactions))]
(select-keys transactions (select-keys transactions
(filter send-tx-ids tx-ids))))) (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)))))

View File

@ -53,3 +53,16 @@
:id 100 :id 100
:chain-id 5}} :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])))))