Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
ebe1b08b2c
commit
21595eede7
|
@ -17,7 +17,9 @@
|
|||
[status-im.transport.message.v1.protocol :as protocol]
|
||||
[status-im.data-store.messages :as messages-store]
|
||||
[status-im.data-store.user-statuses :as user-statuses-store]
|
||||
[status-im.utils.datetime :as datetime]))
|
||||
[status-im.ui.screens.currency-settings.subs :as currency-settings]
|
||||
[status-im.utils.datetime :as datetime]
|
||||
[clojure.string :as string]))
|
||||
|
||||
(def receive-interceptors
|
||||
[(re-frame/inject-cofx :random-id)
|
||||
|
@ -385,19 +387,30 @@
|
|||
:as request}
|
||||
{:keys [params command handler-data content-type]}
|
||||
network
|
||||
currency
|
||||
prices
|
||||
tx-hash]
|
||||
(let [content (if request
|
||||
{:request-command request-command
|
||||
;; TODO janherich this is technically not correct, but works for now
|
||||
:request-command-ref (:ref command)
|
||||
:params (assoc request-params :bot-db (:bot-db params))
|
||||
:params (assoc request-params
|
||||
:bot-db (:bot-db params)
|
||||
:fiat-amount (money/fiat-amount-value (:amount request-params)
|
||||
(-> request-params :asset keyword)
|
||||
currency
|
||||
prices)
|
||||
:currency (name currency))
|
||||
:prefill prefill
|
||||
:prefill-bot-db prefillBotDb}
|
||||
{:params (cond-> params
|
||||
(= (:name command) constants/command-send)
|
||||
(assoc :network (ethereum/network-names network)
|
||||
:fiat-amount (money/usd-amount (:amount params) (-> params :asset keyword) prices)
|
||||
:fiat-amount (money/fiat-amount-value (:amount params)
|
||||
(-> params :asset keyword)
|
||||
currency
|
||||
prices)
|
||||
:currency (name currency)
|
||||
:tx-hash tx-hash))})
|
||||
content' (assoc content
|
||||
:command (:name command)
|
||||
|
@ -437,9 +450,11 @@
|
|||
chat (or (get chats chat-id) {:chat-id chat-id})
|
||||
request (:request handler-data)
|
||||
command-name (:name command)
|
||||
tx-hash (get-in db [:wallet :send-transaction :tx-hash])]
|
||||
tx-hash (get-in db [:wallet :send-transaction :tx-hash])
|
||||
currency (-> (currency-settings/get-user-currency db) name string/upper-case keyword)]
|
||||
(handlers-macro/merge-fx cofx
|
||||
(upsert-and-send (prepare-command-message current-public-key chat now request content network prices tx-hash))
|
||||
(upsert-and-send (prepare-command-message current-public-key chat now request content
|
||||
network currency prices tx-hash))
|
||||
(console-events/console-respond-command-messages command handler-data)
|
||||
(requests-events/request-answered chat-id to-message)
|
||||
(update-transactions command-name tx-hash {:with-delay? false}))))
|
||||
|
|
|
@ -77,7 +77,7 @@
|
|||
(defview message-content-command-send
|
||||
[{:keys [content timestamp-str outgoing group-chat]}]
|
||||
(letsubs [network [:network-name]]
|
||||
(let [{{:keys [amount fiat-amount tx-hash asset] send-network :network} :params} content
|
||||
(let [{{:keys [amount fiat-amount tx-hash asset currency] send-network :network} :params} content
|
||||
recipient-name (get-in content [:params :bot-db :public :recipient])
|
||||
amount-text-long? (< 10 (count amount))
|
||||
network-mismatch? (and (seq send-network) (not= network send-network))]
|
||||
|
@ -96,7 +96,7 @@
|
|||
(when fiat-amount
|
||||
[react/view style/command-send-fiat-amount
|
||||
[react/text {:style style/command-send-fiat-amount-text}
|
||||
(str "~ " fiat-amount " " (i18n/label :usd-currency))]])
|
||||
(str "~ " fiat-amount " " (or currency (i18n/label :usd-currency)))]])
|
||||
(when (and group-chat
|
||||
recipient-name)
|
||||
[react/text {:style style/command-send-recipient-text}
|
||||
|
|
|
@ -89,9 +89,8 @@
|
|||
(merge command {:prefill prefill
|
||||
:prefill-bot-db (or prefill-bot-db prefillBotDb)})
|
||||
command)
|
||||
{:keys [amount asset] request-network :network} params
|
||||
{:keys [amount asset fiat-amount currency] request-network :network} params
|
||||
recipient-name (get-in params [:bot-db :public :recipient])
|
||||
usd-amount (money/usd-amount amount (keyword asset) prices)
|
||||
network-mismatch? (and request-network (not= request-network network))
|
||||
on-press-handler (cond
|
||||
network-mismatch? nil
|
||||
|
@ -119,7 +118,7 @@
|
|||
asset]]]
|
||||
[view st/command-request-fiat-amount-row
|
||||
[text {:style st/command-request-fiat-amount-text}
|
||||
(str "~ " usd-amount " " (i18n/label :usd-currency))]]
|
||||
(str "~ " fiat-amount " " (or currency (i18n/label :usd-currency)))]]
|
||||
(when (and group-chat
|
||||
recipient-name)
|
||||
[text {:style st/command-request-recipient-text}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
(ns status-im.ui.screens.currency-settings.events
|
||||
(:require [status-im.ui.screens.accounts.events :as accounts]
|
||||
[status-im.utils.handlers :as handlers]))
|
||||
[status-im.utils.handlers :as handlers]
|
||||
[status-im.utils.handlers-macro :as handlers-macro]
|
||||
[status-im.ui.screens.wallet.events :as wallet.events]))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:wallet.settings/set-currency
|
||||
(fn [{:keys [db] :as cofx} [_ currency]]
|
||||
(let [settings (get-in db [:account/account :settings])
|
||||
new-settings (assoc-in settings [:wallet :currency] currency)]
|
||||
(accounts/update-settings new-settings cofx))))
|
||||
(handlers-macro/merge-fx cofx
|
||||
(accounts/update-settings new-settings)
|
||||
(wallet.events/update-wallet)))))
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
(ns status-im.ui.screens.currency-settings.subs
|
||||
(:require [re-frame.core :as re-frame]))
|
||||
|
||||
(defn get-user-currency [db]
|
||||
(get-in db [:account/account :settings :wallet :currency] :usd))
|
||||
|
||||
(re-frame/reg-sub
|
||||
:wallet.settings/currency
|
||||
:<- [:get-current-account]
|
||||
(fn [current-account]
|
||||
(or (get-in current-account [:settings :wallet :currency]) :usd)))
|
||||
(fn [db]
|
||||
(get-user-currency db)))
|
||||
|
|
|
@ -104,10 +104,7 @@
|
|||
(defn tokens-symbols [v chain]
|
||||
(set/difference (set v) (set (map :symbol (tokens/nfts-for chain)))))
|
||||
|
||||
;; Handlers
|
||||
(handlers/register-handler-fx
|
||||
:update-wallet
|
||||
(fn [{{:keys [web3 network network-status] {:keys [address settings]} :account/account :as db} :db} _]
|
||||
(defn update-wallet [{{:keys [web3 network network-status] {:keys [address settings]} :account/account :as db} :db}]
|
||||
(let [network (get-in db [:account/account :networks network])
|
||||
chain (ethereum/network->chain-keyword network)
|
||||
mainnet? (= :mainnet chain)
|
||||
|
@ -134,7 +131,13 @@
|
|||
(clear-error-message :prices-update)
|
||||
(clear-error-message :balance-update)
|
||||
(assoc-in [:wallet :balance-loading?] true)
|
||||
(assoc :prices-loading? true))}))))
|
||||
(assoc :prices-loading? true))})))
|
||||
|
||||
;; Handlers
|
||||
(handlers/register-handler-fx
|
||||
:update-wallet
|
||||
(fn [cofx _]
|
||||
(update-wallet cofx)))
|
||||
|
||||
(handlers/register-handler-fx
|
||||
:update-transactions
|
||||
|
|
|
@ -143,10 +143,10 @@
|
|||
(when (and amount balance)
|
||||
(.greaterThanOrEqualTo balance amount)))
|
||||
|
||||
(defn usd-amount [amount-str from prices]
|
||||
(defn fiat-amount-value [amount-str from to prices]
|
||||
(-> amount-str
|
||||
(js/parseFloat)
|
||||
bignumber
|
||||
(crypto->fiat (get-in prices [from :USD :price] (bignumber 0)))
|
||||
(crypto->fiat (get-in prices [from to :price] (bignumber 0)))
|
||||
(with-precision 2)
|
||||
str))
|
||||
|
|
Loading…
Reference in New Issue