bug #4746 - using dapp specified gas limit, but default gas price when dapp sets gas limit only

Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
This commit is contained in:
Goran Jovic 2018-06-13 16:25:13 +02:00 committed by Igor Mandrigin
parent e7f559c272
commit 986fc2bc7c
No known key found for this signature in database
GPG Key ID: 4A0EDDE26E66BC8B
1 changed files with 41 additions and 26 deletions

View File

@ -30,13 +30,17 @@
(re-frame/reg-fx
::accept-transaction-with-changed-gas
(fn [{:keys [masked-password id on-completed gas gas-price]}]
(fn [{:keys [masked-password id on-completed gas gas-price default-gas-price]}]
;; unmasking the password as late as possible to avoid being exposed from app-db
(if gas
(status/approve-sign-request-with-args id
(security/unmask masked-password)
(money/to-fixed gas)
(money/to-fixed gas-price)
on-completed)))
(money/to-fixed (or gas-price default-gas-price))
on-completed)
(status/approve-sign-request id
(security/unmask masked-password)
on-completed))))
(defn- send-ethers [{:keys [web3 from to value gas gas-price]}]
(.sendTransaction (.-eth web3)
@ -300,9 +304,19 @@
:masked-password password
:on-completed on-transactions-modal-completed}})))
(defn update-gas-price
([db edit? success-event]
{:update-gas-price {:web3 (:web3 db)
:success-event (or success-event :wallet/update-gas-price-success)
:edit? edit?}})
([db edit?] (update-gas-price db edit? :wallet/update-gas-price-success)))
(handlers/register-handler-fx
:wallet/sign-transaction-modal
(fn [{db :db} _]
:wallet/update-gas-price
(fn [{:keys [db]} [_ edit?]]
(update-gas-price db edit?)))
(defn sign-transaction-modal [{:keys [db]} default-gas-price]
;;TODO(goranjovic) - unify send-transaction and unsigned-transaction
(let [{:keys [id password] :as send-transaction} (get-in db [:wallet :send-transaction])
{:keys [gas gas-price]} [:wallet.send/unsigned-transaction]]
@ -311,7 +325,18 @@
:masked-password password
:gas (or gas (:gas send-transaction))
:gas-price (or gas-price (:gas-price send-transaction))
:on-completed on-transactions-modal-completed}})))
:default-gas-price default-gas-price
:on-completed on-transactions-modal-completed}}))
(handlers/register-handler-fx
:wallet/sign-transaction-modal-update-gas-success
(fn [cofx [_ default-gas-price]]
(sign-transaction-modal cofx default-gas-price)))
(handlers/register-handler-fx
:wallet/sign-transaction-modal
(fn [{:keys [db]} _]
(update-gas-price db false :wallet/sign-transaction-modal-update-gas-success)))
(defn discard-transaction
[{:keys [db]}]
@ -380,16 +405,6 @@
{:value (ethereum/estimate-gas (-> db :wallet :send-transaction :symbol))
:invalid? false})}))
(defn update-gas-price [db edit?]
{:update-gas-price {:web3 (:web3 db)
:success-event :wallet/update-gas-price-success
:edit? edit?}})
(handlers/register-handler-fx
:wallet/update-gas-price
(fn [{:keys [db]} [_ edit?]]
(update-gas-price db edit?)))
(handlers/register-handler-fx
:close-transaction-sent-screen
(fn [{:keys [db]} [_ chat-id]]