This commit is contained in:
Roman Volosovskyi 2016-10-03 17:30:43 +03:00
parent 09e711eef6
commit c29cb2de5e
4 changed files with 41 additions and 32 deletions

View File

@ -5,20 +5,22 @@
[status-im.utils.identicon :refer [identicon]] [status-im.utils.identicon :refer [identicon]]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[clojure.string :as str] [clojure.string :as str]
[status-im.utils.handlers :as u]
[status-im.protocol.core :as protocol])) [status-im.protocol.core :as protocol]))
(defn account-recovered [result password] (defn account-recovered [result]
(let [_ (log/debug result) (let [_ (log/debug result)
data (json->clj result) data (json->clj result)
public-key (:pubkey data) public-key (:pubkey data)
address (:address data) address (:address data)
{:keys [public private]} (protocol/new-keypair!) {:keys [public private]} (protocol/new-keypair!)
account {:public-key public-key account {:public-key public-key
:address address :address address
:name address :name address
:photo-path (identicon public-key) :photo-path (identicon public-key)
:updates-public-key public :updates-public-key public
:updates-private-key private}] :updates-private-key private
:signed-up? true}]
(log/debug "account-recovered") (log/debug "account-recovered")
(when (not (str/blank? public-key)) (when (not (str/blank? public-key))
(do (do
@ -28,8 +30,10 @@
(dispatch [:navigate-back]))))) (dispatch [:navigate-back])))))
(defn recover-account (defn recover-account
[{:keys [recover] :as db} [_ passphrase password]] [_ [_ passphrase password]]
(status/recover-account passphrase password (fn [result] (account-recovered result password))) (status/recover-account
db) passphrase
password
(fn [result] (account-recovered result))))
(register-handler :recover-account recover-account) (register-handler :recover-account (u/side-effect! recover-account))

View File

@ -173,21 +173,22 @@
(set-message-shown db chat-id message-id))) (set-message-shown db chat-id message-id)))
(defn init-console-chat (defn init-console-chat
[{:keys [chats] :as db} existing-account?] ([existing-account?] (init-console-chat {} existing-account?))
(let [new-chat sign-up-service/console-chat] ([{:keys [chats] :as db} existing-account?]
(if (chats console-chat-id) (let [new-chat sign-up-service/console-chat]
db (if (chats console-chat-id)
(do db
(chats/create-chat new-chat) (do
(contacts/save-contacts [sign-up-service/console-contact]) (chats/create-chat new-chat)
(sign-up-service/intro) (contacts/save-contacts [sign-up-service/console-contact])
(when existing-account? (sign-up-service/intro)
(sign-up-service/start-signup)) (when existing-account?
(-> db (sign-up-service/start-signup))
(assoc :new-chat new-chat) (-> db
(update :chats assoc console-chat-id new-chat) (assoc :new-chat new-chat)
(update :chats-ids conj console-chat-id) (update :chats assoc console-chat-id new-chat)
(assoc :current-chat-id console-chat-id)))))) (update :chats-ids conj console-chat-id)
(assoc :current-chat-id console-chat-id)))))))
(register-handler :init-console-chat (register-handler :init-console-chat
(fn [db _] (fn [db _]
@ -215,7 +216,6 @@
db))) db)))
(register-handler :sign-up-confirm (register-handler :sign-up-confirm
(after #(dispatch [:init-wallet-chat]))
(u/side-effect! (u/side-effect!
(fn [_ [_ confirmation-code]] (fn [_ [_ confirmation-code]]
(server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response)))) (server/sign-up-confirm confirmation-code sign-up-service/on-send-code-response))))
@ -265,7 +265,8 @@
;TODO: check if its new account / signup status / create console chat ;TODO: check if its new account / signup status / create console chat
(register-handler :initialize-chats (register-handler :initialize-chats
(after #(dispatch [:load-unviewed-messages!])) [(after #(dispatch [:load-unviewed-messages!]))
(after #(dispatch [:init-wallet-chat]))]
((enrich initialize-chats) load-chats!)) ((enrich initialize-chats) load-chats!))
(defmethod nav/preload-data! :chat (defmethod nav/preload-data! :chat

View File

@ -5,7 +5,10 @@
(register-handler :init-wallet-chat (register-handler :init-wallet-chat
(u/side-effect! (u/side-effect!
(fn [] (fn [{:keys [chats]}]
(dispatch [:add-chat wallet-chat-id {:name "Wallet" (when-not (chats wallet-chat-id)
:dapp-url "http://127.0.0.1:3450"}])))) (dispatch [:add-chat
wallet-chat-id
{:name "Wallet"
:dapp-url "http://127.0.0.1:3450"}])))))

View File

@ -70,6 +70,7 @@
(dispatch [:initialize-db]) (dispatch [:initialize-db])
(dispatch [:load-accounts]) (dispatch [:load-accounts])
(dispatch [:init-console-chat]) (dispatch [:init-console-chat])
(dispatch [:init-wallet-chat])
(dispatch [:load-commands! console-chat-id])))) (dispatch [:load-commands! console-chat-id]))))
(register-handler :initialize-crypt (register-handler :initialize-crypt