Use web3 via cljs-web3
* take cljs-web3 to use and no longer rely on window/web3 injected by wallet
This commit is contained in:
parent
1139e01835
commit
fff720ad71
|
@ -49,7 +49,8 @@
|
||||||
[com.andrewmcveigh/cljs-time "0.5.1"]
|
[com.andrewmcveigh/cljs-time "0.5.1"]
|
||||||
[akiroz.re-frame/storage "0.1.2"]
|
[akiroz.re-frame/storage "0.1.2"]
|
||||||
[cljsjs/chartjs "2.6.0-0"]
|
[cljsjs/chartjs "2.6.0-0"]
|
||||||
[org.web3j/core "2.3.0"]]
|
[org.web3j/core "2.3.0"]
|
||||||
|
[cljs-web3 "0.19.0-0-2"]]
|
||||||
|
|
||||||
:min-lein-version "2.0.0"
|
:min-lein-version "2.0.0"
|
||||||
:source-paths ["src/clj" "src/cljc"]
|
:source-paths ["src/clj" "src/cljc"]
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
inject-cofx]]
|
inject-cofx]]
|
||||||
[ajax.core :refer [GET POST]]
|
[ajax.core :refer [GET POST]]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
|
[cljs-web3.core :as web3]
|
||||||
|
[cljs-web3.eth :as web3-eth]
|
||||||
[akiroz.re-frame.storage
|
[akiroz.re-frame.storage
|
||||||
:as rf-storage
|
:as rf-storage
|
||||||
:refer [reg-co-fx!]]))
|
:refer [reg-co-fx!]]))
|
||||||
|
@ -41,7 +43,15 @@
|
||||||
:initialize-db
|
:initialize-db
|
||||||
[(inject-cofx :store)]
|
[(inject-cofx :store)]
|
||||||
(fn [{:keys [db store]} [_]]
|
(fn [{:keys [db store]} [_]]
|
||||||
{:db (merge db/default-db store)}))
|
(println (boolean (-> js/window .-web3)))
|
||||||
|
(let [injected-web3 (-> js/window .-web3)
|
||||||
|
web3 (if (boolean injected-web3)
|
||||||
|
(new (-> js/window .-Web3) (web3/current-provider injected-web3))
|
||||||
|
;; TODO: put RPC URL in db
|
||||||
|
(web3/create-web3 "http://localhost:8545"))]
|
||||||
|
{:db (-> db/default-db
|
||||||
|
(merge {:web3 web3})
|
||||||
|
(merge store))})))
|
||||||
|
|
||||||
(reg-event-db
|
(reg-event-db
|
||||||
:assoc-in
|
:assoc-in
|
||||||
|
@ -351,8 +361,8 @@
|
||||||
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-eth (-> js/web3 .-eth)
|
(let [web3 (:web3 db)
|
||||||
bignum (-> js/web3 .-BigNumber)
|
bignum (-> web3 .-BigNumber)
|
||||||
confirm-method-id (sig->method-id "confirmTransaction(uint256)")
|
confirm-method-id (sig->method-id "confirmTransaction(uint256)")
|
||||||
confirm-id (strip-0x confirm-hash)
|
confirm-id (strip-0x confirm-hash)
|
||||||
data (str confirm-method-id
|
data (str confirm-method-id
|
||||||
|
@ -365,7 +375,7 @@
|
||||||
:data data}]
|
:data data}]
|
||||||
(println "data:" data)
|
(println "data:" data)
|
||||||
(try
|
(try
|
||||||
(.sendTransaction web3-eth (clj->js payload)
|
(web3-eth/send-transaction! web3 (clj->js 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
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
(ns commiteth.subscriptions
|
(ns commiteth.subscriptions
|
||||||
(:require [re-frame.core :refer [reg-sub]]))
|
(:require [re-frame.core :refer [reg-sub]]))
|
||||||
|
|
||||||
|
(reg-sub
|
||||||
|
:db
|
||||||
|
(fn [db _] db))
|
||||||
|
|
||||||
(reg-sub
|
(reg-sub
|
||||||
:page
|
:page
|
||||||
(fn [db _]
|
(fn [db _]
|
||||||
|
|
|
@ -2,19 +2,18 @@
|
||||||
(:require [re-frame.core :as rf]
|
(:require [re-frame.core :as rf]
|
||||||
[commiteth.common :refer [input dropdown]]
|
[commiteth.common :refer [input dropdown]]
|
||||||
[reagent.core :as r]
|
[reagent.core :as r]
|
||||||
[reagent.crypt :as crypt]))
|
[reagent.crypt :as crypt]
|
||||||
|
[cljs-web3.eth :as web3-eth]))
|
||||||
|
|
||||||
|
|
||||||
(defn update-address-page []
|
(defn update-address-page []
|
||||||
(let [user (rf/subscribe [:user])
|
(let [db (rf/subscribe [:db])
|
||||||
|
user (rf/subscribe [:user])
|
||||||
updating-address (rf/subscribe [:get-in [:updating-address]])
|
updating-address (rf/subscribe [:get-in [:updating-address]])
|
||||||
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
|
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
|
||||||
(fn []
|
(fn []
|
||||||
(let [web3 (.-web3 js/window)
|
(let [web3 (:web3 @db)
|
||||||
web3-accounts (vec (when-not (nil? web3) (-> web3
|
web3-accounts (web3-eth/accounts web3)]
|
||||||
.-eth
|
|
||||||
.-accounts
|
|
||||||
js->clj)))]
|
|
||||||
(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