parent
51b388cce3
commit
5ffeacadbf
|
@ -229,3 +229,8 @@
|
||||||
(def ^:const web3-send-async-callback "web3-send-async-callback")
|
(def ^:const web3-send-async-callback "web3-send-async-callback")
|
||||||
(def ^:const scan-qr-code "scan-qr-code")
|
(def ^:const scan-qr-code "scan-qr-code")
|
||||||
(def ^:const scan-qr-code-callback "scan-qr-code-callback")
|
(def ^:const scan-qr-code-callback "scan-qr-code-callback")
|
||||||
|
|
||||||
|
;;ipfs
|
||||||
|
(def ^:const ipfs-add-url "https://ipfs.infura.io:5001/api/v0/add")
|
||||||
|
(def ^:const ipfs-add-param-name "extension.event.edn")
|
||||||
|
(def ^:const ipfs-cat-url "https://ipfs.infura.io/ipfs/")
|
|
@ -13,6 +13,7 @@
|
||||||
[status-im.ui.screens.wallet.settings.views :as settings]
|
[status-im.ui.screens.wallet.settings.views :as settings]
|
||||||
[status-im.i18n :as i18n]
|
[status-im.i18n :as i18n]
|
||||||
[status-im.utils.money :as money]
|
[status-im.utils.money :as money]
|
||||||
|
[status-im.constants :as constants]
|
||||||
[status-im.ui.components.colors :as colors]
|
[status-im.ui.components.colors :as colors]
|
||||||
[status-im.ui.screens.navigation :as navigation]
|
[status-im.ui.screens.navigation :as navigation]
|
||||||
[status-im.utils.handlers :as handlers]
|
[status-im.utils.handlers :as handlers]
|
||||||
|
@ -196,7 +197,7 @@
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
:ipfs/cat
|
:ipfs/cat
|
||||||
(fn [_ [_ _ {:keys [hash on-success on-failure]}]]
|
(fn [_ [_ _ {:keys [hash on-success on-failure]}]]
|
||||||
{:http-raw-get (merge {:url (str "https://ipfs.infura.io/ipfs/" hash)
|
{:http-raw-get (merge {:url (str constants/ipfs-cat-url hash)
|
||||||
:success-event-creator
|
:success-event-creator
|
||||||
(fn [{:keys [status body]}]
|
(fn [{:keys [status body]}]
|
||||||
(if (= 200 status)
|
(if (= 200 status)
|
||||||
|
@ -207,6 +208,30 @@
|
||||||
{:failure-event-creator on-failure})
|
{:failure-event-creator on-failure})
|
||||||
{:timeout-ms 5000})}))
|
{:timeout-ms 5000})}))
|
||||||
|
|
||||||
|
(defn- parse-ipfs-add-response [res]
|
||||||
|
(let [{:keys [Name Hash Size]} (parse-json res)]
|
||||||
|
{:name Name
|
||||||
|
:hash Hash
|
||||||
|
:size Size}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
:ipfs/add
|
||||||
|
(fn [_ [_ _ {:keys [value on-success on-failure]}]]
|
||||||
|
(let [formdata (doto
|
||||||
|
(js/FormData.)
|
||||||
|
(.append constants/ipfs-add-param-name value))]
|
||||||
|
{:http-raw-post (merge {:url constants/ipfs-add-url
|
||||||
|
:body formdata
|
||||||
|
:success-event-creator
|
||||||
|
(fn [{:keys [status body]}]
|
||||||
|
(if (= 200 status)
|
||||||
|
(on-success {:value (parse-ipfs-add-response body)})
|
||||||
|
(when on-failure
|
||||||
|
(on-failure {:value status}))))}
|
||||||
|
(when on-failure
|
||||||
|
{:failure-event-creator on-failure})
|
||||||
|
{:timeout-ms 5000})})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
:http/post
|
:http/post
|
||||||
(fn [_ [_ _ {:keys [url body on-success on-failure timeout]}]]
|
(fn [_ [_ _ {:keys [url body on-success on-failure timeout]}]]
|
||||||
|
@ -458,6 +483,12 @@
|
||||||
:arguments {:hash :string
|
:arguments {:hash :string
|
||||||
:on-success :event
|
:on-success :event
|
||||||
:on-failure? :event}}
|
:on-failure? :event}}
|
||||||
|
'ipfs/add
|
||||||
|
{:permissions [:read]
|
||||||
|
:value :ipfs/add
|
||||||
|
:arguments {:value :string
|
||||||
|
:on-success :event
|
||||||
|
:on-failure? :event}}
|
||||||
'ethereum/transaction-receipt
|
'ethereum/transaction-receipt
|
||||||
{:permissions [:read]
|
{:permissions [:read]
|
||||||
:value :extensions/ethereum-transaction-receipt
|
:value :extensions/ethereum-transaction-receipt
|
||||||
|
|
|
@ -77,6 +77,18 @@
|
||||||
:http-post
|
:http-post
|
||||||
http-post)
|
http-post)
|
||||||
|
|
||||||
|
(defn- http-raw-post [{:keys [url body response-validator success-event-creator failure-event-creator timeout-ms opts]}]
|
||||||
|
(let [on-success #(re-frame/dispatch (success-event-creator %))
|
||||||
|
on-error #(re-frame/dispatch (failure-event-creator %))
|
||||||
|
all-opts (assoc opts
|
||||||
|
:valid-response? response-validator
|
||||||
|
:timeout-ms timeout-ms)]
|
||||||
|
(http/raw-post url body on-success on-error all-opts)))
|
||||||
|
|
||||||
|
(re-frame/reg-fx
|
||||||
|
:http-raw-post
|
||||||
|
http-raw-post)
|
||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:request-permissions-fx
|
:request-permissions-fx
|
||||||
(fn [options]
|
(fn [options]
|
||||||
|
|
Loading…
Reference in New Issue