From 22310a3ee8ce8f759b06a34ed427b6adc6ff1940 Mon Sep 17 00:00:00 2001 From: virvar Date: Fri, 4 Mar 2016 20:28:06 +0300 Subject: [PATCH] Add web3 --- .re-natal | 3 +- project.clj | 86 ++++++++++++++++---------------- src/messenger/android/login.cljs | 24 +++++++++ 3 files changed, 70 insertions(+), 43 deletions(-) diff --git a/.re-natal b/.re-natal index 4bcf0c5673..4deadeddf4 100644 --- a/.re-natal +++ b/.re-natal @@ -5,7 +5,8 @@ "modules": [ "react-native-contacts", "react-native-invertible-scroll-view", - "awesome-phonenumber" + "awesome-phonenumber", + "web3" ], "imageDirs": [ "images" diff --git a/project.clj b/project.clj index ab8ac3c760..ca655223e5 100644 --- a/project.clj +++ b/project.clj @@ -1,43 +1,45 @@ (defproject messenger "0.1.0-SNAPSHOT" - :description "FIXME: write description" - :url "http://example.com/FIXME" - :license {:name "Eclipse Public License" - :url "http://www.eclipse.org/legal/epl-v10.html"} - :dependencies [[org.clojure/clojure "1.7.0"] - [org.clojure/clojurescript "1.7.170"] - [org.omcljs/om "1.0.0-alpha28" :exclusions [cljsjs/react cljsjs/react-dom]] -[natal-shell "0.1.6"]] - :plugins [[lein-cljsbuild "1.1.1"] - [lein-figwheel "0.5.0-2"]] - :clean-targets ["target/" "index.ios.js" "index.android.js"] - :aliases {"prod-build" ^{:doc "Recompile code with prod profile."} - ["do" "clean" - ["with-profile" "prod" "cljsbuild" "once" "ios"] - ["with-profile" "prod" "cljsbuild" "once" "android"]]} - :profiles {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"] - [com.cemerick/piggieback "0.2.1"]] - :source-paths ["src" "env/dev"] - :cljsbuild {:builds {:ios {:source-paths ["src" "env/dev"] - :figwheel true - :compiler {:output-to "target/ios/not-used.js" - :main "env.ios.main" - :output-dir "target/ios" - :optimizations :none}} - :android {:source-paths ["src" "env/dev"] - :figwheel true - :compiler {:output-to "target/android/not-used.js" - :main "env.android.main" - :output-dir "target/android" - :optimizations :none}}}} - :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}} - :prod {:cljsbuild {:builds {:ios {:source-paths ["src" "env/prod"] - :compiler {:output-to "index.ios.js" - :main "env.ios.main" - :output-dir "target/ios" - :optimizations :simple}} - :android {:source-paths ["src" "env/prod"] - :compiler {:output-to "index.android.js" - :main "env.android.main" - :output-dir "target/android" - :optimizations :simple}}}} - }}) \ No newline at end of file + :description "FIXME: write description" + :url "http://example.com/FIXME" + :license {:name "Eclipse Public License" + :url "http://www.eclipse.org/legal/epl-v10.html"} + :dependencies [[org.clojure/clojure "1.7.0"] + [org.clojure/clojurescript "1.7.170"] + [org.omcljs/om "1.0.0-alpha28" :exclusions [cljsjs/react cljsjs/react-dom]] + [natal-shell "0.1.6"]] + :plugins [[lein-cljsbuild "1.1.1"] + [lein-figwheel "0.5.0-2"]] + :clean-targets ["target/" "index.ios.js" "index.android.js"] + :aliases {"prod-build" ^{:doc "Recompile code with prod profile."} + ["do" "clean" + ["with-profile" "prod" "cljsbuild" "once" "ios"] + ["with-profile" "prod" "cljsbuild" "once" "android"]]} + :profiles + {:dev {:dependencies [[figwheel-sidecar "0.5.0-2"] + [com.cemerick/piggieback "0.2.1"]] + :source-paths ["src" "env/dev"] + :cljsbuild {:builds + {:ios {:source-paths ["src" "env/dev"] + :figwheel true + :compiler {:output-to "target/ios/not-used.js" + :main "env.ios.main" + :output-dir "target/ios" + :optimizations :none}} + :android {:source-paths ["src" "env/dev"] + :figwheel true + :compiler {:output-to "target/android/not-used.js" + :main "env.android.main" + :output-dir "target/android" + :optimizations :none}}}} + :repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}} + :prod {:cljsbuild {:builds + {:ios {:source-paths ["src" "env/prod"] + :compiler {:output-to "index.ios.js" + :main "env.ios.main" + :output-dir "target/ios" + :optimizations :simple}} + :android {:source-paths ["src" "env/prod"] + :compiler {:output-to "index.android.js" + :main "env.android.main" + :output-dir "target/android" + :optimizations :simple}}}}}}) diff --git a/src/messenger/android/login.cljs b/src/messenger/android/login.cljs index 24848f4dd4..10ded41287 100644 --- a/src/messenger/android/login.cljs +++ b/src/messenger/android/login.cljs @@ -14,6 +14,30 @@ (set! js/PhoneNumber (js/require "awesome-phonenumber")) (def country-code "US") +(set! js/Web3 (js/require "web3")) +(def ethereum-rpc-url "http://localhost:8545") +(defn make-web3 [rpc-url] + (->> (js/Web3.providers.HttpProvider. rpc-url) + (js/Web3.))) +(defn new-identity [web3 handler] + (.newIdentity (.-shh web3) handler)) + +(defn my-handler [error result] + (if error + (do (alert (str error)) + (.log js/console "error") + (.log js/console error)) + (alert (str result))) + (.log js/console "result") + (.log js/console result)) + +;; (def web3 (make-web3 ethereum-rpc-url)) +(new-identity (make-web3 ethereum-rpc-url) my-handler) +;; (def whisper-identity (new-identity web3 my-handler)) +;; (alert (str whisper-identity)) + + + (defn show-home-view [nav] (binding [state/*nav-render* false] (.replace nav (clj->js {:component contacts-list