diff --git a/src/status_im/constants.cljs b/src/status_im/constants.cljs index 78de93d412..9130ce0cfa 100644 --- a/src/status_im/constants.cljs +++ b/src/status_im/constants.cljs @@ -492,3 +492,25 @@ (def ^:const status-hostname "status.app") (def ^:const community-joined-notification-type "communityJoined") + +(def ^:const wallet-activity-error-code-success 1) +(def ^:const wallet-activity-error-code-task-canceled 2) +(def ^:const wallet-activity-error-code-failed 3) + +(def ^:const wallet-activity-type-send 0) +(def ^:const wallet-activity-type-receive 1) +(def ^:const wallet-activity-type-buy 2) +(def ^:const wallet-activity-type-swap 3) +(def ^:const wallet-activity-type-bridge 4) +(def ^:const wallet-activity-type-contract-deployment 5) +(def ^:const wallet-activity-type-mint 6) + +(def ^:const wallet-activity-status-failed 0) +(def ^:const wallet-activity-status-pending 1) +(def ^:const wallet-activity-status-complete 2) +(def ^:const wallet-activity-status-finalized 3) + +(def ^:const wallet-activity-token-type-native 0) +(def ^:const wallet-activity-token-type-erc-20 1) +(def ^:const wallet-activity-token-type-erc-721 2) +(def ^:const wallet-activity-token-type-erc-1155 3) diff --git a/src/status_im/contexts/wallet/account/tabs/view.cljs b/src/status_im/contexts/wallet/account/tabs/view.cljs index fd06ce5cad..7728c25041 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] + :activity [activity/view {:activities []}] :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/common/activity_tab/view.cljs b/src/status_im/contexts/wallet/common/activity_tab/view.cljs index 75b8632ce1..4bc686d80a 100644 --- a/src/status_im/contexts/wallet/common/activity_tab/view.cljs +++ b/src/status_im/contexts/wallet/common/activity_tab/view.cljs @@ -16,16 +16,15 @@ item)]]) (defn- view-internal - [{:keys [theme]}] - (let [activity-list []] - (if (empty? activity-list) - [empty-tab/view - {:title (i18n/label :t/no-activity) - :description (i18n/label :t/empty-tab-description) - :image (resources/get-themed-image :no-activity theme)}] - [rn/flat-list - {:data activity-list - :style {:flex 1} - :render-fn activity-item}]))) + [{:keys [theme activity-list]}] + (if (empty? activity-list) + [empty-tab/view + {:title (i18n/label :t/no-activity) + :description (i18n/label :t/empty-tab-description) + :image (resources/get-themed-image :no-activity theme)}] + [rn/flat-list + {:data activity-list + :style {:flex 1} + :render-fn activity-item}])) (def view (quo.theme/with-theme view-internal)) diff --git a/src/status_im/contexts/wallet/events.cljs b/src/status_im/contexts/wallet/events.cljs index 54d05d546d..e3542c06ff 100644 --- a/src/status_im/contexts/wallet/events.cljs +++ b/src/status_im/contexts/wallet/events.cljs @@ -1,5 +1,6 @@ (ns status-im.contexts.wallet.events (:require + [camel-snake-kebab.extras :as cske] [clojure.string :as string] [react-native.background-timer :as background-timer] [react-native.platform :as platform] @@ -10,6 +11,7 @@ [status-im.contexts.wallet.item-types :as item-types] [taoensso.timbre :as log] [utils.collection] + [utils.ethereum.chain :as chain] [utils.ethereum.eip.eip55 :as eip55] [utils.i18n :as i18n] [utils.number] @@ -63,6 +65,7 @@ (utils.collection/index-by :address (data-store/rpc->accounts wallet-accounts))) :fx [[:dispatch [:wallet/get-wallet-token]] [:dispatch [:wallet/request-collectibles-for-all-accounts {:new-request? true}]] + [:dispatch [:wallet/check-recent-history]] (when new-account? [:dispatch [:wallet/navigate-to-new-account navigate-to-account]])]}))) @@ -392,6 +395,20 @@ {:error % :event :wallet/start-wallet})}]]]})) +(rf/reg-event-fx + :wallet/check-recent-history + (fn [{:keys [db]}] + (let [addresses (->> (get-in db [:wallet :accounts]) + vals + (map :address)) + chain-ids (chain/chain-ids db)] + {:fx [[:json-rpc/call + [{:method "wallet_checkRecentHistoryForChainIDs" + :params [chain-ids addresses] + :on-error #(log/info "failed to check recent history" + {:error % + :event :wallet/check-recent-history})}]]]}))) + (rf/reg-event-fx :wallet/initialize (fn [] {:fx [[:dispatch [:wallet/start-wallet]] @@ -477,3 +494,45 @@ {:db (update-in db [:wallet :ui :network-filter :selected-networks] update-fn network-name)}))) (rf/reg-event-fx :wallet/update-selected-networks update-selected-networks) + +(rf/reg-event-fx + :wallet/fetch-activities + (fn [{:keys [db]}] + (let [addresses (->> (get-in db [:wallet :accounts]) + vals + (map :address)) + chain-ids (chain/chain-ids db) + request-id 0 + filters {:period {:startTimestamp 0 + :endTimestamp 0} + :types [] + :statuses [] + :counterpartyAddresses [] + :assets [] + :collectibles [] + :filterOutAssets false + :filterOutCollectibles false} + offset 0 + limit 20 + request-params [request-id + addresses + chain-ids + filters + offset + limit]] + {:fx [[:json-rpc/call + [{;; This method is deprecated and will be replaced by + ;; "wallet_startActivityFilterSession" + :method "wallet_filterActivityAsync" + :params request-params + :on-error #(log/info "failed to fetch activities" + {:error % + :event :wallet/fetch-activities})}]]]}))) + +(rf/reg-event-fx + :wallet/activity-filtering-done + (fn [{:keys [db]} [{:keys [message]}]] + (let [{:keys [activities]} (transforms/json->clj message) + activities (cske/transform-keys transforms/->kebab-case-keyword activities) + sorted-activities (sort :timestamp activities)] + {:db (assoc-in db [:wallet :activities] sorted-activities)}))) diff --git a/src/status_im/contexts/wallet/home/tabs/view.cljs b/src/status_im/contexts/wallet/home/tabs/view.cljs index 570108f1d9..b02b92137c 100644 --- a/src/status_im/contexts/wallet/home/tabs/view.cljs +++ b/src/status_im/contexts/wallet/home/tabs/view.cljs @@ -34,4 +34,4 @@ :on-end-reached request-collectibles :on-collectible-press (fn [{:keys [id]}] (rf/dispatch [:wallet/get-collectible-details id]))}] - [activity/view])])) + [activity/view {:activities []}])])) diff --git a/src/status_im/contexts/wallet/home/view.cljs b/src/status_im/contexts/wallet/home/view.cljs index 307de25720..67357750d0 100644 --- a/src/status_im/contexts/wallet/home/view.cljs +++ b/src/status_im/contexts/wallet/home/view.cljs @@ -6,6 +6,7 @@ [status-im.contexts.wallet.home.style :as style] [status-im.contexts.wallet.home.tabs.view :as tabs] [status-im.contexts.wallet.sheets.network-filter.view :as network-filter] + [status-im.feature-flags :as ff] [utils.i18n :as i18n] [utils.re-frame :as rf])) @@ -76,5 +77,9 @@ :size 32 :default-active selected-tab :data tabs-data - :on-change #(set-selected-tab %)}] + :on-change (fn [tab] + (when (and (ff/enabled? ::ff/wallet.activities) + (= :activity tab)) + (rf/dispatch [:wallet/fetch-activities])) + (set-selected-tab tab))}] [tabs/view {:selected-tab selected-tab}]])) diff --git a/src/status_im/contexts/wallet/signals.cljs b/src/status_im/contexts/wallet/signals.cljs index 335478c97c..fa296d434c 100644 --- a/src/status_im/contexts/wallet/signals.cljs +++ b/src/status_im/contexts/wallet/signals.cljs @@ -37,6 +37,9 @@ "wallet-blockchain-status-changed" {:fx [[:dispatch [:wallet/blockchain-status-changed (transforms/js->clj event-js)]]]} + "wallet-activity-filtering-done" {:fx [[:dispatch + [:wallet/activity-filtering-done + (transforms/js->clj event-js)]]]} (log/debug ::unknown-wallet-event :type event-type :event (transforms/js->clj event-js)))))) diff --git a/src/status_im/feature_flags.cljs b/src/status_im/feature_flags.cljs index 1f331d6e6b..7d9a87bf81 100644 --- a/src/status_im/feature_flags.cljs +++ b/src/status_im/feature_flags.cljs @@ -17,7 +17,8 @@ ::wallet.assets-modal-manage-tokens (enabled-in-env? :FLAG_ASSETS_MODAL_MANAGE_TOKENS) ::wallet.assets-modal-hide (enabled-in-env? :FLAG_ASSETS_MODAL_HIDE) ::community.edit-account-selection (enabled-in-env? :FLAG_EDIT_ACCOUNT_SELECTION_ENABLED) - ::wallet.contacts (enabled-in-env? :FLAG_CONTACTS_ENABLED)})) + ::wallet.contacts (enabled-in-env? :FLAG_CONTACTS_ENABLED) + ::wallet.activities (enabled-in-env? :FLAG_WALLET_ACTIVITY_ENABLED)})) (defn feature-flags [] @feature-flags-config) diff --git a/src/status_im/subs/wallet/activities.cljs b/src/status_im/subs/wallet/activities.cljs new file mode 100644 index 0000000000..38f10ff45b --- /dev/null +++ b/src/status_im/subs/wallet/activities.cljs @@ -0,0 +1,17 @@ +(ns status-im.subs.wallet.activities + (:require [re-frame.core :as rf])) + +(rf/reg-sub + :wallet/all-activities + :<- [:wallet] + :-> :activities) + +(rf/reg-sub + :wallet/activities-for-current-viewing-account + :<- [:wallet/all-activities] + :<- [:wallet/current-viewing-account-address] + (fn [[activities current-viewing-account-address]] + (filter (fn [{:keys [sender recipient]}] + (or (= sender current-viewing-account-address) + (= recipient current-viewing-account-address))) + activities)))