added filters and signed message
This commit is contained in:
parent
8174279e24
commit
20d7ecb8e1
|
@ -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"]]
|
||||
|
|
|
@ -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]])
|
||||
|
|
|
@ -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))
|
|
@ -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})
|
|
@ -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))]}))
|
||||
(fn [{{:keys [web3 web3-async-data message]} :db} _]
|
||||
{:sign-message-fx [web3 (first (:accounts web3-async-data)) message]}))
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue