mirror of
https://github.com/status-im/status-react.git
synced 2025-01-15 13:37:39 +00:00
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.transport.message.v1.protocol :as protocol]
|
||||||
[status-im.data-store.messages :as messages-store]
|
[status-im.data-store.messages :as messages-store]
|
||||||
[status-im.data-store.user-statuses :as user-statuses-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
|
(def receive-interceptors
|
||||||
[(re-frame/inject-cofx :random-id)
|
[(re-frame/inject-cofx :random-id)
|
||||||
@ -385,19 +387,30 @@
|
|||||||
:as request}
|
:as request}
|
||||||
{:keys [params command handler-data content-type]}
|
{:keys [params command handler-data content-type]}
|
||||||
network
|
network
|
||||||
|
currency
|
||||||
prices
|
prices
|
||||||
tx-hash]
|
tx-hash]
|
||||||
(let [content (if request
|
(let [content (if request
|
||||||
{:request-command request-command
|
{:request-command request-command
|
||||||
;; TODO janherich this is technically not correct, but works for now
|
;; TODO janherich this is technically not correct, but works for now
|
||||||
:request-command-ref (:ref command)
|
: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 prefill
|
||||||
:prefill-bot-db prefillBotDb}
|
:prefill-bot-db prefillBotDb}
|
||||||
{:params (cond-> params
|
{:params (cond-> params
|
||||||
(= (:name command) constants/command-send)
|
(= (:name command) constants/command-send)
|
||||||
(assoc :network (ethereum/network-names network)
|
(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))})
|
:tx-hash tx-hash))})
|
||||||
content' (assoc content
|
content' (assoc content
|
||||||
:command (:name command)
|
:command (:name command)
|
||||||
@ -434,12 +447,14 @@
|
|||||||
[{{:keys [current-public-key chats network prices] :as db} :db :keys [now] :as cofx} params]
|
[{{:keys [current-public-key chats network prices] :as db} :db :keys [now] :as cofx} params]
|
||||||
(let [{{:keys [handler-data to-message command] :as content} :command chat-id :chat-id} params
|
(let [{{:keys [handler-data to-message command] :as content} :command chat-id :chat-id} params
|
||||||
;; We send commands to deleted chats as well, i.e. signed later transactions
|
;; We send commands to deleted chats as well, i.e. signed later transactions
|
||||||
chat (or (get chats chat-id) {:chat-id chat-id})
|
chat (or (get chats chat-id) {:chat-id chat-id})
|
||||||
request (:request handler-data)
|
request (:request handler-data)
|
||||||
command-name (:name command)
|
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
|
(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)
|
(console-events/console-respond-command-messages command handler-data)
|
||||||
(requests-events/request-answered chat-id to-message)
|
(requests-events/request-answered chat-id to-message)
|
||||||
(update-transactions command-name tx-hash {:with-delay? false}))))
|
(update-transactions command-name tx-hash {:with-delay? false}))))
|
||||||
|
@ -77,7 +77,7 @@
|
|||||||
(defview message-content-command-send
|
(defview message-content-command-send
|
||||||
[{:keys [content timestamp-str outgoing group-chat]}]
|
[{:keys [content timestamp-str outgoing group-chat]}]
|
||||||
(letsubs [network [:network-name]]
|
(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])
|
recipient-name (get-in content [:params :bot-db :public :recipient])
|
||||||
amount-text-long? (< 10 (count amount))
|
amount-text-long? (< 10 (count amount))
|
||||||
network-mismatch? (and (seq send-network) (not= network send-network))]
|
network-mismatch? (and (seq send-network) (not= network send-network))]
|
||||||
@ -96,7 +96,7 @@
|
|||||||
(when fiat-amount
|
(when fiat-amount
|
||||||
[react/view style/command-send-fiat-amount
|
[react/view style/command-send-fiat-amount
|
||||||
[react/text {:style style/command-send-fiat-amount-text}
|
[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
|
(when (and group-chat
|
||||||
recipient-name)
|
recipient-name)
|
||||||
[react/text {:style style/command-send-recipient-text}
|
[react/text {:style style/command-send-recipient-text}
|
||||||
|
@ -89,9 +89,8 @@
|
|||||||
(merge command {:prefill prefill
|
(merge command {:prefill prefill
|
||||||
:prefill-bot-db (or prefill-bot-db prefillBotDb)})
|
:prefill-bot-db (or prefill-bot-db prefillBotDb)})
|
||||||
command)
|
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])
|
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))
|
network-mismatch? (and request-network (not= request-network network))
|
||||||
on-press-handler (cond
|
on-press-handler (cond
|
||||||
network-mismatch? nil
|
network-mismatch? nil
|
||||||
@ -119,7 +118,7 @@
|
|||||||
asset]]]
|
asset]]]
|
||||||
[view st/command-request-fiat-amount-row
|
[view st/command-request-fiat-amount-row
|
||||||
[text {:style st/command-request-fiat-amount-text}
|
[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
|
(when (and group-chat
|
||||||
recipient-name)
|
recipient-name)
|
||||||
[text {:style st/command-request-recipient-text}
|
[text {:style st/command-request-recipient-text}
|
||||||
|
@ -1,10 +1,14 @@
|
|||||||
(ns status-im.ui.screens.currency-settings.events
|
(ns status-im.ui.screens.currency-settings.events
|
||||||
(:require [status-im.ui.screens.accounts.events :as accounts]
|
(: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
|
(handlers/register-handler-fx
|
||||||
:wallet.settings/set-currency
|
:wallet.settings/set-currency
|
||||||
(fn [{:keys [db] :as cofx} [_ currency]]
|
(fn [{:keys [db] :as cofx} [_ currency]]
|
||||||
(let [settings (get-in db [:account/account :settings])
|
(let [settings (get-in db [:account/account :settings])
|
||||||
new-settings (assoc-in settings [:wallet :currency] currency)]
|
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
|
(ns status-im.ui.screens.currency-settings.subs
|
||||||
(:require [re-frame.core :as re-frame]))
|
(: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
|
(re-frame/reg-sub
|
||||||
:wallet.settings/currency
|
:wallet.settings/currency
|
||||||
:<- [:get-current-account]
|
(fn [db]
|
||||||
(fn [current-account]
|
(get-user-currency db)))
|
||||||
(or (get-in current-account [:settings :wallet :currency]) :usd)))
|
|
||||||
|
@ -104,37 +104,40 @@
|
|||||||
(defn tokens-symbols [v chain]
|
(defn tokens-symbols [v chain]
|
||||||
(set/difference (set v) (set (map :symbol (tokens/nfts-for chain)))))
|
(set/difference (set v) (set (map :symbol (tokens/nfts-for chain)))))
|
||||||
|
|
||||||
|
(defn update-wallet [{{:keys [web3 network network-status] {:keys [address settings]} :account/account :as db} :db}]
|
||||||
|
(let [network (get-in db [:account/account :networks network])
|
||||||
|
chain (ethereum/network->chain-keyword network)
|
||||||
|
mainnet? (= :mainnet chain)
|
||||||
|
assets (get-in settings [:wallet :visible-tokens chain])
|
||||||
|
tokens (tokens-symbols (get-in settings [:wallet :visible-tokens chain]) chain)
|
||||||
|
currency-id (or (get-in settings [:wallet :currency]) :usd)
|
||||||
|
currency (get constants/currencies currency-id)]
|
||||||
|
(when (not= network-status :offline)
|
||||||
|
{:get-balance {:web3 web3
|
||||||
|
:account-id address
|
||||||
|
:success-event :update-balance-success
|
||||||
|
:error-event :update-balance-fail}
|
||||||
|
:get-tokens-balance {:web3 web3
|
||||||
|
:account-id address
|
||||||
|
:symbols assets
|
||||||
|
:chain chain
|
||||||
|
:success-event :update-token-balance-success
|
||||||
|
:error-event :update-token-balance-fail}
|
||||||
|
:get-prices {:from (if mainnet? (conj tokens "ETH") ["ETH"])
|
||||||
|
:to [(:code currency)]
|
||||||
|
:success-event :update-prices-success
|
||||||
|
:error-event :update-prices-fail}
|
||||||
|
:db (-> db
|
||||||
|
(clear-error-message :prices-update)
|
||||||
|
(clear-error-message :balance-update)
|
||||||
|
(assoc-in [:wallet :balance-loading?] true)
|
||||||
|
(assoc :prices-loading? true))})))
|
||||||
|
|
||||||
;; Handlers
|
;; Handlers
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-wallet
|
:update-wallet
|
||||||
(fn [{{:keys [web3 network network-status] {:keys [address settings]} :account/account :as db} :db} _]
|
(fn [cofx _]
|
||||||
(let [network (get-in db [:account/account :networks network])
|
(update-wallet cofx)))
|
||||||
chain (ethereum/network->chain-keyword network)
|
|
||||||
mainnet? (= :mainnet chain)
|
|
||||||
assets (get-in settings [:wallet :visible-tokens chain])
|
|
||||||
tokens (tokens-symbols (get-in settings [:wallet :visible-tokens chain]) chain)
|
|
||||||
currency-id (or (get-in settings [:wallet :currency]) :usd)
|
|
||||||
currency (get constants/currencies currency-id)]
|
|
||||||
(when (not= network-status :offline)
|
|
||||||
{:get-balance {:web3 web3
|
|
||||||
:account-id address
|
|
||||||
:success-event :update-balance-success
|
|
||||||
:error-event :update-balance-fail}
|
|
||||||
:get-tokens-balance {:web3 web3
|
|
||||||
:account-id address
|
|
||||||
:symbols assets
|
|
||||||
:chain chain
|
|
||||||
:success-event :update-token-balance-success
|
|
||||||
:error-event :update-token-balance-fail}
|
|
||||||
:get-prices {:from (if mainnet? (conj tokens "ETH") ["ETH"])
|
|
||||||
:to [(:code currency)]
|
|
||||||
:success-event :update-prices-success
|
|
||||||
:error-event :update-prices-fail}
|
|
||||||
:db (-> db
|
|
||||||
(clear-error-message :prices-update)
|
|
||||||
(clear-error-message :balance-update)
|
|
||||||
(assoc-in [:wallet :balance-loading?] true)
|
|
||||||
(assoc :prices-loading? true))}))))
|
|
||||||
|
|
||||||
(handlers/register-handler-fx
|
(handlers/register-handler-fx
|
||||||
:update-transactions
|
:update-transactions
|
||||||
|
@ -143,10 +143,10 @@
|
|||||||
(when (and amount balance)
|
(when (and amount balance)
|
||||||
(.greaterThanOrEqualTo balance amount)))
|
(.greaterThanOrEqualTo balance amount)))
|
||||||
|
|
||||||
(defn usd-amount [amount-str from prices]
|
(defn fiat-amount-value [amount-str from to prices]
|
||||||
(-> amount-str
|
(-> amount-str
|
||||||
(js/parseFloat)
|
(js/parseFloat)
|
||||||
bignumber
|
bignumber
|
||||||
(crypto->fiat (get-in prices [from :USD :price] (bignumber 0)))
|
(crypto->fiat (get-in prices [from to :price] (bignumber 0)))
|
||||||
(with-precision 2)
|
(with-precision 2)
|
||||||
str))
|
str))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user