Replace accounts/accounts by account/account in app-db [#3907]
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
8604efdfff
commit
ef0024c5dc
|
@ -20,7 +20,7 @@
|
||||||
|
|
||||||
(defn request-command-message-data
|
(defn request-command-message-data
|
||||||
"Requests command message data from jail"
|
"Requests command message data from jail"
|
||||||
[{:accounts/keys [current-account-id] :contacts/keys [contacts] :as db}
|
[{:contacts/keys [contacts] :as db}
|
||||||
{{:keys [command command-scope-bitmask bot params type]} :content
|
{{:keys [command command-scope-bitmask bot params type]} :content
|
||||||
:keys [chat-id group-id] :as message}
|
:keys [chat-id group-id] :as message}
|
||||||
{:keys [data-type] :as opts}]
|
{:keys [data-type] :as opts}]
|
||||||
|
@ -31,8 +31,9 @@
|
||||||
[command command-scope-bitmask]
|
[command command-scope-bitmask]
|
||||||
data-type]
|
data-type]
|
||||||
to (get-in contacts [chat-id :address])
|
to (get-in contacts [chat-id :address])
|
||||||
|
address (get-in db [:account/account :address])
|
||||||
jail-params {:parameters params
|
jail-params {:parameters params
|
||||||
:context (generate-context current-account-id chat-id (models.message/group-message? message) to)}]
|
:context (generate-context address chat-id (models.message/group-message? message) to)}]
|
||||||
{:db db
|
{:db db
|
||||||
:call-jail {:jail-id bot
|
:call-jail {:jail-id bot
|
||||||
:path path
|
:path path
|
||||||
|
|
|
@ -42,8 +42,7 @@
|
||||||
(def console-commands->fx
|
(def console-commands->fx
|
||||||
{"faucet"
|
{"faucet"
|
||||||
(fn [{:keys [db random-id] :as cofx} {:keys [params]}]
|
(fn [{:keys [db random-id] :as cofx} {:keys [params]}]
|
||||||
(let [{:accounts/keys [accounts current-account-id]} db
|
(let [current-address (get-in db [:account/account :address])
|
||||||
current-address (get-in accounts [current-account-id :address])
|
|
||||||
faucet-url (faucet-base-url->url (:url params))]
|
faucet-url (faucet-base-url->url (:url params))]
|
||||||
{:http-get {:url (gstring/format faucet-url current-address)
|
{:http-get {:url (gstring/format faucet-url current-address)
|
||||||
:success-event-creator (fn [_]
|
:success-event-creator (fn [_]
|
||||||
|
|
|
@ -68,16 +68,17 @@
|
||||||
;; jail function in each participant's jail
|
;; jail function in each participant's jail
|
||||||
(defn call-on-message-input-change
|
(defn call-on-message-input-change
|
||||||
"Calls bot's `on-message-input-change` function"
|
"Calls bot's `on-message-input-change` function"
|
||||||
[{:keys [current-chat-id current-account-id chats local-storage] :as db}]
|
[{:keys [current-chat-id chats local-storage] :as db}]
|
||||||
(let [chat-text (string/trim (or (get-in chats [current-chat-id :input-text]) ""))
|
(let [chat-text (string/trim (or (get-in chats [current-chat-id :input-text]) ""))
|
||||||
{:keys [dapp?]} (get-in db [:contacts/contacts current-chat-id])]
|
{:keys [dapp?]} (get-in db [:contacts/contacts current-chat-id])
|
||||||
|
address (get-in db [:account/account :address])]
|
||||||
(cond-> {:db db}
|
(cond-> {:db db}
|
||||||
(and dapp? (not (string/blank? chat-text)))
|
(and dapp? (not (string/blank? chat-text)))
|
||||||
(assoc :call-jail-function {:chat-id current-chat-id
|
(assoc :call-jail-function {:chat-id current-chat-id
|
||||||
:function :on-message-input-change
|
:function :on-message-input-change
|
||||||
:parameters {:message chat-text}
|
:parameters {:message chat-text}
|
||||||
:context {:data (get local-storage current-chat-id)
|
:context {:data (get local-storage current-chat-id)
|
||||||
:from current-account-id}}))))
|
:from address}}))))
|
||||||
|
|
||||||
(defn set-chat-input-metadata
|
(defn set-chat-input-metadata
|
||||||
"Set input metadata for active chat. Takes db and metadata and returns updated db."
|
"Set input metadata for active chat. Takes db and metadata and returns updated db."
|
||||||
|
@ -121,7 +122,7 @@
|
||||||
|
|
||||||
(defn load-chat-parameter-box
|
(defn load-chat-parameter-box
|
||||||
"Returns fx for loading chat parameter box for active chat"
|
"Returns fx for loading chat parameter box for active chat"
|
||||||
[{:keys [current-chat-id bot-db] :accounts/keys [current-account-id] :as db}
|
[{:keys [current-chat-id bot-db] :as db}
|
||||||
{:keys [name scope-bitmask type bot owner-id] :as command}]
|
{:keys [name scope-bitmask type bot owner-id] :as command}]
|
||||||
(let [parameter-index (input-model/argument-position db)]
|
(let [parameter-index (input-model/argument-position db)]
|
||||||
(when (and command (> parameter-index -1))
|
(when (and command (> parameter-index -1))
|
||||||
|
@ -137,11 +138,12 @@
|
||||||
rest)
|
rest)
|
||||||
seq-arg (get-in db [:chats current-chat-id :seq-argument-input-text])
|
seq-arg (get-in db [:chats current-chat-id :seq-argument-input-text])
|
||||||
to (get-in db [:contacts/contacts current-chat-id :address])
|
to (get-in db [:contacts/contacts current-chat-id :address])
|
||||||
|
from (get-in db [:account/account :address])
|
||||||
params {:parameters {:args args
|
params {:parameters {:args args
|
||||||
:bot-db bot-db
|
:bot-db bot-db
|
||||||
:seq-arg seq-arg}
|
:seq-arg seq-arg}
|
||||||
:context {:data data
|
:context {:data data
|
||||||
:from current-account-id
|
:from from
|
||||||
:to to}}]
|
:to to}}]
|
||||||
{:call-jail {:jail-id owner-id
|
{:call-jail {:jail-id owner-id
|
||||||
:path path
|
:path path
|
||||||
|
@ -330,18 +332,19 @@
|
||||||
::send-command
|
::send-command
|
||||||
message-model/send-interceptors
|
message-model/send-interceptors
|
||||||
(fn [{:keys [db] :as cofx} [command-message]]
|
(fn [{:keys [db] :as cofx} [command-message]]
|
||||||
(let [{:keys [current-public-key current-chat-id] :accounts/keys [current-account-id]} db
|
(let [{:keys [current-chat-id current-public-key]} db
|
||||||
new-db (-> (model/set-chat-ui-props db {:sending-in-progress? false})
|
new-db (-> (model/set-chat-ui-props db {:sending-in-progress? false})
|
||||||
(clear-seq-arguments)
|
(clear-seq-arguments)
|
||||||
(set-chat-input-metadata nil)
|
(set-chat-input-metadata nil)
|
||||||
(set-chat-input-text nil))]
|
(set-chat-input-text nil))
|
||||||
|
address (get-in db [:account/account :address])]
|
||||||
(merge {:db new-db}
|
(merge {:db new-db}
|
||||||
(message-model/process-command (assoc cofx :db new-db)
|
(message-model/process-command (assoc cofx :db new-db)
|
||||||
{:message (get-in db [:chats current-chat-id :input-text])
|
{:message (get-in db [:chats current-chat-id :input-text])
|
||||||
:command command-message
|
:command command-message
|
||||||
:chat-id current-chat-id
|
:chat-id current-chat-id
|
||||||
:identity current-public-key
|
:identity current-public-key
|
||||||
:address current-account-id})))))
|
:address address})))))
|
||||||
|
|
||||||
(defn command-complete?
|
(defn command-complete?
|
||||||
[chat-command]
|
[chat-command]
|
||||||
|
|
|
@ -110,10 +110,9 @@
|
||||||
(rest command-args)
|
(rest command-args)
|
||||||
seq-arguments))})))
|
seq-arguments))})))
|
||||||
([{:keys [chats current-chat-id access-scope->commands-responses]
|
([{:keys [chats current-chat-id access-scope->commands-responses]
|
||||||
:contacts/keys [contacts]
|
:contacts/keys [contacts] :as db}]
|
||||||
:accounts/keys [accounts current-account-id] :as db}]
|
|
||||||
(let [chat (get chats current-chat-id)
|
(let [chat (get chats current-chat-id)
|
||||||
account (get accounts current-account-id)]
|
account (:account/account db)]
|
||||||
(selected-chat-command chat
|
(selected-chat-command chat
|
||||||
(commands-model/commands-responses :command
|
(commands-model/commands-responses :command
|
||||||
access-scope->commands-responses
|
access-scope->commands-responses
|
||||||
|
|
|
@ -51,9 +51,6 @@
|
||||||
(chat-model/upsert-chat {:chat-id chat-id
|
(chat-model/upsert-chat {:chat-id chat-id
|
||||||
:timestamp now} cofx))
|
:timestamp now} cofx))
|
||||||
|
|
||||||
(defn- get-current-account [{:accounts/keys [accounts current-account-id]}]
|
|
||||||
(get accounts current-account-id))
|
|
||||||
|
|
||||||
(defn- send-message-seen [chat-id message-id send-seen? cofx]
|
(defn- send-message-seen [chat-id message-id send-seen? cofx]
|
||||||
(when send-seen?
|
(when send-seen?
|
||||||
(transport/send (protocol/map->MessagesSeen {:message-ids #{message-id}}) chat-id cofx)))
|
(transport/send (protocol/map->MessagesSeen {:message-ids #{message-id}}) chat-id cofx)))
|
||||||
|
@ -66,7 +63,7 @@
|
||||||
view-id
|
view-id
|
||||||
access-scope->commands-responses]
|
access-scope->commands-responses]
|
||||||
:contacts/keys [contacts]} db
|
:contacts/keys [contacts]} db
|
||||||
{:keys [public-key] :as current-account} (get-current-account db)
|
{:keys [public-key] :as current-account} (:account/account db)
|
||||||
current-chat? (and (= :chat view-id) (= current-chat-id chat-id))
|
current-chat? (and (= :chat view-id) (= current-chat-id chat-id))
|
||||||
{:keys [last-clock-value] :as chat} (get-in db [:chats chat-id])
|
{:keys [last-clock-value] :as chat} (get-in db [:chats chat-id])
|
||||||
request-command (:request-command content)
|
request-command (:request-command content)
|
||||||
|
@ -157,7 +154,7 @@
|
||||||
(receive message cofx)))
|
(receive message cofx)))
|
||||||
|
|
||||||
(defn- send-dapp-message!
|
(defn- send-dapp-message!
|
||||||
[{{:accounts/keys [current-account-id] :as db} :db :as cofx} chat-id {:keys [content-type] :as message}]
|
[{:keys [db] :as cofx} chat-id {:keys [content-type] :as message}]
|
||||||
(if (= content-type constants/content-type-command)
|
(if (= content-type constants/content-type-command)
|
||||||
(when-let [text-message (get-in message [:content :handler-data :text-message])]
|
(when-let [text-message (get-in message [:content :handler-data :text-message])]
|
||||||
(handle-message-from-bot cofx {:message text-message
|
(handle-message-from-bot cofx {:message text-message
|
||||||
|
@ -167,7 +164,7 @@
|
||||||
:function :on-message-send
|
:function :on-message-send
|
||||||
:parameters {:message (:content message)}
|
:parameters {:message (:content message)}
|
||||||
:context {:data data
|
:context {:data data
|
||||||
:from current-account-id}}})))
|
:from (get-in db [:account/account :address])}}})))
|
||||||
|
|
||||||
(defn- send
|
(defn- send
|
||||||
[chat-id message-id send-record {{:contacts/keys [contacts] :keys [network-status current-public-key]} :db :as cofx}]
|
[chat-id message-id send-record {{:contacts/keys [contacts] :keys [network-status current-public-key]} :db :as cofx}]
|
||||||
|
@ -307,8 +304,7 @@
|
||||||
(merge {:dispatch-n dn} (dissoc fx :dispatch-n) (dissoc command :dispatch-n)))))
|
(merge {:dispatch-n dn} (dissoc fx :dispatch-n) (dissoc command :dispatch-n)))))
|
||||||
|
|
||||||
(defn invoke-command-handlers
|
(defn invoke-command-handlers
|
||||||
[{{:accounts/keys [accounts current-account-id]
|
[{{:contacts/keys [contacts] :as db} :db}
|
||||||
:contacts/keys [contacts]} :db}
|
|
||||||
{{:keys [command params id]} :command
|
{{:keys [command params id]} :command
|
||||||
:keys [chat-id address]
|
:keys [chat-id address]
|
||||||
:as orig-params}]
|
:as orig-params}]
|
||||||
|
@ -321,7 +317,7 @@
|
||||||
jail-params {:parameters params
|
jail-params {:parameters params
|
||||||
:context (cond-> {:from address
|
:context (cond-> {:from address
|
||||||
:to to
|
:to to
|
||||||
:current-account (get accounts current-account-id)
|
:current-account (get db :account/account)
|
||||||
:message-id id}
|
:message-id id}
|
||||||
(:async-handler command)
|
(:async-handler command)
|
||||||
(assoc :orig-params orig-params))}]
|
(assoc :orig-params orig-params))}]
|
||||||
|
|
|
@ -157,7 +157,7 @@
|
||||||
(cond-> {:db (add-jail-result db jail-id result)
|
(cond-> {:db (add-jail-result db jail-id result)
|
||||||
:call-jail-function {:chat-id jail-id
|
:call-jail-function {:chat-id jail-id
|
||||||
:function :init :context
|
:function :init :context
|
||||||
{:from (:accounts/current-account-id db)}}}
|
{:from (get-in db [:account/account :address])}}}
|
||||||
(seq jail-loaded-events)
|
(seq jail-loaded-events)
|
||||||
(-> (assoc :dispatch-n jail-loaded-events)
|
(-> (assoc :dispatch-n jail-loaded-events)
|
||||||
(update-in [:db :contacts/contacts jail-id] dissoc :jail-loaded-events)))))))
|
(update-in [:db :contacts/contacts jail-id] dissoc :jail-loaded-events)))))))
|
||||||
|
|
|
@ -91,8 +91,8 @@
|
||||||
:text "Command has been executed."}))
|
:text "Command has been executed."}))
|
||||||
|
|
||||||
(defn switch-node
|
(defn switch-node
|
||||||
[{:accounts/keys [current-account-id]} {:keys [url]}]
|
[{:keys [account/account]} {:keys [url]}]
|
||||||
(re-frame/dispatch [:initialize-protocol current-account-id url])
|
(re-frame/dispatch [:initialize-protocol (:address account) url])
|
||||||
(respond {:type :ok
|
(respond {:type :ok
|
||||||
:text "You've successfully switched the node."}))
|
:text "You've successfully switched the node."}))
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
- (optionally) initializing offline inboxing"
|
- (optionally) initializing offline inboxing"
|
||||||
[current-account-id {:keys [db web3] :as cofx}]
|
[current-account-id {:keys [db web3] :as cofx}]
|
||||||
(log/debug :init-whisper)
|
(log/debug :init-whisper)
|
||||||
(when-let [public-key (get-in db [:accounts/accounts current-account-id :public-key])]
|
(when-let [public-key (get-in db [:account/account :public-key])]
|
||||||
(let [sym-key-added-callback (fn [chat-id sym-key sym-key-id]
|
(let [sym-key-added-callback (fn [chat-id sym-key sym-key-id]
|
||||||
(re-frame/dispatch [::sym-key-added {:chat-id chat-id
|
(re-frame/dispatch [::sym-key-added {:chat-id chat-id
|
||||||
:sym-key sym-key
|
:sym-key sym-key
|
||||||
|
|
|
@ -36,9 +36,9 @@
|
||||||
(error-fn error)
|
(error-fn error)
|
||||||
(success-fn result)))))
|
(success-fn result)))))
|
||||||
|
|
||||||
(defn get-current-wnode-address [{:accounts/keys [current-account-id accounts] :as db}]
|
(defn get-current-wnode-address [db]
|
||||||
(let [network (ethereum/network->chain-keyword (get db :network))
|
(let [network (ethereum/network->chain-keyword (get db :network))
|
||||||
wnode-id (get-in accounts [current-account-id :settings :wnode network])]
|
wnode-id (get-in db [:account/account :settings :wnode network])]
|
||||||
(get-in db [:inbox/wnodes network wnode-id :address])))
|
(get-in db [:inbox/wnodes network wnode-id :address])))
|
||||||
|
|
||||||
(defn initialize-offline-inbox
|
(defn initialize-offline-inbox
|
||||||
|
|
|
@ -42,12 +42,11 @@
|
||||||
|
|
||||||
(spec/def :accounts/accounts (spec/nilable (spec/map-of :account/address :accounts/account)))
|
(spec/def :accounts/accounts (spec/nilable (spec/map-of :account/address :accounts/account)))
|
||||||
|
|
||||||
;;id of logged in account
|
|
||||||
(spec/def :accounts/current-account-id (spec/nilable string?))
|
|
||||||
|
|
||||||
;;used during creating account
|
;;used during creating account
|
||||||
(spec/def :accounts/create (spec/nilable map?))
|
(spec/def :accounts/create (spec/nilable map?))
|
||||||
;;used during recovering account
|
;;used during recovering account
|
||||||
(spec/def :accounts/recover (spec/nilable map?))
|
(spec/def :accounts/recover (spec/nilable map?))
|
||||||
;;used during logging
|
;;used during logging
|
||||||
(spec/def :accounts/login (spec/nilable map?))
|
(spec/def :accounts/login (spec/nilable map?))
|
||||||
|
;;logged in account
|
||||||
|
(spec/def :account/account (spec/nilable :accounts/account))
|
||||||
|
|
|
@ -106,11 +106,9 @@
|
||||||
{:db (assoc-in db [:accounts/accounts id] new-account)
|
{:db (assoc-in db [:accounts/accounts id] new-account)
|
||||||
:data-store/save-account new-account})))
|
:data-store/save-account new-account})))
|
||||||
|
|
||||||
(defn update-settings [settings {:keys [db] :as cofx}]
|
(defn update-settings [settings {{:keys [account/account] :as db} :db :as cofx}]
|
||||||
(let [{:accounts/keys [current-account-id accounts]} db
|
(let [new-account (assoc account :settings settings)]
|
||||||
new-account (-> (get accounts current-account-id)
|
{:db (assoc db :account/account new-account)
|
||||||
(assoc :settings settings))]
|
|
||||||
{:db (assoc-in db [:accounts/accounts current-account-id] new-account)
|
|
||||||
:data-store/save-account new-account}))
|
:data-store/save-account new-account}))
|
||||||
|
|
||||||
(defn account-update
|
(defn account-update
|
||||||
|
@ -118,10 +116,10 @@
|
||||||
Optionally, one can specify event to be dispatched after fields are persisted."
|
Optionally, one can specify event to be dispatched after fields are persisted."
|
||||||
([new-account-fields cofx]
|
([new-account-fields cofx]
|
||||||
(account-update new-account-fields nil cofx))
|
(account-update new-account-fields nil cofx))
|
||||||
([new-account-fields after-update-event {{:accounts/keys [accounts current-account-id] :as db} :db :as cofx}]
|
([new-account-fields after-update-event {:keys [db] :as cofx}]
|
||||||
(let [current-account (get accounts current-account-id)
|
(let [current-account (:account/account db)
|
||||||
new-account (merge current-account new-account-fields)
|
new-account (merge current-account new-account-fields)
|
||||||
fx {:db (assoc-in db [:accounts/accounts current-account-id] new-account)
|
fx {:db (assoc db :account/account new-account)
|
||||||
:data-store/save-account (assoc new-account :after-update-event after-update-event)}
|
:data-store/save-account (assoc new-account :after-update-event after-update-event)}
|
||||||
{:keys [name photo-path]} new-account]
|
{:keys [name photo-path]} new-account]
|
||||||
(if (or (:name new-account-fields) (:photo-path new-account-fields))
|
(if (or (:name new-account-fields) (:photo-path new-account-fields))
|
||||||
|
@ -130,8 +128,8 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:send-account-update-if-needed
|
:send-account-update-if-needed
|
||||||
(fn [{{:accounts/keys [accounts current-account-id] :as db} :db now :now :as cofx} _]
|
(fn [{:keys [db now] :as cofx} _]
|
||||||
(let [{:keys [last-updated]} (get accounts current-account-id)
|
(let [{:keys [last-updated]} (:account/account db)
|
||||||
needs-update? (> (- now last-updated) time/week)]
|
needs-update? (> (- now last-updated) time/week)]
|
||||||
(log/info "Need to send account-update: " needs-update?)
|
(log/info "Need to send account-update: " needs-update?)
|
||||||
(when needs-update?
|
(when needs-update?
|
||||||
|
|
|
@ -13,19 +13,13 @@
|
||||||
(fn [db]
|
(fn [db]
|
||||||
(:accounts/accounts db)))
|
(:accounts/accounts db)))
|
||||||
|
|
||||||
(reg-sub :get-current-account-id
|
|
||||||
(fn [db]
|
|
||||||
(:accounts/current-account-id db)))
|
|
||||||
|
|
||||||
(reg-sub :get-current-account
|
(reg-sub :get-current-account
|
||||||
:<- [:get-current-account-id]
|
(fn [db]
|
||||||
:<- [:get-accounts]
|
(:account/account db)))
|
||||||
(fn [[account-id accounts]]
|
|
||||||
(some-> accounts (get account-id))))
|
|
||||||
|
|
||||||
(reg-sub :get-current-account-hex
|
(reg-sub :get-current-account-hex
|
||||||
:<- [:get-current-account-id]
|
:<- [:get-current-account]
|
||||||
(fn [address]
|
(fn [{:keys [address]}]
|
||||||
(ethereum/normalized-address address)))
|
(ethereum/normalized-address address)))
|
||||||
|
|
||||||
(reg-sub
|
(reg-sub
|
||||||
|
@ -34,4 +28,4 @@
|
||||||
(let [{:keys [step password password-confirm name]} create]
|
(let [{:keys [step password password-confirm name]} create]
|
||||||
(or (and password (= :enter-password step) (spec/valid? ::db/password password))
|
(or (and password (= :enter-password step) (spec/valid? ::db/password password))
|
||||||
(and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm))
|
(and password-confirm (= :confirm-password step) (spec/valid? ::db/password password-confirm))
|
||||||
(and name (= :enter-name step) (not (string/blank? name)))))))
|
(and name (= :enter-name step) (not (string/blank? name)))))))
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
(assoc-in [:contacts/new-identity] ""))
|
(assoc-in [:contacts/new-identity] ""))
|
||||||
:data-store/save-contact new-contact}))
|
:data-store/save-contact new-contact}))
|
||||||
|
|
||||||
(defn- own-info [{:accounts/keys [accounts current-account-id] :as db}]
|
(defn- own-info [db]
|
||||||
(let [{:keys [name photo-path address]} (get accounts current-account-id)
|
(let [{:keys [name photo-path address]} (:account/account db)
|
||||||
fcm-token (get-in db [:notifications :fcm-token])]
|
fcm-token (get-in db [:notifications :fcm-token])]
|
||||||
{:name name
|
{:name name
|
||||||
:profile-image photo-path
|
:profile-image photo-path
|
||||||
|
@ -82,8 +82,8 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:set-contact-identity-from-qr
|
:set-contact-identity-from-qr
|
||||||
[(re-frame/inject-cofx :random-id)]
|
[(re-frame/inject-cofx :random-id)]
|
||||||
(fn [{{:accounts/keys [accounts current-account-id] :as db} :db :as cofx} [_ _ contact-identity]]
|
(fn [{:keys [db] :as cofx} [_ _ contact-identity]]
|
||||||
(let [current-account (get accounts current-account-id)
|
(let [current-account (:account/account db)
|
||||||
fx {:db (assoc db :contacts/new-identity contact-identity)}]
|
fx {:db (assoc db :contacts/new-identity contact-identity)}]
|
||||||
(if (new-chat.db/validate-pub-key contact-identity current-account)
|
(if (new-chat.db/validate-pub-key contact-identity current-account)
|
||||||
fx
|
fx
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG)
|
:status-module-initialized? (or platform/ios? js/goog.DEBUG)
|
||||||
:keyboard-height 0
|
:keyboard-height 0
|
||||||
:tab-bar-visible? true
|
:tab-bar-visible? true
|
||||||
:accounts/accounts {}
|
|
||||||
:navigation-stack '()
|
:navigation-stack '()
|
||||||
:contacts/contacts {}
|
:contacts/contacts {}
|
||||||
:qr-codes {}
|
:qr-codes {}
|
||||||
|
@ -151,9 +150,9 @@
|
||||||
:group/groups-order
|
:group/groups-order
|
||||||
:accounts/accounts
|
:accounts/accounts
|
||||||
:accounts/create
|
:accounts/create
|
||||||
:accounts/current-account-id
|
|
||||||
:accounts/recover
|
:accounts/recover
|
||||||
:accounts/login
|
:accounts/login
|
||||||
|
:account/account
|
||||||
:my-profile/profile
|
:my-profile/profile
|
||||||
:my-profile/default-name
|
:my-profile/default-name
|
||||||
:my-profile/editing?
|
:my-profile/editing?
|
||||||
|
|
|
@ -213,8 +213,8 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:logout
|
:logout
|
||||||
(fn [{:keys [db] :as cofx} _]
|
(fn [{:keys [db] :as cofx} _]
|
||||||
(let [{:transport/keys [chats] :keys [current-account-id]} db
|
(let [{:transport/keys [chats]} db
|
||||||
sharing-usage-data? (get-in db [:accounts/accounts current-account-id :sharing-usage-data?])]
|
sharing-usage-data? (get-in db [:account/account :sharing-usage-data?])]
|
||||||
(handlers-macro/merge-fx cofx
|
(handlers-macro/merge-fx cofx
|
||||||
{:dispatch-n (concat [[:initialize-db]
|
{:dispatch-n (concat [[:initialize-db]
|
||||||
[:load-accounts]
|
[:load-accounts]
|
||||||
|
@ -231,7 +231,6 @@
|
||||||
:or {network (get app-db :network)}} :db} _]
|
:or {network (get app-db :network)}} :db} _]
|
||||||
{::init-store nil
|
{::init-store nil
|
||||||
:db (assoc app-db
|
:db (assoc app-db
|
||||||
:accounts/current-account-id nil
|
|
||||||
:contacts/contacts {}
|
:contacts/contacts {}
|
||||||
:network-status network-status
|
:network-status network-status
|
||||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||||
|
@ -244,22 +243,19 @@
|
||||||
network network-status view-id navigation-stack
|
network network-status view-id navigation-stack
|
||||||
access-scope->commands-responses
|
access-scope->commands-responses
|
||||||
status-module-initialized? status-node-started?]
|
status-module-initialized? status-node-started?]
|
||||||
:or [network (get app-db :network)]} [_ address]]
|
:or [network (get app-db :network)]} [_ address]]
|
||||||
(let [console-contact (get contacts constants/console-chat-id)]
|
(let [console-contact (get contacts constants/console-chat-id)
|
||||||
|
current-account (accounts address)]
|
||||||
(cond-> (assoc app-db
|
(cond-> (assoc app-db
|
||||||
:access-scope->commands-responses access-scope->commands-responses
|
:access-scope->commands-responses access-scope->commands-responses
|
||||||
:accounts/current-account-id address
|
:current-public-key (:public-key current-account)
|
||||||
;; TODO (yenda) bad, this is derived data and shouldn't be stored in the db
|
|
||||||
;; the cost of retrieving public key from db with a function taking using
|
|
||||||
;; current-account-id is negligeable
|
|
||||||
:current-public-key (:public-key (accounts address))
|
|
||||||
:view-id view-id
|
:view-id view-id
|
||||||
:navigation-stack navigation-stack
|
:navigation-stack navigation-stack
|
||||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||||
:status-node-started? status-node-started?
|
:status-node-started? status-node-started?
|
||||||
:accounts/accounts accounts
|
|
||||||
:accounts/create create
|
:accounts/create create
|
||||||
:networks/networks networks
|
:networks/networks networks
|
||||||
|
:account/account current-account
|
||||||
:network-status network-status
|
:network-status network-status
|
||||||
:network network)
|
:network network)
|
||||||
console-contact
|
console-contact
|
||||||
|
@ -301,10 +297,9 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:initialize-geth
|
:initialize-geth
|
||||||
(fn [{db :db} _]
|
(fn [{db :db} _]
|
||||||
(let [{:accounts/keys [current-account-id accounts]} db
|
(let [default-networks (:networks/networks db)
|
||||||
default-networks (:networks/networks db)
|
|
||||||
default-network (:network db)
|
default-network (:network db)
|
||||||
{:keys [network networks]} (get accounts current-account-id)
|
{:keys [network networks]} (:account/account db)
|
||||||
network-config (or (get-in networks [network :config])
|
network-config (or (get-in networks [network :config])
|
||||||
(get-in default-networks [default-network :config]))]
|
(get-in default-networks [default-network :config]))]
|
||||||
{:initialize-geth-fx network-config})))
|
{:initialize-geth-fx network-config})))
|
||||||
|
|
|
@ -43,10 +43,11 @@
|
||||||
chats (:transport/chats db)]
|
chats (:transport/chats db)]
|
||||||
(if (utils/network-with-upstream-rpc? networks current-network)
|
(if (utils/network-with-upstream-rpc? networks current-network)
|
||||||
(handlers-macro/merge-fx cofx
|
(handlers-macro/merge-fx cofx
|
||||||
{:dispatch [:navigate-to-clean :accounts]}
|
{:dispatch-n [[:load-accounts]
|
||||||
(transport/stop-whisper)
|
[:navigate-to-clean :accounts]]}
|
||||||
(accounts-events/account-update {:network network
|
(transport/stop-whisper)
|
||||||
:last-updated now}))
|
(accounts-events/account-update {:network network
|
||||||
|
:last-updated now}))
|
||||||
{:show-confirmation {:title (i18n/label :t/close-app-title)
|
{:show-confirmation {:title (i18n/label :t/close-app-title)
|
||||||
:content (i18n/label :t/close-app-content)
|
:content (i18n/label :t/close-app-content)
|
||||||
:confirm-button-text (i18n/label :t/close-app-button)
|
:confirm-button-text (i18n/label :t/close-app-button)
|
||||||
|
|
|
@ -10,12 +10,11 @@
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
::save-wnode
|
::save-wnode
|
||||||
(fn [{:keys [db now] :as cofx} [_ wnode]]
|
(fn [{:keys [db now] :as cofx} [_ wnode]]
|
||||||
(let [{:accounts/keys [current-account-id accounts]} db
|
(let [network (ethereum/network->chain-keyword (:network db))
|
||||||
network (ethereum/network->chain-keyword (:network db))
|
settings (get-in db [:account/account :settings])]
|
||||||
settings (get-in accounts [current-account-id :settings])]
|
|
||||||
(handlers-macro/merge-fx cofx
|
(handlers-macro/merge-fx cofx
|
||||||
{:dispatch [:logout]}
|
{:dispatch [:logout]}
|
||||||
(accounts-events/update-settings (assoc-in settings [:wnode network] wnode))))))
|
(accounts-events/update-settings (assoc-in settings [:wnode network] wnode))))))
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:connect-wnode
|
:connect-wnode
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
(chat-events/start-chat chat-id {:navigation-replace? true})
|
(chat-events/start-chat chat-id {:navigation-replace? true})
|
||||||
(input-events/select-chat-input-command send-command nil true)))))
|
(input-events/select-chat-input-command send-command nil true)))))
|
||||||
|
|
||||||
(defn get-current-account [{:accounts/keys [current-account-id] :as db}]
|
(defn get-current-account [db]
|
||||||
(get-in db [:accounts/accounts current-account-id]))
|
(:account/account db))
|
||||||
|
|
||||||
(defn valid-name? [name]
|
(defn valid-name? [name]
|
||||||
(spec/valid? :profile/name name))
|
(spec/valid? :profile/name name))
|
||||||
|
@ -55,11 +55,11 @@
|
||||||
{:db (assoc-in db [:my-profile/profile :photo-path] (str "data:image/jpeg;base64," base64-image))}
|
{:db (assoc-in db [:my-profile/profile :photo-path] (str "data:image/jpeg;base64," base64-image))}
|
||||||
{:open-image-picker this-event})))
|
{:open-image-picker this-event})))
|
||||||
|
|
||||||
(defn clean-name [{:accounts/keys [current-account-id] :as db} edit-view]
|
(defn clean-name [db edit-view]
|
||||||
(let [name (get-in db [edit-view :name])]
|
(let [name (get-in db [edit-view :name])]
|
||||||
(if (valid-name? name)
|
(if (valid-name? name)
|
||||||
name
|
name
|
||||||
(get-in db [:accounts/accounts current-account-id :name]))))
|
(get-in db [:account/account :name]))))
|
||||||
|
|
||||||
(defn clear-profile [{:keys [db] :as cofx}]
|
(defn clear-profile [{:keys [db] :as cofx}]
|
||||||
{:db (dissoc db :my-profile/profile :my-profile/default-name :my-profile/editing?)})
|
{:db (dissoc db :my-profile/profile :my-profile/default-name :my-profile/editing?)})
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
;;TODO(goranjovic) - replace this with an atomic navigation event that calls functions, not dispatch
|
;;TODO(goranjovic) - replace this with an atomic navigation event that calls functions, not dispatch
|
||||||
;; possibly use the generic event, see https://github.com/status-im/status-react/issues/2987
|
;; possibly use the generic event, see https://github.com/status-im/status-react/issues/2987
|
||||||
(defmethod navigation/preload-data! :profile-qr-viewer
|
(defmethod navigation/preload-data! :profile-qr-viewer
|
||||||
[{:accounts/keys [current-account-id] :as db} [_ _ {:keys [contact source value]}]]
|
[db [_ _ {:keys [contact source value]}]]
|
||||||
(update db :qr-modal #(merge % {:contact (or contact (get-in db [:accounts/accounts current-account-id]))
|
(update db :qr-modal #(merge % {:contact (or contact (get db :account/account))
|
||||||
:source source
|
:source source
|
||||||
:value value})))
|
:value value})))
|
||||||
|
|
||||||
(defmethod navigation/preload-data! :backup-seed
|
(defmethod navigation/preload-data! :backup-seed
|
||||||
[db]
|
[db]
|
||||||
(assoc db :my-profile/seed {:step :intro}))
|
(assoc db :my-profile/seed {:step :intro}))
|
||||||
|
|
|
@ -93,16 +93,17 @@
|
||||||
;; Handlers
|
;; Handlers
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-wallet
|
:update-wallet
|
||||||
(fn [{{:keys [web3 accounts/current-account-id network network-status] :as db} :db} _]
|
(fn [{{:keys [web3 account/account network network-status] :as db} :db} _]
|
||||||
(let [chain (ethereum/network->chain-keyword network)
|
(let [chain (ethereum/network->chain-keyword network)
|
||||||
symbols (get-in db [:accounts/accounts current-account-id :settings :wallet :visible-tokens chain])]
|
address (:address account)
|
||||||
|
symbols (get-in account [:settings :wallet :visible-tokens chain])]
|
||||||
(when (not= network-status :offline)
|
(when (not= network-status :offline)
|
||||||
{:get-balance {:web3 web3
|
{:get-balance {:web3 web3
|
||||||
:account-id current-account-id
|
:account-id address
|
||||||
:success-event :update-balance-success
|
:success-event :update-balance-success
|
||||||
:error-event :update-balance-fail}
|
:error-event :update-balance-fail}
|
||||||
:get-tokens-balance {:web3 web3
|
:get-tokens-balance {:web3 web3
|
||||||
:account-id current-account-id
|
:account-id address
|
||||||
:symbols symbols
|
:symbols symbols
|
||||||
:chain chain
|
:chain chain
|
||||||
:success-event :update-token-balance-success
|
:success-event :update-token-balance-success
|
||||||
|
@ -119,9 +120,9 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-transactions
|
:update-transactions
|
||||||
(fn [{{:keys [accounts/current-account-id network network-status] :as db} :db} _]
|
(fn [{{:keys [network network-status] :as db} :db} _]
|
||||||
(when (not= network-status :offline)
|
(when (not= network-status :offline)
|
||||||
{:get-transactions {:account-id current-account-id
|
{:get-transactions {:account-id (get-in db [:account/account :address])
|
||||||
:network network
|
:network network
|
||||||
:success-event :update-transactions-success
|
:success-event :update-transactions-success
|
||||||
:error-event :update-transactions-fail}
|
:error-event :update-transactions-fail}
|
||||||
|
|
|
@ -232,8 +232,7 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet/sign-transaction
|
:wallet/sign-transaction
|
||||||
(fn [{{:keys [web3]
|
(fn [{{:keys [web3] :as db} :db} [_ later?]]
|
||||||
:accounts/keys [accounts current-account-id] :as db} :db} [_ later?]]
|
|
||||||
(let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false)
|
(let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false)
|
||||||
network (:network db)
|
network (:network db)
|
||||||
{:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])]
|
{:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])]
|
||||||
|
@ -247,7 +246,7 @@
|
||||||
:later? later?
|
:later? later?
|
||||||
:in-progress? true)
|
:in-progress? true)
|
||||||
::send-transaction {:web3 web3
|
::send-transaction {:web3 web3
|
||||||
:from (get-in accounts [current-account-id :address])
|
:from (get-in db [:account/account :address])
|
||||||
:to to
|
:to to
|
||||||
:value amount
|
:value amount
|
||||||
:gas gas
|
:gas gas
|
||||||
|
|
|
@ -10,8 +10,8 @@
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:wallet.settings/toggle-visible-token
|
:wallet.settings/toggle-visible-token
|
||||||
(fn [{{:keys [network] :accounts/keys [current-account-id] :as db} :db :as cofx} [_ symbol checked?]]
|
(fn [{{:keys [network account/account] :as db} :db :as cofx} [_ symbol checked?]]
|
||||||
(let [chain (ethereum/network->chain-keyword network)
|
(let [chain (ethereum/network->chain-keyword network)
|
||||||
settings (get-in db [:accounts/accounts current-account-id :settings])
|
settings (get account :settings)
|
||||||
new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))]
|
new-settings (update-in settings [:wallet :visible-tokens chain] #(toggle-checked % symbol checked?))]
|
||||||
(accounts/update-settings new-settings cofx))))
|
(accounts/update-settings new-settings cofx))))
|
||||||
|
|
|
@ -91,10 +91,8 @@
|
||||||
(fn track-handler
|
(fn track-handler
|
||||||
[context]
|
[context]
|
||||||
(let [new-db (get-coeffect context :db)
|
(let [new-db (get-coeffect context :db)
|
||||||
current-account-id (:accounts/current-account-id new-db)]
|
current-account-id (get-in new-db [:account/account :address])]
|
||||||
(when (get-in new-db [:accounts/accounts
|
(when (get-in new-db [:account/account :sharing-usage-data?])
|
||||||
current-account-id
|
|
||||||
:sharing-usage-data?])
|
|
||||||
(let [event (get-coeffect context :event)
|
(let [event (get-coeffect context :event)
|
||||||
offline? (or (= :offline (:network-status new-db))
|
offline? (or (= :offline (:network-status new-db))
|
||||||
(= :offline (:sync-state new-db)))
|
(= :offline (:sync-state new-db)))
|
||||||
|
|
|
@ -21,8 +21,7 @@
|
||||||
(is (not fx))))
|
(is (not fx))))
|
||||||
|
|
||||||
(testing "initialising console without existing account and console chat not initialisated"
|
(testing "initialising console without existing account and console chat not initialisated"
|
||||||
(let [fresh-db {:chats {}
|
(let [fresh-db {:chats {}}
|
||||||
:accounts/current-account-id nil}
|
|
||||||
{:keys [db dispatch-n]} (chat-events/init-console-chat {:db fresh-db})]
|
{:keys [db dispatch-n]} (chat-events/init-console-chat {:db fresh-db})]
|
||||||
(is (= (:current-chat-id db)
|
(is (= (:current-chat-id db)
|
||||||
(:chat-id console-chat/chat)))
|
(:chat-id console-chat/chat)))
|
||||||
|
@ -30,8 +29,7 @@
|
||||||
const/console-chat-id))))
|
const/console-chat-id))))
|
||||||
|
|
||||||
(testing "initialising console with existing account and console chat not initialisated"
|
(testing "initialising console with existing account and console chat not initialisated"
|
||||||
(let [fresh-db {:chats {}
|
(let [fresh-db {:chats {}}
|
||||||
:accounts/current-account-id (:whisper-identity contact)}
|
|
||||||
{:keys [db dispatch-n]} (chat-events/init-console-chat {:db fresh-db})]
|
{:keys [db dispatch-n]} (chat-events/init-console-chat {:db fresh-db})]
|
||||||
(is (= (:current-chat-id db)
|
(is (= (:current-chat-id db)
|
||||||
(:chat-id console-chat/chat)))
|
(:chat-id console-chat/chat)))
|
||||||
|
|
Loading…
Reference in New Issue