re-frame subscriptions optimization

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2019-04-26 12:09:58 +02:00
parent b90f1e5324
commit 428464df07
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
75 changed files with 1717 additions and 1806 deletions

View File

@ -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 []

View File

@ -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

View File

@ -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)])))

View File

@ -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]]

View File

@ -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]))))

View File

@ -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)))

View File

@ -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]

View File

@ -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}}

View File

@ -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])

View File

@ -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 []

View File

@ -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))))

View File

@ -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)))

1642
src/status_im/subs.cljs Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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}

View File

@ -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)

View File

@ -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}))

View File

@ -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]))})))

View File

@ -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}}

View File

@ -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])]]))

View File

@ -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

View File

@ -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?]]

View File

@ -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?)

View File

@ -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)))))

View File

@ -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)))

View File

@ -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))))

View File

@ -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]

View File

@ -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))))

View File

@ -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)])))

View File

@ -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)))))

View File

@ -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}]])))

View File

@ -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

View File

@ -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

View File

@ -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)))

View File

@ -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

View File

@ -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)))

View File

@ -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

View File

@ -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}

View File

@ -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]

View File

@ -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?]))

View File

@ -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)

View File

@ -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

View File

@ -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 []

View File

@ -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)))

View File

@ -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)))

View File

@ -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))

View File

@ -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)))

View File

@ -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)

View File

@ -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]

View File

@ -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)))

View File

@ -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?]))

View File

@ -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)))

View File

@ -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

View File

@ -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)]

View File

@ -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))))

View File

@ -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)))))

View File

@ -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)))

View File

@ -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)

View File

@ -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})))

View File

@ -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?

View File

@ -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)))

View File

@ -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)))

View File

@ -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

View File

@ -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))))

View File

@ -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

View File

@ -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)

View File

@ -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 #" " " "))))

View File

@ -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)))

View File

@ -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)))

View File

@ -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])))

View File

@ -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")))

View File

@ -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))))

View File

@ -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"

View File

@ -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)]

View File

@ -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)

View File

@ -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"}