bug #4983 - a few workarounds for blinking token transactions in history

Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
Goran Jovic 2018-06-29 09:08:39 +02:00
parent 0a062d1e91
commit ebe1b08b2c
No known key found for this signature in database
GPG Key ID: D429D1A9B2EB8A8E
2 changed files with 35 additions and 7 deletions

View File

@ -155,19 +155,25 @@
(assoc-in [:wallet :transactions-loading?] true))}))))
(defn combine-entries [transaction token-transfer]
(merge transaction (select-keys token-transfer
(if (= :ETH (:symbol transaction))
[:symbol :from :to :value :type :token]
[:confirmations]))))
(merge transaction (select-keys token-transfer [:symbol :from :to :value :type :token :transfer])))
(defn update-confirmations [tx1 tx2]
(assoc tx1 :confirmations (max (:confirmations tx1)
(:confirmations tx2))))
(defn- tx-and-transfer?
"A helper function that checks if first argument is a transaction and the second argument a token transfer object."
[tx1 tx2]
(and (not (:transfer tx1)) (:transfer tx2)))
(defn- both-transfer?
[tx1 tx2]
(and (:transfer tx1) (:transfer tx2)))
(defn dedupe-transactions [tx1 tx2]
(cond (tx-and-transfer? tx1 tx2) (combine-entries tx1 tx2)
(tx-and-transfer? tx2 tx1) (combine-entries tx2 tx1)
(both-transfer? tx1 tx2) (update-confirmations tx1 tx2)
:else tx2))
(handlers/register-handler-db

View File

@ -265,18 +265,40 @@
(handle-failed-tx error_message))
{:db (update-in db [:wallet :transactions-unsigned] dissoc id)})))))
(defn prepare-unconfirmed-transaction [db now hash id]
(let [transaction (get-in db [:wallet :transactions-unsigned id])]
(defn prepare-unconfirmed-dapp-transaction [now hash transaction]
(-> transaction
(assoc :confirmations "0"
:timestamp (str now)
:type :outbound
:hash hash)
(update :gas-price str)
(update :value str)
(update :gas str)
(dissoc :message-id :id)))
(defn prepare-unconfirmed-status-transaction [db now hash transaction]
(let [network (:network db)
token (tokens/symbol->token (keyword (ethereum/network-names network)) (:symbol transaction))]
(-> transaction
(assoc :confirmations "0"
:timestamp (str now)
:type :outbound
:hash hash)
(update :gas-price str)
(update :value str)
(assoc :value (:amount transaction))
(assoc :token token)
(update :gas str)
(dissoc :message-id :id))))
(defn prepare-unconfirmed-transaction [db now hash id]
(let [unsigned-transaction (get-in db [:wallet :transactions-unsigned id])
send-transaction (get-in db [:wallet :send-transaction])]
;;TODO(goranjovic) - unify `send-transaction` with transactions-unsigned`
;; currently the latter is only used for transactions initiated from dapps
(if-not (:symbol send-transaction)
(prepare-unconfirmed-dapp-transaction now hash unsigned-transaction)
(prepare-unconfirmed-status-transaction db now hash send-transaction))))
(handlers/register-handler-fx
:send-transaction-message
(concat models.message/send-interceptors