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

Fix limited Cryptokitties display and order #9810

Closed
wants to merge 1 commit into from
Closed
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
21 changes: 13 additions & 8 deletions src/status_im/wallet/collectibles/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,35 @@
;; Crypto Kitties
(def ck :CK)

;; TODO Can't maintain the order (ascending) of id's array, mapv randomises indexes and filterv results in a error
(handlers/register-handler-fx
:load-kitties
(fn [{db :db} [_ ids]]
{:db db
:http-get-n (mapv (fn [id]
{:url (str "https://api.cryptokitties.co/kitties/" id)
{:url (str "https://api.cryptokitties.co/kitties/" id)
:success-event-creator (fn [o]
[:load-collectible-success ck {id (http/parse-payload o)}])
:failure-event-creator (fn [o]
[:load-collectible-failure ck {id (http/parse-payload o)}])})
ids)}))
[:load-collectible-failure ck {id (http/parse-payload o)}])
:timeout-ms 10000})
ids)}))

;; TODO(andrey) Each HTTP call will return up to 100 kitties. Maybe we need to implement some kind of paging later
(defmethod load-collectibles-fx ck [_ _ items-number address _]
{:http-get {:url (str "https://api.cryptokitties.co/kitties?offset=0&limit="
items-number
(def metakitties [])
{:http-get-n (mapv (fn [offset]
{:url (str "https://api.cryptokitties.co/kitties?limit=20&offset="
offset
"&owner_wallet_address="
address
"&parents=false")
:success-event-creator (fn [o]
[:load-kitties (map :id (:kitties (http/parse-payload o)))])
(def metakitties (concat (map :id (:kitties (http/parse-payload o))) metakitties))
(when (= (count metakitties) items-number) [:load-kitties (sort metakitties)]))
:failure-event-creator (fn [o]
[:load-collectibles-failure (http/parse-payload o)])
:timeout-ms 10000}})
:timeout-ms 10000})
(range 0 items-number 20))})

;; Crypto Strikers
(def strikers :STRK)
Expand Down