diff --git a/src/status_im/contexts/wallet/collectible/events.cljs b/src/status_im/contexts/wallet/collectible/events.cljs index 7daf473c4c..7acd1d4b1f 100644 --- a/src/status_im/contexts/wallet/collectible/events.cljs +++ b/src/status_im/contexts/wallet/collectible/events.cljs @@ -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}))))) diff --git a/src/status_im/contexts/wallet/collectible/tabs/overview/view.cljs b/src/status_im/contexts/wallet/collectible/tabs/overview/view.cljs index 7c2f9d5711..1fb599ce61 100644 --- a/src/status_im/contexts/wallet/collectible/tabs/overview/view.cljs +++ b/src/status_im/contexts/wallet/collectible/tabs/overview/view.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/collectible/view.cljs b/src/status_im/contexts/wallet/collectible/view.cljs index 2f814fd6a1..30e8e97712 100644 --- a/src/status_im/contexts/wallet/collectible/view.cljs +++ b/src/status_im/contexts/wallet/collectible/view.cljs @@ -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 diff --git a/src/status_im/contexts/wallet/send/events.cljs b/src/status_im/contexts/wallet/send/events.cljs index 6ecfd42fe9..76ef4d028c 100644 --- a/src/status_im/contexts/wallet/send/events.cljs +++ b/src/status_im/contexts/wallet/send/events.cljs @@ -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) diff --git a/src/status_im/contexts/wallet/send/select_asset/view.cljs b/src/status_im/contexts/wallet/send/select_asset/view.cljs index 0d3a7923af..180739bd2d 100644 --- a/src/status_im/contexts/wallet/send/select_asset/view.cljs +++ b/src/status_im/contexts/wallet/send/select_asset/view.cljs @@ -30,14 +30,15 @@ (let [collectibles (rf/sub [:wallet/current-viewing-account-collectibles-filtered search-text]) search-performed? (not (string/blank? search-text))] [collectibles-tab/view - {:collectibles collectibles - :filtered? search-performed? - :on-end-reached #(rf/dispatch [:wallet/request-collectibles-for-current-viewing-account]) - :on-collectible-press (fn [{:keys [collectible]}] - (rf/dispatch [:wallet/set-collectible-to-send - {:collectible collectible - :current-screen :screen/wallet.select-asset - :entry-point :account-send-button}]))}])) + {: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]}] + (rf/dispatch [:wallet/set-collectible-to-send + {:collectible collectible + :current-screen :screen/wallet.select-asset + :entry-point :account-send-button}]))}])) (defn- tab-view [search-text selected-tab on-change-text] diff --git a/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs b/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs index b2e40242cc..2027be6796 100644 --- a/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs +++ b/src/status_im/contexts/wallet/send/select_collectible_amount/view.cljs @@ -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))) diff --git a/src/status_im/subs/wallet/collectibles.cljs b/src/status_im/subs/wallet/collectibles.cljs index 46b26ba70c..dcc6670115 100644 --- a/src/status_im/subs/wallet/collectibles.cljs +++ b/src/status_im/subs/wallet/collectibles.cljs @@ -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