From 869153e862ffe583ec30a713751824500508c6ec Mon Sep 17 00:00:00 2001 From: Jamie Caprani Date: Fri, 22 Dec 2023 11:52:21 +0000 Subject: [PATCH] chore: remove old wallet signals and move signals to status-im ns --- .../status_im/ethereum/subscriptions.cljs | 88 ------------------- src/legacy/status_im/events.cljs | 1 - src/status_im/common/signals/events.cljs | 9 +- src/status_im/contexts/wallet/signals.cljs | 20 +++++ src/status_im/events.cljs | 1 + 5 files changed, 25 insertions(+), 94 deletions(-) delete mode 100644 src/legacy/status_im/ethereum/subscriptions.cljs create mode 100644 src/status_im/contexts/wallet/signals.cljs diff --git a/src/legacy/status_im/ethereum/subscriptions.cljs b/src/legacy/status_im/ethereum/subscriptions.cljs deleted file mode 100644 index 1b891afe097..00000000000 --- a/src/legacy/status_im/ethereum/subscriptions.cljs +++ /dev/null @@ -1,88 +0,0 @@ -(ns legacy.status-im.ethereum.subscriptions - (:require - [legacy.status-im.ethereum.transactions.core :as transactions] - [legacy.status-im.wallet.core :as wallet.core] - [legacy.status-im.wallet.db :as wallet] - [taoensso.timbre :as log] - [utils.ethereum.eip.eip55 :as eip55] - [utils.re-frame :as rf])) - -(rf/defn new-transfers - [cofx block-number accounts] - (log/debug "[wallet-subs] new-transfers" - "accounts" accounts - "block" block-number) - (transactions/check-watched-transactions cofx)) - -(rf/defn recent-history-fetching-started - [{:keys [db]} accounts] - (log/debug "[wallet-subs] recent-history-fetching-started" - "accounts" - accounts) - (let [event (get db :wallet-legacy/on-recent-history-fetching)] - (cond-> {:db (-> db - (transactions/update-fetching-status accounts :recent? true) - (assoc :wallet-legacy/recent-history-fetching-started? true) - (dissoc :wallet-legacy/on-recent-history-fetching))} - event - (assoc :dispatch event)))) - -(rf/defn recent-history-fetching-ended - [{:keys [db]} {:keys [accounts blockNumber]}] - (log/debug "[wallet-subs] recent-history-fetching-ended" - "accounts" accounts - "block" blockNumber) - {:db (-> db - (assoc :ethereum/current-block blockNumber) - (update-in [:wallet-legacy :accounts] - wallet/remove-transactions-since-block - blockNumber) - (transactions/update-fetching-status accounts :recent? false) - (dissoc :wallet-legacy/waiting-for-recent-history? - :wallet-legacy/refreshing-history? - :wallet-legacy/fetching-error - :wallet-legacy/recent-history-fetching-started?)) - :transactions/get-transfers - {:chain-tokens (:wallet-legacy/all-tokens db) - :addresses (reduce - (fn [v address] - (let [normalized-address - (eip55/address->checksum address)] - (if (contains? v normalized-address) - v - (conj v address)))) - [] - accounts) - :before-block blockNumber - :limit 20}}) - -(rf/defn fetching-error - [{:keys [db] :as cofx} {:keys [message]}] - (rf/merge - cofx - {:db (assoc db :wallet-legacy/fetching-error message)} - (wallet.core/after-checking-history))) - -(rf/defn non-archival-node-detected - [{:keys [db]} _] - {:db (assoc db :wallet-legacy/non-archival-node true)}) - -(rf/defn new-wallet-event - [cofx {:keys [type blockNumber accounts] :as event}] - (log/debug "[wallet-subs] new-wallet-event" - "event-type" type - "blockNumber" blockNumber - "accounts" accounts) - (case type - "new-transfers" (new-transfers cofx blockNumber accounts) - "recent-history-fetching" (recent-history-fetching-started cofx accounts) - "recent-history-ready" (recent-history-fetching-ended cofx event) - "fetching-history-error" (fetching-error cofx event) - "non-archival-node-detected" (non-archival-node-detected cofx event) - "wallet-owned-collectibles-filtering-done" {:fx [[:dispatch - [:wallet/owned-collectibles-filtering-done - event]]]} - "wallet-get-collectibles-details-done" {:fx [[:dispatch - [:wallet/get-collectible-details-done - event]]]} - (log/debug ::unknown-wallet-event :type type :event event))) diff --git a/src/legacy/status_im/events.cljs b/src/legacy/status_im/events.cljs index 87e8e33d472..38a7a0989ba 100644 --- a/src/legacy/status_im/events.cljs +++ b/src/legacy/status_im/events.cljs @@ -8,7 +8,6 @@ legacy.status-im.chat.models.loading legacy.status-im.contact.block legacy.status-im.currency.core - legacy.status-im.ethereum.subscriptions legacy.status-im.fleet.core [legacy.status-im.keycard.core :as keycard] legacy.status-im.log-level.core diff --git a/src/status_im/common/signals/events.cljs b/src/status_im/common/signals/events.cljs index dc5b57c5170..9df594bd076 100644 --- a/src/status_im/common/signals/events.cljs +++ b/src/status_im/common/signals/events.cljs @@ -1,7 +1,6 @@ (ns status-im.common.signals.events (:require [legacy.status-im.chat.models.message :as models.message] - [legacy.status-im.ethereum.subscriptions :as ethereum.subscriptions] [legacy.status-im.mailserver.core :as mailserver] [legacy.status-im.visibility-status-updates.core :as visibility-status-updates] [status-im.common.pairing.events :as pairing] @@ -70,10 +69,10 @@ "messages.new" (messages.transport/sanitize-messages-and-process-response cofx event-js true) - "wallet" (ethereum.subscriptions/new-wallet-event cofx - (js->clj event-js - :keywordize-keys - true)) + "wallet" (rf/dispatch [:wallet/signal-fired + (js->clj event-js + :keywordize-keys + true)]) "local-notifications" (local-notifications/process cofx (js->clj event-js :keywordize-keys true)) "community.found" (link-preview/cache-community-preview-data (js->clj event-js diff --git a/src/status_im/contexts/wallet/signals.cljs b/src/status_im/contexts/wallet/signals.cljs new file mode 100644 index 00000000000..81edc7bf1c6 --- /dev/null +++ b/src/status_im/contexts/wallet/signals.cljs @@ -0,0 +1,20 @@ +(ns status-im.contexts.wallet.signals + (:require + [taoensso.timbre :as log] + [utils.re-frame :as rf])) + +(rf/reg-event-fx + :wallet/signal-fired + (fn [_ {:keys [type blockNumber accounts] :as event}] + (log/debug "[wallet-subs] new-wallet-event" + "event-type" type + "blockNumber" blockNumber + "accounts" accounts) + (case type + "wallet-owned-collectibles-filtering-done" {:fx [[:dispatch + [:wallet/owned-collectibles-filtering-done + event]]]} + "wallet-get-collectibles-details-done" {:fx [[:dispatch + [:wallet/get-collectible-details-done + event]]]} + (log/debug ::unknown-wallet-event :type type :event event)))) diff --git a/src/status_im/events.cljs b/src/status_im/events.cljs index a55f29dacd6..6968d8d4fab 100644 --- a/src/status_im/events.cljs +++ b/src/status_im/events.cljs @@ -25,6 +25,7 @@ status-im.contexts.syncing.events status-im.contexts.wallet.events status-im.contexts.wallet.send.events + status-im.contexts.wallet.signals [status-im.db :as db] [utils.re-frame :as rf]))