Use 'current-identity'
This commit is contained in:
parent
785ddcc245
commit
797fe3336b
|
@ -15,7 +15,7 @@
|
|||
[messenger.android.chat :refer [chat]]
|
||||
[messenger.comm.pubsub :as pubsub]
|
||||
[messenger.comm.intercom :as intercom :refer [load-user-phone-number
|
||||
load-user-whisper-identity]]
|
||||
load-user-identity]]
|
||||
[messenger.protocol.protocol-handler :refer [make-handler]]
|
||||
[syng-im.protocol.api :refer [init-protocol]]
|
||||
[messenger.init :refer [init-simple-store]]))
|
||||
|
@ -40,7 +40,7 @@
|
|||
(defui AppRoot
|
||||
static om/IQuery
|
||||
(query [this]
|
||||
'[:loading :contacts-ds :user-phone-number :confirmation-code])
|
||||
'[:loading :contacts-ds :user-phone-number :user-identity :confirmation-code])
|
||||
Object
|
||||
(render [this]
|
||||
(navigator
|
||||
|
@ -67,6 +67,6 @@
|
|||
(pubsub/setup-pub-sub)
|
||||
(init-protocol (make-handler))
|
||||
(load-user-phone-number)
|
||||
(load-user-whisper-identity)
|
||||
(load-user-identity)
|
||||
(om/add-root! state/reconciler AppRoot 1)
|
||||
(.registerComponent app-registry "Messenger" (fn [] app-root)))
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
(swap! state/app-state assoc :loading true)
|
||||
(let [app-state (state/state)
|
||||
phone-number (:user-phone-number app-state)
|
||||
whisper-identity (:user-whisper-identity app-state)]
|
||||
whisper-identity (:public (:user-identity app-state))]
|
||||
(intercom/sign-up phone-number whisper-identity show-confirm-view)))
|
||||
|
||||
(defn update-phone-number [value]
|
||||
|
@ -38,10 +38,10 @@
|
|||
(defui Login
|
||||
static om/IQuery
|
||||
(query [this]
|
||||
'[:user-phone-number :user-whisper-identity :loading])
|
||||
'[:user-phone-number :user-identity :loading])
|
||||
Object
|
||||
(render [this]
|
||||
(let [{:keys [user-phone-number user-whisper-identity loading]} (om/props this)
|
||||
(let [{:keys [user-phone-number user-identity loading]} (om/props this)
|
||||
{:keys [nav]} (om/get-computed this)]
|
||||
(reset! nav-atom nav)
|
||||
(view
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
[natal-shell.alert :refer [alert]])
|
||||
(:require [om.next :as om :refer-macros [defui]]
|
||||
[re-natal.support :as sup]
|
||||
[syng-im.protocol.web3 :as whisper]
|
||||
[messenger.state :as state]
|
||||
[messenger.utils.utils :refer [log toast]]
|
||||
[messenger.utils.resources :as res]
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
;; :service [service_name action_id args_map]
|
||||
(publish! :service [:user-data :user-data/load-phone-number nil]))
|
||||
|
||||
(defn load-user-whisper-identity []
|
||||
(publish! :service [:user-data :user-data/load-whisper-identity nil]))
|
||||
(defn load-user-identity []
|
||||
(publish! :service [:user-data :user-data/load-identity nil]))
|
||||
|
||||
(defn set-confirmation-code [confirmation-code]
|
||||
(publish! :service [:user-data :user-data/set-confirmation-code confirmation-code]))
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
[messenger.state :as state]
|
||||
[messenger.utils.utils :refer [log on-error toast]]))
|
||||
|
||||
(def ethereum-rpc-url "http://localhost:8545")
|
||||
|
||||
(defn set-phone-number [phone-number]
|
||||
(swap! state/app-state assoc :user-phone-number phone-number))
|
||||
|
||||
|
@ -23,33 +21,8 @@
|
|||
(swap! state/app-state assoc :user-phone-number (when value
|
||||
(str value)))))))
|
||||
|
||||
(defn save-whisper-identity [identity]
|
||||
(set-item "user-whisper-identity" identity)
|
||||
(swap! state/app-state assoc :user-whisper-identity identity))
|
||||
|
||||
(defn load-whisper-identity []
|
||||
(let [ch (chan)]
|
||||
(get-item "user-whisper-identity"
|
||||
(fn [error value]
|
||||
(log (str "load whisper identity: " value))
|
||||
(put! ch
|
||||
{:error error
|
||||
:value (let [whisper-identity (when value (str value))]
|
||||
(swap! state/app-state assoc :user-whisper-identity
|
||||
whisper-identity)
|
||||
whisper-identity)})))
|
||||
ch))
|
||||
|
||||
(defn new-whisper-identity []
|
||||
(let [ch (chan)]
|
||||
(let [web3 (web3/make-web3 ethereum-rpc-url)]
|
||||
(.newIdentity (web3/whisper web3)
|
||||
(fn [error value]
|
||||
(log (str "new whisper identity: " value))
|
||||
(swap! state/app-state assoc :user-whisper-identity value)
|
||||
(put! ch {:error error
|
||||
:value value}))))
|
||||
ch))
|
||||
(defn set-identity [identity]
|
||||
(swap! state/app-state assoc :user-identity identity))
|
||||
|
||||
(defn set-confirmation-code [code]
|
||||
(swap! state/app-state assoc :confirmation-code code))
|
||||
|
|
|
@ -4,10 +4,9 @@
|
|||
[messenger.models.user-data :refer [set-phone-number
|
||||
save-phone-number
|
||||
load-phone-number
|
||||
save-whisper-identity
|
||||
load-whisper-identity
|
||||
new-whisper-identity
|
||||
set-identity
|
||||
set-confirmation-code]]
|
||||
[messenger.models.protocol :refer [current-identity]]
|
||||
[messenger.utils.utils :refer [log on-error]]
|
||||
[syng-im.utils.logging :as log]))
|
||||
|
||||
|
@ -29,18 +28,11 @@
|
|||
(log/debug "handling " id "args = " args)
|
||||
(load-phone-number))
|
||||
|
||||
(defmethod user-data :user-data/load-whisper-identity
|
||||
(defmethod user-data :user-data/load-identity
|
||||
[state id args]
|
||||
(log/info "handling " id " args = " args)
|
||||
(go
|
||||
(let [result (<! (load-whisper-identity))]
|
||||
(if-let [error (:error result)]
|
||||
(on-error error)
|
||||
(when (not (:value result))
|
||||
(let [result (<! (new-whisper-identity))]
|
||||
(if-let [error (:error result)]
|
||||
(on-error error)
|
||||
(save-whisper-identity (:value result)))))))))
|
||||
(let [identity (current-identity)]
|
||||
(set-identity identity)))
|
||||
|
||||
(defmethod user-data :user-data/set-confirmation-code
|
||||
[state id confirmation-code]
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
(defonce app-state (atom {:component nil
|
||||
:loading false
|
||||
:user-phone-number nil
|
||||
:user-whisper-identity nil
|
||||
:user-identity nil
|
||||
:confirmation-code nil
|
||||
:channels {:pub-sub-publisher (chan)
|
||||
:pub-sub-publication nil}}))
|
||||
|
|
Loading…
Reference in New Issue