[#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 :dismiss-keyboard
nil} nil}
#(when-not gas #(when-not gas
{:signing/update-estimated-gas {:obj tx-obj {:db (assoc-in (:db %) [:signing/edit-fee :gas-loading?] true)
:success-event :signing/update-estimated-gas-success}}) :signing/update-estimated-gas {:obj tx-obj
:success-event :signing/update-estimated-gas-success
:error-event :signing/update-estimated-gas-error}})
#(when-not gasPrice #(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}] (fx/defn check-queue [{:keys [db] :as cofx}]
(let [{:signing/keys [in-progress? queue]} db] (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 (.lt (money/->wei :gwei value) min-gas-price-wei) :t/wallet-send-min-wei
(-> (money/->wei :gwei value) .decimalPlaces pos?) :t/invalid-number)) (-> (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] (defmethod get-error-label-key :default [_ value]
(when (or (not value) (when (or (not value)
(<= value 0)) (<= value 0))
@ -58,12 +64,26 @@
(fx/defn update-estimated-gas-success (fx/defn update-estimated-gas-success
{:events [:signing/update-estimated-gas-success]} {:events [:signing/update-estimated-gas-success]}
[{db :db} gas] [{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 (fx/defn update-gas-price-success
{:events [:signing/update-gas-price-success]} {:events [:signing/update-gas-price-success]}
[{db :db} price] [{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 (fx/defn open-fee-sheet
{:events [:signing.ui/open-fee-sheet]} {:events [:signing.ui/open-fee-sheet]}
@ -86,15 +106,17 @@
(re-frame/reg-fx (re-frame/reg-fx
:signing/update-gas-price :signing/update-gas-price
(fn [{:keys [success-event edit?]}] (fn [{:keys [success-event error-event]}]
(json-rpc/call (json-rpc/call
{:method "eth_gasPrice" {: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 (re-frame/reg-fx
:signing/update-estimated-gas :signing/update-estimated-gas
(fn [{:keys [obj success-event]}] (fn [{:keys [obj success-event error-event]}]
(json-rpc/call (json-rpc/call
{:method "eth_estimateGas" {:method "eth_estimateGas"
:params [obj] :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) :default-value (:value gas-edit)
:keyboard-type :numeric :keyboard-type :numeric
:auto-capitalize :none :auto-capitalize :none
:placeholder "0.000" :placeholder "0"
:auto-focus false}]] :auto-focus false}]]
[react/view {:flex 1 :margin-left 33} [react/view {:flex 1 :margin-left 33}
[text-input/text-input-with-label [text-input/text-input-with-label

View File

@ -221,30 +221,35 @@
" " " "
(str (:code wallet-currency))]]}])) (str (:code wallet-currency))]]}]))
(defn fee-item [prices wallet-currency fee-display-symbol fee gas-error] (defn loading-indicator []
(let [converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))] [react/activity-indicator {:color :colors/gray
[list-item/list-item :ios {:size :small}
{:type :small :android {:size :16}}])
:title :t/network-fee
:error gas-error (views/defview fee-item [prices wallet-currency fee-display-symbol fee gas-error]
:accessories [[react/nested-text {:style {:color colors/gray}} (views/letsubs [{:keys [gas-price-loading? gas-loading?]} [:signing/edit-fee]]
[{:style {:color colors/black}} (utils/format-decimals fee 6)] (let [converted-fee-value (* fee (get-in prices [(keyword fee-display-symbol) (keyword (:code wallet-currency)) :price]))]
" " [list-item/list-item
fee-display-symbol {:type :small
" • " :title :t/network-fee
[{:style {:color colors/black}} :error (when-not (or gas-price-loading? gas-loading?) gas-error)
(if converted-fee-value :disabled? (or gas-price-loading? gas-loading?)
(i18n/format-currency converted-fee-value (:code wallet-currency)) :accessories (if (or gas-price-loading? gas-loading?)
[react/activity-indicator {:color :colors/gray [[loading-indicator]]
:ios {:size :small} [[react/nested-text {:style {:color colors/gray}}
:android {:size :16}}])] [{:style {:color colors/black}} (utils/format-decimals fee 6)]
" " " "
(str (:code wallet-currency))] fee-display-symbol
:chevron] " • "
:on-press #(re-frame/dispatch [{:style {:color colors/black}}
[:signing.ui/open-fee-sheet (i18n/format-currency converted-fee-value (:code wallet-currency))]
{:content (fn [] [sheets/fee-bottom-sheet fee-display-symbol]) " "
:content-height 270}])}])) (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/defview network-item []
(views/letsubs [network-name [:network-name]] (views/letsubs [network-name [:network-name]]