bug #4983 - a few workarounds for blinking token transactions in history
Signed-off-by: Goran Jovic <goranjovic@gmail.com>
This commit is contained in:
parent
0a062d1e91
commit
ebe1b08b2c
|
@ -155,19 +155,25 @@
|
||||||
(assoc-in [:wallet :transactions-loading?] true))}))))
|
(assoc-in [:wallet :transactions-loading?] true))}))))
|
||||||
|
|
||||||
(defn combine-entries [transaction token-transfer]
|
(defn combine-entries [transaction token-transfer]
|
||||||
(merge transaction (select-keys token-transfer
|
(merge transaction (select-keys token-transfer [:symbol :from :to :value :type :token :transfer])))
|
||||||
(if (= :ETH (:symbol transaction))
|
|
||||||
[:symbol :from :to :value :type :token]
|
(defn update-confirmations [tx1 tx2]
|
||||||
[:confirmations]))))
|
(assoc tx1 :confirmations (max (:confirmations tx1)
|
||||||
|
(:confirmations tx2))))
|
||||||
|
|
||||||
(defn- tx-and-transfer?
|
(defn- tx-and-transfer?
|
||||||
"A helper function that checks if first argument is a transaction and the second argument a token transfer object."
|
"A helper function that checks if first argument is a transaction and the second argument a token transfer object."
|
||||||
[tx1 tx2]
|
[tx1 tx2]
|
||||||
(and (not (:transfer tx1)) (:transfer tx2)))
|
(and (not (:transfer tx1)) (:transfer tx2)))
|
||||||
|
|
||||||
|
(defn- both-transfer?
|
||||||
|
[tx1 tx2]
|
||||||
|
(and (:transfer tx1) (:transfer tx2)))
|
||||||
|
|
||||||
(defn dedupe-transactions [tx1 tx2]
|
(defn dedupe-transactions [tx1 tx2]
|
||||||
(cond (tx-and-transfer? tx1 tx2) (combine-entries tx1 tx2)
|
(cond (tx-and-transfer? tx1 tx2) (combine-entries tx1 tx2)
|
||||||
(tx-and-transfer? tx2 tx1) (combine-entries tx2 tx1)
|
(tx-and-transfer? tx2 tx1) (combine-entries tx2 tx1)
|
||||||
|
(both-transfer? tx1 tx2) (update-confirmations tx1 tx2)
|
||||||
:else tx2))
|
:else tx2))
|
||||||
|
|
||||||
(handlers/register-handler-db
|
(handlers/register-handler-db
|
||||||
|
|
|
@ -265,18 +265,40 @@
|
||||||
(handle-failed-tx error_message))
|
(handle-failed-tx error_message))
|
||||||
{:db (update-in db [:wallet :transactions-unsigned] dissoc id)})))))
|
{:db (update-in db [:wallet :transactions-unsigned] dissoc id)})))))
|
||||||
|
|
||||||
(defn prepare-unconfirmed-transaction [db now hash id]
|
(defn prepare-unconfirmed-dapp-transaction [now hash transaction]
|
||||||
(let [transaction (get-in db [:wallet :transactions-unsigned id])]
|
(-> 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
|
(-> transaction
|
||||||
(assoc :confirmations "0"
|
(assoc :confirmations "0"
|
||||||
:timestamp (str now)
|
:timestamp (str now)
|
||||||
:type :outbound
|
:type :outbound
|
||||||
:hash hash)
|
:hash hash)
|
||||||
(update :gas-price str)
|
(update :gas-price str)
|
||||||
(update :value str)
|
(assoc :value (:amount transaction))
|
||||||
|
(assoc :token token)
|
||||||
(update :gas str)
|
(update :gas str)
|
||||||
(dissoc :message-id :id))))
|
(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
|
(handlers/register-handler-fx
|
||||||
:send-transaction-message
|
:send-transaction-message
|
||||||
(concat models.message/send-interceptors
|
(concat models.message/send-interceptors
|
||||||
|
|
Loading…
Reference in New Issue