Skip to content

Instantly share code, notes, and snippets.

@madvas
madvas / cljs-react-material-ui-reagent-example.cljs
Created May 13, 2016 16:26
Snippet example of using library cljs-react-material-ui with Reagent
(ns crmui-reagent.core
(:require
[cljsjs.material-ui]
[cljs-react-material-ui.core :as ui]
[cljs-react-material-ui.reagent :as rui]
[cljs-react-material-ui.icons :as ic]
[reagent.core :as r :refer [atom]]
[reagent.session :as session]
[secretary.core :as secretary :include-macros true]
[accountant.core :as accountant]
@madvas
madvas / partial-right.clj
Created June 13, 2015 12:40
Clojure partial-right (Like a partial, but arguments are added to the end)
(defn partial-right
"Takes a function f and fewer than the normal arguments to f, and
returns a fn that takes a variable number of additional args. When
called, the returned function calls f with additional args + args."
([f] f)
([f arg1]
(fn [& args] (apply f (concat args [arg1]))))
([f arg1 arg2]
(fn [& args] (apply f (concat args [arg1 arg2]))))
([f arg1 arg2 arg3]
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
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
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: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
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
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]]}}))))