From ebe1b08b2c939e4315676d6ca1a20f0637234c3f Mon Sep 17 00:00:00 2001 From: Goran Jovic Date: Fri, 29 Jun 2018 09:08:39 +0200 Subject: [PATCH] bug #4983 - a few workarounds for blinking token transactions in history Signed-off-by: Goran Jovic --- src/status_im/ui/screens/wallet/events.cljs | 14 +++++++--- .../ui/screens/wallet/send/events.cljs | 28 +++++++++++++++++-- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/status_im/ui/screens/wallet/events.cljs b/src/status_im/ui/screens/wallet/events.cljs index 8814b45a3b..3ec14c42e0 100644 --- a/src/status_im/ui/screens/wallet/events.cljs +++ b/src/status_im/ui/screens/wallet/events.cljs @@ -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 diff --git a/src/status_im/ui/screens/wallet/send/events.cljs b/src/status_im/ui/screens/wallet/send/events.cljs index cc4ab58a08..001105a6f1 100644 --- a/src/status_im/ui/screens/wallet/send/events.cljs +++ b/src/status_im/ui/screens/wallet/send/events.cljs @@ -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