created new accounts realm object and fixed new create account flow

This commit is contained in:
Adrian Tiberius 2016-06-30 18:06:05 +03:00
parent 8a75e1eea7
commit c878fba6f1
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");
// TODO: remove second argument
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);
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
(fn [db [_ password]]
(.createAccount geth password (fn [result]
(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])))))
(dispatch [:create-account password])
(sign-up-service/save-password password)
(assoc db :password-saved true)))

View File

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

View File

@ -19,6 +19,7 @@
status-im.new-group.handlers
status-im.participants.handlers
status-im.qr-scanner.handlers
status-im.accounts.handlers
status-im.protocol.handlers))
;; -- Middleware ------------------------------------------------------------

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}
:photo-path {:type "string"
:optinal true}}}
{:name :accounts
:primaryKey :address
:properties {:address "string"
:public-key "string"}}
{:name :kv-store
:primaryKey :key
:properties {:key "string"