From 683e6b5ed07891eedafe6193ac3a30a5b7602e46 Mon Sep 17 00:00:00 2001 From: Julien Eluard Date: Wed, 29 Aug 2018 10:10:44 +0200 Subject: [PATCH] [Fixes #5496] Added SuperRare NFT support Signed-off-by: Julien Eluard --- resources/images/tokens/mainnet/SUPR.png | Bin 0 -> 1720 bytes resources/images/tokens/testnet/SUPR.png | Bin 0 -> 1720 bytes src/status_im/translations/en.cljs | 2 + src/status_im/ui/screens/events.cljs | 13 ++++++ .../screens/wallet/collectibles/events.cljs | 12 +++-- .../ui/screens/wallet/collectibles/subs.cljs | 3 +- .../wallet/collectibles/superrare/events.cljs | 41 ++++++++++++++++++ .../wallet/collectibles/superrare/views.cljs | 27 ++++++++++++ .../ui/screens/wallet/collectibles/views.cljs | 14 ++++-- .../ui/screens/wallet/main/views.cljs | 3 +- src/status_im/utils/ethereum/core.cljs | 4 ++ src/status_im/utils/ethereum/tokens.cljs | 6 ++- src/status_im/utils/http.cljs | 20 ++++++++- 13 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 resources/images/tokens/mainnet/SUPR.png create mode 100644 resources/images/tokens/testnet/SUPR.png create mode 100644 src/status_im/ui/screens/wallet/collectibles/superrare/events.cljs create mode 100644 src/status_im/ui/screens/wallet/collectibles/superrare/views.cljs diff --git a/resources/images/tokens/mainnet/SUPR.png b/resources/images/tokens/mainnet/SUPR.png new file mode 100644 index 0000000000000000000000000000000000000000..9838f1b0096722d33968f3bd169a537bebbb65b2 GIT binary patch literal 1720 zcmV;p21ogcP)QGxPTFDnL~5=wQO`?Lr3$ySD=>NT>j)AfbXl1ql^E2hLOwSiV(8$AiE)*1sG( zKj-^S5{M;B$5+z5lI(m#vpAIONFGU^NQ!r&@UHMGIWN5blAKAty#H?}K*7!=ZzVIy zWg;@K(R<#9*g|w9Cz1=K6U{^==0<~-Fu?jm(^+N@tKC7X(FWnFgdAW4&_~+7tuBjf z9faf*?G>)f30l;wFVL>$>PnWmhX%pE?gpDDT$wj$07CK^n=4wG&s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!9*=Q%clRZ~(P;FM#sr>^I6697IiBZWSsouB@$m3~ z1Yn{6uKI%gp0`=c$}ewjZkELD?QQ$~0I-TbEMhG}5i+30!9^XUL z+5{wN*}ekW($Pvyt;NEX!Nj}y%0BC(Ff3@u1t?mU?4Pv9%6>ISKni5CUe{KmVYevY z*thaUux|?~L{S(vE8TJI*Fpp&O--5NMpz;D_u%`xfIr~@jQ!drhs&@ zwBOO{BfAd47w>fsn}cezO5dv5QDr4QqcG29LgEp4N&&~d30a{K zKgvbOstWqLF{X3SLL;M(B1eowc(lTbE6w}?`-y;ONfyZUJfMpLHxW4QYVGhpIT2&Si z5^ollN10yNpW0@AY*u7*=mW#N71f=$^y-?FNrWn@u+KIa*_xp#jwb2&+u-S7k5GY5 ztbj^Hm#KVCEfEZ_OyY5B$_2J_+O~%f6xvY(?K-YgGcLL@6o3{$7A=LJDN?aeY~oC- zjyF}hxa-RmCM$B8Md$YpgGyEuth_&P2#042u;VAIoK<$nYI7yu)t)`&G}BE{`v*-Z zZ_soF^VKb5y5?ze!trMVzIL?p8ccSO8A{8*-%A4W(&@d=J!pAz+d;HKD!mC7v2N>g zMjt@a1#TOA@Wd2ow7_lR%9dUi2json {: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}}) diff --git a/src/status_im/ui/screens/wallet/collectibles/superrare/views.cljs b/src/status_im/ui/screens/wallet/collectibles/superrare/views.cljs new file mode 100644 index 0000000000..bee9c5b454 --- /dev/null +++ b/src/status_im/ui/screens/wallet/collectibles/superrare/views.cljs @@ -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)])}]]) diff --git a/src/status_im/ui/screens/wallet/collectibles/views.cljs b/src/status_im/ui/screens/wallet/collectibles/views.cljs index f978ff7c3e..3ffa3653af 100644 --- a/src/status_im/ui/screens/wallet/collectibles/views.cljs +++ b/src/status_im/ui/screens/wallet/collectibles/views.cljs @@ -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}]])]])) \ No newline at end of file + [react/text (i18n/label :t/error)]])]])) + diff --git a/src/status_im/ui/screens/wallet/main/views.cljs b/src/status_im/ui/screens/wallet/main/views.cljs index 6590e61af0..4b0e8a72e8 100644 --- a/src/status_im/ui/screens/wallet/main/views.cljs +++ b/src/status_im/ui/screens/wallet/main/views.cljs @@ -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] @@ -198,4 +199,4 @@ (views/letsubs [{:keys [wallet-set-up-passed?]} [:get-current-account]] (if (not wallet-set-up-passed?) [onboarding.views/onboarding] - [wallet-root false]))) \ No newline at end of file + [wallet-root false]))) diff --git a/src/status_im/utils/ethereum/core.cljs b/src/status_im/utils/ethereum/core.cljs index b44da489ff..b739d1661a 100644 --- a/src/status_im/utils/ethereum/core.cljs +++ b/src/status_im/utils/ethereum/core.cljs @@ -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))) diff --git a/src/status_im/utils/ethereum/tokens.cljs b/src/status_im/utils/ethereum/tokens.cljs index 51b14c8682..fad684bbb7 100644 --- a/src/status_im/utils/ethereum/tokens.cljs +++ b/src/status_im/utils/ethereum/tokens.cljs @@ -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" diff --git a/src/status_im/utils/http.cljs b/src/status_im/utils/http.cljs index 77273ae509..712f1444e9 100644 --- a/src/status_im/utils/http.cljs +++ b/src/status_im/utils/http.cljs @@ -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))))))))