Handle clients with no web3 correctly
* fix issues with clients that have no wallet connected Fixes: #92
This commit is contained in:
parent
05f1a711c1
commit
667b3919c4
|
@ -210,6 +210,7 @@
|
||||||
|
|
||||||
(defn init! []
|
(defn init! []
|
||||||
(rf/dispatch-sync [:initialize-db])
|
(rf/dispatch-sync [:initialize-db])
|
||||||
|
(rf/dispatch [:initialize-web3])
|
||||||
(when config/debug?
|
(when config/debug?
|
||||||
(enable-re-frisk!))
|
(enable-re-frisk!))
|
||||||
(load-interceptors!)
|
(load-interceptors!)
|
||||||
|
|
|
@ -43,24 +43,19 @@
|
||||||
:initialize-db
|
:initialize-db
|
||||||
[(inject-cofx :store)]
|
[(inject-cofx :store)]
|
||||||
(fn [{:keys [db store]} [_]]
|
(fn [{:keys [db store]} [_]]
|
||||||
(let [injected-web3 (-> js/window .-web3)
|
{:db (merge db/default-db store)}))
|
||||||
injected-web3-ctor (aget js/window "Web3")
|
|
||||||
Web3 (if (boolean injected-web3)
|
|
||||||
(if (boolean injected-web3-ctor)
|
(reg-event-fx
|
||||||
(do
|
:initialize-web3
|
||||||
(println "Using injected Web3 constructor with current provider")
|
(fn [{:keys [db]} [_]]
|
||||||
(new injected-web3-ctor (web3/current-provider injected-web3))) ;; mist >= 0.9.0, metamask
|
(let [injected-web3 (-> js/window .-web3)
|
||||||
(do
|
w3 (when (boolean injected-web3)
|
||||||
(println "Using injected web3")
|
|
||||||
injected-web3) ;; older mist
|
|
||||||
)
|
|
||||||
(do
|
(do
|
||||||
(println "Falling back to default web3 HTTP URL")
|
(println "Using injected Web3 constructor with current provider")
|
||||||
;; TODO: put RPC URL in db
|
(new (aget js/window "web3" "constructor") (web3/current-provider injected-web3))))]
|
||||||
(web3/create-web3 "http://localhost:8545")))]
|
(println "web3" w3)
|
||||||
{:db (-> db/default-db
|
{:db (merge db {:web3 w3})})))
|
||||||
(merge store)
|
|
||||||
(merge {:web3 Web3}))})))
|
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:assoc-in
|
:assoc-in
|
||||||
|
@ -357,8 +352,9 @@
|
||||||
(when payout-hash
|
(when payout-hash
|
||||||
(dispatch [:save-payout-hash issue-id payout-hash]))))
|
(dispatch [:save-payout-hash issue-id payout-hash]))))
|
||||||
|
|
||||||
(defn sig->method-id [sig]
|
(defn sig->method-id [w3 sig]
|
||||||
(let [sha3 web3/sha3]
|
(println "sig->method-id" w3 sig)
|
||||||
|
(let [sha3 (fn [x] (web3/sha3 w3 x))]
|
||||||
(apply str (take 10 (sha3 sig)))))
|
(apply str (take 10 (sha3 sig)))))
|
||||||
|
|
||||||
(defn strip-0x [x]
|
(defn strip-0x [x]
|
||||||
|
@ -370,8 +366,9 @@
|
||||||
owner-address :owner_address
|
owner-address :owner_address
|
||||||
contract-address :contract_address
|
contract-address :contract_address
|
||||||
confirm-hash :confirm_hash} issue]]
|
confirm-hash :confirm_hash} issue]]
|
||||||
(let [Web3 (:web3 db)
|
(println (:web3 db))
|
||||||
confirm-method-id (sig->method-id "confirmTransaction(uint256)")
|
(let [w3 (:web3 db)
|
||||||
|
confirm-method-id (sig->method-id w3 "confirmTransaction(uint256)")
|
||||||
confirm-id (strip-0x confirm-hash)
|
confirm-id (strip-0x confirm-hash)
|
||||||
data (str confirm-method-id
|
data (str confirm-method-id
|
||||||
confirm-id)
|
confirm-id)
|
||||||
|
@ -383,7 +380,7 @@
|
||||||
:data data}]
|
:data data}]
|
||||||
(println "data:" data)
|
(println "data:" data)
|
||||||
(try
|
(try
|
||||||
(web3-eth/send-transaction! Web3 payload
|
(web3-eth/send-transaction! w3 payload
|
||||||
(send-transaction-callback issue-id))
|
(send-transaction-callback issue-id))
|
||||||
{:db (assoc-in db [:owner-bounties issue-id :confirming?] true)}
|
{:db (assoc-in db [:owner-bounties issue-id :confirming?] true)}
|
||||||
(catch js/Error e
|
(catch js/Error e
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
|
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
|
||||||
(fn []
|
(fn []
|
||||||
(let [web3 (:web3 @db)
|
(let [web3 (:web3 @db)
|
||||||
web3-accounts (web3-eth/accounts web3)]
|
web3-accounts (when web3
|
||||||
|
(web3-eth/accounts web3))]
|
||||||
(println "web3-accounts" web3-accounts)
|
(println "web3-accounts" web3-accounts)
|
||||||
[:div.ui.container.grid
|
[:div.ui.container.grid
|
||||||
[:div.ui.form.sixteen.wide.column
|
[:div.ui.form.sixteen.wide.column
|
||||||
|
|
Loading…
Reference in New Issue