mirror of
https://github.com/status-im/status-mobile.git
synced 2025-03-01 08:40:50 +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]
|
[{:keys [checked? blur? accessibility-label container-style on-change icon customization-color]} label]
|
||||||
(let [theme (quo.theme/use-theme)]
|
(let [theme (quo.theme/use-theme)]
|
||||||
[rn/touchable-without-feedback
|
[rn/touchable-without-feedback
|
||||||
{:on-press on-change
|
{:on-press (when on-change
|
||||||
|
#(on-change (not checked?)))
|
||||||
:accessibility-label :disclaimer-touchable-opacity}
|
:accessibility-label :disclaimer-touchable-opacity}
|
||||||
[rn/view {:style (merge container-style (style/container blur? theme))}
|
[rn/view {:style (merge container-style (style/container blur? theme))}
|
||||||
[selectors/view
|
[selectors/view
|
||||||
|
@ -237,7 +237,8 @@
|
|||||||
(assoc-in [:wallet :ui :send :token-not-supported-in-receiver-networks?]
|
(assoc-in [:wallet :ui :send :token-not-supported-in-receiver-networks?]
|
||||||
token-not-supported-in-receiver-networks?))
|
token-not-supported-in-receiver-networks?))
|
||||||
:fx [[:dispatch [:hide-bottom-sheet]]
|
: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
|
(rf/reg-event-fx :wallet/clean-selected-token
|
||||||
(fn [{:keys [db]}]
|
(fn [{:keys [db]}]
|
||||||
|
@ -369,7 +369,7 @@
|
|||||||
:allow-selection? false}]
|
:allow-selection? false}]
|
||||||
[routes/view
|
[routes/view
|
||||||
{:token token-by-symbol
|
{:token token-by-symbol
|
||||||
:input-value input-amount
|
:send-amount-in-crypto amount-in-crypto
|
||||||
:valid-input? valid-input?
|
:valid-input? valid-input?
|
||||||
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
:token-not-supported-in-receiver-networks? token-not-supported-in-receiver-networks?
|
||||||
:lock-fetch-routes? just-toggled-mode?
|
:lock-fetch-routes? just-toggled-mode?
|
||||||
|
@ -47,3 +47,6 @@
|
|||||||
(defn keyboard-container
|
(defn keyboard-container
|
||||||
[bottom]
|
[bottom]
|
||||||
{:padding-bottom 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.send.utils :as send-utils]
|
||||||
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
|
[status-im.contexts.wallet.sheets.network-preferences.view :as network-preferences]
|
||||||
[utils.i18n :as i18n]
|
[utils.i18n :as i18n]
|
||||||
|
[utils.money :as money]
|
||||||
[utils.number :as number]
|
[utils.number :as number]
|
||||||
[utils.re-frame :as rf]))
|
[utils.re-frame :as rf]))
|
||||||
|
|
||||||
@ -86,7 +87,7 @@
|
|||||||
chain-ids]))}]))}]))
|
chain-ids]))}]))}]))
|
||||||
|
|
||||||
(defn- edit-amount
|
(defn- edit-amount
|
||||||
[{:keys [chain-id token-symbol]}]
|
[{:keys [chain-id token-symbol send-amount-in-crypto init-amount]}]
|
||||||
(rf/dispatch
|
(rf/dispatch
|
||||||
[:show-bottom-sheet
|
[:show-bottom-sheet
|
||||||
{:content
|
{:content
|
||||||
@ -105,6 +106,9 @@
|
|||||||
locked-amount (get send-from-locked-amounts chain-id)
|
locked-amount (get send-from-locked-amounts chain-id)
|
||||||
network-name-str (string/capitalize (name network-name))
|
network-name-str (string/capitalize (name network-name))
|
||||||
[input-state set-input-state] (rn/use-state (cond-> controlled-input/init-state
|
[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
|
locked-amount
|
||||||
(controlled-input/set-input-value
|
(controlled-input/set-input-value
|
||||||
locked-amount)))
|
locked-amount)))
|
||||||
@ -133,6 +137,13 @@
|
|||||||
(.toFixed (/ input-amount
|
(.toFixed (/ input-amount
|
||||||
conversion-rate)
|
conversion-rate)
|
||||||
crypto-decimals)))
|
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?]
|
swap-between-fiat-and-crypto (fn [swap-to-crypto-currency?]
|
||||||
(set-crypto-currency swap-to-crypto-currency?)
|
(set-crypto-currency swap-to-crypto-currency?)
|
||||||
(set-input-state
|
(set-input-state
|
||||||
@ -187,6 +198,12 @@
|
|||||||
:value (controlled-input/input-value input-state)
|
:value (controlled-input/input-value input-state)
|
||||||
:on-swap swap-between-fiat-and-crypto
|
:on-swap swap-between-fiat-and-crypto
|
||||||
:allow-selection? false}]
|
: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
|
[quo/disclaimer
|
||||||
{:on-change (fn [checked?]
|
{:on-change (fn [checked?]
|
||||||
(set-is-amount-locked checked?))
|
(set-is-amount-locked checked?))
|
||||||
@ -203,7 +220,8 @@
|
|||||||
:button-one-props {:on-press lock-or-unlock-amount
|
:button-one-props {:on-press lock-or-unlock-amount
|
||||||
:customization-color account-color
|
:customization-color account-color
|
||||||
:disabled? (or (controlled-input/empty-value? input-state)
|
: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
|
[quo/numbered-keyboard
|
||||||
{:container-style (style/keyboard-container bottom)
|
{:container-style (style/keyboard-container bottom)
|
||||||
:left-action :dot
|
:left-action :dot
|
||||||
@ -217,40 +235,46 @@
|
|||||||
(set-is-amount-locked true)
|
(set-is-amount-locked true)
|
||||||
(set-input-state #(controlled-input/add-character % c)))))
|
(set-input-state #(controlled-input/add-character % c)))))
|
||||||
:on-delete (fn []
|
:on-delete (fn []
|
||||||
|
(set-is-amount-locked true)
|
||||||
(set-input-state controlled-input/delete-last))
|
(set-input-state controlled-input/delete-last))
|
||||||
:on-long-press-delete (fn []
|
:on-long-press-delete (fn []
|
||||||
|
(set-is-amount-locked true)
|
||||||
(set-input-state controlled-input/delete-all))}]]))}]))
|
(set-input-state controlled-input/delete-all))}]]))}]))
|
||||||
|
|
||||||
(defn render-network-values
|
(defn render-network-values
|
||||||
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
[{:keys [network-values token-symbol on-press on-long-press receiver? loading-routes?
|
||||||
token-not-supported-in-receiver-networks?]}]
|
token-not-supported-in-receiver-networks?]}]
|
||||||
[rn/view
|
[rn/view
|
||||||
(map-indexed (fn [index {:keys [chain-id total-amount type]}]
|
(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
|
[rn/view
|
||||||
{:key (str (if receiver? "to" "from") "-" chain-id)
|
{:key (str (if receiver? "to" "from") "-" chain-id)
|
||||||
:style {:margin-top (if (pos? index) 11 7.5)}}
|
:style {:margin-top (if (pos? index) 11 7.5)}}
|
||||||
[quo/network-bridge
|
[quo/network-bridge
|
||||||
{:amount (if (= type :not-available)
|
{:amount (if (= network-value-type :not-available)
|
||||||
(i18n/label :t/not-available)
|
(i18n/label :t/not-available)
|
||||||
(str total-amount " " token-symbol))
|
(str total-amount " " token-symbol))
|
||||||
:network (network-utils/id->network chain-id)
|
:network (network-utils/id->network chain-id)
|
||||||
:status (cond (and (= type :not-available)
|
:status status
|
||||||
loading-routes?
|
|
||||||
token-not-supported-in-receiver-networks?)
|
|
||||||
:loading
|
|
||||||
(= type :not-available)
|
|
||||||
:disabled
|
|
||||||
:else type)
|
|
||||||
:on-press #(when (not loading-routes?)
|
:on-press #(when (not loading-routes?)
|
||||||
(cond
|
(cond
|
||||||
(= type :edit)
|
(= network-value-type :edit)
|
||||||
(open-preferences)
|
(open-preferences)
|
||||||
on-press (on-press chain-id total-amount)))
|
on-press (on-press chain-id total-amount)))
|
||||||
:on-long-press #(when (not loading-routes?)
|
:on-long-press #(when (and (not loading-routes?) (not= status :disabled))
|
||||||
(cond
|
(cond
|
||||||
(= type :add)
|
(= network-value-type :add)
|
||||||
(open-preferences)
|
(open-preferences)
|
||||||
on-long-press (on-long-press chain-id)))}]])
|
on-long-press (on-long-press chain-id total-amount)))}]]))
|
||||||
network-values)])
|
network-values)])
|
||||||
|
|
||||||
(defn render-network-links
|
(defn render-network-links
|
||||||
@ -313,9 +337,9 @@
|
|||||||
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
:text (i18n/label :t/at-least-one-network-must-be-activated)}]))))
|
||||||
|
|
||||||
(defn view
|
(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
|
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)
|
(let [token-symbol (:symbol token)
|
||||||
nav-current-screen-id (rf/sub [:view-id])
|
nav-current-screen-id (rf/sub [:view-id])
|
||||||
active-screen? (= nav-current-screen-id current-screen-id)
|
active-screen? (= nav-current-screen-id current-screen-id)
|
||||||
@ -340,7 +364,7 @@
|
|||||||
(> (count token-available-networks-for-suggested-routes) 0)
|
(> (count token-available-networks-for-suggested-routes) 0)
|
||||||
(not lock-fetch-routes?))
|
(not lock-fetch-routes?))
|
||||||
(request-fetch-routes 2000)))
|
(request-fetch-routes 2000)))
|
||||||
[input-value valid-input?])
|
[send-amount-in-crypto valid-input?])
|
||||||
(rn/use-effect
|
(rn/use-effect
|
||||||
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
#(when (and active-screen? (> (count token-available-networks-for-suggested-routes) 0))
|
||||||
(request-fetch-routes 0))
|
(request-fetch-routes 0))
|
||||||
@ -363,11 +387,12 @@
|
|||||||
chain-id-to-disable
|
chain-id-to-disable
|
||||||
disabled-from-chain-ids
|
disabled-from-chain-ids
|
||||||
token-available-networks-for-suggested-routes))
|
token-available-networks-for-suggested-routes))
|
||||||
|
:on-long-press (fn [chain-id amount-calculated-for-chain]
|
||||||
:on-long-press (fn [chain-id]
|
|
||||||
(edit-amount
|
(edit-amount
|
||||||
{:chain-id chain-id
|
{:chain-id chain-id
|
||||||
:token-symbol token-symbol}))
|
:token-symbol token-symbol
|
||||||
|
:send-amount-in-crypto send-amount-in-crypto
|
||||||
|
:init-amount amount-calculated-for-chain}))
|
||||||
:receiver? false
|
:receiver? false
|
||||||
:theme theme
|
:theme theme
|
||||||
:loading-routes? loading-routes?
|
:loading-routes? loading-routes?
|
||||||
|
@ -2736,5 +2736,6 @@
|
|||||||
"dont-auto-recalculate-network": "Don't auto recalculate {{network}}",
|
"dont-auto-recalculate-network": "Don't auto recalculate {{network}}",
|
||||||
"import-keypair-to-use-account": "Import key pair to use this account",
|
"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.",
|
"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