Use syng-im/protocol to get whisper identity
This commit is contained in:
parent
c4686d781d
commit
119c613f8a
|
@ -4,9 +4,12 @@
|
||||||
|
|
||||||
https://github.com/drapanjanas/re-natal
|
https://github.com/drapanjanas/re-natal
|
||||||
|
|
||||||
In `.re-natal`:
|
|
||||||
- set `"androidHost": "localhost"` for real device
|
Can be required after pulling changes:
|
||||||
- set `"androidHost": "10.0.3.2"` for genymotion
|
|
||||||
|
switching between android device
|
||||||
|
|
||||||
|
https://github.com/drapanjanas/re-natal#switching-between-android-devices
|
||||||
|
|
||||||
## Issues
|
## Issues
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
:dependencies [[org.clojure/clojure "1.7.0"]
|
:dependencies [[org.clojure/clojure "1.7.0"]
|
||||||
[org.clojure/clojurescript "1.7.170"]
|
[org.clojure/clojurescript "1.7.170"]
|
||||||
[org.omcljs/om "1.0.0-alpha28" :exclusions [cljsjs/react cljsjs/react-dom]]
|
[org.omcljs/om "1.0.0-alpha28" :exclusions [cljsjs/react cljsjs/react-dom]]
|
||||||
[natal-shell "0.1.6"]]
|
[natal-shell "0.1.6"]
|
||||||
|
[syng-im/protocol "0.1.0"]]
|
||||||
:plugins [[lein-cljsbuild "1.1.1"]
|
:plugins [[lein-cljsbuild "1.1.1"]
|
||||||
[lein-figwheel "0.5.0-2"]]
|
[lein-figwheel "0.5.0-2"]]
|
||||||
:clean-targets ["target/" "index.ios.js" "index.android.js"]
|
:clean-targets ["target/" "index.ios.js" "index.android.js"]
|
||||||
|
@ -30,7 +31,10 @@
|
||||||
:compiler {:output-to "target/android/not-used.js"
|
:compiler {:output-to "target/android/not-used.js"
|
||||||
:main "env.android.main"
|
:main "env.android.main"
|
||||||
:output-dir "target/android"
|
:output-dir "target/android"
|
||||||
:optimizations :none}}}}
|
:optimizations :none
|
||||||
|
:foreign-libs [{:file "resources/vendor/js/web3.js"
|
||||||
|
:file-min "resources/vendor/js/web3.min.js"
|
||||||
|
:provides ["cljsjs.web3"]}]}}}}
|
||||||
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
|
:repl-options {:nrepl-middleware [cemerick.piggieback/wrap-cljs-repl]}}
|
||||||
:prod {:cljsbuild {:builds
|
:prod {:cljsbuild {:builds
|
||||||
{:ios {:source-paths ["src" "env/prod"]
|
{:ios {:source-paths ["src" "env/prod"]
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -7,58 +7,82 @@
|
||||||
[natal-shell.alert :refer [alert]])
|
[natal-shell.alert :refer [alert]])
|
||||||
(:require [om.next :as om :refer-macros [defui]]
|
(:require [om.next :as om :refer-macros [defui]]
|
||||||
[re-natal.support :as sup]
|
[re-natal.support :as sup]
|
||||||
|
[syng-im.protocol.whisper :as whisper]
|
||||||
[messenger.state :as state]
|
[messenger.state :as state]
|
||||||
[messenger.android.resources :as res]
|
[messenger.android.resources :as res]
|
||||||
[messenger.android.contacts-list :refer [contacts-list]]))
|
[messenger.android.contacts-list :refer [contacts-list]]))
|
||||||
|
|
||||||
|
(def nav-atom (atom nil))
|
||||||
|
|
||||||
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
|
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
|
||||||
(def country-code "US")
|
(def country-code "US")
|
||||||
|
|
||||||
(set! js/Web3 (js/require "web3"))
|
|
||||||
(def ethereum-rpc-url "http://localhost:8545")
|
(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]
|
(defn show-home-view []
|
||||||
|
(binding [state/*nav-render* false]
|
||||||
|
(.replace @nav-atom (clj->js {:component contacts-list
|
||||||
|
:name "contacts-list"}))))
|
||||||
|
|
||||||
|
(defn sign-in [phone-number whisper-identity]
|
||||||
|
(alert (str "TODO: send number: " phone-number ", "
|
||||||
|
(subs whisper-identity 0 2) ".."
|
||||||
|
(subs whisper-identity (- (count whisper-identity) 2)
|
||||||
|
(count whisper-identity))))
|
||||||
|
(show-home-view))
|
||||||
|
|
||||||
|
(defn identity-handler [error result]
|
||||||
(if error
|
(if error
|
||||||
(do (alert (str error))
|
(do (alert (str error))
|
||||||
(.log js/console "error")
|
(.log js/console "error")
|
||||||
(.log js/console error))
|
(.log js/console error))
|
||||||
(alert (str result)))
|
(alert (str result))))
|
||||||
(.log js/console "result")
|
|
||||||
(.log js/console result))
|
|
||||||
|
|
||||||
;; (def web3 (make-web3 ethereum-rpc-url))
|
(defn get-identity [handler]
|
||||||
(new-identity (make-web3 ethereum-rpc-url) my-handler)
|
(let [web3 (whisper/make-web3 ethereum-rpc-url)]
|
||||||
;; (def whisper-identity (new-identity web3 my-handler))
|
(str (.newIdentity (whisper/whisper web3) handler))))
|
||||||
;; (alert (str whisper-identity))
|
|
||||||
|
|
||||||
|
(defn get-whisper-identity-handler [phone-number]
|
||||||
|
(fn [identity]
|
||||||
|
(if identity
|
||||||
|
(sign-in phone-number identity)
|
||||||
|
(get-identity (fn [error identity]
|
||||||
|
(if (not error)
|
||||||
|
(do (set-item "user-whisper-identity" identity)
|
||||||
|
(swap! state/app-state assoc :user-whisper-identity identity)
|
||||||
|
(sign-in phone-number identity))
|
||||||
|
(alert error)))))))
|
||||||
|
|
||||||
|
(defn load-user-whisper-identity [handler]
|
||||||
|
(get-item "user-whisper-identity"
|
||||||
|
(fn [error value]
|
||||||
|
(if (not error)
|
||||||
|
(let [whisper-identity (when value (str value))]
|
||||||
|
(swap! state/app-state assoc :user-whisper-identity whisper-identity)
|
||||||
|
(handler whisper-identity))
|
||||||
|
(alert (str "error" error))))))
|
||||||
|
|
||||||
(defn show-home-view [nav]
|
(defn handle-phone-number [phone-number]
|
||||||
(binding [state/*nav-render* false]
|
(when phone-number
|
||||||
(.replace nav (clj->js {:component contacts-list
|
(load-user-whisper-identity (get-whisper-identity-handler phone-number))))
|
||||||
:name "contacts-list"}))))
|
|
||||||
|
|
||||||
(defn save-phone-number [nav]
|
(defn save-phone-number []
|
||||||
(let [phone-number (:user-phone-number @state/app-state)]
|
(let [phone-number (:user-phone-number @state/app-state)]
|
||||||
(set-item "user-phone-number" phone-number)
|
(set-item "user-phone-number" phone-number)
|
||||||
(show-home-view nav)))
|
(handle-phone-number phone-number)))
|
||||||
|
|
||||||
(defn update-phone-number [value]
|
(defn update-phone-number [value]
|
||||||
(let [formatted (str (.getNumber (js/PhoneNumber. value country-code "international")))]
|
(let [formatted (str (.getNumber (js/PhoneNumber. value country-code "international")))]
|
||||||
(swap! state/app-state assoc :user-phone-number
|
(swap! state/app-state assoc :user-phone-number
|
||||||
formatted)))
|
formatted)))
|
||||||
|
|
||||||
(defn load-user-phone-number []
|
(defn load-user-phone-number [handler]
|
||||||
(get-item "user-phone-number"
|
(get-item "user-phone-number"
|
||||||
(fn [error value]
|
(fn [error value]
|
||||||
(if (not error)
|
(if (not error)
|
||||||
(swap! state/app-state assoc :user-phone-number
|
(let [phone-number (when value (str value))]
|
||||||
value)
|
(swap! state/app-state assoc :user-phone-number phone-number)
|
||||||
|
(when handler
|
||||||
|
(handler phone-number)))
|
||||||
(alert (str "error" error))))))
|
(alert (str "error" error))))))
|
||||||
|
|
||||||
(defui Login
|
(defui Login
|
||||||
|
@ -67,10 +91,11 @@
|
||||||
'[:user-phone-number])
|
'[:user-phone-number])
|
||||||
Object
|
Object
|
||||||
(componentDidMount [this]
|
(componentDidMount [this]
|
||||||
(load-user-phone-number))
|
(load-user-phone-number nil))
|
||||||
(render [this]
|
(render [this]
|
||||||
(let [{:keys [user-phone-number]} (om/props this)
|
(let [{:keys [user-phone-number]} (om/props this)
|
||||||
{:keys [nav]} (om/get-computed this)]
|
{:keys [nav]} (om/get-computed this)]
|
||||||
|
(reset! nav-atom nav)
|
||||||
(view
|
(view
|
||||||
{:style {:flex 1
|
{:style {:flex 1
|
||||||
:backgroundColor "white"}}
|
:backgroundColor "white"}}
|
||||||
|
@ -94,7 +119,7 @@
|
||||||
:fontFamily "Avenir-Roman"
|
:fontFamily "Avenir-Roman"
|
||||||
:color "#9CBFC0"}}
|
:color "#9CBFC0"}}
|
||||||
user-phone-number)
|
user-phone-number)
|
||||||
(touchable-highlight {:onPress #(save-phone-number nav)
|
(touchable-highlight {:onPress #(save-phone-number)
|
||||||
:style {:alignSelf "center"
|
:style {:alignSelf "center"
|
||||||
:borderRadius 7
|
:borderRadius 7
|
||||||
:backgroundColor "#E5F5F6"
|
:backgroundColor "#E5F5F6"
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
(set! js/React (js/require "react-native"))
|
(set! js/React (js/require "react-native"))
|
||||||
|
|
||||||
(defonce app-state (atom {:component nil
|
(defonce app-state (atom {:component nil
|
||||||
:user-phone-number nil}))
|
:user-phone-number nil
|
||||||
|
:user-whisper-identity nil}))
|
||||||
(def ^{:dynamic true :private true} *nav-render*
|
(def ^{:dynamic true :private true} *nav-render*
|
||||||
"Flag to suppress navigator re-renders from outside om when pushing/popping."
|
"Flag to suppress navigator re-renders from outside om when pushing/popping."
|
||||||
true)
|
true)
|
||||||
|
|
Loading…
Reference in New Issue