Skip to content

Instantly share code, notes, and snippets.

0xbBC5eE8be95683983dF67260B0AB033c237Bde60
@madvas
madvas / handlers.cljs
Created October 3, 2016 17:34
: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
@madvas
madvas / handlers.cljs
Created October 3, 2016 17:26
:contract/settings-loaded
(reg-event-db
:contract/settings-loaded
interceptors
(fn [db [[max-name-length max-tweet-length]]]
(assoc db :settings {:max-name-length (.toNumber max-name-length)
:max-tweet-length (.toNumber max-tweet-length)})))
@madvas
madvas / handlers.cljs
Created October 3, 2016 17:22
:contract/on-tweet-loaded
(reg-event-db
:contract/on-tweet-loaded
interceptors
(fn [db [tweet]]
(update db :tweets conj (merge (select-keys tweet [:author-address :text :name])
{:date (u/big-number->date-time (:date tweet))
:tweet-key (.toNumber (:tweet-key tweet))}))))
@madvas
madvas / handlers.cljs
Last active October 3, 2016 17:00
:contract/compiled-code-loaded
(reg-event-fx
:contract/abi-loaded
interceptors
(fn [{:keys [db]} [abi]]
(let [web3 (:web3 db)
contract-instance (web3-eth/contract-at web3 abi (:address (:contract db)))]
{:db (assoc-in db [:contract :instance] contract-instance)
:web3-fx.contract/events
@madvas
madvas / handlers.cljs
Last active October 3, 2016 17:29
:blockchain/my-addresses-loaded
(reg-event-fx
:blockchain/my-addresses-loaded
interceptors
(fn [{:keys [db]} [addresses]]
{:db (-> db
(assoc :my-addresses addresses)
(assoc-in [:new-tweet :address] (first addresses)))
:web3-fx.blockchain/balances
{:web3 (:web3 db/default-db)
:addresses addresses
@madvas
madvas / handlers.cljs
Last active October 3, 2016 17:01
initialize
(reg-event-fx
:initialize
(fn [_ _]
(merge
{:db db/default-db
:http-xhrio {:method :get
:uri (gstring/format "/contracts/build/%s.abi"
(get-in db/default-db [:contract :name]))
:timeout 6000
:response-format (ajax/json-response-format {:keywords? true})
@madvas
madvas / handlers.cljs
Created October 3, 2016 16:25
initialize
(reg-event-fx
:initialize
(fn [_ _]
(merge
{:db db/default-db
:dispatch [:contract/fetch-compiled-code [:contract/compiled-code-loaded]]}
(when (:provides-web3? db/default-db)
{:web3-fx.blockchain/fns
{:web3 (:web3 db/default-db)
:fns [[web3-eth/accounts :blockchain/my-addresses-loaded :log-error]]}}))))
@madvas
madvas / handlers.cljs
Created October 3, 2016 16:23
:initialize
(reg-event-fx
:initialize
(fn [_ _]
(merge
{:db db/default-db
:dispatch [:contract/fetch-compiled-code [:contract/compiled-code-loaded]]}
(when (:provides-web3? db/default-db)
{:web3-fx.blockchain/fns
{:web3 (:web3 db/default-db)
:fns [[web3-eth/accounts :blockchain/my-addresses-loaded :log-error]]}}))))
@madvas
madvas / handlers.cljs
Created October 3, 2016 15:17
:contract/fetch-compiled-code
(reg-event-fx
:contract/fetch-compiled-code
interceptors
(fn [{:keys [db]} [on-success]]
{:http-xhrio {:method :get
:uri (gstring/format "/contracts/build/%s.json"
(get-in db [:contract :name]))
:timeout 6000
:response-format (ajax/json-response-format {:keywords? true})
:on-success on-success