Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#9107] Collectibles (except CryptoKitties) are not loaded (endless s… #9147

Merged
merged 1 commit into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/status_im/ui/screens/wallet/account/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
[status-im.ui.components.icons.vector-icons :as icons]
[status-im.ui.screens.wallet.account.styles :as styles]
[status-im.ui.screens.wallet.transactions.views :as history]
[status-im.ethereum.core :as ethereum]))
[status-im.ethereum.core :as ethereum]
[status-im.ui.components.list-item.views :as list-item]
[status-im.utils.money :as money]
[status-im.wallet.utils :as wallet.utils]))

(def state (reagent/atom {:tab :assets}))

Expand Down Expand Up @@ -66,6 +69,19 @@
[react/view {:style styles/divider}]
[button (i18n/label :t/receive) :main-icons/receive #(re-frame/dispatch [:show-popover {:view :share-account :address address}])]]]))

(defn render-collectible [address]
(fn [{:keys [name icon amount] :as collectible}]
(let [items-number (money/to-fixed amount)
details? (pos? items-number)]
[list-item/list-item
{:title (wallet.utils/display-symbol collectible)
:subtitle name
:icon [list/item-image icon]
:on-press (when details?
#(re-frame/dispatch
[:show-collectibles-list collectible address]))
:accessories [items-number :chevron]}])))

(views/defview transactions [address]
(views/letsubs [{:keys [transaction-history-sections]}
[:wallet.transactions.history/screen address]]
Expand Down Expand Up @@ -97,7 +113,7 @@
:footer [react/view
{:style {:height tabs.styles/tabs-diff
:align-self :stretch}}]
:render-fn accounts/render-collectible}]
:render-fn (render-collectible address)}]
[react/view {:align-items :center :margin-top 32}
[react/text {:style {:color colors/gray}}
(i18n/label :t/no-collectibles)]])
Expand Down
51 changes: 10 additions & 41 deletions src/status_im/ui/screens/wallet/accounts/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
[status-im.wallet.utils :as wallet.utils]
[status-im.ui.components.tabbar.styles :as tabs.styles]
[reagent.core :as reagent]
[status-im.utils.money :as money]
[re-frame.core :as re-frame]
[status-im.ui.screens.wallet.accounts.sheets :as sheets]
[status-im.ethereum.core :as ethereum]
[status-im.ui.screens.wallet.accounts.styles :as styles]))

(def state (reagent/atom {:tab :assets}))
Expand Down Expand Up @@ -79,45 +77,16 @@
[list/item-image icon]
[chat-icon/custom-icon-view-list (:name token) color])}]))

(defn render-collectible [{:keys [name icon amount] :as collectible}]
(let [items-number (money/to-fixed amount)
details? (pos? items-number)]
[list-item/list-item
{:title (wallet.utils/display-symbol collectible)
:subtitle name
:icon [list/item-image icon]
:on-press (when details?
#(re-frame/dispatch
[:show-collectibles-list collectible]))
:accessories [items-number :chevron]}]))

(views/defview assets-and-collections []
(views/defview assets []
(views/letsubs [{:keys [tokens nfts]} [:wallet/all-visible-assets-with-values]
currency [:wallet/currency]]
(let [{:keys [tab]} @state]
[react/view {:flex 1}
[react/view {:flex-direction :row :margin-bottom 8 :margin-horizontal 4}
[tab-title state :assets (i18n/label :t/wallet-assets) (= tab :assets)]
[tab-title state :nft (i18n/label :t/wallet-collectibles) (= tab :nft)]]
(if (= tab :assets)
[list/flat-list {:data tokens
:default-separator? false
:key-fn :name
:footer [react/view
{:style {:height tabs.styles/tabs-diff
:align-self :stretch}}]
:render-fn (render-asset (:code currency))}]
(if (seq nfts)
[list/flat-list {:data nfts
:default-separator? false
:key-fn :name
:footer [react/view
{:style {:height tabs.styles/tabs-diff
:align-self :stretch}}]
:render-fn render-collectible}]
[react/view {:align-items :center :margin-top 32}
[react/text {:style {:color colors/gray}}
(i18n/label :t/no-collectibles)]]))])))
[list/flat-list {:data tokens
:default-separator? false
:key-fn :name
:footer [react/view
{:style {:height tabs.styles/tabs-diff
:align-self :stretch}}]
:render-fn (render-asset (:code currency))}]))

(views/defview total-value []
(views/letsubs [currency [:wallet/currency]
Expand Down Expand Up @@ -149,7 +118,7 @@
[icons/icon :main-icons/more {:accessibility-label :accounts-more-options}]]]]))

(views/defview accounts []
(views/letsubs [{:keys [accounts address keycard-key-uid]} [:multiaccount]]
(views/letsubs [{:keys [accounts keycard-key-uid]} [:multiaccount]]
[react/scroll-view {:horizontal true}
[react/view {:flex-direction :row :padding-top 11 :padding-bottom 12}
(for [account accounts]
Expand All @@ -167,4 +136,4 @@
[react/view {:margin-top 8 :padding-horizontal 16}
[total-value]
[accounts]]
[assets-and-collections]]])
[assets]]])
21 changes: 9 additions & 12 deletions src/status_im/wallet/collectibles/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@

(defmethod load-collectible-fx :default [_ _ _] nil)

(defmulti load-collectibles-fx (fn [_ symbol _ _] symbol))
(defmulti load-collectibles-fx (fn [_ symbol _ _ _] symbol))

(defmethod load-collectibles-fx :default [all-tokens symbol items-number address chain-id]
{:load-collectibles-fx [all-tokens symbol items-number address chain-id]})
(defmethod load-collectibles-fx :default [all-tokens symbol items-number address chain]
{:load-collectibles-fx [all-tokens symbol items-number address chain]})

(defn load-token [i items-number contract address symbol]
(when (< i items-number)
Expand All @@ -31,20 +31,20 @@

(re-frame/reg-fx
:load-collectibles-fx
(fn [[all-tokens symbol items-number address chain-id]]
(let [chain (ethereum/chain-id->chain-keyword chain-id)
contract (:address (tokens/symbol->token all-tokens chain symbol))]
(fn [[all-tokens symbol items-number address chain]]
(let [contract (:address (tokens/symbol->token all-tokens chain symbol))]
(load-token 0 items-number contract address symbol))))

(handlers/register-handler-fx
:show-collectibles-list
(fn [{:keys [db]} [_ {:keys [symbol amount] :as collectible}]]
(let [chain-id (get-in constants/default-networks [(:network db) :config :NetworkId])
(fn [{:keys [db]} [_ {:keys [symbol amount] :as collectible} address]]
(let [chain (ethereum/chain-id->chain-keyword
(get-in constants/default-networks [(:networks/current-network db) :config :NetworkId]))
all-tokens (:wallet/all-tokens db)
items-number (money/to-number amount)
loaded-items-number (count (get-in db [:collectibles symbol]))]
(merge (when (not= items-number loaded-items-number)
(load-collectibles-fx all-tokens symbol items-number (ethereum/default-address db) chain-id))
(load-collectibles-fx all-tokens symbol items-number address chain))
{:dispatch [:navigate-to :collectibles-list collectible]}))))

;; Crypto Kitties
Expand Down Expand Up @@ -168,9 +168,6 @@
(fn [o]
[:load-collectible-failure kudos {tokenId (http/parse-payload o)}])}}))

;;


(handlers/register-handler-fx
:load-collectible
(fn [cofx [_ symbol token-id]]
Expand Down