[#9550] Improve stickers usage experience

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2019-11-30 11:29:25 +01:00
parent 7bf626c3a3
commit 6facfe3938
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
4 changed files with 54 additions and 47 deletions

View File

@ -1374,8 +1374,8 @@
(handlers/register-handler-fx
:stickers/load-sticker-pack-success
(fn [cofx [_ edn-string id price open?]]
(stickers/load-sticker-pack-success cofx edn-string id price open?)))
(fn [cofx [_ edn-string id price]]
(stickers/load-sticker-pack-success cofx edn-string id price)))
(handlers/register-handler-fx
:stickers/install-pack
@ -1389,8 +1389,8 @@
(handlers/register-handler-fx
:stickers/load-pack
(fn [cofx [_ url id price open?]]
(stickers/load-pack cofx url id price open?)))
(fn [cofx [_ url id price]]
(stickers/load-pack cofx url id price)))
(handlers/register-handler-fx
:stickers/select-pack

View File

@ -15,10 +15,10 @@
[clojure.string :as string]))
(defn pack-data-callback
[id open?]
[id]
(fn [[category owner mintable timestamp price contenthash]]
(when-let [url (contenthash/url contenthash)]
(re-frame/dispatch [:stickers/load-pack url id price open?]))))
(re-frame/dispatch [:stickers/load-pack url id price]))))
(re-frame/reg-fx
:stickers/set-pending-timout-fx
@ -27,7 +27,7 @@
10000)))
(defn eth-call-pack-data
[contract id open?]
[contract id]
(json-rpc/eth-call
{:contract contract
;; Returns vector of pack data parameters by pack id:
@ -35,12 +35,12 @@
:method "getPackData(uint256)"
:params [id]
:outputs ["bytes4[]" "address" "bool" "uint256" "uint256" "bytes"]
:on-success (pack-data-callback id open?)}))
:on-success (pack-data-callback id)}))
(re-frame/reg-fx
:stickers/pack-data-fx
(fn [[contract id]]
(eth-call-pack-data contract id true)))
(eth-call-pack-data contract id)))
(re-frame/reg-fx
:stickers/load-packs-fx
@ -53,7 +53,7 @@
:on-success
(fn [[count]]
(dotimes [id count]
(eth-call-pack-data contract id false)))})))
(eth-call-pack-data contract id)))})))
(re-frame/reg-fx
:stickers/owned-packs-fx
@ -108,16 +108,14 @@
(contains? sticker :hash))
(fx/defn load-sticker-pack-success
[{:keys [db] :as cofx} edn-string id price open?]
[{:keys [db] :as cofx} edn-string id price]
(let [{:keys [stickers] :as pack} (assoc (get (edn/read-string edn-string) 'meta)
:id id :price price)]
(fx/merge cofx
{:db (cond-> db
(and (seq stickers)
(every? valid-sticker? stickers))
(assoc-in [:stickers/packs id] pack))}
#(when open?
(navigation/navigate-to-cofx % :stickers-pack-modal pack)))))
(assoc-in [:stickers/packs id] pack))})))
(fx/defn open-sticker-pack
[{{:stickers/keys [packs packs-installed] :networks/keys [current-network] :as db} :db :as cofx} id]
@ -125,17 +123,17 @@
(let [pack (or (get packs-installed id)
(get packs id))
contract-address (contracts/get-address db :status/stickers)]
(if pack
(navigation/navigate-to-cofx cofx :stickers-pack-modal pack)
(when contract-address
{:stickers/pack-data-fx [contract-address id]})))))
(fx/merge cofx
(navigation/navigate-to-cofx :stickers-pack-modal {:id id})
#(when (and contract-address (not pack))
{:stickers/pack-data-fx [contract-address id]})))))
(fx/defn load-pack
[cofx url id price open?]
[cofx url id price]
{:http-get {:url url
:success-event-creator
(fn [o]
[:stickers/load-sticker-pack-success o id price open?])}})
[:stickers/load-sticker-pack-success o id price])}})
(fx/defn load-packs
[{:keys [db]}]

View File

@ -43,8 +43,8 @@
(zero? price) (i18n/label :t/free)
:else (str (money/wei-> :eth price)))])]])))
(defn pack-badge [{:keys [name author price thumbnail preview id installed owned pending] :as pack}]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:navigate-to :stickers-pack pack])}
(defn pack-badge [{:keys [name author price thumbnail preview id installed owned pending]}]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:navigate-to :stickers-pack {:id id}])}
[react/view {:margin-bottom 27}
[react/image {:style {:height 200 :border-radius 20} :source {:uri (contenthash/url preview)}}]
[react/view {:height 64 :align-items :center :flex-direction :row}
@ -62,34 +62,43 @@
[react/view styles/screen
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar (i18n/label :t/sticker-market)]
[react/scroll-view {:keyboard-should-persist-taps :handled :style {:padding 16}}
[react/view
(for [pack packs]
^{:key pack}
[pack-badge pack])]]]]))
(if (seq packs)
[react/scroll-view {:keyboard-should-persist-taps :handled :style {:padding 16}}
[react/view
(for [pack packs]
^{:key pack}
[pack-badge pack])]]
[react/view {:flex 1 :align-items :center :justify-content :center}
[react/activity-indicator {:animating true}]])]]))
(def sticker-icon-size 60)
(defview pack-main [modal?]
(letsubs [{:keys [id name author price thumbnail stickers installed owned pending]} [:stickers/get-current-pack]]
[react/view styles/screen
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar nil modal?]
[react/view {:height 74 :align-items :center :flex-direction :row :padding-horizontal 16}
[thumbnail-icon (contenthash/url thumbnail) 64]
[react/view {:padding-horizontal 16 :flex 1}
[react/text {:style {:typography :header}} name]
[react/text {:style {:color colors/gray :margin-top 6}} author]]
(if installed
[installed-icon]
[price-badge price id owned pending])]
[react/view {:style {:padding-top 8 :flex 1}}
[react/scroll-view {:keyboard-should-persist-taps :handled :style {:flex 1}}
[react/view {:flex-direction :row :flex-wrap :wrap}
(for [{:keys [hash]} stickers]
^{:key hash}
[react/image {:style (styles/sticker-image sticker-icon-size)
:source {:uri (contenthash/url hash)}}])]]]]]))
(letsubs [{:keys [id name author price thumbnail
stickers installed owned pending]
:as pack}
[:stickers/get-current-pack]]
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar nil modal?]
(if pack
[react/view {:flex 1}
[react/view {:height 74 :align-items :center :flex-direction :row :padding-horizontal 16}
[thumbnail-icon (contenthash/url thumbnail) 64]
[react/view {:padding-horizontal 16 :flex 1}
[react/text {:style {:typography :header}} name]
[react/text {:style {:color colors/gray :margin-top 6}} author]]
(if installed
[installed-icon]
[price-badge price id owned pending])]
[react/view {:style {:padding-top 8 :flex 1}}
[react/scroll-view {:keyboard-should-persist-taps :handled :style {:flex 1}}
[react/view {:flex-direction :row :flex-wrap :wrap}
(for [{:keys [hash]} stickers]
^{:key hash}
[react/image {:style (styles/sticker-image sticker-icon-size)
:source {:uri (contenthash/url hash)}}])]]]]
[react/view {:flex 1 :align-items :center :justify-content :center}
[react/activity-indicator {:animating true}]])]))
(defview pack []
[pack-main false])

View File

@ -58,7 +58,7 @@
(defn url [hex]
(let [{:keys [namespace hash]} (decode (ethereum/normalized-hex hex))]
(case namespace
:ipfs (str "https://ipfs.infura.io/ipfs/" hash)
:ipfs (str "https://cloudflare-ipfs.com/ipfs/" hash)
"")))
(fx/defn cat