Use syng-im/protocol to get whisper identity
Former-commit-id: 119c613f8a
This commit is contained in:
parent
7e1cec422e
commit
93848fd255
|
@ -4,9 +4,12 @@
|
|||
|
||||
https://github.com/drapanjanas/re-natal
|
||||
|
||||
In `.re-natal`:
|
||||
- set `"androidHost": "localhost"` for real device
|
||||
- set `"androidHost": "10.0.3.2"` for genymotion
|
||||
|
||||
Can be required after pulling changes:
|
||||
|
||||
switching between android device
|
||||
|
||||
https://github.com/drapanjanas/re-natal#switching-between-android-devices
|
||||
|
||||
## Issues
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@
|
|||
: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"]]
|
||||
[natal-shell "0.1.6"]
|
||||
[syng-im/protocol "0.1.0"]]
|
||||
:plugins [[lein-cljsbuild "1.1.1"]
|
||||
[lein-figwheel "0.5.0-2"]]
|
||||
:clean-targets ["target/" "index.ios.js" "index.android.js"]
|
||||
|
@ -30,7 +31,10 @@
|
|||
:compiler {:output-to "target/android/not-used.js"
|
||||
:main "env.android.main"
|
||||
: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]}}
|
||||
:prod {:cljsbuild {:builds
|
||||
{: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]])
|
||||
(:require [om.next :as om :refer-macros [defui]]
|
||||
[re-natal.support :as sup]
|
||||
[syng-im.protocol.whisper :as whisper]
|
||||
[messenger.state :as state]
|
||||
[messenger.android.resources :as res]
|
||||
[messenger.android.contacts-list :refer [contacts-list]]))
|
||||
|
||||
(def nav-atom (atom nil))
|
||||
|
||||
(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]
|
||||
(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
|
||||
(do (alert (str error))
|
||||
(.log js/console "error")
|
||||
(.log js/console error))
|
||||
(alert (str result)))
|
||||
(.log js/console "result")
|
||||
(.log js/console result))
|
||||
(alert (str 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 get-identity [handler]
|
||||
(let [web3 (whisper/make-web3 ethereum-rpc-url)]
|
||||
(str (.newIdentity (whisper/whisper web3) handler))))
|
||||
|
||||
(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]
|
||||
(binding [state/*nav-render* false]
|
||||
(.replace nav (clj->js {:component contacts-list
|
||||
:name "contacts-list"}))))
|
||||
(defn handle-phone-number [phone-number]
|
||||
(when phone-number
|
||||
(load-user-whisper-identity (get-whisper-identity-handler phone-number))))
|
||||
|
||||
(defn save-phone-number [nav]
|
||||
(defn save-phone-number []
|
||||
(let [phone-number (:user-phone-number @state/app-state)]
|
||||
(set-item "user-phone-number" phone-number)
|
||||
(show-home-view nav)))
|
||||
(handle-phone-number phone-number)))
|
||||
|
||||
(defn update-phone-number [value]
|
||||
(let [formatted (str (.getNumber (js/PhoneNumber. value country-code "international")))]
|
||||
(swap! state/app-state assoc :user-phone-number
|
||||
formatted)))
|
||||
|
||||
(defn load-user-phone-number []
|
||||
(defn load-user-phone-number [handler]
|
||||
(get-item "user-phone-number"
|
||||
(fn [error value]
|
||||
(if (not error)
|
||||
(swap! state/app-state assoc :user-phone-number
|
||||
value)
|
||||
(let [phone-number (when value (str value))]
|
||||
(swap! state/app-state assoc :user-phone-number phone-number)
|
||||
(when handler
|
||||
(handler phone-number)))
|
||||
(alert (str "error" error))))))
|
||||
|
||||
(defui Login
|
||||
|
@ -67,10 +91,11 @@
|
|||
'[:user-phone-number])
|
||||
Object
|
||||
(componentDidMount [this]
|
||||
(load-user-phone-number))
|
||||
(load-user-phone-number nil))
|
||||
(render [this]
|
||||
(let [{:keys [user-phone-number]} (om/props this)
|
||||
{:keys [nav]} (om/get-computed this)]
|
||||
(reset! nav-atom nav)
|
||||
(view
|
||||
{:style {:flex 1
|
||||
:backgroundColor "white"}}
|
||||
|
@ -94,7 +119,7 @@
|
|||
:fontFamily "Avenir-Roman"
|
||||
:color "#9CBFC0"}}
|
||||
user-phone-number)
|
||||
(touchable-highlight {:onPress #(save-phone-number nav)
|
||||
(touchable-highlight {:onPress #(save-phone-number)
|
||||
:style {:alignSelf "center"
|
||||
:borderRadius 7
|
||||
:backgroundColor "#E5F5F6"
|
||||
|
|
|
@ -5,7 +5,8 @@
|
|||
(set! js/React (js/require "react-native"))
|
||||
|
||||
(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*
|
||||
"Flag to suppress navigator re-renders from outside om when pushing/popping."
|
||||
true)
|
||||
|
|
Loading…
Reference in New Issue