[ISSUE #3241] Do not use hardcoded gas price

Signed-off-by: Eric Dvorsak <eric@dvorsak.fr>
This commit is contained in:
Julien Eluard 2018-02-12 10:09:12 +01:00 committed by Eric Dvorsak
parent 032c5b42eb
commit d74b27f951
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
5 changed files with 34 additions and 19 deletions

View File

@ -3,7 +3,6 @@
(:require [cljs.spec.alpha :as spec] (:require [cljs.spec.alpha :as spec]
[status-im.constants :as constants] [status-im.constants :as constants]
[status-im.utils.platform :as platform] [status-im.utils.platform :as platform]
[status-im.utils.ethereum.core :as ethereum]
status-im.ui.screens.accounts.db status-im.ui.screens.accounts.db
status-im.ui.screens.contacts.db status-im.ui.screens.contacts.db
status-im.ui.screens.qr-scanner.db status-im.ui.screens.qr-scanner.db
@ -18,15 +17,6 @@
status-im.ui.screens.browser.db status-im.ui.screens.browser.db
status-im.ui.screens.add-new.db)) status-im.ui.screens.add-new.db))
(defn gas-default [symbol]
{:gas (ethereum/estimate-gas symbol)
:gas-price ethereum/default-gas-price})
(def transaction-send-default
(let [symbol :ETH]
(merge (gas-default symbol)
{:symbol symbol})))
;; initial state of app-db ;; initial state of app-db
(def app-db {:current-public-key nil (def app-db {:current-public-key nil
:status-module-initialized? (or platform/ios? js/goog.DEBUG) :status-module-initialized? (or platform/ios? js/goog.DEBUG)
@ -46,7 +36,6 @@
:tags [] :tags []
:sync-state :done :sync-state :done
:wallet.transactions constants/default-wallet-transactions :wallet.transactions constants/default-wallet-transactions
:wallet {:send-transaction transaction-send-default}
:wallet-selected-asset {} :wallet-selected-asset {}
:prices {} :prices {}
:notifications {} :notifications {}

View File

@ -79,6 +79,11 @@
#(re-frame/dispatch [success-event %]) #(re-frame/dispatch [success-event %])
#(re-frame/dispatch [error-event %])))) #(re-frame/dispatch [error-event %]))))
(reg-fx
:update-gas-price
(fn [{:keys [web3 success-event edit?]}]
(ethereum/gas-price web3 #(re-frame/dispatch [success-event %2 edit?]))))
;; Handlers ;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
@ -202,3 +207,15 @@
:content (i18n/label :t/transactions-delete-content) :content (i18n/label :t/transactions-delete-content)
:confirm-button-text (i18n/label :t/confirm) :confirm-button-text (i18n/label :t/confirm)
:on-accept #(re-frame/dispatch [:wallet/discard-unsigned-transaction transaction-id])}})) :on-accept #(re-frame/dispatch [:wallet/discard-unsigned-transaction transaction-id])}}))
(handlers/register-handler-fx
:wallet/update-gas-price
(fn [{:keys [db]} [_ edit?]]
{:update-gas-price {:web3 (:web3 db)
:success-event :wallet/update-gas-price-success
:edit? edit?}}))
(handlers/register-handler-db
:wallet/update-gas-price-success
(fn [db [_ price edit?]]
(assoc-in db [:wallet (if edit? :edit :send-transaction) :gas-price] price)))

View File

@ -1,6 +1,5 @@
(ns status-im.ui.screens.wallet.navigation (ns status-im.ui.screens.wallet.navigation
(:require [re-frame.core :as re-frame] (:require [re-frame.core :as re-frame]
[status-im.ui.screens.db :as db]
[status-im.ui.screens.navigation :as navigation] [status-im.ui.screens.navigation :as navigation]
[status-im.utils.ethereum.core :as ethereum] [status-im.utils.ethereum.core :as ethereum]
[status-im.utils.ethereum.tokens :as tokens])) [status-im.utils.ethereum.tokens :as tokens]))
@ -15,16 +14,23 @@
(re-frame/dispatch [:update-transactions]) (re-frame/dispatch [:update-transactions])
db) db)
(def transaction-send-default
(let [symbol :ETH]
{:gas (ethereum/estimate-gas symbol)
:symbol symbol}))
(defmethod navigation/preload-data! :wallet-request-transaction (defmethod navigation/preload-data! :wallet-request-transaction
[db [event]] [db [event]]
(if (= event :navigate-back) (if (= event :navigate-back)
db db
(-> db (-> db
(update :wallet dissoc :request-transaction) (update :wallet dissoc :request-transaction)
(assoc-in [:wallet :send-transaction] db/transaction-send-default)))) (assoc-in [:wallet :send-transaction] transaction-send-default))))
(defmethod navigation/preload-data! :wallet-send-transaction (defmethod navigation/preload-data! :wallet-send-transaction
[db [event]] [db [event]]
(re-frame/dispatch [:wallet/update-gas-price])
(if (= event :navigate-back) (if (= event :navigate-back)
db db
(assoc-in db [:wallet :send-transaction] db/transaction-send-default))) (assoc-in db [:wallet :send-transaction] transaction-send-default)))

View File

@ -291,6 +291,7 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/reset-gas-default :wallet.send/reset-gas-default
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:db (update-in db [:wallet :edit] {:dispatch [:wallet/update-gas-price true]
merge :db (update-in db [:wallet :edit]
(db/gas-default (get-in db [:wallet :send-transaction :symbol])))})) assoc
:gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))}))

View File

@ -83,7 +83,9 @@
(.sendTransaction (.-eth web3) (clj->js params) cb)) (.sendTransaction (.-eth web3) (clj->js params) cb))
(def default-transaction-gas (money/bignumber 21000)) (def default-transaction-gas (money/bignumber 21000))
(def default-gas-price (money/->wei :gwei 21))
(defn gas-price [web3 cb]
(.getGasPrice (.-eth web3) cb))
(defn estimate-gas [symbol] (defn estimate-gas [symbol]
(if (tokens/ethereum? symbol) (if (tokens/ethereum? symbol)