mirror of
https://github.com/status-im/status-react.git
synced 2025-01-09 10:42:53 +00:00
[Fixes #5496] Added SuperRare NFT support
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
96b8edc846
commit
683e6b5ed0
BIN
resources/images/tokens/mainnet/SUPR.png
Normal file
BIN
resources/images/tokens/mainnet/SUPR.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
BIN
resources/images/tokens/testnet/SUPR.png
Normal file
BIN
resources/images/tokens/testnet/SUPR.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.7 KiB |
@ -642,6 +642,8 @@
|
||||
|
||||
:view-cryptostrikers "View in CryptoStrikers"
|
||||
|
||||
:view-superrare "View in SuperRare"
|
||||
|
||||
;; network settings
|
||||
:new-network "New network"
|
||||
:add-network "Add network"
|
||||
|
@ -36,6 +36,7 @@
|
||||
status-im.ui.screens.wallet.collectibles.cryptokitties.events
|
||||
status-im.ui.screens.wallet.collectibles.cryptostrikers.events
|
||||
status-im.ui.screens.wallet.collectibles.etheremon.events
|
||||
status-im.ui.screens.wallet.collectibles.superrare.events
|
||||
status-im.ui.screens.browser.events
|
||||
status-im.ui.screens.offline-messaging-settings.events
|
||||
status-im.ui.screens.privacy-policy.events
|
||||
@ -92,6 +93,18 @@
|
||||
(doseq [call calls]
|
||||
(http-get call))))
|
||||
|
||||
(defn- http-post [{:keys [url data response-validator success-event-creator failure-event-creator timeout-ms opts]}]
|
||||
(let [on-success #(re-frame/dispatch (success-event-creator %))
|
||||
on-error #(re-frame/dispatch (failure-event-creator %))
|
||||
all-opts (assoc opts
|
||||
:valid-response? response-validator
|
||||
:timeout-ms timeout-ms)]
|
||||
(http/post url data on-success on-error all-opts)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:http-post
|
||||
http-post)
|
||||
|
||||
(re-frame/reg-fx
|
||||
:request-permissions-fx
|
||||
(fn [options]
|
||||
|
@ -41,6 +41,12 @@
|
||||
(fn [_ [_ symbol token-id]]
|
||||
(load-collectible-fx symbol token-id)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:store-collectibles
|
||||
(fn [{db :db} [_ symbol collectibles]]
|
||||
{:db (update-in db [:collectibles symbol] merge
|
||||
(reduce #(assoc %1 (:tokenId %2) %2) {} collectibles))}))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:load-collectible-success
|
||||
[re-frame/trim-v]
|
||||
@ -50,8 +56,8 @@
|
||||
(handlers/register-handler-fx
|
||||
:load-collectibles-failure
|
||||
[re-frame/trim-v]
|
||||
(fn [{db :db} [{:keys [message]}]]
|
||||
{:db (assoc db :collectibles-failure message)}))
|
||||
(fn [{db :db} [reason]]
|
||||
{:db (update-in db [:collectibles symbol :errors] merge reason)}))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:load-collectible-failure
|
||||
|
@ -8,4 +8,5 @@
|
||||
:<- [:collectibles]
|
||||
:<- [:get-screen-params]
|
||||
(fn [[collectibles {:keys [symbol]}]]
|
||||
(mapv #(assoc (second %) :id (first %)) (get collectibles symbol))))
|
||||
(when-let [v (get collectibles symbol)]
|
||||
(mapv #(assoc (second %) :id (first %)) v))))
|
||||
|
@ -0,0 +1,41 @@
|
||||
(ns status-im.ui.screens.wallet.collectibles.superrare.events
|
||||
(:require [status-im.ui.screens.wallet.collectibles.events :as collectibles]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.http :as http]
|
||||
[status-im.utils.types :as types]))
|
||||
|
||||
(def superrare :SUPR)
|
||||
|
||||
(defmethod collectibles/load-collectible-fx superrare [_ ids]
|
||||
{:http-get-n (mapv (fn [id]
|
||||
{:url id
|
||||
:success-event-creator (fn [o]
|
||||
[:load-collectible-success superrare {id (http/parse-payload o)}])
|
||||
:failure-event-creator (fn [o]
|
||||
[:load-collectible-failure superrare {id (http/parse-payload o)}])})
|
||||
ids)})
|
||||
|
||||
(def graphql-url "https://api.pixura.io/graphql")
|
||||
|
||||
(defn graphql-query [address]
|
||||
(str "{
|
||||
collectiblesByOwner: allErc721Tokens(condition: {owner: \"" address "\"}) {
|
||||
collectibles: nodes {
|
||||
tokenId,
|
||||
metadata: erc721MetadatumByTokenId {
|
||||
metadataUri,
|
||||
description,
|
||||
name,
|
||||
imageUri
|
||||
}}}}"))
|
||||
|
||||
(defmethod collectibles/load-collectibles-fx superrare [_ _ _ address]
|
||||
{:http-post {:url graphql-url
|
||||
:data (types/clj->json {:query (graphql-query (ethereum/naked-address address))})
|
||||
:opts {:headers {"Content-Type" "application/json"}}
|
||||
:success-event-creator (fn [o]
|
||||
[:store-collectibles superrare
|
||||
(get-in (http/parse-payload o) [:data :collectiblesByOwner :collectibles])])
|
||||
:failure-event-creator (fn [o]
|
||||
[:load-collectibles-failure (http/parse-payload o)])
|
||||
:timeout-ms 10000}})
|
@ -0,0 +1,27 @@
|
||||
(ns status-im.ui.screens.wallet.collectibles.superrare.views
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.ui.components.action-button.action-button :as action-button]
|
||||
[status-im.ui.components.colors :as colors]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.screens.wallet.collectibles.styles :as styles]
|
||||
[status-im.ui.screens.wallet.collectibles.views :as collectibles]))
|
||||
|
||||
(defmethod collectibles/render-collectible :SUPR [_ {tokenId :tokenId {:keys [description name imageUri]} :metadata}]
|
||||
[react/view {:style styles/details}
|
||||
[react/view {:style styles/details-text}
|
||||
[react/image {:style (merge {:resize-mode :contain :width 100 :height 100} styles/details-image)
|
||||
:source {:uri imageUri
|
||||
:k 1.4}}]
|
||||
[react/view {:flex 1 :justify-content :center}
|
||||
[react/text {:style styles/details-name}
|
||||
name]
|
||||
[react/text
|
||||
description]]]
|
||||
[action-button/action-button
|
||||
{:label (i18n/label :t/view-superrare)
|
||||
:icon :icons/address
|
||||
:icon-opts {:color colors/blue}
|
||||
:accessibility-label :open-collectible-button
|
||||
:on-press #(re-frame/dispatch [:open-collectible-in-browser
|
||||
(str "https://superrare.co/artwork/" name "-" tokenId)])}]])
|
@ -1,6 +1,7 @@
|
||||
(ns status-im.ui.screens.wallet.collectibles.views
|
||||
(:require-macros [status-im.utils.views :refer [defview letsubs]])
|
||||
(:require [status-im.ui.components.colors :as colors]
|
||||
(:require [status-im.i18n :as i18n]
|
||||
[status-im.ui.components.colors :as colors]
|
||||
[status-im.ui.components.list.views :as list]
|
||||
[status-im.ui.components.react :as react]
|
||||
[status-im.ui.components.status-bar.view :as status-bar]
|
||||
@ -23,9 +24,16 @@
|
||||
[toolbar/toolbar {}
|
||||
toolbar/default-nav-back
|
||||
[toolbar/content-title name]]
|
||||
(if (seq collectibles)
|
||||
(cond
|
||||
(nil? collectibles)
|
||||
[react/view {:style styles/loading-indicator}
|
||||
[react/activity-indicator {:animating true :size :large :color colors/blue}]]
|
||||
(seq collectibles)
|
||||
[list/flat-list {:data collectibles
|
||||
:key-fn (comp str :id)
|
||||
:render-fn #(render-collectible symbol %)}]
|
||||
:else
|
||||
;; Should never happen. Less confusing to debug new NFT support.
|
||||
[react/view {:style styles/loading-indicator}
|
||||
[react/activity-indicator {:animating true :size :large :color colors/blue}]])]]))
|
||||
[react/text (i18n/label :t/error)]])]]))
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
status-im.ui.screens.wallet.collectibles.etheremon.views
|
||||
status-im.ui.screens.wallet.collectibles.cryptostrikers.views
|
||||
status-im.ui.screens.wallet.collectibles.cryptokitties.views
|
||||
status-im.ui.screens.wallet.collectibles.superrare.views
|
||||
[status-im.ui.components.status-bar.view :as status-bar.view]
|
||||
[status-im.ui.components.text :as text]
|
||||
[status-im.ui.screens.wallet.transactions.views :as transactions.views]
|
||||
|
@ -33,6 +33,10 @@
|
||||
address
|
||||
(str hex-prefix address))))
|
||||
|
||||
(defn naked-address [s]
|
||||
(when s
|
||||
(string/replace s hex-prefix "")))
|
||||
|
||||
(defn address? [s]
|
||||
(when s
|
||||
(.isAddress dependencies/Web3.prototype s)))
|
||||
|
@ -406,7 +406,11 @@
|
||||
{:symbol :STRK
|
||||
:nft? true
|
||||
:name "CryptoStrikers"
|
||||
:address "0xdcaad9fd9a74144d226dbf94ce6162ca9f09ed7e"}])
|
||||
:address "0xdcaad9fd9a74144d226dbf94ce6162ca9f09ed7e"}
|
||||
{:symbol :SUPR
|
||||
:nft? true
|
||||
:name "SuperRare"
|
||||
:address "0x41a322b28d0ff354040e2cbc676f0320d8c8850d"}])
|
||||
:testnet
|
||||
(resolve-icons :testnet
|
||||
[{:name "Status Test Token"
|
||||
|
@ -15,7 +15,7 @@
|
||||
(post url data on-success nil))
|
||||
([url data on-success on-error]
|
||||
(post url data on-success on-error nil))
|
||||
([url data on-success on-error {:keys [timeout-ms headers]}]
|
||||
([url data on-success on-error {:keys [valid-response? timeout-ms headers]}]
|
||||
(-> (rn-dependencies/fetch
|
||||
url
|
||||
(clj->js (merge {:method "POST"
|
||||
@ -24,7 +24,23 @@
|
||||
(when headers
|
||||
{:headers headers}))))
|
||||
(.then (fn [response]
|
||||
(on-success response)))
|
||||
(->
|
||||
(.text response)
|
||||
(.then (fn [response-body]
|
||||
(let [ok? (.-ok response)
|
||||
ok?' (if valid-response?
|
||||
(and ok? (valid-response? response))
|
||||
ok?)]
|
||||
[response-body ok?']))))))
|
||||
(.then (fn [[response ok?]]
|
||||
(cond
|
||||
(and on-success ok?)
|
||||
(on-success response)
|
||||
|
||||
(and on-error (not ok?))
|
||||
(on-error response)
|
||||
|
||||
:else false)))
|
||||
(.catch (or on-error
|
||||
(fn [error]
|
||||
(utils/show-popup "Error" (str error))))))))
|
||||
|
Loading…
x
Reference in New Issue
Block a user