mirror of
https://github.com/status-im/status-react.git
synced 2025-02-25 17:16:03 +00:00
Match the changes in collectibles api in status-go (#18033)
This commit is contained in:
parent
439fdfa12c
commit
489557c1a3
@ -10,7 +10,7 @@
|
|||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
(defn header
|
(defn header
|
||||||
[{:keys [name description collection-image-url]}]
|
[{:keys [name description] :as _collectible-details} collection-image-url]
|
||||||
[rn/view {:style style/header}
|
[rn/view {:style style/header}
|
||||||
[quo/text
|
[quo/text
|
||||||
{:weight :semi-bold
|
{:weight :semi-bold
|
||||||
@ -112,9 +112,11 @@
|
|||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[]
|
[]
|
||||||
(let [collectible-details (rf/sub [:wallet/last-collectible-details])
|
(let [collectible (rf/sub [:wallet/last-collectible-details])
|
||||||
{:keys [name description preview-url traits id]} collectible-details
|
{:keys [collectible-data preview-url
|
||||||
chain-id (get-in id [:contract-id :chain-id])]
|
collection-data]} collectible
|
||||||
|
{:keys [traits description]} collectible-data
|
||||||
|
chain-id (rf/sub [:wallet/last-collectible-chain-id])]
|
||||||
[scroll-page/scroll-page
|
[scroll-page/scroll-page
|
||||||
{:navigate-back? true
|
{:navigate-back? true
|
||||||
:height 148
|
:height 148
|
||||||
@ -129,7 +131,7 @@
|
|||||||
[rn/image
|
[rn/image
|
||||||
{:source preview-url
|
{:source preview-url
|
||||||
:style style/preview}]]
|
:style style/preview}]]
|
||||||
[header collectible-details]
|
[header collectible-data (:image-url collection-data)]
|
||||||
[cta-buttons]
|
[cta-buttons]
|
||||||
[tabs]
|
[tabs]
|
||||||
[info chain-id]
|
[info chain-id]
|
||||||
|
@ -215,9 +215,10 @@
|
|||||||
(def collectibles-request-batch-size 1000)
|
(def collectibles-request-batch-size 1000)
|
||||||
|
|
||||||
(defn displayable-collectible?
|
(defn displayable-collectible?
|
||||||
[{:keys [image-url animation-url]}]
|
[collectible]
|
||||||
(or (not (string/blank? animation-url))
|
(let [{:keys [image-url animation-url]} (:collectible-data collectible)]
|
||||||
(not (string/blank? image-url))))
|
(or (not (string/blank? animation-url))
|
||||||
|
(not (string/blank? image-url)))))
|
||||||
|
|
||||||
(defn store-collectibles
|
(defn store-collectibles
|
||||||
[{:keys [db]} [collectibles]]
|
[{:keys [db]} [collectibles]]
|
||||||
@ -243,28 +244,47 @@
|
|||||||
|
|
||||||
(rf/reg-event-fx :wallet/store-last-collectible-details store-last-collectible-details)
|
(rf/reg-event-fx :wallet/store-last-collectible-details store-last-collectible-details)
|
||||||
|
|
||||||
|
(def collectible-data-types
|
||||||
|
{:unique-id 0
|
||||||
|
:header 1
|
||||||
|
:details 2
|
||||||
|
:community-header 3})
|
||||||
|
|
||||||
|
(def fetch-type
|
||||||
|
{:never-fetch 0
|
||||||
|
:always-fetch 1
|
||||||
|
:fetch-if-not-cached 2
|
||||||
|
:fetch-if-cache-old 3})
|
||||||
|
|
||||||
|
(def max-cache-age-seconds 3600)
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:wallet/request-collectibles
|
:wallet/request-collectibles
|
||||||
(fn [{:keys [db]} [{:keys [start-at-index new-request?]}]]
|
(fn [{:keys [db]} [{:keys [start-at-index new-request?]}]]
|
||||||
(let [request-id 0
|
(let [request-id 0
|
||||||
collectibles-filter nil
|
collectibles-filter nil
|
||||||
|
data-type (collectible-data-types :header)
|
||||||
|
fetch-criteria {:fetch-type (fetch-type :fetch-if-not-cached)
|
||||||
|
:max-cache-age-seconds max-cache-age-seconds}
|
||||||
request-params [request-id
|
request-params [request-id
|
||||||
[(chain/chain-id db)]
|
[(chain/chain-id db)]
|
||||||
(map :address (:profile/wallet-accounts db))
|
(map :address (:profile/wallet-accounts db))
|
||||||
collectibles-filter
|
collectibles-filter
|
||||||
start-at-index
|
start-at-index
|
||||||
collectibles-request-batch-size]]
|
collectibles-request-batch-size
|
||||||
{:json-rpc/call [{:method "wallet_filterOwnedCollectiblesAsync"
|
data-type
|
||||||
:params request-params
|
fetch-criteria]]
|
||||||
:on-success #()
|
{:fx [[:json-rpc/call
|
||||||
:on-error (fn [error]
|
[{:method "wallet_getOwnedCollectiblesAsync"
|
||||||
(log/error "failed to request collectibles"
|
:params request-params
|
||||||
{:event :wallet/request-collectibles
|
:on-success #()
|
||||||
:error error
|
:on-error (fn [error]
|
||||||
:params request-params}))}]
|
(log/error "failed to request collectibles"
|
||||||
:fx (if new-request?
|
{:event :wallet/request-collectibles
|
||||||
[[:dispatch [:wallet/clear-stored-collectibles]]]
|
:error error
|
||||||
[])})))
|
:params request-params}))}]]
|
||||||
|
(when new-request?
|
||||||
|
[:dispatch [:wallet/clear-stored-collectibles]])]})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/owned-collectibles-filtering-done
|
(rf/reg-event-fx :wallet/owned-collectibles-filtering-done
|
||||||
(fn [_ [{:keys [message]}]]
|
(fn [_ [{:keys [message]}]]
|
||||||
@ -283,14 +303,16 @@
|
|||||||
(fn [_ [collectible-id]]
|
(fn [_ [collectible-id]]
|
||||||
(let [request-id 0
|
(let [request-id 0
|
||||||
collectible-id-converted (cske/transform-keys csk/->PascalCaseKeyword collectible-id)
|
collectible-id-converted (cske/transform-keys csk/->PascalCaseKeyword collectible-id)
|
||||||
request-params [request-id [collectible-id-converted]]]
|
data-type (collectible-data-types :details)
|
||||||
{:json-rpc/call [{:method "wallet_getCollectiblesDetailsAsync"
|
request-params [request-id [collectible-id-converted] data-type]]
|
||||||
:params request-params
|
{:fx [[:json-rpc/call
|
||||||
:on-error (fn [error]
|
[{:method "wallet_getCollectiblesByUniqueIDAsync"
|
||||||
(log/error "failed to request collectible"
|
:params request-params
|
||||||
{:event :wallet/get-collectible-details
|
:on-error (fn [error]
|
||||||
:error error
|
(log/error "failed to request collectible"
|
||||||
:params request-params}))}]})))
|
{:event :wallet/get-collectible-details
|
||||||
|
:error error
|
||||||
|
:params request-params}))}]]]})))
|
||||||
|
|
||||||
(rf/reg-event-fx :wallet/get-collectible-details-done
|
(rf/reg-event-fx :wallet/get-collectible-details-done
|
||||||
(fn [_ [{:keys [message]}]]
|
(fn [_ [{:keys [message]}]]
|
||||||
|
@ -23,24 +23,27 @@
|
|||||||
|
|
||||||
(deftest store-collectibles
|
(deftest store-collectibles
|
||||||
(testing "(displayable-collectible?) helper function"
|
(testing "(displayable-collectible?) helper function"
|
||||||
(let [expected-results [[true {:image-url "https://..." :animation-url "https://..."}]
|
(let [expected-results [[true
|
||||||
[true {:image-url "" :animation-url "https://..."}]
|
{:collectible-data {:image-url "https://..." :animation-url "https://..."}}]
|
||||||
[true {:image-url nil :animation-url "https://..."}]
|
[true {:collectible-data {:image-url "" :animation-url "https://..."}}]
|
||||||
[true {:image-url "https://..." :animation-url ""}]
|
[true {:collectible-data {:image-url nil :animation-url "https://..."}}]
|
||||||
[true {:image-url "https://..." :animation-url nil}]
|
[true {:collectible-data {:image-url "https://..." :animation-url ""}}]
|
||||||
[false {:image-url "" :animation-url nil}]
|
[true {:collectible-data {:image-url "https://..." :animation-url nil}}]
|
||||||
[false {:image-url nil :animation-url nil}]
|
[false {:collectible-data {:image-url "" :animation-url nil}}]
|
||||||
[false {:image-url nil :animation-url ""}]
|
[false {:collectible-data {:image-url nil :animation-url nil}}]
|
||||||
[false {:image-url "" :animation-url ""}]]]
|
[false {:collectible-data {:image-url nil :animation-url ""}}]
|
||||||
|
[false {:collectible-data {:image-url "" :animation-url ""}}]]]
|
||||||
(doseq [[result collection] expected-results]
|
(doseq [[result collection] expected-results]
|
||||||
(is (= result (events/displayable-collectible? collection))))))
|
(is (= result (events/displayable-collectible? collection))))))
|
||||||
(testing "save-collectibles-request-details"
|
(testing "save-collectibles-request-details"
|
||||||
(let [db {:wallet {}}
|
(let [db {:wallet {}}
|
||||||
collectibles [{:image-url "https://..." :animation-url "https://..."}
|
collectibles [{:collectible-data {:image-url "https://..." :animation-url "https://..."}}
|
||||||
{:image-url "" :animation-url "https://..."}
|
{:collectible-data {:image-url "" :animation-url "https://..."}}
|
||||||
{:image-url "" :animation-url nil}]
|
{:collectible-data {:image-url "" :animation-url nil}}]
|
||||||
expected-db {:wallet {:collectibles [{:image-url "https://..." :animation-url "https://..."}
|
expected-db {:wallet {:collectibles [{:collectible-data
|
||||||
{:image-url "" :animation-url "https://..."}]}}
|
{:image-url "https://..." :animation-url "https://..."}}
|
||||||
|
{:collectible-data
|
||||||
|
{:image-url "" :animation-url "https://..."}}]}}
|
||||||
effects (events/store-collectibles {:db db} [collectibles])
|
effects (events/store-collectibles {:db db} [collectibles])
|
||||||
result-db (:db effects)]
|
result-db (:db effects)]
|
||||||
(is (= result-db expected-db)))))
|
(is (= result-db expected-db)))))
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
(fn [wallet]
|
(fn [wallet]
|
||||||
(map (fn [collectible]
|
(map (fn [collectible]
|
||||||
(assoc collectible :preview-url (preview-url collectible)))
|
(assoc collectible :preview-url (preview-url (:collectible-data collectible))))
|
||||||
(:collectibles wallet))))
|
(:collectibles wallet))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
@ -23,4 +23,10 @@
|
|||||||
:<- [:wallet]
|
:<- [:wallet]
|
||||||
(fn [wallet]
|
(fn [wallet]
|
||||||
(let [last-collectible (:last-collectible-details wallet)]
|
(let [last-collectible (:last-collectible-details wallet)]
|
||||||
(assoc last-collectible :preview-url (preview-url last-collectible)))))
|
(assoc last-collectible :preview-url (preview-url (:collectible-data last-collectible))))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
:wallet/last-collectible-chain-id
|
||||||
|
:<- [:wallet/last-collectible-details]
|
||||||
|
(fn [collectible]
|
||||||
|
(get-in collectible [:id :contract-id :chain-id])))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user