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
key)
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]))
;; check if collectibles are updating (never fetched and cached before) for this address
updating-chains (-> (select-keys
@ -301,16 +304,20 @@
old-value
new-value))
(def merge-skipping-empty-values (partial merge-with keep-not-empty-value))
(rf/reg-event-fx
:wallet/get-collectible-details-done
(fn [{db :db} [{:keys [message]}]]
(let [response (cske/transform-keys transforms/->kebab-case-keyword
(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
{: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"
{:event :wallet/get-collectible-details-done
:response response})))))

View File

@ -63,7 +63,9 @@
(defn view
[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)]
[:<>
[info

View File

@ -157,12 +157,10 @@
set-title-ref (rn/use-callback #(reset! title-ref %))
animation-shared-element-id (rf/sub [:animation-shared-element-id])
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])
gradient-color (rf/sub [:wallet/collectible-gradient-color])
total-owned (rf/sub [:wallet/total-owned-collectible
(:ownership collectible)
(:address collectible-owner)])
total-owned (:total-owned collectible)
{:keys [id
preview-url
collection-data

View File

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

View File

@ -31,6 +31,7 @@
search-performed? (not (string/blank? search-text))]
[collectibles-tab/view
{:collectibles collectibles
:current-account-address (rf/sub [:wallet/current-viewing-account-address])
:filtered? search-performed?
:on-end-reached #(rf/dispatch [:wallet/request-collectibles-for-current-viewing-account])
:on-collectible-press (fn [{:keys [collectible]}]

View File

@ -15,7 +15,9 @@
#(rf/dispatch [:wallet/collectible-amount-navigate-back]))
send-transaction-data (rf/sub [:wallet/wallet-send])
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
(controlled-input/set-value-numeric 1)
(controlled-input/set-lower-limit 1)))

View File

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