From 553f2c0e01d800079a0af9bf4e344bfbc9cf71c5 Mon Sep 17 00:00:00 2001 From: krzyzowiec Date: Mon, 3 Feb 2020 15:26:57 -0500 Subject: [PATCH] Fixed cryptokitties loading/ordering Signed-off-by: Andrey Shovkoplyas --- src/status_im/wallet/collectibles/core.cljs | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/status_im/wallet/collectibles/core.cljs b/src/status_im/wallet/collectibles/core.cljs index 6768ad7973a..5079cfa2a59 100644 --- a/src/status_im/wallet/collectibles/core.cljs +++ b/src/status_im/wallet/collectibles/core.cljs @@ -54,7 +54,7 @@ (handlers/register-handler-fx :load-kitties (fn [{db :db} [_ ids]] - {:db db + {:db (update-in db [:collectibles] merge {ck (sorted-map-by >)}) :http-get-n (mapv (fn [id] {:url (str "https://api.cryptokitties.co/kitties/" id) :success-event-creator (fn [o] @@ -63,18 +63,19 @@ [:load-collectible-failure ck {id (http/parse-payload o)}])}) 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 - "&owner_wallet_address=" - address - "&parents=false") - :success-event-creator (fn [o] - [:load-kitties (map :id (:kitties (http/parse-payload o)))]) - :failure-event-creator (fn [o] - [:load-collectibles-failure (http/parse-payload o)]) - :timeout-ms 10000}}) + {: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)))]) + :failure-event-creator (fn [o] + [:load-collectibles-failure (http/parse-payload o)]) + :timeout-ms 10000}) + (range 0 items-number 20))}) ;; Cryptokitties API limited to 20 items per request ;; Crypto Strikers (def strikers :STRK)