Fixed broken extensions HTTP events

Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
This commit is contained in:
Julien Eluard 2018-11-23 08:43:22 +01:00
parent 6ca3933b71
commit 6f08a9fe7f
No known key found for this signature in database
GPG Key ID: 6FD7DB5437FCBEF6
2 changed files with 22 additions and 23 deletions

View File

@ -93,14 +93,15 @@
(fn [_ [_ _ {:keys [value]}]]
{::json-stringify value}))
(defn- parse-result [o on-success]
(let [res (if (json? o) (update o :body parse-json) o)]
(on-success res)))
(re-frame/reg-event-fx
:http/get
(fn [_ [_ _ {:keys [url on-success on-failure timeout]}]]
{:http-raw-get (merge {:url url
:success-event-creator
(fn [{:keys [body] :as o}]
(let [res (if (json? body) (update o :body parse-json))]
(on-success res)))}
:success-event-creator #(parse-result % on-success)}
(when on-failure
{:failure-event-creator on-failure})
(when timeout
@ -125,10 +126,7 @@
(fn [_ [_ _ {:keys [url body on-success on-failure timeout]}]]
{:http-raw-post (merge {:url url
:body (clj->js body)
:success-event-creator
(fn [{:keys [body] :as o}]
(let [res (if (json? body) (update o :body parse-json))]
(on-success res)))}
:success-event-creator #(parse-result % on-success)}
(when on-failure
{:failure-event-creator on-failure})
(when timeout
@ -167,8 +165,9 @@
(fn [_ [_ _ m]]
{::arithmetic m}))
(defn button [{:keys [on-click]} label]
[button/secondary-button (when on-click {:on-press #(re-frame/dispatch (on-click {}))}) label])
(defn button [{:keys [on-click disabled]} label]
[button/secondary-button (merge {:disabled? disabled}
(when on-click {:on-press #(re-frame/dispatch (on-click {}))})) label])
(defn input [{:keys [on-change placeholder]}]
[react/text-input (merge {:placeholder placeholder
@ -218,7 +217,7 @@
'touchable-opacity {:value touchable-opacity :properties {:on-press :event}}
'image {:value image :properties {:uri :string}}
'input {:value input :properties {:on-change :event :placeholder :string}}
'button {:value button :properties {:on-click :event}}
'button {:value button :properties {:disabled :boolean :on-click :event}}
'link {:value link :properties {:uri :string}}
;'list {:value list :properties {:data :vector :item-view :view}}
'checkbox {:value checkbox :properties {:on-change :event :checked :boolean}}
@ -273,7 +272,7 @@
:arguments {:key :string :value :map}}
'store/clear
{:permissions [:read]
:value :store/put
:value :store/clear
:arguments {:key :string}}
'http/get
{:permissions [:read]

View File

@ -1,8 +1,7 @@
(ns status-im.utils.ethereum.abi-spec
(:require [cljs.spec.alpha :as spec]
[clojure.string :as string]
[status-im.js-dependencies :as dependencies]
[clojure.string :as str]))
[status-im.js-dependencies :as dependencies]))
;; Utility functions for encoding
@ -44,7 +43,8 @@
(.sha3 utils (str s)))
(defn is-hex? [value]
(string/starts-with? value "0x"))
(when value
(string/starts-with? value "0x")))
;; Encoder for parsed abi spec
@ -71,7 +71,7 @@
;; address: as in the uint160 case
(defmethod enc :address
[{:keys [value]}]
(when value
(when (string? value)
(left-pad (string/replace value "0x" ""))))
;; bytes, of length k (which is assumed to be of type uint256):
@ -330,10 +330,10 @@
(defn dyn-hex-to-value [hex type]
(cond
(str/starts-with? type "bytes")
(string/starts-with? type "bytes")
(str "0x" (hex-to-bytes hex))
(str/starts-with? type "string")
(string/starts-with? type "string")
(hex-to-utf8 (hex-to-bytes hex))))
(defn hex-to-bytesM [hex type]
@ -343,10 +343,10 @@
(defn hex-to-value [hex type]
(cond
(= "bool" type) (= hex "0000000000000000000000000000000000000000000000000000000000000001")
(str/starts-with? type "uint") (hex-to-number hex)
(str/starts-with? type "int") (hex-to-number hex)
(str/starts-with? type "address") (str "0x" (subs hex (- (count hex) 40)))
(str/starts-with? type "bytes") (hex-to-bytesM hex type)))
(string/starts-with? type "uint") (hex-to-number hex)
(string/starts-with? type "int") (hex-to-number hex)
(string/starts-with? type "address") (str "0x" (subs hex (- (count hex) 40)))
(string/starts-with? type "bytes") (hex-to-bytesM hex type)))
(defn dec-type [bytes]
(fn [offset type]
@ -369,7 +369,7 @@
(recur (conj res ((dec-type bytes) (+ arr-start i) nname)) (+ i rnstatpartlen)))))
(or (re-matches #"^bytes(\[([0-9]*)\])*$" type)
(str/starts-with? type "string"))
(string/starts-with? type "string"))
(let [dyn-off (js/parseInt (str "0x" (substr bytes (* offset 2) 64)))
len (js/parseInt (str "0x" (substr bytes (* dyn-off 2) 64)))