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