[#4492]: Invalid values for `gas limit` and `gas price` are immediately replaced by default ones instead of warning

This commit is contained in:
Aleksandr Pantiukhov 2018-05-29 13:54:48 +02:00 committed by Roman Volosovskyi
parent 1e4311d4cb
commit 7eba090b16
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
4 changed files with 51 additions and 33 deletions

View File

@ -374,6 +374,7 @@
;;validation ;;validation
:invalid-phone "Invalid phone number" :invalid-phone "Invalid phone number"
:amount "Amount" :amount "Amount"
:invalid-number "Invalid number"
;;transactions ;;transactions
:confirm "Confirm" :confirm "Confirm"

View File

@ -327,14 +327,14 @@
{:db (assoc-in db [:wallet :send-transaction :signing?] signing?)})) {:db (assoc-in db [:wallet :send-transaction :signing?] signing?)}))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/edit-gas :wallet.send/edit-value
(fn [{:keys [db]} [_ gas]] (fn [{:keys [db]} [_ key value]]
{:db (assoc-in db [:wallet :edit :gas] (money/bignumber gas))})) (let [bn-value (money/bignumber value)
data (if bn-value
(handlers/register-handler-fx {:value bn-value
:wallet.send/edit-gas-price :invalid? false}
(fn [{:keys [db]} [_ gas-price]] {:invalid? true})]
{:db (assoc-in db [:wallet :edit :gas-price] (money/bignumber gas-price))})) {:db (update-in db [:wallet :edit key] merge data)})))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-gas-details :wallet.send/set-gas-details
@ -352,9 +352,7 @@
:wallet.send/reset-gas-default :wallet.send/reset-gas-default
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:dispatch [:wallet/update-gas-price true] {:dispatch [:wallet/update-gas-price true]
:db (update-in db [:wallet :edit] :db (assoc-in db [:wallet :edit :gas] nil)}))
assoc
:gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))}))
(defn update-gas-price [db edit?] (defn update-gas-price [db edit?]
{:update-gas-price {:web3 (:web3 db) {:update-gas-price {:web3 (:web3 db)

View File

@ -74,6 +74,10 @@
{:margin-top 24 {:margin-top 24
:margin-bottom 16}) :margin-bottom 16})
(def gas-container-wrapper
{:flex 1
:flex-direction :row})
(def gas-input-wrapper (def gas-input-wrapper
{:align-items :center {:align-items :center
:justify-content :space-between :justify-content :space-between

View File

@ -24,7 +24,8 @@
[status-im.utils.utils :as utils] [status-im.utils.utils :as utils]
[status-im.transport.utils :as transport.utils] [status-im.transport.utils :as transport.utils]
[status-im.utils.ethereum.tokens :as tokens] [status-im.utils.ethereum.tokens :as tokens]
[status-im.utils.ethereum.core :as ethereum])) [status-im.utils.ethereum.core :as ethereum]
[clojure.string :as string]))
(defn sign-later-popup (defn sign-later-popup
[from-chat?] [from-chat?]
@ -117,31 +118,41 @@
(defview transaction-fee [] (defview transaction-fee []
(letsubs [{:keys [amount symbol] :as transaction} [:wallet.send/transaction] (letsubs [{:keys [amount symbol] :as transaction} [:wallet.send/transaction]
network [:get-current-account-network] network [:get-current-account-network]
edit [:wallet/edit]] {gas-edit :gas
(let [gas (or (:gas edit) (:gas transaction)) gas-price-edit :gas-price} [:wallet/edit]]
gas-price (or (:gas-price edit) (:gas-price transaction)) (let [gas (or (:value gas-edit) (:gas transaction))
gas-price (or (:value gas-price-edit) (:gas-price transaction))
{:keys [decimals]} (tokens/asset-for (ethereum/network->chain-keyword network) symbol)] {:keys [decimals]} (tokens/asset-for (ethereum/network->chain-keyword network) symbol)]
[wallet.components/simple-screen {:status-toolbar-type :modal-wallet} [wallet.components/simple-screen {:status-toolbar-type :modal-wallet}
[toolbar true act/close-white [toolbar true act/close-white
(i18n/label :t/wallet-transaction-fee)] (i18n/label :t/wallet-transaction-fee)]
[react/view components.styles/flex [react/view components.styles/flex
[react/view {:flex-direction :row} [react/view {:flex-direction :row}
[wallet.components/cartouche {}
(i18n/label :t/gas-limit) [react/view styles/gas-container-wrapper
[react/view styles/gas-input-wrapper [wallet.components/cartouche {}
[react/text-input (merge styles/transaction-fee-input (i18n/label :t/gas-limit)
{:on-change-text #(re-frame/dispatch [:wallet.send/edit-gas %]) [react/view styles/gas-input-wrapper
:default-value (str (money/to-fixed gas)) [react/text-input (merge styles/transaction-fee-input
:accessibility-label :gas-limit-input})]]] {:on-change-text #(re-frame/dispatch [:wallet.send/edit-value :gas %])
[wallet.components/cartouche {} :default-value (str (money/to-fixed gas))
(i18n/label :t/gas-price) :accessibility-label :gas-limit-input})]]]
[react/view styles/gas-input-wrapper (when (:invalid? gas-edit)
[react/text-input (merge styles/transaction-fee-input [tooltip/tooltip (i18n/label :t/invalid-number)])]
{:on-change-text #(re-frame/dispatch [:wallet.send/edit-gas-price (money/->wei :gwei %)])
:default-value (str (money/to-fixed (money/wei-> :gwei gas-price))) [react/view styles/gas-container-wrapper
:accessibility-label :gas-price-input})] [wallet.components/cartouche {}
[wallet.components/cartouche-secondary-text (i18n/label :t/gas-price)
(i18n/label :t/gwei)]]]] [react/view styles/gas-input-wrapper
[react/text-input (merge styles/transaction-fee-input
{:on-change-text #(re-frame/dispatch [:wallet.send/edit-value :gas-price (money/->wei :gwei %)])
:default-value (str (money/to-fixed (money/wei-> :gwei gas-price)))
:accessibility-label :gas-price-input})]
[wallet.components/cartouche-secondary-text
(i18n/label :t/gwei)]]]
(when (:invalid? gas-price-edit)
[tooltip/tooltip (i18n/label :t/invalid-number)])]]
[react/view styles/transaction-fee-info [react/view styles/transaction-fee-info
[react/view styles/transaction-fee-info-icon [react/view styles/transaction-fee-info-icon
[react/text {:style styles/transaction-fee-info-icon-text} "?"]] [react/text {:style styles/transaction-fee-info-icon-text} "?"]]
@ -162,12 +173,16 @@
[wallet.components/cartouche-text-content [wallet.components/cartouche-text-content
(str (money/to-fixed (max-fee gas gas-price))) (str (money/to-fixed (max-fee gas gas-price)))
(i18n/label :t/eth)]]]] (i18n/label :t/eth)]]]]
[bottom-buttons/bottom-buttons styles/fee-buttons [bottom-buttons/bottom-buttons styles/fee-buttons
[button/button {:on-press #(re-frame/dispatch [:wallet.send/reset-gas-default]) [button/button {:on-press #(re-frame/dispatch [:wallet.send/reset-gas-default])
:accessibility-label :reset-to-default-button} :accessibility-label :reset-to-default-button}
(i18n/label :t/reset-default)] (i18n/label :t/reset-default)]
[button/button {:on-press #(do (re-frame/dispatch [:wallet.send/set-gas-details gas gas-price]) (act/default-handler)) [button/button {:on-press #(do (re-frame/dispatch [:wallet.send/set-gas-details gas gas-price])
:accessibility-label :done-button} (act/default-handler))
:accessibility-label :done-button
:disabled? (or (:invalid? gas-edit)
(:invalid? gas-price-edit))}
(i18n/label :t/done)]]]]))) (i18n/label :t/done)]]]])))
(defn- advanced-cartouche [{:keys [gas gas-price]} modal?] (defn- advanced-cartouche [{:keys [gas gas-price]} modal?]