[#12816] Better meesage on insufficient balance to cover fee
This commit is contained in:
parent
82916de15c
commit
8f52b9b63c
|
@ -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)})))
|
||||
(let [insufficient-balance? (gas-required-exceeds-allowance? gas-error-message)]
|
||||
{:gas-error-state (when gas-error-message :gas-isnt-set)
|
||||
:gas-error (or gas-error-message (i18n/label :t/invalid-number))}))
|
||||
: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
|
||||
|
|
|
@ -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,10 +362,11 @@
|
|||
(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?)
|
||||
: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}
|
||||
|
@ -381,7 +383,7 @@
|
|||
[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))]]))
|
||||
[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)
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue