gas estimation sets original-gas when nil

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
tbenr 2018-11-04 13:48:47 +01:00 committed by Goran Jovic
parent 17f74ff2f6
commit c363c06a17
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
4 changed files with 16 additions and 7 deletions

View File

@ -223,7 +223,9 @@
(defn open-modal-wallet-for-transaction [db transaction tx-object]
(let [{:keys [gas gas-price]} transaction
{:keys [wallet-set-up-passed?]} (:account/account db)]
{:db (assoc-in db [:wallet :send-transaction] transaction)
{:db (-> db
(assoc-in [:wallet :send-transaction] transaction)
(assoc-in [:wallet :send-transaction :original-gas] gas))
:dispatch-n [[:update-wallet]
(when-not gas
[:wallet/update-estimated-gas tx-object])

View File

@ -238,7 +238,11 @@
:wallet/update-estimated-gas-success
(fn [{:keys [db]} [_ gas]]
(when gas
{:db (assoc-in db [:wallet :send-transaction :gas] (money/bignumber (int (* gas 1.2))))})))
(let [adjusted-gas (money/bignumber (int (* gas 1.2)))
db-with-adjusted-gas (assoc-in db [:wallet :send-transaction :gas] adjusted-gas)]
{:db (if (some? (-> db :wallet :send-transaction :original-gas))
db-with-adjusted-gas
(assoc-in db-with-adjusted-gas [:wallet :send-transaction :original-gas] adjusted-gas))}))))
(handlers/register-handler-fx
:wallet-setup-navigate-back

View File

@ -8,6 +8,7 @@
(spec/def ::to (spec/nilable string?))
(spec/def ::amount (spec/nilable money/valid?))
(spec/def ::gas (spec/nilable money/valid?))
(spec/def ::original-gas (spec/nilable money/valid?))
(spec/def ::gas-price (spec/nilable money/valid?))
; dapp transaction
(spec/def ::data (spec/nilable string?))
@ -38,4 +39,4 @@
::password ::show-password-input? ::id ::from ::data ::nonce
::camera-flashlight ::in-progress? ::on-result ::on-error
::wrong-password? ::from-chat? ::symbol ::advanced?
::gas ::gas-price ::public-key ::method ::tx-hash]))
::gas ::gas-price ::original-gas ::public-key ::method ::tx-hash]))

View File

@ -251,12 +251,14 @@
(handlers/register-handler-fx
:wallet.send/reset-gas-default
(fn [{:keys [db] :as cofx}]
(let [gas-estimate (money/to-fixed
(ethereum/estimate-gas
(-> db :wallet :send-transaction :symbol)))]
(let [gas-default (if-some [original-gas (-> db :wallet :send-transaction :original-gas)]
(money/to-fixed original-gas)
(money/to-fixed
(ethereum/estimate-gas
(-> db :wallet :send-transaction :symbol))))]
(assoc (models.wallet/edit-value
:gas
gas-estimate
gas-default
cofx)
:dispatch [:wallet/update-gas-price true]))))