Skip to content

Instantly share code, notes, and snippets.

@madvas
Created October 3, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save madvas/92ff50799e7d7fff8a01998c034e263a to your computer and use it in GitHub Desktop.
Save madvas/92ff50799e7d7fff8a01998c034e263a to your computer and use it in GitHub Desktop.
:new-tweet/send
(reg-event-fx
:new-tweet/send
interceptors
(fn [{:keys [db]} []]
(let [{:keys [name text address]} (:new-tweet db)]
{:web3-fx.contract/state-fn
{:instance (:instance (:contract db))
:web3 (:web3 db)
:db-path [:contract :send-tweet]
:fn [:add-tweet name text
{:from address
:gas tweet-gas-limit}
:new-tweet/confirmed
:log-error
:new-tweet/transaction-receipt-loaded]}})))
(reg-event-db
:new-tweet/confirmed
interceptors
(fn [db [transaction-hash]]
(assoc-in db [:new-tweet :sending?] true)))
(reg-event-db
:new-tweet/transaction-receipt-loaded
interceptors
(fn [db [{:keys [gas-used] :as transaction-receipt}]]
(console :log transaction-receipt)
(when (= gas-used tweet-gas-limit)
(console :error "All gas used"))
(assoc-in db [:new-tweet :sending?] false)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment