[#12816] Better meesage on insufficient balance to cover fee

This commit is contained in:
Roman Volosovskyi 2022-02-04 17:34:35 +02:00
parent 82916de15c
commit 8f52b9b63c
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 39 additions and 26 deletions

View File

@ -2752,6 +2752,11 @@
(when-not (money/sufficient-funds? amount (get balance symbol))
{:amount-error (i18n/label :t/wallet-insufficient-funds)}))
(defn gas-required-exceeds-allowance? [gas-error-message]
(and gas-error-message (string/starts-with?
gas-error-message
"gas required exceeds allowance")))
(defn get-sufficient-gas-error
[gas-error-message balance symbol amount ^js gas ^js gasPrice]
(if (and gas gasPrice)
@ -2763,8 +2768,13 @@
(merge {:gas-error-state (when gas-error-message :gas-is-set)}
(when-not (money/sufficient-funds? fee (money/bignumber available-for-gas))
{:gas-error (i18n/label :t/wallet-insufficient-gas)})))
{:gas-error-state (when gas-error-message :gas-isnt-set)
:gas-error (or gas-error-message (i18n/label :t/invalid-number))}))
(let [insufficient-balance? (gas-required-exceeds-allowance? gas-error-message)]
{:gas-error-state (when gas-error-message :gas-isnt-set)
:insufficient-balalce? insufficient-balance?
:gas-error (if insufficient-balance?
(i18n/label :t/insufficient-balance-to-cover-fee)
(or gas-error-message
(i18n/label :t/invalid-number)))})))
(re-frame/reg-sub
:signing/amount-errors

View File

@ -350,7 +350,8 @@
(i18n/format-currency converted-value (:code wallet-currency))])
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]}]))))
(views/defview fee-item [prices wallet-currency fee-display-symbol fee gas-error gas-error-state prices-loading?]
(views/defview fee-item [prices wallet-currency fee-display-symbol fee
insufficient-balance? gas-error gas-error-state prices-loading?]
(views/letsubs [{:keys [gas-price-loading? gas-loading?]} [:signing/edit-fee]
show-error (reagent/atom false)]
(let [converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))]
@ -361,27 +362,28 @@
(i18n/label :t/network-fee))
:error (when (and (not (or gas-price-loading? gas-loading?)) gas-error @show-error)
gas-error)
:disabled (or gas-price-loading? gas-loading?)
:chevron true
:disabled (or insufficient-balance? gas-price-loading? gas-loading?)
:chevron (not insufficient-balance?)
:animated false
:accessory (if (or gas-price-loading? gas-loading?)
[react/small-loading-indicator]
(if (= :gas-isnt-set gas-error-state)
[react/text {:style {:color colors/blue}
:accessibility-label :custom-gas-fee}
(i18n/label :t/set-custom-fee)]
[react/view {:style {:flex-direction :row}
:accessibility-label :custom-gas-fee}
[react/nested-text {:style {:color colors/gray}}
[{:style {:color colors/black}} (utils/format-decimals fee 6)]
" "
fee-display-symbol
" • "]
(if prices-loading?
[react/small-loading-indicator]
[react/text {:style {:color colors/black}}
(i18n/format-currency converted-fee-value (:code wallet-currency))])
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]))
:accessory (when-not insufficient-balance?
(if (or gas-price-loading? gas-loading?)
[react/small-loading-indicator]
(if (= :gas-isnt-set gas-error-state)
[react/text {:style {:color colors/blue}
:accessibility-label :custom-gas-fee}
(i18n/label :t/set-custom-fee)]
[react/view {:style {:flex-direction :row}
:accessibility-label :custom-gas-fee}
[react/nested-text {:style {:color colors/gray}}
[{:style {:color colors/black}} (utils/format-decimals fee 6)]
" "
fee-display-symbol
" • "]
(if prices-loading?
[react/small-loading-indicator]
[react/text {:style {:color colors/black}}
(i18n/format-currency converted-fee-value (:code wallet-currency))])
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]])))
:on-press #(re-frame/dispatch
[:signing.ui/open-fee-sheet
{:content (fn []
@ -411,7 +413,7 @@
(views/letsubs [fee [:signing/fee]
sign [:signing/sign]
chain [:current-network]
{:keys [amount-error gas-error gas-error-state]}
{:keys [amount-error gas-error gas-error-state insufficient-balalce?]}
[:signing/amount-errors (:address from)]
keycard-multiaccount? [:keycard-multiaccount?]
prices [:prices]
@ -442,7 +444,7 @@
(when-not cancel?
[amount-item prices wallet-currency amount amount-error display-symbol fee-display-symbol prices-loading?])
[separator]
[fee-item prices wallet-currency fee-display-symbol fee gas-error gas-error-state prices-loading?]
[fee-item prices wallet-currency fee-display-symbol fee insufficient-balalce? gas-error gas-error-state prices-loading?]
(when (and management-enabled? (not keycard-multiaccount?))
[advanced-item])
(when (= :gas-is-set gas-error-state)

View File

@ -1730,5 +1730,6 @@
"safe-estimate": "Safe estimate",
"current-average": "Current average",
"current-base": "Current base",
"maximum-fee-desc": "Maximum overall price for the transaction. If the current block base fee exceeds this, your transaction will be included in a following block with a lower base fee."
"maximum-fee-desc": "Maximum overall price for the transaction. If the current block base fee exceeds this, your transaction will be included in a following block with a lower base fee.",
"insufficient-balance-to-cover-fee": "not enough balance to cover transaction fee"
}