From 2d71a15de7944e328a720ca264b9c49f98eece94 Mon Sep 17 00:00:00 2001 From: Volodymyr Kozieiev Date: Tue, 22 Oct 2024 16:10:14 +0100 Subject: [PATCH] collectible metrics (#21280) --- .../contexts/centralized_metrics/events.cljs | 2 +- .../centralized_metrics/events_test.cljs | 2 +- .../centralized_metrics/tracking.cljs | 27 ++++++++++++++----- .../centralized_metrics/tracking_test.cljs | 8 +++--- .../contexts/wallet/collectible/events.cljs | 12 +++++++-- src/status_im/contexts/wallet/db.cljs | 3 ++- src/status_im/contexts/wallet/events.cljs | 4 +++ src/status_im/contexts/wallet/home/view.cljs | 22 ++++++++------- src/status_im/subs/wallet/wallet.cljs | 6 +++++ 9 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/status_im/contexts/centralized_metrics/events.cljs b/src/status_im/contexts/centralized_metrics/events.cljs index e9087bf879..cb016a0c6f 100644 --- a/src/status_im/contexts/centralized_metrics/events.cljs +++ b/src/status_im/contexts/centralized_metrics/events.cljs @@ -14,7 +14,7 @@ (defn centralized-metrics-interceptor [context] - (when-let [event (tracking/tracked-event (interceptor/get-coeffect context :event))] + (when-let [event (tracking/metrics-event (interceptor/get-coeffect context :event))] (log/debug "tracking event" event) (when (push-event? (interceptor/get-coeffect context :db)) (native-module/add-centralized-metric event))) diff --git a/src/status_im/contexts/centralized_metrics/events_test.cljs b/src/status_im/contexts/centralized_metrics/events_test.cljs index 816609694f..feb394cfb1 100644 --- a/src/status_im/contexts/centralized_metrics/events_test.cljs +++ b/src/status_im/contexts/centralized_metrics/events_test.cljs @@ -15,7 +15,7 @@ (deftest centralized-metrics-interceptor-test (testing "processes context correctly" - (with-redefs [tracking/tracked-event (fn [_] {:metric "mocked-event"}) + (with-redefs [tracking/metrics-event (fn [_] {:metric "mocked-event"}) events/push-event? (fn [_] true)] (let [context {:coeffects {:event [:some-event] :db {:centralized-metrics/enabled? true}}}] diff --git a/src/status_im/contexts/centralized_metrics/tracking.cljs b/src/status_im/contexts/centralized_metrics/tracking.cljs index b605f70e63..97ab1098c7 100644 --- a/src/status_im/contexts/centralized_metrics/tracking.cljs +++ b/src/status_im/contexts/centralized_metrics/tracking.cljs @@ -43,23 +43,38 @@ :screen/onboarding.syncing-progress :screen/onboarding.syncing-progress-intro :screen/onboarding.syncing-results - :screen/onboarding.welcome}) + :screen/onboarding.welcome + + ;; Collectibles + :screen/wallet.collectible}) (defn track-view-id-event [view-id] (when (contains? view-ids-to-track view-id) (navigation-event (name view-id)))) -(defn tracked-event - [[event-name second-parameter]] - (case event-name +(defn navigated-to-collectibles-tab-event + [location] + (key-value-event "navigated-to-collectibles-tab" {:location location})) + +(defn metrics-event + [[rf-event-name rf-event-parameter]] + (case rf-event-name :profile/get-profiles-overview-success (user-journey-event app-started-event) :centralized-metrics/toggle-centralized-metrics - (key-value-event "events.metrics-enabled" {:enabled second-parameter}) + (key-value-event "events.metrics-enabled" {:enabled rf-event-parameter}) :set-view-id - (track-view-id-event second-parameter) + (track-view-id-event rf-event-parameter) + + :wallet/select-account-tab + (when (= rf-event-parameter :collectibles) + (navigated-to-collectibles-tab-event :account)) + + :wallet/select-home-tab + (when (= rf-event-parameter :collectibles) + (navigated-to-collectibles-tab-event :home)) nil)) diff --git a/src/status_im/contexts/centralized_metrics/tracking_test.cljs b/src/status_im/contexts/centralized_metrics/tracking_test.cljs index cbe139d043..380e1f94bb 100644 --- a/src/status_im/contexts/centralized_metrics/tracking_test.cljs +++ b/src/status_im/contexts/centralized_metrics/tracking_test.cljs @@ -63,17 +63,17 @@ :platform platform-os :appVersion app-version :eventValue {:action tracking/app-started-event}}} - (tracking/tracked-event [:profile/get-profiles-overview-success]))) + (tracking/metrics-event [:profile/get-profiles-overview-success]))) (is (= {:metric {:eventName "events.metrics-enabled" :platform platform-os :appVersion app-version :eventValue {:enabled true}}} - (tracking/tracked-event [:centralized-metrics/toggle-centralized-metrics true]))) + (tracking/metrics-event [:centralized-metrics/toggle-centralized-metrics true]))) (is (= {:metric {:eventName "navigation" :platform platform-os :appVersion app-version :eventValue {:viewId "wallet-stack"}}} - (tracking/tracked-event [:set-view-id :wallet-stack]))) - (is (nil? (tracking/tracked-event [:unknown-event]))))) + (tracking/metrics-event [:set-view-id :wallet-stack]))) + (is (nil? (tracking/metrics-event [:unknown-event]))))) diff --git a/src/status_im/contexts/wallet/collectible/events.cljs b/src/status_im/contexts/wallet/collectible/events.cljs index 7acd1d4b1f..6cceb48bec 100644 --- a/src/status_im/contexts/wallet/collectible/events.cljs +++ b/src/status_im/contexts/wallet/collectible/events.cljs @@ -43,10 +43,18 @@ (defn flush-collectibles [{:keys [db]}] - (let [collectibles-per-account (get-in db [:wallet :ui :collectibles :fetched])] + (let [collectibles-per-account (get-in db [:wallet :ui :collectibles :fetched]) + updated-accounts (move-collectibles-to-accounts (get-in db [:wallet :accounts]) + collectibles-per-account) + has-collectibles? (some (fn [account] + (pos? (count (:collectibles account)))) + (vals updated-accounts))] {:db (-> db (update-in [:wallet :ui :collectibles] dissoc :pending-requests :fetched) - (update-in [:wallet :accounts] move-collectibles-to-accounts collectibles-per-account))})) + (assoc-in [:wallet :accounts] updated-accounts)) + :fx [[:dispatch + [:centralized-metrics/track :metric/wallet-collectibles-fetched + {:has-collectibles? has-collectibles?}]]]})) (rf/reg-event-fx :wallet/flush-collectibles-fetched flush-collectibles) diff --git a/src/status_im/contexts/wallet/db.cljs b/src/status_im/contexts/wallet/db.cljs index 921476a62b..ad0e5a8d73 100644 --- a/src/status_im/contexts/wallet/db.cljs +++ b/src/status_im/contexts/wallet/db.cljs @@ -10,4 +10,5 @@ ;; Note: we set it to nil by default to differentiate when the user logs ;; in and the device is offline, versus re-fetching when offline and ;; tokens already exist in the app-db. - :tokens-loading nil}}) + :tokens-loading nil + :active-tab :assets}}) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 9da8679ed5..72f19b2c4a 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -59,6 +59,10 @@ (fn [{:keys [db]} [tab]] {:db (assoc-in db [:wallet :ui :account-page :active-tab] tab)})) +(rf/reg-event-fx :wallet/select-home-tab + (fn [{:keys [db]} [tab]] + {:db (assoc-in db [:wallet :ui :active-tab] tab)})) + (rf/reg-event-fx :wallet/clear-account-tab (fn [{:keys [db]}] {:db (assoc-in db [:wallet :ui :account-page :active-tab] nil)})) diff --git a/src/status_im/contexts/wallet/home/view.cljs b/src/status_im/contexts/wallet/home/view.cljs index a4cbee8c10..77b453e9bf 100644 --- a/src/status_im/contexts/wallet/home/view.cljs +++ b/src/status_im/contexts/wallet/home/view.cljs @@ -41,6 +41,8 @@ (when (ff/enabled? ::ff/wallet.home-activity) {:id :activity :label (i18n/label :t/activity) :accessibility-label :activity-tab})]) +(defn- change-tab [id] (rf/dispatch [:wallet/select-home-tab id])) + (defn- render-cards [cards ref] [rn/flat-list @@ -64,15 +66,15 @@ (defn view [] - (let [[selected-tab set-selected-tab] (rn/use-state (:id (first tabs-data))) - account-list-ref (rn/use-ref-atom nil) - tokens-loading? (rf/sub [:wallet/home-tokens-loading?]) - networks (rf/sub [:wallet/selected-network-details]) - account-cards-data (rf/sub [:wallet/account-cards-data]) - cards (conj account-cards-data (new-account-card-data)) - [init-loaded? set-init-loaded] (rn/use-state false) - {:keys [formatted-balance]} (rf/sub [:wallet/aggregated-token-values-and-balance]) - theme (quo.theme/use-theme)] + (let [selected-tab (rf/sub [:wallet/home-tab]) + account-list-ref (rn/use-ref-atom nil) + tokens-loading? (rf/sub [:wallet/home-tokens-loading?]) + networks (rf/sub [:wallet/selected-network-details]) + account-cards-data (rf/sub [:wallet/account-cards-data]) + cards (conj account-cards-data (new-account-card-data)) + [init-loaded? set-init-loaded] (rn/use-state false) + {:keys [formatted-balance]} (rf/sub [:wallet/aggregated-token-values-and-balance]) + theme (quo.theme/use-theme)] (rn/use-effect (fn [] (when (and @account-list-ref (pos? (count cards))) (.scrollToOffset ^js @account-list-ref @@ -104,7 +106,7 @@ (when (ff/enabled? ::ff/wallet.graph) [quo/wallet-graph {:time-frame :empty}]) [render-cards cards account-list-ref] - [render-tabs tabs-data set-selected-tab selected-tab]] + [render-tabs tabs-data change-tab selected-tab]] :content-container-style style/list-container :sticky-header-indices [0] :data [] diff --git a/src/status_im/subs/wallet/wallet.cljs b/src/status_im/subs/wallet/wallet.cljs index a7d21e3bef..a73d5dd5a3 100644 --- a/src/status_im/subs/wallet/wallet.cljs +++ b/src/status_im/subs/wallet/wallet.cljs @@ -591,6 +591,12 @@ (fn [ui] (get-in ui [:account-page :active-tab]))) +(rf/reg-sub + :wallet/home-tab + :<- [:wallet/ui] + (fn [ui] + (:active-tab ui))) + (rf/reg-sub :wallet/aggregated-tokens :<- [:wallet/accounts-without-watched-accounts]