fixed Empty Gas limit and Gas price

Signed-off-by: Andrey Shovkoplyas <motor4ik@gmail.com>
This commit is contained in:
Andrey Shovkoplyas 2018-03-29 15:46:03 +03:00
parent f4799184c5
commit 1faa35bfd9
No known key found for this signature in database
GPG Key ID: EAAB7C8622D860A4
6 changed files with 59 additions and 24 deletions

View File

@ -26,6 +26,8 @@
(def default-network config/default-network) (def default-network config/default-network)
(def contract-address "0x0000000000000000000000000000000000000000")
(def default-wallet-transactions (def default-wallet-transactions
{:filters {:filters
{:type [{:id :inbound :label (i18n/label :t/incoming) :checked? true} {:type [{:id :inbound :label (i18n/label :t/incoming) :checked? true}

View File

@ -438,6 +438,7 @@
:receive-transaction "Receive transaction" :receive-transaction "Receive transaction"
:new-transaction "New Transaction" :new-transaction "New Transaction"
:transaction-history "Transaction History" :transaction-history "Transaction History"
:new-contract "New Contract"
;; Wallet Send ;; Wallet Send
:wallet-choose-recipient "Choose Recipient" :wallet-choose-recipient "Choose Recipient"

View File

@ -9,7 +9,8 @@
[status-im.utils.prices :as prices] [status-im.utils.prices :as prices]
[status-im.utils.transactions :as transactions] [status-im.utils.transactions :as transactions]
[taoensso.timbre :as log] [taoensso.timbre :as log]
status-im.ui.screens.wallet.request.events)) status-im.ui.screens.wallet.request.events
[status-im.utils.money :as money]))
(defn get-balance [{:keys [web3 account-id on-success on-error]}] (defn get-balance [{:keys [web3 account-id on-success on-error]}]
(if (and web3 account-id) (if (and web3 account-id)
@ -84,6 +85,11 @@
(fn [{:keys [web3 success-event edit?]}] (fn [{:keys [web3 success-event edit?]}]
(ethereum/gas-price web3 #(re-frame/dispatch [success-event %2 edit?])))) (ethereum/gas-price web3 #(re-frame/dispatch [success-event %2 edit?]))))
(reg-fx
:update-estimated-gas
(fn [{:keys [web3 obj success-event]}]
(ethereum/estimate-gas-web3 web3 (clj->js obj) #(re-frame/dispatch [success-event %2]))))
;; Handlers ;; Handlers
(handlers/register-handler-fx (handlers/register-handler-fx
@ -220,7 +226,19 @@
(fn [db [_ price edit?]] (fn [db [_ price edit?]]
(assoc-in db [:wallet (if edit? :edit :send-transaction) :gas-price] price))) (assoc-in db [:wallet (if edit? :edit :send-transaction) :gas-price] price)))
(handlers/register-handler-fx
:wallet/update-estimated-gas
(fn [{:keys [db]} [_ obj]]
{:update-estimated-gas {:web3 (:web3 db)
:obj obj
:success-event :wallet/update-estimated-gas-success}}))
(handlers/register-handler-db
:wallet/update-estimated-gas-success
(fn [db [_ gas]]
(assoc-in db [:wallet :send-transaction :gas] (money/bignumber gas))))
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet/show-error :wallet/show-error
(fn [] (fn []
{:show-error (i18n/label :t/wallet-error)})) {:show-error (i18n/label :t/wallet-error)}))

View File

@ -106,22 +106,31 @@
transaction {:id id transaction {:id id
:from from :from from
:to to :to to
:to-name (when (= to constants/contract-address)
(i18n/label :t/new-contract))
:symbol symbol :symbol symbol
:value (money/bignumber (or value 0)) :value (money/bignumber (or value 0))
:data data :data data
:gas (money/bignumber (money/to-decimal gas)) :gas (when (seq gas)
:gas-price (money/bignumber (money/to-decimal gasPrice)) (money/bignumber (money/to-decimal gas)))
:gas-price (when (seq gasPrice)
(money/bignumber (money/to-decimal gasPrice)))
:timestamp now :timestamp now
:message-id message_id} :message-id message_id}
sending-from-chat? (not (get-in db [:wallet :send-transaction :waiting-signal?])) sending-from-bot-or-dapp? (not (get-in db [:wallet :send-transaction :waiting-signal?]))
new-db (assoc-in db [:wallet :transactions-unsigned id] transaction) new-db (assoc-in db [:wallet :transactions-unsigned id] transaction)
sending-db {:id id sending-db {:id id
:from-chat? sending-from-chat?}] :from-chat? sending-from-bot-or-dapp?}]
(if sending-from-chat? (if sending-from-bot-or-dapp?
;;SENDING FROM CHAT ;;SENDING FROM BOT (CHAT) OR DAPP
{:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here {:db (assoc-in new-db [:wallet :send-transaction] sending-db) ; we need to completely reset sending state here
:dispatch-n [[:update-wallet (map :symbol (tokens/tokens-for (ethereum/network->chain-keyword (:network db))))] [:navigate-to-modal :wallet-send-transaction-modal]]} :dispatch-n [[:update-wallet (map :symbol (tokens/tokens-for (ethereum/network->chain-keyword (:network db))))]
;;SEND SCREEN WAITING SIGNAL [:navigate-to-modal :wallet-send-transaction-modal]
(when-not (seq gas)
[:wallet/update-estimated-gas transaction])
(when-not (seq gasPrice)
[:wallet/update-gas-price])]}
;;WALLET SEND SCREEN WAITING SIGNAL
(let [{:keys [later? password]} (get-in db [:wallet :send-transaction]) (let [{:keys [later? password]} (get-in db [:wallet :send-transaction])
new-db' (update-in new-db [:wallet :send-transaction] merge sending-db)] ; just update sending state as we are in wallet flow new-db' (update-in new-db [:wallet :send-transaction] merge sending-db)] ; just update sending state as we are in wallet flow
(if later? (if later?
@ -181,14 +190,14 @@
(if (and error (string? error) (not (string/blank? error))) ;; ignore error here, error will be handled in :transaction-failed (if (and error (string? error) (not (string/blank? error))) ;; ignore error here, error will be handled in :transaction-failed
{:db db'} {:db db'}
(merge (merge
{:db (-> db' {:db (-> db'
(assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id)) (assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id))
(update-in [:wallet :transactions-unsigned] dissoc id) (update-in [:wallet :transactions-unsigned] dissoc id)
(update-in [:wallet :send-transaction] merge clear-send-properties))} (update-in [:wallet :send-transaction] merge clear-send-properties))}
(if modal? (if modal?
{:dispatch [:navigate-back] {:dispatch [:navigate-back]
:dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}]} :dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}]}
{:dispatch [:navigate-to :wallet-transaction-sent]})))))) {:dispatch [:navigate-to :wallet-transaction-sent]}))))))
(defn on-transactions-modal-completed [raw-results] (defn on-transactions-modal-completed [raw-results]
(let [results (:results (types/json->clj raw-results))] (let [results (:results (types/json->clj raw-results))]
@ -199,7 +208,7 @@
:wallet/sign-transaction :wallet/sign-transaction
(fn [{{:keys [web3] (fn [{{:keys [web3]
:accounts/keys [accounts current-account-id] :as db} :db} [_ later?]] :accounts/keys [accounts current-account-id] :as db} :db} [_ later?]]
(let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false) (let [db' (assoc-in db [:wallet :send-transaction :wrong-password?] false)
network (:network db) network (:network db)
{:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])] {:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])]
(if id (if id
@ -292,6 +301,6 @@
:wallet.send/reset-gas-default :wallet.send/reset-gas-default
(fn [{:keys [db]}] (fn [{:keys [db]}]
{:dispatch [:wallet/update-gas-price true] {:dispatch [:wallet/update-gas-price true]
:db (update-in db [:wallet :edit] :db (update-in db [:wallet :edit]
assoc assoc
:gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))})) :gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))}))

View File

@ -58,7 +58,9 @@
(when-let [unsigned-transaction (get unsigned-transactions (when-let [unsigned-transaction (get unsigned-transactions
(:id send-transaction))] (:id send-transaction))]
(merge send-transaction (merge send-transaction
unsigned-transaction)))) unsigned-transaction
{:gas (or (:gas unsigned-transaction) (:gas send-transaction))
:gas-price (or (:gas-price unsigned-transaction) (:gas-price send-transaction))}))))
(re-frame/reg-sub :wallet/edit (re-frame/reg-sub :wallet/edit
:<- [:wallet] :<- [:wallet]

View File

@ -87,6 +87,9 @@
(defn gas-price [web3 cb] (defn gas-price [web3 cb]
(.getGasPrice (.-eth web3) cb)) (.getGasPrice (.-eth web3) cb))
(defn estimate-gas-web3 [web3 obj cb]
(.estimateGas (.-eth web3) obj cb))
(defn estimate-gas [symbol] (defn estimate-gas [symbol]
(if (tokens/ethereum? symbol) (if (tokens/ethereum? symbol)
default-transaction-gas default-transaction-gas