mirror of
https://github.com/status-im/status-mobile.git
synced 2025-03-01 00:30:49 +00:00
Fixes for screen where user locks network amounts to send (#20519)
This commit is contained in:
parent
35a1905396
commit
b28a8e153e
@ -12,7 +12,8 @@
|
||||
[{:keys [checked? blur? accessibility-label container-style on-change icon customization-color]} label]
|
||||
(let [theme (quo.theme/use-theme)]
|
||||
[rn/touchable-without-feedback
|
||||
{:on-press on-change
|
||||
{:on-press (when on-change
|
||||
#(on-change (not checked?)))
|
||||
:accessibility-label :disclaimer-touchable-opacity}
|
||||
[rn/view {:style (merge container-style (style/container blur? theme))}
|
||||
[selectors/view
|
||||
|
@ -237,7 +237,8 @@
|
||||
(assoc-in [:wallet :ui :send :token-not-supported-in-receiver-networks?]
|
||||
token-not-supported-in-receiver-networks?))
|
||||
:fx [[:dispatch [:hide-bottom-sheet]]
|
||||
[:dispatch [:wallet/clean-suggested-routes]]]})))
|
||||
[:dispatch [:wallet/clean-suggested-routes]]
|
||||
[:dispatch [:wallet/clean-from-locked-amounts]]]})))
|
||||
|
||||
(rf/reg-event-fx :wallet/clean-selected-token
|
||||
(fn [{:keys [db]}]
|
||||
|
@ -369,7 +369,7 @@
|
||||
:allow-selection? false}]
|
||||
[routes/view
|
||||
{:token token-by-symbol
|
||||
:input-value input-amount
|
||||
:send-amount-in-crypto amount-in-crypto
|
||||
:valid-input? valid-input?
|
||||
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
||||
:lock-fetch-routes? just-toggled-mode?
|
||||
|
@ -47,3 +47,6 @@
|
||||
(defn keyboard-container
|
||||
[bottom]
|
||||
{:padding-bottom bottom})
|
||||
|
||||
(def error-box
|
||||
{:margin-horizontal 20})
|
||||
|
@ -11,6 +11,7 @@
|
||||
[status-im.contexts.wallet.send.utils :as send-utils]
|
||||
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
|
||||
[utils.i18n :as i18n]
|
||||
[utils.money :as money]
|
||||
[utils.number :as number]
|
||||
[utils.re-frame :as rf]))
|
||||
|
||||
@ -86,7 +87,7 @@
|
||||
chain-ids]))}]))}]))
|
||||
|
||||
(defn- edit-amount
|
||||
[{:keys [chain-id token-symbol]}]
|
||||
[{:keys [chain-id token-symbol send-amount-in-crypto init-amount]}]
|
||||
(rf/dispatch
|
||||
[:show-bottom-sheet
|
||||
{:content
|
||||
@ -105,6 +106,9 @@
|
||||
locked-amount (get send-from-locked-amounts chain-id)
|
||||
network-name-str (string/capitalize (name network-name))
|
||||
[input-state set-input-state] (rn/use-state (cond-> controlled-input/init-state
|
||||
init-amount
|
||||
(controlled-input/set-input-value
|
||||
(money/to-string init-amount))
|
||||
locked-amount
|
||||
(controlled-input/set-input-value
|
||||
locked-amount)))
|
||||
@ -133,6 +137,13 @@
|
||||
(.toFixed (/ input-amount
|
||||
conversion-rate)
|
||||
crypto-decimals)))
|
||||
locked-greater-then-send-amount? (let [amount (money/bignumber
|
||||
amount-in-crypto)
|
||||
send-amount (money/bignumber
|
||||
send-amount-in-crypto)]
|
||||
(and (money/bignumber? amount)
|
||||
(money/bignumber? send-amount)
|
||||
(money/greater-than amount send-amount)))
|
||||
swap-between-fiat-and-crypto (fn [swap-to-crypto-currency?]
|
||||
(set-crypto-currency swap-to-crypto-currency?)
|
||||
(set-input-state
|
||||
@ -187,6 +198,12 @@
|
||||
:value (controlled-input/input-value input-state)
|
||||
:on-swap swap-between-fiat-and-crypto
|
||||
:allow-selection? false}]
|
||||
(when locked-greater-then-send-amount?
|
||||
[quo/information-box
|
||||
{:type :error
|
||||
:icon :i/info
|
||||
:style style/error-box}
|
||||
(i18n/label :t/value-higher-than-send-amount)])
|
||||
[quo/disclaimer
|
||||
{:on-change (fn [checked?]
|
||||
(set-is-amount-locked checked?))
|
||||
@ -203,7 +220,8 @@
|
||||
:button-one-props {:on-press lock-or-unlock-amount
|
||||
:customization-color account-color
|
||||
:disabled? (or (controlled-input/empty-value? input-state)
|
||||
(controlled-input/input-error input-state))}}]
|
||||
(controlled-input/input-error input-state)
|
||||
locked-greater-then-send-amount?)}}]
|
||||
[quo/numbered-keyboard
|
||||
{:container-style (style/keyboard-container bottom)
|
||||
:left-action :dot
|
||||
@ -217,40 +235,46 @@
|
||||
(set-is-amount-locked true)
|
||||
(set-input-state #(controlled-input/add-character % c)))))
|
||||
:on-delete (fn []
|
||||
(set-is-amount-locked true)
|
||||
(set-input-state controlled-input/delete-last))
|
||||
:on-long-press-delete (fn []
|
||||
(set-is-amount-locked true)
|
||||
(set-input-state controlled-input/delete-all))}]]))}]))
|
||||
|
||||
(defn render-network-values
|
||||
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
||||
token-not-supported-in-receiver-networks?]}]
|
||||
[rn/view
|
||||
(map-indexed (fn [index {:keys [chain-id total-amount type]}]
|
||||
[rn/view
|
||||
{:key (str (if receiver? "to" "from") "-" chain-id)
|
||||
:style {:margin-top (if (pos? index) 11 7.5)}}
|
||||
[quo/network-bridge
|
||||
{:amount (if (= type :not-available)
|
||||
(i18n/label :t/not-available)
|
||||
(str total-amount " " token-symbol))
|
||||
:network (network-utils/id->network chain-id)
|
||||
:status (cond (and (= type :not-available)
|
||||
loading-routes?
|
||||
token-not-supported-in-receiver-networks?)
|
||||
:loading
|
||||
(= type :not-available)
|
||||
:disabled
|
||||
:else type)
|
||||
:on-press #(when (not loading-routes?)
|
||||
(cond
|
||||
(= type :edit)
|
||||
(open-preferences)
|
||||
on-press (on-press chain-id total-amount)))
|
||||
:on-long-press #(when (not loading-routes?)
|
||||
(cond
|
||||
(= type :add)
|
||||
(open-preferences)
|
||||
on-long-press (on-long-press chain-id)))}]])
|
||||
(map-indexed (fn [index
|
||||
{chain-id :chain-id
|
||||
network-value-type :type
|
||||
total-amount :total-amount}]
|
||||
(let [status (cond (and (= network-value-type :not-available)
|
||||
loading-routes?
|
||||
token-not-supported-in-receiver-networks?)
|
||||
:loading
|
||||
(= network-value-type :not-available)
|
||||
:disabled
|
||||
:else network-value-type)]
|
||||
[rn/view
|
||||
{:key (str (if receiver? "to" "from") "-" chain-id)
|
||||
:style {:margin-top (if (pos? index) 11 7.5)}}
|
||||
[quo/network-bridge
|
||||
{:amount (if (= network-value-type :not-available)
|
||||
(i18n/label :t/not-available)
|
||||
(str total-amount " " token-symbol))
|
||||
:network (network-utils/id->network chain-id)
|
||||
:status status
|
||||
:on-press #(when (not loading-routes?)
|
||||
(cond
|
||||
(= network-value-type :edit)
|
||||
(open-preferences)
|
||||
on-press (on-press chain-id total-amount)))
|
||||
:on-long-press #(when (and (not loading-routes?) (not= status :disabled))
|
||||
(cond
|
||||
(= network-value-type :add)
|
||||
(open-preferences)
|
||||
on-long-press (on-long-press chain-id total-amount)))}]]))
|
||||
network-values)])
|
||||
|
||||
(defn render-network-links
|
||||
@ -313,9 +337,9 @@
|
||||
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
||||
|
||||
(defn view
|
||||
[{:keys [token theme input-value valid-input? request-fetch-routes
|
||||
[{:keys [token theme valid-input? request-fetch-routes
|
||||
lock-fetch-routes? on-press-to-network current-screen-id
|
||||
token-not-supported-in-receiver-networks?]}]
|
||||
token-not-supported-in-receiver-networks? send-amount-in-crypto]}]
|
||||
(let [token-symbol (:symbol token)
|
||||
nav-current-screen-id (rf/sub [:view-id])
|
||||
active-screen? (= nav-current-screen-id current-screen-id)
|
||||
@ -340,7 +364,7 @@
|
||||
(> (count token-available-networks-for-suggested-routes) 0)
|
||||
(not lock-fetch-routes?))
|
||||
(request-fetch-routes 2000)))
|
||||
[input-value valid-input?])
|
||||
[send-amount-in-crypto valid-input?])
|
||||
(rn/use-effect
|
||||
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
||||
(request-fetch-routes 0))
|
||||
@ -363,11 +387,12 @@
|
||||
chain-id-to-disable
|
||||
disabled-from-chain-ids
|
||||
token-available-networks-for-suggested-routes))
|
||||
|
||||
:on-long-press (fn [chain-id]
|
||||
:on-long-press (fn [chain-id amount-calculated-for-chain]
|
||||
(edit-amount
|
||||
{:chain-id chain-id
|
||||
:token-symbol token-symbol}))
|
||||
{:chain-id chain-id
|
||||
:token-symbol token-symbol
|
||||
:send-amount-in-crypto send-amount-in-crypto
|
||||
:init-amount amount-calculated-for-chain}))
|
||||
:receiver? false
|
||||
:theme theme
|
||||
:loading-routes? loading-routes?
|
||||
|
@ -2736,5 +2736,6 @@
|
||||
"dont-auto-recalculate-network": "Don't auto recalculate {{network}}",
|
||||
"import-keypair-to-use-account": "Import key pair to use this account",
|
||||
"import-keypair-steps": "{{account-name}} was derived from your {{keypair-name}} key pair, which has not yet been imported to this device. To transact using this account, you will need to import the {{keypair-name}} key pair first.",
|
||||
"not-now": "Not now"
|
||||
"not-now": "Not now",
|
||||
"value-higher-than-send-amount": "This value is higher than entered amount to send"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user