chore: remove old wallet signals and move signals to status-im ns (#18285)

This commit is contained in:
Jamie Caprani 2024-02-05 11:40:58 +00:00 committed by GitHub
parent b6ce60eccf
commit 0964424a36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 100 deletions

View File

@ -1,93 +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)
"pending-transaction-status-changed" {:fx
[[:dispatch
[:wallet/pending-transaction-status-changed-received
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]]]}
"wallet-tick-reload" {:fx [[:dispatch [:wallet/reload]]]}
(log/debug ::unknown-wallet-event :type type :event event)))

View File

@ -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

View File

@ -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,7 @@
"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-received event-js])
"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

View File

@ -1,5 +1,8 @@
(ns status-im.contexts.wallet.signals
(:require [utils.re-frame :as rf]))
(:require
[oops.core :as oops]
[taoensso.timbre :as log]
[utils.re-frame :as rf]))
(rf/reg-event-fx
:wallet/pending-transaction-status-changed-received
@ -8,3 +11,36 @@
tx-hash (:hash details)]
{:db (update-in db [:wallet :transactions tx-hash] assoc :status :confirmed :blocks 1)})))
(rf/reg-event-fx
:wallet/signal-received
(fn [_ [event-js]]
(let [event-type (oops/oget event-js "type")
blockNumber (oops/oget event-js "blockNumber")
accounts (oops/oget event-js "accounts")]
(log/debug "[wallet-subs] New wallet event"
{:type event-type
:block-number blockNumber
:accounts accounts})
(case event-type
"pending-transaction-status-changed" {:fx
[[:dispatch
[:wallet/pending-transaction-status-changed-received
(js->clj event-js
:keywordize-keys
true)]]]}
"wallet-owned-collectibles-filtering-done" {:fx [[:dispatch
[:wallet/owned-collectibles-filtering-done
(js->clj event-js
:keywordize-keys
true)]]]}
"wallet-get-collectibles-details-done" {:fx [[:dispatch
[:wallet/get-collectible-details-done
(js->clj event-js
:keywordize-keys
true)]]]}
"wallet-tick-reload" {:fx [[:dispatch [:wallet/reload]]]}
(log/debug ::unknown-wallet-event
:type type
:event (js->clj event-js
:keywordize-keys
true))))))