refactor :initialize-account into single event
fix tests for :initialize-account refactoring fix destructuring typo
This commit is contained in:
parent
198596d5e6
commit
002f3e73d1
|
@ -1,29 +1,23 @@
|
|||
(ns status-im.chat.events
|
||||
(:require [clojure.set :as set]
|
||||
(:require status-im.chat.events.input
|
||||
status-im.chat.events.requests
|
||||
status-im.chat.events.send-message
|
||||
status-im.chat.events.receive-message
|
||||
[clojure.string :as string]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.chat.models :as models]
|
||||
[status-im.chat.models.message :as models.message]
|
||||
[status-im.chat.commands.core :as commands]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.data-store.user-statuses :as user-statuses-store]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.transport.message.core :as transport.message]
|
||||
[status-im.transport.message.v1.group-chat :as group-chat]
|
||||
[status-im.transport.message.v1.protocol :as protocol]
|
||||
[status-im.transport.message.v1.public-chat :as public-chat]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.contacts :as utils.contacts]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.transport.message.core :as transport.message]
|
||||
[status-im.transport.message.v1.protocol :as protocol]
|
||||
[status-im.transport.message.v1.public-chat :as public-chat]
|
||||
[status-im.transport.message.v1.group-chat :as group-chat]
|
||||
[status-im.data-store.chats :as chats-store]
|
||||
[status-im.data-store.messages :as messages-store]
|
||||
[status-im.data-store.user-statuses :as user-statuses-store]
|
||||
[status-im.data-store.contacts :as contacts-store]
|
||||
status-im.chat.events.input
|
||||
status-im.chat.events.requests
|
||||
status-im.chat.events.send-message
|
||||
status-im.chat.events.receive-message))
|
||||
[status-im.utils.utils :as utils]))
|
||||
|
||||
;;;; Effects
|
||||
|
||||
|
@ -84,105 +78,6 @@
|
|||
new-status)
|
||||
:data-store/tx [(user-statuses-store/save-status-tx new-status)]})))
|
||||
|
||||
;; Change status of own messages which are still in "sending" status to "not-sent"
|
||||
;; (If signal from status-go has not been received)
|
||||
(handlers/register-handler-fx
|
||||
:process-pending-messages
|
||||
[re-frame/trim-v]
|
||||
(fn [{:keys [db]} []]
|
||||
(let [me (:current-public-key db)
|
||||
pending-statuses (->> (vals (:chats db))
|
||||
(mapcat :message-statuses)
|
||||
(mapcat (fn [[_ user-id->status]]
|
||||
(filter (comp (partial = :sending) :status)
|
||||
(get user-id->status me)))))
|
||||
updated-statuses (map #(assoc % :status :not-sent) pending-statuses)]
|
||||
{:data-store/tx [(user-statuses-store/save-statuses-tx updated-statuses)]
|
||||
:db (reduce
|
||||
(fn [acc {:keys [chat-id message-id status whisper-identity]}]
|
||||
(assoc-in acc
|
||||
[:chats chat-id :message-status message-id
|
||||
whisper-identity :status]
|
||||
status))
|
||||
db
|
||||
updated-statuses)})))
|
||||
|
||||
(defn- add-default-contacts
|
||||
[{:keys [db default-contacts] :as cofx}]
|
||||
(let [new-contacts (-> {}
|
||||
(into (map (fn [[id props]]
|
||||
(let [contact-id (name id)]
|
||||
[contact-id {:whisper-identity contact-id
|
||||
:address (utils.contacts/public-key->address contact-id)
|
||||
:name (-> props :name :en)
|
||||
:photo-path (:photo-path props)
|
||||
:public-key (:public-key props)
|
||||
:unremovable? (-> props :unremovable? boolean)
|
||||
:hide-contact? (-> props :hide-contact? boolean)
|
||||
:pending? (-> props :pending? boolean)
|
||||
:dapp? (:dapp? props)
|
||||
:dapp-url (-> props :dapp-url :en)
|
||||
:bot-url (:bot-url props)
|
||||
:description (:description props)}])))
|
||||
default-contacts))
|
||||
existing-contacts (:contacts/contacts db)
|
||||
contacts-to-add (select-keys new-contacts (set/difference (set (keys new-contacts))
|
||||
(set (keys existing-contacts))))]
|
||||
{:db (update db :contacts/contacts merge contacts-to-add)
|
||||
:data-store/tx [(contacts-store/save-contacts-tx (vals contacts-to-add))]}))
|
||||
|
||||
(defn- group-chat-messages
|
||||
[{:keys [db]}]
|
||||
(reduce-kv (fn [fx chat-id {:keys [messages]}]
|
||||
(models.message/group-messages chat-id (vals messages) fx))
|
||||
{:db db}
|
||||
(:chats db)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:initialize-chats
|
||||
[(re-frame/inject-cofx :get-default-contacts)
|
||||
(re-frame/inject-cofx :get-default-dapps)
|
||||
(re-frame/inject-cofx :data-store/all-chats)
|
||||
(re-frame/inject-cofx :data-store/get-messages)
|
||||
(re-frame/inject-cofx :data-store/get-user-statuses)
|
||||
(re-frame/inject-cofx :data-store/unviewed-messages)
|
||||
(re-frame/inject-cofx :data-store/message-ids)
|
||||
(re-frame/inject-cofx :data-store/get-unanswered-requests)
|
||||
(re-frame/inject-cofx :data-store/get-local-storage-data)]
|
||||
(fn [{:keys [db
|
||||
default-dapps
|
||||
all-stored-chats
|
||||
stored-unanswered-requests
|
||||
get-stored-messages
|
||||
get-stored-user-statuses
|
||||
stored-unviewed-messages
|
||||
stored-message-ids] :as cofx} _]
|
||||
(let [chat->message-id->request (reduce (fn [acc {:keys [chat-id message-id] :as request}]
|
||||
(assoc-in acc [chat-id message-id] request))
|
||||
{}
|
||||
stored-unanswered-requests)
|
||||
chats (reduce (fn [acc {:keys [chat-id] :as chat}]
|
||||
(let [chat-messages (index-messages (get-stored-messages chat-id))
|
||||
message-ids (keys chat-messages)
|
||||
unviewed-ids (get stored-unviewed-messages chat-id)]
|
||||
(assoc acc chat-id
|
||||
(assoc chat
|
||||
:unviewed-messages unviewed-ids
|
||||
:requests (get chat->message-id->request chat-id)
|
||||
:messages chat-messages
|
||||
:message-statuses (get-stored-user-statuses chat-id message-ids)
|
||||
:not-loaded-message-ids (set/difference (get stored-message-ids chat-id)
|
||||
(set message-ids))))))
|
||||
{}
|
||||
all-stored-chats)]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc db
|
||||
:chats chats
|
||||
:contacts/dapps default-dapps)}
|
||||
(group-chat-messages)
|
||||
(add-default-contacts)
|
||||
(commands/index-commands commands/register)))))
|
||||
|
||||
(defn- send-messages-seen [chat-id message-ids {:keys [db] :as cofx}]
|
||||
(when (and (not (get-in db [:chats chat-id :public?]))
|
||||
(not (models/bot-only-chat? db chat-id)))
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
(ns status-im.chat.models
|
||||
(:require [status-im.ui.components.styles :as styles]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.clocks :as utils.clocks]
|
||||
(:require [status-im.data-store.chats :as chats-store]
|
||||
[status-im.data-store.messages :as messages-store]
|
||||
[status-im.transport.message.core :as transport.message]
|
||||
[status-im.data-store.chats :as chats-store]
|
||||
[status-im.transport.message.v1.group-chat :as transport.group-chat]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.ui.components.styles :as styles]
|
||||
[status-im.utils.clocks :as utils.clocks]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.data-store.messages :as messages-store]))
|
||||
[status-im.utils.platform :as platform]))
|
||||
|
||||
(defn multi-user-chat? [chat-id cofx]
|
||||
(get-in cofx [:db :chats chat-id :group-chat]))
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
(ns status-im.models.account)
|
||||
(ns status-im.models.account
|
||||
(:require [status-im.ui.screens.accounts.utils :as accounts.utils]))
|
||||
|
||||
(defn logged-in? [cofx]
|
||||
(boolean
|
||||
(get-in cofx [:db :account/account])))
|
||||
|
||||
(defn update-sign-in-time
|
||||
[{db :db now :now :as cofx}]
|
||||
(accounts.utils/account-update {:last-sign-in now} cofx))
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
(ns status-im.models.bootnode
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.ethereum.core :as ethereum]))
|
||||
(:require [clojure.string :as string]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(def address-regex #"enode://[a-zA-Z0-9]+:?(.*)\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})")
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
(ns status-im.models.browser
|
||||
(:require [status-im.data-store.browser :as browser-store]
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.data-store.browser :as browser-store]
|
||||
[status-im.data-store.dapp-permissions :as dapp-permissions]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.ui.screens.browser.default-dapps :as default-dapps]
|
||||
[status-im.utils.http :as http]
|
||||
[re-frame.core :as re-frame]))
|
||||
[status-im.utils.http :as http]))
|
||||
|
||||
(defn get-current-url [{:keys [history history-index]}]
|
||||
(when (and history-index history)
|
||||
|
@ -108,3 +108,13 @@
|
|||
:messageId message-id
|
||||
:error %1
|
||||
:result %2}])]}))
|
||||
|
||||
(defn initialize-browsers
|
||||
[{:keys [db all-stored-browsers]}]
|
||||
(let [browsers (into {} (map #(vector (:browser-id %) %) all-stored-browsers))]
|
||||
{:db (assoc db :browser/browsers browsers)}))
|
||||
|
||||
(defn initialize-dapp-permissions
|
||||
[{:keys [db all-dapp-permissions]}]
|
||||
(let [dapp-permissions (into {} (map #(vector (:dapp %) %) all-dapp-permissions))]
|
||||
{:db (assoc db :dapps/permissions dapp-permissions)}))
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
(ns status-im.models.chat
|
||||
(:require [clojure.set :as set]
|
||||
[status-im.chat.commands.core :as commands]
|
||||
[status-im.chat.models.message :as models.message]
|
||||
[status-im.data-store.contacts :as contacts-store]
|
||||
[status-im.data-store.user-statuses :as user-statuses-store]
|
||||
[status-im.utils.contacts :as utils.contacts]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(def index-messages (partial into {} (map (juxt :message-id identity))))
|
||||
|
||||
(defn- add-default-contacts
|
||||
[{:keys [db default-contacts] :as cofx}]
|
||||
(let [new-contacts (-> {}
|
||||
(into (map (fn [[id props]]
|
||||
(let [contact-id (name id)]
|
||||
[contact-id {:whisper-identity contact-id
|
||||
:address (utils.contacts/public-key->address contact-id)
|
||||
:name (-> props :name :en)
|
||||
:photo-path (:photo-path props)
|
||||
:public-key (:public-key props)
|
||||
:unremovable? (-> props :unremovable? boolean)
|
||||
:hide-contact? (-> props :hide-contact? boolean)
|
||||
:pending? (-> props :pending? boolean)
|
||||
:dapp? (:dapp? props)
|
||||
:dapp-url (-> props :dapp-url :en)
|
||||
:bot-url (:bot-url props)
|
||||
:description (:description props)}])))
|
||||
default-contacts))
|
||||
existing-contacts (:contacts/contacts db)
|
||||
contacts-to-add (select-keys new-contacts (set/difference (set (keys new-contacts))
|
||||
(set (keys existing-contacts))))]
|
||||
{:db (update db :contacts/contacts merge contacts-to-add)
|
||||
:data-store/tx [(contacts-store/save-contacts-tx (vals contacts-to-add))]}))
|
||||
|
||||
(defn- group-chat-messages
|
||||
[{:keys [db]}]
|
||||
(reduce-kv (fn [fx chat-id {:keys [messages]}]
|
||||
(models.message/group-messages chat-id (vals messages) fx))
|
||||
{:db db}
|
||||
(:chats db)))
|
||||
|
||||
(defn initialize-chats [{:keys [db
|
||||
default-dapps
|
||||
all-stored-chats
|
||||
stored-unanswered-requests
|
||||
get-stored-messages
|
||||
get-stored-user-statuses
|
||||
stored-unviewed-messages
|
||||
stored-message-ids] :as cofx}]
|
||||
(let [chat->message-id->request (reduce (fn [acc {:keys [chat-id message-id] :as request}]
|
||||
(assoc-in acc [chat-id message-id] request))
|
||||
{}
|
||||
stored-unanswered-requests)
|
||||
chats (reduce (fn [acc {:keys [chat-id] :as chat}]
|
||||
(let [chat-messages (index-messages (get-stored-messages chat-id))
|
||||
message-ids (keys chat-messages)
|
||||
unviewed-ids (get stored-unviewed-messages chat-id)]
|
||||
(assoc acc chat-id
|
||||
(assoc chat
|
||||
:unviewed-messages unviewed-ids
|
||||
:requests (get chat->message-id->request chat-id)
|
||||
:messages chat-messages
|
||||
:message-statuses (get-stored-user-statuses chat-id message-ids)
|
||||
:not-loaded-message-ids (set/difference (get stored-message-ids chat-id)
|
||||
(set message-ids))))))
|
||||
{}
|
||||
all-stored-chats)]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc db
|
||||
:chats chats
|
||||
:contacts/dapps default-dapps)}
|
||||
(group-chat-messages)
|
||||
(add-default-contacts)
|
||||
(commands/index-commands commands/register))))
|
||||
|
||||
(defn process-pending-messages
|
||||
"Change status of own messages which are still in `sending` status to `not-sent`
|
||||
(If signal from status-go has not been received)"
|
||||
[{:keys [db]}]
|
||||
(let [me (:current-public-key db)
|
||||
pending-statuses (->> (vals (:chats db))
|
||||
(mapcat :message-statuses)
|
||||
(mapcat (fn [[_ user-id->status]]
|
||||
(filter (comp (partial = :sending) :status)
|
||||
(get user-id->status me)))))
|
||||
updated-statuses (map #(assoc % :status :not-sent) pending-statuses)]
|
||||
{:data-store/tx [(user-statuses-store/save-statuses-tx updated-statuses)]
|
||||
:db (reduce
|
||||
(fn [acc {:keys [chat-id message-id status whisper-identity]}]
|
||||
(assoc-in acc
|
||||
[:chats chat-id :message-status message-id
|
||||
whisper-identity :status]
|
||||
status))
|
||||
db
|
||||
updated-statuses)}))
|
|
@ -1,10 +1,9 @@
|
|||
(ns status-im.models.contact
|
||||
(:require
|
||||
[status-im.utils.contacts :as utils.contacts]
|
||||
[status-im.data-store.contacts :as contacts-store]
|
||||
[status-im.transport.message.core :as transport]
|
||||
[status-im.transport.message.v1.contact :as message.v1.contact]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
(:require [status-im.data-store.contacts :as contacts-store]
|
||||
[status-im.transport.message.core :as transport]
|
||||
[status-im.transport.message.v1.contact :as message.v1.contact]
|
||||
[status-im.utils.contacts :as utils.contacts]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(defn can-add-to-contacts? [{:keys [pending? dapp?]}]
|
||||
(and (not dapp?)
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
(ns status-im.models.contacts)
|
||||
|
||||
(defn load-contacts
|
||||
[{:keys [db all-contacts]}]
|
||||
(let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts)
|
||||
contacts (into {} contacts-list)]
|
||||
{:db (update db :contacts/contacts #(merge contacts %))}))
|
|
@ -1,10 +1,9 @@
|
|||
(ns status-im.models.mailserver
|
||||
(:require
|
||||
[clojure.string :as string]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.models.network :as models.network]
|
||||
[status-im.data-store.mailservers :as data-store.mailservers]))
|
||||
(:require [clojure.string :as string]
|
||||
[status-im.data-store.mailservers :as data-store.mailservers]
|
||||
[status-im.models.network :as models.network]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(def enode-address-regex #"enode://[a-zA-Z0-9]+\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})")
|
||||
(def enode-url-regex #"enode://[a-zA-Z0-9]+:(.+)\@\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b:(\d{1,5})")
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
(ns status-im.models.network
|
||||
(:require [clojure.string :as string]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]))
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(def url-regex
|
||||
#"https?://(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}(\.[a-z]{2,6})?\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)")
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
(ns status-im.protocol.models
|
||||
(:require [status-im.constants :as constants]
|
||||
[status-im.utils.semaphores :as semaphores]
|
||||
(ns status-im.models.protocol
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.transport.inbox :as transport.inbox]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.semaphores :as semaphores]))
|
||||
|
||||
(defn update-sync-state
|
||||
[{:keys [sync-state sync-data] :as db} error sync]
|
||||
|
@ -27,7 +30,7 @@
|
|||
(defn check-sync-state
|
||||
[{{:keys [web3] :as db} :db :as cofx}]
|
||||
(if (:account/account db)
|
||||
{::web3-get-syncing web3
|
||||
{:protocol/web3-get-syncing web3
|
||||
:dispatch-later [{:ms 10000 :dispatch [:check-sync-state]}]}
|
||||
(semaphores/free :check-sync-state? cofx)))
|
||||
|
||||
|
@ -38,3 +41,17 @@
|
|||
(handlers-macro/merge-fx cofx
|
||||
{:dispatch [:check-sync-state]}
|
||||
(semaphores/lock :check-sync-state?))))
|
||||
|
||||
(defn initialize-protocol
|
||||
[address {:data-store/keys [transport mailservers] :keys [db web3] :as cofx}]
|
||||
(let [network (get-in db [:account/account :network])
|
||||
network-id (str (get-in db [:account/account :networks network :config :NetworkId]))]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc db
|
||||
:rpc-url constants/ethereum-rpc-url
|
||||
:transport/chats transport)
|
||||
:protocol/assert-correct-network {:web3 web3
|
||||
:network-id network-id}}
|
||||
(start-check-sync-state)
|
||||
(transport.inbox/initialize-offline-inbox mailservers)
|
||||
(transport/init-whisper address))))
|
|
@ -1,8 +1,8 @@
|
|||
(ns status-im.models.transactions
|
||||
(:require [clojure.set :as set]
|
||||
[status-im.utils.datetime :as time]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.semaphores :as semaphores]
|
||||
[taoensso.timbre :as log]))
|
||||
|
@ -55,10 +55,10 @@
|
|||
chat-transactions
|
||||
(wallet-transactions-set db))))
|
||||
|
||||
; Find missing chat transactions
|
||||
; and store them at [:wallet :chat-transactions]
|
||||
; to be used later by have-missing-chat-transactions? on every sync request
|
||||
(defn load-missing-chat-transactions [{:keys [db] :as cofx}]
|
||||
(defn load-missing-chat-transactions
|
||||
"Find missing chat transactions and store them at [:wallet :chat-transactions]
|
||||
to be used later by have-missing-chat-transactions? on every sync request"
|
||||
[{:keys [db] :as cofx}]
|
||||
(when (nil? (get-in db [:wallet :chat-transactions]))
|
||||
{:db (assoc-in db
|
||||
[:wallet :chat-transactions]
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
(ns status-im.models.wallet
|
||||
(:require [status-im.utils.money :as money]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
(:require [clojure.set :as set]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.hex :as utils.hex]
|
||||
[status-im.transport.utils :as transport.utils]))
|
||||
[status-im.utils.money :as money]))
|
||||
|
||||
(def min-gas-price-wei (money/bignumber 1))
|
||||
|
||||
|
@ -172,3 +173,39 @@
|
|||
(cond-> transaction
|
||||
(= method constants/web3-personal-sign)
|
||||
(update :data transport.utils/to-utf8)))
|
||||
|
||||
(defn clear-error-message [db error-type]
|
||||
(update-in db [:wallet :errors] dissoc error-type))
|
||||
|
||||
(defn tokens-symbols [v chain]
|
||||
(set/difference (set v) (set (map :symbol (tokens/nfts-for chain)))))
|
||||
|
||||
(defn update-wallet
|
||||
[{{:keys [web3 network network-status] {:keys [address settings]} :account/account :as db} :db}]
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network)
|
||||
mainnet? (= :mainnet chain)
|
||||
assets (get-in settings [:wallet :visible-tokens chain])
|
||||
tokens (tokens-symbols (get-in settings [:wallet :visible-tokens chain]) chain)
|
||||
currency-id (or (get-in settings [:wallet :currency]) :usd)
|
||||
currency (get constants/currencies currency-id)]
|
||||
(when (not= network-status :offline)
|
||||
{:get-balance {:web3 web3
|
||||
:account-id address
|
||||
:success-event :update-balance-success
|
||||
:error-event :update-balance-fail}
|
||||
:get-tokens-balance {:web3 web3
|
||||
:account-id address
|
||||
:symbols assets
|
||||
:chain chain
|
||||
:success-event :update-token-balance-success
|
||||
:error-event :update-token-balance-fail}
|
||||
:get-prices {:from (if mainnet? (conj tokens "ETH") ["ETH"])
|
||||
:to [(:code currency)]
|
||||
:success-event :update-prices-success
|
||||
:error-event :update-prices-fail}
|
||||
:db (-> db
|
||||
(clear-error-message :prices-update)
|
||||
(clear-error-message :balance-update)
|
||||
(assoc-in [:wallet :balance-loading?] true)
|
||||
(assoc :prices-loading? true))})))
|
||||
|
|
|
@ -1,30 +1,21 @@
|
|||
(ns status-im.protocol.handlers
|
||||
(:require [cljs.core.async :as async]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.utils.datetime :as datetime]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.web3-provider :as web3-provider]
|
||||
[status-im.transport.core :as transport]
|
||||
[status-im.transport.inbox :as transport.inbox]
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.models.protocol :as models]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.protocol.models :as models]))
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.utils.web3-provider :as web3-provider]))
|
||||
|
||||
;;;; COFX
|
||||
(re-frame/reg-cofx
|
||||
::get-web3
|
||||
(fn [coeffects _]
|
||||
(let [web3 (web3-provider/make-internal-web3)
|
||||
address (get-in coeffects [:db :account/account :address])]
|
||||
(set! (.-defaultAccount (.-eth web3))
|
||||
(ethereum/normalized-address address))
|
||||
(assoc coeffects :web3 web3))))
|
||||
:protocol/get-web3
|
||||
(fn [cofx _]
|
||||
(let [web3 (web3-provider/make-internal-web3)]
|
||||
(assoc cofx :web3 web3))))
|
||||
|
||||
;;; FX
|
||||
(re-frame/reg-fx
|
||||
::web3-get-syncing
|
||||
:protocol/web3-get-syncing
|
||||
(fn [web3]
|
||||
(when web3
|
||||
(.getSyncing
|
||||
|
@ -32,40 +23,25 @@
|
|||
(fn [error sync]
|
||||
(re-frame/dispatch [:update-sync-state error sync]))))))
|
||||
|
||||
(defn- assert-correct-network
|
||||
[{:keys [db]}]
|
||||
;; Assure that node was started correctly
|
||||
(let [{:keys [web3]} db]
|
||||
(let [network (get-in db [:account/account :network])
|
||||
network-id (str (get-in db [:account/account :networks network :config :NetworkId]))]
|
||||
(when (and network-id web3) ; necessary because of the unit tests
|
||||
(.getNetwork (.-version web3)
|
||||
(fn [error fetched-network-id]
|
||||
(when (and (not error) ; error most probably means we are offline
|
||||
(not= network-id fetched-network-id))
|
||||
(utils/show-popup
|
||||
"Ethereum node started incorrectly"
|
||||
"Ethereum node was started with incorrect configuration, application will be stopped to recover from that condition."
|
||||
#(re-frame/dispatch [:close-application])))))))))
|
||||
(re-frame/reg-fx
|
||||
:protocol/set-default-account
|
||||
(fn [[web3 address]]
|
||||
(set! (.-defaultAccount (.-eth web3))
|
||||
(ethereum/normalized-address address))))
|
||||
|
||||
(defn initialize-protocol
|
||||
[{:data-store/keys [transport mailservers] :keys [db web3] :as cofx} [current-account-id ethereum-rpc-url]]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc db
|
||||
:web3 web3
|
||||
:rpc-url (or ethereum-rpc-url constants/ethereum-rpc-url)
|
||||
:transport/chats transport)}
|
||||
(assert-correct-network)
|
||||
(transport.inbox/initialize-offline-inbox mailservers)
|
||||
(transport/init-whisper current-account-id)))
|
||||
;;; INITIALIZE PROTOCOL
|
||||
(handlers/register-handler-fx
|
||||
:initialize-protocol
|
||||
[re-frame/trim-v
|
||||
(re-frame/inject-cofx ::get-web3)
|
||||
(re-frame/inject-cofx :data-store/get-all-mailservers)
|
||||
(re-frame/inject-cofx :data-store/transport)]
|
||||
initialize-protocol)
|
||||
(re-frame/reg-fx
|
||||
:protocol/assert-correct-network
|
||||
(fn [{:keys [web3 network-id]}]
|
||||
;; ensure that node was started correctly
|
||||
(when (and network-id web3) ; necessary because of the unit tests
|
||||
(.getNetwork (.-version web3)
|
||||
(fn [error fetched-network-id]
|
||||
(when (and (not error) ; error most probably means we are offline
|
||||
(not= network-id fetched-network-id))
|
||||
(utils/show-popup
|
||||
"Ethereum node started incorrectly"
|
||||
"Ethereum node was started with incorrect configuration, application will be stopped to recover from that condition."
|
||||
#(re-frame/dispatch [:close-application]))))))))
|
||||
|
||||
;;; NODE SYNC STATE
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
(ns ^{:doc "Contact request and update API"}
|
||||
status-im.transport.message.v1.contact
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.data-store.transport :as transport-store]
|
||||
[status-im.transport.message.core :as message]
|
||||
[status-im.transport.message.v1.protocol :as protocol]
|
||||
[status-im.transport.utils :as transport.utils]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.data-store.transport :as transport-store]))
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(defrecord ContactRequest [name profile-image address fcm-token]
|
||||
message/StatusMessage
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
(ns status-im.ui.screens.accounts.events
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
status-im.ui.screens.accounts.create.navigation
|
||||
[status-im.ui.screens.accounts.models :as models]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.ui.screens.accounts.models :as models]))
|
||||
[status-im.utils.handlers :as handlers]))
|
||||
|
||||
;;;; COFX
|
||||
|
||||
|
@ -36,11 +36,6 @@
|
|||
(fn [cofx [_ result password]]
|
||||
(models/on-account-created result password false cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:send-account-update-if-needed
|
||||
(fn [cofx _]
|
||||
(models/send-account-update-if-needed cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:account-set-name
|
||||
(fn [cofx _]
|
||||
|
@ -51,11 +46,6 @@
|
|||
(fn [cofx [_ input-key text]]
|
||||
(models/account-set-input-text input-key text cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:update-sign-in-time
|
||||
(fn [{db :db now :now :as cofx} _]
|
||||
(accounts.utils/account-update {:last-sign-in now} cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:update-mainnet-warning-shown
|
||||
(fn [cofx _]
|
||||
|
|
|
@ -1,26 +1,24 @@
|
|||
(ns status-im.ui.screens.accounts.models
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[clojure.string :as str]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.utils.datetime :as time]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.ui.screens.accounts.statuses :as statuses]
|
||||
[status-im.utils.signing-phrase.core :as signing-phrase]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.utils.hex :as utils.hex]
|
||||
(:require [clojure.string :as str]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
status-im.ui.screens.accounts.create.navigation
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.data-store.accounts :as accounts-store]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.ui.screens.accounts.statuses :as statuses]
|
||||
[status-im.ui.screens.accounts.utils :as accounts.utils]
|
||||
[status-im.ui.screens.accounts.login.models :as login.models]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.ui.screens.wallet.settings.models :as wallet.settings.models]))
|
||||
[status-im.ui.screens.wallet.settings.models :as wallet.settings.models]
|
||||
[status-im.utils.config :as config]
|
||||
[status-im.utils.gfycat.core :as gfycat]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.hex :as utils.hex]
|
||||
[status-im.utils.identicon :as identicon]
|
||||
[status-im.utils.signing-phrase.core :as signing-phrase]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.utils :as utils]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
;;;; COFX
|
||||
|
||||
|
@ -88,15 +86,6 @@
|
|||
:data-store/base-tx [{:transaction (accounts-store/save-account-tx new-account)
|
||||
:success-event success-event}]})))
|
||||
|
||||
(defn send-account-update-if-needed [{:keys [db now] :as cofx}]
|
||||
(let [{:keys [last-updated]} (:account/account db)
|
||||
needs-update? (> (- now last-updated) time/week)]
|
||||
(log/info "Need to send account-update: " needs-update?)
|
||||
(when needs-update?
|
||||
;; TODO(janherich): this is very strange and misleading, need to figure out why it'd necessary to update
|
||||
;; account with network update when last update was more then week ago
|
||||
(accounts.utils/account-update nil cofx))))
|
||||
|
||||
(defn account-set-name [{{:accounts/keys [create] :as db} :db :as cofx}]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:db (assoc db :accounts/create {:show-welcome? true})
|
||||
|
|
|
@ -1,21 +1,19 @@
|
|||
(ns status-im.ui.screens.browser.events
|
||||
(:require status-im.ui.screens.browser.navigation
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.utils.random :as random]
|
||||
[status-im.ui.components.list-selection :as list-selection]
|
||||
[status-im.utils.universal-links.core :as utils.universal-links]
|
||||
[status-im.data-store.browser :as browser-store]
|
||||
[status-im.utils.http :as http]
|
||||
[status-im.models.browser :as model]
|
||||
[status-im.utils.platform :as platform]
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.data-store.browser :as browser-store]
|
||||
[status-im.models.browser :as model]
|
||||
[status-im.native-module.core :as status]
|
||||
[taoensso.timbre :as log]
|
||||
[status-im.ui.components.list-selection :as list-selection]
|
||||
status-im.ui.screens.browser.navigation
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.http :as http]
|
||||
[status-im.utils.platform :as platform]
|
||||
[status-im.utils.random :as random]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.constants :as constants]))
|
||||
[status-im.utils.universal-links.core :as utils.universal-links]
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:browse
|
||||
|
@ -41,20 +39,6 @@
|
|||
(fn [[message webview]]
|
||||
(.sendToBridge webview (types/clj->json message))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:initialize-browsers
|
||||
[(re-frame/inject-cofx :data-store/all-browsers)]
|
||||
(fn [{:keys [db all-stored-browsers]} _]
|
||||
(let [browsers (into {} (map #(vector (:browser-id %) %) all-stored-browsers))]
|
||||
{:db (assoc db :browser/browsers browsers)})))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:initialize-dapp-permissions
|
||||
[(re-frame/inject-cofx :data-store/all-dapp-permissions)]
|
||||
(fn [{:keys [db all-dapp-permissions]} _]
|
||||
(let [dapp-permissions (into {} (map #(vector (:dapp %) %) all-dapp-permissions))]
|
||||
{:db (assoc db :dapps/permissions dapp-permissions)})))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:browse-link-from-message
|
||||
(fn [_ [_ link]]
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
(ns status-im.ui.screens.contacts.events
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.chat.events :as chat.events]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.models.contact :as models.contact]
|
||||
[status-im.ui.screens.add-new.new-chat.db :as new-chat.db]
|
||||
[status-im.ui.screens.browser.default-dapps :as default-dapps]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.utils.js-resources :as js-res]
|
||||
[status-im.chat.events :as chat.events]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.models.contact :as models.contact]))
|
||||
[status-im.utils.utils :as utils]))
|
||||
|
||||
(defn add-contact-and-open-chat [whisper-id cofx]
|
||||
(handlers-macro/merge-fx cofx
|
||||
|
@ -28,15 +28,6 @@
|
|||
(assoc coeffects :default-dapps default-dapps/all)))
|
||||
|
||||
;;;; Handlers
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:load-contacts
|
||||
[(re-frame/inject-cofx :data-store/get-all-contacts)]
|
||||
(fn [{:keys [db all-contacts]} _]
|
||||
(let [contacts-list (map #(vector (:whisper-identity %) %) all-contacts)
|
||||
contacts (into {} contacts-list)]
|
||||
{:db (update db :contacts/contacts #(merge contacts %))})))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:add-contact
|
||||
[(re-frame/inject-cofx :random-id)]
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
(ns status-im.ui.screens.currency-settings.events
|
||||
(:require [status-im.ui.screens.accounts.models :as accounts.models]
|
||||
(:require [status-im.models.wallet :as wallet]
|
||||
[status-im.ui.screens.accounts.models :as accounts.models]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.ui.screens.wallet.events :as wallet.events]))
|
||||
[status-im.utils.handlers-macro :as handlers-macro]))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:wallet.settings/set-currency
|
||||
|
@ -11,4 +11,4 @@
|
|||
new-settings (assoc-in settings [:wallet :currency] currency)]
|
||||
(handlers-macro/merge-fx cofx
|
||||
(accounts.models/update-settings new-settings)
|
||||
(wallet.events/update-wallet)))))
|
||||
(wallet/update-wallet)))))
|
||||
|
|
|
@ -1,13 +1,17 @@
|
|||
(ns status-im.ui.screens.events
|
||||
(:require status-im.chat.events
|
||||
[status-im.models.chat :as chat]
|
||||
status-im.network.events
|
||||
[status-im.transport.handlers :as transport.handlers]
|
||||
status-im.protocol.handlers
|
||||
[status-im.models.protocol :as models.protocol]
|
||||
[status-im.models.account :as models.account]
|
||||
[status-im.ui.screens.accounts.models :as accounts.models]
|
||||
status-im.ui.screens.accounts.login.events
|
||||
[status-im.ui.screens.accounts.login.models :as login]
|
||||
status-im.ui.screens.accounts.recover.events
|
||||
[status-im.ui.screens.contacts.events :as contacts]
|
||||
[status-im.models.contacts :as models.contacts]
|
||||
status-im.ui.screens.add-new.new-chat.events
|
||||
status-im.ui.screens.group.chat-settings.events
|
||||
status-im.ui.screens.group.events
|
||||
|
@ -20,15 +24,18 @@
|
|||
status-im.ui.screens.profile.events
|
||||
status-im.ui.screens.qr-scanner.events
|
||||
status-im.ui.screens.wallet.events
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
status-im.ui.screens.wallet.collectibles.events
|
||||
status-im.ui.screens.wallet.send.events
|
||||
status-im.ui.screens.wallet.settings.events
|
||||
status-im.ui.screens.wallet.transactions.events
|
||||
[status-im.models.transactions :as transactions]
|
||||
status-im.ui.screens.wallet.choose-recipient.events
|
||||
status-im.ui.screens.wallet.collectibles.cryptokitties.events
|
||||
status-im.ui.screens.wallet.collectibles.cryptostrikers.events
|
||||
status-im.ui.screens.wallet.collectibles.etheremon.events
|
||||
status-im.ui.screens.browser.events
|
||||
[status-im.models.browser :as browser]
|
||||
status-im.ui.screens.offline-messaging-settings.events
|
||||
status-im.ui.screens.privacy-policy.events
|
||||
status-im.ui.screens.bootnodes-settings.events
|
||||
|
@ -97,6 +104,14 @@
|
|||
(doseq [call calls]
|
||||
(http-get call))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:fetch-web3-node-version
|
||||
(fn [web3 _]
|
||||
(.. web3 -version (getNode (fn [err resp]
|
||||
(when-not err
|
||||
(re-frame/dispatch [:fetch-web3-node-version-callback resp])))))
|
||||
nil))
|
||||
|
||||
;; Try to decrypt the database, move on if successful otherwise go back to
|
||||
;; initial state
|
||||
(re-frame/reg-fx
|
||||
|
@ -149,7 +164,8 @@
|
|||
(re-frame/reg-fx
|
||||
::get-fcm-token-fx
|
||||
(fn [_]
|
||||
(notifications/get-fcm-token)))
|
||||
(when platform/mobile?
|
||||
(notifications/get-fcm-token))))
|
||||
|
||||
(re-frame/reg-fx
|
||||
:show-error
|
||||
|
@ -231,20 +247,20 @@
|
|||
"Initialize db to the initial state"
|
||||
[{{:universal-links/keys [url]
|
||||
:push-notifications/keys [initial?]
|
||||
:keys [status-module-initialized? status-node-started?
|
||||
network-status network peers-count peers-summary device-UUID]
|
||||
:or {network (get app-db :network)}} :db}]
|
||||
{:db (assoc app-db
|
||||
:contacts/contacts {}
|
||||
:network-status network-status
|
||||
:peers-count (or peers-count 0)
|
||||
:peers-summary (or peers-summary [])
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:status-node-started? status-node-started?
|
||||
:network network
|
||||
:universal-links/url url
|
||||
:push-notifications/initial? initial?
|
||||
:device-UUID device-UUID)})
|
||||
:keys [status-module-initialized? status-node-started?
|
||||
network-status network peers-count peers-summary device-UUID]
|
||||
:or {network (get app-db :network)}} :db}]
|
||||
{:db (assoc app-db
|
||||
:contacts/contacts {}
|
||||
:network-status network-status
|
||||
:peers-count (or peers-count 0)
|
||||
:peers-summary (or peers-summary [])
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:status-node-started? status-node-started?
|
||||
:network network
|
||||
:universal-links/url url
|
||||
:push-notifications/initial? initial?
|
||||
:device-UUID device-UUID)})
|
||||
|
||||
;; Entrypoint, fetches the key from the keychain and initialize the app
|
||||
(handlers/register-handler-fx
|
||||
|
@ -294,56 +310,71 @@
|
|||
(navigation/navigate-to-clean nil)
|
||||
(transport/stop-whisper)))))
|
||||
|
||||
(handlers/register-handler-db
|
||||
:initialize-account-db
|
||||
(fn [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks
|
||||
network network-status peers-count peers-summary view-id navigation-stack
|
||||
status-module-initialized? status-node-started? device-UUID
|
||||
push-notifications/initial? semaphores]
|
||||
:or [network (get app-db :network)]} [_ address]]
|
||||
(let [console-contact (get contacts constants/console-chat-id)
|
||||
current-account (accounts address)
|
||||
account-network-id (get current-account :network network)
|
||||
account-network (get-in current-account [:networks account-network-id])]
|
||||
(cond-> (assoc app-db
|
||||
:current-public-key (:public-key current-account)
|
||||
:view-id view-id
|
||||
:navigation-stack navigation-stack
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:status-node-started? status-node-started?
|
||||
:accounts/create create
|
||||
:networks/networks networks
|
||||
:account/account current-account
|
||||
:network-status network-status
|
||||
:network network
|
||||
:chain (ethereum/network->chain-name account-network)
|
||||
:push-notifications/initial? initial?
|
||||
:peers-summary peers-summary
|
||||
:peers-count peers-count
|
||||
:device-UUID device-UUID
|
||||
:semaphores semaphores)
|
||||
console-contact
|
||||
(assoc :contacts/contacts {constants/console-chat-id console-contact})))))
|
||||
(defn initialize-account-db [address {:keys [db web3]}]
|
||||
(let [{:keys [accounts/accounts accounts/create contacts/contacts networks/networks
|
||||
network network-status peers-count peers-summary view-id navigation-stack
|
||||
status-module-initialized? status-node-started? device-UUID
|
||||
push-notifications/initial? semaphores]
|
||||
:or {network (get app-db :network)}} db
|
||||
console-contact (get contacts constants/console-chat-id)
|
||||
current-account (accounts address)
|
||||
account-network-id (get current-account :network network)
|
||||
account-network (get-in current-account [:networks account-network-id])]
|
||||
{:db (cond-> (assoc app-db
|
||||
:current-public-key (:public-key current-account)
|
||||
:view-id view-id
|
||||
:navigation-stack navigation-stack
|
||||
:status-module-initialized? (or platform/ios? js/goog.DEBUG status-module-initialized?)
|
||||
:status-node-started? status-node-started?
|
||||
:accounts/create create
|
||||
:networks/networks networks
|
||||
:account/account current-account
|
||||
:network-status network-status
|
||||
:network network
|
||||
:chain (ethereum/network->chain-name account-network)
|
||||
:push-notifications/initial? initial?
|
||||
:peers-summary peers-summary
|
||||
:peers-count peers-count
|
||||
:device-UUID device-UUID
|
||||
:semaphores semaphores
|
||||
:web3 web3)
|
||||
console-contact
|
||||
(assoc :contacts/contacts {constants/console-chat-id console-contact}))}))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:initialize-account
|
||||
(fn [cofx [_ address events-after]]
|
||||
{:dispatch-n (cond-> [[:initialize-account-db address]
|
||||
[:initialize-protocol address]
|
||||
[:fetch-web3-node-version]
|
||||
[:start-check-sync-state]
|
||||
[:load-contacts]
|
||||
[:initialize-chats]
|
||||
[:initialize-browsers]
|
||||
[:initialize-dapp-permissions]
|
||||
[:send-account-update-if-needed]
|
||||
[:process-pending-messages]
|
||||
[:update-wallet]
|
||||
[:update-transactions]
|
||||
(when platform/mobile? [:get-fcm-token])
|
||||
[:start-wallet-transactions-sync]
|
||||
[:update-sign-in-time]]
|
||||
(seq events-after) (into events-after))}))
|
||||
[(re-frame/inject-cofx :protocol/get-web3)
|
||||
(re-frame/inject-cofx :get-default-contacts)
|
||||
(re-frame/inject-cofx :get-default-dapps)
|
||||
(re-frame/inject-cofx :data-store/all-chats)
|
||||
(re-frame/inject-cofx :data-store/get-messages)
|
||||
(re-frame/inject-cofx :data-store/get-user-statuses)
|
||||
(re-frame/inject-cofx :data-store/unviewed-messages)
|
||||
(re-frame/inject-cofx :data-store/message-ids)
|
||||
(re-frame/inject-cofx :data-store/get-unanswered-requests)
|
||||
(re-frame/inject-cofx :data-store/get-local-storage-data)
|
||||
(re-frame/inject-cofx :data-store/get-all-contacts)
|
||||
(re-frame/inject-cofx :data-store/get-all-mailservers)
|
||||
(re-frame/inject-cofx :data-store/transport)
|
||||
(re-frame/inject-cofx :data-store/all-browsers)
|
||||
(re-frame/inject-cofx :data-store/all-dapp-permissions)]
|
||||
(fn [{:keys [web3] :as cofx} [_ address events-after]]
|
||||
(handlers-macro/merge-fx cofx
|
||||
{:protocol/set-default-account [web3 address]
|
||||
:fetch-web3-node-version web3
|
||||
::get-fcm-token-fx nil
|
||||
:dispatch-n (or events-after [])}
|
||||
(initialize-account-db address)
|
||||
(models.protocol/initialize-protocol address)
|
||||
(models.contacts/load-contacts)
|
||||
(chat/initialize-chats)
|
||||
(chat/process-pending-messages)
|
||||
(browser/initialize-browsers)
|
||||
(browser/initialize-dapp-permissions)
|
||||
(models.wallet/update-wallet)
|
||||
(transactions/run-update)
|
||||
(transactions/start-sync)
|
||||
(models.account/update-sign-in-time))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:initialize-geth
|
||||
|
@ -359,19 +390,6 @@
|
|||
(when-let [git-commit (nth (re-find #"-([0-9a-f]{7,})/" resp) 1)]
|
||||
{:db (assoc db :web3-node-version git-commit)})))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:fetch-web3-node-version
|
||||
(fn [{{:keys [web3] :as db} :db} _]
|
||||
(.. web3 -version (getNode (fn [err resp]
|
||||
(when-not err
|
||||
(re-frame/dispatch [:fetch-web3-node-version-callback resp])))))
|
||||
nil))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:get-fcm-token
|
||||
(fn [_ _]
|
||||
{::get-fcm-token-fx nil}))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:discovery/summary
|
||||
(fn [{:keys [db] :as cofx} [_ peers-summary]]
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
(ns status-im.ui.screens.wallet.events
|
||||
(:require [clojure.set :as set]
|
||||
[re-frame.core :as re-frame :refer [dispatch reg-fx]]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.ui.screens.wallet.navigation]
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.models.transactions :as wallet.transactions]
|
||||
[status-im.models.wallet :as models]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
status-im.ui.screens.wallet.navigation
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.ethereum.erc20 :as erc20]
|
||||
[status-im.utils.ethereum.tokens :as tokens]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.money :as money]
|
||||
[status-im.utils.prices :as prices]
|
||||
[status-im.utils.transactions :as transactions]
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
[taoensso.timbre :as log]
|
||||
status-im.ui.screens.wallet.request.events
|
||||
[status-im.constants :as constants]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.utils.money :as money]
|
||||
[status-im.models.transactions :as wallet.transactions]))
|
||||
[taoensso.timbre :as log]))
|
||||
|
||||
(defn get-balance [{:keys [web3 account-id on-success on-error]}]
|
||||
(if (and web3 account-id)
|
||||
|
@ -43,12 +39,9 @@
|
|||
(defn assoc-error-message [db error-type err]
|
||||
(assoc-in db [:wallet :errors error-type] (or err :unknown-error)))
|
||||
|
||||
(defn clear-error-message [db error-type]
|
||||
(update-in db [:wallet :errors] dissoc error-type))
|
||||
|
||||
;; FX
|
||||
|
||||
(reg-fx
|
||||
(re-frame/reg-fx
|
||||
:get-balance
|
||||
(fn [{:keys [web3 account-id success-event error-event]}]
|
||||
(get-balance {:web3 web3
|
||||
|
@ -56,7 +49,7 @@
|
|||
:on-success #(re-frame/dispatch [success-event %])
|
||||
:on-error #(re-frame/dispatch [error-event %])})))
|
||||
|
||||
(reg-fx
|
||||
(re-frame/reg-fx
|
||||
:get-tokens-balance
|
||||
(fn [{:keys [web3 symbols chain account-id success-event error-event]}]
|
||||
(doseq [symbol symbols]
|
||||
|
@ -67,7 +60,7 @@
|
|||
:on-success #(re-frame/dispatch [success-event symbol %])
|
||||
:on-error #(re-frame/dispatch [error-event symbol %])})))))
|
||||
|
||||
(reg-fx
|
||||
(re-frame/reg-fx
|
||||
:get-transactions
|
||||
(fn [{:keys [web3 chain account-id token-addresses success-event error-event]}]
|
||||
(transactions/get-transactions chain
|
||||
|
@ -83,7 +76,7 @@
|
|||
#(re-frame/dispatch [success-event % account-id])))))
|
||||
|
||||
;; TODO(oskarth): At some point we want to get list of relevant assets to get prices for
|
||||
(reg-fx
|
||||
(re-frame/reg-fx
|
||||
:get-prices
|
||||
(fn [{:keys [from to success-event error-event]}]
|
||||
(prices/get-prices from
|
||||
|
@ -91,53 +84,21 @@
|
|||
#(re-frame/dispatch [success-event %])
|
||||
#(re-frame/dispatch [error-event %]))))
|
||||
|
||||
(reg-fx
|
||||
(re-frame/reg-fx
|
||||
:update-gas-price
|
||||
(fn [{:keys [web3 success-event edit?]}]
|
||||
(ethereum/gas-price web3 #(re-frame/dispatch [success-event %2 edit?]))))
|
||||
|
||||
(reg-fx
|
||||
(re-frame/reg-fx
|
||||
:update-estimated-gas
|
||||
(fn [{:keys [web3 obj success-event]}]
|
||||
(ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2]))))
|
||||
|
||||
(defn tokens-symbols [v chain]
|
||||
(set/difference (set v) (set (map :symbol (tokens/nfts-for chain)))))
|
||||
|
||||
(defn update-wallet [{{:keys [web3 network network-status] {:keys [address settings]} :account/account :as db} :db}]
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network)
|
||||
mainnet? (= :mainnet chain)
|
||||
assets (get-in settings [:wallet :visible-tokens chain])
|
||||
tokens (tokens-symbols (get-in settings [:wallet :visible-tokens chain]) chain)
|
||||
currency-id (or (get-in settings [:wallet :currency]) :usd)
|
||||
currency (get constants/currencies currency-id)]
|
||||
(when (not= network-status :offline)
|
||||
{:get-balance {:web3 web3
|
||||
:account-id address
|
||||
:success-event :update-balance-success
|
||||
:error-event :update-balance-fail}
|
||||
:get-tokens-balance {:web3 web3
|
||||
:account-id address
|
||||
:symbols assets
|
||||
:chain chain
|
||||
:success-event :update-token-balance-success
|
||||
:error-event :update-token-balance-fail}
|
||||
:get-prices {:from (if mainnet? (conj tokens "ETH") ["ETH"])
|
||||
:to [(:code currency)]
|
||||
:success-event :update-prices-success
|
||||
:error-event :update-prices-fail}
|
||||
:db (-> db
|
||||
(clear-error-message :prices-update)
|
||||
(clear-error-message :balance-update)
|
||||
(assoc-in [:wallet :balance-loading?] true)
|
||||
(assoc :prices-loading? true))})))
|
||||
|
||||
;; Handlers
|
||||
(handlers/register-handler-fx
|
||||
:update-wallet
|
||||
(fn [cofx _]
|
||||
(update-wallet cofx)))
|
||||
(models/update-wallet cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:update-transactions
|
||||
|
@ -257,7 +218,7 @@
|
|||
:wallet/update-gas-price-success
|
||||
(fn [db [_ price edit?]]
|
||||
(if edit?
|
||||
(:db (models.wallet/edit-value
|
||||
(:db (models/edit-value
|
||||
:gas-price
|
||||
(money/to-fixed
|
||||
(money/wei-> :gwei price))
|
||||
|
|
|
@ -1,7 +1,13 @@
|
|||
(ns status-im.ui.screens.wallet.send.events
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[status-im.chat.commands.sending :as commands-sending]
|
||||
[status-im.chat.models.message :as models.message]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.i18n :as i18n]
|
||||
[status-im.models.transactions :as wallet.transactions]
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
[status-im.native-module.core :as status]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.ui.screens.wallet.db :as wallet.db]
|
||||
[status-im.utils.ethereum.core :as ethereum]
|
||||
[status-im.utils.ethereum.erc20 :as erc20]
|
||||
|
@ -11,13 +17,7 @@
|
|||
[status-im.utils.money :as money]
|
||||
[status-im.utils.security :as security]
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.utils :as utils]
|
||||
[status-im.models.wallet :as models.wallet]
|
||||
[status-im.chat.models.message :as models.message]
|
||||
[status-im.chat.commands.sending :as commands-sending]
|
||||
[status-im.constants :as constants]
|
||||
[status-im.ui.screens.navigation :as navigation]
|
||||
[status-im.models.transactions :as wallet.transactions]))
|
||||
[status-im.utils.utils :as utils]))
|
||||
|
||||
;;;; FX
|
||||
|
||||
|
@ -269,8 +269,3 @@
|
|||
:sync-wallet-transactions
|
||||
(fn [cofx _]
|
||||
(wallet.transactions/sync cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:start-wallet-transactions-sync
|
||||
(fn [cofx _]
|
||||
(wallet.transactions/start-sync cofx)))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
(ns status-im.utils.handlers-macro
|
||||
(:require-macros status-im.utils.handlers-macro)
|
||||
(:require-macros status-im.utils.handlers-macro
|
||||
[taoensso.timbre :as log])
|
||||
(:require [clojure.set :as set]))
|
||||
|
||||
(defn update-db [cofx fx]
|
||||
|
@ -10,7 +11,7 @@
|
|||
(def ^:private mergable-keys
|
||||
#{:data-store/tx :data-store/base-tx :chat-received-message/add-fx
|
||||
:shh/add-new-sym-keys :shh/get-new-sym-keys :shh/post
|
||||
:confirm-messages-processed})
|
||||
:confirm-messages-processed :utils/dispatch-later})
|
||||
|
||||
(defn safe-merge [fx new-fx]
|
||||
(if (:merging-fx-with-common-keys fx)
|
||||
|
@ -23,7 +24,8 @@
|
|||
(merge-with into
|
||||
(select-keys fx mergable-keys)
|
||||
(select-keys new-fx mergable-keys)))
|
||||
{:merging-fx-with-common-keys common-keys}))))
|
||||
(do (log/error "Merging fx with common-keys: " common-keys)
|
||||
{:merging-fx-with-common-keys common-keys})))))
|
||||
|
||||
(defn merge-effects
|
||||
([{:keys [db] :as cofx} handler args]
|
||||
|
|
|
@ -6,7 +6,10 @@
|
|||
status-im.ui.screens.subs
|
||||
[re-frame.core :as re-frame]
|
||||
[status-im.models.browser :as model]
|
||||
[status-im.utils.types :as types]))
|
||||
[status-im.utils.types :as types]
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.models.browser :as browser]))
|
||||
|
||||
(defn test-fixtures []
|
||||
|
||||
|
@ -32,7 +35,17 @@
|
|||
(fn [[permission {:keys [dapp-name permissions-data index] :as params}]]
|
||||
(if (and (= dapp-name "test.com") (#{0 1} index))
|
||||
(re-frame/dispatch [:next-dapp-permission params permission permissions-data])
|
||||
(re-frame/dispatch [:next-dapp-permission params])))))
|
||||
(re-frame/dispatch [:next-dapp-permission params]))))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
[(re-frame/inject-cofx :data-store/all-browsers)
|
||||
(re-frame/inject-cofx :data-store/all-dapp-permissions)]
|
||||
:initialize-test
|
||||
(fn [cofx [_]]
|
||||
(handlers-macro/merge-fx cofx
|
||||
(events/initialize-db)
|
||||
(browser/initialize-browsers)
|
||||
(browser/initialize-dapp-permissions)))))
|
||||
|
||||
(deftest browser-events
|
||||
|
||||
|
@ -40,16 +53,16 @@
|
|||
|
||||
(test-fixtures)
|
||||
|
||||
(re-frame/dispatch [:initialize-db])
|
||||
(re-frame/dispatch [:initialize-browsers])
|
||||
|
||||
(re-frame/dispatch [:initialize-test])
|
||||
(println :app-db @re-frame.db/app-db)
|
||||
(let [browsers (re-frame/subscribe [:browsers])
|
||||
dapp1-url "cryptokitties.co"
|
||||
dapp2-url "http://test2.com"]
|
||||
|
||||
(testing "open and remove dapps"
|
||||
|
||||
(is (zero? (count @browsers)))
|
||||
(println :browsers @browsers)
|
||||
(is (do (println :browser @browsers)
|
||||
(zero? (count @browsers))))
|
||||
|
||||
(re-frame/dispatch [:open-url-in-browser dapp1-url])
|
||||
|
||||
|
@ -120,8 +133,6 @@
|
|||
(is (= 1 (:history-index @browser)))
|
||||
(is (= [dapp2-url dapp2-url3] (:history @browser))))))
|
||||
|
||||
(re-frame/dispatch [:initialize-dapp-permissions])
|
||||
|
||||
(let [dapps-permissions (re-frame/subscribe [:get :dapps/permissions])
|
||||
dapp-name "test.com"
|
||||
dapp-name2 "test2.org"]
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
|
||||
(def personal-request-command (transactions/PersonalRequestCommand.))
|
||||
|
||||
(deftest personal-send-command-test
|
||||
(deftest personal-request-command-test
|
||||
(testing "That correct parameters are defined"
|
||||
(is (= (into #{} (map :id) (protocol/parameters personal-request-command))
|
||||
#{:asset :amount})))
|
||||
|
@ -72,4 +72,3 @@
|
|||
:message-id "0xAA"
|
||||
:response "send"
|
||||
:status "open"})))))
|
||||
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
(ns status-im.test.transport.core
|
||||
(:require [cljs.test :refer-macros [deftest is testing]]
|
||||
[status-im.protocol.handlers :as protocol.handlers]
|
||||
[status-im.models.protocol :as protocol]
|
||||
[status-im.transport.core :as transport]))
|
||||
|
||||
(deftest init-whisper
|
||||
(let [cofx {:db {:network "mainnet_rpc"
|
||||
:account/account
|
||||
{:networks {"mainnet_rpc" {:config {:NetworkId 1}}}
|
||||
:public-key "1"}}}]
|
||||
:public-key "1"}
|
||||
:semaphores #{}}}]
|
||||
(testing "it adds the discover filter"
|
||||
(is (= (:shh/add-discovery-filter (protocol.handlers/initialize-protocol cofx [])))))
|
||||
(is (= (:shh/add-discovery-filter (protocol/initialize-protocol "user-address" cofx)))))
|
||||
(testing "it restores the sym-keys"
|
||||
(is (= (:shh/restore-sym-keys (protocol.handlers/initialize-protocol cofx [])))))
|
||||
(is (= (:shh/restore-sym-keys (protocol/initialize-protocol "user-address" cofx)))))
|
||||
(testing "custom mailservers"
|
||||
(let [ms-1 {:id "1"
|
||||
:chain "mainnet"
|
||||
|
@ -44,5 +45,5 @@
|
|||
ms-3])]
|
||||
(is (= expected-wnodes
|
||||
(get-in
|
||||
(protocol.handlers/initialize-protocol cofx-with-ms [])
|
||||
(protocol/initialize-protocol "user-address" cofx-with-ms)
|
||||
[:db :inbox/wnodes])))))))
|
||||
|
|
Loading…
Reference in New Issue