[#9709] Empty gas when transacting leads to bug

Signed-off-by: Churikova Tetiana <churikova.tm@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2019-12-27 12:22:09 +01:00 committed by Churikova Tetiana
parent d8db958319
commit b98578ef9d
No known key found for this signature in database
GPG Key ID: 0D4EA7B33B47E6D8
4 changed files with 65 additions and 34 deletions

View File

@ -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]

View File

@ -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 %])})))
:on-success #(re-frame/dispatch [success-event %])
:on-error #(re-frame/dispatch [error-event %])})))

View File

@ -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

View File

@ -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]]