diff --git a/src/status_im/subs.cljs b/src/status_im/subs.cljs index c6ba91547e..c74d9267a7 100644 --- a/src/status_im/subs.cljs +++ b/src/status_im/subs.cljs @@ -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 diff --git a/src/status_im/ui/screens/signing/views.cljs b/src/status_im/ui/screens/signing/views.cljs index 1b1ddf1eb4..36615722cb 100644 --- a/src/status_im/ui/screens/signing/views.cljs +++ b/src/status_im/ui/screens/signing/views.cljs @@ -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) diff --git a/translations/en.json b/translations/en.json index 730b850339..84750ded89 100644 --- a/translations/en.json +++ b/translations/en.json @@ -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" }