Watch-only collectibles should not be included on the main wallet page by default #20735 (#20761)

This commit is contained in:
mmilad75 2024-07-23 14:45:02 +02:00 committed by GitHub
parent 3bb7c308e3
commit 89bb3ea5c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 38 additions and 33 deletions

View File

@ -28,17 +28,6 @@
(log/debug "unsupported collectible file type:" (or collectible-type "Unknown type"))
false)))
(defn total-owned-collectible
([ownership]
(total-owned-collectible ownership false))
([ownership address]
(reduce (fn [acc item]
(if (or (not address) (= (:address item) address))
(+ acc (js/parseInt (:balance item)))
acc))
0
ownership)))
(defn collectible-owned-counter
[total]
(when (> total 1) (str "x" total)))

View File

@ -160,6 +160,9 @@
collectible-owner (rf/sub [:wallet/collectible-details-owner collectible])
aspect-ratio (rf/sub [:wallet/collectible-aspect-ratio])
gradient-color (rf/sub [:wallet/collectible-gradient-color])
total-owned (rf/sub [:wallet/total-owned-collectible
(:ownership collectible)
(:address collectible-owner)])
{:keys [id
preview-url
collection-data
@ -182,10 +185,7 @@
:image-height 300
:id token-id
:header collectible-name
:description collection-name}
total-owned (utils/total-owned-collectible
(:ownership collectible)
(:address collectible-owner))]
:description collection-name}]
[rn/view {:style style/container}
[rn/view
[gradient-layer preview-uri]

View File

@ -7,7 +7,8 @@
[status-im.contexts.wallet.collectible.utils :as utils]
[status-im.contexts.wallet.common.collectibles-tab.style :as style]
[status-im.contexts.wallet.common.empty-tab.view :as empty-tab]
[utils.i18n :as i18n]))
[utils.i18n :as i18n]
[utils.re-frame :as rf]))
(defn- collectible-item
[{:keys [preview-url collection-data collectible-data total-owned on-press on-long-press]
@ -61,15 +62,16 @@
;; TODO: https://github.com/status-im/status-mobile/issues/20137
;; 1. If possible, move `collectibles-data` calculation to a subscription
;; 2. Optimization: do not recalculate all the collectibles, process only the new ones
(let [collectibles-data (map-indexed (fn [index {:keys [ownership] :as collectible}]
(assoc collectible
:total-owned (utils/total-owned-collectible
ownership
current-account-address)
:on-long-press on-collectible-long-press
:on-press on-collectible-press
:collectible-index index))
collectibles)]
(let [collectibles-data (map-indexed
(fn [index {:keys [ownership] :as collectible}]
(let [total-owned (rf/sub [:wallet/total-owned-collectible ownership
current-account-address])]
(assoc collectible
:total-owned total-owned
:on-long-press on-collectible-long-press
:on-press on-collectible-press
:collectible-index index)))
collectibles)]
[rn/flat-list
{:data collectibles-data
:style {:flex 1}

View File

@ -21,7 +21,7 @@
(defn view
[{:keys [selected-tab]}]
(let [collectible-list (rf/sub [:wallet/all-collectibles-list-in-selected-networks])
(let [collectible-list (rf/sub [:wallet/owned-collectibles-list-in-selected-networks])
request-collectibles #(rf/dispatch
[:wallet/request-collectibles-for-all-accounts {}])]
[rn/view {:style style/container}

View File

@ -55,13 +55,13 @@
(filter-collectibles-in-chains collectibles chain-ids)))
(re-frame/reg-sub
:wallet/all-collectibles-list
:<- [:wallet]
(fn [{:keys [accounts]}]
:wallet/owned-collectibles-list
:<- [:wallet/accounts-without-watched-accounts]
(fn [accounts]
(let [max-collectibles (->> accounts
(map (comp count :collectibles val))
(map (comp count :collectibles))
(apply max))
all-collectibles (map (fn [[_address {:keys [collectibles]}]]
all-collectibles (map (fn [{:keys [collectibles]}]
(let [amount-to-add (- max-collectibles (count collectibles))
empty-collectibles (repeat amount-to-add nil)]
(reduce conj collectibles empty-collectibles)))
@ -72,8 +72,8 @@
(add-collectibles-preview-url)))))
(re-frame/reg-sub
:wallet/all-collectibles-list-in-selected-networks
:<- [:wallet/all-collectibles-list]
:wallet/owned-collectibles-list-in-selected-networks
:<- [:wallet/owned-collectibles-list]
:<- [:wallet/selected-networks->chain-ids]
(fn [[all-collectibles chain-ids]]
(filter-collectibles-in-chains all-collectibles chain-ids)))
@ -123,3 +123,17 @@
%)
accounts))))
(re-frame/reg-sub
:wallet/total-owned-collectible
:<- [:wallet/accounts-without-watched-accounts]
(fn [accounts [_ ownership address]]
(let [addresses (map :address accounts)]
(reduce (fn [acc item]
(if (or
(and (not address)
(contains? (set addresses) (:address item)))
(= (:address item) address))
(+ acc (js/parseInt (:balance item)))
acc))
0
ownership))))