Add confirmation code view

This commit is contained in:
virvar 2016-03-07 21:19:26 +03:00
parent 8d7a57e6d4
commit 681adafdcb
5 changed files with 126 additions and 15 deletions

View File

@ -32,7 +32,7 @@
(defui AppRoot (defui AppRoot
static om/IQuery static om/IQuery
(query [this] (query [this]
'[:page :contacts-ds :user-phone-number]) '[:page :contacts-ds :user-phone-number :confirmation-code])
Object Object
(render [this] (render [this]
(let [{:keys [page]} (om/props this)] (let [{:keys [page]} (om/props this)]

View File

@ -9,8 +9,9 @@
[re-natal.support :as sup] [re-natal.support :as sup]
[syng-im.protocol.whisper :as whisper] [syng-im.protocol.whisper :as whisper]
[messenger.state :as state] [messenger.state :as state]
[messenger.android.utils :refer [log toast]]
[messenger.android.resources :as res] [messenger.android.resources :as res]
[messenger.android.contacts-list :refer [contacts-list]])) [messenger.android.sign-up-confirm :refer [sign-up-confirm]]))
(def nav-atom (atom nil)) (def nav-atom (atom nil))
@ -18,24 +19,24 @@
(def country-code "US") (def country-code "US")
(def ethereum-rpc-url "http://localhost:8545") (def ethereum-rpc-url "http://localhost:8545")
(defn show-home-view [] (defn show-confirm-view []
(binding [state/*nav-render* false] (binding [state/*nav-render* false]
(.replace @nav-atom (clj->js {:component contacts-list (.replace @nav-atom (clj->js {:component sign-up-confirm
:name "contacts-list"})))) :name "sign-up-confirm"}))))
(defn sign-in [phone-number whisper-identity] (defn sign-in [phone-number whisper-identity]
(alert (str "TODO: send number: " phone-number ", " (toast (str "TODO: send number: " phone-number ", "
(subs whisper-identity 0 2) ".." (subs whisper-identity 0 2) ".."
(subs whisper-identity (- (count whisper-identity) 2) (subs whisper-identity (- (count whisper-identity) 2)
(count whisper-identity)))) (count whisper-identity))))
(show-home-view)) (show-confirm-view))
(defn identity-handler [error result] (defn identity-handler [error result]
(if error (if error
(do (alert (str error)) (do (toast (str error))
(.log js/console "error") (.log js/console "error")
(.log js/console error)) (.log js/console error))
(alert (str result)))) (toast (str result))))
(defn get-identity [handler] (defn get-identity [handler]
(let [web3 (whisper/make-web3 ethereum-rpc-url)] (let [web3 (whisper/make-web3 ethereum-rpc-url)]
@ -51,7 +52,7 @@
(do (set-item "user-whisper-identity" identity) (do (set-item "user-whisper-identity" identity)
(swap! state/app-state assoc :user-whisper-identity identity) (swap! state/app-state assoc :user-whisper-identity identity)
(sign-in phone-number identity)) (sign-in phone-number identity))
(alert error))))))) (toast (str "error" error))))))))
(defn load-user-whisper-identity [handler] (defn load-user-whisper-identity [handler]
(get-item "user-whisper-identity" (get-item "user-whisper-identity"
@ -60,7 +61,7 @@
(let [whisper-identity (when value (str value))] (let [whisper-identity (when value (str value))]
(swap! state/app-state assoc :user-whisper-identity whisper-identity) (swap! state/app-state assoc :user-whisper-identity whisper-identity)
(handler whisper-identity)) (handler whisper-identity))
(alert (str "error" error)))))) (toast (str "error" error))))))
(defn handle-phone-number [phone-number] (defn handle-phone-number [phone-number]
(when phone-number (when phone-number

View File

@ -0,0 +1,98 @@
(ns messenger.android.sign-up-confirm
(:require-macros
[natal-shell.components :refer [view text image touchable-highlight list-view
toolbar-android text-input]]
[natal-shell.async-storage :refer [get-item set-item]]
[natal-shell.core :refer [with-error-view]]
[natal-shell.alert :refer [alert]]
[natal-shell.toast-android :as toast])
(:require [om.next :as om :refer-macros [defui]]
[re-natal.support :as sup]
[syng-im.protocol.whisper :as whisper]
[messenger.state :as state]
[messenger.android.utils :refer [log toast]]
[messenger.android.resources :as res]
[messenger.android.contacts-list :refer [contacts-list]]))
(def nav-atom (atom nil))
(defn show-home-view []
(binding [state/*nav-render* false]
(.replace @nav-atom (clj->js {:component contacts-list
:name "contacts-list"}))))
(defn handle-send-check-contacts-response []
(show-home-view))
(defn send-check-contacts []
)
(defn handle-send-code-response [response]
)
(defn code-valid? [code]
(= 4 (count code)))
(defn send-code [code]
(when (code-valid? code)
(toast (str code))
(show-home-view)))
(defn update-code [value]
(let [formatted value]
(swap! state/app-state assoc :confirmation-code formatted)))
(defui SignUpConfirm
static om/IQuery
(query [this]
'[:confirmation-code])
Object
(render
[this]
(let [{:keys [confirmation-code]} (om/props this)
{:keys [nav]} (om/get-computed this)]
(reset! nav-atom nav)
(view
{:style {:flex 1
:backgroundColor "white"}}
(toolbar-android {:logo res/logo-icon
:title "Confirm"
:titleColor "#4A5258"
:style {:backgroundColor "white"
:height 56
:elevation 2}})
(view {}
(text-input {:underlineColorAndroid "#9CBFC0"
:placeholder "Enter confirmation code"
:keyboardType "number-pad"
:maxLength 4
:onChangeText (fn [value]
(update-code value))
:style {:flex 1
:marginHorizontal 18
:lineHeight 42
:fontSize 14
:fontFamily "Avenir-Roman"
:color "#9CBFC0"}}
confirmation-code)
(if (code-valid? confirmation-code)
(touchable-highlight
{:onPress #(send-code confirmation-code)
:style {:alignSelf "center"
:borderRadius 7
:backgroundColor "#E5F5F6"
:width 100}}
(text {:style {:marginVertical 10
:textAlign "center"}}
"Confirm"))
(view
{:style {:alignSelf "center"
:borderRadius 7
:backgroundColor "#AAB2B2"
:width 100}}
(text {:style {:marginVertical 10
:textAlign "center"}}
"Confirm"))))))))
(def sign-up-confirm (om/factory SignUpConfirm))

View File

@ -0,0 +1,11 @@
(ns messenger.android.utils
(:require-macros
[natal-shell.async-storage :refer [get-item set-item]]
[natal-shell.alert :refer [alert]]
[natal-shell.toast-android :as toast]))
(defn log [obj]
(.log js/console obj))
(defn toast [s]
(toast/show s (toast/long)))

View File

@ -6,7 +6,8 @@
(defonce app-state (atom {:component nil (defonce app-state (atom {:component nil
:user-phone-number nil :user-phone-number nil
:user-whisper-identity nil})) :user-whisper-identity nil
:confirmation-code nil}))
(def ^{:dynamic true :private true} *nav-render* (def ^{:dynamic true :private true} *nav-render*
"Flag to suppress navigator re-renders from outside om when pushing/popping." "Flag to suppress navigator re-renders from outside om when pushing/popping."
true) true)