beta provider support

This commit is contained in:
Andrey Shovkoplyas 2019-01-10 11:48:35 +01:00
parent 7c5a7e25af
commit 24aba00f23
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
4 changed files with 23 additions and 8 deletions

View File

@ -27,6 +27,8 @@
[tab-button "ETH" :eth tab-view]
[tab-button "Version" :version tab-view]
[tab-button "Status API" :api tab-view]
(when js/ethereumBeta
[tab-button "Beta Provider" :beta tab-view])
[tab-button "About" :about tab-view]]
[react/view {:style {:height 1 :margin-top 10 :background-color "#4360df33"}}]])

View File

@ -2,6 +2,13 @@
(:require [re-frame.core :as re-frame]))
(def web3 (or (when (exists? js/web3) js/web3)
(when js/ethereumBeta
(js/setTimeout (fn []
(.then (.send js/ethereumBeta "eth_requestAccounts") #(re-frame/dispatch [:set-default-account]))
(when js/ethereumBeta
(.then (.getContactCode js/ethereumBeta.status) #(re-frame/dispatch [:on-status-api :contact %]))))
100)
(js/Web3. js/ethereumBeta))
(when js/ethereum
(js/setTimeout (fn []
(.then (.enable js/ethereum) #(re-frame/dispatch [:set-default-account]))

View File

@ -110,14 +110,16 @@
(fn [{{:keys [web3] :as db} :db} _]
(println "WEB3" web3)
(when web3
{:db (update db :web3-async-data
assoc
:api (.-api (.-version web3))
:network (.-network (.-version web3))
:accounts (.-accounts (.-eth web3))
:default-account (.-defaultAccount (.-eth web3))
:coinbase (.-coinbase (.-eth web3))
:default-block (.-defaultBlock (.-eth web3)))
{:db (if js/window.ethereumBeta
db
(update db :web3-async-data
assoc
:api (.-api (.-version web3))
:network (.-network (.-version web3))
:accounts (.-accounts (.-eth web3))
:default-account (.-defaultAccount (.-eth web3))
:coinbase (.-coinbase (.-eth web3))
:default-block (.-defaultBlock (.-eth web3))))
:web3-node-fx web3
:web3-coinbase-fx web3
:web3-ethereum-fx web3

View File

@ -137,6 +137,10 @@
(when gas-price
[ui/label "gasPrice" (str (.toString gas-price 10) " wei")])])
(when (= :beta tab-view)
[react/view
[ui/button "Subscribe logs"
(fn [] (.send js/window.ethereumBeta "eth_subscribe" (clj->js ["syncing" {}])))]])
(when (= :api tab-view)
[react/view
(when (exists? js/window.ethereum.status)