dispatch from within the send-transaction-callback rather than the try/catch block

This commit is contained in:
Rob Culliton 2018-05-15 14:39:48 -04:00
parent 9a5386a5fa
commit 6da6f3417f
No known key found for this signature in database
GPG Key ID: 6FDEF60B3DC84D94
1 changed files with 14 additions and 14 deletions

View File

@ -404,13 +404,15 @@
(defn send-transaction-callback (defn send-transaction-callback
[issue-id] [issue-id pending-revocations]
(fn [error payout-hash] (fn [error payout-hash]
(println "send-transaction-callback" error payout-hash) (println "send-transaction-callback" error payout-hash)
(when error (when error
(dispatch [:set-flash-message (if (empty? pending-revocations)
:error (dispatch [:set-flash-message
(str "Error sending transaction: " error)]) :error
(str "Error sending transaction: " error)])
(dispatch [:remove-bot-confirmation issue-id]))
(dispatch [:payout-confirm-failed issue-id])) (dispatch [:payout-confirm-failed issue-id]))
(when payout-hash (when payout-hash
(dispatch [:save-payout-hash issue-id payout-hash])))) (dispatch [:save-payout-hash issue-id payout-hash]))))
@ -444,7 +446,7 @@
:url "/api/user/remove-bot-confirmation" :url "/api/user/remove-bot-confirmation"
:params {:token (get-admin-token db) :params {:token (get-admin-token db)
:issue-id issue-id} :issue-id issue-id}
:on-success #(println "successfully removed bot confirmation for: " issue-id) :on-success #(dispatch [:remove-pending-revocation issue-id])
:on-error #(println "error removing bot confirmation for " issue-id)}})) :on-error #(println "error removing bot confirmation for " issue-id)}}))
(reg-event-fx (reg-event-fx
@ -483,6 +485,7 @@
confirm-hash :confirm_hash} issue]] confirm-hash :confirm_hash} issue]]
(println (:web3 db)) (println (:web3 db))
(let [w3 (:web3 db) (let [w3 (:web3 db)
pending-revocations (::db/pending-revocations db)
confirm-method-id (sig->method-id w3 "confirmTransaction(uint256)") confirm-method-id (sig->method-id w3 "confirmTransaction(uint256)")
confirm-id (strip-0x confirm-hash) confirm-id (strip-0x confirm-hash)
data (str confirm-method-id data (str confirm-method-id
@ -496,17 +499,14 @@
(println "data:" data) (println "data:" data)
(try (try
(web3-eth/send-transaction! w3 payload (web3-eth/send-transaction! w3 payload
(send-transaction-callback issue-id)) (send-transaction-callback issue-id pending-revocations))
{:db (assoc-in db [:owner-bounties issue-id :confirming?] true)} {:db (assoc-in db [:owner-bounties issue-id :confirming?] true)}
(catch js/Error e (catch js/Error e
(if (empty? (::db/pending-revocations db)) {:db (assoc-in db [:owner-bounties issue-id :confirm-failed?] true)
{:db (assoc-in db [:owner-bounties issue-id :confirm-failed?] true) :dispatch-n [[:payout-confirm-failed issue-id e]
:dispatch-n [[:payout-confirm-failed issue-id e] [:set-flash-message
[:set-flash-message :error
:error (str "Failed to send transaction" e)]]})))))
(str "Failed to send transaction" e)]]}
{:dispatch-n [[:remove-pending-revocation issue-id]
[:remove-bot-confirmation issue-id]]}))))))
(reg-event-fx (reg-event-fx
:payout-confirmed :payout-confirmed