[fix #2985] Show sent transaction immediatly in history

This commit is contained in:
Eric Dvorsak 2018-01-22 22:45:59 +01:00
parent bf95603b56
commit 63afd37921
No known key found for this signature in database
GPG Key ID: 932AC1CE5F05DE0C
3 changed files with 29 additions and 15 deletions

View File

@ -124,7 +124,7 @@
:update-transactions-success :update-transactions-success
(fn [db [_ transactions]] (fn [db [_ transactions]]
(-> db (-> db
(assoc-in [:wallet :transactions] transactions) (update-in [:wallet :transactions] merge transactions)
(assoc-in [:wallet :transactions-loading?] false)))) (assoc-in [:wallet :transactions-loading?] false))))
(handlers/register-handler-db (handlers/register-handler-db
@ -204,4 +204,4 @@
{:show-confirmation {:title (i18n/label :t/transactions-delete) {:show-confirmation {:title (i18n/label :t/transactions-delete)
:content (i18n/label :t/transactions-delete-content) :content (i18n/label :t/transactions-delete-content)
:confirm-button-text (i18n/label :t/confirm) :confirm-button-text (i18n/label :t/confirm)
:on-accept #(re-frame/dispatch [:wallet/discard-unsigned-transaction transaction-id])}})) :on-accept #(re-frame/dispatch [:wallet/discard-unsigned-transaction transaction-id])}}))

View File

@ -98,8 +98,8 @@
[(re-frame/inject-cofx :now)] [(re-frame/inject-cofx :now)]
(fn [{:keys [db now]} [_ {:keys [id message_id args] :as transaction}]] (fn [{:keys [db now]} [_ {:keys [id message_id args] :as transaction}]]
(if (transaction-valid? transaction) (if (transaction-valid? transaction)
;NOTE(goranjovic): the transactions started from chat using /send command ;;NOTE(goranjovic): the transactions started from chat using /send command
; are only in ether, so this parameter defaults to ETH ;; are only in ether, so this parameter defaults to ETH
(let [{:keys [from to value symbol data gas gasPrice] :or {symbol :ETH}} args (let [{:keys [from to value symbol data gas gasPrice] :or {symbol :ETH}} args
;;TODO (andrey) revisit this map later (this map from old transactions, idk if we need all these fields) ;;TODO (andrey) revisit this map later (this map from old transactions, idk if we need all these fields)
transaction {:id id transaction {:id id
@ -160,21 +160,34 @@
::show-transaction-error error_message} ::show-transaction-error 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]
(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))))
(handlers/register-handler-fx (handlers/register-handler-fx
::transaction-completed ::transaction-completed
(fn [{db :db} [_ {:keys [id response]} modal?]] (fn [{db :db now :now} [_ {:keys [id response]} modal?]]
(let [{:keys [hash error]} response (let [{:keys [hash error]} response
db' (assoc-in db [:wallet :send-transaction :in-progress?] false)] db' (assoc-in db [:wallet :send-transaction :in-progress?] false)]
(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'
(update-in [:wallet :transactions-unsigned] dissoc id) (assoc-in [:wallet :transactions hash] (prepare-unconfirmed-transaction db now hash id))
(update-in [:wallet :send-transaction] merge clear-send-properties))} (update-in [:wallet :transactions-unsigned] dissoc id)
(if modal? (update-in [:wallet :send-transaction] merge clear-send-properties))}
{:dispatch-n [[:navigate-back] (if modal?
[:navigate-to-modal :wallet-transaction-sent-modal]]} {:dispatch-n [[:navigate-back]
{:dispatch [:navigate-to :wallet-transaction-sent]})))))) [:navigate-to-modal :wallet-transaction-sent-modal]]}
{: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))]
@ -265,4 +278,4 @@
(handlers/register-handler-fx (handlers/register-handler-fx
:wallet.send/set-gas-price :wallet.send/set-gas-price
(fn [{:keys [db]} [_ gas-price]] (fn [{:keys [db]} [_ gas-price]]
{:db (assoc-in db [:wallet :send-transaction :gas-price] (money/bignumber gas-price))})) {:db (assoc-in db [:wallet :send-transaction :gas-price] (money/bignumber gas-price))}))

View File

@ -144,7 +144,8 @@
:gas-used (i18n/label :not-applicable) :gas-used (i18n/label :not-applicable)
:nonce (i18n/label :not-applicable) :nonce (i18n/label :not-applicable)
:hash (i18n/label :not-applicable)} :hash (i18n/label :not-applicable)}
{:cost (money/wei->str :eth (money/fee-value gas-used gas-price)) {:cost (when gas-used
(money/wei->str :eth (money/fee-value gas-used gas-price)))
:url (transactions/get-transaction-details-url network hash)})))))) :url (transactions/get-transaction-details-url network hash)}))))))
(reg-sub :wallet.transactions.details/confirmations (reg-sub :wallet.transactions.details/confirmations
@ -163,4 +164,4 @@
(reg-sub :wallet.transactions/filters (reg-sub :wallet.transactions/filters
(fn [db] (fn [db]
(get-in db [:wallet.transactions :filters]))) (get-in db [:wallet.transactions :filters])))