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 contract-address "0x0000000000000000000000000000000000000000")
(def default-wallet-transactions
{:filters
{:type [{:id :inbound :label (i18n/label :t/incoming) :checked? true}

View File

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

View File

@ -9,7 +9,8 @@
[status-im.utils.prices :as prices]
[status-im.utils.transactions :as transactions]
[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]}]
(if (and web3 account-id)
@ -84,6 +85,11 @@
(fn [{:keys [web3 success-event 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/register-handler-fx
@ -220,6 +226,18 @@
(fn [db [_ price edit?]]
(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
:wallet/show-error
(fn []

View File

@ -106,22 +106,31 @@
transaction {:id id
:from from
:to to
:to-name (when (= to constants/contract-address)
(i18n/label :t/new-contract))
:symbol symbol
:value (money/bignumber (or value 0))
:data data
:gas (money/bignumber (money/to-decimal gas))
:gas-price (money/bignumber (money/to-decimal gasPrice))
:gas (when (seq gas)
(money/bignumber (money/to-decimal gas)))
:gas-price (when (seq gasPrice)
(money/bignumber (money/to-decimal gasPrice)))
:timestamp now
: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)
sending-db {:id id
:from-chat? sending-from-chat?}]
(if sending-from-chat?
;;SENDING FROM CHAT
{: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]]}
;;SEND SCREEN WAITING SIGNAL
:from-chat? sending-from-bot-or-dapp?}]
(if sending-from-bot-or-dapp?
;;SENDING FROM BOT (CHAT) OR DAPP
{: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]
(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])
new-db' (update-in new-db [:wallet :send-transaction] merge sending-db)] ; just update sending state as we are in wallet flow
(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
{:db db'}
(merge
{:db (-> db'
(assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id))
(update-in [:wallet :transactions-unsigned] dissoc id)
(update-in [:wallet :send-transaction] merge clear-send-properties))}
(if modal?
{:dispatch [:navigate-back]
:dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}]}
{:dispatch [:navigate-to :wallet-transaction-sent]}))))))
{:db (-> db'
(assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id))
(update-in [:wallet :transactions-unsigned] dissoc id)
(update-in [:wallet :send-transaction] merge clear-send-properties))}
(if modal?
{:dispatch [:navigate-back]
:dispatch-later [{:ms 400 :dispatch [:navigate-to-modal :wallet-transaction-sent-modal]}]}
{:dispatch [:navigate-to :wallet-transaction-sent]}))))))
(defn on-transactions-modal-completed [raw-results]
(let [results (:results (types/json->clj raw-results))]
@ -199,7 +208,7 @@
:wallet/sign-transaction
(fn [{{:keys [web3]
: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)
{:keys [amount id password to symbol gas gas-price]} (get-in db [:wallet :send-transaction])]
(if id
@ -292,6 +301,6 @@
:wallet.send/reset-gas-default
(fn [{:keys [db]}]
{:dispatch [:wallet/update-gas-price true]
:db (update-in db [:wallet :edit]
assoc
:gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))}))
:db (update-in db [:wallet :edit]
assoc
:gas (ethereum/estimate-gas (get-in db [:wallet :send-transaction :symbol])))}))

View File

@ -58,7 +58,9 @@
(when-let [unsigned-transaction (get unsigned-transactions
(:id 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
:<- [:wallet]

View File

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