diff --git a/src/status_im/signing/core.cljs b/src/status_im/signing/core.cljs index e8f06adea3..a27cb4f2a6 100644 --- a/src/status_im/signing/core.cljs +++ b/src/status_im/signing/core.cljs @@ -188,10 +188,14 @@ :dismiss-keyboard nil} #(when-not gas - {:signing/update-estimated-gas {:obj tx-obj - :success-event :signing/update-estimated-gas-success}}) + {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true) + :signing/update-estimated-gas {:obj tx-obj + :success-event :signing/update-estimated-gas-success + :error-event :signing/update-estimated-gas-error}}) #(when-not gasPrice - {:signing/update-gas-price {:success-event :signing/update-gas-price-success}}))))) + {:db (assoc-in (:db %) [:signing/edit-fee :gas-price-loading?] true) + :signing/update-gas-price {:success-event :signing/update-gas-price-success + :error-event :signing/update-gas-price-error}}))))) (fx/defn check-queue [{:keys [db] :as cofx}] (let [{:signing/keys [in-progress? queue]} db] diff --git a/src/status_im/signing/gas.cljs b/src/status_im/signing/gas.cljs index 28933d58db..226a81e794 100644 --- a/src/status_im/signing/gas.cljs +++ b/src/status_im/signing/gas.cljs @@ -16,6 +16,12 @@ (.lt (money/->wei :gwei value) min-gas-price-wei) :t/wallet-send-min-wei (-> (money/->wei :gwei value) .decimalPlaces pos?) :t/invalid-number)) +(defmethod get-error-label-key :gas [_ value] + (cond + (not value) :t/invalid-number + (.lt value (money/bignumber 1)) :t/invalid-number + (-> value .decimalPlaces pos?) :t/invalid-number)) + (defmethod get-error-label-key :default [_ value] (when (or (not value) (<= value 0)) @@ -58,12 +64,26 @@ (fx/defn update-estimated-gas-success {:events [:signing/update-estimated-gas-success]} [{db :db} gas] - {:db (assoc-in db [:signing/tx :gas] gas)}) + {:db (-> db + (assoc-in [:signing/tx :gas] gas) + (assoc-in [:signing/edit-fee :gas-loading?] false))}) (fx/defn update-gas-price-success {:events [:signing/update-gas-price-success]} [{db :db} price] - {:db (assoc-in db [:signing/tx :gasPrice] price)}) + {:db (-> db + (assoc-in [:signing/tx :gasPrice] price) + (assoc-in [:signing/edit-fee :gas-price-loading?] false))}) + +(fx/defn update-estimated-gas-error + {:events [:signing/update-estimated-gas-error]} + [{db :db}] + {:db (assoc-in db [:signing/edit-fee :gas-loading?] false)}) + +(fx/defn update-gas-price-error + {:events [:signing/update-gas-price-error]} + [{db :db}] + {:db (assoc-in db [:signing/edit-fee :gas-price-loading?] false)}) (fx/defn open-fee-sheet {:events [:signing.ui/open-fee-sheet]} @@ -86,15 +106,17 @@ (re-frame/reg-fx :signing/update-gas-price - (fn [{:keys [success-event edit?]}] + (fn [{:keys [success-event error-event]}] (json-rpc/call {:method "eth_gasPrice" - :on-success #(re-frame/dispatch [success-event % edit?])}))) + :on-success #(re-frame/dispatch [success-event %]) + :on-error #(re-frame/dispatch [error-event %])}))) (re-frame/reg-fx :signing/update-estimated-gas - (fn [{:keys [obj success-event]}] + (fn [{:keys [obj success-event error-event]}] (json-rpc/call {:method "eth_estimateGas" :params [obj] - :on-success #(re-frame/dispatch [success-event %])}))) \ No newline at end of file + :on-success #(re-frame/dispatch [success-event %]) + :on-error #(re-frame/dispatch [error-event %])}))) \ No newline at end of file diff --git a/src/status_im/ui/screens/signing/sheets.cljs b/src/status_im/ui/screens/signing/sheets.cljs index dd5d246dcb..fb31666c79 100644 --- a/src/status_im/ui/screens/signing/sheets.cljs +++ b/src/status_im/ui/screens/signing/sheets.cljs @@ -21,7 +21,7 @@ :default-value (:value gas-edit) :keyboard-type :numeric :auto-capitalize :none - :placeholder "0.000" + :placeholder "0" :auto-focus false}]] [react/view {:flex 1 :margin-left 33} [text-input/text-input-with-label diff --git a/src/status_im/ui/screens/signing/views.cljs b/src/status_im/ui/screens/signing/views.cljs index 3f49b88767..46b74ec8a2 100644 --- a/src/status_im/ui/screens/signing/views.cljs +++ b/src/status_im/ui/screens/signing/views.cljs @@ -221,30 +221,35 @@ " " (str (:code wallet-currency))]]}])) -(defn fee-item [prices wallet-currency fee-display-symbol fee gas-error] - (let [converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))] - [list-item/list-item - {:type :small - :title :t/network-fee - :error gas-error - :accessories [[react/nested-text {:style {:color colors/gray}} - [{:style {:color colors/black}} (utils/format-decimals fee 6)] - " " - fee-display-symbol - " • " - [{:style {:color colors/black}} - (if converted-fee-value - (i18n/format-currency converted-fee-value (:code wallet-currency)) - [react/activity-indicator {:color :colors/gray - :ios {:size :small} - :android {:size :16}}])] - " " - (str (:code wallet-currency))] - :chevron] - :on-press #(re-frame/dispatch - [:signing.ui/open-fee-sheet - {:content (fn [] [sheets/fee-bottom-sheet fee-display-symbol]) - :content-height 270}])}])) +(defn loading-indicator [] + [react/activity-indicator {:color :colors/gray + :ios {:size :small} + :android {:size :16}}]) + +(views/defview fee-item [prices wallet-currency fee-display-symbol fee gas-error] + (views/letsubs [{:keys [gas-price-loading? gas-loading?]} [:signing/edit-fee]] + (let [converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))] + [list-item/list-item + {:type :small + :title :t/network-fee + :error (when-not (or gas-price-loading? gas-loading?) gas-error) + :disabled? (or gas-price-loading? gas-loading?) + :accessories (if (or gas-price-loading? gas-loading?) + [[loading-indicator]] + [[react/nested-text {:style {:color colors/gray}} + [{:style {:color colors/black}} (utils/format-decimals fee 6)] + " " + fee-display-symbol + " • " + [{:style {:color colors/black}} + (i18n/format-currency converted-fee-value (:code wallet-currency))] + " " + (str (:code wallet-currency))] + :chevron]) + :on-press #(re-frame/dispatch + [:signing.ui/open-fee-sheet + {:content (fn [] [sheets/fee-bottom-sheet fee-display-symbol]) + :content-height 270}])}]))) (views/defview network-item [] (views/letsubs [network-name [:network-name]]