[#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 (handlers/register-handler-fx
:stickers/load-sticker-pack-success :stickers/load-sticker-pack-success
(fn [cofx [_ edn-string id price open?]] (fn [cofx [_ edn-string id price]]
(stickers/load-sticker-pack-success cofx edn-string id price open?))) (stickers/load-sticker-pack-success cofx edn-string id price)))
(handlers/register-handler-fx (handlers/register-handler-fx
:stickers/install-pack :stickers/install-pack
@ -1389,8 +1389,8 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:stickers/load-pack :stickers/load-pack
(fn [cofx [_ url id price open?]] (fn [cofx [_ url id price]]
(stickers/load-pack cofx url id price open?))) (stickers/load-pack cofx url id price)))
(handlers/register-handler-fx (handlers/register-handler-fx
:stickers/select-pack :stickers/select-pack

View File

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

View File

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

View File

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