diff --git a/project.clj b/project.clj index 8bcc667..75fc06b 100644 --- a/project.clj +++ b/project.clj @@ -11,6 +11,7 @@ :clean-targets ^{:protect false} ["resources/public/js/compiled" "target"] :source-paths ["src/cljs"] + :figwheel {:server-port 3450} :profiles {:dev {:dependencies [[re-frisk "0.5.3"]] diff --git a/src/cljs/status_dapp/components.cljs b/src/cljs/status_dapp/components.cljs index 02ad42a..0fa2dd5 100644 --- a/src/cljs/status_dapp/components.cljs +++ b/src/cljs/status_dapp/components.cljs @@ -4,12 +4,12 @@ (defn button [label on-press] [react/touchable-highlight {:on-press on-press} - [react/view {:style {:flex-direction :row :align-items :center :margin-top 10}} + [react/view {:style {:flex-direction :row :align-items :center :margin-vertical 5}} [react/view {:style {:padding 4 :background-color "#4360df" :border-radius 4}} [react/text {:style {:color :white}} label]]]]) (defn label [label value] - [react/view {:style {:flex-direction :row :align-items :center :margin-top 10}} + [react/view {:style {:flex-direction :row :align-items :center :margin-vertical 5}} [react/view {:style {:padding 4 :background-color "#4360df99" :border-radius 4}} [react/text {:style {:color :white}} label]] [react/text {:style {:margin-left 10}} value]]) diff --git a/src/cljs/status_dapp/core.cljs b/src/cljs/status_dapp/core.cljs index fbf8a50..3f94542 100644 --- a/src/cljs/status_dapp/core.cljs +++ b/src/cljs/status_dapp/core.cljs @@ -19,5 +19,6 @@ (defn ^:export init [] (re-frame/dispatch-sync [:initialize-db]) (re-frame/dispatch [:request-web3-async-data]) + (re-frame/dispatch [:check-filters]) (dev-setup) (mount-root)) \ No newline at end of file diff --git a/src/cljs/status_dapp/db.cljs b/src/cljs/status_dapp/db.cljs index 69f7d58..004961f 100644 --- a/src/cljs/status_dapp/db.cljs +++ b/src/cljs/status_dapp/db.cljs @@ -4,4 +4,5 @@ {:web3 (when (exists? js/web3) js/web3) :web3-async-data {} :view-id (if (exists? js/web3) :web3 :no-web3) + :message "Test message" :tab-view :accounts}) \ No newline at end of file diff --git a/src/cljs/status_dapp/events.cljs b/src/cljs/status_dapp/events.cljs index ee504f8..71dda85 100644 --- a/src/cljs/status_dapp/events.cljs +++ b/src/cljs/status_dapp/events.cljs @@ -80,13 +80,14 @@ (re-frame/reg-fx :sign-message-fx - (fn [[web3 account]] + (fn [[web3 account message]] (.sendAsync (.-currentProvider web3) (clj->js {:method "personal_sign" - :params [(.toHex web3 "Kudos to Andrey!") account] + :params [(.toHex web3 message) account] :from account}) - #(println "Sign message CB " %1 %2)))) + #(do (println "Sign message CB " %1 %2) + (re-frame/dispatch [:set :signed-message (js->clj %2 :keywordize-keys true)]))))) (re-frame/reg-event-db :set @@ -124,6 +125,15 @@ :web3-syncyng-fx web3 :web3-gas-price-fx web3}))) +(re-frame/reg-event-fx + :check-filters + (fn [{{:keys [web3] :as db} :db} _] + (when web3 + (let [filter (.filter (.-eth web3) "latest") + _ (.watch filter #()) + _ (js/setTimeout #(.stopWatching filter) 5000)] + nil)))) + (re-frame/reg-event-fx :send-transaction (fn [{{:keys [web3]} :db} [_ data]] @@ -183,5 +193,5 @@ (re-frame/reg-event-fx :sign-message - (fn [{{:keys [web3 web3-async-data]} :db} _] - {:sign-message-fx [web3 (first (:accounts web3-async-data))]})) \ No newline at end of file + (fn [{{:keys [web3 web3-async-data message]} :db} _] + {:sign-message-fx [web3 (first (:accounts web3-async-data)) message]})) \ No newline at end of file diff --git a/src/cljs/status_dapp/views.cljs b/src/cljs/status_dapp/views.cljs index a97aef3..756ef01 100644 --- a/src/cljs/status_dapp/views.cljs +++ b/src/cljs/status_dapp/views.cljs @@ -11,10 +11,22 @@ "Can't find web3 library"]]) (defview contract-panel [accounts] - (letsubs [{:keys [tx-hash address value]} [:get :contract]] + (letsubs [message [:get :message] + {:keys [result]} [:get :signed-message] + {:keys [tx-hash address value]} [:get :contract]] [react/view - [react/view {:style {:margin-bottom 10}} + [react/view {:style {:margin-bottom 10 :flex-direction :row :align-items :center}} + [react/text-input {:style {:font-size 15 :border-width 1 :border-color "#4360df33"} + :default-value message + :on-change (fn [e] + (let [native-event (.-nativeEvent e) + text (.-text native-event)] + (re-frame/dispatch [:set :message text])))}] [ui/button "Sign message" #(re-frame/dispatch [:sign-message])]] + (when result + [react/view {:style {:margin-bottom 10}} + [ui/label "Signed message: " ""] + [react/text {:style {:flex 1}} (str result)]]) (cond address