[#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))
|
(when-not (money/sufficient-funds? amount (get balance symbol))
|
||||||
{:amount-error (i18n/label :t/wallet-insufficient-funds)}))
|
{: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
|
(defn get-sufficient-gas-error
|
||||||
[gas-error-message balance symbol amount ^js gas ^js gasPrice]
|
[gas-error-message balance symbol amount ^js gas ^js gasPrice]
|
||||||
(if (and gas gasPrice)
|
(if (and gas gasPrice)
|
||||||
|
@ -2763,8 +2768,13 @@
|
||||||
(merge {:gas-error-state (when gas-error-message :gas-is-set)}
|
(merge {:gas-error-state (when gas-error-message :gas-is-set)}
|
||||||
(when-not (money/sufficient-funds? fee (money/bignumber available-for-gas))
|
(when-not (money/sufficient-funds? fee (money/bignumber available-for-gas))
|
||||||
{:gas-error (i18n/label :t/wallet-insufficient-gas)})))
|
{:gas-error (i18n/label :t/wallet-insufficient-gas)})))
|
||||||
{:gas-error-state (when gas-error-message :gas-isnt-set)
|
(let [insufficient-balance? (gas-required-exceeds-allowance? gas-error-message)]
|
||||||
:gas-error (or gas-error-message (i18n/label :t/invalid-number))}))
|
{: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
|
(re-frame/reg-sub
|
||||||
:signing/amount-errors
|
:signing/amount-errors
|
||||||
|
|
|
@ -350,7 +350,8 @@
|
||||||
(i18n/format-currency converted-value (:code wallet-currency))])
|
(i18n/format-currency converted-value (:code wallet-currency))])
|
||||||
[react/text {:style {:color colors/gray}} (str " " (: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]
|
(views/letsubs [{:keys [gas-price-loading? gas-loading?]} [:signing/edit-fee]
|
||||||
show-error (reagent/atom false)]
|
show-error (reagent/atom false)]
|
||||||
(let [converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))]
|
(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))
|
(i18n/label :t/network-fee))
|
||||||
:error (when (and (not (or gas-price-loading? gas-loading?)) gas-error @show-error)
|
:error (when (and (not (or gas-price-loading? gas-loading?)) gas-error @show-error)
|
||||||
gas-error)
|
gas-error)
|
||||||
:disabled (or gas-price-loading? gas-loading?)
|
:disabled (or insufficient-balance? gas-price-loading? gas-loading?)
|
||||||
:chevron true
|
:chevron (not insufficient-balance?)
|
||||||
:animated false
|
:animated false
|
||||||
:accessory (if (or gas-price-loading? gas-loading?)
|
:accessory (when-not insufficient-balance?
|
||||||
[react/small-loading-indicator]
|
(if (or gas-price-loading? gas-loading?)
|
||||||
(if (= :gas-isnt-set gas-error-state)
|
[react/small-loading-indicator]
|
||||||
[react/text {:style {:color colors/blue}
|
(if (= :gas-isnt-set gas-error-state)
|
||||||
:accessibility-label :custom-gas-fee}
|
[react/text {:style {:color colors/blue}
|
||||||
(i18n/label :t/set-custom-fee)]
|
:accessibility-label :custom-gas-fee}
|
||||||
[react/view {:style {:flex-direction :row}
|
(i18n/label :t/set-custom-fee)]
|
||||||
:accessibility-label :custom-gas-fee}
|
[react/view {:style {:flex-direction :row}
|
||||||
[react/nested-text {:style {:color colors/gray}}
|
:accessibility-label :custom-gas-fee}
|
||||||
[{:style {:color colors/black}} (utils/format-decimals fee 6)]
|
[react/nested-text {:style {:color colors/gray}}
|
||||||
" "
|
[{:style {:color colors/black}} (utils/format-decimals fee 6)]
|
||||||
fee-display-symbol
|
" "
|
||||||
" • "]
|
fee-display-symbol
|
||||||
(if prices-loading?
|
" • "]
|
||||||
[react/small-loading-indicator]
|
(if prices-loading?
|
||||||
[react/text {:style {:color colors/black}}
|
[react/small-loading-indicator]
|
||||||
(i18n/format-currency converted-fee-value (:code wallet-currency))])
|
[react/text {:style {:color colors/black}}
|
||||||
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]]))
|
(i18n/format-currency converted-fee-value (:code wallet-currency))])
|
||||||
|
[react/text {:style {:color colors/gray}} (str " " (:code wallet-currency))]])))
|
||||||
:on-press #(re-frame/dispatch
|
:on-press #(re-frame/dispatch
|
||||||
[:signing.ui/open-fee-sheet
|
[:signing.ui/open-fee-sheet
|
||||||
{:content (fn []
|
{:content (fn []
|
||||||
|
@ -411,7 +413,7 @@
|
||||||
(views/letsubs [fee [:signing/fee]
|
(views/letsubs [fee [:signing/fee]
|
||||||
sign [:signing/sign]
|
sign [:signing/sign]
|
||||||
chain [:current-network]
|
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)]
|
[:signing/amount-errors (:address from)]
|
||||||
keycard-multiaccount? [:keycard-multiaccount?]
|
keycard-multiaccount? [:keycard-multiaccount?]
|
||||||
prices [:prices]
|
prices [:prices]
|
||||||
|
@ -442,7 +444,7 @@
|
||||||
(when-not cancel?
|
(when-not cancel?
|
||||||
[amount-item prices wallet-currency amount amount-error display-symbol fee-display-symbol prices-loading?])
|
[amount-item prices wallet-currency amount amount-error display-symbol fee-display-symbol prices-loading?])
|
||||||
[separator]
|
[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?))
|
(when (and management-enabled? (not keycard-multiaccount?))
|
||||||
[advanced-item])
|
[advanced-item])
|
||||||
(when (= :gas-is-set gas-error-state)
|
(when (= :gas-is-set gas-error-state)
|
||||||
|
|
|
@ -1730,5 +1730,6 @@
|
||||||
"safe-estimate": "Safe estimate",
|
"safe-estimate": "Safe estimate",
|
||||||
"current-average": "Current average",
|
"current-average": "Current average",
|
||||||
"current-base": "Current base",
|
"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