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:
Teemu Patja 2017-08-28 23:09:57 +03:00
parent 1139e01835
commit fff720ad71
No known key found for this signature in database
GPG Key ID: F5B7035E6580FD4C
4 changed files with 27 additions and 13 deletions

View File

@ -49,7 +49,8 @@
[com.andrewmcveigh/cljs-time "0.5.1"]
[akiroz.re-frame/storage "0.1.2"]
[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"
:source-paths ["src/clj" "src/cljc"]

View File

@ -7,6 +7,8 @@
inject-cofx]]
[ajax.core :refer [GET POST]]
[cuerdas.core :as str]
[cljs-web3.core :as web3]
[cljs-web3.eth :as web3-eth]
[akiroz.re-frame.storage
:as rf-storage
:refer [reg-co-fx!]]))
@ -41,7 +43,15 @@
:initialize-db
[(inject-cofx :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
:assoc-in
@ -351,8 +361,8 @@
owner-address :owner_address
contract-address :contract_address
confirm-hash :confirm_hash} issue]]
(let [web3-eth (-> js/web3 .-eth)
bignum (-> js/web3 .-BigNumber)
(let [web3 (:web3 db)
bignum (-> web3 .-BigNumber)
confirm-method-id (sig->method-id "confirmTransaction(uint256)")
confirm-id (strip-0x confirm-hash)
data (str confirm-method-id
@ -365,8 +375,8 @@
:data data}]
(println "data:" data)
(try
(.sendTransaction web3-eth (clj->js payload)
(send-transaction-callback issue-id))
(web3-eth/send-transaction! web3 (clj->js payload)
(send-transaction-callback issue-id))
{:db (assoc-in db [:owner-bounties issue-id :confirming?] true)}
(catch js/Error e
{:db (assoc-in db [:owner-bounties issue-id :confirm-failed?] true)

View File

@ -1,6 +1,10 @@
(ns commiteth.subscriptions
(:require [re-frame.core :refer [reg-sub]]))
(reg-sub
:db
(fn [db _] db))
(reg-sub
:page
(fn [db _]

View File

@ -2,19 +2,18 @@
(:require [re-frame.core :as rf]
[commiteth.common :refer [input dropdown]]
[reagent.core :as r]
[reagent.crypt :as crypt]))
[reagent.crypt :as crypt]
[cljs-web3.eth :as web3-eth]))
(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]])
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
(fn []
(let [web3 (.-web3 js/window)
web3-accounts (vec (when-not (nil? web3) (-> web3
.-eth
.-accounts
js->clj)))]
(let [web3 (:web3 @db)
web3-accounts (web3-eth/accounts web3)]
(println "web3-accounts" web3-accounts)
[:div.ui.container.grid
[:div.ui.form.sixteen.wide.column