created new accounts realm object and fixed new create account flow
Former-commit-id: c878fba6f1
This commit is contained in:
parent
688fde47e9
commit
ea7c5b1665
|
@ -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();
|
||||
|
|
|
@ -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)))
|
|
@ -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)))
|
||||
|
||||
|
|
|
@ -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 #{}
|
||||
|
|
|
@ -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 ------------------------------------------------------------
|
||||
|
|
|
@ -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)))
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue