Match the changes in collectibles api in status-go (#18033)

This commit is contained in:
Volodymyr Kozieiev 2023-12-04 16:44:56 +00:00 committed by GitHub
parent 439fdfa12c
commit 489557c1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 44 deletions

View File

@ -10,7 +10,7 @@
[utils.re-frame :as rf]))
(defn header
[{:keys [name description collection-image-url]}]
[{:keys [name description] :as _collectible-details} collection-image-url]
[rn/view {:style style/header}
[quo/text
{:weight :semi-bold
@ -112,9 +112,11 @@
(defn view
[]
(let [collectible-details (rf/sub [:wallet/last-collectible-details])
{:keys [name description preview-url traits id]} collectible-details
chain-id (get-in id [:contract-id :chain-id])]
(let [collectible (rf/sub [:wallet/last-collectible-details])
{:keys [collectible-data preview-url
collection-data]} collectible
{:keys [traits description]} collectible-data
chain-id (rf/sub [:wallet/last-collectible-chain-id])]
[scroll-page/scroll-page
{:navigate-back? true
:height 148
@ -129,7 +131,7 @@
[rn/image
{:source preview-url
:style style/preview}]]
[header collectible-details]
[header collectible-data (:image-url collection-data)]
[cta-buttons]
[tabs]
[info chain-id]

View File

@ -215,9 +215,10 @@
(def collectibles-request-batch-size 1000)
(defn displayable-collectible?
[{:keys [image-url animation-url]}]
(or (not (string/blank? animation-url))
(not (string/blank? image-url))))
[collectible]
(let [{:keys [image-url animation-url]} (:collectible-data collectible)]
(or (not (string/blank? animation-url))
(not (string/blank? image-url)))))
(defn store-collectibles
[{:keys [db]} [collectibles]]
@ -243,28 +244,47 @@
(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
:wallet/request-collectibles
(fn [{:keys [db]} [{:keys [start-at-index new-request?]}]]
(let [request-id 0
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
[(chain/chain-id db)]
(map :address (:profile/wallet-accounts db))
collectibles-filter
start-at-index
collectibles-request-batch-size]]
{:json-rpc/call [{:method "wallet_filterOwnedCollectiblesAsync"
:params request-params
:on-success #()
:on-error (fn [error]
(log/error "failed to request collectibles"
{:event :wallet/request-collectibles
:error error
:params request-params}))}]
:fx (if new-request?
[[:dispatch [:wallet/clear-stored-collectibles]]]
[])})))
collectibles-request-batch-size
data-type
fetch-criteria]]
{:fx [[:json-rpc/call
[{:method "wallet_getOwnedCollectiblesAsync"
:params request-params
:on-success #()
:on-error (fn [error]
(log/error "failed to request collectibles"
{:event :wallet/request-collectibles
:error error
:params request-params}))}]]
(when new-request?
[:dispatch [:wallet/clear-stored-collectibles]])]})))
(rf/reg-event-fx :wallet/owned-collectibles-filtering-done
(fn [_ [{:keys [message]}]]
@ -283,14 +303,16 @@
(fn [_ [collectible-id]]
(let [request-id 0
collectible-id-converted (cske/transform-keys csk/->PascalCaseKeyword collectible-id)
request-params [request-id [collectible-id-converted]]]
{:json-rpc/call [{:method "wallet_getCollectiblesDetailsAsync"
:params request-params
:on-error (fn [error]
(log/error "failed to request collectible"
{:event :wallet/get-collectible-details
:error error
:params request-params}))}]})))
data-type (collectible-data-types :details)
request-params [request-id [collectible-id-converted] data-type]]
{:fx [[:json-rpc/call
[{:method "wallet_getCollectiblesByUniqueIDAsync"
:params request-params
:on-error (fn [error]
(log/error "failed to request collectible"
{:event :wallet/get-collectible-details
:error error
:params request-params}))}]]]})))
(rf/reg-event-fx :wallet/get-collectible-details-done
(fn [_ [{:keys [message]}]]

View File

@ -23,24 +23,27 @@
(deftest store-collectibles
(testing "(displayable-collectible?) helper function"
(let [expected-results [[true {:image-url "https://..." :animation-url "https://..."}]
[true {:image-url "" :animation-url "https://..."}]
[true {:image-url nil :animation-url "https://..."}]
[true {:image-url "https://..." :animation-url ""}]
[true {:image-url "https://..." :animation-url nil}]
[false {:image-url "" :animation-url nil}]
[false {:image-url nil :animation-url nil}]
[false {:image-url nil :animation-url ""}]
[false {:image-url "" :animation-url ""}]]]
(let [expected-results [[true
{:collectible-data {:image-url "https://..." :animation-url "https://..."}}]
[true {:collectible-data {:image-url "" :animation-url "https://..."}}]
[true {:collectible-data {:image-url nil :animation-url "https://..."}}]
[true {:collectible-data {:image-url "https://..." :animation-url ""}}]
[true {:collectible-data {:image-url "https://..." :animation-url nil}}]
[false {:collectible-data {:image-url "" :animation-url nil}}]
[false {:collectible-data {:image-url nil :animation-url nil}}]
[false {:collectible-data {:image-url nil :animation-url ""}}]
[false {:collectible-data {:image-url "" :animation-url ""}}]]]
(doseq [[result collection] expected-results]
(is (= result (events/displayable-collectible? collection))))))
(testing "save-collectibles-request-details"
(let [db {:wallet {}}
collectibles [{:image-url "https://..." :animation-url "https://..."}
{:image-url "" :animation-url "https://..."}
{:image-url "" :animation-url nil}]
expected-db {:wallet {:collectibles [{:image-url "https://..." :animation-url "https://..."}
{:image-url "" :animation-url "https://..."}]}}
collectibles [{:collectible-data {:image-url "https://..." :animation-url "https://..."}}
{:collectible-data {:image-url "" :animation-url "https://..."}}
{:collectible-data {:image-url "" :animation-url nil}}]
expected-db {:wallet {:collectibles [{:collectible-data
{:image-url "https://..." :animation-url "https://..."}}
{:collectible-data
{:image-url "" :animation-url "https://..."}}]}}
effects (events/store-collectibles {:db db} [collectibles])
result-db (:db effects)]
(is (= result-db expected-db)))))

View File

@ -15,7 +15,7 @@
:<- [:wallet]
(fn [wallet]
(map (fn [collectible]
(assoc collectible :preview-url (preview-url collectible)))
(assoc collectible :preview-url (preview-url (:collectible-data collectible))))
(:collectibles wallet))))
(re-frame/reg-sub
@ -23,4 +23,10 @@
:<- [:wallet]
(fn [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])))