mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-26 08:30:01 +00:00
Improved extensions error handling. Various fixes.
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
parent
7a1a8ba615
commit
009d974d83
2
deps.edn
2
deps.edn
@ -11,7 +11,7 @@
|
||||
com.taoensso/timbre {:mvn/version "4.10.0"}
|
||||
hickory {:mvn/version "0.7.1"}
|
||||
com.cognitect/transit-cljs {:mvn/version "0.8.248"}
|
||||
status-im/pluto {:mvn/version "iteration-3"}
|
||||
status-im/pluto {:mvn/version "iteration-4-SNAPSHOT"}
|
||||
mvxcvi/alphabase {:mvn/version "1.0.0"}
|
||||
rasom/cljs-react-navigation {:mvn/version "0.1.4"}}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
[com.taoensso/timbre "4.10.0"]
|
||||
[hickory "0.7.1"]
|
||||
[com.cognitect/transit-cljs "0.8.248"]
|
||||
[status-im/pluto "iteration-3"]
|
||||
[status-im/pluto "iteration-4-SNAPSHOT"]
|
||||
[mvxcvi/alphabase "1.0.0"]
|
||||
[rasom/cljs-react-navigation "0.1.4"]]
|
||||
:plugins [[lein-cljsbuild "1.1.7"]
|
||||
|
@ -147,7 +147,7 @@
|
||||
(id [_] (name id))
|
||||
(scope [_] scope)
|
||||
(description [_] description)
|
||||
(parameters [_] parameters)
|
||||
(parameters [_] (or parameters []))
|
||||
(validate [_ _ _])
|
||||
(on-send [_ command-message _] (when on-send {:dispatch (on-send command-message)}))
|
||||
(on-receive [_ command-message _] (when on-receive {:dispatch (on-receive command-message)}))
|
||||
|
@ -65,23 +65,27 @@
|
||||
{:db (update-in db [:extensions-store :collectible] dissoc key)}))
|
||||
|
||||
(defn- json? [res]
|
||||
(string/starts-with? (get-in res [:headers "content-type"]) "application/json"))
|
||||
(when-let [type (get-in res [:headers "content-type"])]
|
||||
(string/starts-with? type "application/json")))
|
||||
|
||||
(defn- parse-json [o]
|
||||
(js->clj (js/JSON.parse o) :keywordize-keys true))
|
||||
(when o
|
||||
(js->clj (js/JSON.parse o) :keywordize-keys true)))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::json-parse
|
||||
(fn [value on-result] (re-frame/dispatch (on-result {:value (parse-json value)}))))
|
||||
(fn [{:keys [value on-result]}]
|
||||
(re-frame/dispatch (on-result {:value (parse-json value)}))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/json-parse
|
||||
(fn [_ [_ {:keys [value]}]]
|
||||
{::json-parse value}))
|
||||
(fn [_ [_ m]]
|
||||
{::json-parse m}))
|
||||
|
||||
(re-frame/reg-fx
|
||||
::json-stringify
|
||||
(fn [value on-result] (re-frame/dispatch (on-result {:value (js/JSON.stringify (clj->js value))}))))
|
||||
(fn [value on-result]
|
||||
(re-frame/dispatch (on-result {:value (js/JSON.stringify (clj->js value))}))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/json-stringify
|
||||
@ -93,8 +97,8 @@
|
||||
(fn [_ [_ {:keys [url on-success on-failure timeout]}]]
|
||||
{:http-raw-get (merge {:url url
|
||||
:success-event-creator
|
||||
(fn [o]
|
||||
(let [res (if (json? o) (update o :body parse-json o))]
|
||||
(fn [{:keys [body] :as o}]
|
||||
(let [res (if (json? body) (update o :body parse-json))]
|
||||
(on-success res)))}
|
||||
(when on-failure
|
||||
{:failure-event-creator on-failure})
|
||||
@ -106,9 +110,11 @@
|
||||
(fn [_ [_ {:keys [hash on-success on-failure]}]]
|
||||
{:http-raw-get (merge {:url (str "https://ipfs.infura.io/ipfs/" hash)
|
||||
:success-event-creator
|
||||
(fn [o]
|
||||
(let [res (if (json? o) (update o :body parse-json o))]
|
||||
(on-success res)))}
|
||||
(fn [{:keys [status body]}]
|
||||
(if (= 200 status)
|
||||
(on-success {:value body})
|
||||
(when on-failure
|
||||
(on-failure {:value status}))))}
|
||||
(when on-failure
|
||||
{:failure-event-creator on-failure})
|
||||
{:timeout-ms 5000})}))
|
||||
@ -117,10 +123,10 @@
|
||||
:http/post
|
||||
(fn [_ [_ {:keys [url body on-success on-failure timeout]}]]
|
||||
{:http-raw-post (merge {:url url
|
||||
:body body
|
||||
:body (clj->js body)
|
||||
:success-event-creator
|
||||
(fn [o]
|
||||
(let [res (if (json? o) (update o :body parse-json o))]
|
||||
(fn [{:keys [body] :as o}]
|
||||
(let [res (if (json? body) (update o :body parse-json))]
|
||||
(on-success res)))}
|
||||
(when on-failure
|
||||
{:failure-event-creator on-failure})
|
||||
@ -272,21 +278,18 @@
|
||||
:method :string
|
||||
:params? :vector
|
||||
:outputs? :vector
|
||||
:on-result? :event}}}
|
||||
:on-result :event}}}
|
||||
:hooks {:commands commands/command-hook}})
|
||||
|
||||
(defn read-extension [{:keys [value]}]
|
||||
(when (seq value)
|
||||
(let [{:keys [content]} (first value)]
|
||||
(reader/read content))))
|
||||
|
||||
(defn parse [{:keys [data]}]
|
||||
(try
|
||||
(let [{:keys [errors] :as extension-data} (reader/parse {:capacities capacities} data)]
|
||||
(when errors
|
||||
(println "Failed to parse status extensions" errors))
|
||||
extension-data)
|
||||
(catch :default e (println "EXC" e))))
|
||||
(reader/parse {:capacities capacities} data)
|
||||
(catch :default e {:errors [{:value (str e)}]})))
|
||||
|
||||
(defn parse-extension [{:keys [type value]}]
|
||||
(if (= type :success)
|
||||
(parse (reader/read (:content value)))
|
||||
{:errors [{:type type :value value}]}))
|
||||
|
||||
(def uri-prefix "https://get.status.im/extension/")
|
||||
|
||||
|
@ -64,10 +64,11 @@
|
||||
{:browser/call-rpc [{"jsonrpc" "2.0"
|
||||
"method" "eth_call"
|
||||
"params" [tx-object "latest"]}
|
||||
#(when on-result
|
||||
(let [result-str (when %2
|
||||
(get (js->clj %2) "result"))
|
||||
result (if (and outputs result-str)
|
||||
(abi-spec/decode (string/replace result-str #"0x" "") outputs)
|
||||
result-str)]
|
||||
(re-frame/dispatch (on-result {:error %1 :result result}))))]})))
|
||||
#(let [result-str (when %2
|
||||
(get (js->clj %2) "result"))
|
||||
result (cond
|
||||
(= "0x" result-str) nil
|
||||
(and outputs result-str)
|
||||
(abi-spec/decode (string/replace result-str #"0x" "") outputs)
|
||||
:else result-str)]
|
||||
(re-frame/dispatch (on-result (merge {:result result} (when %1 {:error %1})))))]})))
|
||||
|
@ -49,7 +49,7 @@
|
||||
http-get)
|
||||
|
||||
(defn- http-raw-get [{:keys [url success-event-creator failure-event-creator timeout-ms]}]
|
||||
(let [on-success #(re-frame/dispatch (success-event-creator %))
|
||||
(let [on-success #(when-let [event (success-event-creator %)] (re-frame/dispatch event))
|
||||
on-error (when failure-event-creator #(re-frame/dispatch (failure-event-creator %)))
|
||||
opts {:timeout-ms timeout-ms}]
|
||||
(http/raw-get url on-success on-error opts)))
|
||||
|
@ -10,7 +10,7 @@
|
||||
:extensions/load
|
||||
(fn [{:keys [extensions follow-up]}]
|
||||
(doseq [{:keys [url active?]} extensions]
|
||||
(extensions/load-from url #(re-frame/dispatch [follow-up (-> % extensions/read-extension extensions/parse) active?])))))
|
||||
(extensions/load-from url #(re-frame/dispatch [follow-up (extensions/parse-extension %) active?])))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:extensions/stage
|
||||
@ -29,4 +29,4 @@
|
||||
(fn [cofx [_ extensions]]
|
||||
(apply fx/merge cofx (map (fn [{:keys [id]}]
|
||||
(partial registry/deactivate id))
|
||||
extensions))))
|
||||
extensions))))
|
||||
|
@ -1,6 +1,7 @@
|
||||
(ns status-im.ui.screens.extensions.add.views
|
||||
(:require-macros [status-im.utils.views :as views])
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[reagent.core :as reagent]
|
||||
[clojure.string :as string]
|
||||
[status-im.extensions.core :as extensions]
|
||||
[status-im.i18n :as i18n]
|
||||
@ -76,7 +77,8 @@
|
||||
[react/view {:flex 1}
|
||||
[toolbar/simple-toolbar (i18n/label :t/extension)]
|
||||
[react/view {:style {:flex 1 :justify-content :center :align-items :center}}
|
||||
[react/text (i18n/label :t/invalid-extension)]]]])))
|
||||
[react/text (i18n/label :t/invalid-extension)]
|
||||
[react/text (str errors)]]]])))
|
||||
|
||||
(def qr-code
|
||||
[react/touchable-highlight {:on-press #(re-frame/dispatch [:qr-scanner.ui/scan-qr-code-pressed
|
||||
@ -88,7 +90,8 @@
|
||||
|
||||
(views/defview edit-extension []
|
||||
(views/letsubs [manage-extension [:get-manage-extension]]
|
||||
(let [url (get-in manage-extension [:url :value])]
|
||||
(let [url (get-in manage-extension [:url :value])
|
||||
pressed (reagent/atom false)]
|
||||
[react/view styles/screen
|
||||
[status-bar/status-bar]
|
||||
[react/keyboard-avoiding-view components.styles/flex
|
||||
@ -108,5 +111,5 @@
|
||||
[components.common/bottom-button
|
||||
{:forward? true
|
||||
:label (i18n/label :t/find)
|
||||
:disabled? (not (extensions/valid-uri? url))
|
||||
:on-press #(re-frame/dispatch [:extensions.ui/show-button-pressed (string/trim url)])}]]]])))
|
||||
:disabled? (and (not @pressed) (not (extensions/valid-uri? url)))
|
||||
:on-press #(do (reset! pressed true) (re-frame/dispatch [:extensions.ui/show-button-pressed (string/trim url)]))}]]]])))
|
||||
|
Loading…
x
Reference in New Issue
Block a user