From 428464df073bb51f2d2a824843c9a2c2ceb8ce93 Mon Sep 17 00:00:00 2001 From: Andrey Shovkoplyas Date: Fri, 26 Apr 2019 12:09:58 +0200 Subject: [PATCH] re-frame subscriptions optimization Signed-off-by: Andrey Shovkoplyas --- src/status_im/android/core.cljs | 4 +- .../chat/commands/impl/transactions.cljs | 9 +- .../chat/commands/impl/transactions/subs.cljs | 8 - src/status_im/chat/models/loading.cljs | 4 +- src/status_im/chat/subs.cljs | 331 ---- src/status_im/contact/subs.cljs | 130 -- src/status_im/desktop/core.cljs | 2 +- src/status_im/extensions/capacities/subs.cljs | 90 +- src/status_im/fleet/core.cljs | 4 + src/status_im/ios/core.cljs | 4 +- src/status_im/mailserver/subs.cljs | 95 - src/status_im/search/subs.cljs | 52 - src/status_im/subs.cljs | 1642 +++++++++++++++++ .../ui/components/bottom_bar/core.cljs | 2 +- .../ui/components/bottom_sheet/core.cljs | 1 - .../ui/components/bottom_sheet/subs.cljs | 8 - .../ui/components/connectivity/subs.cljs | 62 - .../ui/components/connectivity/view.cljs | 2 +- src/status_im/ui/components/desktop/tabs.cljs | 4 +- .../ui/screens/accounts/create/views.cljs | 7 +- .../ui/screens/accounts/login/views.cljs | 2 +- .../ui/screens/accounts/recover/views.cljs | 2 +- src/status_im/ui/screens/accounts/subs.cljs | 57 - .../ui/screens/add_new/new_chat/subs.cljs | 6 - .../screens/add_new/new_public_chat/subs.cljs | 13 - .../screens/add_new/new_public_chat/view.cljs | 2 +- .../edit_bootnode/subs.cljs | 17 - .../ui/screens/bootnodes_settings/subs.cljs | 15 - src/status_im/ui/screens/browser/subs.cljs | 31 - src/status_im/ui/screens/browser/views.cljs | 7 +- .../chat/input/animations/expandable.cljs | 4 +- .../ui/screens/chat/input/send_button.cljs | 6 +- .../ui/screens/chat/stickers/subs.cljs | 9 - .../ui/screens/chat/toolbar_content.cljs | 2 +- .../ui/screens/currency_settings/subs.cljs | 12 - .../ui/screens/dapps_permissions/views.cljs | 2 +- .../screens/desktop/main/add_new/views.cljs | 4 +- .../ui/screens/desktop/main/chat/views.cljs | 4 +- .../screens/desktop/main/tabs/home/views.cljs | 4 +- .../desktop/main/tabs/profile/views.cljs | 10 +- .../ui/screens/desktop/main/views.cljs | 8 +- src/status_im/ui/screens/desktop/views.cljs | 2 +- .../ui/screens/extensions/add/subs.cljs | 12 - src/status_im/ui/screens/extensions/subs.cljs | 10 - .../ui/screens/fleet_settings/subs.cljs | 14 - src/status_im/ui/screens/group/subs.cljs | 39 - src/status_im/ui/screens/group/views.cljs | 2 +- .../ui/screens/hardwallet/login/views.cljs | 2 +- src/status_im/ui/screens/home/subs.cljs | 37 - src/status_im/ui/screens/home/views.cljs | 4 +- .../ui/screens/log_level_settings/subs.cljs | 15 - .../mobile_network_settings/sheets.cljs | 2 +- .../screens/mobile_network_settings/view.cljs | 2 +- .../network_settings/edit_network/subs.cljs | 14 - .../ui/screens/network_settings/subs.cljs | 36 - src/status_im/ui/screens/pairing/subs.cljs | 18 - .../ui/screens/profile/group_chat/views.cljs | 4 +- src/status_im/ui/screens/profile/subs.cljs | 41 - .../ui/screens/profile/user/views.cljs | 12 +- src/status_im/ui/screens/stickers/subs.cljs | 52 - src/status_im/ui/screens/subs.cljs | 109 -- src/status_im/ui/screens/views.cljs | 2 +- .../ui/screens/wallet/collectibles/subs.cljs | 12 - .../ui/screens/wallet/navigation.cljs | 4 - .../ui/screens/wallet/request/subs.cljs | 6 - .../ui/screens/wallet/send/subs.cljs | 98 - .../ui/screens/wallet/settings/subs.cljs | 8 - src/status_im/ui/screens/wallet/subs.cljs | 130 -- .../ui/screens/wallet/transactions/subs.cljs | 127 -- src/status_im/utils/js_resources.cljs | 5 +- src/status_im/utils/subs.cljs | 8 - test/cljs/status_im/test/search/core.cljs | 2 +- .../ui/screens/currency_settings/models.cljs | 10 +- test/cljs/status_im/test/wallet/subs.cljs | 2 +- .../test/wallet/transactions/subs.cljs | 4 +- 75 files changed, 1717 insertions(+), 1806 deletions(-) delete mode 100644 src/status_im/chat/commands/impl/transactions/subs.cljs delete mode 100644 src/status_im/chat/subs.cljs delete mode 100644 src/status_im/contact/subs.cljs delete mode 100644 src/status_im/mailserver/subs.cljs delete mode 100644 src/status_im/search/subs.cljs create mode 100644 src/status_im/subs.cljs delete mode 100644 src/status_im/ui/components/bottom_sheet/subs.cljs delete mode 100644 src/status_im/ui/components/connectivity/subs.cljs delete mode 100644 src/status_im/ui/screens/accounts/subs.cljs delete mode 100644 src/status_im/ui/screens/add_new/new_chat/subs.cljs delete mode 100644 src/status_im/ui/screens/add_new/new_public_chat/subs.cljs delete mode 100644 src/status_im/ui/screens/bootnodes_settings/edit_bootnode/subs.cljs delete mode 100644 src/status_im/ui/screens/bootnodes_settings/subs.cljs delete mode 100644 src/status_im/ui/screens/browser/subs.cljs delete mode 100644 src/status_im/ui/screens/chat/stickers/subs.cljs delete mode 100644 src/status_im/ui/screens/currency_settings/subs.cljs delete mode 100644 src/status_im/ui/screens/extensions/add/subs.cljs delete mode 100644 src/status_im/ui/screens/extensions/subs.cljs delete mode 100644 src/status_im/ui/screens/fleet_settings/subs.cljs delete mode 100644 src/status_im/ui/screens/group/subs.cljs delete mode 100644 src/status_im/ui/screens/home/subs.cljs delete mode 100644 src/status_im/ui/screens/log_level_settings/subs.cljs delete mode 100644 src/status_im/ui/screens/network_settings/edit_network/subs.cljs delete mode 100644 src/status_im/ui/screens/network_settings/subs.cljs delete mode 100644 src/status_im/ui/screens/pairing/subs.cljs delete mode 100644 src/status_im/ui/screens/profile/subs.cljs delete mode 100644 src/status_im/ui/screens/stickers/subs.cljs delete mode 100644 src/status_im/ui/screens/subs.cljs delete mode 100644 src/status_im/ui/screens/wallet/collectibles/subs.cljs delete mode 100644 src/status_im/ui/screens/wallet/request/subs.cljs delete mode 100644 src/status_im/ui/screens/wallet/send/subs.cljs delete mode 100644 src/status_im/ui/screens/wallet/settings/subs.cljs delete mode 100644 src/status_im/ui/screens/wallet/subs.cljs delete mode 100644 src/status_im/ui/screens/wallet/transactions/subs.cljs delete mode 100644 src/status_im/utils/subs.cljs diff --git a/src/status_im/android/core.cljs b/src/status_im/android/core.cljs index e6291bc705..923e664c70 100644 --- a/src/status_im/android/core.cljs +++ b/src/status_im/android/core.cljs @@ -4,7 +4,7 @@ status-im.utils.db status-im.ui.screens.db status-im.ui.screens.events - status-im.ui.screens.subs + status-im.subs status-im.data-store.core [status-im.ui.screens.views :as views] [status-im.ui.components.react :as react] @@ -22,7 +22,7 @@ (set! (.-locale rn-dependencies/i18n) (.-language event))) (defn app-root [props] - (let [keyboard-height (subscribe [:get :keyboard-height])] + (let [keyboard-height (subscribe [:keyboard-height])] (reagent/create-class {:component-will-mount (fn [] diff --git a/src/status_im/chat/commands/impl/transactions.cljs b/src/status_im/chat/commands/impl/transactions.cljs index e5cc92c64d..42f723cff7 100644 --- a/src/status_im/chat/commands/impl/transactions.cljs +++ b/src/status_im/chat/commands/impl/transactions.cljs @@ -14,7 +14,6 @@ [status-im.ui.components.svgimage :as svgimage] [status-im.i18n :as i18n] [status-im.contact.db :as db.contact] - [status-im.constants :as constants] [status-im.utils.ethereum.core :as ethereum] [status-im.utils.ethereum.tokens :as tokens] [status-im.utils.datetime :as datetime] @@ -23,10 +22,7 @@ [status-im.utils.platform :as platform] [status-im.ui.screens.wallet.db :as wallet.db] [status-im.ui.screens.wallet.choose-recipient.events :as choose-recipient.events] - [status-im.ui.screens.currency-settings.subs :as currency-settings.subs] - [status-im.models.transactions :as wallet.transactions] [status-im.ui.screens.navigation :as navigation] - status-im.chat.commands.impl.transactions.subs [status-im.ui.screens.wallet.utils :as wallet.utils])) ;; common `send/request` functionality @@ -250,9 +246,12 @@ (tokens/asset-for all-tokens (keyword network) (keyword asset)))] (assoc parameters :coin coin))) +(defn get-currency [db] + (or (get-in db [:account/account :settings :wallet :currency]) :usd)) + (defn- inject-price-info [{:keys [amount asset] :as parameters} {:keys [db]}] (let [currency (-> db - currency-settings.subs/get-currency + get-currency name string/upper-case)] (assoc parameters diff --git a/src/status_im/chat/commands/impl/transactions/subs.cljs b/src/status_im/chat/commands/impl/transactions/subs.cljs deleted file mode 100644 index 25b9a06b97..0000000000 --- a/src/status_im/chat/commands/impl/transactions/subs.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns status-im.chat.commands.impl.transactions.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :get-collectible-token - :<- [:collectibles] - (fn [collectibles [_ {:keys [symbol token]}]] - (get-in collectibles [(keyword symbol) (js/parseInt token)]))) diff --git a/src/status_im/chat/models/loading.cljs b/src/status_im/chat/models/loading.cljs index b077defbfd..a32b0a7810 100644 --- a/src/status_im/chat/models/loading.cljs +++ b/src/status_im/chat/models/loading.cljs @@ -1,9 +1,7 @@ (ns status-im.chat.models.loading - (:require [clojure.set :as set] - [status-im.accounts.db :as accounts.db] + (:require [status-im.accounts.db :as accounts.db] [status-im.chat.commands.core :as commands] [status-im.chat.models :as chat-model] - [status-im.data-store.user-statuses :as user-statuses-store] [status-im.utils.datetime :as time] [status-im.utils.fx :as fx] [status-im.utils.priority-map :refer [empty-message-map]] diff --git a/src/status_im/chat/subs.cljs b/src/status_im/chat/subs.cljs deleted file mode 100644 index a50e9965e7..0000000000 --- a/src/status_im/chat/subs.cljs +++ /dev/null @@ -1,331 +0,0 @@ -(ns status-im.chat.subs - (:require [clojure.string :as string] - [re-frame.core :as re-frame] - [status-im.chat.commands.core :as commands] - [status-im.chat.commands.input :as commands.input] - [status-im.chat.constants :as chat.constants] - [status-im.chat.db :as chat.db] - [status-im.models.transactions :as transactions] - [status-im.utils.platform :as platform] - [status-im.utils.universal-links.core :as links] - [status-im.ui.components.bottom-bar.styles :as tabs.styles] - [status-im.ui.components.toolbar.styles :as toolbar.styles] - [status-im.ui.screens.chat.stickers.styles :as stickers.styles])) - -(re-frame/reg-sub ::chats :chats) -(re-frame/reg-sub ::access-scope->command-id :access-scope->command-id) -(re-frame/reg-sub ::chat-ui-props :chat-ui-props) - -(re-frame/reg-sub - ::cooldown-enabled? - (fn [db] - (:chat/cooldown-enabled? db))) - -(re-frame/reg-sub - ::show-suggestions? - :<- [::show-suggestions-view?] - :<- [:chats/selected-chat-command] - (fn [[show-suggestions-box? selected-command]] - (and show-suggestions-box? (not selected-command)))) - -(re-frame/reg-sub - ::show-suggestions-view? - :<- [:chats/current-chat-ui-prop :show-suggestions?] - :<- [:chats/current-chat] - :<- [:chats/all-available-commands] - (fn [[show-suggestions? {:keys [input-text]} commands]] - (and (or show-suggestions? - (commands.input/starts-as-command? (string/trim (or input-text "")))) - (seq commands)))) - -(re-frame/reg-sub - ::get-commands-for-chat - :<- [:chats/id->command] - :<- [::access-scope->command-id] - :<- [:chats/current-chat] - (fn [[id->command access-scope->command-id chat]] - (commands/chat-commands id->command access-scope->command-id chat))) - -(re-frame/reg-sub :chats/id->command :id->command) -(re-frame/reg-sub :chats/current-chat-id :current-chat-id) - -(re-frame/reg-sub - :chats/chat - :<- [:chats/active-chats] - (fn [chats [_ chat-id]] - (get chats chat-id))) - -(re-frame/reg-sub - :chats/content-layout-height - :<- [:get :content-layout-height] - :<- [:chats/current-chat-ui-prop :input-height] - :<- [:chats/current-chat-ui-prop :input-focused?] - :<- [:get :keyboard-height] - :<- [:chats/current-chat-ui-prop :show-stickers?] - (fn [[home-content-layout-height input-height input-focused? kheight stickers?]] - (- (+ home-content-layout-height tabs.styles/tabs-height) - (if platform/iphone-x? - (* 2 toolbar.styles/toolbar-height) - toolbar.styles/toolbar-height) - (if input-height input-height 0) - (if stickers? - (stickers.styles/stickers-panel-height) - kheight) - (if input-focused? - (cond - platform/iphone-x? 0 - platform/ios? tabs.styles/tabs-diff - :else 0) - (cond - platform/iphone-x? (* 2 tabs.styles/minimized-tabs-height) - platform/ios? tabs.styles/tabs-height - :else tabs.styles/minimized-tabs-height))))) - -(re-frame/reg-sub - :chats/current-chat-ui-props - :<- [::chat-ui-props] - :<- [:chats/current-chat-id] - (fn [[chat-ui-props id]] - (get chat-ui-props id))) - -(re-frame/reg-sub - :chats/current-chat-ui-prop - :<- [:chats/current-chat-ui-props] - (fn [ui-props [_ prop]] - (get ui-props prop))) - -(re-frame/reg-sub - :chats/validation-messages - :<- [:chats/current-chat-ui-props] - (fn [ui-props] - (some-> ui-props :validation-messages))) - -(re-frame/reg-sub - :chats/input-margin - :<- [:get :keyboard-height] - (fn [kb-height] - (cond - (and platform/iphone-x? (> kb-height 0)) - (- kb-height (* 2 tabs.styles/minimized-tabs-height)) - - platform/ios? - (+ kb-height (- (if (> kb-height 0) - tabs.styles/minimized-tabs-height - 0))) - - :default 0))) - -(re-frame/reg-sub - :chats/active-chats - :<- [:contacts/contacts] - :<- [::chats] - :<- [:account/account] - (fn [[contacts chats account]] - (chat.db/active-chats contacts chats account))) - -(re-frame/reg-sub - :chats/current-chat - :<- [:chats/active-chats] - :<- [:chats/current-chat-id] - (fn [[chats current-chat-id]] - (let [current-chat (get chats current-chat-id) - messages (:messages current-chat)] - (if (empty? messages) - (assoc current-chat - :universal-link - (links/generate-link :public-chat :external current-chat-id)) - current-chat)))) - -(re-frame/reg-sub - :chats/current-chat-message - :<- [:chats/current-chat] - (fn [{:keys [messages]} [_ message-id]] - (get messages message-id))) - -(re-frame/reg-sub - :chats/current-chat-messages - :<- [:chats/current-chat] - (fn [{:keys [messages]}] - (or messages {}))) - -(re-frame/reg-sub - :chats/current-chat-message-groups - :<- [:chats/current-chat] - (fn [{:keys [message-groups]}] - (or message-groups {}))) - -(re-frame/reg-sub - :chats/current-chat-message-statuses - :<- [:chats/current-chat] - (fn [{:keys [message-statuses]}] - (or message-statuses {}))) - -(re-frame/reg-sub - :chats/current-chat-referenced-messages - :<- [:chats/current-chat] - (fn [{:keys [referenced-messages]}] - (or referenced-messages {}))) - -(re-frame/reg-sub - :chats/current-chat-topic - (fn [db] - (chat.db/topic-by-current-chat db))) - -(re-frame/reg-sub - :chats/messages-gaps - :<- [:get-in [:mailserver/gaps]] - :<- [:chats/current-chat-id] - (fn [[gaps chat-id]] - (sort-by :from (vals (get gaps chat-id))))) - -(re-frame/reg-sub - :chats/range - :<- [:get-in [:mailserver/ranges]] - :<- [:chats/current-chat-id] - (fn [[ranges chat-id]] - (get ranges chat-id))) - -(re-frame/reg-sub - :chats/all-loaded? - :<- [:chats/current-chat] - (fn [chat] - (:all-loaded? chat))) - -(re-frame/reg-sub - :chats/public? - :<- [:chats/current-chat] - (fn [chat] - (:public? chat))) - -(re-frame/reg-sub - :chats/current-chat-messages-stream - :<- [:chats/current-chat-messages] - :<- [:chats/current-chat-message-groups] - :<- [:chats/current-chat-message-statuses] - :<- [:chats/current-chat-referenced-messages] - :<- [:chats/messages-gaps] - :<- [:chats/range] - :<- [:chats/all-loaded?] - :<- [:chats/public?] - (fn [[messages message-groups message-statuses referenced-messages - messages-gaps range all-loaded? public?]] - (-> (chat.db/sort-message-groups message-groups messages) - (chat.db/messages-with-datemarks-and-statuses - messages message-statuses referenced-messages - messages-gaps range all-loaded? public?) - chat.db/messages-stream))) - -(re-frame/reg-sub - :chats/fetching-gap-in-progress? - (fn [db [_ ids]] - (let [chat-id (:current-chat-id db) - gaps (:mailserver/fetching-gaps-in-progress db)] - (seq (select-keys (get gaps chat-id) ids))))) - -(re-frame/reg-sub - :chats/current-chat-intro-status - :<- [:chats/current-chat] - :<- [:chats/current-chat-messages] - (fn [[{:keys [might-have-join-time-messages?]} messages]] - (if might-have-join-time-messages? - :loading - (if (empty? messages) - :empty - :messages)))) - -(re-frame/reg-sub - :chats/available-commands - :<- [::get-commands-for-chat] - :<- [:chats/current-chat] - (fn [[commands chat]] - (chat.db/available-commands commands chat))) - -(re-frame/reg-sub - :chats/all-available-commands - :<- [::get-commands-for-chat] - (fn [commands] - (chat.db/map->sorted-seq commands))) - -(re-frame/reg-sub - :chats/selected-chat-command - :<- [:chats/current-chat] - :<- [:chats/current-chat-ui-prop :selection] - :<- [::get-commands-for-chat] - (fn [[{:keys [input-text]} selection commands]] - (commands.input/selected-chat-command input-text selection commands))) - -(re-frame/reg-sub - :chats/input-placeholder - :<- [:chats/current-chat] - :<- [:chats/selected-chat-command] - (fn [[{:keys [input-text]} {:keys [params current-param-position cursor-in-the-end?]}]] - (when (and cursor-in-the-end? (string/ends-with? (or input-text "") chat.constants/spacing-char)) - (get-in params [current-param-position :placeholder])))) - -(re-frame/reg-sub - :chats/parameter-box - :<- [:chats/current-chat] - :<- [:chats/selected-chat-command] - (fn [[_ {:keys [current-param-position params]}]] - (when (and params current-param-position) - (get-in params [current-param-position :suggestions])))) - -(re-frame/reg-sub - :chats/show-parameter-box? - :<- [:chats/parameter-box] - :<- [::show-suggestions?] - :<- [:chats/validation-messages] - :<- [:chats/selected-chat-command] - (fn [[chat-parameter-box show-suggestions? validation-messages {:keys [command-completion]}]] - (and chat-parameter-box - (not validation-messages) - (not show-suggestions?) - (not (= :complete command-completion))))) - -(re-frame/reg-sub - :chats/unviewed-messages-count - (fn [[_ chat-id]] - (re-frame/subscribe [:chats/chat chat-id])) - (fn [{:keys [unviewed-messages-count]}] - unviewed-messages-count)) - -(re-frame/reg-sub - :chats/photo-path - :<- [:contacts/contacts] - :<- [:account/account] - (fn [[contacts account] [_ id]] - (or (:photo-path (contacts id)) - (when (= id (:public-key account)) - (:photo-path account))))) - -(re-frame/reg-sub - :chats/unread-messages-number - :<- [:chats/active-chats] - (fn [chats _] - (apply + (map :unviewed-messages-count (vals chats))))) - -(re-frame/reg-sub - :chats/transaction-confirmed? - (fn [db [_ tx-hash]] - (-> (get-in db [:wallet :transactions tx-hash :confirmations] "0") - (js/parseInt) - (>= transactions/confirmations-count-threshold)))) - -(re-frame/reg-sub - :chats/wallet-transaction-exists? - (fn [db [_ tx-hash]] - (not (nil? (get-in db [:wallet :transactions tx-hash]))))) - -(re-frame/reg-sub - :chats/cooldown-enabled? - :<- [:chats/current-chat] - :<- [::cooldown-enabled?] - (fn [[{:keys [public?]} cooldown-enabled?]] - (and public? - cooldown-enabled?))) - -(re-frame/reg-sub - :chats/reply-message - :<- [:chats/current-chat] - (fn [{:keys [metadata messages]}] - (get messages (get-in metadata [:responding-to-message :message-id])))) diff --git a/src/status_im/contact/subs.cljs b/src/status_im/contact/subs.cljs deleted file mode 100644 index e8dd443880..0000000000 --- a/src/status_im/contact/subs.cljs +++ /dev/null @@ -1,130 +0,0 @@ -(ns status-im.contact.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.identicon :as identicon] - [status-im.contact.db :as contact.db])) - -(re-frame/reg-sub - ::contacts - (fn [db] - (get db :contacts/contacts))) - -(re-frame/reg-sub - ::query-current-chat-contacts - :<- [:chats/current-chat] - :<- [:contacts/contacts] - (fn [[chat contacts] [_ query-fn]] - (contact.db/query-chat-contacts chat contacts query-fn))) - -(re-frame/reg-sub - :contacts/contacts - :<- [::contacts] - (fn [contacts] - (contact.db/enrich-contacts contacts))) - -(re-frame/reg-sub - :contacts/active - :<- [:contacts/contacts] - (fn [contacts] - (contact.db/get-active-contacts contacts))) - -(re-frame/reg-sub - :contacts/active-count - :<- [:contacts/active] - (fn [active-contacts] - (count active-contacts))) - -(re-frame/reg-sub - :contacts/blocked - :<- [:contacts/contacts] - (fn [contacts] - (->> contacts - (filter (fn [[_ contact]] - (contact.db/blocked? contact))) - (contact.db/sort-contacts)))) - -(re-frame/reg-sub - :contacts/blocked-count - :<- [:contacts/blocked] - (fn [blocked-contacts] - (count blocked-contacts))) - -(re-frame/reg-sub - :contacts/current-contact-identity - (fn [db] - (get db :contacts/identity))) - -(re-frame/reg-sub - :contacts/current-contact - :<- [:contacts/contacts] - :<- [:contacts/current-contact-identity] - (fn [[contacts identity]] - (or (contacts identity) - (-> identity - contact.db/public-key->new-contact - contact.db/enrich-contact)))) - -(re-frame/reg-sub - :contacts/contact-name-by-identity - :<- [:contacts/contacts] - :<- [:account/account] - (fn [[contacts current-account] [_ identity]] - (let [me? (= (:public-key current-account) identity)] - (if me? - (:name current-account) - (:name (contacts identity)))))) - -(re-frame/reg-sub - :contacts/all-contacts-not-in-current-chat - :<- [::query-current-chat-contacts remove] - (fn [contacts] - (sort-by (comp clojure.string/lower-case :name) contacts))) - -(re-frame/reg-sub - :contacts/current-chat-contacts - :<- [:chats/current-chat] - :<- [:contacts/contacts] - :<- [:account/account] - (fn [[{:keys [contacts admins]} all-contacts current-account]] - (contact.db/get-all-contacts-in-group-chat contacts admins all-contacts current-account))) - -(re-frame/reg-sub - :contacts/contacts-by-chat - (fn [[_ _ chat-id] _] - [(re-frame/subscribe [:chats/chat chat-id]) - (re-frame/subscribe [:contacts/contacts])]) - (fn [[chat all-contacts] [_ query-fn]] - (contact.db/query-chat-contacts chat all-contacts query-fn))) - -(re-frame/reg-sub - :contacts/chat-photo - (fn [[_ chat-id] _] - [(re-frame/subscribe [:chats/chat chat-id]) - (re-frame/subscribe [:contacts/contacts-by-chat filter chat-id])]) - (fn [[chat contacts] [_ chat-id]] - (when (and chat (not (:group-chat chat))) - (cond - (:photo-path chat) - (:photo-path chat) - - (pos? (count contacts)) - (:photo-path (first contacts)) - - :else - (identicon/identicon chat-id))))) - -(re-frame/reg-sub - :contacts/contact-by-address - :<- [:contacts/contacts] - (fn [contacts [_ address]] - (contact.db/find-contact-by-address contacts address))) - -(re-frame/reg-sub - :contacts/contacts-by-address - :<- [:contacts/contacts] - (fn [contacts] - (reduce (fn [acc [_ {:keys [address] :as contact}]] - (if address - (assoc acc address contact) - acc)) - {} - contacts))) diff --git a/src/status_im/desktop/core.cljs b/src/status_im/desktop/core.cljs index 2618014c2f..0fa4652522 100644 --- a/src/status_im/desktop/core.cljs +++ b/src/status_im/desktop/core.cljs @@ -4,7 +4,7 @@ status-im.utils.db status-im.ui.screens.db status-im.ui.screens.events - status-im.ui.screens.subs + status-im.subs status-im.data-store.core [reagent.impl.component :as reagent.component] [status-im.ui.components.desktop.shortcuts :as shortcuts] diff --git a/src/status_im/extensions/capacities/subs.cljs b/src/status_im/extensions/capacities/subs.cljs index 5c0a0859b0..c22fffbbcc 100644 --- a/src/status_im/extensions/capacities/subs.cljs +++ b/src/status_im/extensions/capacities/subs.cljs @@ -1,92 +1,4 @@ -(ns status-im.extensions.capacities.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.ethereum.tokens :as tokens] - [status-im.utils.ethereum.core :as ethereum] - [status-im.utils.money :as money])) - -(re-frame/reg-sub - :extensions/identity - (fn [_ [_ _ {:keys [value]}]] - value)) - -(defn get-token-for [network all-tokens token] - (if (= token "ETH") - {:decimals 18 - :address "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"} - (tokens/token-for (ethereum/network->chain-keyword network) all-tokens token))) - -(re-frame/reg-sub - :extensions.wallet/balance - :<- [:wallet/all-tokens] - :<- [:network] - :<- [:balance] - (fn [[all-tokens network balance] [_ _ {token :token}]] - (let [{:keys [decimals]} (get-token-for network all-tokens token) - value (or (get balance (keyword token)) (money/bignumber 0))] - {:value (money/token->unit value decimals) - :value-in-wei value}))) - -(re-frame/reg-sub - :extensions.wallet/token - :<- [:wallet/all-tokens] - :<- [:network] - (fn [[all-tokens network] [_ _ {token :token amount :amount amount-in-wei :amount-in-wei}]] - (let [{:keys [decimals] :as m} (get-token-for network all-tokens token)] - (merge m - (when amount {:amount-in-wei (money/unit->token amount decimals)}) - (when amount-in-wei {:amount (money/token->unit amount-in-wei decimals)}))))) - -(defn normalize-token [m] - (update m :symbol name)) - -(re-frame/reg-sub - :extensions.wallet/tokens - :<- [:wallet/all-tokens] - :<- [:wallet/visible-tokens-symbols] - :<- [:network] - (fn [[all-tokens visible-tokens-symbols network] [_ _ {filter-vector :filter visible :visible}]] - (let [tokens (map normalize-token (filter #(and (not (:nft? %)) (if visible (contains? visible-tokens-symbols (:symbol %)) true)) - (tokens/sorted-tokens-for all-tokens (ethereum/network->chain-keyword network))))] - (if filter-vector - (filter #((set filter-vector) (:symbol %)) tokens) - tokens)))) - -(re-frame/reg-sub - :store/get - (fn [db [_ {id :id} {:keys [key] :as params}]] - (let [result (get-in db [:extensions/store id key])] - (if (:reverse params) - (reverse result) - result)))) - -(re-frame/reg-sub - :store/get-in - (fn [db [_ {id :id} {:keys [keys]}]] - (get-in db (into [] (concat [:extensions/store id] keys))))) - -(defn- ->contact [{:keys [photo-path address name public-key]}] - {:photo photo-path - :name name - :address (str "0x" address) - :public-key public-key}) - -(re-frame/reg-sub - :extensions.contacts/all - :<- [:contacts/active] - (fn [[contacts] _] - (map #(update % :address ->contact)))) - -(re-frame/reg-sub - :store/get-vals - (fn [db [_ {id :id} {:keys [key]}]] - (vals (get-in db [:extensions/store id key])))) - -(re-frame/reg-sub - :extensions.time/now - (fn [_ _] - (.toLocaleString (js/Date.)))) - -;;CAPACITIES +(ns status-im.extensions.capacities.subs) (def all {'identity {:data :extensions/identity :arguments {:value :map}} diff --git a/src/status_im/fleet/core.cljs b/src/status_im/fleet/core.cljs index 8fbc818627..5274f99d2d 100644 --- a/src/status_im/fleet/core.cljs +++ b/src/status_im/fleet/core.cljs @@ -17,6 +17,10 @@ (get-in db [:account/account :settings :fleet])) config/fleet)))) +(defn current-fleet-sub [settings] + (keyword (or (get settings :fleet) + config/fleet))) + (def fleets-with-les [:les.dev.ropsten :les.dev.mainnet]) diff --git a/src/status_im/ios/core.cljs b/src/status_im/ios/core.cljs index 22089df52b..1280a8a52e 100644 --- a/src/status_im/ios/core.cljs +++ b/src/status_im/ios/core.cljs @@ -4,7 +4,7 @@ status-im.utils.db status-im.ui.screens.db status-im.ui.screens.events - status-im.ui.screens.subs + status-im.subs status-im.data-store.core [status-im.react-native.js-dependencies :as rn-dependencies] [status-im.ui.screens.views :as views] @@ -20,7 +20,7 @@ (set! (.-locale rn-dependencies/i18n) (.-language event))) (defn app-root [props] - (let [keyboard-height (subscribe [:get :keyboard-height])] + (let [keyboard-height (subscribe [:keyboard-height])] (reagent/create-class {:component-will-mount (fn [] diff --git a/src/status_im/mailserver/subs.cljs b/src/status_im/mailserver/subs.cljs deleted file mode 100644 index 5cbdf39ffa..0000000000 --- a/src/status_im/mailserver/subs.cljs +++ /dev/null @@ -1,95 +0,0 @@ -(ns status-im.mailserver.subs - (:require - [status-im.mailserver.core :as mailserver] - [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :mailserver/state - (fn [db] - (get db :mailserver/state))) - -(re-frame/reg-sub - :mailserver/pending-requests - (fn [db] - (get db :mailserver/pending-requests))) - -(re-frame/reg-sub - :mailserver/connecting? - :<- [:mailserver/state] - (fn [state] - (#{:connecting :added} state))) - -(re-frame/reg-sub - :mailserver/connection-error? - :<- [:mailserver/state] - (fn [state] - (#{:error :disconnected} state))) - -(re-frame/reg-sub - :mailserver/request-error? - (fn [db] - (get db :mailserver/request-error))) - -(re-frame/reg-sub - :mailserver/fetching? - :<- [:mailserver/state] - :<- [:mailserver/pending-requests] - :<- [:mailserver/connecting?] - :<- [:mailserver/connection-error?] - :<- [:mailserver/request-error?] - (fn [[state pending-requests connecting? connection-error? request-error?]] - (and pending-requests - (= state :connected) - (pos-int? pending-requests) - (not (or connecting? connection-error? request-error?))))) - -(re-frame/reg-sub - :mailserver/connected? - (fn [db] - (let [connected? (= :connected (:mailserver/state db)) - online? (= :online (:network-status db))] - (and connected? online?)))) - -(re-frame/reg-sub - :mailserver/current-id - (fn [db] - (:mailserver/current-id db))) - -(re-frame/reg-sub - :mailserver/preferred-id - (fn [db] - (mailserver/preferred-mailserver-id {:db db}))) - -(re-frame/reg-sub - :mailserver/mailservers - (fn [db] - (:mailserver/mailservers db))) - -(re-frame/reg-sub - :mailserver/fleet-mailservers - :<- [:settings/current-fleet] - :<- [:mailserver/mailservers] - (fn [[current-fleet mailservers]] - (current-fleet mailservers))) - -(re-frame/reg-sub - :mailserver.edit/mailserver - (fn [db] - (get db :mailserver.edit/mailserver))) - -(re-frame/reg-sub - :mailserver.edit/connected? - :<- [:mailserver.edit/mailserver] - :<- [:mailserver/current-id] - (fn [[mailserver current-mailserver-id]] - (= (get-in mailserver [:id :value]) - current-mailserver-id))) - -(re-frame/reg-sub - :mailserver.edit/validation-errors - :<- [:mailserver.edit/mailserver] - (fn [mailserver] - (set (keep - (fn [[k {:keys [error]}]] - (when error k)) - mailserver)))) diff --git a/src/status_im/search/subs.cljs b/src/status_im/search/subs.cljs deleted file mode 100644 index 28e748f35a..0000000000 --- a/src/status_im/search/subs.cljs +++ /dev/null @@ -1,52 +0,0 @@ -(ns status-im.search.subs - (:require [clojure.string :as string] - [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :search/filter - (fn [db] - (get-in db [:ui/search :filter]))) - -(defn extract-browser-attributes - [browser] - (let [{:keys [browser-id name]} (val browser)] - [browser-id name])) - -(defn extract-chat-attributes [chat] - (let [{:keys [name random-name tags]} (val chat)] - (into [name random-name] tags))) - -(defn apply-filter - "extract-attributes-fn is a function that take an element from the collection - and returns a vector of attributes which are strings - apply-filter returns the elements for which at least one attribute includes - the search-filter - apply-filter returns nil if the search-filter is empty or if there is no element - that match the filter" - [search-filter coll extract-attributes-fn] - (when (not-empty search-filter) - (let [search-filter (string/lower-case search-filter) - results (filter (fn [element] - (some (fn [s] - (when (string? s) - (string/includes? (string/lower-case s) - search-filter))) - (extract-attributes-fn element))) - coll)] - (when (not-empty results) - (sort-by #(-> % second :timestamp) > - (into {} results)))))) - -(re-frame/reg-sub - :search/filtered-chats - :<- [:chats/active-chats] - :<- [:search/filter] - (fn [[chats search-filter]] - (apply-filter search-filter chats extract-chat-attributes))) - -(re-frame/reg-sub - :search/filtered-browsers - :<- [:browser/browsers] - :<- [:search/filter] - (fn [[browsers search-filter]] - (apply-filter search-filter browsers extract-browser-attributes))) diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs new file mode 100644 index 0000000000..e4112c21ec --- /dev/null +++ b/src/status_im/subs.cljs @@ -0,0 +1,1642 @@ +(ns status-im.subs + (:require [re-frame.core :refer [reg-sub subscribe] :as re-frame] + status-im.tribute-to-talk.subs + status-im.ui.screens.hardwallet.connect.subs + status-im.ui.screens.hardwallet.settings.subs + status-im.ui.screens.hardwallet.pin.subs + status-im.ui.screens.hardwallet.setup.subs + [cljs.spec.alpha :as spec] + [clojure.string :as string] + + [status-im.chat.db :as chat.db] + [status-im.accounts.db :as accounts.db] + [status-im.contact.db :as contact.db] + + [status-im.browser.core :as browser] + [status-im.fleet.core :as fleet] + [status-im.constants :as constants] + + [status-im.models.transactions :as transactions] + [status-im.models.wallet :as models.wallet] + + [status-im.chat.commands.input :as commands.input] + [status-im.chat.commands.core :as commands] + [status-im.chat.constants :as chat.constants] + + [status-im.ui.components.toolbar.styles :as toolbar.styles] + [status-im.ui.components.bottom-bar.styles :as tabs.styles] + + [status-im.ui.screens.chat.stickers.styles :as stickers.styles] + [status-im.ui.screens.add-new.new-public-chat.db :as db] + [status-im.ui.screens.mobile-network-settings.utils :as mobile-network-utils] + [status-im.ui.screens.wallet.utils :as wallet.utils] + + [status-im.utils.universal-links.core :as links] + [status-im.utils.platform :as platform] + [status-im.utils.ethereum.core :as ethereum] + [status-im.utils.security :as security] + [status-im.utils.config :as config] + [status-im.utils.ethereum.tokens :as tokens] + [status-im.utils.money :as money] + [status-im.utils.identicon :as identicon] + [status-im.utils.build :as build] + [status-im.utils.hex :as utils.hex] + [status-im.utils.datetime :as datetime] + + [status-im.i18n :as i18n])) + +;; TOP LEVEL =========================================================================================================== + +(def subs-keys (atom {})) + +(defn reg-root-key-sub [sub-name db-key keys-key] + (swap! subs-keys update keys-key conj db-key) + (reg-sub sub-name :<- [keys-key] (fn [db] (get db db-key)))) + +;;view +(reg-root-key-sub :view-id :view-id :subs/view-keys) +(reg-root-key-sub :navigation-stack :navigation-stack :subs/view-keys) +(reg-root-key-sub :screen-params :navigation/screen-params :subs/view-keys) + +;;bottom sheet +(reg-root-key-sub :bottom-sheet/show? :bottom-sheet/show? :subs/bottom-keys) +(reg-root-key-sub :bottom-sheet/view :bottom-sheet/view :subs/bottom-keys) + +;;general +(reg-root-key-sub :network-name :chain :subs/general-keys) +(reg-root-key-sub :sync-state :sync-state :subs/general-keys) +(reg-root-key-sub :network-status :network-status :subs/general-keys) +(reg-root-key-sub :peers-count :peers-count :subs/general-keys) +(reg-root-key-sub :about-app/node-info :node-info :subs/general-keys) +(reg-root-key-sub :peers-summary :peers-summary :subs/general-keys) +(reg-root-key-sub :node-status :node/status :subs/general-keys) +(reg-root-key-sub :tab-bar-visible? :tab-bar-visible? :subs/general-keys) +(reg-root-key-sub :dimensions/window :dimensions/window :subs/general-keys) +(reg-root-key-sub :initial-props :initial-props :subs/general-keys) +(reg-root-key-sub :get-manage-extension :extensions/manage :subs/general-keys) +(reg-root-key-sub :get-staged-extension :extensions/staged-extension :subs/general-keys) +(reg-root-key-sub :get-device-UUID :device-UUID :subs/general-keys) +(reg-root-key-sub :fleets/custom-fleets :custom-fleets :subs/general-keys) +(reg-root-key-sub :chain-sync-state :node/chain-sync-state :subs/general-keys) +(reg-root-key-sub :desktop/desktop :desktop/desktop :subs/general-keys) +(reg-root-key-sub :desktop :desktop :subs/general-keys) +(reg-root-key-sub :animations :animations :subs/general-keys) +(reg-root-key-sub :get-network :network :subs/general-keys) +(reg-root-key-sub :ui/search :ui/search :subs/general-keys) +(reg-root-key-sub :web3-node-version :web3-node-version :subs/general-keys) +(reg-root-key-sub :keyboard-height :keyboard-height :subs/general-keys) +(reg-root-key-sub :sync-data :sync-data :subs/general-keys) +(reg-root-key-sub :layout-height :layout-height :subs/general-keys) +(reg-root-key-sub :mobile-network/remember-choice? :mobile-network/remember-choice? :subs/general-keys) +(reg-root-key-sub :qr-modal :qr-modal :subs/general-keys) +(reg-root-key-sub :content-layout-height :content-layout-height :subs/general-keys) +(reg-root-key-sub :bootnodes/manage :bootnodes/manage :subs/general-keys) +(reg-root-key-sub :networks/networks :networks/networks :subs/general-keys) +(reg-root-key-sub :networks/manage :networks/manage :subs/general-keys) +(reg-root-key-sub :get-pairing-installations :pairing/installations :subs/general-keys) +(reg-root-key-sub :network/type :network/type :subs/general-keys) +(reg-root-key-sub :tooltips :tooltips :subs/general-keys) + +;;profile +(reg-root-key-sub :my-profile/seed :my-profile/seed :subs/profile-keys) +(reg-root-key-sub :my-profile/advanced? :my-profile/advanced? :subs/profile-keys) +(reg-root-key-sub :my-profile/editing? :my-profile/editing? :subs/profile-keys) +(reg-root-key-sub :extensions/profile :extensions/profile :subs/profile-keys) +(reg-root-key-sub :my-profile/profile :my-profile/profile :subs/profile-keys) +;;account +(reg-root-key-sub :accounts/accounts :accounts/accounts :subs/account-keys) +(reg-root-key-sub :accounts/login :accounts/login :subs/account-keys) +(reg-root-key-sub :account/account :account/account :subs/account-keys) +(reg-root-key-sub :accounts/create :accounts/create :subs/account-keys) +(reg-root-key-sub :get-recover-account :accounts/recover :subs/account-keys) +;;chat +(reg-root-key-sub ::cooldown-enabled? :chat/cooldown-enabled? :subs/chat-keys) +(reg-root-key-sub ::chats :chats :subs/chat-keys) +(reg-root-key-sub ::access-scope->command-id :access-scope->command-id :subs/chat-keys) +(reg-root-key-sub ::chat-ui-props :chat-ui-props :subs/chat-keys) +(reg-root-key-sub :chats/id->command :id->command :subs/chat-keys) +(reg-root-key-sub :chats/current-chat-id :current-chat-id :subs/chat-keys) +(reg-root-key-sub :public-group-topic :public-group-topic :subs/chat-keys) +(reg-root-key-sub :chats/loading? :chats/loading? :subs/chat-keys) +(reg-root-key-sub :new-chat-name :new-chat-name :subs/chat-keys) +(reg-root-key-sub :group-chat-profile/editing? :group-chat-profile/editing? :subs/chat-keys) +(reg-root-key-sub :group-chat-profile/profile :group-chat-profile/profile :subs/chat-keys) +(reg-root-key-sub :selected-participants :selected-participants :subs/chat-keys) + +;;browser +(reg-root-key-sub :browsers :browser/browsers :subs/browser-keys) +(reg-root-key-sub :browser/options :browser/options :subs/browser-keys) +(reg-root-key-sub :dapps/permissions :dapps/permissions :subs/browser-keys) + +;;stickers +(reg-root-key-sub :stickers/selected-pack :stickers/selected-pack :subs/stickers-keys) +(reg-root-key-sub :stickers/packs :stickers/packs :subs/stickers-keys) +(reg-root-key-sub :stickers/installed-packs :stickers/packs-installed :subs/stickers-keys) +(reg-root-key-sub :stickers/packs-owned :stickers/packs-owned :subs/stickers-keys) +(reg-root-key-sub :stickers/packs-pendning :stickers/packs-pendning :subs/stickers-keys) + +;;mailserver +(reg-root-key-sub :mailserver/current-id :mailserver/current-id :subs/mailserver-keys) +(reg-root-key-sub :mailserver/mailservers :mailserver/mailservers :subs/mailserver-keys) +(reg-root-key-sub :mailserver.edit/mailserver :mailserver.edit/mailserver :subs/mailserver-keys) +(reg-root-key-sub :mailserver/state :mailserver/state :subs/mailserver-keys) +(reg-root-key-sub :mailserver/pending-requests :mailserver/pending-requests :subs/mailserver-keys) +(reg-root-key-sub :mailserver/request-error? :mailserver/request-error :subs/mailserver-keys) +(reg-root-key-sub :mailserver/fetching-gaps-in-progress :mailserver/fetching-gaps-in-progress :subs/mailserver-keys) +(reg-root-key-sub :mailserver/gaps :mailserver/gaps :subs/mailserver-keys) +(reg-root-key-sub :mailserver/ranges :mailserver/ranges :subs/mailserver-keys) + +;;contacts +(reg-root-key-sub ::contacts :contacts/contacts :subs/contacts-keys) +(reg-root-key-sub :contacts/current-contact-identity :contacts/identity :subs/contacts-keys) +(reg-root-key-sub :new-identity-error :contacts/new-identity-error :subs/general-keys) +(reg-root-key-sub :contacts/new-identity :contacts/new-identity :subs/general-keys) +(reg-root-key-sub :group/selected-contacts :group/selected-contacts :subs/general-keys) +;;wallet +(reg-root-key-sub :wallet :wallet :subs/wallet-keys) +(reg-root-key-sub :prices :prices :subs/wallet-keys) +(reg-root-key-sub :collectibles :collectibles :subs/wallet-keys) +(reg-root-key-sub :wallet/all-tokens :wallet/all-tokens :subs/wallet-keys) +(reg-root-key-sub :prices-loading? :prices-loading? :subs/wallet-keys) +(reg-root-key-sub :wallet.transactions :wallet.transactions :subs/wallet-keys) + +(doseq [[subs-key db-keys] @subs-keys] + (reg-sub + subs-key + (fn [db] + (select-keys db db-keys)))) + +;;GENERAL ============================================================================================================== + +(reg-sub + :connection-stats + :<- [:desktop/desktop] + (fn [desktop _] + (get desktop :debug-metrics))) + +(reg-sub + :settings/logging-enabled + :<- [:desktop/desktop] + (fn [desktop _] + (get desktop :logging-enabled false))) + +;;TODO we have network in two different places see :account/network, what's the difference? +(reg-sub + :network + :<- [:account/account] + (fn [current-account] + (get (:networks current-account) (:network current-account)))) + +(reg-sub + :disconnected? + :<- [:peers-count] + (fn [peers-count] + (zero? peers-count))) + +(reg-sub + :offline? + :<- [:network-status] + :<- [:sync-state] + :<- [:disconnected?] + (fn [[network-status sync-state disconnected?]] + (or disconnected? + (= network-status :offline) + (= sync-state :offline)))) + +(reg-sub + :syncing? + :<- [:sync-state] + (fn [sync-state] + (#{:pending :in-progress} sync-state))) + +(reg-sub + :dimensions/window-width + :<- [:dimensions/window] + :width) + +(reg-sub + :get-screen-params + :<- [:screen-params] + :<- [:view-id] + (fn [[params view-id-db] [_ view-id]] + (get params (or view-id view-id-db)))) + +(reg-sub + :can-navigate-back? + :<- [:navigation-stack] + (fn [stack] + (> (count stack) 1))) + +(reg-sub + :delete-swipe-position + :<- [:animations] + (fn [animations [_ type item-id]] + (get-in animations [type item-id :delete-swiped]))) + +(reg-sub + :search/filter + :<- [:ui/search] + (fn [search] + (get search :filter))) + +(defn- node-version [web3-node-version] + (str "status-go v" (or web3-node-version "N/A") "")) + +(def app-short-version + (let [version (if platform/desktop? build/version build/build-no)] + (str build/version " (" version ")"))) + +(reg-sub + :get-app-version + :<- [:web3-node-version] + (fn [web3-node-version] + (str app-short-version "; " (node-version web3-node-version)))) + +(reg-sub + :get-app-short-version + (fn [db] app-short-version)) + +(reg-sub + :get-app-node-version + :<- [:web3-node-version] + node-version) + +(reg-sub + :my-profile/recovery + :<- [:my-profile/seed] + (fn [seed] + (or seed {:step :intro}))) + +(reg-sub + :bottom-sheet + :<- [:bottom-sheet/show?] + :<- [:bottom-sheet/view] + (fn [[show? view]] + {:show? show? + :view view})) + +(reg-sub + :is-contact-selected? + :<- [:group/selected-contacts] + (fn [selected-contacts [_ element]] + (-> selected-contacts + (contains? element)))) + +(reg-sub + :is-participant-selected? + :<- [:selected-participants] + (fn [selected-participants [_ element]] + (-> selected-participants + (contains? element)))) + +;;ACCOUNT ============================================================================================================== + +(reg-sub + :account/public-key + :<- [:account/account] + (fn [{:keys [public-key]}] + public-key)) + +(reg-sub + :account/hex-address + :<- [:account/account] + (fn [{:keys [address]}] + (ethereum/normalized-address address))) + +(reg-sub + :sign-in-enabled? + :<- [:accounts/login] + :<- [:node-status] + (fn [[{:keys [password]} status]] + (and (or (nil? status) (= status :stopped)) + (spec/valid? ::accounts.db/password + (security/safe-unmask-data password))))) + +(reg-sub + :settings/current-fleet + :<- [:account-settings] + (fn [sett] + (fleet/current-fleet-sub sett))) + +(reg-sub + :get-account-creation-next-enabled? + :<- [:accounts/create] + (fn [create] + (accounts.db/account-creation-next-enabled? create))) + +(reg-sub + :account-settings + :<- [:account/account] + (fn [acc] + (get acc :settings))) + +;;TODO we have network in two different places see :network, what's the difference? +(reg-sub + :account/network + :<- [:account/account] + :<- [:get-network] + (fn [[account network]] + (get-in account [:networks network]))) + +(reg-sub + :current-network-initialized? + :<- [:account/network] + (fn [network] + (boolean network))) + +(reg-sub + :current-network-uses-rpc? + :<- [:account/network] + (fn [network] + (get-in network [:config :UpstreamConfig :Enabled]))) + +(reg-sub + :latest-block-number + (fn [{:node/keys [latest-block-number]} _] + (if latest-block-number latest-block-number 0))) + +(reg-sub + :settings/current-log-level + :<- [:account-settings] + (fn [sett] + (or (get sett :log-level) + config/log-level-status-go))) + +;;CHAT ============================================================================================================== + +(reg-sub + :get-collectible-token + :<- [:collectibles] + (fn [collectibles [_ {:keys [symbol token]}]] + (get-in collectibles [(keyword symbol) (js/parseInt token)]))) + +(reg-sub + ::show-suggestions-view? + :<- [:chats/current-chat-ui-prop :show-suggestions?] + :<- [:chats/current-chat] + :<- [:chats/all-available-commands] + (fn [[show-suggestions? {:keys [input-text]} commands]] + (and (or show-suggestions? + (commands.input/starts-as-command? (string/trim (or input-text "")))) + (seq commands)))) + +(reg-sub + ::show-suggestions? + :<- [::show-suggestions-view?] + :<- [:chats/selected-chat-command] + (fn [[show-suggestions-box? selected-command]] + (and show-suggestions-box? (not selected-command)))) + +(reg-sub + ::get-commands-for-chat + :<- [:chats/id->command] + :<- [::access-scope->command-id] + :<- [:chats/current-chat] + (fn [[id->command access-scope->command-id chat]] + (commands/chat-commands id->command access-scope->command-id chat))) + +(reg-sub + :chats/chat + :<- [:chats/active-chats] + (fn [chats [_ chat-id]] + (get chats chat-id))) + +(reg-sub + :chats/content-layout-height + :<- [:content-layout-height] + :<- [:chats/current-chat-ui-prop :input-height] + :<- [:chats/current-chat-ui-prop :input-focused?] + :<- [:keyboard-height] + :<- [:chats/current-chat-ui-prop :show-stickers?] + (fn [[home-content-layout-height input-height input-focused? kheight stickers?]] + (- (+ home-content-layout-height tabs.styles/tabs-height) + (if platform/iphone-x? + (* 2 toolbar.styles/toolbar-height) + toolbar.styles/toolbar-height) + (if input-height input-height 0) + (if stickers? + (stickers.styles/stickers-panel-height) + kheight) + (if input-focused? + (cond + platform/iphone-x? 0 + platform/ios? tabs.styles/tabs-diff + :else 0) + (cond + platform/iphone-x? (* 2 tabs.styles/minimized-tabs-height) + platform/ios? tabs.styles/tabs-height + :else tabs.styles/minimized-tabs-height))))) + +(reg-sub + :chats/current-chat-ui-props + :<- [::chat-ui-props] + :<- [:chats/current-chat-id] + (fn [[chat-ui-props id]] + (get chat-ui-props id))) + +(reg-sub + :chats/current-chat-ui-prop + :<- [:chats/current-chat-ui-props] + (fn [ui-props [_ prop]] + (get ui-props prop))) + +(reg-sub + :chats/validation-messages + :<- [:chats/current-chat-ui-props] + (fn [ui-props] + (some-> ui-props :validation-messages))) + +(reg-sub + :chats/input-margin + :<- [:keyboard-height] + (fn [kb-height] + (cond + (and platform/iphone-x? (> kb-height 0)) + (- kb-height (* 2 tabs.styles/minimized-tabs-height)) + + platform/ios? + (+ kb-height (- (if (> kb-height 0) + tabs.styles/minimized-tabs-height + 0))) + + :default 0))) + +(reg-sub + :chats/active-chats + :<- [:contacts/contacts] + :<- [::chats] + :<- [:account/account] + (fn [[contacts chats account]] + (chat.db/active-chats contacts chats account))) + +(reg-sub + :chats/current-chat + :<- [:chats/active-chats] + :<- [:chats/current-chat-id] + (fn [[chats current-chat-id]] + (let [current-chat (get chats current-chat-id) + messages (:messages current-chat)] + (if (empty? messages) + (assoc current-chat :universal-link (links/generate-link :public-chat :external current-chat-id)) + current-chat)))) + +(reg-sub + :chats/current-chat-message + :<- [:chats/current-chat] + (fn [{:keys [messages]} [_ message-id]] + (get messages message-id))) + +(reg-sub + :chats/current-chat-messages + :<- [:chats/current-chat] + (fn [{:keys [messages]}] + (or messages {}))) + +(reg-sub + :chats/current-chat-message-groups + :<- [:chats/current-chat] + (fn [{:keys [message-groups]}] + (or message-groups {}))) + +(reg-sub + :chats/current-chat-message-statuses + :<- [:chats/current-chat] + (fn [{:keys [message-statuses]}] + (or message-statuses {}))) + +(reg-sub + :chats/current-chat-referenced-messages + :<- [:chats/current-chat] + (fn [{:keys [referenced-messages]}] + (or referenced-messages {}))) + +(re-frame/reg-sub + :chats/messages-gaps + :<- [:mailserver/gaps] + :<- [:chats/current-chat-id] + (fn [[gaps chat-id]] + (sort-by :from (vals (get gaps chat-id))))) + +(re-frame/reg-sub + :chats/range + :<- [:mailserver/ranges] + :<- [:chats/current-chat-id] + (fn [[ranges chat-id]] + (get ranges chat-id))) + +(re-frame/reg-sub + :chats/all-loaded? + :<- [:chats/current-chat] + (fn [chat] + (:all-loaded? chat))) + +(re-frame/reg-sub + :chats/public? + :<- [:chats/current-chat] + (fn [chat] + (:public? chat))) + +(re-frame/reg-sub + :chats/current-chat-messages-stream + :<- [:chats/current-chat-messages] + :<- [:chats/current-chat-message-groups] + :<- [:chats/current-chat-message-statuses] + :<- [:chats/current-chat-referenced-messages] + :<- [:chats/messages-gaps] + :<- [:chats/range] + :<- [:chats/all-loaded?] + :<- [:chats/public?] + (fn [[messages message-groups message-statuses referenced-messages + messages-gaps range all-loaded? public?]] + (-> (chat.db/sort-message-groups message-groups messages) + (chat.db/messages-with-datemarks-and-statuses + messages message-statuses referenced-messages + messages-gaps range all-loaded? public?) + chat.db/messages-stream))) + +(reg-sub + :chats/current-chat-intro-status + :<- [:chats/current-chat] + :<- [:chats/current-chat-messages] + (fn [[{:keys [might-have-join-time-messages?]} messages]] + (if might-have-join-time-messages? + :loading + (if (empty? messages) + :empty + :messages)))) + +(reg-sub + :chats/available-commands + :<- [::get-commands-for-chat] + :<- [:chats/current-chat] + (fn [[commands chat]] + (chat.db/available-commands commands chat))) + +(reg-sub + :chats/all-available-commands + :<- [::get-commands-for-chat] + (fn [commands] + (chat.db/map->sorted-seq commands))) + +(reg-sub + :chats/selected-chat-command + :<- [:chats/current-chat] + :<- [:chats/current-chat-ui-prop :selection] + :<- [::get-commands-for-chat] + (fn [[{:keys [input-text]} selection commands]] + (commands.input/selected-chat-command input-text selection commands))) + +(reg-sub + :chats/input-placeholder + :<- [:chats/current-chat] + :<- [:chats/selected-chat-command] + (fn [[{:keys [input-text]} {:keys [params current-param-position cursor-in-the-end?]}]] + (when (and cursor-in-the-end? (string/ends-with? (or input-text "") chat.constants/spacing-char)) + (get-in params [current-param-position :placeholder])))) + +(reg-sub + :chats/parameter-box + :<- [:chats/current-chat] + :<- [:chats/selected-chat-command] + (fn [[_ {:keys [current-param-position params]}]] + (when (and params current-param-position) + (get-in params [current-param-position :suggestions])))) + +(reg-sub + :chats/show-parameter-box? + :<- [:chats/parameter-box] + :<- [::show-suggestions?] + :<- [:chats/validation-messages] + :<- [:chats/selected-chat-command] + (fn [[chat-parameter-box show-suggestions? validation-messages {:keys [command-completion]}]] + (and chat-parameter-box + (not validation-messages) + (not show-suggestions?) + (not (= :complete command-completion))))) + +(reg-sub + :chats/unviewed-messages-count + (fn [[_ chat-id]] + (subscribe [:chats/chat chat-id])) + (fn [{:keys [unviewed-messages-count]}] + unviewed-messages-count)) + +(reg-sub + :chats/photo-path + :<- [:contacts/contacts] + :<- [:account/account] + (fn [[contacts account] [_ id]] + (or (:photo-path (contacts id)) + (when (= id (:public-key account)) + (:photo-path account))))) + +(reg-sub + :chats/unread-messages-number + :<- [:chats/active-chats] + (fn [chats _] + (apply + (map :unviewed-messages-count (vals chats))))) + +(reg-sub + :chats/cooldown-enabled? + :<- [:chats/current-chat] + :<- [::cooldown-enabled?] + (fn [[{:keys [public?]} cooldown-enabled?]] + (and public? + cooldown-enabled?))) + +(reg-sub + :chats/reply-message + :<- [:chats/current-chat] + (fn [{:keys [metadata messages]}] + (get messages (get-in metadata [:responding-to-message :message-id])))) + +(reg-sub + :public-chat.new/topic-error-message + :<- [:public-group-topic] + (fn [topic] + (when-not (or (empty? topic) + (db/valid-topic? topic)) + (i18n/label :topic-name-error)))) + +(defn filter-selected-contacts + [selected-contacts contacts] + (filter #(contact.db/added? (contacts %)) selected-contacts)) + +(reg-sub + :selected-contacts-count + :<- [:group/selected-contacts] + :<- [:contacts/contacts] + (fn [[selected-contacts contacts]] + (count (filter-selected-contacts selected-contacts contacts)))) + +(reg-sub + :selected-participants-count + :<- [:selected-participants] + (fn [selected-participants] + (count selected-participants))) + +(defn filter-contacts [selected-contacts active-contacts] + (filter #(selected-contacts (:public-key %)) active-contacts)) + +(reg-sub + :selected-group-contacts + :<- [:group/selected-contacts] + :<- [:contacts/active] + (fn [[selected-contacts active-contacts]] + (filter-contacts selected-contacts active-contacts))) + +(reg-sub + :chats/transaction-confirmed? + :<- [:wallet-transactions] + (fn [txs [_ tx-hash]] + (-> (get-in txs [tx-hash :confirmations] "0") + (js/parseInt) + (>= transactions/confirmations-count-threshold)))) + +(reg-sub + :chats/wallet-transaction-exists? + :<- [:wallet-transactions] + (fn [txs [_ tx-hash]] + (not (nil? (get txs tx-hash))))) + +;;BOOTNODES ============================================================================================================ + +(reg-sub + :settings/bootnodes-enabled + :<- [:account/account] + (fn [account] + (let [{:keys [network settings]} account] + (get-in settings [:bootnodes network])))) + +(reg-sub + :settings/network-bootnodes + :<- [:account/account] + (fn [account] + (get-in account [:bootnodes (:network account)]))) + +(reg-sub + :get-manage-bootnode + :<- [:bootnodes/manage] + (fn [manage] + manage)) + +(reg-sub + :manage-bootnode-validation-errors + :<- [:get-manage-bootnode] + (fn [manage] + (set (keep + (fn [[k {:keys [error]}]] + (when error k)) + manage)))) + +;;BROWSER ============================================================================================================== + +(reg-sub + :browser/browsers + :<- [:browsers] + (fn [browsers] + (reduce (fn [acc [k browser]] + (update acc k assoc :url (browser/get-current-url browser))) + browsers + browsers))) + +(reg-sub + :browser/browsers-vals + :<- [:browser/browsers] + (fn [browsers] + (sort-by :timestamp > (vals browsers)))) + +(reg-sub + :get-current-browser + :<- [:browser/options] + :<- [:browser/browsers] + (fn [[options browsers]] + (let [browser (get browsers (:browser-id options))] + (assoc browser :secure? (browser/secure? browser options))))) + +;;STICKERS ============================================================================================================= + +(reg-sub + :stickers/installed-packs-vals + :<- [:stickers/installed-packs] + (fn [packs] + (vals packs))) + +(reg-sub + :stickers/all-packs + :<- [:stickers/packs] + :<- [:stickers/installed-packs] + :<- [:stickers/packs-owned] + :<- [:stickers/packs-pendning] + (fn [[packs installed owned pending]] + (map (fn [{:keys [id] :as pack}] + (cond-> pack + (get installed id) (assoc :installed true) + (get owned id) (assoc :owned true) + (get pending id) (assoc :pending true))) + (vals packs)))) + +(reg-sub + :stickers/get-current-pack + :<- [:get-screen-params] + :<- [:stickers/all-packs] + (fn [[{:keys [id]} packs]] + (first (filter #(= (:id %) id) packs)))) + +(defn find-pack-id-for-uri [sticker-uri packs] + (some (fn [{:keys [stickers id]}] + (when (some #(= sticker-uri (:uri %)) stickers) + id)) + packs)) + +(reg-sub + :stickers/recent + :<- [:account/account] + :<- [:stickers/installed-packs-vals] + (fn [[{:keys [recent-stickers]} packs]] + (map (fn [uri] {:uri uri :pack (find-pack-id-for-uri uri packs)}) recent-stickers))) + +;;EXTENSIONS =========================================================================================================== + +(reg-sub + :extensions/all-extensions + :<- [:account/account] + (fn [account] + (get account :extensions))) + +;;HOME ================================================================================================================= + +(reg-sub + :home-items + :<- [:chats/active-chats] + :<- [:search/filter] + :<- [:search/filtered-chats] + (fn [[chats search-filter filtered-chats]] + (if (or (nil? search-filter) + (and platform/desktop? (empty? search-filter))) + {:all-home-items + (sort-by #(-> % second :timestamp) > chats)} + {:search-filter search-filter + :chats filtered-chats}))) + +;;NETWORK SETTINGS ===================================================================================================== + +(reg-sub + :get-network-id + :<- [:network] + (fn [network] + (ethereum/network->chain-id network))) + +(defn- filter-networks [network-type] + (fn [network] + (let [chain-id (ethereum/network->chain-id network) + testnet? (ethereum/testnet? chain-id) + custom? (:custom? network)] + (case network-type + :custom custom? + :mainnet (and (not custom?) (not testnet?)) + :testnet (and (not custom?) testnet?))))) + +(defn- label-networks [default-networks] + (fn [network] + (let [custom? (not (contains? default-networks (:id network)))] + (assoc network :custom? custom?)))) + +(reg-sub + :get-networks + :<- [:account/account] + :<- [:networks/networks] + (fn [[{:keys [networks] :as account} default-networks]] + (let [networks (map (label-networks default-networks) (sort-by :name (vals networks))) + types [:mainnet :testnet :custom]] + (zipmap + types + (map #(filter (filter-networks %) networks) types))))) + +(reg-sub + :get-manage-network + :<- [:networks/manage] + (fn [manage] + manage)) + +(reg-sub + :manage-network-valid? + :<- [:get-manage-network] + (fn [manage] + (not-any? :error (vals manage)))) + +;;PAIRING ============================================================================================================== + +(reg-sub + :pairing/installations + :<- [:get-pairing-installations] + (fn [installations] + (->> installations + vals + (sort-by (comp unchecked-negate :last-paired))))) + +(reg-sub + :pairing/installation-id + :<- [:account/account] + :installation-id) + +(reg-sub + :pairing/installation-name + :<- [:account/account] + (fn [account] (:installation-name account))) + +;;PROFILE ============================================================================================================== + +(reg-sub + :get-profile-unread-messages-number + :<- [:account/account] + (fn [{:keys [seed-backed-up? mnemonic]}] + (if (or seed-backed-up? (string/blank? mnemonic)) 0 1))) + +;;WALLET ============================================================================================================== + +(reg-sub + :balance + :<- [:wallet] + (fn [wallet] + (:balance wallet))) + +(reg-sub + :price + :<- [:prices] + (fn [prices [_ fsym tsym]] + (get-in prices [fsym tsym :price]))) + +(reg-sub + :last-day + :<- [:prices] + (fn [prices [_ fsym tsym]] + (get-in prices [fsym tsym :last-day]))) + +(reg-sub + :wallet-transactions + :<- [:wallet] + (fn [wallet] + (get wallet :transactions))) + +(reg-sub + :wallet.settings/currency + :<- [:account-settings] + (fn [sett] + (or (get-in sett [:wallet :currency]) :usd))) + +(reg-sub + :wallet.transactions/filters + :<- [:wallet.transactions] + (fn [txs] + (get txs :filters))) + +(reg-sub + :asset-value + (fn [[_ fsym decimals tsym]] + [(subscribe [:balance]) + (subscribe [:price fsym tsym]) + (subscribe [:wallet/currency])]) + (fn [[balance price currency] [_ fsym decimals tsym]] + (when (and balance price) + (-> (money/internal->formatted (get balance fsym) fsym decimals) + (money/crypto->fiat price) + (money/with-precision 2) + str + (i18n/format-currency (:code currency)))))) + +(defn- get-balance-total-value [balance prices currency token->decimals] + (reduce-kv (fn [acc symbol value] + (if-let [price (get-in prices [symbol currency :price])] + (+ acc (-> (money/internal->formatted value symbol (token->decimals symbol)) + (money/crypto->fiat price) + .toNumber)) + acc)) 0 balance)) + +(reg-sub + :portfolio-value + :<- [:balance] + :<- [:prices] + :<- [:wallet/currency] + :<- [:network] + :<- [:wallet/all-tokens] + (fn [[balance prices currency network all-tokens] [_ currency-code]] + (if (and balance prices) + (let [assets (tokens/tokens-for all-tokens (ethereum/network->chain-keyword network)) + token->decimals (into {} (map #(vector (:symbol %) (:decimals %)) assets)) + balance-total-value + (get-balance-total-value balance + prices + (or currency-code + (-> currency :code keyword)) + token->decimals)] + (if (pos? balance-total-value) + (-> balance-total-value + (money/with-precision 2) + str + (i18n/format-currency (:code currency) false)) + "0")) + "..."))) + +(reg-sub + :wallet/balance-loading? + :<- [:wallet] + (fn [wallet] + (:balance-loading? wallet))) + +(reg-sub + :wallet/error-message + :<- [:wallet] + (fn [wallet] + (or (get-in wallet [:errors :balance-update]) + (get-in wallet [:errors :prices-update])))) + +(reg-sub + :get-wallet-unread-messages-number + (fn [db] + 0)) + +(reg-sub + :wallet/visible-tokens-symbols + :<- [:network] + :<- [:account/account] + (fn [[network current-account]] + (let [chain (ethereum/network->chain-keyword network)] + (get-in current-account [:settings :wallet :visible-tokens chain])))) + +(reg-sub + :wallet/visible-assets + :<- [:network] + :<- [:wallet/visible-tokens-symbols] + :<- [:wallet/all-tokens] + (fn [[network visible-tokens-symbols all-tokens]] + (let [chain (ethereum/network->chain-keyword network)] + (conj (filter #(contains? visible-tokens-symbols (:symbol %)) + (tokens/sorted-tokens-for all-tokens (ethereum/network->chain-keyword network))) + (tokens/native-currency chain))))) + +(reg-sub + :wallet/visible-assets-with-amount + :<- [:balance] + :<- [:wallet/visible-assets] + (fn [[balance visible-assets]] + (map #(assoc % :amount (get balance (:symbol %))) visible-assets))) + +(reg-sub + :wallet/transferrable-assets-with-amount + :<- [:wallet/visible-assets-with-amount] + (fn [all-assets] + (filter #(not (:nft? %)) all-assets))) + +(reg-sub + :wallet/currency + :<- [:wallet.settings/currency] + (fn [currency-id] + (get constants/currencies currency-id))) + +;;WALLET TRANSACTIONS ================================================================================================== + +(reg-sub + :wallet.transactions/current-tab + :<- [:wallet] + (fn [wallet] + (get wallet :current-tab 0))) + +(defn enrich-transaction [{:keys [type to from timestamp] :as transaction} contacts] + (let [[contact-address key-contact key-wallet] (if (= type :inbound) + [from :from-contact :to-wallet] + [to :to-contact :from-wallet]) + wallet (i18n/label :main-wallet) + contact (get contacts (utils.hex/normalize-hex contact-address))] + (cond-> transaction + contact (assoc key-contact (:name contact)) + :always (assoc key-wallet wallet + :time-formatted (datetime/timestamp->time timestamp))))) + +(reg-sub + :wallet.transactions/transactions + :<- [:wallet] + :<- [:contacts/contacts-by-address] + (fn [[wallet contacts]] + (reduce (fn [acc [hash transaction]] + (assoc acc hash (enrich-transaction transaction contacts))) + {} + (:transactions wallet)))) + +(reg-sub + :wallet.transactions/grouped-transactions + :<- [:wallet.transactions/transactions] + (fn [transactions] + (group-by :type (vals transactions)))) + +(reg-sub + :wallet.transactions/pending-transactions-list + :<- [:wallet.transactions/grouped-transactions] + (fn [{:keys [pending]}] + (when pending + {:title "Pending" + :key :pending + :data pending}))) + +(reg-sub + :wallet.transactions/failed-transactions-list + :<- [:wallet.transactions/grouped-transactions] + (fn [{:keys [failed]}] + (when failed + {:title "Failed" + :key :failed + :data failed}))) + +(defn group-transactions-by-date [transactions] + (->> transactions + (group-by #(datetime/timestamp->date-key (:timestamp %))) + (sort-by key) + reverse + (map (fn [[date-key transactions]] + {:title (datetime/timestamp->mini-date (:timestamp (first transactions))) + :key date-key + :data (sort-by :timestamp > transactions)})))) + +(reg-sub + :wallet.transactions/completed-transactions-list + :<- [:wallet.transactions/grouped-transactions] + (fn [{:keys [inbound outbound failed]}] + (group-transactions-by-date (concat inbound outbound failed)))) + +(reg-sub + :wallet.transactions/transactions-history-list + :<- [:wallet.transactions/pending-transactions-list] + :<- [:wallet.transactions/completed-transactions-list] + (fn [[pending completed]] + (cond-> [] + pending (into pending) + completed (into completed)))) + +(reg-sub + :wallet.transactions/current-transaction + :<- [:wallet] + (fn [wallet] + (:current-transaction wallet))) + +(reg-sub + :wallet.transactions/transaction-details + :<- [:wallet.transactions/transactions] + :<- [:wallet.transactions/current-transaction] + :<- [:network] + (fn [[transactions current-transaction network]] + (let [{:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction) + chain (ethereum/network->chain-keyword network) + native-currency (tokens/native-currency chain) + display-unit (wallet.utils/display-symbol native-currency)] + (when transaction + (merge transaction + {:gas-price-eth (if gas-price (money/wei->str :eth gas-price display-unit) "-") + :gas-price-gwei (if gas-price (money/wei->str :gwei gas-price) "-") + :date (datetime/timestamp->long-date timestamp)} + (if (= type :unsigned) + {:block (i18n/label :not-applicable) + :cost (i18n/label :not-applicable) + :gas-limit (i18n/label :not-applicable) + :gas-used (i18n/label :not-applicable) + :nonce (i18n/label :not-applicable) + :hash (i18n/label :not-applicable)} + {:cost (when gas-used + (money/wei->str :eth (money/fee-value gas-used gas-price) display-unit)) + :url (transactions/get-transaction-details-url chain hash)})))))) + +(reg-sub + :wallet.transactions.details/confirmations + :<- [:wallet.transactions/transaction-details] + (fn [transaction-details] + ;;TODO (yenda) this field should be calculated based on the current-block and the block of the transaction + (:confirmations transaction-details))) + +(reg-sub + :wallet.transactions.details/confirmations-progress + :<- [:wallet.transactions.details/confirmations] + (fn [confirmations] + (let [max-confirmations 10] + (if (>= confirmations max-confirmations) + 100 + (* 100 (/ confirmations max-confirmations)))))) + +;;WALLET SEND ========================================================================================================== + +(reg-sub + ::send-transaction + :<- [:wallet] + (fn [wallet] + (:send-transaction wallet))) + +(reg-sub + :wallet.send/symbol + :<- [::send-transaction] + (fn [send-transaction] + (:symbol send-transaction))) + +(reg-sub + :wallet.send/advanced? + :<- [::send-transaction] + (fn [send-transaction] + (:advanced? send-transaction))) + +(reg-sub + :wallet.send/camera-flashlight + :<- [::send-transaction] + (fn [send-transaction] + (:camera-flashlight send-transaction))) + +(reg-sub + :wallet.send/wrong-password? + :<- [::send-transaction] + (fn [send-transaction] + (:wrong-password? send-transaction))) + +(reg-sub + :wallet.send/sign-password-enabled? + :<- [::send-transaction] + (fn [{:keys [password]}] + (and (not (nil? password)) (not= password "")))) + +(defn edit-or-transaction-data + "Set up edit data structure, defaulting to transaction when not available" + [transaction edit] + (cond-> edit + (not (get-in edit [:gas-price :value])) + (models.wallet/build-edit + :gas-price + (money/to-fixed (money/wei-> :gwei (:gas-price transaction)))) + + (not (get-in edit [:gas :value])) + (models.wallet/build-edit + :gas + (money/to-fixed (:gas transaction))))) + +(reg-sub + :wallet/edit + :<- [::send-transaction] + :<- [:wallet] + (fn [[send-transaction {:keys [edit]}]] + (edit-or-transaction-data + send-transaction + edit))) + +(defn check-sufficient-funds [transaction balance symbol amount] + (assoc transaction :sufficient-funds? + (or (nil? amount) + (money/sufficient-funds? amount (get balance symbol))))) + +(defn check-sufficient-gas [transaction balance symbol amount] + (assoc transaction :sufficient-gas? + (or (nil? amount) + (let [available-ether (get balance :ETH (money/bignumber 0)) + available-for-gas (if (= :ETH symbol) + (.minus available-ether (money/bignumber amount)) + available-ether)] + (money/sufficient-funds? (-> transaction + :max-fee + money/bignumber + (money/formatted->internal :ETH 18)) + (money/bignumber available-for-gas)))))) + +(reg-sub + :wallet.send/transaction + :<- [::send-transaction] + :<- [:balance] + (fn [[{:keys [amount symbol] :as transaction} balance]] + (-> transaction + (models.wallet/add-max-fee) + (check-sufficient-funds balance symbol amount) + (check-sufficient-gas balance symbol amount)))) + +(reg-sub + :wallet.send/signing-phrase-with-padding + :<- [:account/account] + (fn [{:keys [signing-phrase]}] + (when signing-phrase + (clojure.string/replace-all signing-phrase #" " " ")))) + +(reg-sub + :wallet/settings + :<- [:wallet] + (fn [{:keys [settings]}] + (reduce-kv #(conj %1 %3) [] settings))) + +(reg-sub + :wallet.request/transaction + :<- [:wallet] + :request-transaction) + +(reg-sub + :screen-collectibles + :<- [:collectibles] + :<- [:get-screen-params] + (fn [[collectibles {:keys [symbol]}]] + (when-let [v (get collectibles symbol)] + (mapv #(assoc (second %) :id (first %)) v)))) + +;;UI ============================================================================================================== + +;;TODO this subscription looks super weird huge and with dispatches? +(reg-sub + :connectivity/status-properties + :<- [:offline?] + :<- [:disconnected?] + :<- [:mailserver/connecting?] + :<- [:mailserver/connection-error?] + :<- [:mailserver/request-error?] + :<- [:mailserver/fetching?] + :<- [:network/type] + :<- [:account/account] + (fn [[offline? disconnected? mailserver-connecting? mailserver-connection-error? + mailserver-request-error? mailserver-fetching? network-type account]] + (let [wallet-offline? (and offline? + ;; There's no wallet of desktop + (not platform/desktop?)) + error-label (cond + (and wallet-offline? + disconnected?) + :t/offline + + wallet-offline? + :t/wallet-offline + + disconnected? + :t/disconnected + + mailserver-connecting? + :t/connecting + + mailserver-connection-error? + :t/mailserver-reconnect + + mailserver-request-error? + :t/mailserver-request-error-status + + (and (mobile-network-utils/cellular? network-type) + (not (:syncing-on-mobile-network? account))) + :mobile-network + + :else nil)] + {:message (or error-label :t/connected) + :connected? (and (nil? error-label) (not= :mobile-network error-label)) + :connecting? (= error-label :t/connecting) + :loading-indicator? mailserver-fetching? + :on-press-fn #(cond + mailserver-connection-error? + (re-frame/dispatch [:mailserver.ui/reconnect-mailserver-pressed]) + mailserver-request-error? + (re-frame/dispatch [:mailserver.ui/request-error-pressed]) + + (= :mobile-network error-label) + (re-frame/dispatch [:mobile-network/show-offline-sheet]))}))) + +;;CONTACT ============================================================================================================== + +(reg-sub + ::query-current-chat-contacts + :<- [:chats/current-chat] + :<- [:contacts/contacts] + (fn [[chat contacts] [_ query-fn]] + (contact.db/query-chat-contacts chat contacts query-fn))) + +(reg-sub + :contacts/contacts + :<- [::contacts] + (fn [contacts] + (contact.db/enrich-contacts contacts))) + +(reg-sub + :contacts/active + :<- [:contacts/contacts] + (fn [contacts] + (contact.db/get-active-contacts contacts))) + +(reg-sub + :contacts/active-count + :<- [:contacts/active] + (fn [active-contacts] + (count active-contacts))) + +(reg-sub + :contacts/blocked + :<- [:contacts/contacts] + (fn [contacts] + (->> contacts + (filter (fn [[_ contact]] + (contact.db/blocked? contact))) + (contact.db/sort-contacts)))) + +(reg-sub + :contacts/blocked-count + :<- [:contacts/blocked] + (fn [blocked-contacts] + (count blocked-contacts))) + +(reg-sub + :contacts/current-contact + :<- [:contacts/contacts] + :<- [:contacts/current-contact-identity] + (fn [[contacts identity]] + (or (contacts identity) + (-> identity + contact.db/public-key->new-contact + contact.db/enrich-contact)))) + +(reg-sub + :contacts/contact-name-by-identity + :<- [:contacts/contacts] + :<- [:account/account] + (fn [[contacts current-account] [_ identity]] + (let [me? (= (:public-key current-account) identity)] + (if me? + (:name current-account) + (:name (contacts identity)))))) + +(reg-sub + :contacts/all-contacts-not-in-current-chat + :<- [::query-current-chat-contacts remove] + (fn [contacts] + (sort-by (comp clojure.string/lower-case :name) contacts))) + +(reg-sub + :contacts/current-chat-contacts + :<- [:chats/current-chat] + :<- [:contacts/contacts] + :<- [:account/account] + (fn [[{:keys [contacts admins]} all-contacts current-account]] + (contact.db/get-all-contacts-in-group-chat contacts admins all-contacts current-account))) + +(reg-sub + :contacts/contacts-by-chat + (fn [[_ _ chat-id] _] + [(subscribe [:chats/chat chat-id]) + (subscribe [:contacts/contacts])]) + (fn [[chat all-contacts] [_ query-fn]] + (contact.db/query-chat-contacts chat all-contacts query-fn))) + +(reg-sub + :contacts/chat-photo + (fn [[_ chat-id] _] + [(subscribe [:chats/chat chat-id]) + (subscribe [:contacts/contacts-by-chat filter chat-id])]) + (fn [[chat contacts] [_ chat-id]] + (when (and chat (not (:group-chat chat))) + (cond + (:photo-path chat) + (:photo-path chat) + + (pos? (count contacts)) + (:photo-path (first contacts)) + + :else + (identicon/identicon chat-id))))) + +(reg-sub + :contacts/contact-by-address + :<- [:contacts/contacts] + (fn [contacts [_ address]] + (contact.db/find-contact-by-address contacts address))) + +(reg-sub + :contacts/contacts-by-address + :<- [:contacts/contacts] + (fn [contacts] + (reduce (fn [acc [_ {:keys [address] :as contact}]] + (if address + (assoc acc address contact) + acc)) + {} + contacts))) + +;;EXTENSIONS ============================================================================================================ +;;TODO not optimized yet + +(reg-sub + :extensions/identity + (fn [_ [_ _ {:keys [value]}]] + value)) + +(defn get-token-for [network all-tokens token] + (if (= token "ETH") + {:decimals 18 + :address "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"} + (tokens/token-for (ethereum/network->chain-keyword network) all-tokens token))) + +(reg-sub + :extensions.wallet/balance + :<- [:wallet/all-tokens] + :<- [:network] + :<- [:balance] + (fn [[all-tokens network balance] [_ _ {token :token}]] + (let [{:keys [decimals]} (get-token-for network all-tokens token) + value (or (get balance (keyword token)) (money/bignumber 0))] + {:value (money/token->unit value decimals) + :value-in-wei value}))) + +(reg-sub + :extensions.wallet/token + :<- [:wallet/all-tokens] + :<- [:network] + (fn [[all-tokens network] [_ _ {token :token amount :amount amount-in-wei :amount-in-wei}]] + (let [{:keys [decimals] :as m} (get-token-for network all-tokens token)] + (merge m + (when amount {:amount-in-wei (money/unit->token amount decimals)}) + (when amount-in-wei {:amount (money/token->unit amount-in-wei decimals)}))))) + +(defn normalize-token [m] + (update m :symbol name)) + +(reg-sub + :extensions.wallet/tokens + :<- [:wallet/all-tokens] + :<- [:wallet/visible-tokens-symbols] + :<- [:network] + (fn [[all-tokens visible-tokens-symbols network] [_ _ {filter-vector :filter visible :visible}]] + (let [tokens (map normalize-token (filter #(and (not (:nft? %)) (if visible (contains? visible-tokens-symbols (:symbol %)) true)) + (tokens/sorted-tokens-for all-tokens (ethereum/network->chain-keyword network))))] + (if filter-vector + (filter #((set filter-vector) (:symbol %)) tokens) + tokens)))) + +(reg-sub + :store/get + (fn [db [_ {id :id} {:keys [key] :as params}]] + (let [result (get-in db [:extensions/store id key])] + (if (:reverse params) + (reverse result) + result)))) + +(reg-sub + :store/get-in + (fn [db [_ {id :id} {:keys [keys]}]] + (get-in db (into [] (concat [:extensions/store id] keys))))) + +(defn- ->contact [{:keys [photo-path address name public-key]}] + {:photo photo-path + :name name + :address (str "0x" address) + :public-key public-key}) + +(reg-sub + :extensions.contacts/all + :<- [:contacts/active] + (fn [[contacts] _] + (map #(update % :address ->contact)))) + +(reg-sub + :store/get-vals + (fn [db [_ {id :id} {:keys [key]}]] + (vals (get-in db [:extensions/store id key])))) + +(reg-sub + :extensions.time/now + (fn [_ _] + (.toLocaleString (js/Date.)))) + +;;MAILSERVER =========================================================================================================== + +(reg-sub + :mailserver/connecting? + :<- [:mailserver/state] + (fn [state] + (#{:connecting :added} state))) + +(reg-sub + :mailserver/connection-error? + :<- [:mailserver/state] + (fn [state] + (#{:error :disconnected} state))) + +(reg-sub + :chats/fetching-gap-in-progress? + :<- [:chats/current-chat-id] + :<- [:mailserver/fetching-gaps-in-progress] + (fn [[chat-id gaps] [_ ids]] + (seq (select-keys (get gaps chat-id) ids)))) + +(reg-sub + :mailserver/fetching? + :<- [:mailserver/state] + :<- [:mailserver/pending-requests] + :<- [:mailserver/connecting?] + :<- [:mailserver/connection-error?] + :<- [:mailserver/request-error?] + (fn [[state pending-requests connecting? connection-error? request-error?]] + (and pending-requests + (= state :connected) + (pos-int? pending-requests) + (not (or connecting? connection-error? request-error?))))) + +(reg-sub + :mailserver/fleet-mailservers + :<- [:settings/current-fleet] + :<- [:mailserver/mailservers] + (fn [[current-fleet mailservers]] + (current-fleet mailservers))) + +(reg-sub + :mailserver.edit/connected? + :<- [:mailserver.edit/mailserver] + :<- [:mailserver/current-id] + (fn [[mailserver current-mailserver-id]] + (= (get-in mailserver [:id :value]) + current-mailserver-id))) + +(reg-sub + :mailserver.edit/validation-errors + :<- [:mailserver.edit/mailserver] + (fn [mailserver] + (set (keep + (fn [[k {:keys [error]}]] + (when error k)) + mailserver)))) + +(reg-sub + :mailserver/connected? + :<- [:mailserver/state] + :<- [:network-status] + (fn [[mail-state network-status]] + (let [connected? (= :connected mail-state) + online? (= :online network-status)] + (and connected? online?)))) + +(reg-sub + :mailserver/preferred-id + :<- [:account-settings] + (fn [settings] + (get-in settings [:mailserver (fleet/current-fleet-sub settings)]))) + +;;SEARCH ============================================================================================================== + +(defn extract-chat-attributes [chat] + (let [{:keys [name random-name tags]} (val chat)] + (into [name random-name] tags))) + +(defn apply-filter + "extract-attributes-fn is a function that take an element from the collection + and returns a vector of attributes which are strings + apply-filter returns the elements for which at least one attribute includes + the search-filter + apply-filter returns nil if the search-filter is empty or if there is no element + that match the filter" + [search-filter coll extract-attributes-fn] + (when (not-empty search-filter) + (let [search-filter (string/lower-case search-filter) + results (filter (fn [element] + (some (fn [s] + (when (string? s) + (string/includes? (string/lower-case s) + search-filter))) + (extract-attributes-fn element))) + coll)] + (when (not-empty results) + (sort-by #(-> % second :timestamp) > + (into {} results)))))) + +(reg-sub + :search/filtered-chats + :<- [:chats/active-chats] + :<- [:search/filter] + (fn [[chats search-filter]] + (apply-filter search-filter chats extract-chat-attributes))) \ No newline at end of file diff --git a/src/status_im/ui/components/bottom_bar/core.cljs b/src/status_im/ui/components/bottom_bar/core.cljs index f3a8567e2a..9cb64f8e19 100644 --- a/src/status_im/ui/components/bottom_bar/core.cljs +++ b/src/status_im/ui/components/bottom_bar/core.cljs @@ -56,7 +56,7 @@ [react/touchable-highlight {:style tabs.styles/touchable-container :disabled active? - :on-press #(re-frame/dispatch [:navigate-to nav-stack]) + :on-press #(re-frame/dispatch-sync [:navigate-to nav-stack]) :accessibility-label accessibility-label} [react/view {:style tabs.styles/new-tab-container} diff --git a/src/status_im/ui/components/bottom_sheet/core.cljs b/src/status_im/ui/components/bottom_sheet/core.cljs index a97d23cf00..f624867aeb 100644 --- a/src/status_im/ui/components/bottom_sheet/core.cljs +++ b/src/status_im/ui/components/bottom_sheet/core.cljs @@ -1,7 +1,6 @@ (ns status-im.ui.components.bottom-sheet.core (:require [status-im.ui.components.bottom-sheet.view :as view] [status-im.ui.components.bottom-sheet.events :as events] - status-im.ui.components.bottom-sheet.subs status-im.ui.components.bottom-sheet.db)) (def show-bottom-sheet events/show-bottom-sheet) diff --git a/src/status_im/ui/components/bottom_sheet/subs.cljs b/src/status_im/ui/components/bottom_sheet/subs.cljs deleted file mode 100644 index 66eeb2b93b..0000000000 --- a/src/status_im/ui/components/bottom_sheet/subs.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns status-im.ui.components.bottom-sheet.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :bottom-sheet - (fn [{:bottom-sheet/keys [show? view]}] - {:show? show? - :view view})) diff --git a/src/status_im/ui/components/connectivity/subs.cljs b/src/status_im/ui/components/connectivity/subs.cljs deleted file mode 100644 index b6400f6ed4..0000000000 --- a/src/status_im/ui/components/connectivity/subs.cljs +++ /dev/null @@ -1,62 +0,0 @@ -(ns status-im.ui.components.connectivity.subs - (:require - [re-frame.core :as re-frame] - [status-im.utils.platform :as utils.platform] - [status-im.ui.screens.mobile-network-settings.utils :as mobile-network-utils])) - -(re-frame/reg-sub - :connectivity/status-properties - :<- [:offline?] - :<- [:disconnected?] - :<- [:mailserver/connecting?] - :<- [:mailserver/connection-error?] - :<- [:mailserver/request-error?] - :<- [:mailserver/fetching?] - :<- [:get :network/type] - :<- [:get :account/account] - (fn [[offline? disconnected? mailserver-connecting? mailserver-connection-error? - mailserver-request-error? mailserver-fetching? network-type account]] - (let [wallet-offline? (and offline? - ;; There's no wallet of desktop - (not utils.platform/desktop?)) - error-label (cond - (and wallet-offline? - disconnected?) - :t/offline - - wallet-offline? - :t/wallet-offline - - disconnected? - :t/disconnected - - mailserver-connecting? - :t/connecting - - mailserver-connection-error? - :t/mailserver-reconnect - - mailserver-request-error? - :t/mailserver-request-error-status - - (and (mobile-network-utils/cellular? network-type) - (not (:syncing-on-mobile-network? account))) - :mobile-network - - :else nil)] - {:message (or error-label :t/connected) - :connected? (and (nil? error-label) (not= :mobile-network error-label)) - :connecting? (= error-label :t/connecting) - :loading-indicator? mailserver-fetching? - :on-press-fn #(cond - mailserver-connection-error? - (re-frame/dispatch - [:mailserver.ui/reconnect-mailserver-pressed]) - mailserver-request-error? - (re-frame/dispatch - [:mailserver.ui/request-error-pressed]) - - (= :mobile-network error-label) - (re-frame/dispatch - - [:mobile-network/show-offline-sheet]))}))) diff --git a/src/status_im/ui/components/connectivity/view.cljs b/src/status_im/ui/components/connectivity/view.cljs index a0419876ff..efdf5b9097 100644 --- a/src/status_im/ui/components/connectivity/view.cljs +++ b/src/status_im/ui/components/connectivity/view.cljs @@ -133,7 +133,7 @@ (defview connectivity-view [] (letsubs [status-properties [:connectivity/status-properties] - view-id [:get :view-id] + view-id [:view-id] window-width [:dimensions/window-width]] (let [{:keys [loading-indicator?]} status-properties] [react/view {:style {:align-self :flex-start}} diff --git a/src/status_im/ui/components/desktop/tabs.cljs b/src/status_im/ui/components/desktop/tabs.cljs index 7bded21a0e..6264aad5ea 100644 --- a/src/status_im/ui/components/desktop/tabs.cljs +++ b/src/status_im/ui/components/desktop/tabs.cljs @@ -43,9 +43,9 @@ [content active? cnt]]])) (views/defview main-tabs [] - (views/letsubs [current-tab [:get-in [:desktop/desktop :tab-view-id]]] + (views/letsubs [{:keys [tab-view-id]} [:desktop/desktop]] [react/view [react/view {:style tabs.styles/tabs-container} (for [[index {:keys [content view-id count-subscription]}] tabs-list-indexed] ^{:key index} - [tab index content view-id (= current-tab view-id) count-subscription])]])) + [tab index content view-id (= tab-view-id view-id) count-subscription])]])) diff --git a/src/status_im/ui/screens/accounts/create/views.cljs b/src/status_im/ui/screens/accounts/create/views.cljs index a62f239f66..eb3f3071a7 100644 --- a/src/status_im/ui/screens/accounts/create/views.cljs +++ b/src/status_im/ui/screens/accounts/create/views.cljs @@ -38,11 +38,8 @@ next-enabled? (assoc :on-submit-editing #(re-frame/dispatch [:accounts.create.ui/next-step-pressed step password password-confirm])))]) (defview create-account [] - (letsubs [step [:get-in [:accounts/create :step]] - next-enabled? [:get-account-creation-next-enabled?] - error [:get-in [:accounts/create :error]] - password [:get-in [:accounts/create :password]] - password-confirm [:get-in [:accounts/create :password-confirm]]] + (letsubs [{:keys [step error password password-confirm]} [:accounts/create] + next-enabled? [:get-account-creation-next-enabled?]] [react/keyboard-avoiding-view {:style styles/create-account-view} [status-bar/status-bar {:flat? true}] [toolbar/toolbar nil diff --git a/src/status_im/ui/screens/accounts/login/views.cljs b/src/status_im/ui/screens/accounts/login/views.cljs index 1bbed2fd1a..034e71e7e6 100644 --- a/src/status_im/ui/screens/accounts/login/views.cljs +++ b/src/status_im/ui/screens/accounts/login/views.cljs @@ -56,7 +56,7 @@ name]]]) (defview login [] - (letsubs [{:keys [photo-path name error processing save-password? can-save-password?]} [:get :accounts/login] + (letsubs [{:keys [photo-path name error processing save-password? can-save-password?]} [:accounts/login] can-navigate-back? [:can-navigate-back?] password-text-input (atom nil) sign-in-enabled? [:sign-in-enabled?]] diff --git a/src/status_im/ui/screens/accounts/recover/views.cljs b/src/status_im/ui/screens/accounts/recover/views.cljs index 7884383d5d..1164dff4ae 100644 --- a/src/status_im/ui/screens/accounts/recover/views.cljs +++ b/src/status_im/ui/screens/accounts/recover/views.cljs @@ -60,7 +60,7 @@ (defview recover [] (letsubs [recovered-account [:get-recover-account] - node-status? [:get :node/status]] + node-status? [:node-status]] (let [{:keys [passphrase password passphrase-valid? password-valid? password-error passphrase-error passphrase-warning processing?]} recovered-account node-stopped? (or (nil? node-status?) diff --git a/src/status_im/ui/screens/accounts/subs.cljs b/src/status_im/ui/screens/accounts/subs.cljs deleted file mode 100644 index e92a7b0c46..0000000000 --- a/src/status_im/ui/screens/accounts/subs.cljs +++ /dev/null @@ -1,57 +0,0 @@ -(ns status-im.ui.screens.accounts.subs - (:require [re-frame.core :as re-frame] - [status-im.accounts.db :as db] - [status-im.utils.ethereum.core :as ethereum] - [cljs.spec.alpha :as spec] - [status-im.utils.security :as security])) - -(re-frame/reg-sub - :accounts/accounts - (fn [db] - (:accounts/accounts db))) - -(re-frame/reg-sub - :accounts/login - (fn [db] - (:accounts/login db))) - -(re-frame/reg-sub - :account/account - (fn [db] - (:account/account db))) - -(re-frame/reg-sub - :account/public-key - :<- [:account/account] - (fn [{:keys [public-key]}] - public-key)) - -(re-frame/reg-sub - :account/hex-address - :<- [:account/account] - (fn [{:keys [address]}] - (ethereum/normalized-address address))) - -(re-frame/reg-sub - :account/network - (fn [{:keys [network] :as db}] - (get-in db [:account/account :networks network]))) - -(re-frame/reg-sub - :get-account-creation-next-enabled? - (fn [{:accounts/keys [create]}] - (db/account-creation-next-enabled? create))) - -(re-frame/reg-sub - :get-recover-account - (fn [db] - (:accounts/recover db))) - -(re-frame/reg-sub - :sign-in-enabled? - :<- [:get :accounts/login] - :<- [:get :node/status] - (fn [[{:keys [password]} status]] - (and (or (nil? status) (= status :stopped)) - (spec/valid? ::db/password - (security/safe-unmask-data password))))) diff --git a/src/status_im/ui/screens/add_new/new_chat/subs.cljs b/src/status_im/ui/screens/add_new/new_chat/subs.cljs deleted file mode 100644 index 4681717690..0000000000 --- a/src/status_im/ui/screens/add_new/new_chat/subs.cljs +++ /dev/null @@ -1,6 +0,0 @@ -(ns status-im.ui.screens.add-new.new-chat.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub :new-identity-error - (fn [db _] - (get db :contacts/new-identity-error nil))) diff --git a/src/status_im/ui/screens/add_new/new_public_chat/subs.cljs b/src/status_im/ui/screens/add_new/new_public_chat/subs.cljs deleted file mode 100644 index 9c7a867a49..0000000000 --- a/src/status_im/ui/screens/add_new/new_public_chat/subs.cljs +++ /dev/null @@ -1,13 +0,0 @@ -(ns status-im.ui.screens.add-new.new-public-chat.subs - (:require [re-frame.core :as re-frame] - [status-im.i18n :as i18n] - [status-im.ui.screens.add-new.new-public-chat.db :as db] - [cljs.spec.alpha :as spec])) - -(re-frame/reg-sub - :public-chat.new/topic-error-message - :<- [:get :public-group-topic] - (fn [topic] - (when-not (or (empty? topic) - (db/valid-topic? topic)) - (i18n/label :topic-name-error)))) diff --git a/src/status_im/ui/screens/add_new/new_public_chat/view.cljs b/src/status_im/ui/screens/add_new/new_public_chat/view.cljs index 51d717fbe4..b85e5957cc 100644 --- a/src/status_im/ui/screens/add_new/new_public_chat/view.cljs +++ b/src/status_im/ui/screens/add_new/new_public_chat/view.cljs @@ -58,7 +58,7 @@ (def default-public-chats (types/json->clj (slurp "resources/default_public_chats.json"))) (views/defview new-public-chat [] - (views/letsubs [topic [:get :public-group-topic] + (views/letsubs [topic [:public-group-topic] error [:public-chat.new/topic-error-message]] [react/keyboard-avoiding-view styles/group-container [status-bar/status-bar] diff --git a/src/status_im/ui/screens/bootnodes_settings/edit_bootnode/subs.cljs b/src/status_im/ui/screens/bootnodes_settings/edit_bootnode/subs.cljs deleted file mode 100644 index 9df984eb23..0000000000 --- a/src/status_im/ui/screens/bootnodes_settings/edit_bootnode/subs.cljs +++ /dev/null @@ -1,17 +0,0 @@ -(ns status-im.ui.screens.bootnodes-settings.edit-bootnode.subs - (:require [re-frame.core :refer [reg-sub]])) - -(reg-sub - :get-manage-bootnode - :<- [:get :bootnodes/manage] - (fn [manage] - manage)) - -(reg-sub - :manage-bootnode-validation-errors - :<- [:get-manage-bootnode] - (fn [manage] - (set (keep - (fn [[k {:keys [error]}]] - (when error k)) - manage)))) diff --git a/src/status_im/ui/screens/bootnodes_settings/subs.cljs b/src/status_im/ui/screens/bootnodes_settings/subs.cljs deleted file mode 100644 index 5daa5c8500..0000000000 --- a/src/status_im/ui/screens/bootnodes_settings/subs.cljs +++ /dev/null @@ -1,15 +0,0 @@ -(ns status-im.ui.screens.bootnodes-settings.subs - (:require [re-frame.core :as re-frame] - status-im.ui.screens.bootnodes-settings.edit-bootnode.subs - [status-im.utils.ethereum.core :as ethereum])) - -(re-frame/reg-sub :settings/bootnodes-enabled - :<- [:get :account/account] - (fn [account] - (let [{:keys [network settings]} account] - (get-in settings [:bootnodes network])))) - -(re-frame/reg-sub :settings/network-bootnodes - :<- [:get :account/account] - (fn [account] - (get-in account [:bootnodes (:network account)]))) diff --git a/src/status_im/ui/screens/browser/subs.cljs b/src/status_im/ui/screens/browser/subs.cljs deleted file mode 100644 index 9a8ee91fee..0000000000 --- a/src/status_im/ui/screens/browser/subs.cljs +++ /dev/null @@ -1,31 +0,0 @@ -(ns status-im.ui.screens.browser.subs - (:require [re-frame.core :as re-frame] - [status-im.browser.core :as browser])) - -(re-frame/reg-sub - :browsers - (fn [db _] - (:browser/browsers db))) - -(re-frame/reg-sub - :browser/browsers - :<- [:browsers] - (fn [browsers] - (reduce (fn [acc [k browser]] - (update acc k assoc :url (browser/get-current-url browser))) - browsers - browsers))) - -(re-frame/reg-sub - :browser/browsers-vals - :<- [:browser/browsers] - (fn [browsers] - (sort-by :timestamp > (vals browsers)))) - -(re-frame/reg-sub - :get-current-browser - :<- [:get :browser/options] - :<- [:browser/browsers] - (fn [[options browsers]] - (let [browser (get browsers (:browser-id options))] - (assoc browser :secure? (browser/secure? browser options))))) diff --git a/src/status_im/ui/screens/browser/views.cljs b/src/status_im/ui/screens/browser/views.cljs index 1134a47adf..4effccbc07 100644 --- a/src/status_im/ui/screens/browser/views.cljs +++ b/src/status_im/ui/screens/browser/views.cljs @@ -104,7 +104,7 @@ (views/defview browser-component [{:keys [webview error? url browser browser-id unsafe? can-go-back? can-go-forward? resolving? network-id address url-original - show-permission show-tooltip opt-in? dapp? rpc-url name]}] + show-permission show-tooltip opt-in? dapp? name]}] {:should-component-update (fn [_ _ args] (let [[_ props] args] (not (nil? (:url props)))))} @@ -133,7 +133,6 @@ (if opt-in? (js-res/web3-opt-in-init (str network-id)) (js-res/web3-init - rpc-url (ethereum/normalized-address address) (str network-id))) (get-inject-js url)) @@ -152,8 +151,7 @@ window-width [:dimensions/window-width] {:keys [address settings]} [:account/account] {:keys [browser-id dapp? name unsafe?] :as browser} [:get-current-browser] - {:keys [url error? loading? url-editing? show-tooltip show-permission resolving?]} [:get :browser/options] - rpc-url [:get :rpc-url] + {:keys [url error? loading? url-editing? show-tooltip show-permission resolving?]} [:browser/options] network-id [:get-network-id]] (let [can-go-back? (browser/can-go-back? browser) can-go-forward? (browser/can-go-forward? browser) @@ -181,5 +179,4 @@ :show-permission show-permission :show-tooltip show-tooltip :opt-in? opt-in? - :rpc-url rpc-url :name name}]]))) diff --git a/src/status_im/ui/screens/chat/input/animations/expandable.cljs b/src/status_im/ui/screens/chat/input/animations/expandable.cljs index b5a8244c70..af39add55c 100644 --- a/src/status_im/ui/screens/chat/input/animations/expandable.cljs +++ b/src/status_im/ui/screens/chat/input/animations/expandable.cljs @@ -22,8 +22,8 @@ input-focused? [:chats/current-chat-ui-prop :input-focused?] messages-focused? [:chats/current-chat-ui-prop :messages-focused?] chat-input-margin [:chats/input-margin] - keyboard-height [:get :keyboard-height] - chat-layout-height [:get :layout-height]] + keyboard-height [:keyboard-height] + chat-layout-height [:layout-height]] (let [input-height (or input-height (+ input-style/padding-vertical input-style/min-input-height input-style/padding-vertical diff --git a/src/status_im/ui/screens/chat/input/send_button.cljs b/src/status_im/ui/screens/chat/input/send_button.cljs index 684b17b66f..934322d589 100644 --- a/src/status_im/ui/screens/chat/input/send_button.cljs +++ b/src/status_im/ui/screens/chat/input/send_button.cljs @@ -15,10 +15,10 @@ (defview send-button-view [] (letsubs [{:keys [command-completion]} [:chats/selected-chat-command] - {:keys [input-text seq-arg-input-text]} [:chats/current-chat] + {:keys [input-text]} [:chats/current-chat] disconnected? [:disconnected?] - login-processing? [:get-in [:accounts/login :processing]]] - (when (and (sendable? input-text disconnected? login-processing?) + {:keys [processing]} [:accounts/login]] + (when (and (sendable? input-text disconnected? processing) (or (not command-completion) (#{:complete :less-than-needed} command-completion))) [react/touchable-highlight diff --git a/src/status_im/ui/screens/chat/stickers/subs.cljs b/src/status_im/ui/screens/chat/stickers/subs.cljs deleted file mode 100644 index 61575e37e5..0000000000 --- a/src/status_im/ui/screens/chat/stickers/subs.cljs +++ /dev/null @@ -1,9 +0,0 @@ -(ns status-im.ui.screens.chat.stickers.subs - (:require [re-frame.core :as re-frame] - status-im.ui.screens.extensions.add.subs)) - -(re-frame/reg-sub - :stickers/selected-pack - (fn [db] - (get db :stickers/selected-pack))) - diff --git a/src/status_im/ui/screens/chat/toolbar_content.cljs b/src/status_im/ui/screens/chat/toolbar_content.cljs index bc12d40faa..7f3e8d5b10 100644 --- a/src/status_im/ui/screens/chat/toolbar_content.cljs +++ b/src/status_im/ui/screens/chat/toolbar_content.cljs @@ -30,7 +30,7 @@ (str (i18n/label :t/sync-in-progress) " " percentage "% " currentBlock))) (defview last-activity [{:keys [sync-state accessibility-label]}] - (letsubs [state [:get :sync-data]] + (letsubs [state [:sync-data]] [react/text {:style st/last-activity-text :accessibility-label accessibility-label} (case sync-state diff --git a/src/status_im/ui/screens/currency_settings/subs.cljs b/src/status_im/ui/screens/currency_settings/subs.cljs deleted file mode 100644 index f9ae8f1e2a..0000000000 --- a/src/status_im/ui/screens/currency_settings/subs.cljs +++ /dev/null @@ -1,12 +0,0 @@ -(ns status-im.ui.screens.currency-settings.subs - (:require [re-frame.core :as re-frame])) - -;;TODO(goranjovic): this fn should go to `status-im.ui.screens.currency-settings.subs` -;; but it can't because of cyclic dependencies -(defn get-currency [db] - (or (get-in db [:account/account :settings :wallet :currency]) :usd)) - -(re-frame/reg-sub - :wallet.settings/currency - (fn [db] - (get-currency db))) diff --git a/src/status_im/ui/screens/dapps_permissions/views.cljs b/src/status_im/ui/screens/dapps_permissions/views.cljs index bbe5a4e8a0..fb909cbccc 100644 --- a/src/status_im/ui/screens/dapps_permissions/views.cljs +++ b/src/status_im/ui/screens/dapps_permissions/views.cljs @@ -31,7 +31,7 @@ :accessories [:check]}) (views/defview dapps-permissions [] - (views/letsubs [permissions [:get :dapps/permissions]] + (views/letsubs [permissions [:dapps/permissions]] [react/view {:flex 1 :background-color colors/white} [status-bar/status-bar] [toolbar/simple-toolbar diff --git a/src/status_im/ui/screens/desktop/main/add_new/views.cljs b/src/status_im/ui/screens/desktop/main/add_new/views.cljs index 3987b63c99..6292e81d9e 100644 --- a/src/status_im/ui/screens/desktop/main/add_new/views.cljs +++ b/src/status_im/ui/screens/desktop/main/add_new/views.cljs @@ -25,7 +25,7 @@ [react/view {:style styles/tooltip-triangle}]]) (views/defview new-one-to-one [] - (views/letsubs [new-contact-identity [:get :contacts/new-identity] + (views/letsubs [new-contact-identity [:contacts/new-identity] contacts [:contacts/active] chat-error [:new-identity-error]] {:component-will-unmount #(re-frame/dispatch [:new-chat/set-new-identity nil])} @@ -85,7 +85,7 @@ (i18n/label :start-chat)]]]]) (views/defview new-public-chat [] - (views/letsubs [topic [:get :public-group-topic] + (views/letsubs [topic [:public-group-topic] topic-error [:public-chat.new/topic-error-message]] [react/view {:style styles/new-view} [react/view {:style styles/new-contact-title} diff --git a/src/status_im/ui/screens/desktop/main/chat/views.cljs b/src/status_im/ui/screens/desktop/main/chat/views.cljs index a844670374..0d32e115c0 100644 --- a/src/status_im/ui/screens/desktop/main/chat/views.cljs +++ b/src/status_im/ui/screens/desktop/main/chat/views.cljs @@ -309,7 +309,7 @@ (views/defview chat-text-input [chat-id input-text] (views/letsubs [inp-ref (atom nil) disconnected? [:disconnected?] - show-emoji? [:get-in [:desktop :show-emoji?]]] + {:keys [show-emoji?]} [:desktop]] {:component-will-update (fn [e [_ new-chat-id new-input-text]] (let [[_ old-chat-id] (.. e -props -argv)] @@ -366,7 +366,7 @@ (views/defview chat-view [] (views/letsubs [{:keys [input-text chat-id pending-invite-inviter-name] :as current-chat} [:chats/current-chat] - show-emoji? [:get-in [:desktop :show-emoji?]] + {:keys [show-emoji?]} [:desktop] current-public-key [:account/public-key]] [react/view {:style styles/chat-view} [toolbar-chat-view current-chat] diff --git a/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs b/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs index 7838335ea9..34507dd585 100644 --- a/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs +++ b/src/status_im/ui/screens/desktop/main/tabs/home/views.cljs @@ -145,7 +145,7 @@ (views/defview chat-list-view [loading?] (views/letsubs [search-filter [:search/filter] - logging-in? [:get :accounts/login] + logging-in? [:accounts/login] {:keys [all-home-items chats]} [:home-items]] {:component-did-mount (fn [this] @@ -168,5 +168,5 @@ [chat-list-item chat])]]])) (views/defview chat-list-view-wrapper [] - (views/letsubs [loading? [:get :chats/loading?]] + (views/letsubs [loading? [:chats/loading?]] [chat-list-view loading?])) diff --git a/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs b/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs index 14e3e8bc2a..5bb2dee280 100644 --- a/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs +++ b/src/status_im/ui/screens/desktop/main/tabs/profile/views.cljs @@ -55,7 +55,7 @@ (views/defview qr-code [] (views/letsubs [{:keys [public-key]} [:account/account] - tooltip-opacity [:get-in [:tooltips :qr-copied]]] + {:keys [qr-copied]} [:tooltips]] [react/view [react/view {:style styles/qr-code-container} [react/text {:style styles/qr-code-title} @@ -67,8 +67,8 @@ :selectable true :selection-color colors/blue} public-key] - (when tooltip-opacity - [copied-tooltip tooltip-opacity])] + (when qr-copied + [copied-tooltip qr-copied])] [react/touchable-highlight {:on-press #(do (re-frame/dispatch [:copy-to-clipboard public-key]) (re-frame/dispatch [:show-tooltip :qr-copied]))} @@ -271,8 +271,8 @@ [vector-icons/icon :main-icons/next {:style {:tint-color colors/gray}}]]]) (views/defview profile [{:keys [seed-backed-up? mnemonic] :as user}] - (views/letsubs [current-view-id [:get :view-id] - editing? [:get :my-profile/editing?]] ;; TODO janherich: refactor my-profile, unnecessary complicated structure in db (could be just `:staged-name`/`:editing?` fields in account map) and horrible way to access it woth `:get`/`:set` subs/events + (views/letsubs [current-view-id [:view-id] + editing? [:my-profile/editing?]] ;; TODO janherich: refactor my-profile, unnecessary complicated structure in db (could be just `:staged-name`/`:editing?` fields in account map) and horrible way to access it woth `:get`/`:set` subs/events (let [adv-settings-open? (= current-view-id :advanced-settings) about-app-open? (= current-view-id :about-app) help-open? (= current-view-id :help-center) diff --git a/src/status_im/ui/screens/desktop/main/views.cljs b/src/status_im/ui/screens/desktop/main/views.cljs index 6919606102..eae1d71020 100644 --- a/src/status_im/ui/screens/desktop/main/views.cljs +++ b/src/status_im/ui/screens/desktop/main/views.cljs @@ -20,8 +20,8 @@ "Status.im"]]) (views/defview tab-views [] - (views/letsubs [tab [:get-in [:desktop/desktop :tab-view-id]]] - (let [component (case tab + (views/letsubs [{:keys [tab-view-id]} [:desktop/desktop]] + (let [component (case tab-view-id :profile profile.views/profile-data :home home.views/chat-list-view-wrapper react/view)] @@ -29,7 +29,7 @@ [component]]))) (views/defview popup-view [] - (views/letsubs [popup [:get-in [:desktop :popup]]] + (views/letsubs [{:keys [popup]} [:desktop]] (when popup [react/view {:style styles/absolute} [react/touchable-highlight {:on-press #(re-frame/dispatch [:set-in [:desktop :popup] nil]) @@ -39,7 +39,7 @@ [popup]]]))) (views/defview main-view [] - (views/letsubs [view-id [:get :view-id]] + (views/letsubs [view-id [:view-id]] (let [component (case view-id :chat chat.views/chat-view :desktop/new-one-to-one add-new.views/new-one-to-one diff --git a/src/status_im/ui/screens/desktop/views.cljs b/src/status_im/ui/screens/desktop/views.cljs index 87e77376e7..274d48ced1 100644 --- a/src/status_im/ui/screens/desktop/views.cljs +++ b/src/status_im/ui/screens/desktop/views.cljs @@ -20,7 +20,7 @@ (enable-console-print!) (views/defview main [] - (views/letsubs [view-id [:get :view-id] + (views/letsubs [view-id [:view-id] version [:get-app-version]] {:component-did-mount (fn [] diff --git a/src/status_im/ui/screens/extensions/add/subs.cljs b/src/status_im/ui/screens/extensions/add/subs.cljs deleted file mode 100644 index 0a6be3f916..0000000000 --- a/src/status_im/ui/screens/extensions/add/subs.cljs +++ /dev/null @@ -1,12 +0,0 @@ -(ns status-im.ui.screens.extensions.add.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :get-manage-extension - (fn [db] - (:extensions/manage db))) - -(re-frame/reg-sub - :get-staged-extension - (fn [db] - (:extensions/staged-extension db))) diff --git a/src/status_im/ui/screens/extensions/subs.cljs b/src/status_im/ui/screens/extensions/subs.cljs deleted file mode 100644 index afc9bc3027..0000000000 --- a/src/status_im/ui/screens/extensions/subs.cljs +++ /dev/null @@ -1,10 +0,0 @@ -(ns status-im.ui.screens.extensions.subs - (:require [re-frame.core :as re-frame] - status-im.ui.screens.extensions.add.subs)) - -(re-frame/reg-sub - :extensions/all-extensions - :<- [:get :account/account] - (fn [account] - (get account :extensions))) - diff --git a/src/status_im/ui/screens/fleet_settings/subs.cljs b/src/status_im/ui/screens/fleet_settings/subs.cljs deleted file mode 100644 index 3afc79a5f4..0000000000 --- a/src/status_im/ui/screens/fleet_settings/subs.cljs +++ /dev/null @@ -1,14 +0,0 @@ -(ns status-im.ui.screens.fleet-settings.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.config :as config] - [status-im.fleet.core :as fleet])) - -(re-frame/reg-sub - :settings/current-fleet - (fn [db _] - (fleet/current-fleet db))) - -(re-frame/reg-sub - :fleets/custom-fleets - (fn [{:keys [custom-fleets]} _] - custom-fleets)) diff --git a/src/status_im/ui/screens/group/subs.cljs b/src/status_im/ui/screens/group/subs.cljs deleted file mode 100644 index 55a2aa8654..0000000000 --- a/src/status_im/ui/screens/group/subs.cljs +++ /dev/null @@ -1,39 +0,0 @@ -(ns status-im.ui.screens.group.subs - (:require [re-frame.core :refer [reg-sub]] - [status-im.contact.db :as contact.db] - [status-im.utils.subs :as utils])) - -(reg-sub - :is-contact-selected? - (utils/contains-sub :group/selected-contacts)) - -(reg-sub - :is-participant-selected? - (utils/contains-sub :selected-participants)) - -(defn filter-selected-contacts - [selected-contacts contacts] - (filter #(contact.db/added? (contacts %)) selected-contacts)) - -(reg-sub - :selected-contacts-count - :<- [:get :group/selected-contacts] - :<- [:contacts/contacts] - (fn [[selected-contacts contacts]] - (count (filter-selected-contacts selected-contacts contacts)))) - -(reg-sub - :selected-participants-count - :<- [:get :selected-participants] - (fn [selected-participants] - (count selected-participants))) - -(defn filter-contacts [selected-contacts active-contacts] - (filter #(selected-contacts (:public-key %)) active-contacts)) - -(reg-sub - :selected-group-contacts - :<- [:get :group/selected-contacts] - :<- [:contacts/active] - (fn [[selected-contacts active-contacts]] - (filter-contacts selected-contacts active-contacts))) diff --git a/src/status_im/ui/screens/group/views.cljs b/src/status_im/ui/screens/group/views.cljs index b67d0ec6a2..d9aea280d0 100644 --- a/src/status_im/ui/screens/group/views.cljs +++ b/src/status_im/ui/screens/group/views.cljs @@ -140,7 +140,7 @@ ;; Set name of new group-chat (views/defview new-group [] (views/letsubs [contacts [:selected-group-contacts] - group-name [:get :new-chat-name]] + group-name [:new-chat-name]] (let [save-btn-enabled? (and (spec/valid? :global/not-empty-string group-name) (pos? (count contacts)))] [react/keyboard-avoiding-view (merge {:behavior :padding} styles/group-container) diff --git a/src/status_im/ui/screens/hardwallet/login/views.cljs b/src/status_im/ui/screens/hardwallet/login/views.cljs index 705c599732..80f7bb0491 100644 --- a/src/status_im/ui/screens/hardwallet/login/views.cljs +++ b/src/status_im/ui/screens/hardwallet/login/views.cljs @@ -17,7 +17,7 @@ [re-frame.core :as re-frame])) (defview hardwallet-login [] - (letsubs [{:keys [photo-path name processing]} [:get :accounts/login] + (letsubs [{:keys [photo-path name processing]} [:accounts/login] nfc-enabled? [:hardwallet/nfc-enabled?]] [react/keyboard-avoiding-view styles/container [status-bar/status-bar] diff --git a/src/status_im/ui/screens/home/subs.cljs b/src/status_im/ui/screens/home/subs.cljs deleted file mode 100644 index a0720dcc7e..0000000000 --- a/src/status_im/ui/screens/home/subs.cljs +++ /dev/null @@ -1,37 +0,0 @@ -(ns status-im.ui.screens.home.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.platform :as platform])) - -(re-frame/reg-sub - :home-items - :<- [:chats/active-chats] - :<- [:search/filter] - :<- [:search/filtered-chats] - (fn [[chats search-filter filtered-chats]] - (if (or (nil? search-filter) - (and platform/desktop? (empty? search-filter))) - {:all-home-items - (sort-by #(-> % second :timestamp) > chats)} - {:search-filter search-filter - :chats filtered-chats}))) - -(re-frame/reg-sub - :chain-sync-state - (fn [{:node/keys [chain-sync-state]} _] chain-sync-state)) - -(re-frame/reg-sub - :current-network-initialized? - (fn [db _] - (let [network (get-in db [:account/account :networks (:network db)])] - (boolean network)))) - -(re-frame/reg-sub - :current-network-uses-rpc? - (fn [db _] - (let [network (get-in db [:account/account :networks (:network db)])] - (get-in network [:config :UpstreamConfig :Enabled])))) - -(re-frame/reg-sub - :latest-block-number - (fn [{:node/keys [latest-block-number]} _] - (if latest-block-number latest-block-number 0))) diff --git a/src/status_im/ui/screens/home/views.cljs b/src/status_im/ui/screens/home/views.cljs index 925e37ee15..ea30be725d 100644 --- a/src/status_im/ui/screens/home/views.cljs +++ b/src/status_im/ui/screens/home/views.cljs @@ -101,7 +101,7 @@ [inner-item/home-list-item home-item])}]])))) (views/defview home-action-button [] - (views/letsubs [logging-in? [:get :accounts/login]] + (views/letsubs [logging-in? [:accounts/login]] [react/view styles/action-button-container [react/touchable-highlight {:accessibility-label :new-chat-button :on-press (when-not logging-in? #(re-frame/dispatch [:bottom-sheet/show-sheet :add-new]))} @@ -144,5 +144,5 @@ [home-action-button]]])) (views/defview home-wrapper [] - (views/letsubs [loading? [:get :chats/loading?]] + (views/letsubs [loading? [:chats/loading?]] [home loading?])) diff --git a/src/status_im/ui/screens/log_level_settings/subs.cljs b/src/status_im/ui/screens/log_level_settings/subs.cljs deleted file mode 100644 index 818970e305..0000000000 --- a/src/status_im/ui/screens/log_level_settings/subs.cljs +++ /dev/null @@ -1,15 +0,0 @@ -(ns status-im.ui.screens.log-level-settings.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.config :as config])) - -(re-frame/reg-sub - :settings/current-log-level - (fn [db _] - (or (get-in db [:account/account :settings :log-level]) - config/log-level-status-go))) - -(re-frame/reg-sub - :settings/logging-enabled - (fn [db _] - (or (get-in db [:desktop/desktop :logging-enabled]) false))) - diff --git a/src/status_im/ui/screens/mobile_network_settings/sheets.cljs b/src/status_im/ui/screens/mobile_network_settings/sheets.cljs index fc4ca6dbc4..14ddb237e7 100644 --- a/src/status_im/ui/screens/mobile_network_settings/sheets.cljs +++ b/src/status_im/ui/screens/mobile_network_settings/sheets.cljs @@ -32,7 +32,7 @@ (i18n/label :mobile-network-go-to-settings)]]) (views/defview checkbox [] - (views/letsubs [checked? [:get :mobile-network/remember-choice?]] + (views/letsubs [checked? [:mobile-network/remember-choice?]] [react/view {:style styles/checkbox-line-container} [checkbox/checkbox diff --git a/src/status_im/ui/screens/mobile_network_settings/view.cljs b/src/status_im/ui/screens/mobile_network_settings/view.cljs index 3eebcc42a0..e0bbdfac36 100644 --- a/src/status_im/ui/screens/mobile_network_settings/view.cljs +++ b/src/status_im/ui/screens/mobile_network_settings/view.cljs @@ -19,7 +19,7 @@ (views/letsubs [{:keys [syncing-on-mobile-network? remember-syncing-choice?]} - [:get :account/account]] + [:account/account]] [react/view {:style styles/container} [status-bar/status-bar] [toolbar/simple-toolbar (i18n/label :t/mobile-network-settings)] diff --git a/src/status_im/ui/screens/network_settings/edit_network/subs.cljs b/src/status_im/ui/screens/network_settings/edit_network/subs.cljs deleted file mode 100644 index 00f88edf52..0000000000 --- a/src/status_im/ui/screens/network_settings/edit_network/subs.cljs +++ /dev/null @@ -1,14 +0,0 @@ -(ns status-im.ui.screens.network-settings.edit-network.subs - (:require [re-frame.core :refer [reg-sub]])) - -(reg-sub - :get-manage-network - :<- [:get :networks/manage] - (fn [manage] - manage)) - -(reg-sub - :manage-network-valid? - :<- [:get-manage-network] - (fn [manage] - (not-any? :error (vals manage)))) diff --git a/src/status_im/ui/screens/network_settings/subs.cljs b/src/status_im/ui/screens/network_settings/subs.cljs deleted file mode 100644 index f69ad4c2a6..0000000000 --- a/src/status_im/ui/screens/network_settings/subs.cljs +++ /dev/null @@ -1,36 +0,0 @@ -(ns status-im.ui.screens.network-settings.subs - (:require [re-frame.core :refer [reg-sub subscribe]] - [status-im.utils.ethereum.core :as ethereum] - status-im.ui.screens.network-settings.edit-network.subs)) - -(reg-sub - :get-network-id - :<- [:network] - (fn [network] - (ethereum/network->chain-id network))) - -(defn- filter-networks [network-type] - (fn [network] - (let [chain-id (ethereum/network->chain-id network) - testnet? (ethereum/testnet? chain-id) - custom? (:custom? network)] - (case network-type - :custom custom? - :mainnet (and (not custom?) (not testnet?)) - :testnet (and (not custom?) testnet?))))) - -(defn- label-networks [default-networks] - (fn [network] - (let [custom? (not (contains? default-networks (:id network)))] - (assoc network :custom? custom?)))) - -(reg-sub - :get-networks - :<- [:get :account/account] - :<- [:get :networks/networks] - (fn [[{:keys [networks] :as account} default-networks]] - (let [networks (map (label-networks default-networks) (sort-by :name (vals networks))) - types [:mainnet :testnet :custom]] - (zipmap - types - (map #(filter (filter-networks %) networks) types))))) diff --git a/src/status_im/ui/screens/pairing/subs.cljs b/src/status_im/ui/screens/pairing/subs.cljs deleted file mode 100644 index f7a591e81b..0000000000 --- a/src/status_im/ui/screens/pairing/subs.cljs +++ /dev/null @@ -1,18 +0,0 @@ -(ns status-im.ui.screens.pairing.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.ethereum.core :as ethereum])) - -(re-frame/reg-sub :pairing/installations - :<- [:get :pairing/installations] - (fn [installations] - (->> installations - vals - (sort-by (comp unchecked-negate :last-paired))))) - -(re-frame/reg-sub :pairing/installation-id - :<- [:get :account/account] - :installation-id) - -(re-frame/reg-sub :pairing/installation-name - :<- [:get :account/account] - (fn [account] (:installation-name account))) diff --git a/src/status_im/ui/screens/profile/group_chat/views.cljs b/src/status_im/ui/screens/profile/group_chat/views.cljs index 45f7abaea7..bd449838db 100644 --- a/src/status_im/ui/screens/profile/group_chat/views.cljs +++ b/src/status_im/ui/screens/profile/group_chat/views.cljs @@ -91,9 +91,9 @@ (defview group-chat-profile [] (letsubs [{:keys [admins chat-id] :as current-chat} [:chats/current-chat] - editing? [:get :group-chat-profile/editing?] + editing? [:group-chat-profile/editing?] members [:contacts/current-chat-contacts] - changed-chat [:get :group-chat-profile/profile] + changed-chat [:group-chat-profile/profile] current-pk [:account/public-key]] (when current-chat (let [shown-chat (merge current-chat changed-chat) diff --git a/src/status_im/ui/screens/profile/subs.cljs b/src/status_im/ui/screens/profile/subs.cljs deleted file mode 100644 index f0e6c5ac84..0000000000 --- a/src/status_im/ui/screens/profile/subs.cljs +++ /dev/null @@ -1,41 +0,0 @@ -(ns status-im.ui.screens.profile.subs - (:require [re-frame.core :as re-frame] - [clojure.string :as string] - [status-im.utils.build :as build] - [status-im.utils.platform :as platform])) - -(defn- node-version [{:keys [web3-node-version]}] - (str "status-go v" (or web3-node-version "N/A") "")) - -(def app-short-version - (let [version (if platform/desktop? build/version build/build-no)] - (str build/version " (" version ")"))) - -(re-frame/reg-sub - :get-profile-unread-messages-number - :<- [:account/account] - (fn [{:keys [seed-backed-up? mnemonic]}] - (if (or seed-backed-up? (string/blank? mnemonic)) 0 1))) - -(re-frame/reg-sub - :get-app-version - (fn [db] - (str app-short-version "; " (node-version db)))) - -(re-frame/reg-sub - :get-app-short-version - (fn [db] app-short-version)) - -(re-frame/reg-sub - :get-app-node-version - node-version) - -(re-frame/reg-sub - :get-device-UUID - (fn [db] - (:device-UUID db))) - -(re-frame/reg-sub - :my-profile/recovery - (fn [db] - (or (:my-profile/seed db) {:step :intro}))) diff --git a/src/status_im/ui/screens/profile/user/views.cljs b/src/status_im/ui/screens/profile/user/views.cljs index 8ce1ae7a5c..08e26a58f1 100644 --- a/src/status_im/ui/screens/profile/user/views.cljs +++ b/src/status_im/ui/screens/profile/user/views.cljs @@ -82,7 +82,7 @@ :style styles/share-link-button}])) (defview qr-viewer [] - (letsubs [{:keys [value contact]} [:get :qr-modal]] + (letsubs [{:keys [value contact]} [:qr-modal]] [react/view styles/qr-code-viewer [status-bar/status-bar {:type :modal-white}] [qr-viewer-toolbar (:name contact) value] @@ -241,7 +241,7 @@ :action-fn #(re-frame/dispatch [:accounts.ui/chaos-mode-switched %])}]]) (defview advanced [params on-show] - (letsubs [advanced? [:get :my-profile/advanced?]] + (letsubs [advanced? [:my-profile/advanced?]] {:component-will-unmount #(re-frame/dispatch [:set :my-profile/advanced? false])} [react/view {:padding-bottom 16} [react/touchable-highlight {:on-press #(re-frame/dispatch [:set :my-profile/advanced? (not advanced?)]) @@ -315,11 +315,11 @@ (defview my-profile [] (letsubs [{:keys [public-key photo-path] :as current-account} [:account/account] - editing? [:get :my-profile/editing?] - extensions [:get :extensions/profile] - changed-account [:get :my-profile/profile] + editing? [:my-profile/editing?] + extensions [:extensions/profile] + changed-account [:my-profile/profile] currency [:wallet/currency] - login-data [:get :accounts/login] + login-data [:accounts/login] scroll (reagent/atom nil) active-contacts-count [:contacts/active-count] {tribute-to-talk-seen? :seen? diff --git a/src/status_im/ui/screens/stickers/subs.cljs b/src/status_im/ui/screens/stickers/subs.cljs deleted file mode 100644 index a17566f7ad..0000000000 --- a/src/status_im/ui/screens/stickers/subs.cljs +++ /dev/null @@ -1,52 +0,0 @@ -(ns status-im.ui.screens.stickers.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :stickers/packs - (fn [db] - (:stickers/packs db))) - -(re-frame/reg-sub - :stickers/installed-packs - (fn [db] - (:stickers/packs-installed db))) - -(re-frame/reg-sub - :stickers/installed-packs-vals - :<- [:stickers/installed-packs] - (fn [packs] - (vals packs))) - -(re-frame/reg-sub - :stickers/all-packs - :<- [:stickers/packs] - :<- [:stickers/installed-packs] - :<- [:get :stickers/packs-owned] - :<- [:get :stickers/packs-pendning] - (fn [[packs installed owned pending]] - (map (fn [{:keys [id] :as pack}] - (cond-> pack - (get installed id) (assoc :installed true) - (get owned id) (assoc :owned true) - (get pending id) (assoc :pending true))) - (vals packs)))) - -(re-frame/reg-sub - :stickers/get-current-pack - :<- [:get-screen-params] - :<- [:stickers/all-packs] - (fn [[{:keys [id]} packs]] - (first (filter #(= (:id %) id) packs)))) - -(defn find-pack-id-for-uri [sticker-uri packs] - (some (fn [{:keys [stickers id]}] - (when (some #(= sticker-uri (:uri %)) stickers) - id)) - packs)) - -(re-frame/reg-sub - :stickers/recent - :<- [:account/account] - :<- [:stickers/installed-packs-vals] - (fn [[{:keys [recent-stickers]} packs]] - (map (fn [uri] {:uri uri :pack (find-pack-id-for-uri uri packs)}) recent-stickers))) \ No newline at end of file diff --git a/src/status_im/ui/screens/subs.cljs b/src/status_im/ui/screens/subs.cljs deleted file mode 100644 index 3eed15a497..0000000000 --- a/src/status_im/ui/screens/subs.cljs +++ /dev/null @@ -1,109 +0,0 @@ -(ns status-im.ui.screens.subs - (:require [re-frame.core :refer [reg-sub subscribe]] - [status-im.utils.ethereum.core :as ethereum] - status-im.chat.subs - status-im.contact.subs - status-im.search.subs - status-im.mailserver.subs - status-im.tribute-to-talk.subs - status-im.ui.components.connectivity.subs - status-im.ui.screens.accounts.subs - status-im.ui.screens.chat.stickers.subs - status-im.ui.screens.extensions.subs - status-im.ui.screens.home.subs - status-im.ui.screens.group.subs - status-im.ui.screens.stickers.subs - status-im.ui.screens.wallet.subs - status-im.ui.screens.wallet.collectibles.subs - status-im.ui.screens.wallet.request.subs - status-im.ui.screens.wallet.send.subs - status-im.ui.screens.wallet.settings.subs - status-im.ui.screens.wallet.transactions.subs - status-im.ui.screens.hardwallet.settings.subs - status-im.ui.screens.network-settings.subs - status-im.ui.screens.log-level-settings.subs - status-im.ui.screens.fleet-settings.subs - status-im.ui.screens.bootnodes-settings.subs - status-im.ui.screens.pairing.subs - status-im.ui.screens.currency-settings.subs - status-im.ui.screens.browser.subs - status-im.ui.screens.add-new.new-chat.subs - status-im.ui.screens.add-new.new-public-chat.subs - status-im.ui.screens.profile.subs - status-im.ui.screens.hardwallet.connect.subs - status-im.ui.screens.hardwallet.pin.subs - status-im.ui.screens.hardwallet.setup.subs)) - -(reg-sub :get - (fn [db [_ k]] - (get db k))) - -(reg-sub :get-in - (fn [db [_ path]] - (get-in db path))) - -(reg-sub :network - :<- [:account/account] - (fn [current-account] - (get (:networks current-account) (:network current-account)))) - -(reg-sub :network-name :chain) - -(reg-sub :sync-state :sync-state) -(reg-sub :network-status :network-status) -(reg-sub :peers-count :peers-count) -(reg-sub :about-app/node-info :node-info) -(reg-sub :peers-summary :peers-summary) -(reg-sub :node-status :node/status) - -(reg-sub :disconnected? - :<- [:peers-count] - (fn [peers-count] - (zero? peers-count))) - -(reg-sub :connection-stats - (fn [db _] - (get-in db [:desktop/desktop :debug-metrics]))) - -(reg-sub :offline? - :<- [:network-status] - :<- [:sync-state] - :<- [:disconnected?] - (fn [[network-status sync-state disconnected?]] - (or disconnected? - (= network-status :offline) - (= sync-state :offline)))) - -(reg-sub :syncing? - :<- [:sync-state] - (fn [sync-state] - (#{:pending :in-progress} sync-state))) - -(reg-sub :tab-bar-visible? - (fn [db _] - (get db :tab-bar-visible?))) - -(reg-sub :get-screen-params - (fn [db [_ view-id]] - (get-in db [:navigation/screen-params (or view-id (:view-id db))]))) - -(reg-sub :can-navigate-back? - (fn [db] - (> (count (:navigation-stack db)) 1))) - -(reg-sub :delete-swipe-position - (fn [db [_ type item-id]] - (let [item-animation (get-in db [:animations type item-id])] - (if (some? item-animation) (:delete-swiped item-animation) nil)))) - -(reg-sub :dimensions/window - (fn [db _] - (get db :dimensions/window))) - -(reg-sub :dimensions/window-width - :<- [:dimensions/window] - :width) - -(reg-sub :initial-props - (fn [db _] - (get db :initial-props))) diff --git a/src/status_im/ui/screens/views.cljs b/src/status_im/ui/screens/views.cljs index b5cf151a87..7294ca6882 100644 --- a/src/status_im/ui/screens/views.cljs +++ b/src/status_im/ui/screens/views.cljs @@ -36,7 +36,7 @@ [bottom-sheet/bottom-sheet opts]))) (defn main [] - (let [view-id (re-frame/subscribe [:get :view-id]) + (let [view-id (re-frame/subscribe [:view-id]) main-component (atom nil)] (reagent/create-class {:component-did-mount diff --git a/src/status_im/ui/screens/wallet/collectibles/subs.cljs b/src/status_im/ui/screens/wallet/collectibles/subs.cljs deleted file mode 100644 index 929b5251b1..0000000000 --- a/src/status_im/ui/screens/wallet/collectibles/subs.cljs +++ /dev/null @@ -1,12 +0,0 @@ -(ns status-im.ui.screens.wallet.collectibles.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub :collectibles :collectibles) - -(re-frame/reg-sub - :screen-collectibles - :<- [:collectibles] - :<- [:get-screen-params] - (fn [[collectibles {:keys [symbol]}]] - (when-let [v (get collectibles symbol)] - (mapv #(assoc (second %) :id (first %)) v)))) diff --git a/src/status_im/ui/screens/wallet/navigation.cljs b/src/status_im/ui/screens/wallet/navigation.cljs index 59570ebc02..1a6fb5306c 100644 --- a/src/status_im/ui/screens/wallet/navigation.cljs +++ b/src/status_im/ui/screens/wallet/navigation.cljs @@ -7,15 +7,11 @@ (defmethod navigation/preload-data! :wallet [db _] ;;TODO(goranjovic) - get rid of this preload hook completely - (re-frame/dispatch [:wallet.ui/pull-to-refresh]) - (re-frame/dispatch [:update-wallet]) (assoc-in db [:wallet :current-tab] 0)) (defmethod navigation/preload-data! :wallet-stack [db _] ;;TODO(goranjovic) - get rid of this preload hook completely - (re-frame/dispatch [:wallet.ui/pull-to-refresh]) - (re-frame/dispatch [:update-wallet]) (assoc-in db [:wallet :current-tab] 0)) (defmethod navigation/preload-data! :transactions-history diff --git a/src/status_im/ui/screens/wallet/request/subs.cljs b/src/status_im/ui/screens/wallet/request/subs.cljs deleted file mode 100644 index 16d6735b6a..0000000000 --- a/src/status_im/ui/screens/wallet/request/subs.cljs +++ /dev/null @@ -1,6 +0,0 @@ -(ns status-im.ui.screens.wallet.request.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub :wallet.request/transaction - :<- [:wallet] - :request-transaction) diff --git a/src/status_im/ui/screens/wallet/send/subs.cljs b/src/status_im/ui/screens/wallet/send/subs.cljs deleted file mode 100644 index 2dae90ce35..0000000000 --- a/src/status_im/ui/screens/wallet/send/subs.cljs +++ /dev/null @@ -1,98 +0,0 @@ -(ns status-im.ui.screens.wallet.send.subs - (:require [re-frame.core :as re-frame] - [status-im.utils.money :as money] - [status-im.models.wallet :as models.wallet])) - -(re-frame/reg-sub - ::send-transaction - :<- [:wallet] - (fn [wallet] - (:send-transaction wallet))) - -(re-frame/reg-sub - :wallet.send/symbol - :<- [::send-transaction] - (fn [send-transaction] - (:symbol send-transaction))) - -(re-frame/reg-sub - :wallet.send/advanced? - :<- [::send-transaction] - (fn [send-transaction] - (:advanced? send-transaction))) - -(re-frame/reg-sub - :wallet.send/camera-flashlight - :<- [::send-transaction] - (fn [send-transaction] - (:camera-flashlight send-transaction))) - -(re-frame/reg-sub - :wallet.send/wrong-password? - :<- [::send-transaction] - (fn [send-transaction] - (:wrong-password? send-transaction))) - -(re-frame/reg-sub - :wallet.send/sign-password-enabled? - :<- [::send-transaction] - (fn [{:keys [password]}] - (and (not (nil? password)) (not= password "")))) - -(defn edit-or-transaction-data - "Set up edit data structure, defaulting to transaction when not available" - [transaction edit] - (cond-> edit - (not (get-in edit [:gas-price :value])) - (models.wallet/build-edit - :gas-price - (money/to-fixed (money/wei-> :gwei (:gas-price transaction)))) - - (not (get-in edit [:gas :value])) - (models.wallet/build-edit - :gas - (money/to-fixed (:gas transaction))))) - -(re-frame/reg-sub - :wallet/edit - :<- [::send-transaction] - :<- [:wallet] - (fn [[send-transaction {:keys [edit]}]] - (edit-or-transaction-data - send-transaction - edit))) - -(defn check-sufficient-funds [transaction balance symbol amount] - (assoc transaction :sufficient-funds? - (or (nil? amount) - (money/sufficient-funds? amount (get balance symbol))))) - -(defn check-sufficient-gas [transaction balance symbol amount] - (assoc transaction :sufficient-gas? - (or (nil? amount) - (let [available-ether (get balance :ETH (money/bignumber 0)) - available-for-gas (if (= :ETH symbol) - (.minus available-ether (money/bignumber amount)) - available-ether)] - (money/sufficient-funds? (-> transaction - :max-fee - money/bignumber - (money/formatted->internal :ETH 18)) - (money/bignumber available-for-gas)))))) - -(re-frame/reg-sub - :wallet.send/transaction - :<- [::send-transaction] - :<- [:balance] - (fn [[{:keys [amount symbol] :as transaction} balance]] - (-> transaction - (models.wallet/add-max-fee) - (check-sufficient-funds balance symbol amount) - (check-sufficient-gas balance symbol amount)))) - -(re-frame/reg-sub - :wallet.send/signing-phrase-with-padding - :<- [:account/account] - (fn [{:keys [signing-phrase]}] - (when signing-phrase - (clojure.string/replace-all signing-phrase #" " " ")))) diff --git a/src/status_im/ui/screens/wallet/settings/subs.cljs b/src/status_im/ui/screens/wallet/settings/subs.cljs deleted file mode 100644 index 16b22c9706..0000000000 --- a/src/status_im/ui/screens/wallet/settings/subs.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns status-im.ui.screens.wallet.settings.subs - (:require [re-frame.core :as re-frame])) - -(re-frame/reg-sub - :wallet/settings - :<- [:wallet] - (fn [{:keys [settings]}] - (reduce-kv #(conj %1 %3) [] settings))) diff --git a/src/status_im/ui/screens/wallet/subs.cljs b/src/status_im/ui/screens/wallet/subs.cljs deleted file mode 100644 index 2f8840bc4b..0000000000 --- a/src/status_im/ui/screens/wallet/subs.cljs +++ /dev/null @@ -1,130 +0,0 @@ -(ns status-im.ui.screens.wallet.subs - (:require [re-frame.core :as re-frame] - [status-im.constants :as constants] - [status-im.i18n :as i18n] - [status-im.utils.ethereum.core :as ethereum] - [status-im.utils.ethereum.tokens :as tokens] - [status-im.utils.money :as money])) - -(re-frame/reg-sub :wallet - (fn [db] - (:wallet db))) - -(re-frame/reg-sub :balance - :<- [:wallet] - (fn [wallet] - (:balance wallet))) - -(re-frame/reg-sub :prices - (fn [db] - (:prices db))) - -(re-frame/reg-sub :price - :<- [:prices] - (fn [prices [_ fsym tsym]] - (get-in prices [fsym tsym :price]))) - -(re-frame/reg-sub :last-day - :<- [:prices] - (fn [prices [_ fsym tsym]] - (get-in prices [fsym tsym :last-day]))) - -(re-frame/reg-sub :asset-value - (fn [[_ fsym decimals tsym]] - [(re-frame/subscribe [:balance]) - (re-frame/subscribe [:price fsym tsym]) - (re-frame/subscribe [:wallet/currency])]) - (fn [[balance price currency] [_ fsym decimals tsym]] - (when (and balance price) - (-> (money/internal->formatted (get balance fsym) fsym decimals) - (money/crypto->fiat price) - (money/with-precision 2) - str - (i18n/format-currency (:code currency)))))) - -(defn- get-balance-total-value [balance prices currency token->decimals] - (reduce-kv (fn [acc symbol value] - (if-let [price (get-in prices [symbol currency :price])] - (+ acc (-> (money/internal->formatted value symbol (token->decimals symbol)) - (money/crypto->fiat price) - .toNumber)) - acc)) 0 balance)) - -(re-frame/reg-sub :wallet/all-tokens - (fn [db] (:wallet/all-tokens db))) - -(re-frame/reg-sub :portfolio-value - :<- [:balance] - :<- [:prices] - :<- [:wallet/currency] - :<- [:network] - :<- [:wallet/all-tokens] - (fn [[balance prices currency network all-tokens] [_ currency-code]] - (if (and balance prices) - (let [assets (tokens/tokens-for all-tokens (ethereum/network->chain-keyword network)) - token->decimals (into {} (map #(vector (:symbol %) (:decimals %)) assets)) - balance-total-value - (get-balance-total-value balance - prices - (or currency-code - (-> currency :code keyword)) - token->decimals)] - (if (pos? balance-total-value) - (-> balance-total-value - (money/with-precision 2) - str - (i18n/format-currency (:code currency) false)) - "0")) - "..."))) - -(re-frame/reg-sub :prices-loading? - (fn [db] - (:prices-loading? db))) - -(re-frame/reg-sub :wallet/balance-loading? - :<- [:wallet] - (fn [wallet] - (:balance-loading? wallet))) - -(re-frame/reg-sub :wallet/error-message - :<- [:wallet] - (fn [wallet] - (or (get-in wallet [:errors :balance-update]) - (get-in wallet [:errors :prices-update])))) - -(re-frame/reg-sub :get-wallet-unread-messages-number - (fn [db] - 0)) - -(re-frame/reg-sub :wallet/visible-tokens-symbols - :<- [:network] - :<- [:account/account] - (fn [[network current-account]] - (let [chain (ethereum/network->chain-keyword network)] - (get-in current-account [:settings :wallet :visible-tokens chain])))) - -(re-frame/reg-sub :wallet/visible-assets - :<- [:network] - :<- [:wallet/visible-tokens-symbols] - :<- [:wallet/all-tokens] - (fn [[network visible-tokens-symbols all-tokens]] - (let [chain (ethereum/network->chain-keyword network)] - (conj (filter #(contains? visible-tokens-symbols (:symbol %)) - (tokens/sorted-tokens-for all-tokens (ethereum/network->chain-keyword network))) - (tokens/native-currency chain))))) - -(re-frame/reg-sub :wallet/visible-assets-with-amount - :<- [:balance] - :<- [:wallet/visible-assets] - (fn [[balance visible-assets]] - (map #(assoc % :amount (get balance (:symbol %))) visible-assets))) - -(re-frame/reg-sub :wallet/transferrable-assets-with-amount - :<- [:wallet/visible-assets-with-amount] - (fn [all-assets] - (filter #(not (:nft? %)) all-assets))) - -(re-frame/reg-sub :wallet/currency - :<- [:wallet.settings/currency] - (fn [currency-id] - (get constants/currencies currency-id))) diff --git a/src/status_im/ui/screens/wallet/transactions/subs.cljs b/src/status_im/ui/screens/wallet/transactions/subs.cljs deleted file mode 100644 index f0d5f92727..0000000000 --- a/src/status_im/ui/screens/wallet/transactions/subs.cljs +++ /dev/null @@ -1,127 +0,0 @@ -(ns status-im.ui.screens.wallet.transactions.subs - (:require [re-frame.core :refer [reg-sub subscribe]] - [status-im.i18n :as i18n] - [status-im.utils.datetime :as datetime] - [status-im.utils.hex :as utils.hex] - [status-im.utils.money :as money] - [status-im.models.transactions :as transactions] - [status-im.utils.ethereum.core :as ethereum] - [status-im.utils.ethereum.tokens :as tokens] - [status-im.ui.screens.wallet.utils :as wallet.utils])) - -(reg-sub :wallet.transactions/current-tab - :<- [:wallet] - (fn [wallet] - (get wallet :current-tab 0))) - -(defn enrich-transaction [{:keys [type to from timestamp] :as transaction} contacts] - (let [[contact-address key-contact key-wallet] (if (= type :inbound) - [from :from-contact :to-wallet] - [to :to-contact :from-wallet]) - wallet (i18n/label :main-wallet) - contact (get contacts (utils.hex/normalize-hex contact-address))] - (cond-> transaction - contact (assoc key-contact (:name contact)) - :always (assoc key-wallet wallet - :time-formatted (datetime/timestamp->time timestamp))))) - -(reg-sub :wallet.transactions/transactions - :<- [:wallet] - :<- [:contacts/contacts-by-address] - (fn [[wallet contacts]] - (reduce (fn [acc [hash transaction]] - (assoc acc hash (enrich-transaction transaction contacts))) - {} - (:transactions wallet)))) - -(reg-sub :wallet.transactions/grouped-transactions - :<- [:wallet.transactions/transactions] - (fn [transactions] - (group-by :type (vals transactions)))) - -(reg-sub :wallet.transactions/pending-transactions-list - :<- [:wallet.transactions/grouped-transactions] - (fn [{:keys [pending]}] - (when pending - {:title "Pending" - :key :pending - :data pending}))) - -(reg-sub :wallet.transactions/failed-transactions-list - :<- [:wallet.transactions/grouped-transactions] - (fn [{:keys [failed]}] - (when failed - {:title "Failed" - :key :failed - :data failed}))) - -(defn group-transactions-by-date [transactions] - (->> transactions - (group-by #(datetime/timestamp->date-key (:timestamp %))) - (sort-by key) - reverse - (map (fn [[date-key transactions]] - {:title (datetime/timestamp->mini-date (:timestamp (first transactions))) - :key date-key - :data (sort-by :timestamp > transactions)})))) - -(reg-sub :wallet.transactions/completed-transactions-list - :<- [:wallet.transactions/grouped-transactions] - (fn [{:keys [inbound outbound failed]}] - (group-transactions-by-date (concat inbound outbound failed)))) - -(reg-sub :wallet.transactions/transactions-history-list - :<- [:wallet.transactions/pending-transactions-list] - :<- [:wallet.transactions/completed-transactions-list] - (fn [[pending completed]] - (cond-> [] - pending (into pending) - completed (into completed)))) - -(reg-sub :wallet.transactions/current-transaction - :<- [:wallet] - (fn [wallet] - (:current-transaction wallet))) - -(reg-sub :wallet.transactions/transaction-details - :<- [:wallet.transactions/transactions] - :<- [:wallet.transactions/current-transaction] - :<- [:network] - (fn [[transactions current-transaction network]] - (let [{:keys [gas-used gas-price hash timestamp type] :as transaction} (get transactions current-transaction) - chain (ethereum/network->chain-keyword network) - native-currency (tokens/native-currency chain) - display-unit (wallet.utils/display-symbol native-currency)] - (when transaction - (merge transaction - {:gas-price-eth (if gas-price (money/wei->str :eth gas-price display-unit) "-") - :gas-price-gwei (if gas-price (money/wei->str :gwei gas-price) "-") - :date (datetime/timestamp->long-date timestamp)} - (if (= type :unsigned) - {:block (i18n/label :not-applicable) - :cost (i18n/label :not-applicable) - :gas-limit (i18n/label :not-applicable) - :gas-used (i18n/label :not-applicable) - :nonce (i18n/label :not-applicable) - :hash (i18n/label :not-applicable)} - {:cost (when gas-used - (money/wei->str :eth (money/fee-value gas-used gas-price) display-unit)) - :url (transactions/get-transaction-details-url chain hash)})))))) - -(reg-sub :wallet.transactions.details/confirmations - :<- [:wallet.transactions/transaction-details] - (fn [transaction-details] - ;;TODO (yenda) this field should be calculated based on the current-block and the block of the transaction - (:confirmations transaction-details))) - -(reg-sub :wallet.transactions.details/confirmations-progress - :<- [:wallet.transactions.details/confirmations] - (fn [confirmations] - (let [max-confirmations 10] - (if (>= confirmations max-confirmations) - 100 - (* 100 (/ confirmations max-confirmations)))))) - -(reg-sub :wallet.transactions/filters - (fn [db] - (get-in db [:wallet.transactions :filters]))) diff --git a/src/status_im/utils/js_resources.cljs b/src/status_im/utils/js_resources.cljs index aca421b5dc..69c01737e7 100644 --- a/src/status_im/utils/js_resources.cljs +++ b/src/status_im/utils/js_resources.cljs @@ -12,9 +12,8 @@ (def web3 (str "; if (typeof Web3 == 'undefined') {" (slurp "node_modules/web3/dist/web3.min.js") "}")) -(defn web3-init [provider-address current-account-address network-id] - (str "var providerAddress = \"" provider-address "\";" - "var currentAccountAddress = \"" current-account-address "\";" +(defn web3-init [current-account-address network-id] + (str "var currentAccountAddress = \"" current-account-address "\";" "var networkId = \"" network-id "\";" (slurp "resources/js/web3_init.js"))) diff --git a/src/status_im/utils/subs.cljs b/src/status_im/utils/subs.cljs deleted file mode 100644 index fd8d0c34b1..0000000000 --- a/src/status_im/utils/subs.cljs +++ /dev/null @@ -1,8 +0,0 @@ -(ns status-im.utils.subs) - -(defn contains-sub - "Creates subscrition that cheks if collection (map or set) contains element" - [collection] - (fn [db [_ element]] - (-> (collection db) - (contains? element)))) diff --git a/test/cljs/status_im/test/search/core.cljs b/test/cljs/status_im/test/search/core.cljs index b2cbba4077..2918b0ac52 100644 --- a/test/cljs/status_im/test/search/core.cljs +++ b/test/cljs/status_im/test/search/core.cljs @@ -1,6 +1,6 @@ (ns status-im.test.search.core (:require [cljs.test :refer-macros [deftest testing is]] - [status-im.search.subs :as search.subs])) + [status-im.subs :as search.subs])) (deftest filter-chats (let [chats {:chat-1 {:name "name1" diff --git a/test/cljs/status_im/test/ui/screens/currency_settings/models.cljs b/test/cljs/status_im/test/ui/screens/currency_settings/models.cljs index ac143ba62a..db40e6f114 100644 --- a/test/cljs/status_im/test/ui/screens/currency_settings/models.cljs +++ b/test/cljs/status_im/test/ui/screens/currency_settings/models.cljs @@ -1,13 +1,13 @@ (ns status-im.test.ui.screens.currency-settings.models (:require [cljs.test :refer-macros [deftest is testing]] - [status-im.ui.screens.currency-settings.subs :as subs] + [status-im.chat.commands.impl.transactions :as txs] [status-im.ui.screens.currency-settings.models :as models])) (deftest get-currency - (is (= :usd (subs/get-currency {:account/account {:settings {:wallet {:currency :usd}}}}))) - (is (= :usd (subs/get-currency {:account/account {:settings {:wallet {:currency nil}}}}))) - (is (= :usd (subs/get-currency {:account/account {:settings {:wallet {}}}}))) - (is (= :aud (subs/get-currency {:account/account {:settings {:wallet {:currency :aud}}}})))) + (is (= :usd (txs/get-currency {:account/account {:settings {:wallet {:currency :usd}}}}))) + (is (= :usd (txs/get-currency {:account/account {:settings {:wallet {:currency nil}}}}))) + (is (= :usd (txs/get-currency {:account/account {:settings {:wallet {}}}}))) + (is (= :aud (txs/get-currency {:account/account {:settings {:wallet {:currency :aud}}}})))) (deftest set-currency (let [cofx (models/set-currency {:db {:account/account {:settings {:wallet {}}}}} :usd)] diff --git a/test/cljs/status_im/test/wallet/subs.cljs b/test/cljs/status_im/test/wallet/subs.cljs index 0be9d0d714..86d6b3de1e 100644 --- a/test/cljs/status_im/test/wallet/subs.cljs +++ b/test/cljs/status_im/test/wallet/subs.cljs @@ -1,7 +1,7 @@ (ns status-im.test.wallet.subs (:require [cljs.test :refer-macros [deftest is]] [status-im.utils.money :as money] - [status-im.ui.screens.wallet.subs :as s])) + [status-im.subs :as s])) (deftest test-balance-total-value (is (= (s/get-balance-total-value {:ETH (money/bignumber 1000000000000000000) diff --git a/test/cljs/status_im/test/wallet/transactions/subs.cljs b/test/cljs/status_im/test/wallet/transactions/subs.cljs index 01d672358f..c0d9f6f4e1 100644 --- a/test/cljs/status_im/test/wallet/transactions/subs.cljs +++ b/test/cljs/status_im/test/wallet/transactions/subs.cljs @@ -4,9 +4,9 @@ [re-frame.core :as re-frame] [day8.re-frame.test :refer [run-test-sync]] status-im.ui.screens.db - status-im.ui.screens.subs + status-im.subs [status-im.ui.screens.events :as events] - [status-im.ui.screens.wallet.transactions.subs :as transactions-subs])) + [status-im.subs :as transactions-subs])) (def transactions [{:timestamp "1505912551000"} {:timestamp "1505764322000"}