created new accounts realm object and fixed new create account flow

Former-commit-id: c878fba6f1
This commit is contained in:
Adrian Tiberius 2016-06-30 18:06:05 +03:00
parent 688fde47e9
commit ea7c5b1665
7 changed files with 65 additions and 9 deletions

View File

@ -186,7 +186,7 @@ public class GethService extends Service {
String password = data.getString("password"); String password = data.getString("password");
// TODO: remove second argument // TODO: remove second argument
Log.d(TAG, "Creating account: " + password + " - " + dataFolder); Log.d(TAG, "Creating account: " + password + " - " + dataFolder);
String jsonData = Statusgo.CreateAccount(password, dataFolder); String jsonData = Statusgo.CreateAccount(password, dataFolder + "/keystore");
Log.d(TAG, "Created account: " + jsonData); Log.d(TAG, "Created account: " + jsonData);
Bundle replyData = new Bundle(); Bundle replyData = new Bundle();

View File

@ -0,0 +1,32 @@
(ns status-im.accounts.handlers
(:require [status-im.models.accounts :as accounts]
[re-frame.core :refer [register-handler after dispatch debug]]
[status-im.utils.logging :as log]
[status-im.components.react :refer [geth]]
[status-im.utils.types :refer [json->clj]]
[clojure.string :as str]))
(defn save-account [_ [_ account]]
(accounts/save-accounts [account]))
(register-handler :add-account
(-> (fn [db [_ {:keys [address] :as account}]]
(update db :accounts assoc address account))
((after save-account))))
(defn account-created [result]
(let [data (json->clj result)
public-key (:pubkey data)
address (:address data)]
(log/debug "Created account: " result)
(when (not (str/blank? public-key))
(do
(dispatch [:initialize-protocol public-key])
(dispatch [:add-account {:address address
:public-key public-key}])))))
(register-handler :create-account
(-> (fn [db [_ password]]
(.createAccount geth password (fn [result] (account-created result)))
db)))

View File

@ -262,11 +262,7 @@
(register-handler :save-password (register-handler :save-password
(fn [db [_ password]] (fn [db [_ password]]
(.createAccount geth password (fn [result] (dispatch [:create-account password])
(let [data (json->clj result)
public-key (:pubkey data)]
(log/debug "Created account: " result)
(when (not (str/blank? public-key)) (dispatch [:initialize-protocol public-key])))))
(sign-up-service/save-password password) (sign-up-service/save-password password)
(assoc db :password-saved true))) (assoc db :password-saved true)))

View File

@ -11,6 +11,7 @@
;; initial state of app-db ;; initial state of app-db
(def app-db {:identity-password "replace-me-with-user-entered-password" (def app-db {:identity-password "replace-me-with-user-entered-password"
:identity "me" :identity "me"
:accounts {}
:contacts [] :contacts []
:contacts-ids #{} :contacts-ids #{}
:selected-contacts #{} :selected-contacts #{}

View File

@ -19,6 +19,7 @@
status-im.new-group.handlers status-im.new-group.handlers
status-im.participants.handlers status-im.participants.handlers
status-im.qr-scanner.handlers status-im.qr-scanner.handlers
status-im.accounts.handlers
status-im.protocol.handlers)) status-im.protocol.handlers))
;; -- Middleware ------------------------------------------------------------ ;; -- Middleware ------------------------------------------------------------
@ -77,9 +78,9 @@
(dispatch [:crypt-initialized])))))))) (dispatch [:crypt-initialized]))))))))
(register-handler :initialize-geth (register-handler :initialize-geth
(u/side-effect! (u/side-effect!
(fn [_ _] (fn [_ _]
(log/debug "Starting node") (log/debug "Starting node")
(.startNode geth (fn [result] (log/debug "Started Node: " result)))))) (.startNode geth (fn [result] (log/debug "Started Node: " result))))))
(register-handler :crypt-initialized (register-handler :crypt-initialized
(u/side-effect! (u/side-effect!

View File

@ -0,0 +1,22 @@
(ns status-im.models.accounts
(:require [status-im.persistence.realm :as r]))
(defn get-accounts []
(-> (r/get-all :accounts)
r/collection->map))
(defn create-account [{:keys [address public-key] :as account}]
(->> account
(r/create :accounts)))
(defn save-accounts [accounts]
(r/write #(mapv create-account accounts)))
;;;;;;;;;;;;;;;;;;;;----------------------------------------------
(defn accounts-list []
(r/get-all :accounts))
(defn account-by-address [address]
(r/single-cljs (r/get-by-field :accounts :address address)))

View File

@ -15,6 +15,10 @@
:optional true} :optional true}
:photo-path {:type "string" :photo-path {:type "string"
:optinal true}}} :optinal true}}}
{:name :accounts
:primaryKey :address
:properties {:address "string"
:public-key "string"}}
{:name :kv-store {:name :kv-store
:primaryKey :key :primaryKey :key
:properties {:key "string" :properties {:key "string"