* change functionality * fix handle-swap * fix lint issues * update tests * change error to error? * change reset-input-error * update tests * fix lint issues
This commit is contained in:
parent
ee1f93defb
commit
521f39b6fb
|
@ -49,8 +49,12 @@
|
||||||
:height "100%")))
|
:height "100%")))
|
||||||
|
|
||||||
(defn text-input
|
(defn text-input
|
||||||
[theme]
|
[theme error?]
|
||||||
(assoc text-input-dimensions :color (colors/theme-colors colors/neutral-100 colors/white theme)))
|
(assoc text-input-dimensions
|
||||||
|
:color
|
||||||
|
(if error?
|
||||||
|
(colors/resolve-color :danger theme)
|
||||||
|
(colors/theme-colors colors/neutral-100 colors/white theme))))
|
||||||
|
|
||||||
(defn placeholder-text
|
(defn placeholder-text
|
||||||
[theme]
|
[theme]
|
||||||
|
|
|
@ -32,9 +32,12 @@
|
||||||
(crypto-format num-value conversion crypto-decimals token))))
|
(crypto-format num-value conversion crypto-decimals token))))
|
||||||
|
|
||||||
(defn- data-info
|
(defn- data-info
|
||||||
[{:keys [theme token crypto-decimals conversion networks title crypto? currency amount]}]
|
[{:keys [theme token crypto-decimals conversion networks title crypto? currency amount error?]}]
|
||||||
[rn/view {:style style/data-container}
|
[rn/view {:style style/data-container}
|
||||||
[network-tag/view {:networks networks :title title}]
|
[network-tag/view
|
||||||
|
{:networks networks
|
||||||
|
:title title
|
||||||
|
:status (when error? :error)}]
|
||||||
[text/text
|
[text/text
|
||||||
{:size :paragraph-2
|
{:size :paragraph-2
|
||||||
:weight :medium
|
:weight :medium
|
||||||
|
@ -80,7 +83,7 @@
|
||||||
(reset! value-atom v))
|
(reset! value-atom v))
|
||||||
(when on-change-text
|
(when on-change-text
|
||||||
(on-change-text v)))]
|
(on-change-text v)))]
|
||||||
(fn [{:keys [theme token customization-color show-keyboard? crypto? currency value]
|
(fn [{:keys [theme token customization-color show-keyboard? crypto? currency value error?]
|
||||||
:or {show-keyboard? true}}]
|
:or {show-keyboard? true}}]
|
||||||
[rn/pressable
|
[rn/pressable
|
||||||
{:on-press focus-input
|
{:on-press focus-input
|
||||||
|
@ -90,7 +93,7 @@
|
||||||
:size :size-32}]
|
:size :size-32}]
|
||||||
[rn/view {:style style/text-input-container}
|
[rn/view {:style style/text-input-container}
|
||||||
[rn/text-input
|
[rn/text-input
|
||||||
(cond-> {:style (style/text-input theme)
|
(cond-> {:style (style/text-input theme error?)
|
||||||
:placeholder-text-color (style/placeholder-text theme)
|
:placeholder-text-color (style/placeholder-text theme)
|
||||||
:auto-focus true
|
:auto-focus true
|
||||||
:ref set-ref
|
:ref set-ref
|
||||||
|
|
|
@ -21,7 +21,9 @@
|
||||||
{:key :currency
|
{:key :currency
|
||||||
:type :select
|
:type :select
|
||||||
:options [{:key :usd}
|
:options [{:key :usd}
|
||||||
{:key :eur}]}])
|
{:key :eur}]}
|
||||||
|
{:key :error?
|
||||||
|
:type :boolean}])
|
||||||
|
|
||||||
(defn view
|
(defn view
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -57,6 +57,7 @@
|
||||||
(h/is-truthy (h/get-by-text "0"))
|
(h/is-truthy (h/get-by-text "0"))
|
||||||
(h/is-truthy (h/get-by-text "ETH"))
|
(h/is-truthy (h/get-by-text "ETH"))
|
||||||
(h/is-truthy (h/get-by-text "$0.00"))
|
(h/is-truthy (h/get-by-text "$0.00"))
|
||||||
|
(h/is-truthy (h/get-by-label-text :container))
|
||||||
(h/is-disabled (h/get-by-label-text :button-one)))
|
(h/is-disabled (h/get-by-label-text :button-one)))
|
||||||
|
|
||||||
(h/test "Fill token input and confirm"
|
(h/test "Fill token input and confirm"
|
||||||
|
@ -77,6 +78,7 @@
|
||||||
(-> (h/wait-for #(h/get-by-text "$1234.50"))
|
(-> (h/wait-for #(h/get-by-text "$1234.50"))
|
||||||
(.then (fn []
|
(.then (fn []
|
||||||
(h/is-truthy (h/get-by-label-text :button-one))
|
(h/is-truthy (h/get-by-label-text :button-one))
|
||||||
|
(h/is-truthy (h/get-by-label-text :container))
|
||||||
(h/fire-event :press (h/get-by-label-text :button-one))
|
(h/fire-event :press (h/get-by-label-text :button-one))
|
||||||
(h/was-called on-confirm))))))
|
(h/was-called on-confirm))))))
|
||||||
|
|
||||||
|
@ -99,61 +101,33 @@
|
||||||
(-> (h/wait-for #(h/get-by-text "$1234.50"))
|
(-> (h/wait-for #(h/get-by-text "$1234.50"))
|
||||||
(.then (fn []
|
(.then (fn []
|
||||||
(h/is-truthy (h/get-by-label-text :button-one))
|
(h/is-truthy (h/get-by-label-text :button-one))
|
||||||
|
(h/is-truthy (h/get-by-label-text :container))
|
||||||
(h/fire-event :press (h/get-by-label-text :button-one))
|
(h/fire-event :press (h/get-by-label-text :button-one))
|
||||||
(h/was-called on-confirm))))))
|
(h/was-called on-confirm))))))
|
||||||
|
|
||||||
(h/test "Try to fill more than limit"
|
(h/test "Try to fill more than limit"
|
||||||
(h/setup-subs sub-mocks)
|
(h/setup-subs sub-mocks)
|
||||||
(h/render [input-amount/view
|
(h/render [input-amount/view
|
||||||
{:crypto-decimals 10
|
{:crypto-decimals 1
|
||||||
:limit-crypto 286}])
|
:limit-crypto 1}])
|
||||||
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-2))
|
(h/fire-event :press (h/query-by-label-text :keyboard-key-2))
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-9))
|
(h/fire-event :press (h/query-by-label-text :keyboard-key-9))
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
||||||
|
|
||||||
(-> (h/wait-for #(h/is-truthy (h/get-by-text "$290.00")))
|
(h/is-truthy (h/get-by-label-text :container-error)))
|
||||||
(.then (fn []
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-backspace))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-8))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
|
||||||
(h/wait-for #(h/get-by-text "$2850.00"))))))
|
|
||||||
|
|
||||||
(h/test "Try to fill more than limit"
|
|
||||||
(h/setup-subs sub-mocks)
|
|
||||||
(h/render [input-amount/view
|
|
||||||
{:crypto-decimals 10
|
|
||||||
:limit-crypto 286
|
|
||||||
:on-confirm #()}])
|
|
||||||
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-2))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-9))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
|
||||||
|
|
||||||
(-> (h/wait-for #(h/get-by-text "$290.00"))
|
|
||||||
(.then (fn []
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-backspace))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-8))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
|
||||||
(h/wait-for #(h/get-by-text "$2850.00"))))))
|
|
||||||
|
|
||||||
(h/test "Switch from crypto to fiat and check limit"
|
(h/test "Switch from crypto to fiat and check limit"
|
||||||
(h/setup-subs sub-mocks)
|
(h/setup-subs sub-mocks)
|
||||||
(h/render [input-amount/view
|
(h/render [input-amount/view
|
||||||
{:crypto-decimals 2
|
{:crypto-decimals 1
|
||||||
:limit-crypto 250
|
:limit-crypto 1
|
||||||
:on-confirm #()}])
|
:on-confirm #()}])
|
||||||
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-2))
|
(h/fire-event :press (h/query-by-label-text :keyboard-key-9))
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-0))
|
(h/is-truthy (h/get-by-label-text :container-error))
|
||||||
(-> (h/wait-for #(h/get-by-text "$200.00"))
|
(h/fire-event :press (h/query-by-label-text :reorder))
|
||||||
|
|
||||||
|
(-> (h/wait-for #(h/get-by-text "Max: 1000.00 USD"))
|
||||||
(.then (fn []
|
(.then (fn []
|
||||||
(h/fire-event :press (h/query-by-label-text :reorder))
|
(h/wait-for #(h/is-truthy (h/get-by-label-text :container))))))))
|
||||||
(h/wait-for #(h/get-by-text "2.00 ETH"))))
|
|
||||||
(.then (fn []
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
|
||||||
(h/wait-for #(h/get-by-text "20.50 ETH"))))
|
|
||||||
(.then (fn []
|
|
||||||
(h/fire-event :press (h/query-by-label-text :keyboard-key-5))
|
|
||||||
(h/wait-for #(h/get-by-text "20.50 ETH")))))))
|
|
||||||
|
|
|
@ -61,6 +61,11 @@
|
||||||
(>= (js/parseFloat balance) input-value)))
|
(>= (js/parseFloat balance) input-value)))
|
||||||
(map first)))
|
(map first)))
|
||||||
|
|
||||||
|
(defn- reset-input-error
|
||||||
|
[new-value prev-value input-error]
|
||||||
|
(reset! input-error
|
||||||
|
(> new-value prev-value)))
|
||||||
|
|
||||||
(defn- f-view-internal
|
(defn- f-view-internal
|
||||||
;; crypto-decimals and limit-crypto args are needed for component tests only
|
;; crypto-decimals and limit-crypto args are needed for component tests only
|
||||||
[{:keys [crypto-decimals limit-crypto]}]
|
[{:keys [crypto-decimals limit-crypto]}]
|
||||||
|
@ -75,6 +80,7 @@
|
||||||
limit-fiat (.toFixed (* (:total-balance token) conversion-rate) 2)
|
limit-fiat (.toFixed (* (:total-balance token) conversion-rate) 2)
|
||||||
crypto-decimals (or crypto-decimals (utils/get-crypto-decimals-count token))
|
crypto-decimals (or crypto-decimals (utils/get-crypto-decimals-count token))
|
||||||
input-value (reagent/atom "")
|
input-value (reagent/atom "")
|
||||||
|
input-error (reagent/atom false)
|
||||||
current-limit (reagent/atom {:amount limit-crypto
|
current-limit (reagent/atom {:amount limit-crypto
|
||||||
:currency token-symbol})
|
:currency token-symbol})
|
||||||
handle-swap (fn [crypto?]
|
handle-swap (fn [crypto?]
|
||||||
|
@ -84,27 +90,30 @@
|
||||||
:currency token-symbol}
|
:currency token-symbol}
|
||||||
{:amount limit-fiat
|
{:amount limit-fiat
|
||||||
:currency currency}))
|
:currency currency}))
|
||||||
(when (> num-value (:amount @current-limit))
|
(reset-input-error num-value
|
||||||
(reset! input-value ""))))
|
(:amount @current-limit)
|
||||||
|
input-error)))
|
||||||
handle-keyboard-press (fn [v]
|
handle-keyboard-press (fn [v]
|
||||||
(let [current-value @input-value
|
(let [current-value @input-value
|
||||||
new-value (make-new-input current-value v)
|
new-value (make-new-input current-value v)
|
||||||
num-value (or (parse-double new-value) 0)]
|
num-value (or (parse-double new-value) 0)
|
||||||
(when (and (not loading-suggested-routes?)
|
current-limit-amount (:amount @current-limit)]
|
||||||
(<= num-value (:amount @current-limit)))
|
(when (not loading-suggested-routes?)
|
||||||
(reset! input-value new-value)
|
(reset! input-value new-value)
|
||||||
|
(reset-input-error num-value current-limit-amount input-error)
|
||||||
(reagent/flush))))
|
(reagent/flush))))
|
||||||
handle-delete (fn [_]
|
handle-delete (fn [_]
|
||||||
(when-not loading-suggested-routes?
|
(when-not loading-suggested-routes?
|
||||||
(swap! input-value #(subs % 0 (dec (count %))))
|
(let [current-limit-amount (:amount @current-limit)]
|
||||||
(reagent/flush)))
|
(swap! input-value #(subs % 0 (dec (count %))))
|
||||||
|
(reset-input-error @input-value current-limit-amount input-error)
|
||||||
|
(reagent/flush))))
|
||||||
handle-on-change (fn [v]
|
handle-on-change (fn [v]
|
||||||
(when (valid-input? @input-value v)
|
(when (valid-input? @input-value v)
|
||||||
(let [num-value (or (parse-double v) 0)
|
(let [num-value (or (parse-double v) 0)
|
||||||
current-limit-amount (:amount @current-limit)]
|
current-limit-amount (:amount @current-limit)]
|
||||||
(if (> num-value current-limit-amount)
|
(reset! input-value v)
|
||||||
(reset! input-value (str current-limit-amount))
|
(reset-input-error num-value current-limit-amount input-error)
|
||||||
(reset! input-value v))
|
|
||||||
(reagent/flush))))]
|
(reagent/flush))))]
|
||||||
(fn [{:keys [on-confirm]
|
(fn [{:keys [on-confirm]
|
||||||
:or {on-confirm #(rf/dispatch [:wallet/send-select-amount
|
:or {on-confirm #(rf/dispatch [:wallet/send-select-amount
|
||||||
|
@ -135,7 +144,8 @@
|
||||||
100)))
|
100)))
|
||||||
[@input-value])
|
[@input-value])
|
||||||
[rn/view
|
[rn/view
|
||||||
{:style style/screen}
|
{:style style/screen
|
||||||
|
:accessibility-label (str "container" (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-within-stack :wallet-send-input-amount])
|
:on-press #(rf/dispatch [:navigate-back-within-stack :wallet-send-input-amount])
|
||||||
|
@ -145,6 +155,7 @@
|
||||||
:token token-symbol
|
:token token-symbol
|
||||||
:currency currency
|
:currency currency
|
||||||
:crypto-decimals crypto-decimals
|
:crypto-decimals crypto-decimals
|
||||||
|
:error? @input-error
|
||||||
:networks (:networks token)
|
:networks (:networks token)
|
||||||
:title (i18n/label :t/send-limit {:limit limit-label})
|
:title (i18n/label :t/send-limit {:limit limit-label})
|
||||||
:conversion conversion-rate
|
:conversion conversion-rate
|
||||||
|
|
Loading…
Reference in New Issue