swap-conversion-rate moved to controller
This commit is contained in:
parent
664d9f0f05
commit
5032104bab
|
@ -119,10 +119,12 @@
|
||||||
(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/currency-information]
|
||||||
:<- [:send-input-amount-screen/max-limit]
|
:<- [:send-input-amount-screen/max-limit]
|
||||||
:<- [:send-input-amount-screen/amount-in-crypto]
|
:<- [:send-input-amount-screen/amount-in-crypto]
|
||||||
:<- [:send-input-amount-screen/token-input-converted-value]
|
:<- [:send-input-amount-screen/token-input-converted-value]
|
||||||
(fn [[{:keys [crypto-currency? input-state] :as controller}
|
(fn [[{:keys [crypto-currency? input-state] :as controller}
|
||||||
|
{:keys [conversion-rate]}
|
||||||
max-limit
|
max-limit
|
||||||
amount-in-crypto
|
amount-in-crypto
|
||||||
token-input-converted-value]]
|
token-input-converted-value]]
|
||||||
|
@ -136,23 +138,29 @@
|
||||||
:limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
:limit-exceeded? (controlled-input/upper-limit-exceeded? input-state)
|
||||||
:amount-in-crypto amount-in-crypto
|
:amount-in-crypto amount-in-crypto
|
||||||
:token-input-converted-value token-input-converted-value
|
:token-input-converted-value token-input-converted-value
|
||||||
|
:conversion-rate conversion-rate
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; events
|
;; events
|
||||||
|
|
||||||
(rf/reg-event-fx
|
|
||||||
:send-input-amount-screen/swap-between-fiat-and-crypto
|
|
||||||
(fn [{:keys [db]}]
|
|
||||||
{: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]]
|
||||||
{:db (update-in db [:layers :ui :send :input-amount-screen :controller :input-state] f)}))
|
{:db (update-in db [:layers :ui :send :input-amount-screen :controller :input-state] f)}))
|
||||||
|
|
||||||
|
(rf/reg-event-fx
|
||||||
|
:send-input-amount-screen/swap-between-fiat-and-crypto
|
||||||
|
(fn [{:keys [db]} [crypto-currency? conversion-rate]]
|
||||||
|
{:db (update-in db [:layers :ui :send :input-amount-screen :controller :crypto-currency?] not)
|
||||||
|
:fx (if crypto-currency?
|
||||||
|
[[:dispatch
|
||||||
|
[:send-input-amount-screen/set-input-state #(controlled-input/->fiat % conversion-rate)]]]
|
||||||
|
[[:dispatch
|
||||||
|
[:send-input-amount-screen/set-input-state
|
||||||
|
#(controlled-input/->crypto % conversion-rate)]]])}))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -234,7 +234,8 @@
|
||||||
valid-input?
|
valid-input?
|
||||||
limit-exceeded?
|
limit-exceeded?
|
||||||
amount-in-crypto
|
amount-in-crypto
|
||||||
token-input-converted-value]
|
token-input-converted-value
|
||||||
|
conversion-rate]
|
||||||
: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)
|
||||||
|
@ -253,16 +254,12 @@
|
||||||
token-by-symbol (rf/sub [:wallet/token-by-symbol
|
token-by-symbol (rf/sub [:wallet/token-by-symbol
|
||||||
(str token-symbol)
|
(str token-symbol)
|
||||||
enabled-from-chain-ids])
|
enabled-from-chain-ids])
|
||||||
currency (rf/sub [:profile/currency])
|
|
||||||
conversion-rate (-> token
|
|
||||||
:market-values-per-currency
|
|
||||||
currency
|
|
||||||
:price)
|
|
||||||
token-decimals (-> token
|
token-decimals (-> token
|
||||||
utils/token-usd-price
|
utils/token-usd-price
|
||||||
utils/one-cent-value
|
utils/one-cent-value
|
||||||
utils/calc-max-crypto-decimals)
|
utils/calc-max-crypto-decimals)
|
||||||
clear-input! #(rf/dispatch [:send-input-amount-screen/set-input-state
|
clear-input! #(rf/dispatch
|
||||||
|
[:send-input-amount-screen/set-input-state
|
||||||
controlled-input/delete-all])
|
controlled-input/delete-all])
|
||||||
currency-symbol (rf/sub [:profile/currency-symbol])
|
currency-symbol (rf/sub [:profile/currency-symbol])
|
||||||
loading-routes? (rf/sub
|
loading-routes? (rf/sub
|
||||||
|
@ -348,15 +345,7 @@
|
||||||
:token token
|
:token token
|
||||||
:reset-amounts-to-zero? (and limit-exceeded?
|
:reset-amounts-to-zero? (and limit-exceeded?
|
||||||
(some? routes))}))
|
(some? routes))}))
|
||||||
swap-between-fiat-and-crypto (fn []
|
]
|
||||||
(if crypto-currency?
|
|
||||||
(rf/dispatch [:send-input-amount-screen/set-input-state
|
|
||||||
#(controlled-input/->fiat % conversion-rate)])
|
|
||||||
(rf/dispatch [:send-input-amount-screen/set-input-state
|
|
||||||
#(controlled-input/->crypto % conversion-rate)])
|
|
||||||
)
|
|
||||||
(rf/dispatch
|
|
||||||
[:send-input-amount-screen/swap-between-fiat-and-crypto]))]
|
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
(fn []
|
(fn []
|
||||||
(when active-screen?
|
(when active-screen?
|
||||||
|
@ -401,7 +390,8 @@
|
||||||
{:container-style style/input-container
|
{:container-style style/input-container
|
||||||
:token-symbol token-symbol
|
:token-symbol token-symbol
|
||||||
:value input-value
|
:value input-value
|
||||||
:on-swap swap-between-fiat-and-crypto
|
:on-swap #(rf/dispatch [:send-input-amount-screen/swap-between-fiat-and-crypto
|
||||||
|
crypto-currency? conversion-rate])
|
||||||
:on-token-press show-select-asset-sheet
|
:on-token-press show-select-asset-sheet
|
||||||
:error? input-error
|
:error? input-error
|
||||||
:currency-symbol (if crypto-currency? token-symbol fiat-currency)
|
:currency-symbol (if crypto-currency? token-symbol fiat-currency)
|
||||||
|
|
Loading…
Reference in New Issue