Fixed amounts for multiple collectibles (#21237)

This commit is contained in:
Volodymyr Kozieiev 2024-09-19 12:35:14 +01:00 committed by GitHub
parent 92456612b1
commit 1190fc8069
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 28 deletions

View File

@ -244,7 +244,10 @@
first first
key) key)
ownership-status (get ownership-status-by-address owner-address) ownership-status (get ownership-status-by-address owner-address)
collectibles (data-store/rpc->collectibles collectibles) collectibles (->> collectibles
data-store/rpc->collectibles
(map #(update % :ownership distinct))
vec)
pending-requests (dec (get-in db [:wallet :ui :collectibles :pending-requests])) pending-requests (dec (get-in db [:wallet :ui :collectibles :pending-requests]))
;; check if collectibles are updating (never fetched and cached before) for this address ;; check if collectibles are updating (never fetched and cached before) for this address
updating-chains (-> (select-keys updating-chains (-> (select-keys
@ -301,16 +304,20 @@
old-value old-value
new-value)) new-value))
(def merge-skipping-empty-values (partial merge-with keep-not-empty-value))
(rf/reg-event-fx (rf/reg-event-fx
:wallet/get-collectible-details-done :wallet/get-collectible-details-done
(fn [{db :db} [{:keys [message]}]] (fn [{db :db} [{:keys [message]}]]
(let [response (cske/transform-keys transforms/->kebab-case-keyword (let [response (cske/transform-keys transforms/->kebab-case-keyword
(transforms/json->clj message)) (transforms/json->clj message))
{[collectible] :collectibles} response] {[collectible] :collectibles} response
known-collectible-info (get-in db [:wallet :ui :collectible :details])
merged-collectible (as-> known-collectible-info c
(merge-with keep-not-empty-value
c
collectible)
(update c :ownership distinct))]
(if collectible (if collectible
{:db (update-in db [:wallet :ui :collectible :details] merge-skipping-empty-values collectible)} {:db (assoc-in db [:wallet :ui :collectible :details] merged-collectible)}
(log/error "failed to get collectible details" (log/error "failed to get collectible details"
{:event :wallet/get-collectible-details-done {:event :wallet/get-collectible-details-done
:response response}))))) :response response})))))

View File

@ -63,7 +63,9 @@
(defn view (defn view
[collectible] [collectible]
(let [owner-account (rf/sub [:wallet/collectible-details-owner collectible]) (let [owner-address (or (rf/sub [:wallet/current-viewing-account-address])
(-> collectible :ownership first :address))
owner-account (rf/sub [:wallet-connect/account-details-by-address owner-address])
traits (-> collectible :collectible-data :traits)] traits (-> collectible :collectible-data :traits)]
[:<> [:<>
[info [info

View File

@ -157,12 +157,10 @@
set-title-ref (rn/use-callback #(reset! title-ref %)) set-title-ref (rn/use-callback #(reset! title-ref %))
animation-shared-element-id (rf/sub [:animation-shared-element-id]) animation-shared-element-id (rf/sub [:animation-shared-element-id])
collectible (rf/sub [:wallet/collectible-details]) collectible (rf/sub [:wallet/collectible-details])
collectible-owner (rf/sub [:wallet/collectible-details-owner collectible]) collectible-owner (rf/sub [:wallet/current-viewing-account])
aspect-ratio (rf/sub [:wallet/collectible-aspect-ratio]) aspect-ratio (rf/sub [:wallet/collectible-aspect-ratio])
gradient-color (rf/sub [:wallet/collectible-gradient-color]) gradient-color (rf/sub [:wallet/collectible-gradient-color])
total-owned (rf/sub [:wallet/total-owned-collectible total-owned (:total-owned collectible)
(:ownership collectible)
(:address collectible-owner)])
{:keys [id {:keys [id
preview-url preview-url
collection-data collection-data

View File

@ -284,7 +284,7 @@
collectible collectible
(str (:name collection-data) " #" collectible-id)) (str (:name collection-data) " #" collectible-id))
owner-address (-> collectible :ownership first :address) owner-address (-> db :wallet :current-viewing-account-address)
collectible-tx (-> db collectible-tx (-> db
(update-in [:wallet :ui :send] dissoc :token) (update-in [:wallet :ui :send] dissoc :token)
(assoc-in [:wallet :ui :send :collectible] collectible) (assoc-in [:wallet :ui :send :collectible] collectible)

View File

@ -30,14 +30,15 @@
(let [collectibles (rf/sub [:wallet/current-viewing-account-collectibles-filtered search-text]) (let [collectibles (rf/sub [:wallet/current-viewing-account-collectibles-filtered search-text])
search-performed? (not (string/blank? search-text))] search-performed? (not (string/blank? search-text))]
[collectibles-tab/view [collectibles-tab/view
{:collectibles collectibles {:collectibles collectibles
:filtered? search-performed? :current-account-address (rf/sub [:wallet/current-viewing-account-address])
:on-end-reached #(rf/dispatch [:wallet/request-collectibles-for-current-viewing-account]) :filtered? search-performed?
:on-collectible-press (fn [{:keys [collectible]}] :on-end-reached #(rf/dispatch [:wallet/request-collectibles-for-current-viewing-account])
(rf/dispatch [:wallet/set-collectible-to-send :on-collectible-press (fn [{:keys [collectible]}]
{:collectible collectible (rf/dispatch [:wallet/set-collectible-to-send
:current-screen :screen/wallet.select-asset {:collectible collectible
:entry-point :account-send-button}]))}])) :current-screen :screen/wallet.select-asset
:entry-point :account-send-button}]))}]))
(defn- tab-view (defn- tab-view
[search-text selected-tab on-change-text] [search-text selected-tab on-change-text]

View File

@ -15,7 +15,9 @@
#(rf/dispatch [:wallet/collectible-amount-navigate-back])) #(rf/dispatch [:wallet/collectible-amount-navigate-back]))
send-transaction-data (rf/sub [:wallet/wallet-send]) send-transaction-data (rf/sub [:wallet/wallet-send])
collectible (:collectible send-transaction-data) collectible (:collectible send-transaction-data)
balance (utils/collectible-balance collectible) sender-address (rf/sub [:wallet/current-viewing-account-address])
balance (rf/sub [:wallet/total-owned-collectible (:ownership collectible)
sender-address])
[input-state set-input-state] (rn/use-state (-> controlled-input/init-state [input-state set-input-state] (rn/use-state (-> controlled-input/init-state
(controlled-input/set-value-numeric 1) (controlled-input/set-value-numeric 1)
(controlled-input/set-lower-limit 1))) (controlled-input/set-lower-limit 1)))

View File

@ -1,7 +1,8 @@
(ns status-im.subs.wallet.collectibles (ns status-im.subs.wallet.collectibles
(:require (:require
[clojure.string :as string] [clojure.string :as string]
[re-frame.core :as re-frame])) [re-frame.core :as re-frame]
[utils.collection]))
(defn- filter-collectibles-in-chains (defn- filter-collectibles-in-chains
[collectibles chain-ids] [collectibles chain-ids]
@ -69,6 +70,7 @@
(->> all-collectibles (->> all-collectibles
(apply interleave) (apply interleave)
(remove nil?) (remove nil?)
(utils.collection/distinct-by :id)
(add-collectibles-preview-url))))) (add-collectibles-preview-url)))))
(re-frame/reg-sub (re-frame/reg-sub
@ -118,8 +120,8 @@
:wallet/collectible-details-owner :wallet/collectible-details-owner
:<- [:wallet/accounts] :<- [:wallet/accounts]
(fn [accounts [_ collectible]] (fn [accounts [_ collectible]]
(let [collectible-address (-> collectible :ownership first :address)] (let [owner-address (-> collectible :ownership first :address)]
(some #(when (= (:address %) collectible-address) (some #(when (= (:address %) owner-address)
%) %)
accounts)))) accounts))))
@ -127,12 +129,11 @@
:wallet/total-owned-collectible :wallet/total-owned-collectible
:<- [:wallet/accounts-without-watched-accounts] :<- [:wallet/accounts-without-watched-accounts]
(fn [accounts [_ ownership address]] (fn [accounts [_ ownership address]]
(let [addresses (map :address accounts)] (let [addresses (if address
#{address}
(set (map :address accounts)))]
(reduce (fn [acc item] (reduce (fn [acc item]
(if (or (if (contains? addresses (:address item))
(and (not address)
(contains? (set addresses) (:address item)))
(= (:address item) address))
(+ acc (js/parseInt (:balance item))) (+ acc (js/parseInt (:balance item)))
acc)) acc))
0 0