collectible metrics (#21280)

This commit is contained in:
Volodymyr Kozieiev 2024-10-22 16:10:14 +01:00 committed by Icaro Motta
parent fa42a1b977
commit 2d71a15de7
9 changed files with 61 additions and 25 deletions

View File

@ -14,7 +14,7 @@
(defn centralized-metrics-interceptor (defn centralized-metrics-interceptor
[context] [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) (log/debug "tracking event" event)
(when (push-event? (interceptor/get-coeffect context :db)) (when (push-event? (interceptor/get-coeffect context :db))
(native-module/add-centralized-metric event))) (native-module/add-centralized-metric event)))

View File

@ -15,7 +15,7 @@
(deftest centralized-metrics-interceptor-test (deftest centralized-metrics-interceptor-test
(testing "processes context correctly" (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)] events/push-event? (fn [_] true)]
(let [context {:coeffects {:event [:some-event] (let [context {:coeffects {:event [:some-event]
:db {:centralized-metrics/enabled? true}}}] :db {:centralized-metrics/enabled? true}}}]

View File

@ -43,23 +43,38 @@
:screen/onboarding.syncing-progress :screen/onboarding.syncing-progress
:screen/onboarding.syncing-progress-intro :screen/onboarding.syncing-progress-intro
:screen/onboarding.syncing-results :screen/onboarding.syncing-results
:screen/onboarding.welcome}) :screen/onboarding.welcome
;; Collectibles
:screen/wallet.collectible})
(defn track-view-id-event (defn track-view-id-event
[view-id] [view-id]
(when (contains? view-ids-to-track view-id) (when (contains? view-ids-to-track view-id)
(navigation-event (name view-id)))) (navigation-event (name view-id))))
(defn tracked-event (defn navigated-to-collectibles-tab-event
[[event-name second-parameter]] [location]
(case event-name (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 :profile/get-profiles-overview-success
(user-journey-event app-started-event) (user-journey-event app-started-event)
:centralized-metrics/toggle-centralized-metrics :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 :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)) nil))

View File

@ -63,17 +63,17 @@
:platform platform-os :platform platform-os
:appVersion app-version :appVersion app-version
:eventValue {:action tracking/app-started-event}}} :eventValue {:action tracking/app-started-event}}}
(tracking/tracked-event [:profile/get-profiles-overview-success]))) (tracking/metrics-event [:profile/get-profiles-overview-success])))
(is (= {:metric (is (= {:metric
{:eventName "events.metrics-enabled" {:eventName "events.metrics-enabled"
:platform platform-os :platform platform-os
:appVersion app-version :appVersion app-version
:eventValue {:enabled true}}} :eventValue {:enabled true}}}
(tracking/tracked-event [:centralized-metrics/toggle-centralized-metrics true]))) (tracking/metrics-event [:centralized-metrics/toggle-centralized-metrics true])))
(is (= {:metric (is (= {:metric
{:eventName "navigation" {:eventName "navigation"
:platform platform-os :platform platform-os
:appVersion app-version :appVersion app-version
:eventValue {:viewId "wallet-stack"}}} :eventValue {:viewId "wallet-stack"}}}
(tracking/tracked-event [:set-view-id :wallet-stack]))) (tracking/metrics-event [:set-view-id :wallet-stack])))
(is (nil? (tracking/tracked-event [:unknown-event]))))) (is (nil? (tracking/metrics-event [:unknown-event])))))

View File

@ -43,10 +43,18 @@
(defn flush-collectibles (defn flush-collectibles
[{:keys [db]}] [{: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 {:db (-> db
(update-in [:wallet :ui :collectibles] dissoc :pending-requests :fetched) (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) (rf/reg-event-fx :wallet/flush-collectibles-fetched flush-collectibles)

View File

@ -10,4 +10,5 @@
;; Note: we set it to nil by default to differentiate when the user logs ;; 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 ;; in and the device is offline, versus re-fetching when offline and
;; tokens already exist in the app-db. ;; tokens already exist in the app-db.
:tokens-loading nil}}) :tokens-loading nil
:active-tab :assets}})

View File

@ -59,6 +59,10 @@
(fn [{:keys [db]} [tab]] (fn [{:keys [db]} [tab]]
{:db (assoc-in db [:wallet :ui :account-page :active-tab] 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 (rf/reg-event-fx :wallet/clear-account-tab
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (assoc-in db [:wallet :ui :account-page :active-tab] nil)})) {:db (assoc-in db [:wallet :ui :account-page :active-tab] nil)}))

View File

@ -41,6 +41,8 @@
(when (ff/enabled? ::ff/wallet.home-activity) (when (ff/enabled? ::ff/wallet.home-activity)
{:id :activity :label (i18n/label :t/activity) :accessibility-label :activity-tab})]) {: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 (defn- render-cards
[cards ref] [cards ref]
[rn/flat-list [rn/flat-list
@ -64,15 +66,15 @@
(defn view (defn view
[] []
(let [[selected-tab set-selected-tab] (rn/use-state (:id (first tabs-data))) (let [selected-tab (rf/sub [:wallet/home-tab])
account-list-ref (rn/use-ref-atom nil) account-list-ref (rn/use-ref-atom nil)
tokens-loading? (rf/sub [:wallet/home-tokens-loading?]) tokens-loading? (rf/sub [:wallet/home-tokens-loading?])
networks (rf/sub [:wallet/selected-network-details]) networks (rf/sub [:wallet/selected-network-details])
account-cards-data (rf/sub [:wallet/account-cards-data]) account-cards-data (rf/sub [:wallet/account-cards-data])
cards (conj account-cards-data (new-account-card-data)) cards (conj account-cards-data (new-account-card-data))
[init-loaded? set-init-loaded] (rn/use-state false) [init-loaded? set-init-loaded] (rn/use-state false)
{:keys [formatted-balance]} (rf/sub [:wallet/aggregated-token-values-and-balance]) {:keys [formatted-balance]} (rf/sub [:wallet/aggregated-token-values-and-balance])
theme (quo.theme/use-theme)] theme (quo.theme/use-theme)]
(rn/use-effect (fn [] (rn/use-effect (fn []
(when (and @account-list-ref (pos? (count cards))) (when (and @account-list-ref (pos? (count cards)))
(.scrollToOffset ^js @account-list-ref (.scrollToOffset ^js @account-list-ref
@ -104,7 +106,7 @@
(when (ff/enabled? ::ff/wallet.graph) (when (ff/enabled? ::ff/wallet.graph)
[quo/wallet-graph {:time-frame :empty}]) [quo/wallet-graph {:time-frame :empty}])
[render-cards cards account-list-ref] [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 :content-container-style style/list-container
:sticky-header-indices [0] :sticky-header-indices [0]
:data [] :data []

View File

@ -591,6 +591,12 @@
(fn [ui] (fn [ui]
(get-in ui [:account-page :active-tab]))) (get-in ui [:account-page :active-tab])))
(rf/reg-sub
:wallet/home-tab
:<- [:wallet/ui]
(fn [ui]
(:active-tab ui)))
(rf/reg-sub (rf/reg-sub
:wallet/aggregated-tokens :wallet/aggregated-tokens
:<- [:wallet/accounts-without-watched-accounts] :<- [:wallet/accounts-without-watched-accounts]