mirror of
https://github.com/status-im/status-mobile.git
synced 2025-01-28 09:25:44 +00:00
token-input-converted-value, amount-in-crypto moved to controller
This commit is contained in:
parent
a6c346ea7d
commit
664d9f0f05
@ -3,6 +3,7 @@
|
|||||||
[status-im.common.controlled-input.utils :as controlled-input]
|
[status-im.common.controlled-input.utils :as controlled-input]
|
||||||
[status-im.contexts.wallet.common.utils :as utils]
|
[status-im.contexts.wallet.common.utils :as utils]
|
||||||
[utils.money :as money]
|
[utils.money :as money]
|
||||||
|
[utils.number :as number]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
;; notes
|
;; notes
|
||||||
@ -82,16 +83,59 @@
|
|||||||
conversion-rate)
|
conversion-rate)
|
||||||
utils/cut-fiat-balance-to-two-decimals))))
|
utils/cut-fiat-balance-to-two-decimals))))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:send-input-amount-screen/amount-in-crypto
|
||||||
|
:<- [:send-input-amount-screen/controller]
|
||||||
|
:<- [:send-input-amount-screen/currency-information]
|
||||||
|
(fn [[{:keys [crypto-currency? input-state]}
|
||||||
|
{:keys [conversion-rate token-decimals]}]]
|
||||||
|
(let [input-value (controlled-input/input-value input-state)]
|
||||||
|
(if crypto-currency?
|
||||||
|
input-value
|
||||||
|
(number/remove-trailing-zeroes
|
||||||
|
(.toFixed (/ input-value conversion-rate)
|
||||||
|
token-decimals))))))
|
||||||
|
|
||||||
|
(rf/reg-sub
|
||||||
|
:send-input-amount-screen/token-input-converted-value
|
||||||
|
:<- [:send-input-amount-screen/controller]
|
||||||
|
:<- [:send-input-amount-screen/currency-information]
|
||||||
|
(fn [[{:keys [crypto-currency? input-state]}
|
||||||
|
{:keys [conversion-rate currency-symbol token-symbol]}]]
|
||||||
|
(let [input-value (controlled-input/input-value input-state)]
|
||||||
|
(if crypto-currency?
|
||||||
|
(utils/prettify-balance
|
||||||
|
currency-symbol
|
||||||
|
(money/crypto->fiat input-value
|
||||||
|
conversion-rate))
|
||||||
|
(utils/prettify-crypto-balance
|
||||||
|
(or (clj->js token-symbol) "")
|
||||||
|
(money/fiat->crypto input-value
|
||||||
|
conversion-rate)
|
||||||
|
conversion-rate)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(rf/reg-sub
|
(rf/reg-sub
|
||||||
:send-input-amount-screen/data
|
:send-input-amount-screen/data
|
||||||
:<- [:send-input-amount-screen/controller]
|
:<- [:send-input-amount-screen/controller]
|
||||||
:<- [:send-input-amount-screen/max-limit]
|
:<- [:send-input-amount-screen/max-limit]
|
||||||
(fn [[{:keys [crypto-currency? input-state] :as controller} max-limit]]
|
:<- [:send-input-amount-screen/amount-in-crypto]
|
||||||
|
:<- [:send-input-amount-screen/token-input-converted-value]
|
||||||
|
(fn [[{:keys [crypto-currency? input-state] :as controller}
|
||||||
|
max-limit
|
||||||
|
amount-in-crypto
|
||||||
|
token-input-converted-value]]
|
||||||
{:crypto-currency? crypto-currency?
|
{:crypto-currency? crypto-currency?
|
||||||
:max-limit max-limit
|
:max-limit max-limit
|
||||||
:input-state input-state
|
:input-state input-state
|
||||||
|
:input-value (controlled-input/input-value input-state)
|
||||||
|
:input-error (controlled-input/input-error input-state)
|
||||||
|
:valid-input? (not (or (controlled-input/empty-value? input-state)
|
||||||
|
(controlled-input/input-error input-state)))
|
||||||
|
:limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||||
|
:amount-in-crypto amount-in-crypto
|
||||||
|
:token-input-converted-value token-input-converted-value
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
@ -103,6 +147,7 @@
|
|||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
{:db (update-in db [:layers :ui :send :input-amount-screen :controller :crypto-currency?] not)}))
|
{:db (update-in db [:layers :ui :send :input-amount-screen :controller :crypto-currency?] not)}))
|
||||||
|
|
||||||
|
|
||||||
(rf/reg-event-fx
|
(rf/reg-event-fx
|
||||||
:send-input-amount-screen/set-input-state
|
:send-input-amount-screen/set-input-state
|
||||||
(fn [{:keys [db]} [f]]
|
(fn [{:keys [db]} [f]]
|
||||||
@ -114,6 +159,7 @@
|
|||||||
(comment
|
(comment
|
||||||
(rf/dispatch [:send-input-amount-screen/swap-between-fiat-and-crypto])
|
(rf/dispatch [:send-input-amount-screen/swap-between-fiat-and-crypto])
|
||||||
(rf/sub [:send-input-amount-screen/max-limit])
|
(rf/sub [:send-input-amount-screen/max-limit])
|
||||||
|
(rf/sub [:send-input-amount-screen/amount-in-crypto])
|
||||||
(rf/sub [:send-input-amount-screen/data])
|
(rf/sub [:send-input-amount-screen/data])
|
||||||
(rf/sub [:send-input-amount-screen/controller])
|
(rf/sub [:send-input-amount-screen/controller])
|
||||||
|
|
||||||
@ -124,27 +170,3 @@
|
|||||||
:token (:token (rf/sub [:send-input-amount-screen/currency-information]))})
|
:token (:token (rf/sub [:send-input-amount-screen/currency-information]))})
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
#_(rf/reg-sub
|
|
||||||
:wallet/wallet-send-enough-assets?
|
|
||||||
:<- [:wallet/wallet-send]
|
|
||||||
:-> :enough-assets?)
|
|
||||||
|
|
||||||
#_(rf/reg-sub
|
|
||||||
:wallet/wallet-send-token
|
|
||||||
:<- [:wallet/wallet-send]
|
|
||||||
:<- [:wallet/network-details]
|
|
||||||
:<- [:wallet/wallet-send-disabled-from-chain-ids]
|
|
||||||
(fn [[wallet-send networks disabled-from-chain-ids]]
|
|
||||||
(let [token (:token wallet-send)
|
|
||||||
disabled-from-chain-ids? (set disabled-from-chain-ids)
|
|
||||||
enabled-from-chain-ids (->> networks
|
|
||||||
(map :chain-id)
|
|
||||||
(remove disabled-from-chain-ids?)
|
|
||||||
set)]
|
|
||||||
(some-> token
|
|
||||||
(assoc :networks (network-utils/network-list token networks)
|
|
||||||
:available-balance (utils/calculate-total-token-balance token)
|
|
||||||
:total-balance (utils/calculate-total-token-balance
|
|
||||||
token
|
|
||||||
enabled-from-chain-ids))))))
|
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
|
[status-im.contexts.wallet.common.account-switcher.view :as account-switcher]
|
||||||
[status-im.contexts.wallet.common.asset-list.view :as asset-list]
|
[status-im.contexts.wallet.common.asset-list.view :as asset-list]
|
||||||
[status-im.contexts.wallet.common.utils :as utils]
|
[status-im.contexts.wallet.common.utils :as utils]
|
||||||
|
[status-im.contexts.wallet.send.input-amount.controller]
|
||||||
[status-im.contexts.wallet.send.input-amount.style :as style]
|
[status-im.contexts.wallet.send.input-amount.style :as style]
|
||||||
[status-im.contexts.wallet.send.routes.view :as routes]
|
[status-im.contexts.wallet.send.routes.view :as routes]
|
||||||
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
|
[status-im.contexts.wallet.sheets.buy-token.view :as buy-token]
|
||||||
@ -227,7 +228,13 @@
|
|||||||
from-enabled-networks :from-enabled-networks}]
|
from-enabled-networks :from-enabled-networks}]
|
||||||
(let [{:keys [crypto-currency?
|
(let [{:keys [crypto-currency?
|
||||||
max-limit
|
max-limit
|
||||||
input-state]
|
input-state
|
||||||
|
input-value
|
||||||
|
input-error
|
||||||
|
valid-input?
|
||||||
|
limit-exceeded?
|
||||||
|
amount-in-crypto
|
||||||
|
token-input-converted-value]
|
||||||
:as state} (rf/sub [:send-input-amount-screen/data])
|
:as state} (rf/sub [:send-input-amount-screen/data])
|
||||||
view-id (rf/sub [:view-id])
|
view-id (rf/sub [:view-id])
|
||||||
active-screen? (= view-id current-screen-id)
|
active-screen? (= view-id current-screen-id)
|
||||||
@ -262,17 +269,10 @@
|
|||||||
[:wallet/wallet-send-loading-suggested-routes?])
|
[:wallet/wallet-send-loading-suggested-routes?])
|
||||||
route (rf/sub [:wallet/wallet-send-route])
|
route (rf/sub [:wallet/wallet-send-route])
|
||||||
on-confirm (or default-on-confirm handle-on-confirm)
|
on-confirm (or default-on-confirm handle-on-confirm)
|
||||||
input-value (controlled-input/input-value input-state)
|
|
||||||
valid-input? (not (or (controlled-input/empty-value? input-state)
|
|
||||||
(controlled-input/input-error input-state)))
|
|
||||||
confirm-disabled? (or (nil? route)
|
confirm-disabled? (or (nil? route)
|
||||||
(empty? route)
|
(empty? route)
|
||||||
(not valid-input?))
|
(not valid-input?))
|
||||||
amount-in-crypto (if crypto-currency?
|
|
||||||
input-value
|
|
||||||
(number/remove-trailing-zeroes
|
|
||||||
(.toFixed (/ input-value conversion-rate)
|
|
||||||
token-decimals)))
|
|
||||||
total-amount-receiver (rf/sub [:wallet/total-amount true])
|
total-amount-receiver (rf/sub [:wallet/total-amount true])
|
||||||
amount-text (str (number/remove-trailing-zeroes
|
amount-text (str (number/remove-trailing-zeroes
|
||||||
(.toFixed total-amount-receiver
|
(.toFixed total-amount-receiver
|
||||||
@ -318,8 +318,6 @@
|
|||||||
receiver-preferred-networks-set
|
receiver-preferred-networks-set
|
||||||
receiver-selected-network))
|
receiver-selected-network))
|
||||||
receiver-networks))
|
receiver-networks))
|
||||||
input-error (controlled-input/input-error input-state)
|
|
||||||
limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
|
||||||
should-try-again? (and (not limit-exceeded?) no-routes-found?)
|
should-try-again? (and (not limit-exceeded?) no-routes-found?)
|
||||||
current-address (rf/sub [:wallet/current-viewing-account-address])
|
current-address (rf/sub [:wallet/current-viewing-account-address])
|
||||||
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
owned-eth-token (rf/sub [:wallet/token-by-symbol
|
||||||
@ -394,7 +392,7 @@
|
|||||||
[rn/view
|
[rn/view
|
||||||
{:style style/screen
|
{:style style/screen
|
||||||
:accessibility-label (str "container"
|
:accessibility-label (str "container"
|
||||||
(when (controlled-input/input-error input-state) "-error"))}
|
(when input-error "-error"))}
|
||||||
[account-switcher/view
|
[account-switcher/view
|
||||||
{:icon-name :i/arrow-left
|
{:icon-name :i/arrow-left
|
||||||
:on-press #(rf/dispatch [:navigate-back])
|
:on-press #(rf/dispatch [:navigate-back])
|
||||||
@ -405,18 +403,9 @@
|
|||||||
:value input-value
|
:value input-value
|
||||||
:on-swap swap-between-fiat-and-crypto
|
:on-swap swap-between-fiat-and-crypto
|
||||||
:on-token-press show-select-asset-sheet
|
:on-token-press show-select-asset-sheet
|
||||||
:error? (controlled-input/input-error input-state)
|
:error? input-error
|
||||||
:currency-symbol (if crypto-currency? token-symbol fiat-currency)
|
:currency-symbol (if crypto-currency? token-symbol fiat-currency)
|
||||||
:converted-value (if crypto-currency?
|
:converted-value token-input-converted-value
|
||||||
(utils/prettify-balance
|
|
||||||
currency-symbol
|
|
||||||
(money/crypto->fiat input-value
|
|
||||||
conversion-rate))
|
|
||||||
(utils/prettify-crypto-balance
|
|
||||||
(or (clj->js token-symbol) "")
|
|
||||||
(money/fiat->crypto input-value
|
|
||||||
conversion-rate)
|
|
||||||
conversion-rate))
|
|
||||||
:hint-component [quo/network-tags
|
:hint-component [quo/network-tags
|
||||||
{:networks (seq from-enabled-networks)
|
{:networks (seq from-enabled-networks)
|
||||||
:title (i18n/label
|
:title (i18n/label
|
||||||
|
Loading…
x
Reference in New Issue
Block a user