mirror of
https://github.com/status-im/status-react.git
synced 2025-02-19 22:28:40 +00:00
#[16978] Select collectible to send (#18404)
* Show collectibles to send and add filter capabilities Additionally, * Replace the sub `:wallet/collectibles-per-account` by `:wallet/current-viewing-account-collectibles` since it was only used for the current viewing account and simplified the code. * Refactor the select-asset view. * Generalize collectibles-tab view * Add translations for "not found" state
This commit is contained in:
parent
4165565956
commit
e3ab270933
@ -7,18 +7,24 @@
|
|||||||
[status-im.contexts.wallet.common.activity-tab.view :as activity]
|
[status-im.contexts.wallet.common.activity-tab.view :as activity]
|
||||||
[status-im.contexts.wallet.common.collectibles-tab.view :as collectibles]
|
[status-im.contexts.wallet.common.collectibles-tab.view :as collectibles]
|
||||||
[status-im.contexts.wallet.common.empty-tab.view :as empty-tab]
|
[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 view
|
(defn view
|
||||||
[{:keys [selected-tab]}]
|
[{:keys [selected-tab]}]
|
||||||
|
(let [collectible-list (rf/sub [:wallet/current-viewing-account-collectibles])]
|
||||||
[rn/view {:style {:flex 1}}
|
[rn/view {:style {:flex 1}}
|
||||||
(case selected-tab
|
(case selected-tab
|
||||||
:assets [assets/view]
|
:assets [assets/view]
|
||||||
:collectibles [collectibles/view]
|
:collectibles [collectibles/view
|
||||||
|
{:collectibles collectible-list
|
||||||
|
:on-collectible-press (fn [id]
|
||||||
|
(rf/dispatch [:wallet/get-collectible-details id])
|
||||||
|
(rf/dispatch [:navigate-to :wallet-collectible]))}]
|
||||||
:activity [activity/view]
|
:activity [activity/view]
|
||||||
:permissions [empty-tab/view
|
:permissions [empty-tab/view
|
||||||
{:title (i18n/label :t/no-permissions)
|
{:title (i18n/label :t/no-permissions)
|
||||||
:description (i18n/label :t/no-collectibles-description)
|
:description (i18n/label :t/no-collectibles-description)
|
||||||
:placeholder? true}]
|
:placeholder? true}]
|
||||||
:dapps [dapps/view]
|
:dapps [dapps/view]
|
||||||
[about/view])])
|
[about/view])]))
|
||||||
|
@ -5,32 +5,34 @@
|
|||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[status-im.common.resources :as resources]
|
[status-im.common.resources :as resources]
|
||||||
[status-im.contexts.wallet.common.empty-tab.view :as empty-tab]
|
[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- view-internal
|
(defn- view-internal
|
||||||
[{:keys [theme]}]
|
[{:keys [theme collectibles filtered? on-collectible-press]}]
|
||||||
(let [specific-address (rf/sub [:wallet/current-viewing-account-address])
|
(let [no-results-match-query? (and filtered? (empty? collectibles))]
|
||||||
collectible-list (if specific-address
|
(cond
|
||||||
(rf/sub [:wallet/collectibles-per-account specific-address])
|
no-results-match-query?
|
||||||
(rf/sub [:wallet/all-collectibles]))]
|
[rn/view {:style {:flex 1 :justify-content :center}}
|
||||||
(if (empty? collectible-list)
|
[quo/empty-state
|
||||||
|
{:title (i18n/label :t/nothing-found)
|
||||||
|
:description (i18n/label :t/try-to-search-something-else)
|
||||||
|
:image (resources/get-themed-image :no-collectibles theme)}]]
|
||||||
|
|
||||||
|
(empty? collectibles)
|
||||||
[empty-tab/view
|
[empty-tab/view
|
||||||
{:title (i18n/label :t/no-collectibles)
|
{:title (i18n/label :t/no-collectibles)
|
||||||
:description (i18n/label :t/no-collectibles-description)
|
:description (i18n/label :t/no-collectibles-description)
|
||||||
:image (resources/get-themed-image :no-collectibles theme)}]
|
:image (resources/get-themed-image :no-collectibles theme)}]
|
||||||
|
|
||||||
|
:else
|
||||||
[rn/flat-list
|
[rn/flat-list
|
||||||
{:data collectible-list
|
{:data collectibles
|
||||||
:style {:flex 1}
|
:style {:flex 1}
|
||||||
:content-container-style {:align-items :center}
|
:content-container-style {:align-items :center}
|
||||||
:num-columns 2
|
:num-columns 2
|
||||||
:render-fn (fn [{:keys [preview-url id]}]
|
:render-fn (fn [{:keys [preview-url id]}]
|
||||||
[quo/collectible
|
[quo/collectible
|
||||||
{:images [preview-url]
|
{:images [preview-url]
|
||||||
:on-press (fn []
|
:on-press #(on-collectible-press id)}])}])))
|
||||||
(rf/dispatch [:wallet/get-collectible-details id])
|
|
||||||
(rf/dispatch
|
|
||||||
[:navigate-to
|
|
||||||
:wallet-collectible]))}])}])))
|
|
||||||
|
|
||||||
(def view (quo.theme/with-theme view-internal))
|
(def view (quo.theme/with-theme view-internal))
|
||||||
|
@ -4,12 +4,18 @@
|
|||||||
[status-im.contexts.wallet.common.activity-tab.view :as activity]
|
[status-im.contexts.wallet.common.activity-tab.view :as activity]
|
||||||
[status-im.contexts.wallet.common.collectibles-tab.view :as collectibles]
|
[status-im.contexts.wallet.common.collectibles-tab.view :as collectibles]
|
||||||
[status-im.contexts.wallet.home.tabs.assets.view :as assets]
|
[status-im.contexts.wallet.home.tabs.assets.view :as assets]
|
||||||
[status-im.contexts.wallet.home.tabs.style :as style]))
|
[status-im.contexts.wallet.home.tabs.style :as style]
|
||||||
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[{:keys [selected-tab]}]
|
[{:keys [selected-tab]}]
|
||||||
|
(let [collectible-list (rf/sub [:wallet/all-collectibles])]
|
||||||
[rn/view {:style style/container}
|
[rn/view {:style style/container}
|
||||||
(case selected-tab
|
(case selected-tab
|
||||||
:assets [assets/view]
|
:assets [assets/view]
|
||||||
:collectibles [collectibles/view]
|
:collectibles [collectibles/view
|
||||||
[activity/view])])
|
{:collectibles collectible-list
|
||||||
|
:on-collectible-press (fn [id]
|
||||||
|
(rf/dispatch [:wallet/get-collectible-details id])
|
||||||
|
(rf/dispatch [:navigate-to :wallet-collectible]))}]
|
||||||
|
[activity/view])]))
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
(ns status-im.contexts.wallet.send.select-asset.view
|
(ns status-im.contexts.wallet.send.select-asset.view
|
||||||
(:require
|
(:require
|
||||||
|
[clojure.string :as string]
|
||||||
[quo.core :as quo]
|
[quo.core :as quo]
|
||||||
[quo.theme :as quo.theme]
|
[quo.theme :as quo.theme]
|
||||||
[react-native.core :as rn]
|
[react-native.core :as rn]
|
||||||
[react-native.safe-area :as safe-area]
|
|
||||||
[reagent.core :as reagent]
|
[reagent.core :as reagent]
|
||||||
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
|
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
|
||||||
|
[status-im.contexts.wallet.common.collectibles-tab.view :as collectibles-tab]
|
||||||
[status-im.contexts.wallet.common.utils :as utils]
|
[status-im.contexts.wallet.common.utils :as utils]
|
||||||
[status-im.contexts.wallet.send.select-asset.style :as style]
|
[status-im.contexts.wallet.send.select-asset.style :as style]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
@ -18,8 +19,7 @@
|
|||||||
(defn- asset-component
|
(defn- asset-component
|
||||||
[]
|
[]
|
||||||
(fn [token _ _ {:keys [currency currency-symbol]}]
|
(fn [token _ _ {:keys [currency currency-symbol]}]
|
||||||
(let [on-press
|
(let [on-press #(rf/dispatch [:wallet/send-select-token
|
||||||
#(rf/dispatch [:wallet/send-select-token
|
|
||||||
{:token token
|
{:token token
|
||||||
:stack-id :wallet-select-asset}])
|
:stack-id :wallet-select-asset}])
|
||||||
token-units (utils/total-token-units-in-all-chains token)
|
token-units (utils/total-token-units-in-all-chains token)
|
||||||
@ -50,34 +50,49 @@
|
|||||||
:on-scroll-to-index-failed identity
|
:on-scroll-to-index-failed identity
|
||||||
:render-fn asset-component}]))
|
:render-fn asset-component}]))
|
||||||
|
|
||||||
(defn- tab-view
|
|
||||||
[search-text selected-tab]
|
|
||||||
(case selected-tab
|
|
||||||
:tab/assets [asset-list search-text]
|
|
||||||
:tab/collectibles [quo/empty-state
|
|
||||||
{:title (i18n/label :t/no-collectibles)
|
|
||||||
:description (i18n/label :t/no-collectibles-description)
|
|
||||||
:placeholder? true
|
|
||||||
:container-style (style/empty-container-style (safe-area/get-top))}]))
|
|
||||||
|
|
||||||
(defn- search-input
|
(defn- search-input
|
||||||
[search-text]
|
[search-text on-change-text]
|
||||||
(let [on-change-text #(reset! search-text %)]
|
|
||||||
(fn []
|
|
||||||
[rn/view {:style style/search-input-container}
|
[rn/view {:style style/search-input-container}
|
||||||
[quo/input
|
[quo/input
|
||||||
{:small? true
|
{:small? true
|
||||||
:placeholder (i18n/label :t/search-assets)
|
:placeholder (i18n/label :t/search-assets)
|
||||||
:icon-name :i/search
|
:icon-name :i/search
|
||||||
:value @search-text
|
:value search-text
|
||||||
:on-change-text on-change-text}]])))
|
:on-change-text on-change-text}]])
|
||||||
|
|
||||||
|
(defn collectibles-grid
|
||||||
|
[search-text]
|
||||||
|
(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-collectible-press (fn [collectible-id]
|
||||||
|
(js/alert (str "Collectible to send: \n"
|
||||||
|
collectible-id
|
||||||
|
"\nNavigation not implemented yet")))}]))
|
||||||
|
|
||||||
|
(defn- tab-view
|
||||||
|
[search-text selected-tab on-change-text]
|
||||||
|
(let [unfiltered-collectibles (rf/sub [:wallet/current-viewing-account-collectibles])
|
||||||
|
show-search-input? (or (= selected-tab :tab/assets)
|
||||||
|
(and (= selected-tab :tab/collectibles)
|
||||||
|
(seq unfiltered-collectibles)))]
|
||||||
|
[:<>
|
||||||
|
(when show-search-input?
|
||||||
|
[search-input search-text on-change-text])
|
||||||
|
(case selected-tab
|
||||||
|
:tab/assets [asset-list search-text]
|
||||||
|
:tab/collectibles [collectibles-grid search-text])]))
|
||||||
|
|
||||||
|
|
||||||
(defn- f-view-internal
|
(defn- f-view-internal
|
||||||
[]
|
[]
|
||||||
(let [selected-tab (reagent/atom (:id (first tabs-data)))
|
(let [selected-tab (reagent/atom (:id (first tabs-data)))
|
||||||
search-text (reagent/atom "")
|
search-text (reagent/atom "")
|
||||||
on-close #(rf/dispatch [:navigate-back-within-stack
|
on-change-text #(reset! search-text %)
|
||||||
:wallet-select-asset])]
|
on-change-tab #(reset! selected-tab %)
|
||||||
|
on-close #(rf/dispatch [:navigate-back-within-stack :wallet-select-asset])]
|
||||||
(fn []
|
(fn []
|
||||||
[rn/safe-area-view {:style style/container}
|
[rn/safe-area-view {:style style/container}
|
||||||
[rn/scroll-view
|
[rn/scroll-view
|
||||||
@ -100,9 +115,8 @@
|
|||||||
:container-style {:margin-horizontal 20
|
:container-style {:margin-horizontal 20
|
||||||
:margin-vertical 8}
|
:margin-vertical 8}
|
||||||
:data tabs-data
|
:data tabs-data
|
||||||
:on-change #(reset! selected-tab %)}]
|
:on-change on-change-tab}]
|
||||||
[search-input search-text]
|
[tab-view @search-text @selected-tab on-change-text]]])))
|
||||||
[tab-view @search-text @selected-tab]]])))
|
|
||||||
|
|
||||||
(defn- view-internal
|
(defn- view-internal
|
||||||
[]
|
[]
|
||||||
|
@ -10,15 +10,17 @@
|
|||||||
animation-url
|
animation-url
|
||||||
image-url))
|
image-url))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(defn add-collectibles-preview-url
|
||||||
:wallet/collectibles-per-account
|
[collectibles]
|
||||||
:<- [:wallet]
|
|
||||||
(fn [wallet [_ address]]
|
|
||||||
(as-> wallet $
|
|
||||||
(get-in $ [:accounts address :collectibles])
|
|
||||||
(map (fn [{:keys [collectible-data] :as collectible}]
|
(map (fn [{:keys [collectible-data] :as collectible}]
|
||||||
(assoc collectible :preview-url (preview-url collectible-data)))
|
(assoc collectible :preview-url (preview-url collectible-data)))
|
||||||
$))))
|
collectibles))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
:wallet/current-viewing-account-collectibles
|
||||||
|
:<- [:wallet/current-viewing-account]
|
||||||
|
(fn [current-account]
|
||||||
|
(-> current-account :collectibles add-collectibles-preview-url)))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:wallet/all-collectibles
|
:wallet/all-collectibles
|
||||||
@ -27,8 +29,18 @@
|
|||||||
(->> wallet
|
(->> wallet
|
||||||
:accounts
|
:accounts
|
||||||
(mapcat (comp :collectibles val))
|
(mapcat (comp :collectibles val))
|
||||||
(map (fn [{:keys [collectible-data] :as collectible}]
|
(add-collectibles-preview-url))))
|
||||||
(assoc collectible :preview-url (preview-url collectible-data)))))))
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
:wallet/current-viewing-account-collectibles-filtered
|
||||||
|
:<- [:wallet/current-viewing-account-collectibles]
|
||||||
|
(fn [current-account-collectibles [_ search-text]]
|
||||||
|
(let [search-text-lower-case (string/lower-case search-text)]
|
||||||
|
(filter (fn [{{collection-name :name} :collection-data
|
||||||
|
{collectible-name :name} :collectible-data}]
|
||||||
|
(or (string/includes? (string/lower-case collection-name) search-text-lower-case)
|
||||||
|
(string/includes? (string/lower-case collectible-name) search-text-lower-case)))
|
||||||
|
current-account-collectibles))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
:wallet/last-collectible-details
|
:wallet/last-collectible-details
|
||||||
|
@ -124,10 +124,10 @@
|
|||||||
:<- [:wallet/balances]
|
:<- [:wallet/balances]
|
||||||
:<- [:profile/currency-symbol]
|
:<- [:profile/currency-symbol]
|
||||||
(fn [[accounts current-viewing-account-address balances currency-symbol]]
|
(fn [[accounts current-viewing-account-address balances currency-symbol]]
|
||||||
(let [current-viewing-account (utils/get-account-by-address accounts current-viewing-account-address)
|
(let [balance (get balances current-viewing-account-address)
|
||||||
balance (get balances current-viewing-account-address)
|
|
||||||
formatted-balance (utils/prettify-balance currency-symbol balance)]
|
formatted-balance (utils/prettify-balance currency-symbol balance)]
|
||||||
(-> current-viewing-account
|
(-> accounts
|
||||||
|
(utils/get-account-by-address current-viewing-account-address)
|
||||||
(assoc :balance balance
|
(assoc :balance balance
|
||||||
:formatted-balance formatted-balance)))))
|
:formatted-balance formatted-balance)))))
|
||||||
|
|
||||||
|
@ -1793,6 +1793,8 @@
|
|||||||
"community-info-not-found": "Community information not found",
|
"community-info-not-found": "Community information not found",
|
||||||
"community-info": "Community info",
|
"community-info": "Community info",
|
||||||
"not-found": "Not found",
|
"not-found": "Not found",
|
||||||
|
"nothing-found": "Nothing found",
|
||||||
|
"try-to-search-something-else": "Try to search something else",
|
||||||
"activity": "Activity",
|
"activity": "Activity",
|
||||||
"reject-and-delete": "Reject and delete",
|
"reject-and-delete": "Reject and delete",
|
||||||
"accept-and-add": "Accept and add",
|
"accept-and-add": "Accept and add",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user